refactor: use reqwest to handle http-get requests

Closes #82
This commit is contained in:
Friedel Ziegelmayer
2019-05-27 09:06:55 +02:00
committed by GitHub
parent a247e5b143
commit f0cfcef864
5 changed files with 21 additions and 123 deletions

View File

@@ -16,7 +16,6 @@ use deltachat::dc_job::{
dc_perform_smtp_jobs,
};
use deltachat::dc_lot::*;
use deltachat::x::strdup;
extern "C" fn cb(_ctx: &dc_context_t, event: Event, data1: usize, data2: usize) -> usize {
println!("[{:?}]", event);
@@ -26,22 +25,6 @@ extern "C" fn cb(_ctx: &dc_context_t, event: Event, data1: usize, data2: usize)
println!(" progress: {}", data1);
0
}
Event::HTTP_GET => {
let url = unsafe { CStr::from_ptr(data1 as *const _).to_str().unwrap() };
match reqwest::get(url) {
Ok(ref mut res) => {
let c_res = CString::new(res.text().unwrap()).unwrap();
// need to use strdup to allocate the result with malloc
// so it can be `free`d later.
unsafe { strdup(c_res.as_ptr()) as usize }
}
Err(err) => {
println!("failed to download: {}: {:?}", url, err);
0
}
}
}
Event::INFO | Event::WARNING | Event::ERROR | Event::ERROR_NETWORK => {
println!(
" {}",