mirror of
https://github.com/chatmail/core.git
synced 2026-04-21 15:36:30 +03:00
refactor: start using rust for allocations & locks
This commit is contained in:
@@ -793,11 +793,6 @@ pub unsafe fn dc_get_contact_encrinfo(
|
||||
dc_strbuilder_cat(&mut ret, p);
|
||||
free(p as *mut libc::c_void);
|
||||
if (*self_key).binary.is_null() {
|
||||
dc_pgp_rand_seed(
|
||||
context,
|
||||
(*peerstate).addr as *const libc::c_void,
|
||||
strlen((*peerstate).addr),
|
||||
);
|
||||
dc_ensure_secret_key_exists(context);
|
||||
dc_key_load_self_public(self_key, (*loginparam).addr, (*context).sql);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -527,17 +527,6 @@ unsafe fn load_or_generate_self_public_key(
|
||||
} else {
|
||||
key_creation_here = 1i32;
|
||||
s_in_key_creation = 1i32;
|
||||
/* seed the random generator */
|
||||
let mut seed: [uintptr_t; 4] = [0; 4];
|
||||
seed[0usize] = time(0 as *mut time_t) as uintptr_t;
|
||||
seed[1usize] = seed.as_mut_ptr() as uintptr_t;
|
||||
seed[2usize] = public_key as uintptr_t;
|
||||
seed[3usize] = pthread_self() as uintptr_t;
|
||||
dc_pgp_rand_seed(
|
||||
context,
|
||||
seed.as_mut_ptr() as *const libc::c_void,
|
||||
::std::mem::size_of::<[uintptr_t; 4]>(),
|
||||
);
|
||||
if !random_data_mime.is_null() {
|
||||
let mut random_data_mmap: *mut MMAPString = 0 as *mut MMAPString;
|
||||
let mut col: libc::c_int = 0i32;
|
||||
@@ -546,11 +535,6 @@ unsafe fn load_or_generate_self_public_key(
|
||||
current_block = 10496152961502316708;
|
||||
} else {
|
||||
mailmime_write_mem(random_data_mmap, &mut col, random_data_mime);
|
||||
dc_pgp_rand_seed(
|
||||
context,
|
||||
(*random_data_mmap).str_0 as *const libc::c_void,
|
||||
(*random_data_mmap).len,
|
||||
);
|
||||
mmap_string_free(random_data_mmap);
|
||||
current_block = 26972500619410423;
|
||||
}
|
||||
|
||||
105
src/dc_imap.rs
105
src/dc_imap.rs
@@ -1,4 +1,5 @@
|
||||
use libc;
|
||||
use std::sync::{Condvar, Mutex};
|
||||
|
||||
use crate::constants::Event;
|
||||
use crate::dc_context::dc_context_t;
|
||||
@@ -11,28 +12,25 @@ use crate::dc_tools::*;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[repr(C)]
|
||||
pub struct dc_imap_t {
|
||||
pub addr: *mut libc::c_char,
|
||||
pub imap_server: *mut libc::c_char,
|
||||
pub imap_port: libc::c_int,
|
||||
pub imap_port: i32,
|
||||
pub imap_user: *mut libc::c_char,
|
||||
pub imap_pw: *mut libc::c_char,
|
||||
pub server_flags: libc::c_int,
|
||||
pub connected: libc::c_int,
|
||||
pub server_flags: i32,
|
||||
pub connected: i32,
|
||||
pub etpan: *mut mailimap,
|
||||
pub idle_set_up: libc::c_int,
|
||||
pub idle_set_up: i32,
|
||||
pub selected_folder: *mut libc::c_char,
|
||||
pub selected_folder_needs_expunge: libc::c_int,
|
||||
pub should_reconnect: libc::c_int,
|
||||
pub can_idle: libc::c_int,
|
||||
pub has_xlist: libc::c_int,
|
||||
pub selected_folder_needs_expunge: i32,
|
||||
pub should_reconnect: i32,
|
||||
pub can_idle: i32,
|
||||
pub has_xlist: i32,
|
||||
pub imap_delimiter: libc::c_char,
|
||||
pub watch_folder: *mut libc::c_char,
|
||||
pub watch_cond: pthread_cond_t,
|
||||
pub watch_condmutex: pthread_mutex_t,
|
||||
pub watch_condflag: libc::c_int,
|
||||
pub watch: (Mutex<bool>, Condvar),
|
||||
pub fetch_type_prefetch: *mut mailimap_fetch_type,
|
||||
pub fetch_type_body: *mut mailimap_fetch_type,
|
||||
pub fetch_type_flags: *mut mailimap_fetch_type,
|
||||
@@ -40,66 +38,75 @@ pub struct dc_imap_t {
|
||||
pub set_config: dc_set_config_t,
|
||||
pub precheck_imf: dc_precheck_imf_t,
|
||||
pub receive_imf: dc_receive_imf_t,
|
||||
pub userData: *mut libc::c_void,
|
||||
// TODO: remove
|
||||
pub context: *mut dc_context_t,
|
||||
pub log_connect_errors: libc::c_int,
|
||||
pub skip_log_capabilities: libc::c_int,
|
||||
pub log_connect_errors: i32,
|
||||
pub skip_log_capabilities: i32,
|
||||
}
|
||||
|
||||
pub unsafe fn dc_imap_new(
|
||||
mut get_config: dc_get_config_t,
|
||||
mut set_config: dc_set_config_t,
|
||||
mut precheck_imf: dc_precheck_imf_t,
|
||||
mut receive_imf: dc_receive_imf_t,
|
||||
mut userData: *mut libc::c_void,
|
||||
mut context: *mut dc_context_t,
|
||||
) -> *mut dc_imap_t {
|
||||
let mut imap: *mut dc_imap_t = 0 as *mut dc_imap_t;
|
||||
imap = calloc(1, ::std::mem::size_of::<dc_imap_t>()) as *mut dc_imap_t;
|
||||
if imap.is_null() {
|
||||
exit(25i32);
|
||||
}
|
||||
(*imap).log_connect_errors = 1i32;
|
||||
(*imap).context = context;
|
||||
(*imap).get_config = get_config;
|
||||
(*imap).set_config = set_config;
|
||||
(*imap).precheck_imf = precheck_imf;
|
||||
(*imap).receive_imf = receive_imf;
|
||||
(*imap).userData = userData;
|
||||
pthread_mutex_init(
|
||||
&mut (*imap).watch_condmutex,
|
||||
0 as *const pthread_mutexattr_t,
|
||||
);
|
||||
pthread_cond_init(&mut (*imap).watch_cond, 0 as *const pthread_condattr_t);
|
||||
(*imap).watch_folder = calloc(1, 1) as *mut libc::c_char;
|
||||
(*imap).selected_folder = calloc(1, 1) as *mut libc::c_char;
|
||||
(*imap).fetch_type_prefetch = mailimap_fetch_type_new_fetch_att_list_empty();
|
||||
get_config: dc_get_config_t,
|
||||
set_config: dc_set_config_t,
|
||||
precheck_imf: dc_precheck_imf_t,
|
||||
receive_imf: dc_receive_imf_t,
|
||||
) -> dc_imap_t {
|
||||
let mut imap = dc_imap_t {
|
||||
addr: std::ptr::null_mut(),
|
||||
imap_server: std::ptr::null_mut(),
|
||||
imap_port: 0,
|
||||
imap_user: std::ptr::null_mut(),
|
||||
imap_pw: std::ptr::null_mut(),
|
||||
server_flags: 0,
|
||||
connected: 0,
|
||||
etpan: std::ptr::null_mut(),
|
||||
idle_set_up: 0,
|
||||
selected_folder: calloc(1, 1) as *mut libc::c_char,
|
||||
selected_folder_needs_expunge: 0,
|
||||
should_reconnect: 0,
|
||||
can_idle: 0,
|
||||
has_xlist: 0,
|
||||
imap_delimiter: 0 as libc::c_char,
|
||||
watch_folder: calloc(1, 1) as *mut libc::c_char,
|
||||
watch: (Mutex::new(false), Condvar::new()),
|
||||
fetch_type_prefetch: mailimap_fetch_type_new_fetch_att_list_empty(),
|
||||
fetch_type_body: mailimap_fetch_type_new_fetch_att_list_empty(),
|
||||
fetch_type_flags: mailimap_fetch_type_new_fetch_att_list_empty(),
|
||||
get_config,
|
||||
set_config,
|
||||
precheck_imf,
|
||||
receive_imf,
|
||||
// TODO: remove
|
||||
context: std::ptr::null_mut(),
|
||||
log_connect_errors: 1,
|
||||
skip_log_capabilities: 0,
|
||||
};
|
||||
mailimap_fetch_type_new_fetch_att_list_add(
|
||||
(*imap).fetch_type_prefetch,
|
||||
imap.fetch_type_prefetch,
|
||||
mailimap_fetch_att_new_uid(),
|
||||
);
|
||||
mailimap_fetch_type_new_fetch_att_list_add(
|
||||
(*imap).fetch_type_prefetch,
|
||||
imap.fetch_type_prefetch,
|
||||
mailimap_fetch_att_new_envelope(),
|
||||
);
|
||||
(*imap).fetch_type_body = mailimap_fetch_type_new_fetch_att_list_empty();
|
||||
|
||||
mailimap_fetch_type_new_fetch_att_list_add(
|
||||
(*imap).fetch_type_body,
|
||||
imap.fetch_type_body,
|
||||
mailimap_fetch_att_new_flags(),
|
||||
);
|
||||
mailimap_fetch_type_new_fetch_att_list_add(
|
||||
(*imap).fetch_type_body,
|
||||
imap.fetch_type_body,
|
||||
mailimap_fetch_att_new_body_peek_section(mailimap_section_new(
|
||||
0 as *mut mailimap_section_spec,
|
||||
)),
|
||||
);
|
||||
(*imap).fetch_type_flags = mailimap_fetch_type_new_fetch_att_list_empty();
|
||||
mailimap_fetch_type_new_fetch_att_list_add(
|
||||
(*imap).fetch_type_flags,
|
||||
mailimap_fetch_att_new_flags(),
|
||||
);
|
||||
return imap;
|
||||
|
||||
imap
|
||||
}
|
||||
|
||||
pub unsafe fn dc_imap_unref(mut imap: *mut dc_imap_t) {
|
||||
if imap.is_null() {
|
||||
return;
|
||||
|
||||
@@ -51,11 +51,13 @@ pub unsafe fn dc_perform_imap_jobs(mut context: *mut dc_context_t) {
|
||||
0i32,
|
||||
b"INBOX-jobs started...\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
pthread_mutex_lock(&mut (*context).inboxidle_condmutex);
|
||||
|
||||
let l = (*context).inboxidle_condmutex.lock().unwrap();
|
||||
let mut probe_imap_network: libc::c_int = (*context).probe_imap_network;
|
||||
(*context).probe_imap_network = 0i32;
|
||||
(*context).perform_inbox_jobs_needed = 0i32;
|
||||
pthread_mutex_unlock(&mut (*context).inboxidle_condmutex);
|
||||
drop(l);
|
||||
|
||||
dc_job_perform(context, 100i32, probe_imap_network);
|
||||
dc_log_info(
|
||||
context,
|
||||
@@ -934,9 +936,9 @@ pub unsafe fn dc_interrupt_imap_idle(mut context: *mut dc_context_t) {
|
||||
0i32,
|
||||
b"Interrupting IMAP-IDLE...\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
pthread_mutex_lock(&mut (*context).inboxidle_condmutex);
|
||||
let l = (*context).inboxidle_condmutex.lock().unwrap();
|
||||
(*context).perform_inbox_jobs_needed = 1i32;
|
||||
pthread_mutex_unlock(&mut (*context).inboxidle_condmutex);
|
||||
drop(l);
|
||||
dc_imap_interrupt_idle((*context).inbox);
|
||||
}
|
||||
unsafe fn dc_job_do_DC_JOB_DELETE_MSG_ON_IMAP(
|
||||
@@ -1058,7 +1060,7 @@ pub unsafe fn dc_perform_imap_idle(mut context: *mut dc_context_t) {
|
||||
return;
|
||||
}
|
||||
connect_to_inbox(context);
|
||||
pthread_mutex_lock(&mut (*context).inboxidle_condmutex);
|
||||
let l = (*context).inboxidle_condmutex.lock().unwrap();
|
||||
if 0 != (*context).perform_inbox_jobs_needed {
|
||||
dc_log_info(
|
||||
context,
|
||||
@@ -1066,10 +1068,10 @@ pub unsafe fn dc_perform_imap_idle(mut context: *mut dc_context_t) {
|
||||
b"INBOX-IDLE will not be started because of waiting jobs.\x00" as *const u8
|
||||
as *const libc::c_char,
|
||||
);
|
||||
pthread_mutex_unlock(&mut (*context).inboxidle_condmutex);
|
||||
drop(l);
|
||||
return;
|
||||
}
|
||||
pthread_mutex_unlock(&mut (*context).inboxidle_condmutex);
|
||||
drop(l);
|
||||
dc_log_info(
|
||||
context,
|
||||
0i32,
|
||||
@@ -1251,9 +1253,9 @@ pub unsafe fn dc_maybe_network(mut context: *mut dc_context_t) {
|
||||
pthread_mutex_lock(&mut (*context).smtpidle_condmutex);
|
||||
(*context).probe_smtp_network = 1i32;
|
||||
pthread_mutex_unlock(&mut (*context).smtpidle_condmutex);
|
||||
pthread_mutex_lock(&mut (*context).inboxidle_condmutex);
|
||||
let l = (*context).inboxidle_condmutex.lock().unwrap();
|
||||
(*context).probe_imap_network = 1i32;
|
||||
pthread_mutex_unlock(&mut (*context).inboxidle_condmutex);
|
||||
drop(l);
|
||||
dc_interrupt_smtp_idle(context);
|
||||
dc_interrupt_imap_idle(context);
|
||||
dc_interrupt_mvbox_idle(context);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::sync::{Condvar, Mutex};
|
||||
|
||||
use libc;
|
||||
|
||||
use crate::dc_configure::*;
|
||||
@@ -10,52 +12,47 @@ use crate::dc_tools::*;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
#[repr(C)]
|
||||
pub struct dc_jobthread_t {
|
||||
// TODO: remove
|
||||
pub context: *mut dc_context_t,
|
||||
pub name: *mut libc::c_char,
|
||||
pub folder_config_name: *mut libc::c_char,
|
||||
pub imap: *mut dc_imap_t,
|
||||
pub mutex: pthread_mutex_t,
|
||||
pub idle_cond: pthread_cond_t,
|
||||
pub idle_condflag: libc::c_int,
|
||||
pub idle: (Mutex<bool>, Condvar),
|
||||
pub jobs_needed: libc::c_int,
|
||||
pub suspended: libc::c_int,
|
||||
pub using_handle: libc::c_int,
|
||||
}
|
||||
|
||||
pub unsafe fn dc_jobthread_init(
|
||||
mut jobthread: *mut dc_jobthread_t,
|
||||
mut context: *mut dc_context_t,
|
||||
mut name: *const libc::c_char,
|
||||
mut folder_config_name: *const libc::c_char,
|
||||
) {
|
||||
if jobthread.is_null() || context.is_null() || name.is_null() {
|
||||
return;
|
||||
name: *const libc::c_char,
|
||||
folder_config_name: *const libc::c_char,
|
||||
imap: *mut dc_imap_t,
|
||||
) -> dc_jobthread_t {
|
||||
dc_jobthread_t {
|
||||
context: std::ptr::null_mut(),
|
||||
name: dc_strdup(name),
|
||||
folder_config_name: dc_strdup(folder_config_name),
|
||||
imap,
|
||||
idle: (Mutex::new(false), Condvar::new()),
|
||||
jobs_needed: 0i32,
|
||||
suspended: 0i32,
|
||||
using_handle: 0i32,
|
||||
}
|
||||
(*jobthread).context = context;
|
||||
(*jobthread).name = dc_strdup(name);
|
||||
(*jobthread).folder_config_name = dc_strdup(folder_config_name);
|
||||
(*jobthread).imap = 0 as *mut dc_imap_t;
|
||||
pthread_mutex_init(&mut (*jobthread).mutex, 0 as *const pthread_mutexattr_t);
|
||||
pthread_cond_init(&mut (*jobthread).idle_cond, 0 as *const pthread_condattr_t);
|
||||
(*jobthread).idle_condflag = 0i32;
|
||||
(*jobthread).jobs_needed = 0i32;
|
||||
(*jobthread).suspended = 0i32;
|
||||
(*jobthread).using_handle = 0i32;
|
||||
}
|
||||
|
||||
pub unsafe fn dc_jobthread_exit(mut jobthread: *mut dc_jobthread_t) {
|
||||
if jobthread.is_null() {
|
||||
return;
|
||||
}
|
||||
pthread_cond_destroy(&mut (*jobthread).idle_cond);
|
||||
pthread_mutex_destroy(&mut (*jobthread).mutex);
|
||||
|
||||
free((*jobthread).name as *mut libc::c_void);
|
||||
(*jobthread).name = 0 as *mut libc::c_char;
|
||||
free((*jobthread).folder_config_name as *mut libc::c_void);
|
||||
(*jobthread).folder_config_name = 0 as *mut libc::c_char;
|
||||
}
|
||||
|
||||
pub unsafe fn dc_jobthread_suspend(mut jobthread: *mut dc_jobthread_t, mut suspend: libc::c_int) {
|
||||
if jobthread.is_null() {
|
||||
return;
|
||||
|
||||
@@ -10,17 +10,7 @@ use crate::pgp as rpgp;
|
||||
use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
/* ** library-private **********************************************************/
|
||||
/* validation errors */
|
||||
/* misc. */
|
||||
pub unsafe fn dc_pgp_init() {}
|
||||
pub unsafe fn dc_pgp_exit() {}
|
||||
pub unsafe fn dc_pgp_rand_seed(
|
||||
_context: *mut dc_context_t,
|
||||
_buf: *const libc::c_void,
|
||||
_bytes: size_t,
|
||||
) {
|
||||
}
|
||||
|
||||
pub unsafe fn dc_split_armored_data(
|
||||
mut buf: *mut libc::c_char,
|
||||
|
||||
@@ -25,12 +25,12 @@ use crate::types::*;
|
||||
use crate::x::*;
|
||||
|
||||
pub unsafe fn dc_receive_imf(
|
||||
mut context: *mut dc_context_t,
|
||||
mut imf_raw_not_terminated: *const libc::c_char,
|
||||
mut imf_raw_bytes: size_t,
|
||||
mut server_folder: *const libc::c_char,
|
||||
mut server_uid: uint32_t,
|
||||
mut flags: uint32_t,
|
||||
context: &dc_context_t,
|
||||
imf_raw_not_terminated: *const libc::c_char,
|
||||
imf_raw_bytes: size_t,
|
||||
server_folder: *const libc::c_char,
|
||||
server_uid: uint32_t,
|
||||
flags: uint32_t,
|
||||
) {
|
||||
let mut current_block: u64;
|
||||
/* the function returns the number of created messages in the database */
|
||||
|
||||
@@ -16,21 +16,24 @@ pub struct dc_smtp_t {
|
||||
pub from: *mut libc::c_char,
|
||||
pub esmtp: libc::c_int,
|
||||
pub log_connect_errors: libc::c_int,
|
||||
// TODO: Remvoe
|
||||
pub context: *mut dc_context_t,
|
||||
pub error: *mut libc::c_char,
|
||||
pub error_etpan: libc::c_int,
|
||||
}
|
||||
|
||||
pub unsafe fn dc_smtp_new(mut context: *mut dc_context_t) -> *mut dc_smtp_t {
|
||||
let mut smtp: *mut dc_smtp_t = 0 as *mut dc_smtp_t;
|
||||
smtp = calloc(1, ::std::mem::size_of::<dc_smtp_t>()) as *mut dc_smtp_t;
|
||||
if smtp.is_null() {
|
||||
exit(29i32);
|
||||
pub fn dc_smtp_new() -> dc_smtp_t {
|
||||
dc_smtp_t {
|
||||
etpan: std::ptr::null_mut(),
|
||||
from: std::ptr::null_mut(),
|
||||
esmtp: 0,
|
||||
log_connect_errors: 1,
|
||||
context: std::ptr::null_mut(),
|
||||
error: std::ptr::null_mut(),
|
||||
error_etpan: 0,
|
||||
}
|
||||
(*smtp).log_connect_errors = 1i32;
|
||||
(*smtp).context = context;
|
||||
return smtp;
|
||||
}
|
||||
|
||||
pub unsafe fn dc_smtp_unref(mut smtp: *mut dc_smtp_t) {
|
||||
if smtp.is_null() {
|
||||
return;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user