mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 01:16:31 +03:00
Remove some free() from Mozilla autoconfig (#457)
Remove some free() from Mozilla autoconfig
This commit is contained in:
@@ -14,8 +14,8 @@ use super::read_autoconf_file;
|
|||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
struct moz_autoconfigure_t<'a> {
|
struct moz_autoconfigure_t<'a> {
|
||||||
pub in_0: &'a dc_loginparam_t,
|
pub in_0: &'a dc_loginparam_t,
|
||||||
pub in_emaildomain: *mut libc::c_char,
|
pub in_emaildomain: &'a str,
|
||||||
pub in_emaillocalpart: *mut libc::c_char,
|
pub in_emaillocalpart: &'a str,
|
||||||
pub out: dc_loginparam_t,
|
pub out: dc_loginparam_t,
|
||||||
pub out_imap_set: libc::c_int,
|
pub out_imap_set: libc::c_int,
|
||||||
pub out_smtp_set: libc::c_int,
|
pub out_smtp_set: libc::c_int,
|
||||||
@@ -28,42 +28,35 @@ pub unsafe fn moz_autoconfigure(
|
|||||||
url: &str,
|
url: &str,
|
||||||
param_in: &dc_loginparam_t,
|
param_in: &dc_loginparam_t,
|
||||||
) -> Option<dc_loginparam_t> {
|
) -> Option<dc_loginparam_t> {
|
||||||
let mut moz_ac = moz_autoconfigure_t {
|
let xml_raw = read_autoconf_file(context, url);
|
||||||
in_0: param_in,
|
|
||||||
in_emaildomain: std::ptr::null_mut(),
|
|
||||||
in_emaillocalpart: std::ptr::null_mut(),
|
|
||||||
out: dc_loginparam_new(),
|
|
||||||
out_imap_set: 0,
|
|
||||||
out_smtp_set: 0,
|
|
||||||
tag_server: 0,
|
|
||||||
tag_config: 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
let url_c = url.strdup();
|
|
||||||
let xml_raw = read_autoconf_file(context, url_c);
|
|
||||||
free(url_c as *mut libc::c_void);
|
|
||||||
if xml_raw.is_null() {
|
if xml_raw.is_null() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
moz_ac.in_emaillocalpart = param_in.addr.strdup();
|
// Split address into local part and domain part.
|
||||||
let p = strchr(moz_ac.in_emaillocalpart, '@' as i32);
|
let p = param_in.addr.find("@");
|
||||||
|
if p.is_none() {
|
||||||
if p.is_null() {
|
|
||||||
free(xml_raw as *mut libc::c_void);
|
free(xml_raw as *mut libc::c_void);
|
||||||
free(moz_ac.in_emaildomain as *mut libc::c_void);
|
|
||||||
free(moz_ac.in_emaillocalpart as *mut libc::c_void);
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
let (in_emaillocalpart, in_emaildomain) = param_in.addr.split_at(p.unwrap());
|
||||||
*p = 0 as libc::c_char;
|
let in_emaildomain = &in_emaildomain[1..];
|
||||||
moz_ac.in_emaildomain = dc_strdup(p.offset(1isize));
|
|
||||||
|
|
||||||
let mut reader = quick_xml::Reader::from_str(as_str(xml_raw));
|
let mut reader = quick_xml::Reader::from_str(as_str(xml_raw));
|
||||||
reader.trim_text(true);
|
reader.trim_text(true);
|
||||||
|
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
|
|
||||||
|
let mut moz_ac = moz_autoconfigure_t {
|
||||||
|
in_0: param_in,
|
||||||
|
in_emaildomain,
|
||||||
|
in_emaillocalpart,
|
||||||
|
out: dc_loginparam_new(),
|
||||||
|
out_imap_set: 0,
|
||||||
|
out_smtp_set: 0,
|
||||||
|
tag_server: 0,
|
||||||
|
tag_config: 0,
|
||||||
|
};
|
||||||
loop {
|
loop {
|
||||||
match reader.read_event(&mut buf) {
|
match reader.read_event(&mut buf) {
|
||||||
Ok(quick_xml::events::Event::Start(ref e)) => {
|
Ok(quick_xml::events::Event::Start(ref e)) => {
|
||||||
@@ -96,14 +89,10 @@ pub unsafe fn moz_autoconfigure(
|
|||||||
let r = dc_loginparam_get_readable(&moz_ac.out);
|
let r = dc_loginparam_get_readable(&moz_ac.out);
|
||||||
warn!(context, 0, "Bad or incomplete autoconfig: {}", r,);
|
warn!(context, 0, "Bad or incomplete autoconfig: {}", r,);
|
||||||
free(xml_raw as *mut libc::c_void);
|
free(xml_raw as *mut libc::c_void);
|
||||||
free(moz_ac.in_emaildomain as *mut libc::c_void);
|
|
||||||
free(moz_ac.in_emaillocalpart as *mut libc::c_void);
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(xml_raw as *mut libc::c_void);
|
free(xml_raw as *mut libc::c_void);
|
||||||
free(moz_ac.in_emaildomain as *mut libc::c_void);
|
|
||||||
free(moz_ac.in_emaillocalpart as *mut libc::c_void);
|
|
||||||
Some(moz_ac.out)
|
Some(moz_ac.out)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,8 +104,8 @@ fn moz_autoconfigure_text_cb<B: std::io::BufRead>(
|
|||||||
let val = event.unescape_and_decode(reader).unwrap_or_default();
|
let val = event.unescape_and_decode(reader).unwrap_or_default();
|
||||||
|
|
||||||
let addr = &moz_ac.in_0.addr;
|
let addr = &moz_ac.in_0.addr;
|
||||||
let email_local = as_str(moz_ac.in_emaillocalpart);
|
let email_local = moz_ac.in_emaillocalpart;
|
||||||
let email_domain = as_str(moz_ac.in_emaildomain);
|
let email_domain = moz_ac.in_emaildomain;
|
||||||
|
|
||||||
let val = val
|
let val = val
|
||||||
.trim()
|
.trim()
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ pub unsafe fn outlk_autodiscover(
|
|||||||
0,
|
0,
|
||||||
::std::mem::size_of::<outlk_autodiscover_t>(),
|
::std::mem::size_of::<outlk_autodiscover_t>(),
|
||||||
);
|
);
|
||||||
xml_raw = read_autoconf_file(context, url);
|
xml_raw = read_autoconf_file(context, as_str(url));
|
||||||
if xml_raw.is_null() {
|
if xml_raw.is_null() {
|
||||||
ok_to_continue = false;
|
ok_to_continue = false;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -663,11 +663,11 @@ pub fn dc_stop_ongoing_process(context: &Context) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_autoconf_file(context: &Context, url: *const libc::c_char) -> *mut libc::c_char {
|
pub fn read_autoconf_file(context: &Context, url: &str) -> *mut libc::c_char {
|
||||||
info!(context, 0, "Testing {} ...", to_string(url));
|
info!(context, 0, "Testing {} ...", url);
|
||||||
|
|
||||||
match reqwest::Client::new()
|
match reqwest::Client::new()
|
||||||
.get(as_str(url))
|
.get(url)
|
||||||
.send()
|
.send()
|
||||||
.and_then(|mut res| res.text())
|
.and_then(|mut res| res.text())
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user