fix segfaults and some queries

This commit is contained in:
dignifiedquire
2019-07-10 22:41:20 +02:00
parent a0acfca255
commit 45f7eba1f4
7 changed files with 604 additions and 795 deletions

View File

@@ -79,10 +79,12 @@ fn main() {
println!("opening database {:?}", dbfile); println!("opening database {:?}", dbfile);
dc_open(&ctx, dbfile.as_ptr(), std::ptr::null()); assert_eq!(dc_open(&ctx, dbfile.as_ptr(), std::ptr::null()), 1);
println!("configuring"); println!("configuring");
let pw = std::env::args().collect::<Vec<String>>()[1].clone(); let args = std::env::args().collect::<Vec<String>>();
assert_eq!(args.len(), 2, "missing password");
let pw = args[1].clone();
dc_set_config(&ctx, "addr", Some("d@testrun.org")); dc_set_config(&ctx, "addr", Some("d@testrun.org"));
dc_set_config(&ctx, "mail_pw", Some(&pw)); dc_set_config(&ctx, "mail_pw", Some(&pw));
dc_configure(&ctx); dc_configure(&ctx);

View File

@@ -324,7 +324,7 @@ pub fn dc_lookup_real_nchat_by_contact_id(
unsafe { *ret_chat_blocked = row.get(1)? }; unsafe { *ret_chat_blocked = row.get(1)? };
Ok(()) Ok(())
} }
).unwrap(); );
} }
pub unsafe fn dc_get_chat_id_by_contact_id(context: &Context, contact_id: uint32_t) -> uint32_t { pub unsafe fn dc_get_chat_id_by_contact_id(context: &Context, contact_id: uint32_t) -> uint32_t {

View File

@@ -49,23 +49,16 @@ pub struct dc_job_t {
} }
pub unsafe fn dc_perform_imap_jobs(context: &Context) { pub unsafe fn dc_perform_imap_jobs(context: &Context) {
dc_log_info( info!(context, 0, "INBOX-jobs started...",);
context,
0i32,
b"INBOX-jobs started...\x00" as *const u8 as *const libc::c_char,
);
let probe_imap_network = *context.probe_imap_network.clone().read().unwrap(); let probe_imap_network = *context.probe_imap_network.clone().read().unwrap();
*context.probe_imap_network.write().unwrap() = 0; *context.probe_imap_network.write().unwrap() = 0;
*context.perform_inbox_jobs_needed.write().unwrap() = 0; *context.perform_inbox_jobs_needed.write().unwrap() = 0;
dc_job_perform(context, 100, probe_imap_network); dc_job_perform(context, 100, probe_imap_network);
dc_log_info( info!(context, 0, "INBOX-jobs ended.",);
context,
0i32,
b"INBOX-jobs ended.\x00" as *const u8 as *const libc::c_char,
);
} }
unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network: libc::c_int) { unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network: libc::c_int) {
let process_row = |row: &rusqlite::Row| { let process_row = |row: &rusqlite::Row| {
let job = dc_job_t { let job = dc_job_t {
@@ -101,9 +94,7 @@ unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network:
params_probe params_probe
}; };
context context.sql.query_map(query, params, process_row, |jobs| {
.sql
.query_map(query, params, process_row, |jobs| {
for job in jobs { for job in jobs {
let mut job: dc_job_t = job?; let mut job: dc_job_t = job?;
info!( info!(
@@ -117,11 +108,7 @@ unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network:
if 900 == job.action || 910 == job.action { if 900 == job.action || 910 == job.action {
dc_job_kill_action(context, job.action); dc_job_kill_action(context, job.action);
dc_jobthread_suspend( dc_jobthread_suspend(context, &context.sentbox_thread.clone().read().unwrap(), 1);
context,
&context.sentbox_thread.clone().read().unwrap(),
1,
);
dc_jobthread_suspend(context, &context.mvbox_thread.clone().read().unwrap(), 1); dc_jobthread_suspend(context, &context.mvbox_thread.clone().read().unwrap(), 1);
dc_suspend_smtp_thread(context, 1); dc_suspend_smtp_thread(context, 1);
} }
@@ -238,17 +225,14 @@ unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network:
} }
Ok(()) Ok(())
}) }); // TODO: better error handling
.unwrap(); // TODO: better error handling
} }
fn dc_job_delete(context: &Context, job: &dc_job_t) -> bool { fn dc_job_delete(context: &Context, job: &dc_job_t) -> bool {
dc_sqlite3_execute( context
context, .sql
&context.sql, .execute("DELETE FROM jobs WHERE id=?;", params![job.job_id as i32])
"DELETE FROM jobs WHERE id=?;", .is_ok()
params![job.job_id as i32],
)
} }
/* ****************************************************************************** /* ******************************************************************************
@@ -1053,28 +1037,16 @@ pub unsafe fn dc_perform_smtp_jobs(context: &Context) {
state.perform_jobs_needed = 0; state.perform_jobs_needed = 0;
if 0 != state.suspended { if 0 != state.suspended {
dc_log_info( info!(context, 0, "SMTP-jobs suspended.",);
context,
0,
b"SMTP-jobs suspended.\x00" as *const u8 as *const libc::c_char,
);
return; return;
} }
state.doing_jobs = 1; state.doing_jobs = 1;
probe_smtp_network probe_smtp_network
}; };
dc_log_info( info!(context, 0, "SMTP-jobs started...",);
context,
0,
b"SMTP-jobs started...\x00" as *const u8 as *const libc::c_char,
);
dc_job_perform(context, 5000, probe_smtp_network); dc_job_perform(context, 5000, probe_smtp_network);
dc_log_info( info!(context, 0, "SMTP-jobs ended.");
context,
0,
b"SMTP-jobs ended.\x00" as *const u8 as *const libc::c_char,
);
{ {
let &(ref lock, _) = &*context.smtp_state.clone(); let &(ref lock, _) = &*context.smtp_state.clone();
@@ -1085,11 +1057,7 @@ pub unsafe fn dc_perform_smtp_jobs(context: &Context) {
} }
pub unsafe fn dc_perform_smtp_idle(context: &Context) { pub unsafe fn dc_perform_smtp_idle(context: &Context) {
dc_log_info( info!(context, 0, "SMTP-idle started...",);
context,
0,
b"SMTP-idle started...\x00" as *const u8 as *const libc::c_char,
);
{ {
let &(ref lock, ref cvar) = &*context.smtp_state.clone(); let &(ref lock, ref cvar) = &*context.smtp_state.clone();
let mut state = lock.lock().unwrap(); let mut state = lock.lock().unwrap();

View File

@@ -21,12 +21,12 @@ function. These errors must be shown to the user by a bubble or so.
usually not reported using dc_log_error() - its up to the caller to usually not reported using dc_log_error() - its up to the caller to
decide, what should be reported or done. However, these "Normal" errors decide, what should be reported or done. However, these "Normal" errors
are usually logged by dc_log_warning(). */ are usually logged by dc_log_warning(). */
unsafe fn log_vprintf( unsafe extern "C" fn log_vprintf(
context: &Context, context: &Context,
event: Event, event: Event,
data1: libc::c_int, data1: libc::c_int,
msg_format: *const libc::c_char, msg_format: *const libc::c_char,
va_0: std::ffi::VaListImpl, mut va_0: ...
) { ) {
let msg: *mut libc::c_char; let msg: *mut libc::c_char;
if !msg_format.is_null() { if !msg_format.is_null() {
@@ -35,7 +35,7 @@ unsafe fn log_vprintf(
tempbuf.as_mut_ptr(), tempbuf.as_mut_ptr(),
1024i32 as libc::c_ulong, 1024i32 as libc::c_ulong,
msg_format, msg_format,
va_0, va_0.as_va_list(),
); );
msg = dc_strdup(tempbuf.as_mut_ptr()) msg = dc_strdup(tempbuf.as_mut_ptr())
} else { } else {

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,12 @@ pub enum Error {
Sql(rusqlite::Error), Sql(rusqlite::Error),
#[fail(display = "{:?}", _0)] #[fail(display = "{:?}", _0)]
Failure(failure::Error), Failure(failure::Error),
#[fail(display = "Sqlite: Connection closed")]
SqlNoConnection,
#[fail(display = "Sqlite: Already open")]
SqlAlreadyOpen,
#[fail(display = "Sqlite: Failed to open")]
SqlFailedToOpen,
} }
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;

View File

@@ -49,7 +49,7 @@ extern "C" {
_: *mut libc::c_char, _: *mut libc::c_char,
_: libc::c_ulong, _: libc::c_ulong,
_: *const libc::c_char, _: *const libc::c_char,
_: std::ffi::VaListImpl, _: std::ffi::VaList,
) -> libc::c_int; ) -> libc::c_int;
// -- DC Methods // -- DC Methods