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);
dc_open(&ctx, dbfile.as_ptr(), std::ptr::null());
assert_eq!(dc_open(&ctx, dbfile.as_ptr(), std::ptr::null()), 1);
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, "mail_pw", Some(&pw));
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)? };
Ok(())
}
).unwrap();
);
}
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) {
dc_log_info(
context,
0i32,
b"INBOX-jobs started...\x00" as *const u8 as *const libc::c_char,
);
info!(context, 0, "INBOX-jobs started...",);
let probe_imap_network = *context.probe_imap_network.clone().read().unwrap();
*context.probe_imap_network.write().unwrap() = 0;
*context.perform_inbox_jobs_needed.write().unwrap() = 0;
dc_job_perform(context, 100, probe_imap_network);
dc_log_info(
context,
0i32,
b"INBOX-jobs ended.\x00" as *const u8 as *const libc::c_char,
);
info!(context, 0, "INBOX-jobs ended.",);
}
unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network: libc::c_int) {
let process_row = |row: &rusqlite::Row| {
let job = dc_job_t {
@@ -101,9 +94,7 @@ unsafe fn dc_job_perform(context: &Context, thread: libc::c_int, probe_network:
params_probe
};
context
.sql
.query_map(query, params, process_row, |jobs| {
context.sql.query_map(query, params, process_row, |jobs| {
for job in jobs {
let mut job: dc_job_t = job?;
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 {
dc_job_kill_action(context, job.action);
dc_jobthread_suspend(
context,
&context.sentbox_thread.clone().read().unwrap(),
1,
);
dc_jobthread_suspend(context, &context.sentbox_thread.clone().read().unwrap(), 1);
dc_jobthread_suspend(context, &context.mvbox_thread.clone().read().unwrap(), 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(())
})
.unwrap(); // TODO: better error handling
}); // TODO: better error handling
}
fn dc_job_delete(context: &Context, job: &dc_job_t) -> bool {
dc_sqlite3_execute(
context,
&context.sql,
"DELETE FROM jobs WHERE id=?;",
params![job.job_id as i32],
)
context
.sql
.execute("DELETE FROM jobs WHERE id=?;", params![job.job_id as i32])
.is_ok()
}
/* ******************************************************************************
@@ -1053,28 +1037,16 @@ pub unsafe fn dc_perform_smtp_jobs(context: &Context) {
state.perform_jobs_needed = 0;
if 0 != state.suspended {
dc_log_info(
context,
0,
b"SMTP-jobs suspended.\x00" as *const u8 as *const libc::c_char,
);
info!(context, 0, "SMTP-jobs suspended.",);
return;
}
state.doing_jobs = 1;
probe_smtp_network
};
dc_log_info(
context,
0,
b"SMTP-jobs started...\x00" as *const u8 as *const libc::c_char,
);
info!(context, 0, "SMTP-jobs started...",);
dc_job_perform(context, 5000, probe_smtp_network);
dc_log_info(
context,
0,
b"SMTP-jobs ended.\x00" as *const u8 as *const libc::c_char,
);
info!(context, 0, "SMTP-jobs ended.");
{
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) {
dc_log_info(
context,
0,
b"SMTP-idle started...\x00" as *const u8 as *const libc::c_char,
);
info!(context, 0, "SMTP-idle started...",);
{
let &(ref lock, ref cvar) = &*context.smtp_state.clone();
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
decide, what should be reported or done. However, these "Normal" errors
are usually logged by dc_log_warning(). */
unsafe fn log_vprintf(
unsafe extern "C" fn log_vprintf(
context: &Context,
event: Event,
data1: libc::c_int,
msg_format: *const libc::c_char,
va_0: std::ffi::VaListImpl,
mut va_0: ...
) {
let msg: *mut libc::c_char;
if !msg_format.is_null() {
@@ -35,7 +35,7 @@ unsafe fn log_vprintf(
tempbuf.as_mut_ptr(),
1024i32 as libc::c_ulong,
msg_format,
va_0,
va_0.as_va_list(),
);
msg = dc_strdup(tempbuf.as_mut_ptr())
} else {

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,12 @@ pub enum Error {
Sql(rusqlite::Error),
#[fail(display = "{:?}", _0)]
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>;

View File

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