continue rustification

This commit is contained in:
dignifiedquire
2019-05-01 14:50:09 +02:00
parent 72e9fe6150
commit 75319dbf67
23 changed files with 2091 additions and 2120 deletions

View File

@@ -597,10 +597,7 @@ unsafe extern "C" fn chat_prefix(mut chat: *const dc_chat_t) -> *const libc::c_c
}; };
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn dc_cmdline( pub unsafe extern "C" fn dc_cmdline(context: &dc_context_t, cmdline: &str) -> *mut libc::c_char {
mut context: *mut dc_context_t,
cmdline: &str,
) -> *mut libc::c_char {
let mut cmd: &libc::c_char = 0 as *mut libc::c_char; let mut cmd: &libc::c_char = 0 as *mut libc::c_char;
let mut arg1: *mut libc::c_char = 0 as *mut libc::c_char; let mut arg1: *mut libc::c_char = 0 as *mut libc::c_char;
let mut ret: *mut libc::c_char = 1i32 as *mut libc::c_char; let mut ret: *mut libc::c_char = 1i32 as *mut libc::c_char;

View File

@@ -17,8 +17,8 @@ use crate::x::*;
*/ */
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub struct dc_apeerstate_t { pub struct dc_apeerstate_t<'a> {
pub context: &dc_context_t, pub context: &'a dc_context_t,
pub addr: *mut libc::c_char, pub addr: *mut libc::c_char,
pub last_seen: time_t, pub last_seen: time_t,
pub last_seen_autocrypt: time_t, pub last_seen_autocrypt: time_t,
@@ -35,13 +35,14 @@ pub struct dc_apeerstate_t {
} }
/* the returned pointer is ref'd and must be unref'd after usage */ /* the returned pointer is ref'd and must be unref'd after usage */
pub unsafe fn dc_apeerstate_new(mut context: &dc_context_t) -> *mut dc_apeerstate_t { pub unsafe fn dc_apeerstate_new<'a>(context: &'a dc_context_t) -> *mut dc_apeerstate_t<'a> {
let mut peerstate: *mut dc_apeerstate_t = 0 as *mut dc_apeerstate_t; let mut peerstate: *mut dc_apeerstate_t = 0 as *mut dc_apeerstate_t;
peerstate = calloc(1, ::std::mem::size_of::<dc_apeerstate_t>()) as *mut dc_apeerstate_t; peerstate = calloc(1, ::std::mem::size_of::<dc_apeerstate_t>()) as *mut dc_apeerstate_t;
if peerstate.is_null() { if peerstate.is_null() {
exit(43i32); exit(43i32);
} }
(*peerstate).context = context; (*peerstate).context = context;
return peerstate; return peerstate;
} }
pub unsafe fn dc_apeerstate_unref(mut peerstate: *mut dc_apeerstate_t) { pub unsafe fn dc_apeerstate_unref(mut peerstate: *mut dc_apeerstate_t) {
@@ -311,12 +312,12 @@ pub unsafe fn dc_apeerstate_set_verified(
} }
pub unsafe fn dc_apeerstate_load_by_addr( pub unsafe fn dc_apeerstate_load_by_addr(
mut peerstate: *mut dc_apeerstate_t, mut peerstate: *mut dc_apeerstate_t,
mut sql: *mut dc_sqlite3_t, mut sql: &mut dc_sqlite3_t,
mut addr: *const libc::c_char, mut addr: *const libc::c_char,
) -> libc::c_int { ) -> libc::c_int {
let mut success: libc::c_int = 0i32; let mut success: libc::c_int = 0i32;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
if !(peerstate.is_null() || sql.is_null() || addr.is_null()) { if !(peerstate.is_null() || addr.is_null()) {
dc_apeerstate_empty(peerstate); dc_apeerstate_empty(peerstate);
stmt = stmt =
dc_sqlite3_prepare(sql, dc_sqlite3_prepare(sql,
@@ -361,12 +362,12 @@ unsafe fn dc_apeerstate_set_from_stmt(
} }
pub unsafe fn dc_apeerstate_load_by_fingerprint( pub unsafe fn dc_apeerstate_load_by_fingerprint(
mut peerstate: *mut dc_apeerstate_t, mut peerstate: *mut dc_apeerstate_t,
mut sql: *mut dc_sqlite3_t, mut sql: &mut dc_sqlite3_t,
mut fingerprint: *const libc::c_char, mut fingerprint: *const libc::c_char,
) -> libc::c_int { ) -> libc::c_int {
let mut success: libc::c_int = 0i32; let mut success: libc::c_int = 0i32;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
if !(peerstate.is_null() || sql.is_null() || fingerprint.is_null()) { if !(peerstate.is_null() || fingerprint.is_null()) {
dc_apeerstate_empty(peerstate); dc_apeerstate_empty(peerstate);
stmt = stmt =
dc_sqlite3_prepare(sql, dc_sqlite3_prepare(sql,
@@ -385,13 +386,13 @@ pub unsafe fn dc_apeerstate_load_by_fingerprint(
} }
pub unsafe fn dc_apeerstate_save_to_db( pub unsafe fn dc_apeerstate_save_to_db(
mut peerstate: *const dc_apeerstate_t, mut peerstate: *const dc_apeerstate_t,
mut sql: *mut dc_sqlite3_t, mut sql: &mut dc_sqlite3_t,
mut create: libc::c_int, mut create: libc::c_int,
) -> libc::c_int { ) -> libc::c_int {
let mut current_block: u64; let mut current_block: u64;
let mut success: libc::c_int = 0i32; let mut success: libc::c_int = 0i32;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
if peerstate.is_null() || sql.is_null() || (*peerstate).addr.is_null() { if peerstate.is_null() || (*peerstate).addr.is_null() {
return 0i32; return 0i32;
} }
if 0 != create { if 0 != create {

View File

@@ -268,7 +268,7 @@ pub unsafe fn dc_array_new(initsize: size_t) -> *mut dc_array_t {
pub unsafe extern "C" fn dc_array_new_typed( pub unsafe extern "C" fn dc_array_new_typed(
mut type_0: libc::c_int, mut type_0: libc::c_int,
mut initsize: size_t, mut initsize: size_t,
) -> &dc_array_t { ) -> *mut dc_array_t {
let mut array: *mut dc_array_t = 0 as *mut dc_array_t; let mut array: *mut dc_array_t = 0 as *mut dc_array_t;
array = calloc(1, ::std::mem::size_of::<dc_array_t>()) as *mut dc_array_t; array = calloc(1, ::std::mem::size_of::<dc_array_t>()) as *mut dc_array_t;
if array.is_null() { if array.is_null() {
@@ -286,8 +286,9 @@ pub unsafe extern "C" fn dc_array_new_typed(
if (*array).array.is_null() { if (*array).array.is_null() {
exit(48i32); exit(48i32);
} }
return array; array
} }
pub unsafe fn dc_array_empty(mut array: *mut dc_array_t) { pub unsafe fn dc_array_empty(mut array: *mut dc_array_t) {
if array.is_null() || (*array).magic != 0xa11aai32 as libc::c_uint { if array.is_null() || (*array).magic != 0xa11aai32 as libc::c_uint {
return; return;

File diff suppressed because it is too large Load Diff

View File

@@ -15,27 +15,27 @@ use crate::x::*;
/* * the structure behind dc_chatlist_t */ /* * the structure behind dc_chatlist_t */
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub struct dc_chatlist_t { pub struct dc_chatlist_t<'a> {
pub magic: uint32_t, pub magic: uint32_t,
pub context: &dc_context_t, pub context: &'a dc_context_t,
pub cnt: size_t, pub cnt: size_t,
pub chatNlastmsg_ids: *mut dc_array_t, pub chatNlastmsg_ids: *mut dc_array_t,
} }
// handle chatlists // handle chatlists
pub unsafe fn dc_get_chatlist( pub unsafe fn dc_get_chatlist<'a>(
mut context: &dc_context_t, mut context: &'a dc_context_t,
mut listflags: libc::c_int, mut listflags: libc::c_int,
mut query_str: *const libc::c_char, mut query_str: *const libc::c_char,
mut query_id: uint32_t, mut query_id: uint32_t,
) -> *mut dc_chatlist_t { ) -> *mut dc_chatlist_t<'a> {
let mut success: libc::c_int = 0i32; let mut success: libc::c_int = 0i32;
let mut obj: *mut dc_chatlist_t = dc_chatlist_new(context); let mut obj: *mut dc_chatlist_t = dc_chatlist_new(context);
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
if !(0 == dc_chatlist_load_from_db(obj, listflags, query_str, query_id)) { if !(0 == dc_chatlist_load_from_db(obj, listflags, query_str, query_id)) {
success = 1i32 success = 1i32
} }
}
if 0 != success { if 0 != success {
return obj; return obj;
} else { } else {
@@ -89,7 +89,7 @@ pub unsafe fn dc_chatlist_new(mut context: &dc_context_t) -> *mut dc_chatlist_t
} }
(*chatlist).magic = 0xc4a71157u32; (*chatlist).magic = 0xc4a71157u32;
(*chatlist).context = context; (*chatlist).context = context;
(*chatlist).chatNlastmsg_ids = dc_array_new(context, 128i32 as size_t); (*chatlist).chatNlastmsg_ids = dc_array_new(128i32 as size_t);
if (*chatlist).chatNlastmsg_ids.is_null() { if (*chatlist).chatNlastmsg_ids.is_null() {
exit(32i32); exit(32i32);
} }
@@ -129,8 +129,7 @@ unsafe fn dc_chatlist_load_from_db(
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
let mut strLikeCmd: *mut libc::c_char = 0 as *mut libc::c_char; let mut strLikeCmd: *mut libc::c_char = 0 as *mut libc::c_char;
let mut query: *mut libc::c_char = 0 as *mut libc::c_char; let mut query: *mut libc::c_char = 0 as *mut libc::c_char;
if !(chatlist.is_null() || (*chatlist).magic != 0xc4a71157u32 || (*chatlist).context.is_null()) if !(chatlist.is_null() || (*chatlist).magic != 0xc4a71157u32) {
{
dc_chatlist_empty(chatlist); dc_chatlist_empty(chatlist);
// select with left join and minimum: // select with left join and minimum:
// - the inner select must use `hidden` and _not_ `m.hidden` // - the inner select must use `hidden` and _not_ `m.hidden`
@@ -144,14 +143,14 @@ unsafe fn dc_chatlist_load_from_db(
// shown at all permanent in the chatlist. // shown at all permanent in the chatlist.
if 0 != query_contact_id { if 0 != query_contact_id {
stmt = stmt =
dc_sqlite3_prepare((*(*chatlist).context).sql, dc_sqlite3_prepare(&mut (*chatlist).context.sql.lock().unwrap(),
b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?) GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00" b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?) GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00"
as *const u8 as *const libc::c_char); as *const u8 as *const libc::c_char);
sqlite3_bind_int(stmt, 1i32, query_contact_id as libc::c_int); sqlite3_bind_int(stmt, 1i32, query_contact_id as libc::c_int);
current_block = 3437258052017859086; current_block = 3437258052017859086;
} else if 0 != listflags & 0x1i32 { } else if 0 != listflags & 0x1i32 {
stmt = stmt =
dc_sqlite3_prepare((*(*chatlist).context).sql, dc_sqlite3_prepare(&mut (*chatlist).context.sql.lock().unwrap(),
b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.archived=1 GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00" b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.archived=1 GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00"
as *const u8 as *const libc::c_char); as *const u8 as *const libc::c_char);
current_block = 3437258052017859086; current_block = 3437258052017859086;
@@ -166,7 +165,7 @@ unsafe fn dc_chatlist_load_from_db(
add_archived_link_item = 1i32 add_archived_link_item = 1i32
} }
stmt = stmt =
dc_sqlite3_prepare((*(*chatlist).context).sql, dc_sqlite3_prepare(&mut (*chatlist).context.sql.lock().unwrap(),
b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.archived=0 GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00" b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.archived=0 GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00"
as *const u8 as *const libc::c_char); as *const u8 as *const libc::c_char);
current_block = 3437258052017859086; current_block = 3437258052017859086;
@@ -179,7 +178,7 @@ unsafe fn dc_chatlist_load_from_db(
} else { } else {
strLikeCmd = dc_mprintf(b"%%%s%%\x00" as *const u8 as *const libc::c_char, query); strLikeCmd = dc_mprintf(b"%%%s%%\x00" as *const u8 as *const libc::c_char, query);
stmt = stmt =
dc_sqlite3_prepare((*(*chatlist).context).sql, dc_sqlite3_prepare(&mut (*chatlist).context.sql.lock().unwrap(),
b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.name LIKE ? GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00" b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.name LIKE ? GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00"
as *const u8 as as *const u8 as
*const libc::c_char); *const libc::c_char);
@@ -224,7 +223,7 @@ unsafe fn dc_chatlist_load_from_db(
pub unsafe fn dc_get_archived_cnt(mut context: &dc_context_t) -> libc::c_int { pub unsafe fn dc_get_archived_cnt(mut context: &dc_context_t) -> libc::c_int {
let mut ret: libc::c_int = 0i32; let mut ret: libc::c_int = 0i32;
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare( let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
(*context).sql, &mut context.sql.lock().unwrap(),
b"SELECT COUNT(*) FROM chats WHERE blocked=0 AND archived=1;\x00" as *const u8 b"SELECT COUNT(*) FROM chats WHERE blocked=0 AND archived=1;\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
); );
@@ -238,7 +237,7 @@ unsafe fn get_last_deaddrop_fresh_msg(mut context: &dc_context_t) -> uint32_t {
let mut ret: uint32_t = 0i32 as uint32_t; let mut ret: uint32_t = 0i32 as uint32_t;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
stmt = stmt =
dc_sqlite3_prepare((*context).sql, dc_sqlite3_prepare(&mut context.sql.lock().unwrap(),
b"SELECT m.id FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id WHERE m.state=10 AND m.hidden=0 AND c.blocked=2 ORDER BY m.timestamp DESC, m.id DESC;\x00" b"SELECT m.id FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id WHERE m.state=10 AND m.hidden=0 AND c.blocked=2 ORDER BY m.timestamp DESC, m.id DESC;\x00"
as *const u8 as *const libc::c_char); as *const u8 as *const libc::c_char);
/* we have an index over the state-column, this should be sufficient as there are typically only few fresh messages */ /* we have an index over the state-column, this should be sufficient as there are typically only few fresh messages */
@@ -283,10 +282,10 @@ pub unsafe fn dc_chatlist_get_msg_id(
index.wrapping_mul(2).wrapping_add(1), index.wrapping_mul(2).wrapping_add(1),
); );
} }
pub unsafe fn dc_chatlist_get_summary( pub unsafe fn dc_chatlist_get_summary<'a>(
mut chatlist: *const dc_chatlist_t, mut chatlist: *const dc_chatlist_t<'a>,
mut index: size_t, mut index: size_t,
mut chat: *mut dc_chat_t, mut chat: *mut dc_chat_t<'a>,
) -> *mut dc_lot_t { ) -> *mut dc_lot_t {
let mut current_block: u64; let mut current_block: u64;
/* The summary is created by the chat, not by the last message. /* The summary is created by the chat, not by the last message.
@@ -335,7 +334,7 @@ pub unsafe fn dc_chatlist_get_summary(
lastcontact = dc_contact_new((*chatlist).context); lastcontact = dc_contact_new((*chatlist).context);
dc_contact_load_from_db( dc_contact_load_from_db(
lastcontact, lastcontact,
(*(*chatlist).context).sql, &mut (*chatlist).context.sql.lock().unwrap(),
(*lastmsg).from_id, (*lastmsg).from_id,
); );
} }
@@ -355,9 +354,8 @@ pub unsafe fn dc_chatlist_get_summary(
dc_chat_unref(chat_to_delete); dc_chat_unref(chat_to_delete);
return ret; return ret;
} }
pub unsafe fn dc_chatlist_get_context(mut chatlist: *mut dc_chatlist_t) -> &dc_context_t {
if chatlist.is_null() || (*chatlist).magic != 0xc4a71157u32 { pub unsafe fn dc_chatlist_get_context<'a>(chatlist: *mut dc_chatlist_t<'a>) -> &'a dc_context_t {
return 0 as *mut dc_context_t; assert!(!chatlist.is_null());
} (*chatlist).context
return (*chatlist).context;
} }

View File

@@ -72,9 +72,6 @@ pub unsafe fn dc_configure(mut context: &dc_context_t) {
dc_job_add(context, 900i32, 0i32, 0 as *const libc::c_char, 0i32); dc_job_add(context, 900i32, 0i32, 0 as *const libc::c_char, 0i32);
} }
pub unsafe fn dc_has_ongoing(mut context: &dc_context_t) -> libc::c_int { pub unsafe fn dc_has_ongoing(mut context: &dc_context_t) -> libc::c_int {
if context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint {
return 0i32;
}
return if 0 != (*context).ongoing_running || (*context).shall_stop_ongoing == 0i32 { return if 0 != (*context).ongoing_running || (*context).shall_stop_ongoing == 0i32 {
1i32 1i32
} else { } else {
@@ -82,12 +79,9 @@ pub unsafe fn dc_has_ongoing(mut context: &dc_context_t) -> libc::c_int {
}; };
} }
pub unsafe fn dc_is_configured(mut context: &dc_context_t) -> libc::c_int { pub unsafe fn dc_is_configured(mut context: &dc_context_t) -> libc::c_int {
if context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint {
return 0i32;
}
return if 0 return if 0
!= dc_sqlite3_get_config_int( != dc_sqlite3_get_config_int(
(*context).sql, &mut context.sql.lock().unwrap(),
b"configured\x00" as *const u8 as *const libc::c_char, b"configured\x00" as *const u8 as *const libc::c_char,
0i32, 0i32,
) { ) {
@@ -97,9 +91,6 @@ pub unsafe fn dc_is_configured(mut context: &dc_context_t) -> libc::c_int {
}; };
} }
pub unsafe fn dc_stop_ongoing_process(mut context: &dc_context_t) { pub unsafe fn dc_stop_ongoing_process(mut context: &dc_context_t) {
if context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint {
return;
}
if 0 != (*context).ongoing_running && (*context).shall_stop_ongoing == 0i32 { if 0 != (*context).ongoing_running && (*context).shall_stop_ongoing == 0i32 {
dc_log_info( dc_log_info(
context, context,
@@ -129,32 +120,49 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
let mut param_domain: *mut libc::c_char = 0 as *mut libc::c_char; let mut param_domain: *mut libc::c_char = 0 as *mut libc::c_char;
let mut param_addr_urlencoded: *mut libc::c_char = 0 as *mut libc::c_char; let mut param_addr_urlencoded: *mut libc::c_char = 0 as *mut libc::c_char;
let mut param_autoconfig: *mut dc_loginparam_t = 0 as *mut dc_loginparam_t; let mut param_autoconfig: *mut dc_loginparam_t = 0 as *mut dc_loginparam_t;
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
if !(0 == dc_alloc_ongoing(context)) { if !(0 == dc_alloc_ongoing(context)) {
ongoing_allocated_here = 1i32; ongoing_allocated_here = 1i32;
if 0 == dc_sqlite3_is_open((*context).sql) { if 0 == dc_sqlite3_is_open(&mut context.sql.lock().unwrap()) {
dc_log_error( dc_log_error(
context, context,
0i32, 0i32,
b"Cannot configure, database not opened.\x00" as *const u8 b"Cannot configure, database not opened.\x00" as *const u8 as *const libc::c_char,
as *const libc::c_char,
); );
} else { } else {
dc_imap_disconnect((*context).inbox); dc_imap_disconnect(context, &mut context.inbox.clone().lock().unwrap());
dc_imap_disconnect((*context).sentbox_thread.imap); dc_imap_disconnect(
dc_imap_disconnect((*context).mvbox_thread.imap); context,
dc_smtp_disconnect((*context).smtp); &mut context.sentbox_thread.imap.clone().lock().unwrap(),
(*(*context).smtp).log_connect_errors = 1i32; );
(*(*context).inbox).log_connect_errors = 1i32; dc_imap_disconnect(
(*(*context).sentbox_thread.imap).log_connect_errors = 1i32; context,
(*(*context).mvbox_thread.imap).log_connect_errors = 1i32; &mut context.mvbox_thread.imap.clone().lock().unwrap(),
);
dc_smtp_disconnect(&mut context.smtp.clone().lock().unwrap());
context.smtp.clone().lock().unwrap().log_connect_errors = 1i32;
context.inbox.clone().lock().unwrap().log_connect_errors = 1i32;
context
.sentbox_thread
.imap
.clone()
.lock()
.unwrap()
.log_connect_errors = 1i32;
context
.mvbox_thread
.imap
.clone()
.lock()
.unwrap()
.log_connect_errors = 1i32;
dc_log_info( dc_log_info(
context, context,
0i32, 0i32,
b"Configure ...\x00" as *const u8 as *const libc::c_char, b"Configure ...\x00" as *const u8 as *const libc::c_char,
); );
if !(0 != (*context).shall_stop_ongoing) { if !(0 != context.shall_stop_ongoing) {
((*context).cb)( (context.cb)(
context, context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 0i32 < 1i32 { (if 0i32 < 1i32 {
@@ -169,15 +177,14 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
param = dc_loginparam_new(); param = dc_loginparam_new();
dc_loginparam_read( dc_loginparam_read(
param, param,
(*context).sql, &mut context.sql.lock().unwrap(),
b"\x00" as *const u8 as *const libc::c_char, b"\x00" as *const u8 as *const libc::c_char,
); );
if (*param).addr.is_null() { if (*param).addr.is_null() {
dc_log_error( dc_log_error(
context, context,
0i32, 0i32,
b"Please enter the email address.\x00" as *const u8 b"Please enter the email address.\x00" as *const u8 as *const libc::c_char,
as *const libc::c_char,
); );
} else { } else {
dc_trim((*param).addr); dc_trim((*param).addr);
@@ -185,10 +192,10 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
// the used oauth2 addr may differ, check this. // the used oauth2 addr may differ, check this.
// if dc_get_oauth2_addr() is not available in the oauth2 implementation, // if dc_get_oauth2_addr() is not available in the oauth2 implementation,
// just use the given one. // just use the given one.
if 0 != (*context).shall_stop_ongoing { if 0 != context.shall_stop_ongoing {
current_block = 2927484062889439186; current_block = 2927484062889439186;
} else { } else {
((*context).cb)( (context.cb)(
context, context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 10i32 < 1i32 { (if 10i32 < 1i32 {
@@ -206,15 +213,16 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
free((*param).addr as *mut libc::c_void); free((*param).addr as *mut libc::c_void);
(*param).addr = oauth2_addr; (*param).addr = oauth2_addr;
dc_sqlite3_set_config( dc_sqlite3_set_config(
(*context).sql, context,
&mut context.sql.lock().unwrap(),
b"addr\x00" as *const u8 as *const libc::c_char, b"addr\x00" as *const u8 as *const libc::c_char,
(*param).addr, (*param).addr,
); );
} }
if 0 != (*context).shall_stop_ongoing { if 0 != context.shall_stop_ongoing {
current_block = 2927484062889439186; current_block = 2927484062889439186;
} else { } else {
((*context).cb)( (context.cb)(
context, context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 20i32 < 1i32 { (if 20i32 < 1i32 {
@@ -242,8 +250,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
dc_log_error( dc_log_error(
context, context,
0i32, 0i32,
b"Bad email-address.\x00" as *const u8 b"Bad email-address.\x00" as *const u8 as *const libc::c_char,
as *const libc::c_char,
); );
} else { } else {
param_domain = param_domain.offset(1isize); param_domain = param_domain.offset(1isize);
@@ -251,8 +258,8 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
if (*param).mail_pw.is_null() { if (*param).mail_pw.is_null() {
(*param).mail_pw = dc_strdup(0 as *const libc::c_char) (*param).mail_pw = dc_strdup(0 as *const libc::c_char)
} }
if !(0 != (*context).shall_stop_ongoing) { if !(0 != context.shall_stop_ongoing) {
((*context).cb)( (context.cb)(
context, context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 200i32 < 1i32 { (if 200i32 < 1i32 {
@@ -261,8 +268,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
999i32 999i32
} else { } else {
200i32 200i32
}) }) as uintptr_t,
as uintptr_t,
0i32 as uintptr_t, 0i32 as uintptr_t,
); );
/* 2. Autoconfig /* 2. Autoconfig
@@ -293,10 +299,10 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
param_autoconfig = param_autoconfig =
moz_autoconfigure(context, url, param); moz_autoconfigure(context, url, param);
free(url as *mut libc::c_void); free(url as *mut libc::c_void);
if 0 != (*context).shall_stop_ongoing { if 0 != context.shall_stop_ongoing {
current_block = 2927484062889439186; current_block = 2927484062889439186;
} else { } else {
((*context).cb)( (context.cb)(
context, context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 300i32 < 1i32 { (if 300i32 < 1i32 {
@@ -328,14 +334,13 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
*const libc::c_char, *const libc::c_char,
param_domain, param_domain,
param_addr_urlencoded); param_addr_urlencoded);
param_autoconfig = moz_autoconfigure( param_autoconfig =
context, url_0, param, moz_autoconfigure(context, url_0, param);
);
free(url_0 as *mut libc::c_void); free(url_0 as *mut libc::c_void);
if 0 != (*context).shall_stop_ongoing { if 0 != context.shall_stop_ongoing {
current_block = 2927484062889439186; current_block = 2927484062889439186;
} else { } else {
((*context).cb)( (context.cb)(
context, context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 310i32 < 1i32 { (if 310i32 < 1i32 {
@@ -393,22 +398,16 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
outlk_autodiscover( outlk_autodiscover(
context, url_1, param, context, url_1, param,
); );
free( free(url_1 as *mut libc::c_void);
url_1 as *mut libc::c_void, if 0 != context.shall_stop_ongoing {
);
if 0 != (*context)
.shall_stop_ongoing
{
current_block = current_block =
2927484062889439186; 2927484062889439186;
break; break;
} }
((*context).cb)( (context.cb)(
context, context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 320i32 + i * 10i32 (if 320i32 + i * 10i32 < 1i32 {
< 1i32
{
1i32 1i32
} else if 320i32 + i * 10i32 } else if 320i32 + i * 10i32
> 999i32 > 999i32
@@ -438,19 +437,18 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
param_addr_urlencoded); param_addr_urlencoded);
param_autoconfig = param_autoconfig =
moz_autoconfigure( moz_autoconfigure(
context, url_2, context, url_2, param,
param,
); );
free(url_2 free(
as url_2 as *mut libc::c_void,
*mut libc::c_void); );
if 0 != (*context) if 0 != context
.shall_stop_ongoing .shall_stop_ongoing
{ {
current_block = current_block =
2927484062889439186; 2927484062889439186;
} else { } else {
((*context).cb)( (context.cb)(
context, context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 340i32 (if 340i32
@@ -472,8 +470,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
as as
uintptr_t uintptr_t
); );
current_block current_block =
=
10778260831612459202; 10778260831612459202;
} }
} else { } else {
@@ -495,23 +492,22 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
as as
*const libc::c_char, *const libc::c_char,
param_domain); param_domain);
param_autoconfig param_autoconfig =
= moz_autoconfigure(
moz_autoconfigure(context, context, url_3,
url_3, param,
param); );
free(url_3 free(url_3
as as
*mut libc::c_void); *mut libc::c_void);
if 0 if 0 != context
!= .shall_stop_ongoing
(*context).shall_stop_ongoing
{ {
current_block current_block
= =
2927484062889439186; 2927484062889439186;
} else { } else {
((*context).cb)(context, (context.cb)(context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 350i32 (if 350i32
< <
@@ -536,21 +532,16 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
5207889489643863322; 5207889489643863322;
} }
} else { } else {
current_block current_block =
=
5207889489643863322; 5207889489643863322;
} }
match current_block match current_block {
{ 2927484062889439186 => {
2927484062889439186
=>
{
} }
_ _ => {
=>
{
/* B. If we have no configuration yet, search configuration in Thunderbird's centeral database */ /* B. If we have no configuration yet, search configuration in Thunderbird's centeral database */
if param_autoconfig.is_null() if param_autoconfig
.is_null()
{ {
/* always SSL for Thunderbird's database */ /* always SSL for Thunderbird's database */
let mut url_4: let mut url_4:
@@ -571,13 +562,13 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
*mut libc::c_void); *mut libc::c_void);
if 0 if 0
!= !=
(*context).shall_stop_ongoing context.shall_stop_ongoing
{ {
current_block current_block
= =
2927484062889439186; 2927484062889439186;
} else { } else {
((*context).cb)(context, (context.cb)(context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 500i32 (if 500i32
< <
@@ -692,8 +683,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
} }
if (*param).mail_port == 0i32 { if (*param).mail_port == 0i32 {
(*param).mail_port = if 0 (*param).mail_port = if 0
!= (*param).server_flags != (*param).server_flags & (0x100i32 | 0x400i32)
& (0x100i32 | 0x400i32)
{ {
143i32 143i32
} else { } else {
@@ -716,8 +706,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
) == 0i32 ) == 0i32
{ {
memcpy( memcpy(
(*param).send_server (*param).send_server as *mut libc::c_void,
as *mut libc::c_void,
b"smtp\x00" as *const u8 b"smtp\x00" as *const u8
as *const libc::c_char as *const libc::c_char
as *const libc::c_void, as *const libc::c_void,
@@ -726,12 +715,11 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
} }
} }
if (*param).send_port == 0i32 { if (*param).send_port == 0i32 {
(*param).send_port = (*param).send_port = if 0
if 0 != (*param).server_flags & 0x10000i32 { != (*param).server_flags & 0x10000i32
587i32
} else if 0
!= (*param).server_flags & 0x40000i32
{ {
587i32
} else if 0 != (*param).server_flags & 0x40000i32 {
25i32 25i32
} else { } else {
465i32 465i32
@@ -740,8 +728,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
if (*param).send_user.is_null() if (*param).send_user.is_null()
&& !(*param).mail_user.is_null() && !(*param).mail_user.is_null()
{ {
(*param).send_user = (*param).send_user = dc_strdup((*param).mail_user)
dc_strdup((*param).mail_user)
} }
if (*param).send_pw.is_null() if (*param).send_pw.is_null()
&& !(*param).mail_pw.is_null() && !(*param).mail_pw.is_null()
@@ -797,12 +784,11 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
dc_log_error( dc_log_error(
context, context,
0i32, 0i32,
b"Account settings incomplete.\x00" b"Account settings incomplete.\x00" as *const u8
as *const u8
as *const libc::c_char, as *const libc::c_char,
); );
} else if !(0 != (*context).shall_stop_ongoing) { } else if !(0 != context.shall_stop_ongoing) {
((*context).cb)( (context.cb)(
context, context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 600i32 < 1i32 { (if 600i32 < 1i32 {
@@ -834,7 +820,8 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
); );
free(r_0 as *mut libc::c_void); free(r_0 as *mut libc::c_void);
if 0 != dc_imap_connect( if 0 != dc_imap_connect(
(*context).inbox, context,
&mut context.inbox.clone().lock().unwrap(),
param, param,
) { ) {
current_block = 14187386403465544025; current_block = 14187386403465544025;
@@ -845,11 +832,11 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
break; break;
} }
// probe STARTTLS/993 // probe STARTTLS/993
if 0 != (*context).shall_stop_ongoing { if 0 != context.shall_stop_ongoing {
current_block = 2927484062889439186; current_block = 2927484062889439186;
break; break;
} }
((*context).cb)( (context.cb)(
context, context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 650i32 + username_variation * 30i32 (if 650i32 + username_variation * 30i32
@@ -881,18 +868,19 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
); );
free(r_1 as *mut libc::c_void); free(r_1 as *mut libc::c_void);
if 0 != dc_imap_connect( if 0 != dc_imap_connect(
(*context).inbox, context,
&mut context.inbox.clone().lock().unwrap(),
param, param,
) { ) {
current_block = 14187386403465544025; current_block = 14187386403465544025;
break; break;
} }
// probe STARTTLS/143 // probe STARTTLS/143
if 0 != (*context).shall_stop_ongoing { if 0 != context.shall_stop_ongoing {
current_block = 2927484062889439186; current_block = 2927484062889439186;
break; break;
} }
((*context).cb)( (context.cb)(
context, context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 660i32 + username_variation * 30i32 (if 660i32 + username_variation * 30i32
@@ -922,7 +910,8 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
); );
free(r_2 as *mut libc::c_void); free(r_2 as *mut libc::c_void);
if 0 != dc_imap_connect( if 0 != dc_imap_connect(
(*context).inbox, context,
&mut context.inbox.clone().lock().unwrap(),
param, param,
) { ) {
current_block = 14187386403465544025; current_block = 14187386403465544025;
@@ -933,11 +922,11 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
break; break;
} }
// next probe round with only the localpart of the email-address as the loginname // next probe round with only the localpart of the email-address as the loginname
if 0 != (*context).shall_stop_ongoing { if 0 != context.shall_stop_ongoing {
current_block = 2927484062889439186; current_block = 2927484062889439186;
break; break;
} }
((*context).cb)( (context.cb)(
context, context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 670i32 + username_variation * 30i32 (if 670i32 + username_variation * 30i32
@@ -974,9 +963,8 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
2927484062889439186 => {} 2927484062889439186 => {}
_ => { _ => {
imap_connected_here = 1i32; imap_connected_here = 1i32;
if !(0 != (*context).shall_stop_ongoing) if !(0 != context.shall_stop_ongoing) {
{ (context.cb)(
((*context).cb)(
context, context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 800i32 < 1i32 { (if 800i32 < 1i32 {
@@ -991,39 +979,35 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
); );
/* try to connect to SMTP - if we did not got an autoconfig, the first try was SSL-465 and we do a second try with STARTTLS-587 */ /* try to connect to SMTP - if we did not got an autoconfig, the first try was SSL-465 and we do a second try with STARTTLS-587 */
if 0 == dc_smtp_connect( if 0 == dc_smtp_connect(
(*context).smtp, &mut context
.smtp
.clone()
.lock()
.unwrap(),
param, param,
) { ) {
if !param_autoconfig.is_null() { if !param_autoconfig.is_null() {
current_block = current_block =
2927484062889439186; 2927484062889439186;
} else if 0 } else if 0
!= (*context) != context.shall_stop_ongoing
.shall_stop_ongoing
{ {
current_block = current_block =
2927484062889439186; 2927484062889439186;
} else { } else {
((*context).cb)(context, (context.cb)(
context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 850i32 (if 850i32 < 1i32 {
<
1i32 1i32
{ } else if 850i32 > 999i32 {
1i32
} else if 850i32
>
999i32
{
999i32 999i32
} else { } else {
850i32 850i32
}) })
as as uintptr_t,
uintptr_t, 0i32 as uintptr_t,
0i32 );
as
uintptr_t);
(*param).server_flags &= (*param).server_flags &=
!(0x10000i32 !(0x10000i32
| 0x20000i32 | 0x20000i32
@@ -1031,32 +1015,34 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
(*param).server_flags |= (*param).server_flags |=
0x10000i32; 0x10000i32;
(*param).send_port = 587i32; (*param).send_port = 587i32;
let mut r_3: let mut r_3: *mut libc::c_char =
*mut libc::c_char = dc_loginparam_get_readable(
dc_loginparam_get_readable(param); param,
dc_log_info(context, );
dc_log_info(
context,
0i32, 0i32,
b"Trying: %s\x00" b"Trying: %s\x00"
as as *const u8
*const u8 as *const libc::c_char,
as r_3,
*const libc::c_char, );
r_3); free(r_3 as *mut libc::c_void);
free(r_3
as
*mut libc::c_void);
if 0 == dc_smtp_connect( if 0 == dc_smtp_connect(
(*context).smtp, &mut context
.smtp
.clone()
.lock()
.unwrap(),
param, param,
) { ) {
if 0 != (*context) if 0 != context
.shall_stop_ongoing .shall_stop_ongoing
{ {
current_block current_block =
=
2927484062889439186; 2927484062889439186;
} else { } else {
((*context).cb)(context, (context.cb)(context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 860i32 (if 860i32
< <
@@ -1076,18 +1062,15 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
0i32 0i32
as as
uintptr_t); uintptr_t);
(*param).server_flags
&=
!(0x10000i32
|
0x20000i32
|
0x40000i32);
(*param).server_flags
|=
0x10000i32;
(*param) (*param)
.send_port = .server_flags &=
!(0x10000i32
| 0x20000i32
| 0x40000i32);
(*param)
.server_flags |=
0x10000i32;
(*param).send_port =
25i32; 25i32;
let mut r_4: let mut r_4:
*mut libc::c_char = *mut libc::c_char =
@@ -1103,11 +1086,14 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
free(r_4 free(r_4
as as
*mut libc::c_void); *mut libc::c_void);
if 0 if 0 == dc_smtp_connect(
== &mut context
dc_smtp_connect((*context).smtp, .smtp
param) .clone()
{ .lock()
.unwrap(),
param,
) {
current_block current_block
= =
2927484062889439186; 2927484062889439186;
@@ -1123,18 +1109,17 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
} }
} }
} else { } else {
current_block = current_block = 5083741289379115417;
5083741289379115417;
} }
match current_block { match current_block {
2927484062889439186 => {} 2927484062889439186 => {}
_ => { _ => {
smtp_connected_here = 1i32; smtp_connected_here = 1i32;
if !(0 if !(0
!= (*context) != context
.shall_stop_ongoing) .shall_stop_ongoing)
{ {
((*context).cb)(context, (context.cb)(context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 900i32 (if 900i32
< <
@@ -1158,7 +1143,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
= =
if 0 if 0
!= !=
dc_sqlite3_get_config_int((*context).sql, dc_sqlite3_get_config_int(&mut context.sql.lock().unwrap(),
b"mvbox_watch\x00" b"mvbox_watch\x00"
as as
*const u8 *const u8
@@ -1168,7 +1153,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
|| ||
0 0
!= !=
dc_sqlite3_get_config_int((*context).sql, dc_sqlite3_get_config_int(&mut context.sql.lock().unwrap(),
b"mvbox_move\x00" b"mvbox_move\x00"
as as
*const u8 *const u8
@@ -1182,13 +1167,18 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
}; };
dc_configure_folders( dc_configure_folders(
context, context,
(*context).inbox, &mut context
.inbox
.clone()
.lock()
.unwrap(),
flags, flags,
); );
if !(0 != (*context) if !(0
!= context
.shall_stop_ongoing) .shall_stop_ongoing)
{ {
((*context).cb)(context, (context.cb)(context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 910i32 (if 910i32
< <
@@ -1209,24 +1199,23 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
as as
uintptr_t); uintptr_t);
dc_loginparam_write(param, dc_loginparam_write(param,
(*context).sql, &mut context.sql.lock().unwrap(),
b"configured_\x00" b"configured_\x00"
as as
*const u8 *const u8
as as
*const libc::c_char); *const libc::c_char);
dc_sqlite3_set_config_int((*context).sql, dc_sqlite3_set_config_int(&mut context.sql.lock().unwrap(),
b"configured\x00" b"configured\x00"
as as
*const u8 *const u8
as as
*const libc::c_char, *const libc::c_char,
1i32); 1i32);
if !(0 if !(0 != context
!= .shall_stop_ongoing)
(*context).shall_stop_ongoing)
{ {
((*context).cb)(context, (context.cb)(context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 920i32 (if 920i32
< <
@@ -1247,9 +1236,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
as as
uintptr_t); uintptr_t);
dc_ensure_secret_key_exists(context); dc_ensure_secret_key_exists(context);
success success = 1i32;
=
1i32;
dc_log_info(context, dc_log_info(context,
0i32, 0i32,
b"Configure completed.\x00" b"Configure completed.\x00"
@@ -1259,9 +1246,9 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
*const libc::c_char); *const libc::c_char);
if !(0 if !(0
!= !=
(*context).shall_stop_ongoing) context.shall_stop_ongoing)
{ {
((*context).cb)(context, (context.cb)(context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 940i32 (if 940i32
< <
@@ -1301,12 +1288,12 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
} }
} }
} }
}
if 0 != imap_connected_here { if 0 != imap_connected_here {
dc_imap_disconnect((*context).inbox); dc_imap_disconnect(context, &mut context.inbox.clone().lock().unwrap());
} }
if 0 != smtp_connected_here { if 0 != smtp_connected_here {
dc_smtp_disconnect((*context).smtp); dc_smtp_disconnect(&mut context.smtp.clone().lock().unwrap());
} }
dc_loginparam_unref(param); dc_loginparam_unref(param);
dc_loginparam_unref(param_autoconfig); dc_loginparam_unref(param_autoconfig);
@@ -1315,7 +1302,7 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
dc_free_ongoing(context); dc_free_ongoing(context);
} }
free(mvbox_folder as *mut libc::c_void); free(mvbox_folder as *mut libc::c_void);
((*context).cb)( (context.cb)(
context, context,
Event::CONFIGURE_PROGRESS, Event::CONFIGURE_PROGRESS,
(if 0 != success { 1000i32 } else { 0i32 }) as uintptr_t, (if 0 != success { 1000i32 } else { 0i32 }) as uintptr_t,
@@ -1324,29 +1311,26 @@ pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &dc_context_t, _job: *mut
} }
pub unsafe fn dc_free_ongoing(mut context: &dc_context_t) { pub unsafe fn dc_free_ongoing(mut context: &dc_context_t) {
if context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint { context.ongoing_running = 0i32;
return; context.shall_stop_ongoing = 1i32;
}
(*context).ongoing_running = 0i32;
(*context).shall_stop_ongoing = 1i32;
} }
pub unsafe fn dc_configure_folders( pub unsafe fn dc_configure_folders(
mut context: &dc_context_t, context: &dc_context_t,
mut imap: *mut dc_imap_t, imap: &mut dc_imap_t,
mut flags: libc::c_int, flags: libc::c_int,
) { ) {
let mut folder_list: *mut clist = 0 as *mut clist; let mut folder_list: *mut clist = 0 as *mut clist;
let mut iter: *mut clistiter = 0 as *mut clistiter; let mut iter: *mut clistiter = 0 as *mut clistiter;
let mut mvbox_folder: *mut libc::c_char = 0 as *mut libc::c_char; let mut mvbox_folder: *mut libc::c_char = 0 as *mut libc::c_char;
let mut sentbox_folder: *mut libc::c_char = 0 as *mut libc::c_char; let mut sentbox_folder: *mut libc::c_char = 0 as *mut libc::c_char;
let mut fallback_folder: *mut libc::c_char = 0 as *mut libc::c_char; let mut fallback_folder: *mut libc::c_char = 0 as *mut libc::c_char;
if !(imap.is_null() || (*imap).etpan.is_null()) { if !(*imap).etpan.is_null() {
dc_log_info( dc_log_info(
context, context,
0i32, 0i32,
b"Configuring IMAP-folders.\x00" as *const u8 as *const libc::c_char, b"Configuring IMAP-folders.\x00" as *const u8 as *const libc::c_char,
); );
folder_list = list_folders(imap); folder_list = list_folders(context, imap);
fallback_folder = dc_mprintf( fallback_folder = dc_mprintf(
b"INBOX%c%s\x00" as *const u8 as *const libc::c_char, b"INBOX%c%s\x00" as *const u8 as *const libc::c_char,
(*imap).imap_delimiter as libc::c_int, (*imap).imap_delimiter as libc::c_int,
@@ -1391,7 +1375,7 @@ pub unsafe fn dc_configure_folders(
(*imap).etpan, (*imap).etpan,
b"DeltaChat\x00" as *const u8 as *const libc::c_char, b"DeltaChat\x00" as *const u8 as *const libc::c_char,
); );
if 0 != dc_imap_is_error(imap, r) { if 0 != dc_imap_is_error(context, imap, r) {
dc_log_warning( dc_log_warning(
context, context,
0i32, 0i32,
@@ -1399,7 +1383,7 @@ pub unsafe fn dc_configure_folders(
as *const libc::c_char, as *const libc::c_char,
); );
r = mailimap_create((*imap).etpan, fallback_folder); r = mailimap_create((*imap).etpan, fallback_folder);
if 0 != dc_imap_is_error(imap, r) { if 0 != dc_imap_is_error(context, imap, r) {
dc_log_warning( dc_log_warning(
context, context,
0i32, 0i32,
@@ -1425,17 +1409,19 @@ pub unsafe fn dc_configure_folders(
mailimap_subscribe((*imap).etpan, mvbox_folder); mailimap_subscribe((*imap).etpan, mvbox_folder);
} }
dc_sqlite3_set_config_int( dc_sqlite3_set_config_int(
(*context).sql, &mut context.sql.lock().unwrap(),
b"folders_configured\x00" as *const u8 as *const libc::c_char, b"folders_configured\x00" as *const u8 as *const libc::c_char,
3i32, 3i32,
); );
dc_sqlite3_set_config( dc_sqlite3_set_config(
(*context).sql, context,
&mut context.sql.lock().unwrap(),
b"configured_mvbox_folder\x00" as *const u8 as *const libc::c_char, b"configured_mvbox_folder\x00" as *const u8 as *const libc::c_char,
mvbox_folder, mvbox_folder,
); );
dc_sqlite3_set_config( dc_sqlite3_set_config(
(*context).sql, context,
&mut context.sql.lock().unwrap(),
b"configured_sentbox_folder\x00" as *const u8 as *const libc::c_char, b"configured_sentbox_folder\x00" as *const u8 as *const libc::c_char,
sentbox_folder, sentbox_folder,
); );
@@ -1466,13 +1452,13 @@ unsafe fn free_folders(mut folders: *mut clist) {
clist_free(folders); clist_free(folders);
}; };
} }
unsafe fn list_folders(mut imap: *mut dc_imap_t) -> *mut clist { unsafe fn list_folders(context: &dc_context_t, imap: &mut dc_imap_t) -> *mut clist {
let mut imap_list: *mut clist = 0 as *mut clist; let mut imap_list: *mut clist = 0 as *mut clist;
let mut iter1: *mut clistiter = 0 as *mut clistiter; let mut iter1: *mut clistiter = 0 as *mut clistiter;
let mut ret_list: *mut clist = clist_new(); let mut ret_list: *mut clist = clist_new();
let mut r: libc::c_int = 0i32; let mut r: libc::c_int = 0i32;
let mut xlist_works: libc::c_int = 0i32; let mut xlist_works: libc::c_int = 0i32;
if !(imap.is_null() || (*imap).etpan.is_null()) { if !(*imap).etpan.is_null() {
if 0 != (*imap).has_xlist { if 0 != (*imap).has_xlist {
r = mailimap_xlist( r = mailimap_xlist(
(*imap).etpan, (*imap).etpan,
@@ -1488,16 +1474,16 @@ unsafe fn list_folders(mut imap: *mut dc_imap_t) -> *mut clist {
&mut imap_list, &mut imap_list,
) )
} }
if 0 != dc_imap_is_error(imap, r) || imap_list.is_null() { if 0 != dc_imap_is_error(context, imap, r) || imap_list.is_null() {
imap_list = 0 as *mut clist; imap_list = 0 as *mut clist;
dc_log_warning( dc_log_warning(
(*imap).context, context,
0i32, 0i32,
b"Cannot get folder list.\x00" as *const u8 as *const libc::c_char, b"Cannot get folder list.\x00" as *const u8 as *const libc::c_char,
); );
} else if (*imap_list).count <= 0i32 { } else if (*imap_list).count <= 0i32 {
dc_log_warning( dc_log_warning(
(*imap).context, context,
0i32, 0i32,
b"Folder list is empty.\x00" as *const u8 as *const libc::c_char, b"Folder list is empty.\x00" as *const u8 as *const libc::c_char,
); );
@@ -1869,7 +1855,7 @@ unsafe fn read_autoconf_file(
b"Testing %s ...\x00" as *const u8 as *const libc::c_char, b"Testing %s ...\x00" as *const u8 as *const libc::c_char,
url, url,
); );
filecontent = ((*context).cb)( filecontent = (context.cb)(
context, context,
Event::HTTP_GET, Event::HTTP_GET,
url as uintptr_t, url as uintptr_t,
@@ -1887,9 +1873,9 @@ unsafe fn read_autoconf_file(
return filecontent; return filecontent;
} }
unsafe fn outlk_autodiscover( unsafe fn outlk_autodiscover(
mut context: &dc_context_t, context: &dc_context_t,
mut url__: *const libc::c_char, url__: *const libc::c_char,
mut param_in: *const dc_loginparam_t, param_in: *const dc_loginparam_t,
) -> *mut dc_loginparam_t { ) -> *mut dc_loginparam_t {
let mut current_block: u64; let mut current_block: u64;
let mut xml_raw: *mut libc::c_char = 0 as *mut libc::c_char; let mut xml_raw: *mut libc::c_char = 0 as *mut libc::c_char;
@@ -2071,10 +2057,7 @@ unsafe fn outlk_autodiscover_starttag_cb(
(*outlk_ad).tag_config = 5i32 (*outlk_ad).tag_config = 5i32
}; };
} }
pub unsafe fn dc_alloc_ongoing(mut context: &dc_context_t) -> libc::c_int { pub unsafe fn dc_alloc_ongoing(context: &dc_context_t) -> libc::c_int {
if context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint {
return 0i32;
}
if 0 != dc_has_ongoing(context) { if 0 != dc_has_ongoing(context) {
dc_log_warning( dc_log_warning(
context, context,
@@ -2084,43 +2067,37 @@ pub unsafe fn dc_alloc_ongoing(mut context: &dc_context_t) -> libc::c_int {
); );
return 0i32; return 0i32;
} }
(*context).ongoing_running = 1i32; context.ongoing_running = 1i32;
(*context).shall_stop_ongoing = 0i32; context.shall_stop_ongoing = 0i32;
return 1i32; return 1i32;
} }
pub unsafe fn dc_connect_to_configured_imap( pub unsafe fn dc_connect_to_configured_imap(
mut context: &dc_context_t, context: &dc_context_t,
mut imap: *mut dc_imap_t, imap: &mut dc_imap_t,
) -> libc::c_int { ) -> libc::c_int {
let mut ret_connected: libc::c_int = 0i32; let mut ret_connected: libc::c_int = 0i32;
let mut param: *mut dc_loginparam_t = dc_loginparam_new(); let mut param: *mut dc_loginparam_t = dc_loginparam_new();
if context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint || imap.is_null() { if 0 != dc_imap_is_connected(imap) {
dc_log_warning(
(*imap).context,
0i32,
b"Cannot connect to IMAP: Bad parameters.\x00" as *const u8 as *const libc::c_char,
);
} else if 0 != dc_imap_is_connected(imap) {
ret_connected = 1i32 ret_connected = 1i32
} else if dc_sqlite3_get_config_int( } else if dc_sqlite3_get_config_int(
(*(*imap).context).sql, &mut context.sql.clone().lock().unwrap(),
b"configured\x00" as *const u8 as *const libc::c_char, b"configured\x00" as *const u8 as *const libc::c_char,
0i32, 0i32,
) == 0i32 ) == 0i32
{ {
dc_log_warning( dc_log_warning(
(*imap).context, context,
0i32, 0i32,
b"Not configured, cannot connect.\x00" as *const u8 as *const libc::c_char, b"Not configured, cannot connect.\x00" as *const u8 as *const libc::c_char,
); );
} else { } else {
dc_loginparam_read( dc_loginparam_read(
param, param,
(*(*imap).context).sql, &mut context.sql.clone().lock().unwrap(),
b"configured_\x00" as *const u8 as *const libc::c_char, b"configured_\x00" as *const u8 as *const libc::c_char,
); );
/*the trailing underscore is correct*/ /*the trailing underscore is correct*/
if !(0 == dc_imap_connect(imap, param)) { if !(0 == dc_imap_connect(context, imap, param)) {
ret_connected = 2i32 ret_connected = 2i32
} }
} }

View File

@@ -9,7 +9,6 @@ use crate::dc_e2ee::*;
use crate::dc_key::*; use crate::dc_key::*;
use crate::dc_log::*; use crate::dc_log::*;
use crate::dc_loginparam::*; use crate::dc_loginparam::*;
use crate::dc_pgp::*;
use crate::dc_sqlite3::*; use crate::dc_sqlite3::*;
use crate::dc_stock::*; use crate::dc_stock::*;
use crate::dc_strbuilder::*; use crate::dc_strbuilder::*;
@@ -19,9 +18,9 @@ use crate::x::*;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub struct dc_contact_t { pub struct dc_contact_t<'a> {
pub magic: uint32_t, pub magic: uint32_t,
pub context: *mut dc_context_t, pub context: &'a dc_context_t,
pub id: uint32_t, pub id: uint32_t,
pub name: *mut libc::c_char, pub name: *mut libc::c_char,
pub authname: *mut libc::c_char, pub authname: *mut libc::c_char,
@@ -30,12 +29,9 @@ pub struct dc_contact_t {
pub origin: libc::c_int, pub origin: libc::c_int,
} }
pub unsafe fn dc_marknoticed_contact(mut context: &dc_context_t, mut contact_id: uint32_t) { pub unsafe fn dc_marknoticed_contact(context: &dc_context_t, contact_id: uint32_t) {
if context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint {
return;
}
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare( let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"UPDATE msgs SET state=13 WHERE from_id=? AND state=10;\x00" as *const u8 b"UPDATE msgs SET state=13 WHERE from_id=? AND state=10;\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
); );
@@ -76,14 +72,10 @@ pub unsafe fn dc_lookup_contact_id_by_addr(
let mut addr_normalized: *mut libc::c_char = 0 as *mut libc::c_char; let mut addr_normalized: *mut libc::c_char = 0 as *mut libc::c_char;
let mut addr_self: *mut libc::c_char = 0 as *mut libc::c_char; let mut addr_self: *mut libc::c_char = 0 as *mut libc::c_char;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
if !(context.is_null() if !(addr.is_null() || *addr.offset(0isize) as libc::c_int == 0i32) {
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|| addr.is_null()
|| *addr.offset(0isize) as libc::c_int == 0i32)
{
addr_normalized = dc_addr_normalize(addr); addr_normalized = dc_addr_normalize(addr);
addr_self = dc_sqlite3_get_config( addr_self = dc_sqlite3_get_config(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"configured_addr\x00" as *const u8 as *const libc::c_char, b"configured_addr\x00" as *const u8 as *const libc::c_char,
b"\x00" as *const u8 as *const libc::c_char, b"\x00" as *const u8 as *const libc::c_char,
); );
@@ -91,7 +83,7 @@ pub unsafe fn dc_lookup_contact_id_by_addr(
contact_id = 1i32 contact_id = 1i32
} else { } else {
stmt = stmt =
dc_sqlite3_prepare((*context).sql, dc_sqlite3_prepare(&mut context.sql.clone().lock().unwrap(),
b"SELECT id FROM contacts WHERE addr=?1 COLLATE NOCASE AND id>?2 AND origin>=?3 AND blocked=0;\x00" b"SELECT id FROM contacts WHERE addr=?1 COLLATE NOCASE AND id>?2 AND origin>=?3 AND blocked=0;\x00"
as *const u8 as *const libc::c_char); as *const u8 as *const libc::c_char);
sqlite3_bind_text( sqlite3_bind_text(
@@ -137,11 +129,7 @@ pub unsafe fn dc_create_contact(
let mut contact_id: uint32_t = 0i32 as uint32_t; let mut contact_id: uint32_t = 0i32 as uint32_t;
let mut sth_modified: libc::c_int = 0i32; let mut sth_modified: libc::c_int = 0i32;
let mut blocked: libc::c_int = 0i32; let mut blocked: libc::c_int = 0i32;
if !(context.is_null() if !(addr.is_null() || *addr.offset(0isize) as libc::c_int == 0i32) {
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|| addr.is_null()
|| *addr.offset(0isize) as libc::c_int == 0i32)
{
contact_id = dc_add_or_lookup_contact(context, name, addr, 0x4000000i32, &mut sth_modified); contact_id = dc_add_or_lookup_contact(context, name, addr, 0x4000000i32, &mut sth_modified);
blocked = dc_is_contact_blocked(context, contact_id); blocked = dc_is_contact_blocked(context, contact_id);
((*context).cb)( ((*context).cb)(
@@ -169,15 +157,15 @@ pub unsafe fn dc_block_contact(
let mut send_event: libc::c_int = 0i32; let mut send_event: libc::c_int = 0i32;
let mut contact: *mut dc_contact_t = dc_contact_new(context); let mut contact: *mut dc_contact_t = dc_contact_new(context);
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
if !(context.is_null() if !(contact_id <= 9i32 as libc::c_uint) {
|| (*context).magic != 0x11a11807i32 as libc::c_uint if 0 != dc_contact_load_from_db(
|| contact_id <= 9i32 as libc::c_uint) contact,
{ &mut context.sql.clone().lock().unwrap(),
if 0 != dc_contact_load_from_db(contact, (*context).sql, contact_id) contact_id,
&& (*contact).blocked != new_blocking ) && (*contact).blocked != new_blocking
{ {
stmt = dc_sqlite3_prepare( stmt = dc_sqlite3_prepare(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"UPDATE contacts SET blocked=? WHERE id=?;\x00" as *const u8 b"UPDATE contacts SET blocked=? WHERE id=?;\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
); );
@@ -189,7 +177,7 @@ pub unsafe fn dc_block_contact(
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
stmt = 0 as *mut sqlite3_stmt; stmt = 0 as *mut sqlite3_stmt;
stmt = stmt =
dc_sqlite3_prepare((*context).sql, dc_sqlite3_prepare(&mut context.sql.clone().lock().unwrap(),
b"UPDATE chats SET blocked=? WHERE type=? AND id IN (SELECT chat_id FROM chats_contacts WHERE contact_id=?);\x00" b"UPDATE chats SET blocked=? WHERE type=? AND id IN (SELECT chat_id FROM chats_contacts WHERE contact_id=?);\x00"
as *const u8 as as *const u8 as
*const libc::c_char); *const libc::c_char);
@@ -243,7 +231,7 @@ pub unsafe fn dc_block_contact(
* dc_create_contact() or dc_add_address_book()) * dc_create_contact() or dc_add_address_book())
* only affect the given-name. * only affect the given-name.
*/ */
pub unsafe fn dc_contact_new(mut context: &dc_context_t) -> *mut dc_contact_t { pub unsafe fn dc_contact_new<'a>(context: &'a dc_context_t) -> *mut dc_contact_t<'a> {
let mut contact: *mut dc_contact_t = 0 as *mut dc_contact_t; let mut contact: *mut dc_contact_t = 0 as *mut dc_contact_t;
contact = calloc(1, ::std::mem::size_of::<dc_contact_t>()) as *mut dc_contact_t; contact = calloc(1, ::std::mem::size_of::<dc_contact_t>()) as *mut dc_contact_t;
if contact.is_null() { if contact.is_null() {
@@ -253,7 +241,7 @@ pub unsafe fn dc_contact_new(mut context: &dc_context_t) -> *mut dc_contact_t {
(*contact).context = context; (*contact).context = context;
return contact; return contact;
} }
pub unsafe fn dc_contact_unref(mut contact: *mut dc_contact_t) { pub unsafe fn dc_contact_unref(contact: *mut dc_contact_t) {
if contact.is_null() || (*contact).magic != 0xc047ac7i32 as libc::c_uint { if contact.is_null() || (*contact).magic != 0xc047ac7i32 as libc::c_uint {
return; return;
} }
@@ -296,13 +284,13 @@ pub unsafe fn dc_contact_empty(mut contact: *mut dc_contact_t) {
/* contacts with at least this origin value start a new "normal" chat, defaults to off */ /* contacts with at least this origin value start a new "normal" chat, defaults to off */
pub unsafe fn dc_contact_load_from_db( pub unsafe fn dc_contact_load_from_db(
mut contact: *mut dc_contact_t, mut contact: *mut dc_contact_t,
mut sql: *mut dc_sqlite3_t, mut sql: &mut dc_sqlite3_t,
mut contact_id: uint32_t, mut contact_id: uint32_t,
) -> libc::c_int { ) -> libc::c_int {
let mut current_block: u64; let mut current_block: u64;
let mut success: libc::c_int = 0i32; let mut success: libc::c_int = 0i32;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
if !(contact.is_null() || (*contact).magic != 0xc047ac7i32 as libc::c_uint || sql.is_null()) { if !(contact.is_null() || (*contact).magic != 0xc047ac7i32 as libc::c_uint) {
dc_contact_empty(contact); dc_contact_empty(contact);
if contact_id == 1i32 as libc::c_uint { if contact_id == 1i32 as libc::c_uint {
(*contact).id = contact_id; (*contact).id = contact_id;
@@ -346,7 +334,11 @@ pub unsafe fn dc_is_contact_blocked(
) -> libc::c_int { ) -> libc::c_int {
let mut is_blocked: libc::c_int = 0i32; let mut is_blocked: libc::c_int = 0i32;
let mut contact: *mut dc_contact_t = dc_contact_new(context); let mut contact: *mut dc_contact_t = dc_contact_new(context);
if 0 != dc_contact_load_from_db(contact, (*context).sql, contact_id) { if 0 != dc_contact_load_from_db(
contact,
&mut context.sql.clone().lock().unwrap(),
contact_id,
) {
if 0 != (*contact).blocked { if 0 != (*contact).blocked {
is_blocked = 1i32 is_blocked = 1i32
} }
@@ -374,14 +366,10 @@ pub unsafe fn dc_add_or_lookup_contact(
sth_modified = &mut dummy sth_modified = &mut dummy
} }
*sth_modified = 0i32; *sth_modified = 0i32;
if !(context.is_null() if !(addr__.is_null() || origin <= 0i32) {
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|| addr__.is_null()
|| origin <= 0i32)
{
addr = dc_addr_normalize(addr__); addr = dc_addr_normalize(addr__);
addr_self = dc_sqlite3_get_config( addr_self = dc_sqlite3_get_config(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"configured_addr\x00" as *const u8 as *const libc::c_char, b"configured_addr\x00" as *const u8 as *const libc::c_char,
b"\x00" as *const u8 as *const libc::c_char, b"\x00" as *const u8 as *const libc::c_char,
); );
@@ -401,7 +389,7 @@ pub unsafe fn dc_add_or_lookup_contact(
); );
} else { } else {
stmt = stmt =
dc_sqlite3_prepare((*context).sql, dc_sqlite3_prepare(&mut context.sql.clone().lock().unwrap(),
b"SELECT id, name, addr, origin, authname FROM contacts WHERE addr=? COLLATE NOCASE;\x00" b"SELECT id, name, addr, origin, authname FROM contacts WHERE addr=? COLLATE NOCASE;\x00"
as *const u8 as *const libc::c_char); as *const u8 as *const libc::c_char);
sqlite3_bind_text(stmt, 1i32, addr as *const libc::c_char, -1i32, None); sqlite3_bind_text(stmt, 1i32, addr as *const libc::c_char, -1i32, None);
@@ -438,7 +426,7 @@ pub unsafe fn dc_add_or_lookup_contact(
|| origin > row_origin || origin > row_origin
{ {
stmt = dc_sqlite3_prepare( stmt = dc_sqlite3_prepare(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"UPDATE contacts SET name=?, addr=?, origin=?, authname=? WHERE id=?;\x00" b"UPDATE contacts SET name=?, addr=?, origin=?, authname=? WHERE id=?;\x00"
as *const u8 as *const libc::c_char, as *const u8 as *const libc::c_char,
); );
@@ -482,7 +470,7 @@ pub unsafe fn dc_add_or_lookup_contact(
stmt = 0 as *mut sqlite3_stmt; stmt = 0 as *mut sqlite3_stmt;
if 0 != update_name { if 0 != update_name {
stmt = stmt =
dc_sqlite3_prepare((*context).sql, dc_sqlite3_prepare(&mut context.sql.clone().lock().unwrap(),
b"UPDATE chats SET name=? WHERE type=? AND id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?);\x00" b"UPDATE chats SET name=? WHERE type=? AND id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?);\x00"
as *const u8 as as *const u8 as
*const libc::c_char); *const libc::c_char);
@@ -497,7 +485,7 @@ pub unsafe fn dc_add_or_lookup_contact(
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
stmt = 0 as *mut sqlite3_stmt; stmt = 0 as *mut sqlite3_stmt;
stmt = dc_sqlite3_prepare( stmt = dc_sqlite3_prepare(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"INSERT INTO contacts (name, addr, origin) VALUES(?, ?, ?);\x00" as *const u8 b"INSERT INTO contacts (name, addr, origin) VALUES(?, ?, ?);\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
); );
@@ -516,7 +504,7 @@ pub unsafe fn dc_add_or_lookup_contact(
sqlite3_bind_int(stmt, 3i32, origin); sqlite3_bind_int(stmt, 3i32, origin);
if sqlite3_step(stmt) == 101i32 { if sqlite3_step(stmt) == 101i32 {
row_id = dc_sqlite3_get_rowid( row_id = dc_sqlite3_get_rowid(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"contacts\x00" as *const u8 as *const libc::c_char, b"contacts\x00" as *const u8 as *const libc::c_char,
b"addr\x00" as *const u8 as *const libc::c_char, b"addr\x00" as *const u8 as *const libc::c_char,
addr, addr,
@@ -549,13 +537,9 @@ pub unsafe fn dc_add_address_book(
let mut iCnt: size_t = 0i32 as size_t; let mut iCnt: size_t = 0i32 as size_t;
let mut sth_modified: libc::c_int = 0i32; let mut sth_modified: libc::c_int = 0i32;
let mut modify_cnt: libc::c_int = 0i32; let mut modify_cnt: libc::c_int = 0i32;
if !(context.is_null() if !(adr_book.is_null()) {
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|| adr_book.is_null())
{
lines = dc_split_into_lines(adr_book); lines = dc_split_into_lines(adr_book);
if !lines.is_null() { if !lines.is_null() {
dc_sqlite3_begin_transaction((*context).sql);
iCnt = carray_count(lines) as size_t; iCnt = carray_count(lines) as size_t;
i = 0i32 as size_t; i = 0i32 as size_t;
while i.wrapping_add(1) < iCnt { while i.wrapping_add(1) < iCnt {
@@ -570,7 +554,6 @@ pub unsafe fn dc_add_address_book(
} }
i = (i as libc::c_ulong).wrapping_add(2i32 as libc::c_ulong) as size_t as size_t i = (i as libc::c_ulong).wrapping_add(2i32 as libc::c_ulong) as size_t as size_t
} }
dc_sqlite3_commit((*context).sql);
if 0 != modify_cnt { if 0 != modify_cnt {
((*context).cb)( ((*context).cb)(
context, context,
@@ -628,12 +611,12 @@ pub unsafe fn dc_get_contacts(
let mut self_name: *mut libc::c_char = 0 as *mut libc::c_char; let mut self_name: *mut libc::c_char = 0 as *mut libc::c_char;
let mut self_name2: *mut libc::c_char = 0 as *mut libc::c_char; let mut self_name2: *mut libc::c_char = 0 as *mut libc::c_char;
let mut add_self: libc::c_int = 0i32; let mut add_self: libc::c_int = 0i32;
let mut ret: *mut dc_array_t = dc_array_new(context, 100i32 as size_t); let mut ret: *mut dc_array_t = dc_array_new(100i32 as size_t);
let mut s3strLikeCmd: *mut libc::c_char = 0 as *mut libc::c_char; let mut s3strLikeCmd: *mut libc::c_char = 0 as *mut libc::c_char;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
self_addr = dc_sqlite3_get_config( self_addr = dc_sqlite3_get_config(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"configured_addr\x00" as *const u8 as *const libc::c_char, b"configured_addr\x00" as *const u8 as *const libc::c_char,
b"\x00" as *const u8 as *const libc::c_char, b"\x00" as *const u8 as *const libc::c_char,
); );
@@ -650,7 +633,7 @@ pub unsafe fn dc_get_contacts(
current_block = 7597307149762829253; current_block = 7597307149762829253;
} else { } else {
stmt = stmt =
dc_sqlite3_prepare((*context).sql, dc_sqlite3_prepare(&mut context.sql.clone().lock().unwrap(),
b"SELECT c.id FROM contacts c LEFT JOIN acpeerstates ps ON c.addr=ps.addr WHERE c.addr!=?1 AND c.id>?2 AND c.origin>=?3 AND c.blocked=0 AND (c.name LIKE ?4 OR c.addr LIKE ?5) AND (1=?6 OR LENGTH(ps.verified_key_fingerprint)!=0) ORDER BY LOWER(c.name||c.addr),c.id;\x00" b"SELECT c.id FROM contacts c LEFT JOIN acpeerstates ps ON c.addr=ps.addr WHERE c.addr!=?1 AND c.id>?2 AND c.origin>=?3 AND c.blocked=0 AND (c.name LIKE ?4 OR c.addr LIKE ?5) AND (1=?6 OR LENGTH(ps.verified_key_fingerprint)!=0) ORDER BY LOWER(c.name||c.addr),c.id;\x00"
as *const u8 as as *const u8 as
*const libc::c_char); *const libc::c_char);
@@ -669,7 +652,7 @@ pub unsafe fn dc_get_contacts(
}, },
); );
self_name = dc_sqlite3_get_config( self_name = dc_sqlite3_get_config(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"displayname\x00" as *const u8 as *const libc::c_char, b"displayname\x00" as *const u8 as *const libc::c_char,
b"\x00" as *const u8 as *const libc::c_char, b"\x00" as *const u8 as *const libc::c_char,
); );
@@ -685,7 +668,7 @@ pub unsafe fn dc_get_contacts(
} }
} else { } else {
stmt = stmt =
dc_sqlite3_prepare((*context).sql, dc_sqlite3_prepare(&mut context.sql.clone().lock().unwrap(),
b"SELECT id FROM contacts WHERE addr!=?1 AND id>?2 AND origin>=?3 AND blocked=0 ORDER BY LOWER(name||addr),id;\x00" b"SELECT id FROM contacts WHERE addr!=?1 AND id>?2 AND origin>=?3 AND blocked=0 ORDER BY LOWER(name||addr),id;\x00"
as *const u8 as *const libc::c_char); as *const u8 as *const libc::c_char);
sqlite3_bind_text(stmt, 1i32, self_addr, -1i32, None); sqlite3_bind_text(stmt, 1i32, self_addr, -1i32, None);
@@ -705,7 +688,7 @@ pub unsafe fn dc_get_contacts(
} }
} }
} }
}
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
sqlite3_free(s3strLikeCmd as *mut libc::c_void); sqlite3_free(s3strLikeCmd as *mut libc::c_void);
free(self_addr as *mut libc::c_void); free(self_addr as *mut libc::c_void);
@@ -713,12 +696,13 @@ pub unsafe fn dc_get_contacts(
free(self_name2 as *mut libc::c_void); free(self_name2 as *mut libc::c_void);
return ret; return ret;
} }
pub unsafe fn dc_get_blocked_cnt(mut context: &dc_context_t) -> libc::c_int {
pub unsafe fn dc_get_blocked_cnt(context: &dc_context_t) -> libc::c_int {
let mut ret: libc::c_int = 0i32; let mut ret: libc::c_int = 0i32;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
stmt = dc_sqlite3_prepare( stmt = dc_sqlite3_prepare(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"SELECT COUNT(*) FROM contacts WHERE id>? AND blocked!=0\x00" as *const u8 b"SELECT COUNT(*) FROM contacts WHERE id>? AND blocked!=0\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
); );
@@ -726,16 +710,17 @@ pub unsafe fn dc_get_blocked_cnt(mut context: &dc_context_t) -> libc::c_int {
if !(sqlite3_step(stmt) != 100i32) { if !(sqlite3_step(stmt) != 100i32) {
ret = sqlite3_column_int(stmt, 0i32) ret = sqlite3_column_int(stmt, 0i32)
} }
}
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return ret; return ret;
} }
pub unsafe fn dc_get_blocked_contacts(mut context: &dc_context_t) -> *mut dc_array_t { pub unsafe fn dc_get_blocked_contacts(mut context: &dc_context_t) -> *mut dc_array_t {
let mut ret: *mut dc_array_t = dc_array_new(context, 100i32 as size_t); let mut ret: *mut dc_array_t = dc_array_new(100i32 as size_t);
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
stmt = dc_sqlite3_prepare( stmt = dc_sqlite3_prepare(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"SELECT id FROM contacts WHERE id>? AND blocked!=0 ORDER BY LOWER(name||addr),id;\x00" b"SELECT id FROM contacts WHERE id>? AND blocked!=0 ORDER BY LOWER(name||addr),id;\x00"
as *const u8 as *const libc::c_char, as *const u8 as *const libc::c_char,
); );
@@ -743,7 +728,7 @@ pub unsafe fn dc_get_blocked_contacts(mut context: &dc_context_t) -> *mut dc_arr
while sqlite3_step(stmt) == 100i32 { while sqlite3_step(stmt) == 100i32 {
dc_array_add_id(ret, sqlite3_column_int(stmt, 0i32) as uint32_t); dc_array_add_id(ret, sqlite3_column_int(stmt, 0i32) as uint32_t);
} }
}
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return ret; return ret;
} }
@@ -765,7 +750,7 @@ pub unsafe fn dc_get_contact_encrinfo(
let mut fingerprint_other_verified: *mut libc::c_char = 0 as *mut libc::c_char; let mut fingerprint_other_verified: *mut libc::c_char = 0 as *mut libc::c_char;
let mut fingerprint_other_unverified: *mut libc::c_char = 0 as *mut libc::c_char; let mut fingerprint_other_unverified: *mut libc::c_char = 0 as *mut libc::c_char;
let mut p: *mut libc::c_char = 0 as *mut libc::c_char; let mut p: *mut libc::c_char = 0 as *mut libc::c_char;
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
ret = dc_strbuilder_t { ret = dc_strbuilder_t {
buf: 0 as *mut libc::c_char, buf: 0 as *mut libc::c_char,
allocated: 0, allocated: 0,
@@ -773,14 +758,28 @@ pub unsafe fn dc_get_contact_encrinfo(
eos: 0 as *mut libc::c_char, eos: 0 as *mut libc::c_char,
}; };
dc_strbuilder_init(&mut ret, 0i32); dc_strbuilder_init(&mut ret, 0i32);
if !(0 == dc_contact_load_from_db(contact, (*context).sql, contact_id)) { if !(0
dc_apeerstate_load_by_addr(peerstate, (*context).sql, (*contact).addr); == dc_contact_load_from_db(
contact,
&mut context.sql.clone().lock().unwrap(),
contact_id,
))
{
dc_apeerstate_load_by_addr(
peerstate,
&mut context.sql.clone().lock().unwrap(),
(*contact).addr,
);
dc_loginparam_read( dc_loginparam_read(
loginparam, loginparam,
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"configured_\x00" as *const u8 as *const libc::c_char, b"configured_\x00" as *const u8 as *const libc::c_char,
); );
dc_key_load_self_public(self_key, (*loginparam).addr, (*context).sql); dc_key_load_self_public(
self_key,
(*loginparam).addr,
&mut context.sql.clone().lock().unwrap(),
);
if !dc_apeerstate_peek_key(peerstate, 0i32).is_null() { if !dc_apeerstate_peek_key(peerstate, 0i32).is_null() {
p = dc_stock_str( p = dc_stock_str(
context, context,
@@ -794,7 +793,11 @@ pub unsafe fn dc_get_contact_encrinfo(
free(p as *mut libc::c_void); free(p as *mut libc::c_void);
if (*self_key).binary.is_null() { if (*self_key).binary.is_null() {
dc_ensure_secret_key_exists(context); dc_ensure_secret_key_exists(context);
dc_key_load_self_public(self_key, (*loginparam).addr, (*context).sql); dc_key_load_self_public(
self_key,
(*loginparam).addr,
&mut context.sql.clone().lock().unwrap(),
);
} }
dc_strbuilder_cat(&mut ret, b" \x00" as *const u8 as *const libc::c_char); dc_strbuilder_cat(&mut ret, b" \x00" as *const u8 as *const libc::c_char);
p = dc_stock_str(context, 30i32); p = dc_stock_str(context, 30i32);
@@ -845,7 +848,7 @@ pub unsafe fn dc_get_contact_encrinfo(
free(p as *mut libc::c_void); free(p as *mut libc::c_void);
} }
} }
}
dc_apeerstate_unref(peerstate); dc_apeerstate_unref(peerstate);
dc_contact_unref(contact); dc_contact_unref(contact);
dc_loginparam_unref(loginparam); dc_loginparam_unref(loginparam);
@@ -895,12 +898,9 @@ pub unsafe fn dc_delete_contact(
) -> libc::c_int { ) -> libc::c_int {
let mut success: libc::c_int = 0i32; let mut success: libc::c_int = 0i32;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
if !(context.is_null() if !contact_id <= 9i32 as libc::c_uint {
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|| contact_id <= 9i32 as libc::c_uint)
{
stmt = dc_sqlite3_prepare( stmt = dc_sqlite3_prepare(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"SELECT COUNT(*) FROM chats_contacts WHERE contact_id=?;\x00" as *const u8 b"SELECT COUNT(*) FROM chats_contacts WHERE contact_id=?;\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
); );
@@ -909,7 +909,7 @@ pub unsafe fn dc_delete_contact(
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
stmt = 0 as *mut sqlite3_stmt; stmt = 0 as *mut sqlite3_stmt;
stmt = dc_sqlite3_prepare( stmt = dc_sqlite3_prepare(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"SELECT COUNT(*) FROM msgs WHERE from_id=? OR to_id=?;\x00" as *const u8 b"SELECT COUNT(*) FROM msgs WHERE from_id=? OR to_id=?;\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
); );
@@ -919,7 +919,7 @@ pub unsafe fn dc_delete_contact(
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
stmt = 0 as *mut sqlite3_stmt; stmt = 0 as *mut sqlite3_stmt;
stmt = dc_sqlite3_prepare( stmt = dc_sqlite3_prepare(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"DELETE FROM contacts WHERE id=?;\x00" as *const u8 as *const libc::c_char, b"DELETE FROM contacts WHERE id=?;\x00" as *const u8 as *const libc::c_char,
); );
sqlite3_bind_int(stmt, 1i32, contact_id as libc::c_int); sqlite3_bind_int(stmt, 1i32, contact_id as libc::c_int);
@@ -943,7 +943,7 @@ pub unsafe fn dc_get_contact(
mut contact_id: uint32_t, mut contact_id: uint32_t,
) -> *mut dc_contact_t { ) -> *mut dc_contact_t {
let mut ret: *mut dc_contact_t = dc_contact_new(context); let mut ret: *mut dc_contact_t = dc_contact_new(context);
if 0 == dc_contact_load_from_db(ret, (*context).sql, contact_id) { if 0 == dc_contact_load_from_db(ret, &mut context.sql.clone().lock().unwrap(), contact_id) {
dc_contact_unref(ret); dc_contact_unref(ret);
ret = 0 as *mut dc_contact_t ret = 0 as *mut dc_contact_t
} }
@@ -1044,9 +1044,9 @@ pub unsafe fn dc_contact_is_blocked(mut contact: *const dc_contact_t) -> libc::c
pub unsafe fn dc_contact_is_verified(mut contact: *mut dc_contact_t) -> libc::c_int { pub unsafe fn dc_contact_is_verified(mut contact: *mut dc_contact_t) -> libc::c_int {
return dc_contact_is_verified_ex(contact, 0 as *const dc_apeerstate_t); return dc_contact_is_verified_ex(contact, 0 as *const dc_apeerstate_t);
} }
pub unsafe fn dc_contact_is_verified_ex( pub unsafe fn dc_contact_is_verified_ex<'a>(
mut contact: *mut dc_contact_t, contact: *mut dc_contact_t<'a>,
mut peerstate: *const dc_apeerstate_t, peerstate: *const dc_apeerstate_t<'a>,
) -> libc::c_int { ) -> libc::c_int {
let mut current_block: u64; let mut current_block: u64;
let mut contact_verified: libc::c_int = 0i32; let mut contact_verified: libc::c_int = 0i32;
@@ -1060,7 +1060,7 @@ pub unsafe fn dc_contact_is_verified_ex(
peerstate_to_delete = dc_apeerstate_new((*contact).context); peerstate_to_delete = dc_apeerstate_new((*contact).context);
if 0 == dc_apeerstate_load_by_addr( if 0 == dc_apeerstate_load_by_addr(
peerstate_to_delete, peerstate_to_delete,
(*(*contact).context).sql, &mut (*contact).context.sql.clone().lock().unwrap(),
(*contact).addr, (*contact).addr,
) { ) {
current_block = 8667923638376902112; current_block = 8667923638376902112;
@@ -1105,10 +1105,10 @@ pub unsafe fn dc_addr_equals_self(
let mut ret: libc::c_int = 0i32; let mut ret: libc::c_int = 0i32;
let mut normalized_addr: *mut libc::c_char = 0 as *mut libc::c_char; let mut normalized_addr: *mut libc::c_char = 0 as *mut libc::c_char;
let mut self_addr: *mut libc::c_char = 0 as *mut libc::c_char; let mut self_addr: *mut libc::c_char = 0 as *mut libc::c_char;
if !(context.is_null() || addr.is_null()) { if !addr.is_null() {
normalized_addr = dc_addr_normalize(addr); normalized_addr = dc_addr_normalize(addr);
self_addr = dc_sqlite3_get_config( self_addr = dc_sqlite3_get_config(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"configured_addr\x00" as *const u8 as *const libc::c_char, b"configured_addr\x00" as *const u8 as *const libc::c_char,
0 as *const libc::c_char, 0 as *const libc::c_char,
); );
@@ -1132,7 +1132,11 @@ pub unsafe fn dc_addr_equals_contact(
let mut addr_are_equal: libc::c_int = 0i32; let mut addr_are_equal: libc::c_int = 0i32;
if !addr.is_null() { if !addr.is_null() {
let mut contact: *mut dc_contact_t = dc_contact_new(context); let mut contact: *mut dc_contact_t = dc_contact_new(context);
if 0 != dc_contact_load_from_db(contact, (*context).sql, contact_id) { if 0 != dc_contact_load_from_db(
contact,
&mut context.sql.clone().lock().unwrap(),
contact_id,
) {
if !(*contact).addr.is_null() { if !(*contact).addr.is_null() {
let mut normalized_addr: *mut libc::c_char = dc_addr_normalize(addr); let mut normalized_addr: *mut libc::c_char = dc_addr_normalize(addr);
if strcasecmp((*contact).addr, normalized_addr) == 0i32 { if strcasecmp((*contact).addr, normalized_addr) == 0i32 {
@@ -1149,12 +1153,9 @@ pub unsafe fn dc_addr_equals_contact(
pub unsafe fn dc_get_real_contact_cnt(mut context: &dc_context_t) -> size_t { pub unsafe fn dc_get_real_contact_cnt(mut context: &dc_context_t) -> size_t {
let mut ret: size_t = 0i32 as size_t; let mut ret: size_t = 0i32 as size_t;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
if !(context.is_null() if !context.sql.clone().lock().unwrap().cobj.is_null() {
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|| (*(*context).sql).cobj.is_null())
{
stmt = dc_sqlite3_prepare( stmt = dc_sqlite3_prepare(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"SELECT COUNT(*) FROM contacts WHERE id>?;\x00" as *const u8 as *const libc::c_char, b"SELECT COUNT(*) FROM contacts WHERE id>?;\x00" as *const u8 as *const libc::c_char,
); );
sqlite3_bind_int(stmt, 1i32, 9i32); sqlite3_bind_int(stmt, 1i32, 9i32);
@@ -1177,7 +1178,13 @@ pub unsafe fn dc_get_contact_origin(
} }
let mut contact: *mut dc_contact_t = dc_contact_new(context); let mut contact: *mut dc_contact_t = dc_contact_new(context);
*ret_blocked = 0i32; *ret_blocked = 0i32;
if !(0 == dc_contact_load_from_db(contact, (*context).sql, contact_id)) { if !(0
== dc_contact_load_from_db(
contact,
&mut context.sql.clone().lock().unwrap(),
contact_id,
))
{
/* we could optimize this by loading only the needed fields */ /* we could optimize this by loading only the needed fields */
if 0 != (*contact).blocked { if 0 != (*contact).blocked {
*ret_blocked = 1i32 *ret_blocked = 1i32
@@ -1194,13 +1201,9 @@ pub unsafe fn dc_real_contact_exists(
) -> libc::c_int { ) -> libc::c_int {
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
let mut ret: libc::c_int = 0i32; let mut ret: libc::c_int = 0i32;
if !(context.is_null() if !(context.sql.clone().lock().unwrap().cobj.is_null() || contact_id <= 9i32 as libc::c_uint) {
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|| (*(*context).sql).cobj.is_null()
|| contact_id <= 9i32 as libc::c_uint)
{
stmt = dc_sqlite3_prepare( stmt = dc_sqlite3_prepare(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"SELECT id FROM contacts WHERE id=?;\x00" as *const u8 as *const libc::c_char, b"SELECT id FROM contacts WHERE id=?;\x00" as *const u8 as *const libc::c_char,
); );
sqlite3_bind_int(stmt, 1i32, contact_id as libc::c_int); sqlite3_bind_int(stmt, 1i32, contact_id as libc::c_int);
@@ -1216,11 +1219,8 @@ pub unsafe fn dc_scaleup_contact_origin(
mut contact_id: uint32_t, mut contact_id: uint32_t,
mut origin: libc::c_int, mut origin: libc::c_int,
) { ) {
if context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint {
return;
}
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare( let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"UPDATE contacts SET origin=? WHERE id=? AND origin<?;\x00" as *const u8 b"UPDATE contacts SET origin=? WHERE id=? AND origin<?;\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
); );

View File

@@ -15,7 +15,6 @@ use crate::dc_loginparam::*;
use crate::dc_lot::dc_lot_t; use crate::dc_lot::dc_lot_t;
use crate::dc_move::*; use crate::dc_move::*;
use crate::dc_msg::*; use crate::dc_msg::*;
use crate::dc_pgp::*;
use crate::dc_receive_imf::*; use crate::dc_receive_imf::*;
use crate::dc_smtp::*; use crate::dc_smtp::*;
use crate::dc_sqlite3::*; use crate::dc_sqlite3::*;
@@ -30,13 +29,13 @@ pub struct dc_context_t {
pub userdata: *mut libc::c_void, pub userdata: *mut libc::c_void,
pub dbfile: *mut libc::c_char, pub dbfile: *mut libc::c_char,
pub blobdir: *mut libc::c_char, pub blobdir: *mut libc::c_char,
pub sql: dc_sqlite3_t, pub sql: Arc<Mutex<dc_sqlite3_t>>,
pub inbox: dc_imap_t, pub inbox: Arc<Mutex<dc_imap_t>>,
pub perform_inbox_jobs_needed: Arc<RwLock<i32>>, pub perform_inbox_jobs_needed: Arc<RwLock<i32>>,
pub probe_imap_network: Arc<RwLock<i32>>, pub probe_imap_network: Arc<RwLock<i32>>,
pub sentbox_thread: dc_jobthread_t, pub sentbox_thread: dc_jobthread_t,
pub mvbox_thread: dc_jobthread_t, pub mvbox_thread: dc_jobthread_t,
pub smtp: dc_smtp_t, pub smtp: Arc<Mutex<dc_smtp_t>>,
pub smtpidle: Arc<(Mutex<bool>, Condvar)>, pub smtpidle: Arc<(Mutex<bool>, Condvar)>,
pub smtp_suspended: Arc<RwLock<i32>>, pub smtp_suspended: Arc<RwLock<i32>>,
pub smtp_doing_jobs: Arc<RwLock<i32>>, pub smtp_doing_jobs: Arc<RwLock<i32>>,
@@ -79,21 +78,21 @@ pub fn dc_context_new(
dc_context_t { dc_context_t {
blobdir: std::ptr::null_mut(), blobdir: std::ptr::null_mut(),
dbfile: std::ptr::null_mut(), dbfile: std::ptr::null_mut(),
inbox: unsafe { inbox: Arc::new(Mutex::new(unsafe {
dc_imap_new( dc_imap_new(
Some(cb_get_config), Some(cb_get_config),
Some(cb_set_config), Some(cb_set_config),
Some(cb_precheck_imf), Some(cb_precheck_imf),
Some(cb_receive_imf), Some(cb_receive_imf),
) )
}, })),
userdata, userdata,
cb, cb,
os_name: dc_strdup_keep_null(os_name), os_name: dc_strdup_keep_null(os_name),
ongoing_running: 0, ongoing_running: 0,
shall_stop_ongoing: 1, shall_stop_ongoing: 1,
sql: dc_sqlite3_new(), sql: Arc::new(Mutex::new(dc_sqlite3_new())),
smtp: dc_smtp_new(), smtp: Arc::new(Mutex::new(dc_smtp_new())),
smtpidle: Arc::new((Mutex::new(false), Condvar::new())), smtpidle: Arc::new((Mutex::new(false), Condvar::new())),
smtp_suspended: Arc::new(RwLock::new(0)), smtp_suspended: Arc::new(RwLock::new(0)),
smtp_doing_jobs: Arc::new(RwLock::new(0)), smtp_doing_jobs: Arc::new(RwLock::new(0)),
@@ -135,7 +134,7 @@ pub fn dc_context_new(
} }
unsafe fn cb_receive_imf( unsafe fn cb_receive_imf(
context: &dc_context, context: &dc_context_t,
imf_raw_not_terminated: *const libc::c_char, imf_raw_not_terminated: *const libc::c_char,
imf_raw_bytes: size_t, imf_raw_bytes: size_t,
server_folder: *const libc::c_char, server_folder: *const libc::c_char,
@@ -212,7 +211,12 @@ unsafe fn cb_set_config(
key: *const libc::c_char, key: *const libc::c_char,
value: *const libc::c_char, value: *const libc::c_char,
) { ) {
dc_sqlite3_set_config(&context.sql, key, value); dc_sqlite3_set_config(
context,
&mut context.sql.clone().lock().unwrap(),
key,
value,
);
} }
/* * /* *
* The following three callback are given to dc_imap_new() to read/write configuration * The following three callback are given to dc_imap_new() to read/write configuration
@@ -222,22 +226,28 @@ unsafe fn cb_set_config(
* @private @memberof dc_context_t * @private @memberof dc_context_t
*/ */
unsafe fn cb_get_config( unsafe fn cb_get_config(
context: &dc_context, context: &dc_context_t,
key: *const libc::c_char, key: *const libc::c_char,
def: *const libc::c_char, def: *const libc::c_char,
) -> *mut libc::c_char { ) -> *mut libc::c_char {
dc_sqlite3_get_config(context.sql, key, def) dc_sqlite3_get_config(&mut context.sql.clone().lock().unwrap(), key, def)
} }
pub unsafe fn dc_context_unref(context: &mut dc_context_t) { pub unsafe fn dc_context_unref(context: &mut dc_context_t) {
if 0 != dc_is_open(context) { if 0 != dc_is_open(context) {
dc_close(context); dc_close(context);
} }
dc_imap_unref(&mut context.inbox); dc_imap_unref(context, &mut context.inbox.clone().lock().unwrap());
dc_imap_unref(&mut context.sentbox_thread.imap); dc_imap_unref(
dc_imap_unref(&mut context.mvbox_thread.imap); context,
dc_smtp_unref(&mut context.smtp); &mut context.sentbox_thread.imap.clone().lock().unwrap(),
dc_sqlite3_unref(&mut context.sql); );
dc_imap_unref(
context,
&mut context.mvbox_thread.imap.clone().lock().unwrap(),
);
dc_smtp_unref(&mut context.smtp.clone().lock().unwrap());
dc_sqlite3_unref(context, &mut context.sql.clone().lock().unwrap());
dc_jobthread_exit(&mut context.sentbox_thread); dc_jobthread_exit(&mut context.sentbox_thread);
dc_jobthread_exit(&mut context.mvbox_thread); dc_jobthread_exit(&mut context.mvbox_thread);
@@ -246,13 +256,19 @@ pub unsafe fn dc_context_unref(context: &mut dc_context_t) {
} }
pub unsafe fn dc_close(context: &mut dc_context_t) { pub unsafe fn dc_close(context: &mut dc_context_t) {
dc_imap_disconnect(&mut context.inbox); dc_imap_disconnect(context, &mut context.inbox.clone().lock().unwrap());
dc_imap_disconnect(&mut context.sentbox_thread.imap); dc_imap_disconnect(
dc_imap_disconnect(&mut context.mvbox_thread.imap); context,
dc_smtp_disconnect(&mut context.smtp); &mut context.sentbox_thread.imap.clone().lock().unwrap(),
);
dc_imap_disconnect(
context,
&mut context.mvbox_thread.imap.clone().lock().unwrap(),
);
dc_smtp_disconnect(&mut context.smtp.clone().lock().unwrap());
if 0 != dc_sqlite3_is_open(context.sql) { if 0 != dc_sqlite3_is_open(&mut context.sql.clone().lock().unwrap()) {
dc_sqlite3_close(context.sql); dc_sqlite3_close(context, &mut context.sql.clone().lock().unwrap());
} }
free(context.dbfile as *mut libc::c_void); free(context.dbfile as *mut libc::c_void);
context.dbfile = 0 as *mut libc::c_char; context.dbfile = 0 as *mut libc::c_char;
@@ -261,11 +277,11 @@ pub unsafe fn dc_close(context: &mut dc_context_t) {
} }
pub unsafe fn dc_is_open(context: &dc_context_t) -> libc::c_int { pub unsafe fn dc_is_open(context: &dc_context_t) -> libc::c_int {
dc_sqlite3_is_open(context.sql) dc_sqlite3_is_open(&mut context.sql.clone().lock().unwrap())
} }
pub unsafe fn dc_get_userdata(context: &mut dc_context_t) -> *mut libc::c_void { pub unsafe fn dc_get_userdata(context: &mut dc_context_t) -> *mut libc::c_void {
&mut context.userdata as *mut _ context.userdata as *mut _
} }
pub unsafe fn dc_open( pub unsafe fn dc_open(
@@ -288,7 +304,14 @@ pub unsafe fn dc_open(
dc_create_folder(context, context.blobdir); dc_create_folder(context, context.blobdir);
} }
// Create/open sqlite database, this may already use the blobdir // Create/open sqlite database, this may already use the blobdir
if !(0 == dc_sqlite3_open(&mut context.sql, dbfile, 0i32)) { if !(0
== dc_sqlite3_open(
context,
&mut context.sql.clone().lock().unwrap(),
dbfile,
0i32,
))
{
success = 1i32 success = 1i32
} }
} }
@@ -316,25 +339,46 @@ pub unsafe fn dc_set_config(
if strcmp(key, b"selfavatar\x00" as *const u8 as *const libc::c_char) == 0 && !value.is_null() { if strcmp(key, b"selfavatar\x00" as *const u8 as *const libc::c_char) == 0 && !value.is_null() {
rel_path = dc_strdup(value); rel_path = dc_strdup(value);
if !(0 == dc_make_rel_and_copy(context, &mut rel_path)) { if !(0 == dc_make_rel_and_copy(context, &mut rel_path)) {
ret = dc_sqlite3_set_config(context.sql, key, rel_path) ret = dc_sqlite3_set_config(
context,
&mut context.sql.clone().lock().unwrap(),
key,
rel_path,
)
} }
} else if strcmp(key, b"inbox_watch\x00" as *const u8 as *const libc::c_char) == 0 { } else if strcmp(key, b"inbox_watch\x00" as *const u8 as *const libc::c_char) == 0 {
ret = dc_sqlite3_set_config(&context.sql, key, value); ret = dc_sqlite3_set_config(
context,
&mut context.sql.clone().lock().unwrap(),
key,
value,
);
dc_interrupt_imap_idle(context); dc_interrupt_imap_idle(context);
} else if strcmp( } else if strcmp(
key, key,
b"sentbox_watch\x00" as *const u8 as *const libc::c_char, b"sentbox_watch\x00" as *const u8 as *const libc::c_char,
) == 0 ) == 0
{ {
ret = dc_sqlite3_set_config(&context.sql, key, value); ret = dc_sqlite3_set_config(
context,
&mut context.sql.clone().lock().unwrap(),
key,
value,
);
dc_interrupt_sentbox_idle(context); dc_interrupt_sentbox_idle(context);
} else if strcmp(key, b"mvbox_watch\x00" as *const u8 as *const libc::c_char) == 0 { } else if strcmp(key, b"mvbox_watch\x00" as *const u8 as *const libc::c_char) == 0 {
ret = dc_sqlite3_set_config(&context.sql, key, value); ret = dc_sqlite3_set_config(
context,
&mut context.sql.clone().lock().unwrap(),
key,
value,
);
dc_interrupt_mvbox_idle(context); dc_interrupt_mvbox_idle(context);
} else if strcmp(key, b"selfstatus\x00" as *const u8 as *const libc::c_char) == 0 { } else if strcmp(key, b"selfstatus\x00" as *const u8 as *const libc::c_char) == 0 {
let mut def = dc_stock_str(context, 13); let mut def = dc_stock_str(context, 13);
ret = dc_sqlite3_set_config( ret = dc_sqlite3_set_config(
context.sql, context,
&mut context.sql.clone().lock().unwrap(),
key, key,
if value.is_null() || strcmp(value, def) == 0 { if value.is_null() || strcmp(value, def) == 0 {
0 as *const libc::c_char 0 as *const libc::c_char
@@ -344,7 +388,12 @@ pub unsafe fn dc_set_config(
); );
free(def as *mut libc::c_void); free(def as *mut libc::c_void);
} else { } else {
ret = dc_sqlite3_set_config(&context.sql, key, value); ret = dc_sqlite3_set_config(
context,
&mut context.sql.clone().lock().unwrap(),
key,
value,
);
} }
free(rel_path as *mut libc::c_void); free(rel_path as *mut libc::c_void);
ret ret
@@ -420,14 +469,21 @@ pub unsafe fn dc_get_config(context: &dc_context_t, key: *const libc::c_char) ->
} }
if strcmp(key, b"selfavatar\x00" as *const u8 as *const libc::c_char) == 0 { if strcmp(key, b"selfavatar\x00" as *const u8 as *const libc::c_char) == 0 {
let mut rel_path: *mut libc::c_char = let mut rel_path: *mut libc::c_char = dc_sqlite3_get_config(
dc_sqlite3_get_config(context.sql, key, 0 as *const libc::c_char); &mut context.sql.clone().lock().unwrap(),
key,
0 as *const libc::c_char,
);
if !rel_path.is_null() { if !rel_path.is_null() {
value = dc_get_abs_path(context, rel_path); value = dc_get_abs_path(context, rel_path);
free(rel_path as *mut libc::c_void); free(rel_path as *mut libc::c_void);
} }
} else { } else {
value = dc_sqlite3_get_config(context.sql, key, 0 as *const libc::c_char) value = dc_sqlite3_get_config(
&mut context.sql.clone().lock().unwrap(),
key,
0 as *const libc::c_char,
)
} }
if value.is_null() { if value.is_null() {
@@ -578,20 +634,20 @@ pub unsafe fn dc_get_info(context: &dc_context_t) -> *mut libc::c_char {
eos: 0 as *mut libc::c_char, eos: 0 as *mut libc::c_char,
}; };
dc_strbuilder_init(&mut ret, 0); dc_strbuilder_init(&mut ret, 0);
if context.is_null() || context.magic != 0x11a11807 as libc::c_uint {
return dc_strdup(b"ErrBadPtr\x00" as *const u8 as *const libc::c_char);
}
l = dc_loginparam_new(); l = dc_loginparam_new();
l2 = dc_loginparam_new(); l2 = dc_loginparam_new();
dc_loginparam_read(l, context.sql, b"\x00" as *const u8 as *const libc::c_char); dc_loginparam_read(
l,
&mut context.sql.clone().lock().unwrap(),
b"\x00" as *const u8 as *const libc::c_char,
);
dc_loginparam_read( dc_loginparam_read(
l2, l2,
context.sql, &mut context.sql.clone().lock().unwrap(),
b"configured_\x00" as *const u8 as *const libc::c_char, b"configured_\x00" as *const u8 as *const libc::c_char,
); );
displayname = dc_sqlite3_get_config( displayname = dc_sqlite3_get_config(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"displayname\x00" as *const u8 as *const libc::c_char, b"displayname\x00" as *const u8 as *const libc::c_char,
0 as *const libc::c_char, 0 as *const libc::c_char,
); );
@@ -600,40 +656,44 @@ pub unsafe fn dc_get_info(context: &dc_context_t) -> *mut libc::c_char {
deaddrop_msgs = dc_get_deaddrop_msg_cnt(context) as libc::c_int; deaddrop_msgs = dc_get_deaddrop_msg_cnt(context) as libc::c_int;
contacts = dc_get_real_contact_cnt(context) as libc::c_int; contacts = dc_get_real_contact_cnt(context) as libc::c_int;
is_configured = dc_sqlite3_get_config_int( is_configured = dc_sqlite3_get_config_int(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"configured\x00" as *const u8 as *const libc::c_char, b"configured\x00" as *const u8 as *const libc::c_char,
0, 0,
); );
dbversion = dc_sqlite3_get_config_int( dbversion = dc_sqlite3_get_config_int(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"dbversion\x00" as *const u8 as *const libc::c_char, b"dbversion\x00" as *const u8 as *const libc::c_char,
0, 0,
); );
e2ee_enabled = dc_sqlite3_get_config_int( e2ee_enabled = dc_sqlite3_get_config_int(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"e2ee_enabled\x00" as *const u8 as *const libc::c_char, b"e2ee_enabled\x00" as *const u8 as *const libc::c_char,
1, 1,
); );
mdns_enabled = dc_sqlite3_get_config_int( mdns_enabled = dc_sqlite3_get_config_int(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"mdns_enabled\x00" as *const u8 as *const libc::c_char, b"mdns_enabled\x00" as *const u8 as *const libc::c_char,
1, 1,
); );
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare( let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"SELECT COUNT(*) FROM keypairs;\x00" as *const u8 as *const libc::c_char, b"SELECT COUNT(*) FROM keypairs;\x00" as *const u8 as *const libc::c_char,
); );
sqlite3_step(stmt); sqlite3_step(stmt);
prv_key_cnt = sqlite3_column_int(stmt, 0); prv_key_cnt = sqlite3_column_int(stmt, 0);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
stmt = dc_sqlite3_prepare( stmt = dc_sqlite3_prepare(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"SELECT COUNT(*) FROM acpeerstates;\x00" as *const u8 as *const libc::c_char, b"SELECT COUNT(*) FROM acpeerstates;\x00" as *const u8 as *const libc::c_char,
); );
sqlite3_step(stmt); sqlite3_step(stmt);
pub_key_cnt = sqlite3_column_int(stmt, 0); pub_key_cnt = sqlite3_column_int(stmt, 0);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
if 0 != dc_key_load_self_public(self_public, (*l2).addr, context.sql) { if 0 != dc_key_load_self_public(
self_public,
(*l2).addr,
&mut context.sql.clone().lock().unwrap(),
) {
fingerprint_str = dc_key_get_fingerprint(self_public) fingerprint_str = dc_key_get_fingerprint(self_public)
} else { } else {
fingerprint_str = dc_strdup(b"<Not yet calculated>\x00" as *const u8 as *const libc::c_char) fingerprint_str = dc_strdup(b"<Not yet calculated>\x00" as *const u8 as *const libc::c_char)
@@ -641,37 +701,37 @@ pub unsafe fn dc_get_info(context: &dc_context_t) -> *mut libc::c_char {
l_readable_str = dc_loginparam_get_readable(l); l_readable_str = dc_loginparam_get_readable(l);
l2_readable_str = dc_loginparam_get_readable(l2); l2_readable_str = dc_loginparam_get_readable(l2);
inbox_watch = dc_sqlite3_get_config_int( inbox_watch = dc_sqlite3_get_config_int(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"inbox_watch\x00" as *const u8 as *const libc::c_char, b"inbox_watch\x00" as *const u8 as *const libc::c_char,
1, 1,
); );
sentbox_watch = dc_sqlite3_get_config_int( sentbox_watch = dc_sqlite3_get_config_int(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"sentbox_watch\x00" as *const u8 as *const libc::c_char, b"sentbox_watch\x00" as *const u8 as *const libc::c_char,
1, 1,
); );
mvbox_watch = dc_sqlite3_get_config_int( mvbox_watch = dc_sqlite3_get_config_int(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"mvbox_watch\x00" as *const u8 as *const libc::c_char, b"mvbox_watch\x00" as *const u8 as *const libc::c_char,
1, 1,
); );
mvbox_move = dc_sqlite3_get_config_int( mvbox_move = dc_sqlite3_get_config_int(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"mvbox_move\x00" as *const u8 as *const libc::c_char, b"mvbox_move\x00" as *const u8 as *const libc::c_char,
1, 1,
); );
folders_configured = dc_sqlite3_get_config_int( folders_configured = dc_sqlite3_get_config_int(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"folders_configured\x00" as *const u8 as *const libc::c_char, b"folders_configured\x00" as *const u8 as *const libc::c_char,
0, 0,
); );
configured_sentbox_folder = dc_sqlite3_get_config( configured_sentbox_folder = dc_sqlite3_get_config(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"configured_sentbox_folder\x00" as *const u8 as *const libc::c_char, b"configured_sentbox_folder\x00" as *const u8 as *const libc::c_char,
b"<unset>\x00" as *const u8 as *const libc::c_char, b"<unset>\x00" as *const u8 as *const libc::c_char,
); );
configured_mvbox_folder = dc_sqlite3_get_config( configured_mvbox_folder = dc_sqlite3_get_config(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"configured_mvbox_folder\x00" as *const u8 as *const libc::c_char, b"configured_mvbox_folder\x00" as *const u8 as *const libc::c_char,
b"<unset>\x00" as *const u8 as *const libc::c_char, b"<unset>\x00" as *const u8 as *const libc::c_char,
); );
@@ -779,11 +839,11 @@ pub unsafe fn dc_get_version_str() -> *mut libc::c_char {
pub unsafe fn dc_get_fresh_msgs(context: &dc_context_t) -> *mut dc_array_t { pub unsafe fn dc_get_fresh_msgs(context: &dc_context_t) -> *mut dc_array_t {
let mut show_deaddrop = 0; let mut show_deaddrop = 0;
let mut ret = dc_array_new(context, 128 as size_t); let mut ret = dc_array_new(128 as size_t);
let mut stmt = 0 as *mut sqlite3_stmt; let mut stmt = 0 as *mut sqlite3_stmt;
if !ret.is_null() { if !ret.is_null() {
stmt = dc_sqlite3_prepare( stmt = dc_sqlite3_prepare(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"SELECT m.id FROM msgs m LEFT JOIN contacts ct \ b"SELECT m.id FROM msgs m LEFT JOIN contacts ct \
ON m.from_id=ct.id LEFT JOIN chats c ON m.chat_id=c.id WHERE m.state=? \ ON m.from_id=ct.id LEFT JOIN chats c ON m.chat_id=c.id WHERE m.state=? \
AND m.hidden=0 \ AND m.hidden=0 \
@@ -809,7 +869,7 @@ pub unsafe fn dc_search_msgs(
query: *const libc::c_char, query: *const libc::c_char,
) -> *mut dc_array_t { ) -> *mut dc_array_t {
let mut success = 0; let mut success = 0;
let mut ret = dc_array_new(context, 100 as size_t); let mut ret = dc_array_new(100 as size_t);
let mut strLikeInText = 0 as *mut libc::c_char; let mut strLikeInText = 0 as *mut libc::c_char;
let mut strLikeBeg = 0 as *mut libc::c_char; let mut strLikeBeg = 0 as *mut libc::c_char;
let mut real_query = 0 as *mut libc::c_char; let mut real_query = 0 as *mut libc::c_char;
@@ -828,7 +888,7 @@ pub unsafe fn dc_search_msgs(
strLikeBeg = dc_mprintf(b"%s%%\x00" as *const u8 as *const libc::c_char, real_query); strLikeBeg = dc_mprintf(b"%s%%\x00" as *const u8 as *const libc::c_char, real_query);
if 0 != chat_id { if 0 != chat_id {
stmt = dc_sqlite3_prepare( stmt = dc_sqlite3_prepare(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"SELECT m.id, m.timestamp FROM msgs m LEFT JOIN contacts ct ON m.from_id=ct.id WHERE m.chat_id=? \ b"SELECT m.id, m.timestamp FROM msgs m LEFT JOIN contacts ct ON m.from_id=ct.id WHERE m.chat_id=? \
AND m.hidden=0 \ AND m.hidden=0 \
AND ct.blocked=0 AND (txt LIKE ? OR ct.name LIKE ?) ORDER BY m.timestamp,m.id;\x00" AND ct.blocked=0 AND (txt LIKE ? OR ct.name LIKE ?) ORDER BY m.timestamp,m.id;\x00"
@@ -840,7 +900,7 @@ pub unsafe fn dc_search_msgs(
} else { } else {
let mut show_deaddrop = 0; let mut show_deaddrop = 0;
stmt = dc_sqlite3_prepare( stmt = dc_sqlite3_prepare(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"SELECT m.id, m.timestamp FROM msgs m LEFT JOIN contacts ct ON m.from_id=ct.id \ b"SELECT m.id, m.timestamp FROM msgs m LEFT JOIN contacts ct ON m.from_id=ct.id \
LEFT JOIN chats c ON m.chat_id=c.id WHERE m.chat_id>9 AND m.hidden=0 \ LEFT JOIN chats c ON m.chat_id=c.id WHERE m.chat_id>9 AND m.hidden=0 \
AND (c.blocked=0 OR c.blocked=?) \ AND (c.blocked=0 OR c.blocked=?) \
@@ -897,7 +957,7 @@ pub unsafe fn dc_is_sentbox(
folder_name: *const libc::c_char, folder_name: *const libc::c_char,
) -> libc::c_int { ) -> libc::c_int {
let mut sentbox_name = dc_sqlite3_get_config( let mut sentbox_name = dc_sqlite3_get_config(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"configured_sentbox_folder\x00" as *const u8 as *const libc::c_char, b"configured_sentbox_folder\x00" as *const u8 as *const libc::c_char,
0 as *const libc::c_char, 0 as *const libc::c_char,
); );
@@ -915,7 +975,7 @@ pub unsafe fn dc_is_sentbox(
pub unsafe fn dc_is_mvbox(context: &dc_context_t, folder_name: *const libc::c_char) -> libc::c_int { pub unsafe fn dc_is_mvbox(context: &dc_context_t, folder_name: *const libc::c_char) -> libc::c_int {
let mut mvbox_name = dc_sqlite3_get_config( let mut mvbox_name = dc_sqlite3_get_config(
context.sql, &mut context.sql.clone().lock().unwrap(),
b"configured_mvbox_folder\x00" as *const u8 as *const libc::c_char, b"configured_mvbox_folder\x00" as *const u8 as *const libc::c_char,
0 as *const libc::c_char, 0 as *const libc::c_char,
); );

View File

@@ -54,7 +54,7 @@ pub unsafe fn dc_e2ee_encrypt(
let mut plain: *mut MMAPString = mmap_string_new(b"\x00" as *const u8 as *const libc::c_char); let mut plain: *mut MMAPString = mmap_string_new(b"\x00" as *const u8 as *const libc::c_char);
let mut ctext: *mut libc::c_char = 0 as *mut libc::c_char; let mut ctext: *mut libc::c_char = 0 as *mut libc::c_char;
let mut ctext_bytes: size_t = 0i32 as size_t; let mut ctext_bytes: size_t = 0i32 as size_t;
let mut peerstates: &dc_array_t = dc_array_new(0 as *mut dc_context_t, 10i32 as size_t); let mut peerstates = dc_array_new(10i32 as size_t);
if !helper.is_null() { if !helper.is_null() {
memset( memset(
helper as *mut libc::c_void, helper as *mut libc::c_void,
@@ -62,9 +62,7 @@ pub unsafe fn dc_e2ee_encrypt(
::std::mem::size_of::<dc_e2ee_helper_t>(), ::std::mem::size_of::<dc_e2ee_helper_t>(),
); );
} }
if !(context.is_null() if !(recipients_addr.is_null()
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|| recipients_addr.is_null()
|| in_out_message.is_null() || in_out_message.is_null()
|| !(*in_out_message).mm_parent.is_null() || !(*in_out_message).mm_parent.is_null()
|| autocryptheader.is_null() || autocryptheader.is_null()
@@ -76,14 +74,14 @@ pub unsafe fn dc_e2ee_encrypt(
/* libEtPan's pgp_encrypt_mime() takes the parent as the new root. We just expect the root as being given to this function. */ /* libEtPan's pgp_encrypt_mime() takes the parent as the new root. We just expect the root as being given to this function. */
(*autocryptheader).prefer_encrypt = 0i32; (*autocryptheader).prefer_encrypt = 0i32;
if 0 != dc_sqlite3_get_config_int( if 0 != dc_sqlite3_get_config_int(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"e2ee_enabled\x00" as *const u8 as *const libc::c_char, b"e2ee_enabled\x00" as *const u8 as *const libc::c_char,
1i32, 1i32,
) { ) {
(*autocryptheader).prefer_encrypt = 1i32 (*autocryptheader).prefer_encrypt = 1i32
} }
(*autocryptheader).addr = dc_sqlite3_get_config( (*autocryptheader).addr = dc_sqlite3_get_config(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"configured_addr\x00" as *const u8 as *const libc::c_char, b"configured_addr\x00" as *const u8 as *const libc::c_char,
0 as *const libc::c_char, 0 as *const libc::c_char,
); );
@@ -113,7 +111,7 @@ pub unsafe fn dc_e2ee_encrypt(
if !(strcasecmp(recipient_addr, (*autocryptheader).addr) == 0i32) { if !(strcasecmp(recipient_addr, (*autocryptheader).addr) == 0i32) {
if 0 != dc_apeerstate_load_by_addr( if 0 != dc_apeerstate_load_by_addr(
peerstate, peerstate,
(*context).sql, &mut context.sql.clone().lock().unwrap(),
recipient_addr, recipient_addr,
) && { ) && {
key_to_use = dc_apeerstate_peek_key(peerstate, min_verified); key_to_use = dc_apeerstate_peek_key(peerstate, min_verified);
@@ -141,7 +139,7 @@ pub unsafe fn dc_e2ee_encrypt(
if 0 == dc_key_load_self_private( if 0 == dc_key_load_self_private(
sign_key, sign_key,
(*autocryptheader).addr, (*autocryptheader).addr,
(*context).sql, &mut context.sql.clone().lock().unwrap(),
) { ) {
do_encrypt = 0i32 do_encrypt = 0i32
} }
@@ -516,11 +514,12 @@ unsafe fn load_or_generate_self_public_key(
let mut key_created: libc::c_int = 0i32; let mut key_created: libc::c_int = 0i32;
let mut success: libc::c_int = 0i32; let mut success: libc::c_int = 0i32;
let mut key_creation_here: libc::c_int = 0i32; let mut key_creation_here: libc::c_int = 0i32;
if !(context.is_null() if !public_key.is_null() {
|| (*context).magic != 0x11a11807i32 as libc::c_uint if 0 == dc_key_load_self_public(
|| public_key.is_null()) public_key,
{ self_addr,
if 0 == dc_key_load_self_public(public_key, self_addr, (*context).sql) { &mut context.sql.clone().lock().unwrap(),
) {
/* create the keypair - this may take a moment, however, as this is in a thread, this is no big deal */ /* create the keypair - this may take a moment, however, as this is in a thread, this is no big deal */
if 0 != s_in_key_creation { if 0 != s_in_key_creation {
current_block = 10496152961502316708; current_block = 10496152961502316708;
@@ -579,7 +578,7 @@ unsafe fn load_or_generate_self_public_key(
private_key, private_key,
self_addr, self_addr,
1i32, 1i32,
(*context).sql, &mut context.sql.clone().lock().unwrap(),
) )
{ {
/*set default*/ /*set default*/
@@ -643,12 +642,7 @@ pub unsafe fn dc_e2ee_decrypt(
::std::mem::size_of::<dc_e2ee_helper_t>(), ::std::mem::size_of::<dc_e2ee_helper_t>(),
); );
} }
if !(context.is_null() if !(in_out_message.is_null() || helper.is_null() || imffields.is_null()) {
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|| in_out_message.is_null()
|| helper.is_null()
|| imffields.is_null())
{
if !imffields.is_null() { if !imffields.is_null() {
let mut field: *mut mailimf_field = let mut field: *mut mailimf_field =
mailimf_find_field(imffields, MAILIMF_FIELD_FROM as libc::c_int); mailimf_find_field(imffields, MAILIMF_FIELD_FROM as libc::c_int);
@@ -676,24 +670,36 @@ pub unsafe fn dc_e2ee_decrypt(
} }
} }
if message_time > 0i32 as libc::c_long && !from.is_null() { if message_time > 0i32 as libc::c_long && !from.is_null() {
if 0 != dc_apeerstate_load_by_addr(peerstate, (*context).sql, from) { if 0 != dc_apeerstate_load_by_addr(
peerstate,
&mut context.sql.clone().lock().unwrap(),
from,
) {
if !autocryptheader.is_null() { if !autocryptheader.is_null() {
dc_apeerstate_apply_header(peerstate, autocryptheader, message_time); dc_apeerstate_apply_header(peerstate, autocryptheader, message_time);
dc_apeerstate_save_to_db(peerstate, (*context).sql, 0i32); dc_apeerstate_save_to_db(
peerstate,
&mut context.sql.clone().lock().unwrap(),
0i32,
);
} else if message_time > (*peerstate).last_seen_autocrypt } else if message_time > (*peerstate).last_seen_autocrypt
&& 0 == contains_report(in_out_message) && 0 == contains_report(in_out_message)
{ {
dc_apeerstate_degrade_encryption(peerstate, message_time); dc_apeerstate_degrade_encryption(peerstate, message_time);
dc_apeerstate_save_to_db(peerstate, (*context).sql, 0i32); dc_apeerstate_save_to_db(
peerstate,
&mut context.sql.clone().lock().unwrap(),
0i32,
);
} }
} else if !autocryptheader.is_null() { } else if !autocryptheader.is_null() {
dc_apeerstate_init_from_header(peerstate, autocryptheader, message_time); dc_apeerstate_init_from_header(peerstate, autocryptheader, message_time);
dc_apeerstate_save_to_db(peerstate, (*context).sql, 1i32); dc_apeerstate_save_to_db(peerstate, &mut context.sql.clone().lock().unwrap(), 1i32);
} }
} }
/* load private key for decryption */ /* load private key for decryption */
self_addr = dc_sqlite3_get_config( self_addr = dc_sqlite3_get_config(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"configured_addr\x00" as *const u8 as *const libc::c_char, b"configured_addr\x00" as *const u8 as *const libc::c_char,
0 as *const libc::c_char, 0 as *const libc::c_char,
); );
@@ -702,11 +708,15 @@ pub unsafe fn dc_e2ee_decrypt(
== dc_keyring_load_self_private_for_decrypting( == dc_keyring_load_self_private_for_decrypting(
private_keyring, private_keyring,
self_addr, self_addr,
(*context).sql, &mut context.sql.clone().lock().unwrap(),
)) ))
{ {
if (*peerstate).last_seen == 0i32 as libc::c_long { if (*peerstate).last_seen == 0i32 as libc::c_long {
dc_apeerstate_load_by_addr(peerstate, (*context).sql, from); dc_apeerstate_load_by_addr(
peerstate,
&mut context.sql.clone().lock().unwrap(),
from,
);
} }
if 0 != (*peerstate).degrade_event { if 0 != (*peerstate).degrade_event {
dc_handle_degrade_event(context, peerstate); dc_handle_degrade_event(context, peerstate);
@@ -795,14 +805,22 @@ unsafe fn update_gossip_peerstates(
let mut peerstate: *mut dc_apeerstate_t = dc_apeerstate_new(context); let mut peerstate: *mut dc_apeerstate_t = dc_apeerstate_new(context);
if 0 == dc_apeerstate_load_by_addr( if 0 == dc_apeerstate_load_by_addr(
peerstate, peerstate,
(*context).sql, &mut context.sql.clone().lock().unwrap(),
(*gossip_header).addr, (*gossip_header).addr,
) { ) {
dc_apeerstate_init_from_gossip(peerstate, gossip_header, message_time); dc_apeerstate_init_from_gossip(peerstate, gossip_header, message_time);
dc_apeerstate_save_to_db(peerstate, (*context).sql, 1i32); dc_apeerstate_save_to_db(
peerstate,
&mut context.sql.clone().lock().unwrap(),
1i32,
);
} else { } else {
dc_apeerstate_apply_gossip(peerstate, gossip_header, message_time); dc_apeerstate_apply_gossip(peerstate, gossip_header, message_time);
dc_apeerstate_save_to_db(peerstate, (*context).sql, 0i32); dc_apeerstate_save_to_db(
peerstate,
&mut context.sql.clone().lock().unwrap(),
0i32,
);
} }
if 0 != (*peerstate).degrade_event { if 0 != (*peerstate).degrade_event {
dc_handle_degrade_event(context, peerstate); dc_handle_degrade_event(context, peerstate);
@@ -855,7 +873,7 @@ unsafe fn decrypt_recursive(
) -> libc::c_int { ) -> libc::c_int {
let mut ct: *mut mailmime_content = 0 as *mut mailmime_content; let mut ct: *mut mailmime_content = 0 as *mut mailmime_content;
let mut cur: *mut clistiter = 0 as *mut clistiter; let mut cur: *mut clistiter = 0 as *mut clistiter;
if context.is_null() || mime.is_null() { if mime.is_null() {
return 0i32; return 0i32;
} }
if (*mime).mm_type == MAILMIME_MULTIPLE as libc::c_int { if (*mime).mm_type == MAILMIME_MULTIPLE as libc::c_int {
@@ -1198,12 +1216,9 @@ pub unsafe fn dc_ensure_secret_key_exists(mut context: &dc_context_t) -> libc::c
let mut success: libc::c_int = 0i32; let mut success: libc::c_int = 0i32;
let mut public_key: *mut dc_key_t = dc_key_new(); let mut public_key: *mut dc_key_t = dc_key_new();
let mut self_addr: *mut libc::c_char = 0 as *mut libc::c_char; let mut self_addr: *mut libc::c_char = 0 as *mut libc::c_char;
if !(context.is_null() if !public_key.is_null() {
|| (*context).magic != 0x11a11807i32 as libc::c_uint
|| public_key.is_null())
{
self_addr = dc_sqlite3_get_config( self_addr = dc_sqlite3_get_config(
(*context).sql, &mut context.sql.clone().lock().unwrap(),
b"configured_addr\x00" as *const u8 as *const libc::c_char, b"configured_addr\x00" as *const u8 as *const libc::c_char,
0 as *const libc::c_char, 0 as *const libc::c_char,
); );

View File

@@ -38,8 +38,6 @@ pub struct dc_imap_t {
pub set_config: dc_set_config_t, pub set_config: dc_set_config_t,
pub precheck_imf: dc_precheck_imf_t, pub precheck_imf: dc_precheck_imf_t,
pub receive_imf: dc_receive_imf_t, pub receive_imf: dc_receive_imf_t,
// TODO: remove
pub context: *mut dc_context_t,
pub log_connect_errors: i32, pub log_connect_errors: i32,
pub skip_log_capabilities: i32, pub skip_log_capabilities: i32,
} }
@@ -75,8 +73,6 @@ pub unsafe fn dc_imap_new(
set_config, set_config,
precheck_imf, precheck_imf,
receive_imf, receive_imf,
// TODO: remove
context: std::ptr::null_mut(),
log_connect_errors: 1, log_connect_errors: 1,
skip_log_capabilities: 0, skip_log_capabilities: 0,
}; };
@@ -107,8 +103,8 @@ pub unsafe fn dc_imap_new(
imap imap
} }
pub unsafe fn dc_imap_unref(imap: &mut dc_imap_t) { pub unsafe fn dc_imap_unref(context: &dc_context_t, imap: &mut dc_imap_t) {
dc_imap_disconnect(imap); dc_imap_disconnect(context, imap);
free(imap.watch_folder as *mut libc::c_void); free(imap.watch_folder as *mut libc::c_void);
free(imap.selected_folder as *mut libc::c_void); free(imap.selected_folder as *mut libc::c_void);
if !imap.fetch_type_prefetch.is_null() { if !imap.fetch_type_prefetch.is_null() {
@@ -122,9 +118,9 @@ pub unsafe fn dc_imap_unref(imap: &mut dc_imap_t) {
} }
} }
pub unsafe fn dc_imap_disconnect(imap: &mut dc_imap_t) { pub unsafe fn dc_imap_disconnect(context: &dc_context_t, imap: &mut dc_imap_t) {
if 0 != imap.connected { if 0 != imap.connected {
unsetup_handle(imap); unsetup_handle(context, imap);
free_connect_param(imap); free_connect_param(imap);
imap.connected = 0 imap.connected = 0
}; };
@@ -150,7 +146,7 @@ unsafe fn free_connect_param(imap: &mut dc_imap_t) {
imap.has_xlist = 0; imap.has_xlist = 0;
} }
unsafe fn unsetup_handle(imap: &mut dc_imap_t) { unsafe fn unsetup_handle(context: &dc_context_t, imap: &mut dc_imap_t) {
if !imap.etpan.is_null() { if !imap.etpan.is_null() {
if 0 != imap.idle_set_up { if 0 != imap.idle_set_up {
mailstream_unsetup_idle((*imap.etpan).imap_stream); mailstream_unsetup_idle((*imap.etpan).imap_stream);
@@ -163,7 +159,7 @@ unsafe fn unsetup_handle(imap: &mut dc_imap_t) {
mailimap_free(imap.etpan); mailimap_free(imap.etpan);
imap.etpan = 0 as *mut mailimap; imap.etpan = 0 as *mut mailimap;
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"IMAP disconnected.\x00" as *const u8 as *const libc::c_char, b"IMAP disconnected.\x00" as *const u8 as *const libc::c_char,
); );
@@ -171,7 +167,11 @@ unsafe fn unsetup_handle(imap: &mut dc_imap_t) {
*imap.selected_folder.offset(0isize) = 0 as libc::c_char; *imap.selected_folder.offset(0isize) = 0 as libc::c_char;
} }
pub unsafe fn dc_imap_connect(imap: &mut dc_imap_t, lp: *const dc_loginparam_t) -> libc::c_int { pub unsafe fn dc_imap_connect(
context: &dc_context_t,
imap: &mut dc_imap_t,
lp: *const dc_loginparam_t,
) -> libc::c_int {
let mut success: libc::c_int = 0; let mut success: libc::c_int = 0;
if lp.is_null() if lp.is_null()
|| (*lp).mail_server.is_null() || (*lp).mail_server.is_null()
@@ -189,7 +189,7 @@ pub unsafe fn dc_imap_connect(imap: &mut dc_imap_t, lp: *const dc_loginparam_t)
imap.imap_user = dc_strdup((*lp).mail_user); imap.imap_user = dc_strdup((*lp).mail_user);
imap.imap_pw = dc_strdup((*lp).mail_pw); imap.imap_pw = dc_strdup((*lp).mail_pw);
imap.server_flags = (*lp).server_flags; imap.server_flags = (*lp).server_flags;
if !(0 == setup_handle_if_needed(imap)) { if !(0 == setup_handle_if_needed(context, imap)) {
imap.can_idle = mailimap_has_idle(imap.etpan); imap.can_idle = mailimap_has_idle(imap.etpan);
imap.has_xlist = mailimap_has_xlist(imap.etpan); imap.has_xlist = mailimap_has_xlist(imap.etpan);
imap.can_idle = 0; imap.can_idle = 0;
@@ -236,7 +236,7 @@ pub unsafe fn dc_imap_connect(imap: &mut dc_imap_t, lp: *const dc_loginparam_t)
} }
} }
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"IMAP-capabilities:%s\x00" as *const u8 as *const libc::c_char, b"IMAP-capabilities:%s\x00" as *const u8 as *const libc::c_char,
capinfostr.buf, capinfostr.buf,
@@ -248,19 +248,19 @@ pub unsafe fn dc_imap_connect(imap: &mut dc_imap_t, lp: *const dc_loginparam_t)
} }
} }
if success == 0 { if success == 0 {
unsetup_handle(imap); unsetup_handle(context, imap);
free_connect_param(imap); free_connect_param(imap);
} }
success success
} }
unsafe fn setup_handle_if_needed(imap: &mut dc_imap_t) -> libc::c_int { unsafe fn setup_handle_if_needed(context: &dc_context_t, imap: &mut dc_imap_t) -> libc::c_int {
let mut current_block: u64; let mut current_block: u64;
let mut r: libc::c_int = 0; let mut r: libc::c_int = 0;
let mut success: libc::c_int = 0; let mut success: libc::c_int = 0;
if !(imap.imap_server.is_null()) { if !(imap.imap_server.is_null()) {
if 0 != imap.should_reconnect { if 0 != imap.should_reconnect {
unsetup_handle(imap); unsetup_handle(context, imap);
} }
if !imap.etpan.is_null() { if !imap.etpan.is_null() {
success = 1 success = 1
@@ -273,9 +273,9 @@ unsafe fn setup_handle_if_needed(imap: &mut dc_imap_t) -> libc::c_int {
imap.imap_server, imap.imap_server,
imap.imap_port as uint16_t, imap.imap_port as uint16_t,
); );
if 0 != dc_imap_is_error(imap, r) { if 0 != dc_imap_is_error(context, imap, r) {
dc_log_event_seq( dc_log_event_seq(
imap.context, context,
Event::ERROR_NETWORK, Event::ERROR_NETWORK,
&mut imap.log_connect_errors as *mut libc::c_int, &mut imap.log_connect_errors as *mut libc::c_int,
b"Could not connect to IMAP-server %s:%i. (Error #%i)\x00" as *const u8 b"Could not connect to IMAP-server %s:%i. (Error #%i)\x00" as *const u8
@@ -287,8 +287,8 @@ unsafe fn setup_handle_if_needed(imap: &mut dc_imap_t) -> libc::c_int {
current_block = 15811161807000851472; current_block = 15811161807000851472;
} else if 0 != imap.server_flags & 0x100 { } else if 0 != imap.server_flags & 0x100 {
r = mailimap_socket_starttls(imap.etpan); r = mailimap_socket_starttls(imap.etpan);
if 0 != dc_imap_is_error(imap, r) { if 0 != dc_imap_is_error(context, imap, r) {
dc_log_event_seq(imap.context, Event::ERROR_NETWORK, dc_log_event_seq(context, Event::ERROR_NETWORK,
&mut imap.log_connect_errors as &mut imap.log_connect_errors as
*mut libc::c_int, *mut libc::c_int,
b"Could not connect to IMAP-server %s:%i using STARTTLS. (Error #%i)\x00" b"Could not connect to IMAP-server %s:%i using STARTTLS. (Error #%i)\x00"
@@ -300,7 +300,7 @@ unsafe fn setup_handle_if_needed(imap: &mut dc_imap_t) -> libc::c_int {
current_block = 15811161807000851472; current_block = 15811161807000851472;
} else { } else {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"IMAP-server %s:%i STARTTLS-connected.\x00" as *const u8 b"IMAP-server %s:%i STARTTLS-connected.\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -311,7 +311,7 @@ unsafe fn setup_handle_if_needed(imap: &mut dc_imap_t) -> libc::c_int {
} }
} else { } else {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"IMAP-server %s:%i connected.\x00" as *const u8 as *const libc::c_char, b"IMAP-server %s:%i connected.\x00" as *const u8 as *const libc::c_char,
imap.imap_server, imap.imap_server,
@@ -321,9 +321,9 @@ unsafe fn setup_handle_if_needed(imap: &mut dc_imap_t) -> libc::c_int {
} }
} else { } else {
r = mailimap_ssl_connect(imap.etpan, imap.imap_server, imap.imap_port as uint16_t); r = mailimap_ssl_connect(imap.etpan, imap.imap_server, imap.imap_port as uint16_t);
if 0 != dc_imap_is_error(imap, r) { if 0 != dc_imap_is_error(context, imap, r) {
dc_log_event_seq( dc_log_event_seq(
imap.context, context,
Event::ERROR_NETWORK, Event::ERROR_NETWORK,
&mut imap.log_connect_errors as *mut libc::c_int, &mut imap.log_connect_errors as *mut libc::c_int,
b"Could not connect to IMAP-server %s:%i using SSL. (Error #%i)\x00" b"Could not connect to IMAP-server %s:%i using SSL. (Error #%i)\x00"
@@ -335,7 +335,7 @@ unsafe fn setup_handle_if_needed(imap: &mut dc_imap_t) -> libc::c_int {
current_block = 15811161807000851472; current_block = 15811161807000851472;
} else { } else {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"IMAP-server %s:%i SSL-connected.\x00" as *const u8 as *const libc::c_char, b"IMAP-server %s:%i SSL-connected.\x00" as *const u8 as *const libc::c_char,
imap.imap_server, imap.imap_server,
@@ -349,21 +349,17 @@ unsafe fn setup_handle_if_needed(imap: &mut dc_imap_t) -> libc::c_int {
_ => { _ => {
if 0 != imap.server_flags & 0x2 { if 0 != imap.server_flags & 0x2 {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"IMAP-OAuth2 connect...\x00" as *const u8 as *const libc::c_char, b"IMAP-OAuth2 connect...\x00" as *const u8 as *const libc::c_char,
); );
let mut access_token: *mut libc::c_char = let mut access_token: *mut libc::c_char =
dc_get_oauth2_access_token(imap.context, imap.addr, imap.imap_pw, 0); dc_get_oauth2_access_token(context, imap.addr, imap.imap_pw, 0);
r = mailimap_oauth2_authenticate(imap.etpan, imap.imap_user, access_token); r = mailimap_oauth2_authenticate(imap.etpan, imap.imap_user, access_token);
if 0 != dc_imap_is_error(imap, r) { if 0 != dc_imap_is_error(context, imap, r) {
free(access_token as *mut libc::c_void); free(access_token as *mut libc::c_void);
access_token = dc_get_oauth2_access_token( access_token =
imap.context, dc_get_oauth2_access_token(context, imap.addr, imap.imap_pw, 0x1);
imap.addr,
imap.imap_pw,
0x1,
);
r = mailimap_oauth2_authenticate( r = mailimap_oauth2_authenticate(
imap.etpan, imap.etpan,
imap.imap_user, imap.imap_user,
@@ -374,14 +370,15 @@ unsafe fn setup_handle_if_needed(imap: &mut dc_imap_t) -> libc::c_int {
} else { } else {
r = mailimap_login(imap.etpan, imap.imap_user, imap.imap_pw) r = mailimap_login(imap.etpan, imap.imap_user, imap.imap_pw)
} }
if 0 != dc_imap_is_error(imap, r) { if 0 != dc_imap_is_error(context, imap, r) {
let mut msg: *mut libc::c_char = get_error_msg( let mut msg: *mut libc::c_char = get_error_msg(
context,
imap, imap,
b"Cannot login\x00" as *const u8 as *const libc::c_char, b"Cannot login\x00" as *const u8 as *const libc::c_char,
r, r,
); );
dc_log_event_seq( dc_log_event_seq(
imap.context, context,
Event::ERROR_NETWORK, Event::ERROR_NETWORK,
&mut imap.log_connect_errors as *mut libc::c_int, &mut imap.log_connect_errors as *mut libc::c_int,
b"%s\x00" as *const u8 as *const libc::c_char, b"%s\x00" as *const u8 as *const libc::c_char,
@@ -390,7 +387,7 @@ unsafe fn setup_handle_if_needed(imap: &mut dc_imap_t) -> libc::c_int {
free(msg as *mut libc::c_void); free(msg as *mut libc::c_void);
} else { } else {
dc_log_event( dc_log_event(
imap.context, context,
Event::IMAP_CONNECTED, Event::IMAP_CONNECTED,
0, 0,
b"IMAP-login as %s ok.\x00" as *const u8 as *const libc::c_char, b"IMAP-login as %s ok.\x00" as *const u8 as *const libc::c_char,
@@ -403,13 +400,14 @@ unsafe fn setup_handle_if_needed(imap: &mut dc_imap_t) -> libc::c_int {
} }
} }
if success == 0 { if success == 0 {
unsetup_handle(imap); unsetup_handle(context, imap);
} }
imap.should_reconnect = 0; imap.should_reconnect = 0;
success success
} }
unsafe fn get_error_msg( unsafe fn get_error_msg(
context: &dc_context_t,
imap: &mut dc_imap_t, imap: &mut dc_imap_t,
what_failed: *const libc::c_char, what_failed: *const libc::c_char,
code: libc::c_int, code: libc::c_int,
@@ -424,7 +422,7 @@ unsafe fn get_error_msg(
dc_strbuilder_init(&mut msg, 1000); dc_strbuilder_init(&mut msg, 1000);
match code { match code {
28 => { 28 => {
stock = dc_stock_str_repl_string(imap.context, 60, imap.imap_user); stock = dc_stock_str_repl_string(context, 60, imap.imap_user);
dc_strbuilder_cat(&mut msg, stock); dc_strbuilder_cat(&mut msg, stock);
} }
_ => { _ => {
@@ -440,12 +438,8 @@ unsafe fn get_error_msg(
stock = 0 as *mut libc::c_char; stock = 0 as *mut libc::c_char;
if !(*imap.etpan).imap_response.is_null() { if !(*imap.etpan).imap_response.is_null() {
dc_strbuilder_cat(&mut msg, b"\n\n\x00" as *const u8 as *const libc::c_char); dc_strbuilder_cat(&mut msg, b"\n\n\x00" as *const u8 as *const libc::c_char);
stock = dc_stock_str_repl_string2( stock =
imap.context, dc_stock_str_repl_string2(context, 61, imap.imap_server, (*imap.etpan).imap_response);
61,
imap.imap_server,
(*imap.etpan).imap_response,
);
dc_strbuilder_cat(&mut msg, stock); dc_strbuilder_cat(&mut msg, stock);
} }
free(stock as *mut libc::c_void); free(stock as *mut libc::c_void);
@@ -453,7 +447,11 @@ unsafe fn get_error_msg(
msg.buf msg.buf
} }
pub unsafe fn dc_imap_is_error(imap: &mut dc_imap_t, code: libc::c_int) -> libc::c_int { pub unsafe fn dc_imap_is_error(
context: &dc_context_t,
imap: &mut dc_imap_t,
code: libc::c_int,
) -> libc::c_int {
if code == MAILIMAP_NO_ERROR as libc::c_int if code == MAILIMAP_NO_ERROR as libc::c_int
|| code == MAILIMAP_NO_ERROR_AUTHENTICATED as libc::c_int || code == MAILIMAP_NO_ERROR_AUTHENTICATED as libc::c_int
|| code == MAILIMAP_NO_ERROR_NON_AUTHENTICATED as libc::c_int || code == MAILIMAP_NO_ERROR_NON_AUTHENTICATED as libc::c_int
@@ -462,7 +460,7 @@ pub unsafe fn dc_imap_is_error(imap: &mut dc_imap_t, code: libc::c_int) -> libc:
} }
if code == MAILIMAP_ERROR_STREAM as libc::c_int || code == MAILIMAP_ERROR_PARSE as libc::c_int { if code == MAILIMAP_ERROR_STREAM as libc::c_int || code == MAILIMAP_ERROR_PARSE as libc::c_int {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"IMAP stream lost; we\'ll reconnect soon.\x00" as *const u8 as *const libc::c_char, b"IMAP stream lost; we\'ll reconnect soon.\x00" as *const u8 as *const libc::c_char,
); );
@@ -482,21 +480,22 @@ pub unsafe extern "C" fn dc_imap_set_watch_folder(
imap.watch_folder = dc_strdup(watch_folder); imap.watch_folder = dc_strdup(watch_folder);
} }
pub unsafe fn dc_imap_is_connected(imap: *const dc_imap_t) -> libc::c_int { pub unsafe fn dc_imap_is_connected(imap: &dc_imap_t) -> libc::c_int {
(0 != imap.connected) as libc::c_int (0 != imap.connected) as libc::c_int
} }
pub unsafe fn dc_imap_fetch(imap: &mut dc_imap_t) -> libc::c_int { pub unsafe fn dc_imap_fetch(context: &dc_context_t, imap: &mut dc_imap_t) -> libc::c_int {
let mut success: libc::c_int = 0; let mut success: libc::c_int = 0;
if !(imap.is_null() || 0 == imap.connected) { if !0 == imap.connected {
setup_handle_if_needed(imap); setup_handle_if_needed(context, imap);
while fetch_from_single_folder(imap, imap.watch_folder) > 0 {} while fetch_from_single_folder(context, imap, imap.watch_folder) > 0 {}
success = 1; success = 1;
} }
success success
} }
unsafe fn fetch_from_single_folder( unsafe fn fetch_from_single_folder(
context: &dc_context_t,
imap: &mut dc_imap_t, imap: &mut dc_imap_t,
folder: *const libc::c_char, folder: *const libc::c_char,
) -> libc::c_int { ) -> libc::c_int {
@@ -512,25 +511,25 @@ unsafe fn fetch_from_single_folder(
let mut set: *mut mailimap_set = 0 as *mut mailimap_set; let mut set: *mut mailimap_set = 0 as *mut mailimap_set;
if imap.etpan.is_null() { if imap.etpan.is_null() {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"Cannot fetch from \"%s\" - not connected.\x00" as *const u8 as *const libc::c_char, b"Cannot fetch from \"%s\" - not connected.\x00" as *const u8 as *const libc::c_char,
folder, folder,
); );
} else if select_folder(imap, folder) == 0 { } else if select_folder(context, imap, folder) == 0 {
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"Cannot select folder %s for fetching.\x00" as *const u8 as *const libc::c_char, b"Cannot select folder %s for fetching.\x00" as *const u8 as *const libc::c_char,
folder, folder,
); );
} else { } else {
get_config_lastseenuid(imap, folder, &mut uidvalidity, &mut lastseenuid); get_config_lastseenuid(context, imap, folder, &mut uidvalidity, &mut lastseenuid);
if uidvalidity != (*(*imap.etpan).imap_selection_info).sel_uidvalidity { if uidvalidity != (*(*imap.etpan).imap_selection_info).sel_uidvalidity {
/* first time this folder is selected or UIDVALIDITY has changed, init lastseenuid and save it to config */ /* first time this folder is selected or UIDVALIDITY has changed, init lastseenuid and save it to config */
if (*(*imap.etpan).imap_selection_info).sel_uidvalidity <= 0 as libc::c_uint { if (*(*imap.etpan).imap_selection_info).sel_uidvalidity <= 0 as libc::c_uint {
dc_log_error( dc_log_error(
imap.context, context,
0, 0,
b"Cannot get UIDVALIDITY for folder \"%s\".\x00" as *const u8 b"Cannot get UIDVALIDITY for folder \"%s\".\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -541,13 +540,14 @@ unsafe fn fetch_from_single_folder(
if 0 != (*(*imap.etpan).imap_selection_info).sel_has_exists() { if 0 != (*(*imap.etpan).imap_selection_info).sel_has_exists() {
if (*(*imap.etpan).imap_selection_info).sel_exists <= 0 as libc::c_uint { if (*(*imap.etpan).imap_selection_info).sel_exists <= 0 as libc::c_uint {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"Folder \"%s\" is empty.\x00" as *const u8 as *const libc::c_char, b"Folder \"%s\" is empty.\x00" as *const u8 as *const libc::c_char,
folder, folder,
); );
if (*(*imap.etpan).imap_selection_info).sel_exists == 0 as libc::c_uint { if (*(*imap.etpan).imap_selection_info).sel_exists == 0 as libc::c_uint {
set_config_lastseenuid( set_config_lastseenuid(
context,
imap, imap,
folder, folder,
(*(*imap.etpan).imap_selection_info).sel_uidvalidity, (*(*imap.etpan).imap_selection_info).sel_uidvalidity,
@@ -563,7 +563,7 @@ unsafe fn fetch_from_single_folder(
} }
} else { } else {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"EXISTS is missing for folder \"%s\", using fallback.\x00" as *const u8 b"EXISTS is missing for folder \"%s\", using fallback.\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -585,10 +585,10 @@ unsafe fn fetch_from_single_folder(
mailimap_set_free(set); mailimap_set_free(set);
set = 0 as *mut mailimap_set set = 0 as *mut mailimap_set
} }
if 0 != dc_imap_is_error(imap, r) || fetch_result.is_null() { if 0 != dc_imap_is_error(context, imap, r) || fetch_result.is_null() {
fetch_result = 0 as *mut clist; fetch_result = 0 as *mut clist;
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"No result returned for folder \"%s\".\x00" as *const u8 b"No result returned for folder \"%s\".\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -600,7 +600,7 @@ unsafe fn fetch_from_single_folder(
cur = (*fetch_result).first; cur = (*fetch_result).first;
if cur.is_null() { if cur.is_null() {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"Empty result returned for folder \"%s\".\x00" as *const u8 b"Empty result returned for folder \"%s\".\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -622,7 +622,7 @@ unsafe fn fetch_from_single_folder(
} }
if lastseenuid <= 0 as libc::c_uint { if lastseenuid <= 0 as libc::c_uint {
dc_log_error( dc_log_error(
imap.context, context,
0, 0,
b"Cannot get largest UID for folder \"%s\"\x00" as *const u8 b"Cannot get largest UID for folder \"%s\"\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -640,9 +640,15 @@ unsafe fn fetch_from_single_folder(
} }
uidvalidity = uidvalidity =
(*(*imap.etpan).imap_selection_info).sel_uidvalidity; (*(*imap.etpan).imap_selection_info).sel_uidvalidity;
set_config_lastseenuid(imap, folder, uidvalidity, lastseenuid); set_config_lastseenuid(
context,
imap,
folder,
uidvalidity,
lastseenuid,
);
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"lastseenuid initialized to %i for %s@%i\x00" as *const u8 b"lastseenuid initialized to %i for %s@%i\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -677,11 +683,11 @@ unsafe fn fetch_from_single_folder(
mailimap_set_free(set); mailimap_set_free(set);
set = 0 as *mut mailimap_set set = 0 as *mut mailimap_set
} }
if 0 != dc_imap_is_error(imap, r) || fetch_result.is_null() { if 0 != dc_imap_is_error(context, imap, r) || fetch_result.is_null() {
fetch_result = 0 as *mut clist; fetch_result = 0 as *mut clist;
if r == MAILIMAP_ERROR_PROTOCOL as libc::c_int { if r == MAILIMAP_ERROR_PROTOCOL as libc::c_int {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"Folder \"%s\" is empty\x00" as *const u8 as *const libc::c_char, b"Folder \"%s\" is empty\x00" as *const u8 as *const libc::c_char,
folder, folder,
@@ -689,7 +695,7 @@ unsafe fn fetch_from_single_folder(
} else { } else {
/* the folder is simply empty, this is no error */ /* the folder is simply empty, this is no error */
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"Cannot fetch message list from folder \"%s\".\x00" as *const u8 b"Cannot fetch message list from folder \"%s\".\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -711,10 +717,10 @@ unsafe fn fetch_from_single_folder(
unquote_rfc724_mid(peek_rfc724_mid(msg_att_0)); unquote_rfc724_mid(peek_rfc724_mid(msg_att_0));
read_cnt = read_cnt.wrapping_add(1); read_cnt = read_cnt.wrapping_add(1);
if 0 == imap.precheck_imf.expect("non-null function pointer")( if 0 == imap.precheck_imf.expect("non-null function pointer")(
imap, rfc724_mid, folder, cur_uid, context, rfc724_mid, folder, cur_uid,
) { ) {
if fetch_single_msg(imap, folder, cur_uid) == 0 { if fetch_single_msg(context, imap, folder, cur_uid) == 0 {
dc_log_info(imap.context, 0, dc_log_info(context, 0,
b"Read error for message %s from \"%s\", trying over later.\x00" b"Read error for message %s from \"%s\", trying over later.\x00"
as *const u8 as as *const u8 as
*const libc::c_char, *const libc::c_char,
@@ -723,7 +729,7 @@ unsafe fn fetch_from_single_folder(
} }
} else { } else {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"Skipping message %s from \"%s\" by precheck.\x00" as *const u8 b"Skipping message %s from \"%s\" by precheck.\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -743,7 +749,7 @@ unsafe fn fetch_from_single_folder(
} }
} }
if 0 == read_errors && new_lastseenuid > 0 as libc::c_uint { if 0 == read_errors && new_lastseenuid > 0 as libc::c_uint {
set_config_lastseenuid(imap, folder, uidvalidity, new_lastseenuid); set_config_lastseenuid(context, imap, folder, uidvalidity, new_lastseenuid);
} }
} }
} }
@@ -753,7 +759,7 @@ unsafe fn fetch_from_single_folder(
/* done */ /* done */
if 0 != read_errors { if 0 != read_errors {
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"%i mails read from \"%s\" with %i errors.\x00" as *const u8 as *const libc::c_char, b"%i mails read from \"%s\" with %i errors.\x00" as *const u8 as *const libc::c_char,
read_cnt as libc::c_int, read_cnt as libc::c_int,
@@ -762,7 +768,7 @@ unsafe fn fetch_from_single_folder(
); );
} else { } else {
dc_log_info( dc_log_info(
imap.context, context,
0i32, 0i32,
b"%i mails read from \"%s\".\x00" as *const u8 as *const libc::c_char, b"%i mails read from \"%s\".\x00" as *const u8 as *const libc::c_char,
read_cnt as libc::c_int, read_cnt as libc::c_int,
@@ -777,6 +783,7 @@ unsafe fn fetch_from_single_folder(
} }
unsafe fn set_config_lastseenuid( unsafe fn set_config_lastseenuid(
context: &dc_context_t,
imap: &mut dc_imap_t, imap: &mut dc_imap_t,
folder: *const libc::c_char, folder: *const libc::c_char,
uidvalidity: uint32_t, uidvalidity: uint32_t,
@@ -791,7 +798,7 @@ unsafe fn set_config_lastseenuid(
uidvalidity, uidvalidity,
lastseenuid, lastseenuid,
); );
imap.set_config.expect("non-null function pointer")(imap, key, val); imap.set_config.expect("non-null function pointer")(context, key, val);
free(val as *mut libc::c_void); free(val as *mut libc::c_void);
free(key as *mut libc::c_void); free(key as *mut libc::c_void);
} }
@@ -878,6 +885,7 @@ unsafe fn peek_uid(msg_att: *mut mailimap_msg_att) -> uint32_t {
} }
unsafe fn fetch_single_msg( unsafe fn fetch_single_msg(
context: &dc_context_t,
imap: &mut dc_imap_t, imap: &mut dc_imap_t,
folder: *const libc::c_char, folder: *const libc::c_char,
server_uid: uint32_t, server_uid: uint32_t,
@@ -901,10 +909,10 @@ unsafe fn fetch_single_msg(
mailimap_set_free(set); mailimap_set_free(set);
set = 0 as *mut mailimap_set set = 0 as *mut mailimap_set
} }
if 0 != dc_imap_is_error(imap, r) || fetch_result.is_null() { if 0 != dc_imap_is_error(context, imap, r) || fetch_result.is_null() {
fetch_result = 0 as *mut clist; fetch_result = 0 as *mut clist;
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"Error #%i on fetching message #%i from folder \"%s\"; retry=%i.\x00" as *const u8 b"Error #%i on fetching message #%i from folder \"%s\"; retry=%i.\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -921,7 +929,7 @@ unsafe fn fetch_single_msg(
cur = (*fetch_result).first; cur = (*fetch_result).first;
if cur.is_null() { if cur.is_null() {
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"Message #%i does not exist in folder \"%s\".\x00" as *const u8 b"Message #%i does not exist in folder \"%s\".\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -945,7 +953,7 @@ unsafe fn fetch_single_msg(
if !(msg_content.is_null() || msg_bytes <= 0 || 0 != deleted) { if !(msg_content.is_null() || msg_bytes <= 0 || 0 != deleted) {
/* dc_log_warning(imap->context, 0, "Message #%i in folder \"%s\" is empty or deleted.", (int)server_uid, folder); -- this is a quite usual situation, do not print a warning */ /* dc_log_warning(imap->context, 0, "Message #%i in folder \"%s\" is empty or deleted.", (int)server_uid, folder); -- this is a quite usual situation, do not print a warning */
imap.receive_imf.expect("non-null function pointer")( imap.receive_imf.expect("non-null function pointer")(
imap, context,
msg_content, msg_content,
msg_bytes, msg_bytes,
folder, folder,
@@ -1038,6 +1046,7 @@ unsafe fn peek_body(
} }
unsafe fn get_config_lastseenuid( unsafe fn get_config_lastseenuid(
context: &dc_context_t,
imap: &mut dc_imap_t, imap: &mut dc_imap_t,
folder: *const libc::c_char, folder: *const libc::c_char,
uidvalidity: *mut uint32_t, uidvalidity: *mut uint32_t,
@@ -1050,7 +1059,7 @@ unsafe fn get_config_lastseenuid(
folder, folder,
); );
let mut val1: *mut libc::c_char = let mut val1: *mut libc::c_char =
imap.get_config.expect("non-null function pointer")(imap, key, 0 as *const libc::c_char); imap.get_config.expect("non-null function pointer")(context, key, 0 as *const libc::c_char);
let mut val2: *mut libc::c_char = 0 as *mut libc::c_char; let mut val2: *mut libc::c_char = 0 as *mut libc::c_char;
let mut val3: *mut libc::c_char = 0 as *mut libc::c_char; let mut val3: *mut libc::c_char = 0 as *mut libc::c_char;
if !val1.is_null() { if !val1.is_null() {
@@ -1074,7 +1083,11 @@ unsafe fn get_config_lastseenuid(
* Handle folders * Handle folders
******************************************************************************/ ******************************************************************************/
unsafe fn select_folder(imap: &mut dc_imap_t, folder: *const libc::c_char) -> libc::c_int { unsafe fn select_folder(
context: &dc_context_t,
imap: &mut dc_imap_t,
folder: *const libc::c_char,
) -> libc::c_int {
if imap.etpan.is_null() { if imap.etpan.is_null() {
*imap.selected_folder.offset(0isize) = 0 as libc::c_char; *imap.selected_folder.offset(0isize) = 0 as libc::c_char;
imap.selected_folder_needs_expunge = 0; imap.selected_folder_needs_expunge = 0;
@@ -1089,7 +1102,7 @@ unsafe fn select_folder(imap: &mut dc_imap_t, folder: *const libc::c_char) -> li
if 0 != imap.selected_folder_needs_expunge { if 0 != imap.selected_folder_needs_expunge {
if 0 != *imap.selected_folder.offset(0isize) { if 0 != *imap.selected_folder.offset(0isize) {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"Expunge messages in \"%s\".\x00" as *const u8 as *const libc::c_char, b"Expunge messages in \"%s\".\x00" as *const u8 as *const libc::c_char,
imap.selected_folder, imap.selected_folder,
@@ -1100,9 +1113,9 @@ unsafe fn select_folder(imap: &mut dc_imap_t, folder: *const libc::c_char) -> li
} }
if !folder.is_null() { if !folder.is_null() {
let mut r: libc::c_int = mailimap_select(imap.etpan, folder); let mut r: libc::c_int = mailimap_select(imap.etpan, folder);
if 0 != dc_imap_is_error(imap, r) || (*imap.etpan).imap_selection_info.is_null() { if 0 != dc_imap_is_error(context, imap, r) || (*imap.etpan).imap_selection_info.is_null() {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"Cannot select folder; code=%i, imap_response=%s\x00" as *const u8 b"Cannot select folder; code=%i, imap_response=%s\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -1122,22 +1135,21 @@ unsafe fn select_folder(imap: &mut dc_imap_t, folder: *const libc::c_char) -> li
1 1
} }
pub unsafe fn dc_imap_idle(imap: &mut dc_imap_t) { pub unsafe fn dc_imap_idle(context: &dc_context_t, imap: &mut dc_imap_t) {
let mut current_block: u64; let mut current_block: u64;
let mut r: libc::c_int = 0; let mut r: libc::c_int = 0;
let mut r2: libc::c_int = 0; let mut r2: libc::c_int = 0;
if 0 != imap.can_idle { if 0 != imap.can_idle {
setup_handle_if_needed(imap); setup_handle_if_needed(context, imap);
if imap.idle_set_up == 0 && !imap.etpan.is_null() && !(*imap.etpan).imap_stream.is_null() if imap.idle_set_up == 0 && !imap.etpan.is_null() && !(*imap.etpan).imap_stream.is_null() {
{
r = mailstream_setup_idle((*imap.etpan).imap_stream); r = mailstream_setup_idle((*imap.etpan).imap_stream);
if 0 != dc_imap_is_error(imap, r) { if 0 != dc_imap_is_error(context, imap, r) {
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"IMAP-IDLE: Cannot setup.\x00" as *const u8 as *const libc::c_char, b"IMAP-IDLE: Cannot setup.\x00" as *const u8 as *const libc::c_char,
); );
fake_idle(imap); fake_idle(context, imap);
current_block = 14832935472441733737; current_block = 14832935472441733737;
} else { } else {
imap.idle_set_up = 1; imap.idle_set_up = 1;
@@ -1149,22 +1161,22 @@ pub unsafe fn dc_imap_idle(imap: &mut dc_imap_t) {
match current_block { match current_block {
14832935472441733737 => {} 14832935472441733737 => {}
_ => { _ => {
if 0 == imap.idle_set_up || 0 == select_folder(imap, imap.watch_folder) { if 0 == imap.idle_set_up || 0 == select_folder(context, imap, imap.watch_folder) {
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"IMAP-IDLE not setup.\x00" as *const u8 as *const libc::c_char, b"IMAP-IDLE not setup.\x00" as *const u8 as *const libc::c_char,
); );
fake_idle(imap); fake_idle(context, imap);
} else { } else {
r = mailimap_idle(imap.etpan); r = mailimap_idle(imap.etpan);
if 0 != dc_imap_is_error(imap, r) { if 0 != dc_imap_is_error(context, imap, r) {
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"IMAP-IDLE: Cannot start.\x00" as *const u8 as *const libc::c_char, b"IMAP-IDLE: Cannot start.\x00" as *const u8 as *const libc::c_char,
); );
fake_idle(imap); fake_idle(context, imap);
} else { } else {
r = mailstream_wait_idle((*imap.etpan).imap_stream, 23 * 60); r = mailstream_wait_idle((*imap.etpan).imap_stream, 23 * 60);
r2 = mailimap_idle_done(imap.etpan); r2 = mailimap_idle_done(imap.etpan);
@@ -1172,7 +1184,7 @@ pub unsafe fn dc_imap_idle(imap: &mut dc_imap_t) {
|| r == MAILSTREAM_IDLE_CANCELLED as libc::c_int || r == MAILSTREAM_IDLE_CANCELLED as libc::c_int
{ {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"IMAP-IDLE wait cancelled, r=%i, r2=%i; we\'ll reconnect soon.\x00" b"IMAP-IDLE wait cancelled, r=%i, r2=%i; we\'ll reconnect soon.\x00"
as *const u8 as *const u8
@@ -1183,25 +1195,25 @@ pub unsafe fn dc_imap_idle(imap: &mut dc_imap_t) {
imap.should_reconnect = 1 imap.should_reconnect = 1
} else if r == MAILSTREAM_IDLE_INTERRUPTED as libc::c_int { } else if r == MAILSTREAM_IDLE_INTERRUPTED as libc::c_int {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"IMAP-IDLE interrupted.\x00" as *const u8 as *const libc::c_char, b"IMAP-IDLE interrupted.\x00" as *const u8 as *const libc::c_char,
); );
} else if r == MAILSTREAM_IDLE_HASDATA as libc::c_int { } else if r == MAILSTREAM_IDLE_HASDATA as libc::c_int {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"IMAP-IDLE has data.\x00" as *const u8 as *const libc::c_char, b"IMAP-IDLE has data.\x00" as *const u8 as *const libc::c_char,
); );
} else if r == MAILSTREAM_IDLE_TIMEOUT as libc::c_int { } else if r == MAILSTREAM_IDLE_TIMEOUT as libc::c_int {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"IMAP-IDLE timeout.\x00" as *const u8 as *const libc::c_char, b"IMAP-IDLE timeout.\x00" as *const u8 as *const libc::c_char,
); );
} else { } else {
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"IMAP-IDLE returns unknown value r=%i, r2=%i.\x00" as *const u8 b"IMAP-IDLE returns unknown value r=%i, r2=%i.\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -1214,17 +1226,17 @@ pub unsafe fn dc_imap_idle(imap: &mut dc_imap_t) {
} }
} }
} else { } else {
fake_idle(imap); fake_idle(context, imap);
} }
} }
unsafe fn fake_idle(imap: &mut dc_imap_t) { unsafe fn fake_idle(context: &dc_context_t, imap: &mut dc_imap_t) {
/* Idle using timeouts. This is also needed if we're not yet configured - /* Idle using timeouts. This is also needed if we're not yet configured -
in this case, we're waiting for a configure job */ in this case, we're waiting for a configure job */
let mut fake_idle_start_time: time_t = time(0 as *mut time_t); let mut fake_idle_start_time: time_t = time(0 as *mut time_t);
let mut seconds_to_wait: time_t = 0 as time_t; let mut seconds_to_wait: time_t = 0 as time_t;
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"IMAP-fake-IDLEing...\x00" as *const u8 as *const libc::c_char, b"IMAP-fake-IDLEing...\x00" as *const u8 as *const libc::c_char,
); );
@@ -1236,7 +1248,8 @@ unsafe fn fake_idle(imap: &mut dc_imap_t) {
} else { } else {
60 60
}) as time_t; }) as time_t;
pthread_mutex_lock(&mut imap.watch_condmutex); // FIXME
// pthread_mutex_lock(&mut imap.watch_condmutex);
let mut r: libc::c_int = 0; let mut r: libc::c_int = 0;
let mut wakeup_at: timespec = timespec { let mut wakeup_at: timespec = timespec {
tv_sec: 0, tv_sec: 0,
@@ -1248,23 +1261,24 @@ unsafe fn fake_idle(imap: &mut dc_imap_t) {
::std::mem::size_of::<timespec>(), ::std::mem::size_of::<timespec>(),
); );
wakeup_at.tv_sec = time(0 as *mut time_t) + seconds_to_wait; wakeup_at.tv_sec = time(0 as *mut time_t) + seconds_to_wait;
while imap.watch_condflag == 0 && r == 0 { // FIXME
r = pthread_cond_timedwait( // while imap.watch_condflag == 0 && r == 0 {
&mut imap.watch_cond, // r = pthread_cond_timedwait(
&mut imap.watch_condmutex, // &mut imap.watch_cond,
&mut wakeup_at, // &mut imap.watch_condmutex,
); // &mut wakeup_at,
if 0 != imap.watch_condflag { // );
do_fake_idle = 0 // if 0 != imap.watch_condflag {
} // do_fake_idle = 0
} // }
imap.watch_condflag = 0; // }
pthread_mutex_unlock(&mut imap.watch_condmutex); // imap.watch_condflag = 0;
// pthread_mutex_unlock(&mut imap.watch_condmutex);
if do_fake_idle == 0 { if do_fake_idle == 0 {
return; return;
} }
if 0 != setup_handle_if_needed(imap) { if 0 != setup_handle_if_needed(context, imap) {
if 0 != fetch_from_single_folder(imap, imap.watch_folder) { if 0 != fetch_from_single_folder(context, imap, imap.watch_folder) {
do_fake_idle = 0 do_fake_idle = 0
} }
} else { } else {
@@ -1279,17 +1293,19 @@ pub unsafe fn dc_imap_interrupt_idle(imap: &mut dc_imap_t) {
mailstream_interrupt_idle((*imap.etpan).imap_stream); mailstream_interrupt_idle((*imap.etpan).imap_stream);
} }
} }
pthread_mutex_lock(&mut imap.watch_condmutex); // FIXME
imap.watch_condflag = 1; // pthread_mutex_lock(&mut imap.watch_condmutex);
pthread_cond_signal(&mut imap.watch_cond); // imap.watch_condflag = 1;
pthread_mutex_unlock(&mut imap.watch_condmutex); // pthread_cond_signal(&mut imap.watch_cond);
// pthread_mutex_unlock(&mut imap.watch_condmutex);
} }
pub unsafe fn dc_imap_move( pub unsafe fn dc_imap_move(
context: &dc_context_t,
imap: &mut dc_imap_t, imap: &mut dc_imap_t,
folder: *const libc::c_char, folder: *const libc::c_char,
uid: uint32_t, uid: uint32_t,
_folder: *const libc::c_char, dest_folder: *const libc::c_char,
dest_uid: *mut uint32_t, dest_uid: *mut uint32_t,
) -> dc_imap_res { ) -> dc_imap_res {
let mut current_block: u64; let mut current_block: u64;
@@ -1308,7 +1324,7 @@ pub unsafe fn dc_imap_move(
res = DC_FAILED res = DC_FAILED
} else if strcasecmp(folder, dest_folder) == 0 { } else if strcasecmp(folder, dest_folder) == 0 {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"Skip moving message; message %s/%i is already in %s...\x00" as *const u8 b"Skip moving message; message %s/%i is already in %s...\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -1319,16 +1335,16 @@ pub unsafe fn dc_imap_move(
res = DC_ALREADY_DONE res = DC_ALREADY_DONE
} else { } else {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"Moving message %s/%i to %s...\x00" as *const u8 as *const libc::c_char, b"Moving message %s/%i to %s...\x00" as *const u8 as *const libc::c_char,
folder, folder,
uid as libc::c_int, uid as libc::c_int,
dest_folder, dest_folder,
); );
if select_folder(imap, folder) == 0 { if select_folder(context, imap, folder) == 0 {
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"Cannot select folder %s for moving message.\x00" as *const u8 b"Cannot select folder %s for moving message.\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -1343,7 +1359,7 @@ pub unsafe fn dc_imap_move(
&mut res_setsrc, &mut res_setsrc,
&mut res_setdest, &mut res_setdest,
); );
if 0 != dc_imap_is_error(imap, r) { if 0 != dc_imap_is_error(context, imap, r) {
if !res_setsrc.is_null() { if !res_setsrc.is_null() {
mailimap_set_free(res_setsrc); mailimap_set_free(res_setsrc);
res_setsrc = 0 as *mut mailimap_set res_setsrc = 0 as *mut mailimap_set
@@ -1353,7 +1369,7 @@ pub unsafe fn dc_imap_move(
res_setdest = 0 as *mut mailimap_set res_setdest = 0 as *mut mailimap_set
} }
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"Cannot move message, fallback to COPY/DELETE %s/%i to %s...\x00" as *const u8 b"Cannot move message, fallback to COPY/DELETE %s/%i to %s...\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -1369,9 +1385,9 @@ pub unsafe fn dc_imap_move(
&mut res_setsrc, &mut res_setsrc,
&mut res_setdest, &mut res_setdest,
); );
if 0 != dc_imap_is_error(imap, r) { if 0 != dc_imap_is_error(context, imap, r) {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"Cannot copy message.\x00" as *const u8 as *const libc::c_char, b"Cannot copy message.\x00" as *const u8 as *const libc::c_char,
); );
@@ -1379,7 +1395,7 @@ pub unsafe fn dc_imap_move(
} else { } else {
if add_flag(imap, uid, mailimap_flag_new_deleted()) == 0 { if add_flag(imap, uid, mailimap_flag_new_deleted()) == 0 {
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"Cannot mark message as \"Deleted\".\x00" as *const u8 b"Cannot mark message as \"Deleted\".\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -1463,6 +1479,7 @@ unsafe fn add_flag(
} }
pub unsafe fn dc_imap_set_seen( pub unsafe fn dc_imap_set_seen(
context: &dc_context_t,
imap: &mut dc_imap_t, imap: &mut dc_imap_t,
folder: *const libc::c_char, folder: *const libc::c_char,
uid: uint32_t, uid: uint32_t,
@@ -1472,15 +1489,15 @@ pub unsafe fn dc_imap_set_seen(
res = DC_FAILED res = DC_FAILED
} else if !imap.etpan.is_null() { } else if !imap.etpan.is_null() {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"Marking message %s/%i as seen...\x00" as *const u8 as *const libc::c_char, b"Marking message %s/%i as seen...\x00" as *const u8 as *const libc::c_char,
folder, folder,
uid as libc::c_int, uid as libc::c_int,
); );
if select_folder(imap, folder) == 0 { if select_folder(context, imap, folder) == 0 {
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"Cannot select folder %s for setting SEEN flag.\x00" as *const u8 b"Cannot select folder %s for setting SEEN flag.\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -1488,7 +1505,7 @@ pub unsafe fn dc_imap_set_seen(
); );
} else if add_flag(imap, uid, mailimap_flag_new_seen()) == 0 { } else if add_flag(imap, uid, mailimap_flag_new_seen()) == 0 {
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"Cannot mark message as seen.\x00" as *const u8 as *const libc::c_char, b"Cannot mark message as seen.\x00" as *const u8 as *const libc::c_char,
); );
@@ -1508,6 +1525,7 @@ pub unsafe fn dc_imap_set_seen(
} }
pub unsafe fn dc_imap_set_mdnsent( pub unsafe fn dc_imap_set_mdnsent(
context: &dc_context_t,
imap: &mut dc_imap_t, imap: &mut dc_imap_t,
folder: *const libc::c_char, folder: *const libc::c_char,
uid: uint32_t, uid: uint32_t,
@@ -1522,15 +1540,15 @@ pub unsafe fn dc_imap_set_mdnsent(
res = DC_FAILED res = DC_FAILED
} else if !imap.etpan.is_null() { } else if !imap.etpan.is_null() {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"Marking message %s/%i as $MDNSent...\x00" as *const u8 as *const libc::c_char, b"Marking message %s/%i as $MDNSent...\x00" as *const u8 as *const libc::c_char,
folder, folder,
uid as libc::c_int, uid as libc::c_int,
); );
if select_folder(imap, folder) == 0 { if select_folder(context, imap, folder) == 0 {
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"Cannot select folder %s for setting $MDNSent flag.\x00" as *const u8 b"Cannot select folder %s for setting $MDNSent flag.\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -1584,7 +1602,7 @@ pub unsafe fn dc_imap_set_mdnsent(
if 0 != can_create_flag { if 0 != can_create_flag {
let mut r: libc::c_int = let mut r: libc::c_int =
mailimap_uid_fetch(imap.etpan, set, imap.fetch_type_flags, &mut fetch_result); mailimap_uid_fetch(imap.etpan, set, imap.fetch_type_flags, &mut fetch_result);
if 0 != dc_imap_is_error(imap, r) || fetch_result.is_null() { if 0 != dc_imap_is_error(context, imap, r) || fetch_result.is_null() {
fetch_result = 0 as *mut clist fetch_result = 0 as *mut clist
} else { } else {
let mut cur: *mut clistiter = (*fetch_result).first; let mut cur: *mut clistiter = (*fetch_result).first;
@@ -1616,7 +1634,7 @@ pub unsafe fn dc_imap_set_mdnsent(
17044610252497760460 => {} 17044610252497760460 => {}
_ => { _ => {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
if res as libc::c_uint if res as libc::c_uint
== DC_SUCCESS as libc::c_int as libc::c_uint == DC_SUCCESS as libc::c_int as libc::c_uint
@@ -1636,7 +1654,7 @@ pub unsafe fn dc_imap_set_mdnsent(
} else { } else {
res = DC_SUCCESS; res = DC_SUCCESS;
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"Cannot store $MDNSent flags, risk sending duplicate MDN.\x00" as *const u8 b"Cannot store $MDNSent flags, risk sending duplicate MDN.\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -1724,6 +1742,7 @@ unsafe fn peek_flag_keyword(
/* only returns 0 on connection problems; we should try later again in this case */ /* only returns 0 on connection problems; we should try later again in this case */
pub unsafe fn dc_imap_delete_msg( pub unsafe fn dc_imap_delete_msg(
context: &dc_context_t,
imap: &mut dc_imap_t, imap: &mut dc_imap_t,
rfc724_mid: *const libc::c_char, rfc724_mid: *const libc::c_char,
folder: *const libc::c_char, folder: *const libc::c_char,
@@ -1742,7 +1761,7 @@ pub unsafe fn dc_imap_delete_msg(
success = 1 success = 1
} else { } else {
dc_log_info( dc_log_info(
imap.context, context,
0, 0,
b"Marking message \"%s\", %s/%i for deletion...\x00" as *const u8 b"Marking message \"%s\", %s/%i for deletion...\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -1750,9 +1769,9 @@ pub unsafe fn dc_imap_delete_msg(
folder, folder,
server_uid as libc::c_int, server_uid as libc::c_int,
); );
if select_folder(imap, folder) == 0 { if select_folder(context, imap, folder) == 0 {
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"Cannot select folder %s for deleting message.\x00" as *const u8 b"Cannot select folder %s for deleting message.\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -1767,10 +1786,10 @@ pub unsafe fn dc_imap_delete_msg(
mailimap_set_free(set); mailimap_set_free(set);
set = 0 as *mut mailimap_set set = 0 as *mut mailimap_set
} }
if 0 != dc_imap_is_error(imap, r) || fetch_result.is_null() { if 0 != dc_imap_is_error(context, imap, r) || fetch_result.is_null() {
fetch_result = 0 as *mut clist; fetch_result = 0 as *mut clist;
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"Cannot delete on IMAP, %s/%i not found.\x00" as *const u8 b"Cannot delete on IMAP, %s/%i not found.\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -1798,7 +1817,7 @@ pub unsafe fn dc_imap_delete_msg(
|| strcmp(is_rfc724_mid, rfc724_mid) != 0 || strcmp(is_rfc724_mid, rfc724_mid) != 0
{ {
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"Cannot delete on IMAP, %s/%i does not match %s.\x00" as *const u8 b"Cannot delete on IMAP, %s/%i does not match %s.\x00" as *const u8
as *const libc::c_char, as *const libc::c_char,
@@ -1811,7 +1830,7 @@ pub unsafe fn dc_imap_delete_msg(
/* mark the message for deletion */ /* mark the message for deletion */
if add_flag(imap, server_uid, mailimap_flag_new_deleted()) == 0 { if add_flag(imap, server_uid, mailimap_flag_new_deleted()) == 0 {
dc_log_warning( dc_log_warning(
imap.context, context,
0, 0,
b"Cannot mark message as \"Deleted\".\x00" as *const u8 as *const libc::c_char, b"Cannot mark message as \"Deleted\".\x00" as *const u8 as *const libc::c_char,
); );
@@ -1828,7 +1847,7 @@ pub unsafe fn dc_imap_delete_msg(
free(is_rfc724_mid as *mut libc::c_void); free(is_rfc724_mid as *mut libc::c_void);
free(new_folder as *mut libc::c_void); free(new_folder as *mut libc::c_void);
0 != success { if 0 != success {
1 1
} else { } else {
dc_imap_is_connected(imap) dc_imap_is_connected(imap)

View File

@@ -1347,7 +1347,7 @@ unsafe fn export_backup(mut context: &dc_context_t, mut dir: *const libc::c_char
* Classic key import * Classic key import
******************************************************************************/ ******************************************************************************/
unsafe fn import_self_keys( unsafe fn import_self_keys(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut dir_name: *const libc::c_char, mut dir_name: *const libc::c_char,
) -> libc::c_int { ) -> libc::c_int {
/* hint: even if we switch to import Autocrypt Setup Files, we should leave the possibility to import /* hint: even if we switch to import Autocrypt Setup Files, we should leave the possibility to import
@@ -1481,7 +1481,7 @@ unsafe fn import_self_keys(
return imported_cnt; return imported_cnt;
} }
unsafe fn export_self_keys( unsafe fn export_self_keys(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut dir: *const libc::c_char, mut dir: *const libc::c_char,
) -> libc::c_int { ) -> libc::c_int {
let mut success: libc::c_int = 0i32; let mut success: libc::c_int = 0i32;
@@ -1522,7 +1522,7 @@ unsafe fn export_self_keys(
* Classic key export * Classic key export
******************************************************************************/ ******************************************************************************/
unsafe fn export_key_to_asc_file( unsafe fn export_key_to_asc_file(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut dir: *const libc::c_char, mut dir: *const libc::c_char,
mut id: libc::c_int, mut id: libc::c_int,
mut key: *const dc_key_t, mut key: *const dc_key_t,

View File

@@ -1001,7 +1001,7 @@ unsafe fn dc_job_do_DC_JOB_DELETE_MSG_ON_IMAP(mut context: &dc_context_t, mut jo
dc_msg_unref(msg); dc_msg_unref(msg);
} }
/* delete all pending jobs with the given action */ /* delete all pending jobs with the given action */
pub unsafe fn dc_job_kill_action(mut context: *mut dc_context_t, mut action: libc::c_int) { pub unsafe fn dc_job_kill_action(mut context: &dc_context_t, mut action: libc::c_int) {
if context.is_null() { if context.is_null() {
return; return;
} }
@@ -1013,7 +1013,7 @@ pub unsafe fn dc_job_kill_action(mut context: *mut dc_context_t, mut action: lib
sqlite3_step(stmt); sqlite3_step(stmt);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
} }
pub unsafe fn dc_perform_imap_fetch(mut context: *mut dc_context_t) { pub unsafe fn dc_perform_imap_fetch(mut context: &dc_context_t) {
let mut start: libc::clock_t = clock(); let mut start: libc::clock_t = clock();
if 0 == connect_to_inbox(context) { if 0 == connect_to_inbox(context) {
return; return;
@@ -1228,7 +1228,7 @@ pub unsafe fn dc_perform_smtp_idle(mut context: &dc_context_t) {
b"SMTP-idle ended.\x00" as *const u8 as *const libc::c_char, b"SMTP-idle ended.\x00" as *const u8 as *const libc::c_char,
); );
} }
unsafe fn get_next_wakeup_time(mut context: *mut dc_context_t, mut thread: libc::c_int) -> time_t { unsafe fn get_next_wakeup_time(mut context: &dc_context_t, mut thread: libc::c_int) -> time_t {
let mut wakeup_time: time_t = 0i32 as time_t; let mut wakeup_time: time_t = 0i32 as time_t;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
stmt = dc_sqlite3_prepare( stmt = dc_sqlite3_prepare(
@@ -1246,7 +1246,7 @@ unsafe fn get_next_wakeup_time(mut context: *mut dc_context_t, mut thread: libc:
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return wakeup_time; return wakeup_time;
} }
pub unsafe fn dc_maybe_network(mut context: *mut dc_context_t) { pub unsafe fn dc_maybe_network(mut context: &dc_context_t) {
pthread_mutex_lock(&mut (*context).smtpidle_condmutex); pthread_mutex_lock(&mut (*context).smtpidle_condmutex);
(*context).probe_smtp_network = 1i32; (*context).probe_smtp_network = 1i32;
pthread_mutex_unlock(&mut (*context).smtpidle_condmutex); pthread_mutex_unlock(&mut (*context).smtpidle_condmutex);
@@ -1274,7 +1274,7 @@ pub unsafe fn dc_job_action_exists(
return job_exists; return job_exists;
} }
/* special case for DC_JOB_SEND_MSG_TO_SMTP */ /* special case for DC_JOB_SEND_MSG_TO_SMTP */
pub unsafe fn dc_job_send_msg(mut context: *mut dc_context_t, mut msg_id: uint32_t) -> libc::c_int { pub unsafe fn dc_job_send_msg(mut context: &dc_context_t, mut msg_id: uint32_t) -> libc::c_int {
let mut success: libc::c_int = 0i32; let mut success: libc::c_int = 0i32;
let mut mimefactory: dc_mimefactory_t = dc_mimefactory_t { let mut mimefactory: dc_mimefactory_t = dc_mimefactory_t {
from_addr: 0 as &libc::c_char, from_addr: 0 as &libc::c_char,
@@ -1296,7 +1296,7 @@ pub unsafe fn dc_job_send_msg(mut context: *mut dc_context_t, mut msg_id: uint32
out_gossiped: 0, out_gossiped: 0,
out_last_added_location_id: 0, out_last_added_location_id: 0,
error: 0 as *mut libc::c_char, error: 0 as *mut libc::c_char,
context: 0 as *mut dc_context_t, context: std::ptr::null_mut(),
}; };
dc_mimefactory_init(&mut mimefactory, context); dc_mimefactory_init(&mut mimefactory, context);
/* load message data */ /* load message data */
@@ -1381,7 +1381,6 @@ pub unsafe fn dc_job_send_msg(mut context: *mut dc_context_t, mut msg_id: uint32
dc_strdup(mimefactory.from_addr) as *mut libc::c_void, dc_strdup(mimefactory.from_addr) as *mut libc::c_void,
); );
} }
dc_sqlite3_begin_transaction((*context).sql);
if 0 != mimefactory.out_gossiped { if 0 != mimefactory.out_gossiped {
dc_set_gossiped_timestamp( dc_set_gossiped_timestamp(
context, context,
@@ -1416,7 +1415,6 @@ pub unsafe fn dc_job_send_msg(mut context: *mut dc_context_t, mut msg_id: uint32
0 as *const libc::c_char, 0 as *const libc::c_char,
0 as *const libc::c_char, 0 as *const libc::c_char,
); );
dc_sqlite3_commit((*context).sql);
success = dc_add_smtp_job(context, 5901i32, &mut mimefactory) success = dc_add_smtp_job(context, 5901i32, &mut mimefactory)
} }
} }

View File

@@ -1,4 +1,4 @@
use std::sync::{Condvar, Mutex}; use std::sync::{Arc, Condvar, Mutex};
use libc; use libc;
@@ -18,7 +18,7 @@ pub struct dc_jobthread_t {
pub context: *mut dc_context_t, pub context: *mut dc_context_t,
pub name: *mut libc::c_char, pub name: *mut libc::c_char,
pub folder_config_name: *mut libc::c_char, pub folder_config_name: *mut libc::c_char,
pub imap: *mut dc_imap_t, pub imap: Arc<Mutex<dc_imap_t>>,
pub idle: (Mutex<bool>, Condvar), pub idle: (Mutex<bool>, Condvar),
pub jobs_needed: libc::c_int, pub jobs_needed: libc::c_int,
pub suspended: libc::c_int, pub suspended: libc::c_int,
@@ -28,13 +28,13 @@ pub struct dc_jobthread_t {
pub unsafe fn dc_jobthread_init( pub unsafe fn dc_jobthread_init(
name: *const libc::c_char, name: *const libc::c_char,
folder_config_name: *const libc::c_char, folder_config_name: *const libc::c_char,
imap: *mut dc_imap_t, imap: dc_imap_t,
) -> dc_jobthread_t { ) -> dc_jobthread_t {
dc_jobthread_t { dc_jobthread_t {
context: std::ptr::null_mut(), context: std::ptr::null_mut(),
name: dc_strdup(name), name: dc_strdup(name),
folder_config_name: dc_strdup(folder_config_name), folder_config_name: dc_strdup(folder_config_name),
imap, imap: Arc::new(Mutex::New(imap)),
idle: (Mutex::new(false), Condvar::new()), idle: (Mutex::new(false), Condvar::new()),
jobs_needed: 0i32, jobs_needed: 0i32,
suspended: 0i32, suspended: 0i32,

View File

@@ -256,7 +256,7 @@ pub unsafe fn dc_key_save_self_keypair(
mut private_key: *const dc_key_t, mut private_key: *const dc_key_t,
mut addr: *const libc::c_char, mut addr: *const libc::c_char,
mut is_default: libc::c_int, mut is_default: libc::c_int,
mut sql: *mut dc_sqlite3_t, mut sql: &mut dc_sqlite3_t,
) -> libc::c_int { ) -> libc::c_int {
let mut success: libc::c_int = 0i32; let mut success: libc::c_int = 0i32;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
@@ -292,7 +292,7 @@ pub unsafe fn dc_key_save_self_keypair(
pub unsafe fn dc_key_load_self_public( pub unsafe fn dc_key_load_self_public(
mut key: *mut dc_key_t, mut key: *mut dc_key_t,
mut self_addr: *const libc::c_char, mut self_addr: *const libc::c_char,
mut sql: *mut dc_sqlite3_t, mut sql: &mut dc_sqlite3_t,
) -> libc::c_int { ) -> libc::c_int {
let mut success: libc::c_int = 0i32; let mut success: libc::c_int = 0i32;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
@@ -315,7 +315,7 @@ pub unsafe fn dc_key_load_self_public(
pub unsafe fn dc_key_load_self_private( pub unsafe fn dc_key_load_self_private(
mut key: *mut dc_key_t, mut key: *mut dc_key_t,
mut self_addr: *const libc::c_char, mut self_addr: *const libc::c_char,
mut sql: *mut dc_sqlite3_t, mut sql: &mut dc_sqlite3_t,
) -> libc::c_int { ) -> libc::c_int {
let mut success: libc::c_int = 0i32; let mut success: libc::c_int = 0i32;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;

View File

@@ -56,7 +56,7 @@ pub unsafe fn dc_keyring_add(mut keyring: *mut dc_keyring_t, mut to_add: *mut dc
pub unsafe fn dc_keyring_load_self_private_for_decrypting( pub unsafe fn dc_keyring_load_self_private_for_decrypting(
mut keyring: *mut dc_keyring_t, mut keyring: *mut dc_keyring_t,
mut self_addr: *const libc::c_char, mut self_addr: *const libc::c_char,
mut sql: *mut dc_sqlite3_t, mut sql: &mut dc_sqlite3_t,
) -> libc::c_int { ) -> libc::c_int {
if keyring.is_null() || self_addr.is_null() || sql.is_null() { if keyring.is_null() || self_addr.is_null() || sql.is_null() {
return 0i32; return 0i32;

View File

@@ -61,7 +61,7 @@ pub unsafe fn dc_loginparam_empty(mut loginparam: *mut dc_loginparam_t) {
} }
pub unsafe fn dc_loginparam_read( pub unsafe fn dc_loginparam_read(
mut loginparam: *mut dc_loginparam_t, mut loginparam: *mut dc_loginparam_t,
mut sql: *mut dc_sqlite3_t, mut sql: &mut dc_sqlite3_t,
mut prefix: *const libc::c_char, mut prefix: *const libc::c_char,
) { ) {
let mut key: *mut libc::c_char = 0 as *mut libc::c_char; let mut key: *mut libc::c_char = 0 as *mut libc::c_char;
@@ -140,7 +140,7 @@ pub unsafe fn dc_loginparam_read(
} }
pub unsafe fn dc_loginparam_write( pub unsafe fn dc_loginparam_write(
mut loginparam: *const dc_loginparam_t, mut loginparam: *const dc_loginparam_t,
mut sql: *mut dc_sqlite3_t, mut sql: &mut dc_sqlite3_t,
mut prefix: *const libc::c_char, mut prefix: *const libc::c_char,
) { ) {
let mut key: *mut libc::c_char = 0 as *mut libc::c_char; let mut key: *mut libc::c_char = 0 as *mut libc::c_char;

View File

@@ -19,7 +19,7 @@ use crate::x::*;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub struct dc_mimefactory_t { pub struct dc_mimefactory_t<'a> {
pub from_addr: *mut libc::c_char, pub from_addr: *mut libc::c_char,
pub from_displayname: *mut libc::c_char, pub from_displayname: *mut libc::c_char,
pub selfstatus: *mut libc::c_char, pub selfstatus: *mut libc::c_char,
@@ -28,8 +28,8 @@ pub struct dc_mimefactory_t {
pub timestamp: time_t, pub timestamp: time_t,
pub rfc724_mid: *mut libc::c_char, pub rfc724_mid: *mut libc::c_char,
pub loaded: dc_mimefactory_loaded_t, pub loaded: dc_mimefactory_loaded_t,
pub msg: *mut dc_msg_t, pub msg: *mut dc_msg_t<'a>,
pub chat: *mut dc_chat_t, pub chat: *mut dc_chat_t<'a>,
pub increation: libc::c_int, pub increation: libc::c_int,
pub in_reply_to: *mut libc::c_char, pub in_reply_to: *mut libc::c_char,
pub references: *mut libc::c_char, pub references: *mut libc::c_char,
@@ -39,7 +39,7 @@ pub struct dc_mimefactory_t {
pub out_gossiped: libc::c_int, pub out_gossiped: libc::c_int,
pub out_last_added_location_id: uint32_t, pub out_last_added_location_id: uint32_t,
pub error: *mut libc::c_char, pub error: *mut libc::c_char,
pub context: *mut dc_context_t, pub context: &'a dc_context_t,
} }
pub type dc_mimefactory_loaded_t = libc::c_uint; pub type dc_mimefactory_loaded_t = libc::c_uint;
@@ -47,7 +47,10 @@ pub const DC_MF_MDN_LOADED: dc_mimefactory_loaded_t = 2;
pub const DC_MF_MSG_LOADED: dc_mimefactory_loaded_t = 1; pub const DC_MF_MSG_LOADED: dc_mimefactory_loaded_t = 1;
pub const DC_MF_NOTHING_LOADED: dc_mimefactory_loaded_t = 0; pub const DC_MF_NOTHING_LOADED: dc_mimefactory_loaded_t = 0;
pub unsafe fn dc_mimefactory_init(mut factory: *mut dc_mimefactory_t, mut context: &dc_context_t) { pub unsafe fn dc_mimefactory_init<'a>(
factory: *mut dc_mimefactory_t<'a>,
context: &'a dc_context_t,
) {
if factory.is_null() || context.is_null() { if factory.is_null() || context.is_null() {
return; return;
} }

View File

@@ -20,7 +20,7 @@ use crate::x::*;
/* * the structure behind dc_msg_t */ /* * the structure behind dc_msg_t */
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
#[repr(C)] #[repr(C)]
pub struct dc_msg_t { pub struct dc_msg_t<'a> {
pub magic: uint32_t, pub magic: uint32_t,
pub id: uint32_t, pub id: uint32_t,
pub from_id: uint32_t, pub from_id: uint32_t,
@@ -34,7 +34,7 @@ pub struct dc_msg_t {
pub timestamp_sent: time_t, pub timestamp_sent: time_t,
pub timestamp_rcvd: time_t, pub timestamp_rcvd: time_t,
pub text: *mut libc::c_char, pub text: *mut libc::c_char,
pub context: *mut dc_context_t, pub context: &'a dc_context_t,
pub rfc724_mid: *mut libc::c_char, pub rfc724_mid: *mut libc::c_char,
pub in_reply_to: *mut libc::c_char, pub in_reply_to: *mut libc::c_char,
pub server_folder: *mut libc::c_char, pub server_folder: *mut libc::c_char,
@@ -292,9 +292,10 @@ pub unsafe fn dc_get_msg_info(
free(rawtxt as *mut libc::c_void); free(rawtxt as *mut libc::c_void);
return ret.buf; return ret.buf;
} }
pub unsafe fn dc_msg_new_untyped(mut context: &dc_context_t) -> *mut dc_msg_t { pub unsafe fn dc_msg_new_untyped<'a>(context: &'a dc_context_t) -> *mut dc_msg_t<'a> {
return dc_msg_new(context, 0i32); dc_msg_new(context, 0i32)
} }
/* * /* *
* @class dc_msg_t * @class dc_msg_t
* *
@@ -305,7 +306,10 @@ pub unsafe fn dc_msg_new_untyped(mut context: &dc_context_t) -> *mut dc_msg_t {
// to check if a mail was sent, use dc_msg_is_sent() // to check if a mail was sent, use dc_msg_is_sent()
// approx. max. lenght returned by dc_msg_get_text() // approx. max. lenght returned by dc_msg_get_text()
// approx. max. lenght returned by dc_get_msg_info() // approx. max. lenght returned by dc_get_msg_info()
pub unsafe fn dc_msg_new(mut context: &dc_context_t, mut viewtype: libc::c_int) -> *mut dc_msg_t { pub unsafe fn dc_msg_new<'a>(
mut context: &'a dc_context_t,
mut viewtype: libc::c_int,
) -> *mut dc_msg_t<'a> {
let mut msg: *mut dc_msg_t = 0 as *mut dc_msg_t; let mut msg: *mut dc_msg_t = 0 as *mut dc_msg_t;
msg = calloc(1, ::std::mem::size_of::<dc_msg_t>()) as *mut dc_msg_t; msg = calloc(1, ::std::mem::size_of::<dc_msg_t>()) as *mut dc_msg_t;
if msg.is_null() { if msg.is_null() {
@@ -501,7 +505,7 @@ pub unsafe fn dc_msg_get_timestamp(mut msg: *const dc_msg_t) -> time_t {
} }
pub unsafe fn dc_msg_load_from_db( pub unsafe fn dc_msg_load_from_db(
mut msg: *mut dc_msg_t, mut msg: *mut dc_msg_t,
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut id: uint32_t, mut id: uint32_t,
) -> libc::c_int { ) -> libc::c_int {
let mut success: libc::c_int = 0i32; let mut success: libc::c_int = 0i32;
@@ -605,7 +609,7 @@ unsafe fn dc_msg_set_from_stmt(
return 1i32; return 1i32;
} }
pub unsafe fn dc_get_mime_headers( pub unsafe fn dc_get_mime_headers(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut msg_id: uint32_t, mut msg_id: uint32_t,
) -> *mut libc::c_char { ) -> *mut libc::c_char {
let mut eml: &libc::c_char = 0 as *mut libc::c_char; let mut eml: &libc::c_char = 0 as *mut libc::c_char;
@@ -624,7 +628,7 @@ pub unsafe fn dc_get_mime_headers(
return eml; return eml;
} }
pub unsafe fn dc_delete_msgs( pub unsafe fn dc_delete_msgs(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut msg_ids: *const uint32_t, mut msg_ids: *const uint32_t,
mut msg_cnt: libc::c_int, mut msg_cnt: libc::c_int,
) { ) {
@@ -635,7 +639,6 @@ pub unsafe fn dc_delete_msgs(
{ {
return; return;
} }
dc_sqlite3_begin_transaction((*context).sql);
let mut i: libc::c_int = 0i32; let mut i: libc::c_int = 0i32;
while i < msg_cnt { while i < msg_cnt {
dc_update_msg_chat_id(context, *msg_ids.offset(i as isize), 3i32 as uint32_t); dc_update_msg_chat_id(context, *msg_ids.offset(i as isize), 3i32 as uint32_t);
@@ -648,7 +651,7 @@ pub unsafe fn dc_delete_msgs(
); );
i += 1 i += 1
} }
dc_sqlite3_commit((*context).sql);
if 0 != msg_cnt { if 0 != msg_cnt {
((*context).cb)( ((*context).cb)(
context, context,
@@ -675,7 +678,7 @@ pub unsafe fn dc_update_msg_chat_id(
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
} }
pub unsafe fn dc_markseen_msgs( pub unsafe fn dc_markseen_msgs(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut msg_ids: *const uint32_t, mut msg_ids: *const uint32_t,
mut msg_cnt: libc::c_int, mut msg_cnt: libc::c_int,
) { ) {
@@ -690,7 +693,6 @@ pub unsafe fn dc_markseen_msgs(
|| msg_ids.is_null() || msg_ids.is_null()
|| msg_cnt <= 0i32) || msg_cnt <= 0i32)
{ {
dc_sqlite3_begin_transaction((*context).sql);
transaction_pending = 1i32; transaction_pending = 1i32;
stmt = stmt =
dc_sqlite3_prepare((*context).sql, dc_sqlite3_prepare((*context).sql,
@@ -728,7 +730,6 @@ pub unsafe fn dc_markseen_msgs(
} }
i += 1 i += 1
} }
dc_sqlite3_commit((*context).sql);
transaction_pending = 0i32; transaction_pending = 0i32;
if 0 != send_event { if 0 != send_event {
((*context).cb)( ((*context).cb)(
@@ -739,18 +740,15 @@ pub unsafe fn dc_markseen_msgs(
); );
} }
} }
if 0 != transaction_pending {
dc_sqlite3_rollback((*context).sql);
}
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
} }
pub unsafe fn dc_update_msg_state( pub unsafe fn dc_update_msg_state(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut msg_id: uint32_t, mut msg_id: uint32_t,
mut state: libc::c_int, mut state: libc::c_int,
) { ) {
let mut stmt: &sqlite3_stmt = dc_sqlite3_prepare( let mut stmt: &sqlite3_stmt = dc_sqlite3_prepare(
(*context).sql, &mut context.sql.lock().unwrap(),
b"UPDATE msgs SET state=? WHERE id=?;\x00" as *const u8 as *const libc::c_char, b"UPDATE msgs SET state=? WHERE id=?;\x00" as *const u8 as *const libc::c_char,
); );
sqlite3_bind_int(stmt, 1i32, state); sqlite3_bind_int(stmt, 1i32, state);
@@ -759,7 +757,7 @@ pub unsafe fn dc_update_msg_state(
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
} }
pub unsafe fn dc_star_msgs( pub unsafe fn dc_star_msgs(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut msg_ids: *const uint32_t, mut msg_ids: *const uint32_t,
mut msg_cnt: libc::c_int, mut msg_cnt: libc::c_int,
mut star: libc::c_int, mut star: libc::c_int,
@@ -772,7 +770,6 @@ pub unsafe fn dc_star_msgs(
{ {
return; return;
} }
dc_sqlite3_begin_transaction((*context).sql);
let mut stmt: &sqlite3_stmt = dc_sqlite3_prepare( let mut stmt: &sqlite3_stmt = dc_sqlite3_prepare(
(*context).sql, (*context).sql,
b"UPDATE msgs SET starred=? WHERE id=?;\x00" as *const u8 as *const libc::c_char, b"UPDATE msgs SET starred=? WHERE id=?;\x00" as *const u8 as *const libc::c_char,
@@ -786,23 +783,21 @@ pub unsafe fn dc_star_msgs(
i += 1 i += 1
} }
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
dc_sqlite3_commit((*context).sql);
} }
pub unsafe fn dc_get_msg(mut context: *mut dc_context_t, mut msg_id: uint32_t) -> *mut dc_msg_t { pub unsafe fn dc_get_msg<'a>(context: &'a dc_context_t, msg_id: uint32_t) -> *mut dc_msg_t<'a> {
let mut success: libc::c_int = 0i32; let mut success: libc::c_int = 0i32;
let mut obj: *mut dc_msg_t = dc_msg_new_untyped(context); let mut obj: *mut dc_msg_t = dc_msg_new_untyped(context);
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
if !(0 == dc_msg_load_from_db(obj, context, msg_id)) { if !(0 == dc_msg_load_from_db(obj, context, msg_id)) {
success = 1i32 success = 1i32
} }
}
if 0 != success { if 0 != success {
return obj; obj
} else { } else {
dc_msg_unref(obj); dc_msg_unref(obj);
return 0 as &dc_msg_t; 0 as &dc_msg_t
}; }
} }
pub unsafe fn dc_msg_get_id(mut msg: *const dc_msg_t) -> uint32_t { pub unsafe fn dc_msg_get_id(mut msg: *const dc_msg_t) -> uint32_t {
if msg.is_null() || (*msg).magic != 0x11561156i32 as libc::c_uint { if msg.is_null() || (*msg).magic != 0x11561156i32 as libc::c_uint {
return 0i32 as uint32_t; return 0i32 as uint32_t;
@@ -970,7 +965,7 @@ pub unsafe fn dc_msg_get_summarytext_by_raw(
mut text: *const libc::c_char, mut text: *const libc::c_char,
mut param: *mut dc_param_t, mut param: *mut dc_param_t,
mut approx_characters: libc::c_int, mut approx_characters: libc::c_int,
mut context: *mut dc_context_t, mut context: &dc_context_t,
) -> *mut libc::c_char { ) -> *mut libc::c_char {
/* get a summary text, result must be free()'d, never returns NULL. */ /* get a summary text, result must be free()'d, never returns NULL. */
let mut ret: &libc::c_char = 0 as *mut libc::c_char; let mut ret: &libc::c_char = 0 as *mut libc::c_char;
@@ -1219,15 +1214,16 @@ pub unsafe fn dc_msg_save_param_to_disk(mut msg: *mut dc_msg_t) {
sqlite3_step(stmt); sqlite3_step(stmt);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
} }
pub unsafe fn dc_msg_new_load( pub unsafe fn dc_msg_new_load<'a>(
mut context: *mut dc_context_t, context: &'a dc_context_t,
mut msg_id: uint32_t, msg_id: uint32_t,
) -> *mut dc_msg_t { ) -> *mut dc_msg_t<'a> {
let mut msg: &dc_msg_t = dc_msg_new_untyped(context); let mut msg: &dc_msg_t = dc_msg_new_untyped(context);
dc_msg_load_from_db(msg, context, msg_id); dc_msg_load_from_db(msg, context, msg_id);
return msg; msg
} }
pub unsafe fn dc_delete_msg_from_db(mut context: *mut dc_context_t, mut msg_id: uint32_t) {
pub unsafe fn dc_delete_msg_from_db(context: &dc_context_t, mut msg_id: uint32_t) {
let mut msg: *mut dc_msg_t = dc_msg_new_untyped(context); let mut msg: *mut dc_msg_t = dc_msg_new_untyped(context);
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
if !(0 == dc_msg_load_from_db(msg, context, msg_id)) { if !(0 == dc_msg_load_from_db(msg, context, msg_id)) {
@@ -1256,7 +1252,7 @@ Do not use too long subjects - we add a tag after the subject which gets truncat
It should also be very clear, the subject is _not_ the whole message. It should also be very clear, the subject is _not_ the whole message.
The value is also used for CC:-summaries */ The value is also used for CC:-summaries */
// Context functions to work with messages // Context functions to work with messages
pub unsafe fn dc_msg_exists(mut context: *mut dc_context_t, mut msg_id: uint32_t) -> libc::c_int { pub unsafe fn dc_msg_exists(mut context: &dc_context_t, mut msg_id: uint32_t) -> libc::c_int {
let mut msg_exists: libc::c_int = 0i32; let mut msg_exists: libc::c_int = 0i32;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
if !(context.is_null() if !(context.is_null()
@@ -1295,7 +1291,7 @@ pub unsafe fn dc_update_msg_move_state(
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
} }
pub unsafe fn dc_set_msg_failed( pub unsafe fn dc_set_msg_failed(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut msg_id: uint32_t, mut msg_id: uint32_t,
mut error: *const libc::c_char, mut error: *const libc::c_char,
) { ) {
@@ -1334,7 +1330,7 @@ pub unsafe fn dc_set_msg_failed(
} }
/* returns 1 if an event should be send */ /* returns 1 if an event should be send */
pub unsafe fn dc_mdn_from_ext( pub unsafe fn dc_mdn_from_ext(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut from_id: uint32_t, mut from_id: uint32_t,
mut rfc724_mid: *const libc::c_char, mut rfc724_mid: *const libc::c_char,
mut timestamp_sent: time_t, mut timestamp_sent: time_t,
@@ -1443,7 +1439,7 @@ pub unsafe fn dc_mdn_from_ext(
return read_by_all; return read_by_all;
} }
/* the number of messages assigned to real chat (!=deaddrop, !=trash) */ /* the number of messages assigned to real chat (!=deaddrop, !=trash) */
pub unsafe fn dc_get_real_msg_cnt(mut context: *mut dc_context_t) -> size_t { pub unsafe fn dc_get_real_msg_cnt(mut context: &dc_context_t) -> size_t {
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
let mut ret: size_t = 0i32 as size_t; let mut ret: size_t = 0i32 as size_t;
if !(*(*context).sql).cobj.is_null() { if !(*(*context).sql).cobj.is_null() {
@@ -1506,7 +1502,7 @@ pub unsafe fn dc_rfc724_mid_cnt(
return ret; return ret;
} }
pub unsafe fn dc_rfc724_mid_exists( pub unsafe fn dc_rfc724_mid_exists(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut rfc724_mid: *const libc::c_char, mut rfc724_mid: *const libc::c_char,
mut ret_server_folder: *mut *mut libc::c_char, mut ret_server_folder: *mut *mut libc::c_char,
mut ret_server_uid: &uint32_t, mut ret_server_uid: &uint32_t,
@@ -1544,7 +1540,7 @@ pub unsafe fn dc_rfc724_mid_exists(
return ret; return ret;
} }
pub unsafe fn dc_update_server_uid( pub unsafe fn dc_update_server_uid(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut rfc724_mid: *const libc::c_char, mut rfc724_mid: *const libc::c_char,
mut server_folder: *const libc::c_char, mut server_folder: *const libc::c_char,
mut server_uid: uint32_t, mut server_uid: uint32_t,

View File

@@ -107,7 +107,6 @@ pub unsafe fn dc_receive_imf(
sent_timestamp = dc_timestamp_from_date((*orig_date).dt_date_time) sent_timestamp = dc_timestamp_from_date((*orig_date).dt_date_time)
} }
} }
dc_sqlite3_begin_transaction((*context).sql);
transaction_pending = 1i32; transaction_pending = 1i32;
field = dc_mimeparser_lookup_field( field = dc_mimeparser_lookup_field(
mime_parser, mime_parser,
@@ -226,7 +225,6 @@ pub unsafe fn dc_receive_imf(
if strcmp(old_server_folder, server_folder) != 0i32 if strcmp(old_server_folder, server_folder) != 0i32
|| old_server_uid != server_uid || old_server_uid != server_uid
{ {
dc_sqlite3_rollback((*context).sql);
transaction_pending = 0i32; transaction_pending = 0i32;
dc_update_server_uid( dc_update_server_uid(
context, context,
@@ -282,7 +280,6 @@ pub unsafe fn dc_receive_imf(
msgrmsg = 1i32; msgrmsg = 1i32;
chat_id = 0i32 as uint32_t; chat_id = 0i32 as uint32_t;
allow_creation = 1i32; allow_creation = 1i32;
dc_sqlite3_commit((*context).sql);
let mut handshake: libc::c_int = dc_handle_securejoin_handshake( let mut handshake: libc::c_int = dc_handle_securejoin_handshake(
context, context,
mime_parser, mime_parser,
@@ -293,7 +290,6 @@ pub unsafe fn dc_receive_imf(
add_delete_job = handshake & 0x4i32; add_delete_job = handshake & 0x4i32;
state = 16i32 state = 16i32
} }
dc_sqlite3_begin_transaction((*context).sql);
} }
let mut test_normal_chat_id: uint32_t = 0i32 as uint32_t; let mut test_normal_chat_id: uint32_t = 0i32 as uint32_t;
let mut test_normal_chat_id_blocked: libc::c_int = 0i32; let mut test_normal_chat_id_blocked: libc::c_int = 0i32;
@@ -988,15 +984,11 @@ pub unsafe fn dc_receive_imf(
0i32, 0i32,
); );
} }
dc_sqlite3_commit((*context).sql);
transaction_pending = 0i32 transaction_pending = 0i32
} }
} }
} }
} }
if 0 != transaction_pending {
dc_sqlite3_rollback((*context).sql);
}
dc_mimeparser_unref(mime_parser); dc_mimeparser_unref(mime_parser);
free(rfc724_mid as *mut libc::c_void); free(rfc724_mid as *mut libc::c_void);
free(mime_in_reply_to as *mut libc::c_void); free(mime_in_reply_to as *mut libc::c_void);

View File

@@ -1034,7 +1034,7 @@ unsafe fn encrypted_and_signed(
return 1i32; return 1i32;
} }
pub unsafe fn dc_handle_degrade_event( pub unsafe fn dc_handle_degrade_event(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut peerstate: *mut dc_apeerstate_t, mut peerstate: *mut dc_apeerstate_t,
) { ) {
let mut stmt: &sqlite3_stmt = 0 as *mut sqlite3_stmt; let mut stmt: &sqlite3_stmt = 0 as *mut sqlite3_stmt;

View File

@@ -1,6 +1,5 @@
use libc; use libc;
use crate::constants::*;
use crate::dc_apeerstate::*; use crate::dc_apeerstate::*;
use crate::dc_context::dc_context_t; use crate::dc_context::dc_context_t;
use crate::dc_hash::*; use crate::dc_hash::*;
@@ -10,6 +9,9 @@ use crate::dc_tools::*;
use crate::types::*; use crate::types::*;
use crate::x::*; use crate::x::*;
const DC_OPEN_READONLY: usize = 0x01;
const DC_HOUSEKEEPING_DELAY_SEC: usize = 10;
/// A simple wrapper around the underlying Sqlite3 object. /// A simple wrapper around the underlying Sqlite3 object.
#[repr(C)] #[repr(C)]
pub struct dc_sqlite3_t { pub struct dc_sqlite3_t {
@@ -42,7 +44,7 @@ pub unsafe fn dc_sqlite3_close(context: &dc_context_t, sql: &mut dc_sqlite3_t) {
} }
pub unsafe fn dc_sqlite3_open( pub unsafe fn dc_sqlite3_open(
context: &context, context: &dc_context_t,
sql: &mut dc_sqlite3_t, sql: &mut dc_sqlite3_t,
dbfile: *const libc::c_char, dbfile: *const libc::c_char,
flags: libc::c_int, flags: libc::c_int,
@@ -71,7 +73,7 @@ pub unsafe fn dc_sqlite3_open(
dbfile, dbfile,
&mut sql.cobj, &mut sql.cobj,
SQLITE_OPEN_FULLMUTEX SQLITE_OPEN_FULLMUTEX
| (if (flags & DC_OPEN_READONLY) { | (if flags & DC_OPEN_READONLY {
SQLITE_OPEN_READONLY SQLITE_OPEN_READONLY
} else { } else {
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE
@@ -928,7 +930,7 @@ pub unsafe fn dc_sqlite3_open(
// handle configurations, private // handle configurations, private
pub unsafe fn dc_sqlite3_set_config( pub unsafe fn dc_sqlite3_set_config(
context: &context, context: &dc_context_t,
sql: &mut dc_sqlite3_t, sql: &mut dc_sqlite3_t,
key: *const libc::c_char, key: *const libc::c_char,
value: *const libc::c_char, value: *const libc::c_char,
@@ -1039,7 +1041,7 @@ pub unsafe fn dc_sqlite3_prepare(
} }
pub unsafe extern "C" fn dc_sqlite3_log_error( pub unsafe extern "C" fn dc_sqlite3_log_error(
context: &context, context: &dc_context_t,
sql: &dc_sqlite3_t, sql: &dc_sqlite3_t,
msg_format: *const libc::c_char, msg_format: *const libc::c_char,
va: ... va: ...
@@ -1159,6 +1161,7 @@ pub unsafe fn dc_sqlite3_get_config_int(
} }
pub unsafe fn dc_sqlite3_table_exists( pub unsafe fn dc_sqlite3_table_exists(
context: &dc_context_t,
sql: &mut dc_sqlite3_t, sql: &mut dc_sqlite3_t,
name: *const libc::c_char, name: *const libc::c_char,
) -> libc::c_int { ) -> libc::c_int {
@@ -1197,7 +1200,7 @@ pub unsafe fn dc_sqlite3_table_exists(
} }
pub unsafe fn dc_sqlite3_set_config_int64( pub unsafe fn dc_sqlite3_set_config_int64(
sql: &mutdc_sqlite3_t, sql: &mut dc_sqlite3_t,
key: *const libc::c_char, key: *const libc::c_char,
value: int64_t, value: int64_t,
) -> libc::c_int { ) -> libc::c_int {

View File

@@ -12,11 +12,12 @@ The result must be free()'d! */
pub unsafe fn dc_stock_str(mut context: &dc_context_t, mut id: libc::c_int) -> *mut libc::c_char { pub unsafe fn dc_stock_str(mut context: &dc_context_t, mut id: libc::c_int) -> *mut libc::c_char {
return get_string(context, id, 0i32); return get_string(context, id, 0i32);
} }
unsafe fn get_string( unsafe fn get_string(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut id: libc::c_int, mut id: libc::c_int,
mut qty: libc::c_int, mut qty: libc::c_int,
) -> &libc::c_char { ) -> *mut libc::c_char {
let mut ret: *mut libc::c_char = 0 as *mut libc::c_char; let mut ret: *mut libc::c_char = 0 as *mut libc::c_char;
if !context.is_null() { if !context.is_null() {
ret = ((*context).cb)( ret = ((*context).cb)(
@@ -212,10 +213,10 @@ unsafe fn default_string(mut id: libc::c_int) -> *mut libc::c_char {
/* Replaces the first `%1$s` in the given String-ID by the given value. /* Replaces the first `%1$s` in the given String-ID by the given value.
The result must be free()'d! */ The result must be free()'d! */
pub unsafe fn dc_stock_str_repl_string( pub unsafe fn dc_stock_str_repl_string(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut id: libc::c_int, mut id: libc::c_int,
mut to_insert: *const libc::c_char, mut to_insert: *const libc::c_char,
) -> &libc::c_char { ) -> *mut libc::c_char {
let mut ret: *mut libc::c_char = get_string(context, id, 0i32); let mut ret: *mut libc::c_char = get_string(context, id, 0i32);
dc_str_replace( dc_str_replace(
&mut ret, &mut ret,
@@ -230,10 +231,10 @@ pub unsafe fn dc_stock_str_repl_string(
return ret; return ret;
} }
pub unsafe fn dc_stock_str_repl_int( pub unsafe fn dc_stock_str_repl_int(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut id: libc::c_int, mut id: libc::c_int,
mut to_insert_int: libc::c_int, mut to_insert_int: libc::c_int,
) -> &libc::c_char { ) -> *mut libc::c_char {
let mut ret: *mut libc::c_char = get_string(context, id, to_insert_int); let mut ret: *mut libc::c_char = get_string(context, id, to_insert_int);
let mut to_insert_str: *mut libc::c_char = dc_mprintf( let mut to_insert_str: *mut libc::c_char = dc_mprintf(
b"%i\x00" as *const u8 as *const libc::c_char, b"%i\x00" as *const u8 as *const libc::c_char,
@@ -255,11 +256,11 @@ pub unsafe fn dc_stock_str_repl_int(
/* Replaces the first `%1$s` and `%2$s` in the given String-ID by the two given strings. /* Replaces the first `%1$s` and `%2$s` in the given String-ID by the two given strings.
The result must be free()'d! */ The result must be free()'d! */
pub unsafe fn dc_stock_str_repl_string2( pub unsafe fn dc_stock_str_repl_string2(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut id: libc::c_int, mut id: libc::c_int,
mut to_insert: *const libc::c_char, mut to_insert: *const libc::c_char,
mut to_insert2: *const libc::c_char, mut to_insert2: *const libc::c_char,
) -> &libc::c_char { ) -> *mut libc::c_char {
let mut ret: *mut libc::c_char = get_string(context, id, 0i32); let mut ret: *mut libc::c_char = get_string(context, id, 0i32);
dc_str_replace( dc_str_replace(
&mut ret, &mut ret,
@@ -285,12 +286,12 @@ pub unsafe fn dc_stock_str_repl_string2(
} }
/* Misc. */ /* Misc. */
pub unsafe fn dc_stock_system_msg( pub unsafe fn dc_stock_system_msg(
mut context: *mut dc_context_t, mut context: &dc_context_t,
mut str_id: libc::c_int, mut str_id: libc::c_int,
mut param1: *const libc::c_char, mut param1: *const libc::c_char,
mut param2: *const libc::c_char, mut param2: *const libc::c_char,
mut from_id: uint32_t, mut from_id: uint32_t,
) -> &libc::c_char { ) -> *mut libc::c_char {
let mut ret: *mut libc::c_char = 0 as *mut libc::c_char; let mut ret: *mut libc::c_char = 0 as *mut libc::c_char;
let mut mod_contact: *mut dc_contact_t = 0 as *mut dc_contact_t; let mut mod_contact: *mut dc_contact_t = 0 as *mut dc_contact_t;
let mut mod_displayname: *mut libc::c_char = 0 as *mut libc::c_char; let mut mod_displayname: *mut libc::c_char = 0 as *mut libc::c_char;

View File

@@ -3,7 +3,6 @@ use libc;
use crate::constants::Event; use crate::constants::Event;
use crate::dc_context::dc_context_t; use crate::dc_context::dc_context_t;
use crate::dc_imap::dc_imap_t;
use crate::x::*; use crate::x::*;
pub use libc::{ pub use libc::{
@@ -1173,7 +1172,7 @@ pub type nlink_t = __uint16_t;
pub type dc_receive_imf_t = Option< pub type dc_receive_imf_t = Option<
unsafe fn( unsafe fn(
_: *mut dc_imap_t, _: &dc_context_t,
_: *const libc::c_char, _: *const libc::c_char,
_: size_t, _: size_t,
_: *const libc::c_char, _: *const libc::c_char,
@@ -1181,38 +1180,28 @@ pub type dc_receive_imf_t = Option<
_: uint32_t, _: uint32_t,
) -> (), ) -> (),
>; >;
/* Purpose: Reading from IMAP servers with no dependencies to the database. /* Purpose: Reading from IMAP servers with no dependencies to the database.
dc_context_t is only used for logging and to get information about dc_context_t is only used for logging and to get information about
the online state. */ the online state. */
pub type dc_precheck_imf_t = Option< pub type dc_precheck_imf_t = Option<
unsafe fn( unsafe fn(
_: *mut dc_imap_t, _: &dc_context_t,
_: *const libc::c_char, _: *const libc::c_char,
_: *const libc::c_char, _: *const libc::c_char,
_: uint32_t, _: uint32_t,
) -> libc::c_int, ) -> libc::c_int,
>; >;
pub type dc_set_config_t = pub type dc_set_config_t =
Option<unsafe fn(_: *mut dc_imap_t, _: *const libc::c_char, _: *const libc::c_char) -> ()>; Option<unsafe fn(_: &dc_context_t, _: *const libc::c_char, _: *const libc::c_char) -> ()>;
pub type dc_get_config_t = Option< pub type dc_get_config_t = Option<
unsafe fn( unsafe fn(
_: *mut dc_imap_t, _: &dc_context_t,
_: *const libc::c_char, _: *const libc::c_char,
_: *const libc::c_char, _: *const libc::c_char,
) -> *mut libc::c_char, ) -> *mut libc::c_char,
>; >;
/* ** library-private **********************************************************/
/* *
* Library-internal.
*/
#[derive(Copy, Clone)]
#[repr(C)]
pub struct _dc_sqlite3 {
pub cobj: *mut sqlite3,
pub context: &dc_context_t,
}
#[inline] #[inline]
pub unsafe fn isascii(mut _c: libc::c_int) -> libc::c_int { pub unsafe fn isascii(mut _c: libc::c_int) -> libc::c_int {