mirror of
https://github.com/chatmail/core.git
synced 2026-05-07 08:56:30 +03:00
first round of configure cleanups
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
use libc::free;
|
|
||||||
use quick_xml;
|
use quick_xml;
|
||||||
use quick_xml::events::{BytesEnd, BytesStart, BytesText};
|
use quick_xml::events::{BytesEnd, BytesStart, BytesText};
|
||||||
|
|
||||||
use crate::constants::*;
|
use crate::constants::*;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::dc_tools::*;
|
|
||||||
use crate::login_param::LoginParam;
|
use crate::login_param::LoginParam;
|
||||||
|
|
||||||
use super::read_autoconf_file;
|
use super::read_autoconf_file;
|
||||||
@@ -24,26 +22,28 @@ struct moz_autoconfigure_t<'a> {
|
|||||||
pub tag_config: libc::c_int,
|
pub tag_config: libc::c_int,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn moz_autoconfigure(
|
pub fn moz_autoconfigure(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
url: &str,
|
url: &str,
|
||||||
param_in: &LoginParam,
|
param_in: &LoginParam,
|
||||||
) -> Option<LoginParam> {
|
) -> Option<LoginParam> {
|
||||||
let xml_raw = read_autoconf_file(context, url);
|
let xml_raw = match read_autoconf_file(context, url) {
|
||||||
if xml_raw.is_null() {
|
Err(err) => {
|
||||||
return None;
|
info!(context, "can't read file: {}", err);
|
||||||
}
|
return None;
|
||||||
|
}
|
||||||
|
Ok(content) => content,
|
||||||
|
};
|
||||||
|
|
||||||
// Split address into local part and domain part.
|
// Split address into local part and domain part.
|
||||||
let p = param_in.addr.find("@");
|
let p = param_in.addr.find("@");
|
||||||
if p.is_none() {
|
if p.is_none() {
|
||||||
free(xml_raw as *mut libc::c_void);
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let (in_emaillocalpart, in_emaildomain) = param_in.addr.split_at(p.unwrap());
|
let (in_emaillocalpart, in_emaildomain) = param_in.addr.split_at(p.unwrap());
|
||||||
let in_emaildomain = &in_emaildomain[1..];
|
let in_emaildomain = &in_emaildomain[1..];
|
||||||
|
|
||||||
let mut reader = quick_xml::Reader::from_str(as_str(xml_raw));
|
let mut reader = quick_xml::Reader::from_str(&xml_raw);
|
||||||
reader.trim_text(true);
|
reader.trim_text(true);
|
||||||
|
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
@@ -88,11 +88,9 @@ pub unsafe fn moz_autoconfigure(
|
|||||||
{
|
{
|
||||||
let r = moz_ac.out.to_string();
|
let r = moz_ac.out.to_string();
|
||||||
warn!(context, "Bad or incomplete autoconfig: {}", r,);
|
warn!(context, "Bad or incomplete autoconfig: {}", r,);
|
||||||
free(xml_raw as *mut libc::c_void);
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(xml_raw as *mut libc::c_void);
|
|
||||||
Some(moz_ac.out)
|
Some(moz_ac.out)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,13 +23,12 @@ struct outlk_autodiscover_t<'a> {
|
|||||||
pub config: [*mut libc::c_char; 6],
|
pub config: [*mut libc::c_char; 6],
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn outlk_autodiscover(
|
pub fn outlk_autodiscover(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
url__: &str,
|
url__: &str,
|
||||||
param_in: &LoginParam,
|
param_in: &LoginParam,
|
||||||
) -> Option<LoginParam> {
|
) -> Option<LoginParam> {
|
||||||
let mut xml_raw: *mut libc::c_char = ptr::null_mut();
|
let mut url = url__.to_string();
|
||||||
let mut url = url__.strdup();
|
|
||||||
let mut outlk_ad = outlk_autodiscover_t {
|
let mut outlk_ad = outlk_autodiscover_t {
|
||||||
in_0: param_in,
|
in_0: param_in,
|
||||||
out: LoginParam::new(),
|
out: LoginParam::new(),
|
||||||
@@ -45,18 +44,21 @@ pub unsafe fn outlk_autodiscover(
|
|||||||
ok_to_continue = true;
|
ok_to_continue = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
libc::memset(
|
unsafe {
|
||||||
&mut outlk_ad as *mut outlk_autodiscover_t as *mut libc::c_void,
|
libc::memset(
|
||||||
0,
|
&mut outlk_ad as *mut outlk_autodiscover_t as *mut libc::c_void,
|
||||||
::std::mem::size_of::<outlk_autodiscover_t>(),
|
0,
|
||||||
);
|
::std::mem::size_of::<outlk_autodiscover_t>(),
|
||||||
xml_raw = read_autoconf_file(context, as_str(url));
|
);
|
||||||
if xml_raw.is_null() {
|
}
|
||||||
|
let xml_raw = read_autoconf_file(context, &url);
|
||||||
|
if xml_raw.is_err() {
|
||||||
ok_to_continue = false;
|
ok_to_continue = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
let xml_raw = xml_raw.unwrap();
|
||||||
|
|
||||||
let mut reader = quick_xml::Reader::from_str(as_str(xml_raw));
|
let mut reader = quick_xml::Reader::from_str(&xml_raw);
|
||||||
reader.trim_text(true);
|
reader.trim_text(true);
|
||||||
|
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
@@ -86,18 +88,17 @@ pub unsafe fn outlk_autodiscover(
|
|||||||
buf.clear();
|
buf.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
if !(!outlk_ad.config[5].is_null()
|
unsafe {
|
||||||
&& 0 != *outlk_ad.config[5usize].offset(0isize) as libc::c_int)
|
if !(!outlk_ad.config[5].is_null()
|
||||||
{
|
&& 0 != *outlk_ad.config[5usize].offset(0isize) as libc::c_int)
|
||||||
ok_to_continue = true;
|
{
|
||||||
break;
|
ok_to_continue = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
free(url as *mut libc::c_void);
|
url = to_string(outlk_ad.config[5usize]);
|
||||||
url = dc_strdup(outlk_ad.config[5usize]);
|
|
||||||
|
|
||||||
outlk_clean_config(&mut outlk_ad);
|
outlk_clean_config(&mut outlk_ad);
|
||||||
free(xml_raw as *mut libc::c_void);
|
|
||||||
xml_raw = ptr::null_mut();
|
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,23 +110,21 @@ pub unsafe fn outlk_autodiscover(
|
|||||||
{
|
{
|
||||||
let r = outlk_ad.out.to_string();
|
let r = outlk_ad.out.to_string();
|
||||||
warn!(context, "Bad or incomplete autoconfig: {}", r,);
|
warn!(context, "Bad or incomplete autoconfig: {}", r,);
|
||||||
free(url as *mut libc::c_void);
|
|
||||||
free(xml_raw as *mut libc::c_void);
|
|
||||||
outlk_clean_config(&mut outlk_ad);
|
outlk_clean_config(&mut outlk_ad);
|
||||||
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(url as *mut libc::c_void);
|
|
||||||
free(xml_raw as *mut libc::c_void);
|
|
||||||
outlk_clean_config(&mut outlk_ad);
|
outlk_clean_config(&mut outlk_ad);
|
||||||
Some(outlk_ad.out)
|
Some(outlk_ad.out)
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn outlk_clean_config(mut outlk_ad: *mut outlk_autodiscover_t) {
|
fn outlk_clean_config(mut outlk_ad: *mut outlk_autodiscover_t) {
|
||||||
for i in 0..6 {
|
for i in 0..6 {
|
||||||
free((*outlk_ad).config[i] as *mut libc::c_void);
|
unsafe {
|
||||||
(*outlk_ad).config[i] = ptr::null_mut();
|
free((*outlk_ad).config[i] as *mut libc::c_void);
|
||||||
|
(*outlk_ad).config[i] = ptr::null_mut();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,53 +141,55 @@ fn outlk_autodiscover_text_cb<B: std::io::BufRead>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn outlk_autodiscover_endtag_cb(event: &BytesEnd, outlk_ad: &mut outlk_autodiscover_t) {
|
fn outlk_autodiscover_endtag_cb(event: &BytesEnd, outlk_ad: &mut outlk_autodiscover_t) {
|
||||||
let tag = String::from_utf8_lossy(event.name()).trim().to_lowercase();
|
let tag = String::from_utf8_lossy(event.name()).trim().to_lowercase();
|
||||||
|
|
||||||
if tag == "protocol" {
|
if tag == "protocol" {
|
||||||
if !outlk_ad.config[1].is_null() {
|
unsafe {
|
||||||
let port = dc_atoi_null_is_0(outlk_ad.config[3]);
|
if !outlk_ad.config[1].is_null() {
|
||||||
let ssl_on = (!outlk_ad.config[4].is_null()
|
let port = dc_atoi_null_is_0(outlk_ad.config[3]);
|
||||||
&& strcasecmp(
|
let ssl_on = (!outlk_ad.config[4].is_null()
|
||||||
outlk_ad.config[4],
|
&& strcasecmp(
|
||||||
b"on\x00" as *const u8 as *const libc::c_char,
|
outlk_ad.config[4],
|
||||||
) == 0) as libc::c_int;
|
b"on\x00" as *const u8 as *const libc::c_char,
|
||||||
let ssl_off = (!outlk_ad.config[4].is_null()
|
) == 0) as libc::c_int;
|
||||||
&& strcasecmp(
|
let ssl_off = (!outlk_ad.config[4].is_null()
|
||||||
outlk_ad.config[4],
|
&& strcasecmp(
|
||||||
b"off\x00" as *const u8 as *const libc::c_char,
|
outlk_ad.config[4],
|
||||||
) == 0) as libc::c_int;
|
b"off\x00" as *const u8 as *const libc::c_char,
|
||||||
if strcasecmp(
|
) == 0) as libc::c_int;
|
||||||
outlk_ad.config[1],
|
if strcasecmp(
|
||||||
b"imap\x00" as *const u8 as *const libc::c_char,
|
outlk_ad.config[1],
|
||||||
) == 0
|
b"imap\x00" as *const u8 as *const libc::c_char,
|
||||||
&& outlk_ad.out_imap_set == 0
|
) == 0
|
||||||
{
|
&& outlk_ad.out_imap_set == 0
|
||||||
outlk_ad.out.mail_server = to_string_lossy(outlk_ad.config[2]);
|
{
|
||||||
outlk_ad.out.mail_port = port;
|
outlk_ad.out.mail_server = to_string_lossy(outlk_ad.config[2]);
|
||||||
if 0 != ssl_on {
|
outlk_ad.out.mail_port = port;
|
||||||
outlk_ad.out.server_flags |= DC_LP_IMAP_SOCKET_SSL as i32
|
if 0 != ssl_on {
|
||||||
} else if 0 != ssl_off {
|
outlk_ad.out.server_flags |= DC_LP_IMAP_SOCKET_SSL as i32
|
||||||
outlk_ad.out.server_flags |= DC_LP_IMAP_SOCKET_PLAIN as i32
|
} else if 0 != ssl_off {
|
||||||
|
outlk_ad.out.server_flags |= DC_LP_IMAP_SOCKET_PLAIN as i32
|
||||||
|
}
|
||||||
|
outlk_ad.out_imap_set = 1
|
||||||
|
} else if strcasecmp(
|
||||||
|
outlk_ad.config[1usize],
|
||||||
|
b"smtp\x00" as *const u8 as *const libc::c_char,
|
||||||
|
) == 0
|
||||||
|
&& outlk_ad.out_smtp_set == 0
|
||||||
|
{
|
||||||
|
outlk_ad.out.send_server = to_string_lossy(outlk_ad.config[2]);
|
||||||
|
outlk_ad.out.send_port = port;
|
||||||
|
if 0 != ssl_on {
|
||||||
|
outlk_ad.out.server_flags |= DC_LP_SMTP_SOCKET_SSL as i32
|
||||||
|
} else if 0 != ssl_off {
|
||||||
|
outlk_ad.out.server_flags |= DC_LP_SMTP_SOCKET_PLAIN as i32
|
||||||
|
}
|
||||||
|
outlk_ad.out_smtp_set = 1
|
||||||
}
|
}
|
||||||
outlk_ad.out_imap_set = 1
|
|
||||||
} else if strcasecmp(
|
|
||||||
outlk_ad.config[1usize],
|
|
||||||
b"smtp\x00" as *const u8 as *const libc::c_char,
|
|
||||||
) == 0
|
|
||||||
&& outlk_ad.out_smtp_set == 0
|
|
||||||
{
|
|
||||||
outlk_ad.out.send_server = to_string_lossy(outlk_ad.config[2]);
|
|
||||||
outlk_ad.out.send_port = port;
|
|
||||||
if 0 != ssl_on {
|
|
||||||
outlk_ad.out.server_flags |= DC_LP_SMTP_SOCKET_SSL as i32
|
|
||||||
} else if 0 != ssl_off {
|
|
||||||
outlk_ad.out.server_flags |= DC_LP_SMTP_SOCKET_PLAIN as i32
|
|
||||||
}
|
|
||||||
outlk_ad.out_smtp_set = 1
|
|
||||||
}
|
}
|
||||||
|
outlk_clean_config(outlk_ad);
|
||||||
}
|
}
|
||||||
outlk_clean_config(outlk_ad);
|
|
||||||
}
|
}
|
||||||
outlk_ad.tag_config = 0;
|
outlk_ad.tag_config = 0;
|
||||||
}
|
}
|
||||||
@@ -197,7 +198,7 @@ fn outlk_autodiscover_starttag_cb(event: &BytesStart, outlk_ad: &mut outlk_autod
|
|||||||
let tag = String::from_utf8_lossy(event.name()).trim().to_lowercase();
|
let tag = String::from_utf8_lossy(event.name()).trim().to_lowercase();
|
||||||
|
|
||||||
if tag == "protocol" {
|
if tag == "protocol" {
|
||||||
unsafe { outlk_clean_config(outlk_ad) };
|
outlk_clean_config(outlk_ad);
|
||||||
} else if tag == "type" {
|
} else if tag == "type" {
|
||||||
outlk_ad.tag_config = 1
|
outlk_ad.tag_config = 1
|
||||||
} else if tag == "server" {
|
} else if tag == "server" {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use crate::constants::*;
|
|||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::dc_tools::*;
|
use crate::dc_tools::*;
|
||||||
use crate::e2ee;
|
use crate::e2ee;
|
||||||
|
use crate::error::*;
|
||||||
use crate::imap::*;
|
use crate::imap::*;
|
||||||
use crate::job::*;
|
use crate::job::*;
|
||||||
use crate::login_param::LoginParam;
|
use crate::login_param::LoginParam;
|
||||||
@@ -27,7 +28,7 @@ macro_rules! progress {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// connect
|
// connect
|
||||||
pub unsafe fn configure(context: &Context) {
|
pub fn configure(context: &Context) {
|
||||||
if dc_has_ongoing(context) {
|
if dc_has_ongoing(context) {
|
||||||
warn!(context, "There is already another ongoing process running.",);
|
warn!(context, "There is already another ongoing process running.",);
|
||||||
return;
|
return;
|
||||||
@@ -46,7 +47,7 @@ pub fn dc_is_configured(context: &Context) -> bool {
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
// the other dc_job_do_DC_JOB_*() functions are declared static in the c-file
|
// the other dc_job_do_DC_JOB_*() functions are declared static in the c-file
|
||||||
#[allow(non_snake_case, unused_must_use)]
|
#[allow(non_snake_case, unused_must_use)]
|
||||||
pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context) {
|
pub fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context) {
|
||||||
let mut success = false;
|
let mut success = false;
|
||||||
let mut imap_connected_here = false;
|
let mut imap_connected_here = false;
|
||||||
let mut smtp_connected_here = false;
|
let mut smtp_connected_here = false;
|
||||||
@@ -633,7 +634,7 @@ pub fn dc_stop_ongoing_process(context: &Context) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_autoconf_file(context: &Context, url: &str) -> *mut libc::c_char {
|
pub fn read_autoconf_file(context: &Context, url: &str) -> Result<String> {
|
||||||
info!(context, "Testing {} ...", url);
|
info!(context, "Testing {} ...", url);
|
||||||
|
|
||||||
match reqwest::Client::new()
|
match reqwest::Client::new()
|
||||||
@@ -641,12 +642,10 @@ pub fn read_autoconf_file(context: &Context, url: &str) -> *mut libc::c_char {
|
|||||||
.send()
|
.send()
|
||||||
.and_then(|mut res| res.text())
|
.and_then(|mut res| res.text())
|
||||||
{
|
{
|
||||||
Ok(res) => unsafe { res.strdup() },
|
Err(err) => {
|
||||||
Err(_err) => {
|
bail!("{}", err);
|
||||||
info!(context, "Can\'t read file.",);
|
|
||||||
|
|
||||||
std::ptr::null_mut()
|
|
||||||
}
|
}
|
||||||
|
Ok(res) => Ok(res.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -664,8 +663,6 @@ mod tests {
|
|||||||
.set_config(Config::Addr, Some("probably@unexistant.addr"))
|
.set_config(Config::Addr, Some("probably@unexistant.addr"))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
t.ctx.set_config(Config::MailPw, Some("123456")).unwrap();
|
t.ctx.set_config(Config::MailPw, Some("123456")).unwrap();
|
||||||
unsafe {
|
dc_job_do_DC_JOB_CONFIGURE_IMAP(&t.ctx);
|
||||||
dc_job_do_DC_JOB_CONFIGURE_IMAP(&t.ctx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -781,8 +781,8 @@ fn job_perform(context: &Context, thread: Thread, probe_network: bool) {
|
|||||||
Action::MarkseenMdnOnImap => job.do_DC_JOB_MARKSEEN_MDN_ON_IMAP(context),
|
Action::MarkseenMdnOnImap => job.do_DC_JOB_MARKSEEN_MDN_ON_IMAP(context),
|
||||||
Action::MoveMsg => job.do_DC_JOB_MOVE_MSG(context),
|
Action::MoveMsg => job.do_DC_JOB_MOVE_MSG(context),
|
||||||
Action::SendMdn => job.do_DC_JOB_SEND(context),
|
Action::SendMdn => job.do_DC_JOB_SEND(context),
|
||||||
Action::ConfigureImap => unsafe { dc_job_do_DC_JOB_CONFIGURE_IMAP(context) },
|
Action::ConfigureImap => dc_job_do_DC_JOB_CONFIGURE_IMAP(context),
|
||||||
Action::ImexImap => match job_do_DC_JOB_IMEX_IMAP(context, &job) {
|
Action::ImexImap => match dc_job_do_DC_JOB_IMEX_IMAP(context) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!(context, "{}", err);
|
error!(context, "{}", err);
|
||||||
|
|||||||
Reference in New Issue
Block a user