mirror of
https://github.com/chatmail/core.git
synced 2026-04-21 15:36:30 +03:00
refactor(job): rusty and safe
This commit is contained in:
@@ -189,7 +189,7 @@ pub unsafe extern "C" fn dc_perform_imap_jobs(context: *mut dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_imap_jobs(context)
|
||||
job::perform_imap_jobs(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -197,7 +197,7 @@ pub unsafe extern "C" fn dc_perform_imap_fetch(context: *mut dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_imap_fetch(context)
|
||||
job::perform_imap_fetch(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -205,7 +205,7 @@ pub unsafe extern "C" fn dc_perform_imap_idle(context: *mut dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_imap_idle(context)
|
||||
job::perform_imap_idle(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -213,7 +213,7 @@ pub unsafe extern "C" fn dc_interrupt_imap_idle(context: *mut dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_interrupt_imap_idle(context)
|
||||
job::interrupt_imap_idle(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -221,7 +221,7 @@ pub unsafe extern "C" fn dc_perform_mvbox_fetch(context: *mut dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_mvbox_fetch(context)
|
||||
job::perform_mvbox_fetch(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -229,7 +229,7 @@ pub unsafe extern "C" fn dc_perform_mvbox_idle(context: *mut dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_mvbox_idle(context)
|
||||
job::perform_mvbox_idle(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -237,7 +237,7 @@ pub unsafe extern "C" fn dc_interrupt_mvbox_idle(context: *mut dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_interrupt_mvbox_idle(context)
|
||||
job::interrupt_mvbox_idle(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -245,7 +245,7 @@ pub unsafe extern "C" fn dc_perform_sentbox_fetch(context: *mut dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_sentbox_fetch(context)
|
||||
job::perform_sentbox_fetch(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -253,7 +253,7 @@ pub unsafe extern "C" fn dc_perform_sentbox_idle(context: *mut dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_sentbox_idle(context)
|
||||
job::perform_sentbox_idle(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -261,7 +261,7 @@ pub unsafe extern "C" fn dc_interrupt_sentbox_idle(context: *mut dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_interrupt_sentbox_idle(context)
|
||||
job::interrupt_sentbox_idle(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -269,7 +269,7 @@ pub unsafe extern "C" fn dc_perform_smtp_jobs(context: *mut dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_smtp_jobs(context)
|
||||
job::perform_smtp_jobs(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -277,7 +277,7 @@ pub unsafe extern "C" fn dc_perform_smtp_idle(context: *mut dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_perform_smtp_idle(context)
|
||||
job::perform_smtp_idle(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -285,7 +285,7 @@ pub unsafe extern "C" fn dc_interrupt_smtp_idle(context: *mut dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_interrupt_smtp_idle(context)
|
||||
job::interrupt_smtp_idle(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -293,7 +293,7 @@ pub unsafe extern "C" fn dc_maybe_network(context: *mut dc_context_t) {
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_job::dc_maybe_network(context)
|
||||
job::maybe_network(context)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -1027,7 +1027,7 @@ pub unsafe extern "C" fn dc_send_locations_to_chat(
|
||||
assert!(!context.is_null());
|
||||
let context = &*context;
|
||||
|
||||
dc_location::dc_send_locations_to_chat(context, chat_id, seconds)
|
||||
dc_location::dc_send_locations_to_chat(context, chat_id, seconds as i64)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
@@ -10,11 +10,11 @@ use deltachat::context::*;
|
||||
use deltachat::dc_array::*;
|
||||
use deltachat::dc_configure::*;
|
||||
use deltachat::dc_imex::*;
|
||||
use deltachat::dc_job::*;
|
||||
use deltachat::dc_location::*;
|
||||
use deltachat::dc_msg::*;
|
||||
use deltachat::dc_receive_imf::*;
|
||||
use deltachat::dc_tools::*;
|
||||
use deltachat::job::*;
|
||||
use deltachat::lot::LotState;
|
||||
use deltachat::peerstate::*;
|
||||
use deltachat::qr::*;
|
||||
@@ -582,7 +582,7 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
|
||||
println!("{}", to_string(dc_get_info(context)));
|
||||
}
|
||||
"maybenetwork" => {
|
||||
dc_maybe_network(context);
|
||||
maybe_network(context);
|
||||
}
|
||||
"housekeeping" => {
|
||||
sql::housekeeping(context);
|
||||
|
||||
@@ -21,9 +21,9 @@ use deltachat::config;
|
||||
use deltachat::constants::*;
|
||||
use deltachat::context::*;
|
||||
use deltachat::dc_configure::*;
|
||||
use deltachat::dc_job::*;
|
||||
use deltachat::dc_securejoin::*;
|
||||
use deltachat::dc_tools::*;
|
||||
use deltachat::job::*;
|
||||
use deltachat::oauth2::*;
|
||||
use deltachat::types::*;
|
||||
use deltachat::x::*;
|
||||
@@ -172,13 +172,11 @@ fn start_threads(c: Arc<RwLock<Context>>) {
|
||||
let ctx = c.clone();
|
||||
let handle_imap = std::thread::spawn(move || loop {
|
||||
while_running!({
|
||||
unsafe {
|
||||
dc_perform_imap_jobs(&ctx.read().unwrap());
|
||||
dc_perform_imap_fetch(&ctx.read().unwrap());
|
||||
}
|
||||
perform_imap_jobs(&ctx.read().unwrap());
|
||||
perform_imap_fetch(&ctx.read().unwrap());
|
||||
while_running!({
|
||||
let context = ctx.read().unwrap();
|
||||
dc_perform_imap_idle(&context);
|
||||
perform_imap_idle(&context);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -186,9 +184,9 @@ fn start_threads(c: Arc<RwLock<Context>>) {
|
||||
let ctx = c.clone();
|
||||
let handle_mvbox = std::thread::spawn(move || loop {
|
||||
while_running!({
|
||||
dc_perform_mvbox_fetch(&ctx.read().unwrap());
|
||||
perform_mvbox_fetch(&ctx.read().unwrap());
|
||||
while_running!({
|
||||
dc_perform_mvbox_idle(&ctx.read().unwrap());
|
||||
perform_mvbox_idle(&ctx.read().unwrap());
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -196,9 +194,9 @@ fn start_threads(c: Arc<RwLock<Context>>) {
|
||||
let ctx = c.clone();
|
||||
let handle_sentbox = std::thread::spawn(move || loop {
|
||||
while_running!({
|
||||
dc_perform_sentbox_fetch(&ctx.read().unwrap());
|
||||
perform_sentbox_fetch(&ctx.read().unwrap());
|
||||
while_running!({
|
||||
dc_perform_sentbox_idle(&ctx.read().unwrap());
|
||||
perform_sentbox_idle(&ctx.read().unwrap());
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -206,9 +204,9 @@ fn start_threads(c: Arc<RwLock<Context>>) {
|
||||
let ctx = c;
|
||||
let handle_smtp = std::thread::spawn(move || loop {
|
||||
while_running!({
|
||||
unsafe { dc_perform_smtp_jobs(&ctx.read().unwrap()) };
|
||||
perform_smtp_jobs(&ctx.read().unwrap());
|
||||
while_running!({
|
||||
unsafe { dc_perform_smtp_idle(&ctx.read().unwrap()) };
|
||||
perform_smtp_idle(&ctx.read().unwrap());
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -226,12 +224,10 @@ fn stop_threads(context: &Context) {
|
||||
println!("Stopping threads");
|
||||
IS_RUNNING.store(false, Ordering::Relaxed);
|
||||
|
||||
unsafe {
|
||||
dc_interrupt_imap_idle(context);
|
||||
dc_interrupt_mvbox_idle(context);
|
||||
dc_interrupt_sentbox_idle(context);
|
||||
dc_interrupt_smtp_idle(context);
|
||||
}
|
||||
interrupt_imap_idle(context);
|
||||
interrupt_mvbox_idle(context);
|
||||
interrupt_sentbox_idle(context);
|
||||
interrupt_smtp_idle(context);
|
||||
|
||||
handle.handle_imap.take().unwrap().join().unwrap();
|
||||
handle.handle_mvbox.take().unwrap().join().unwrap();
|
||||
@@ -487,14 +483,14 @@ unsafe fn handle_cmd(line: &str, ctx: Arc<RwLock<Context>>) -> Result<ExitResult
|
||||
if HANDLE.clone().lock().unwrap().is_some() {
|
||||
println!("smtp-jobs are already running in a thread.",);
|
||||
} else {
|
||||
dc_perform_smtp_jobs(&ctx.read().unwrap());
|
||||
perform_smtp_jobs(&ctx.read().unwrap());
|
||||
}
|
||||
}
|
||||
"imap-jobs" => {
|
||||
if HANDLE.clone().lock().unwrap().is_some() {
|
||||
println!("imap-jobs are already running in a thread.");
|
||||
} else {
|
||||
dc_perform_imap_jobs(&ctx.read().unwrap());
|
||||
perform_imap_jobs(&ctx.read().unwrap());
|
||||
}
|
||||
}
|
||||
"configure" => {
|
||||
|
||||
@@ -12,9 +12,8 @@ use deltachat::constants::Event;
|
||||
use deltachat::contact::*;
|
||||
use deltachat::context::*;
|
||||
use deltachat::dc_configure::*;
|
||||
use deltachat::dc_job::{
|
||||
dc_perform_imap_fetch, dc_perform_imap_idle, dc_perform_imap_jobs, dc_perform_smtp_idle,
|
||||
dc_perform_smtp_jobs,
|
||||
use deltachat::job::{
|
||||
perform_imap_fetch, perform_imap_idle, perform_imap_jobs, perform_smtp_idle, perform_smtp_jobs,
|
||||
};
|
||||
|
||||
extern "C" fn cb(_ctx: &Context, event: Event, data1: usize, data2: usize) -> usize {
|
||||
@@ -52,12 +51,12 @@ fn main() {
|
||||
let r1 = running.clone();
|
||||
let t1 = thread::spawn(move || {
|
||||
while *r1.read().unwrap() {
|
||||
dc_perform_imap_jobs(&ctx1);
|
||||
perform_imap_jobs(&ctx1);
|
||||
if *r1.read().unwrap() {
|
||||
dc_perform_imap_fetch(&ctx1);
|
||||
perform_imap_fetch(&ctx1);
|
||||
|
||||
if *r1.read().unwrap() {
|
||||
dc_perform_imap_idle(&ctx1);
|
||||
perform_imap_idle(&ctx1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,9 +66,9 @@ fn main() {
|
||||
let r1 = running.clone();
|
||||
let t2 = thread::spawn(move || {
|
||||
while *r1.read().unwrap() {
|
||||
dc_perform_smtp_jobs(&ctx1);
|
||||
perform_smtp_jobs(&ctx1);
|
||||
if *r1.read().unwrap() {
|
||||
dc_perform_smtp_idle(&ctx1);
|
||||
perform_smtp_idle(&ctx1);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -123,8 +122,8 @@ fn main() {
|
||||
println!("stopping threads");
|
||||
|
||||
*running.clone().write().unwrap() = false;
|
||||
deltachat::dc_job::dc_interrupt_imap_idle(&ctx);
|
||||
deltachat::dc_job::dc_interrupt_smtp_idle(&ctx);
|
||||
deltachat::job::interrupt_imap_idle(&ctx);
|
||||
deltachat::job::interrupt_smtp_idle(&ctx);
|
||||
|
||||
println!("joining");
|
||||
t1.join().unwrap();
|
||||
|
||||
10
src/chat.rs
10
src/chat.rs
@@ -6,10 +6,10 @@ use crate::constants::*;
|
||||
use crate::contact::*;
|
||||
use crate::context::Context;
|
||||
use crate::dc_array::*;
|
||||
use crate::dc_job::*;
|
||||
use crate::dc_msg::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::error::Error;
|
||||
use crate::job::*;
|
||||
use crate::param::*;
|
||||
use crate::sql::{self, Sql};
|
||||
use crate::stock::StockMessage;
|
||||
@@ -899,7 +899,7 @@ pub unsafe fn send_msg<'a>(
|
||||
}
|
||||
|
||||
ensure!(
|
||||
dc_job_send_msg(context, (*msg).id) != 0,
|
||||
job_send_msg(context, (*msg).id) != 0,
|
||||
"Failed to initiate send job"
|
||||
);
|
||||
|
||||
@@ -1353,8 +1353,8 @@ pub fn delete(context: &Context, chat_id: u32) -> Result<(), Error> {
|
||||
|
||||
context.call_cb(Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t);
|
||||
|
||||
dc_job_kill_action(context, 105);
|
||||
unsafe { dc_job_add(context, 105, 0, Params::new(), 10) };
|
||||
job_kill_action(context, Action::Housekeeping);
|
||||
job_add(context, Action::Housekeeping, 0, Params::new(), 10);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1941,7 +1941,7 @@ pub unsafe fn forward_msgs(
|
||||
new_msg_id = chat
|
||||
.prepare_msg_raw(context, msg, fresh10)
|
||||
.unwrap_or_default();
|
||||
dc_job_send_msg(context, new_msg_id);
|
||||
job_send_msg(context, new_msg_id);
|
||||
}
|
||||
created_db_entries.push(chat_id);
|
||||
created_db_entries.push(new_msg_id);
|
||||
|
||||
@@ -3,9 +3,9 @@ use strum_macros::{AsRefStr, Display, EnumIter, EnumProperty, EnumString};
|
||||
|
||||
use crate::constants::DC_VERSION_STR;
|
||||
use crate::context::Context;
|
||||
use crate::dc_job::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::error::Error;
|
||||
use crate::job::*;
|
||||
use crate::stock::StockMessage;
|
||||
|
||||
/// The available configuration keys.
|
||||
@@ -102,17 +102,17 @@ impl Context {
|
||||
}
|
||||
Config::InboxWatch => {
|
||||
let ret = self.sql.set_config(self, key, value);
|
||||
unsafe { dc_interrupt_imap_idle(self) };
|
||||
interrupt_imap_idle(self);
|
||||
ret
|
||||
}
|
||||
Config::SentboxWatch => {
|
||||
let ret = self.sql.set_config(self, key, value);
|
||||
dc_interrupt_sentbox_idle(self);
|
||||
interrupt_sentbox_idle(self);
|
||||
ret
|
||||
}
|
||||
Config::MvboxWatch => {
|
||||
let ret = self.sql.set_config(self, key, value);
|
||||
dc_interrupt_mvbox_idle(self);
|
||||
interrupt_mvbox_idle(self);
|
||||
ret
|
||||
}
|
||||
Config::Selfstatus => {
|
||||
|
||||
@@ -3,13 +3,13 @@ use std::sync::{Arc, Condvar, Mutex, RwLock};
|
||||
use crate::chat::*;
|
||||
use crate::constants::*;
|
||||
use crate::contact::*;
|
||||
use crate::dc_job::*;
|
||||
use crate::dc_loginparam::*;
|
||||
use crate::dc_move::*;
|
||||
use crate::dc_msg::*;
|
||||
use crate::dc_receive_imf::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::imap::*;
|
||||
use crate::job::*;
|
||||
use crate::job_thread::JobThread;
|
||||
use crate::key::*;
|
||||
use crate::lot::Lot;
|
||||
@@ -230,7 +230,13 @@ unsafe fn cb_precheck_imf(
|
||||
}
|
||||
dc_do_heuristics_moves(context, server_folder, msg_id);
|
||||
if 0 != mark_seen {
|
||||
dc_job_add(context, 130, msg_id as libc::c_int, Params::new(), 0);
|
||||
job_add(
|
||||
context,
|
||||
Action::MarkseenMsgOnImap,
|
||||
msg_id as libc::c_int,
|
||||
Params::new(),
|
||||
0,
|
||||
);
|
||||
}
|
||||
}
|
||||
free(old_server_folder as *mut libc::c_void);
|
||||
|
||||
@@ -5,10 +5,10 @@ use quick_xml::events::{BytesEnd, BytesStart, BytesText};
|
||||
use crate::constants::Event;
|
||||
use crate::context::Context;
|
||||
use crate::dc_e2ee::*;
|
||||
use crate::dc_job::*;
|
||||
use crate::dc_loginparam::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::imap::*;
|
||||
use crate::job::*;
|
||||
use crate::oauth2::*;
|
||||
use crate::param::Params;
|
||||
use crate::types::*;
|
||||
@@ -77,8 +77,8 @@ pub unsafe fn dc_configure(context: &Context) {
|
||||
);
|
||||
return;
|
||||
}
|
||||
dc_job_kill_action(context, 900);
|
||||
dc_job_add(context, 900, 0, Params::new(), 0);
|
||||
job_kill_action(context, Action::ConfigureImap);
|
||||
job_add(context, Action::ConfigureImap, 0, Params::new(), 0);
|
||||
}
|
||||
|
||||
unsafe fn dc_has_ongoing(context: &Context) -> libc::c_int {
|
||||
@@ -118,7 +118,7 @@ pub fn dc_stop_ongoing_process(context: &Context) {
|
||||
|
||||
// the other dc_job_do_DC_JOB_*() functions are declared static in the c-file
|
||||
#[allow(non_snake_case, unused_must_use)]
|
||||
pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: *mut dc_job_t) {
|
||||
pub unsafe fn dc_job_do_DC_JOB_CONFIGURE_IMAP(context: &Context, _job: &Job) {
|
||||
let flags: libc::c_int;
|
||||
let mut success = false;
|
||||
let mut imap_connected_here = false;
|
||||
|
||||
@@ -12,10 +12,10 @@ use crate::constants::*;
|
||||
use crate::context::Context;
|
||||
use crate::dc_configure::*;
|
||||
use crate::dc_e2ee::*;
|
||||
use crate::dc_job::*;
|
||||
use crate::dc_msg::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::error::*;
|
||||
use crate::job::*;
|
||||
use crate::key::*;
|
||||
use crate::param::*;
|
||||
use crate::pgp::*;
|
||||
@@ -44,8 +44,8 @@ pub unsafe fn dc_imex(
|
||||
param.set(Param::Arg2, as_str(param2));
|
||||
}
|
||||
|
||||
dc_job_kill_action(context, 910);
|
||||
dc_job_add(context, 910, 0, param, 0);
|
||||
job_kill_action(context, Action::ImexImap);
|
||||
job_add(context, Action::ImexImap, 0, param, 0);
|
||||
}
|
||||
|
||||
/// Returns the filename of the backup if found, nullptr otherwise.
|
||||
@@ -506,7 +506,7 @@ pub unsafe fn dc_normalize_setup_code(
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: *mut dc_job_t) {
|
||||
pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: &Job) {
|
||||
let mut ok_to_continue = true;
|
||||
let mut success: libc::c_int = 0;
|
||||
let mut ongoing_allocated_here: libc::c_int = 0;
|
||||
@@ -514,10 +514,10 @@ pub unsafe fn dc_job_do_DC_JOB_IMEX_IMAP(context: &Context, job: *mut dc_job_t)
|
||||
|
||||
if !(0 == dc_alloc_ongoing(context)) {
|
||||
ongoing_allocated_here = 1;
|
||||
what = (*job).param.get_int(Param::Cmd).unwrap_or_default();
|
||||
let param1_s = (*job).param.get(Param::Arg).unwrap_or_default();
|
||||
what = job.param.get_int(Param::Cmd).unwrap_or_default();
|
||||
let param1_s = job.param.get(Param::Arg).unwrap_or_default();
|
||||
let param1 = CString::yolo(param1_s);
|
||||
let _param2 = CString::yolo((*job).param.get(Param::Arg2).unwrap_or_default());
|
||||
let _param2 = CString::yolo(job.param.get(Param::Arg2).unwrap_or_default());
|
||||
|
||||
if strlen(param1.as_ptr()) == 0 {
|
||||
error!(context, 0, "No Import/export dir/file given.",);
|
||||
|
||||
@@ -5,9 +5,9 @@ use crate::chat;
|
||||
use crate::constants::Event;
|
||||
use crate::constants::*;
|
||||
use crate::context::*;
|
||||
use crate::dc_job::*;
|
||||
use crate::dc_msg::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::job::*;
|
||||
use crate::param::*;
|
||||
use crate::sql;
|
||||
use crate::stock::StockMessage;
|
||||
@@ -68,15 +68,11 @@ impl dc_kml_t {
|
||||
}
|
||||
|
||||
// location streaming
|
||||
pub unsafe fn dc_send_locations_to_chat(
|
||||
context: &Context,
|
||||
chat_id: uint32_t,
|
||||
seconds: libc::c_int,
|
||||
) {
|
||||
pub unsafe fn dc_send_locations_to_chat(context: &Context, chat_id: uint32_t, seconds: i64) {
|
||||
let now = time();
|
||||
let mut msg: *mut dc_msg_t = 0 as *mut dc_msg_t;
|
||||
let is_sending_locations_before: bool;
|
||||
if !(seconds < 0i32 || chat_id <= 9i32 as libc::c_uint) {
|
||||
if !(seconds < 0 || chat_id <= 9i32 as libc::c_uint) {
|
||||
is_sending_locations_before = dc_is_sending_locations_to_chat(context, chat_id);
|
||||
if sql::execute(
|
||||
context,
|
||||
@@ -87,11 +83,7 @@ pub unsafe fn dc_send_locations_to_chat(
|
||||
WHERE id=?",
|
||||
params![
|
||||
if 0 != seconds { now } else { 0 },
|
||||
if 0 != seconds {
|
||||
now + seconds as i64
|
||||
} else {
|
||||
0
|
||||
},
|
||||
if 0 != seconds { now + seconds } else { 0 },
|
||||
chat_id as i32,
|
||||
],
|
||||
)
|
||||
@@ -115,12 +107,12 @@ pub unsafe fn dc_send_locations_to_chat(
|
||||
);
|
||||
if 0 != seconds {
|
||||
schedule_MAYBE_SEND_LOCATIONS(context, 0i32);
|
||||
dc_job_add(
|
||||
job_add(
|
||||
context,
|
||||
5007i32,
|
||||
Action::MaybeSendLocationsEnded,
|
||||
chat_id as libc::c_int,
|
||||
Params::new(),
|
||||
seconds + 1i32,
|
||||
seconds + 1,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -133,8 +125,8 @@ pub unsafe fn dc_send_locations_to_chat(
|
||||
******************************************************************************/
|
||||
#[allow(non_snake_case)]
|
||||
unsafe fn schedule_MAYBE_SEND_LOCATIONS(context: &Context, flags: libc::c_int) {
|
||||
if 0 != flags & 0x1 || !dc_job_action_exists(context, 5005) {
|
||||
dc_job_add(context, 5005, 0, Params::new(), 60);
|
||||
if 0 != flags & 0x1 || !job_action_exists(context, Action::MaybeSendLocations) {
|
||||
job_add(context, Action::MaybeSendLocations, 0, Params::new(), 60);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -625,7 +617,7 @@ pub unsafe fn dc_kml_unref(kml: &mut dc_kml_t) {
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOCATIONS(context: &Context, _job: *mut dc_job_t) {
|
||||
pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOCATIONS(context: &Context, _job: &Job) {
|
||||
let now = time();
|
||||
let mut continue_streaming: libc::c_int = 1;
|
||||
info!(
|
||||
@@ -707,7 +699,7 @@ pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOCATIONS(context: &Context, _job: *mu
|
||||
}
|
||||
|
||||
#[allow(non_snake_case)]
|
||||
pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOC_ENDED(context: &Context, job: &mut dc_job_t) {
|
||||
pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOC_ENDED(context: &Context, job: &mut Job) {
|
||||
// this function is called when location-streaming _might_ have ended for a chat.
|
||||
// the function checks, if location-streaming is really ended;
|
||||
// if so, a device-message is added if not yet done.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::constants::*;
|
||||
use crate::context::*;
|
||||
use crate::dc_job::*;
|
||||
use crate::dc_msg::*;
|
||||
use crate::job::*;
|
||||
use crate::param::Params;
|
||||
|
||||
pub unsafe fn dc_do_heuristics_moves(context: &Context, folder: &str, msg_id: u32) {
|
||||
@@ -32,7 +32,13 @@ pub unsafe fn dc_do_heuristics_moves(context: &Context, folder: &str, msg_id: u3
|
||||
|
||||
// 1 = dc message, 2 = reply to dc message
|
||||
if 0 != (*msg).is_dc_message {
|
||||
dc_job_add(context, 200, (*msg).id as libc::c_int, Params::new(), 0);
|
||||
job_add(
|
||||
context,
|
||||
Action::MoveMsg,
|
||||
(*msg).id as libc::c_int,
|
||||
Params::new(),
|
||||
0,
|
||||
);
|
||||
dc_update_msg_move_state(context, (*msg).rfc724_mid, MoveState::Moving);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ use crate::chat::{self, Chat};
|
||||
use crate::constants::*;
|
||||
use crate::contact::*;
|
||||
use crate::context::*;
|
||||
use crate::dc_job::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::job::*;
|
||||
use crate::lot::{Lot, LotState, Meaning};
|
||||
use crate::param::*;
|
||||
use crate::pgp::*;
|
||||
@@ -591,9 +591,9 @@ pub unsafe fn dc_delete_msgs(context: &Context, msg_ids: *const uint32_t, msg_cn
|
||||
let mut i: libc::c_int = 0i32;
|
||||
while i < msg_cnt {
|
||||
dc_update_msg_chat_id(context, *msg_ids.offset(i as isize), 3i32 as uint32_t);
|
||||
dc_job_add(
|
||||
job_add(
|
||||
context,
|
||||
110,
|
||||
Action::DeleteMsgOnImap,
|
||||
*msg_ids.offset(i as isize) as libc::c_int,
|
||||
Params::new(),
|
||||
0,
|
||||
@@ -603,8 +603,8 @@ pub unsafe fn dc_delete_msgs(context: &Context, msg_ids: *const uint32_t, msg_cn
|
||||
|
||||
if 0 != msg_cnt {
|
||||
context.call_cb(Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t);
|
||||
dc_job_kill_action(context, 105);
|
||||
dc_job_add(context, 105, 0, Params::new(), 10);
|
||||
job_kill_action(context, Action::Housekeeping);
|
||||
job_add(context, Action::Housekeeping, 0, Params::new(), 10);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -654,7 +654,13 @@ pub fn dc_markseen_msgs(context: &Context, msg_ids: *const u32, msg_cnt: usize)
|
||||
dc_update_msg_state(context, id, MessageState::InSeen);
|
||||
info!(context, 0, "Seen message #{}.", id);
|
||||
|
||||
unsafe { dc_job_add(context, 130, id as i32, Params::new(), 0) };
|
||||
job_add(
|
||||
context,
|
||||
Action::MarkseenMsgOnImap,
|
||||
id as i32,
|
||||
Params::new(),
|
||||
0,
|
||||
);
|
||||
send_event = true;
|
||||
}
|
||||
} else if curr_state == MessageState::InFresh {
|
||||
@@ -1150,16 +1156,17 @@ pub unsafe fn dc_msg_latefiling_mediasize(
|
||||
};
|
||||
}
|
||||
|
||||
pub unsafe fn dc_msg_save_param_to_disk(msg: *mut dc_msg_t) -> bool {
|
||||
pub fn dc_msg_save_param_to_disk(msg: *mut dc_msg_t) -> bool {
|
||||
if msg.is_null() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let msg = unsafe { &*msg };
|
||||
sql::execute(
|
||||
(*msg).context,
|
||||
&(*msg).context.sql,
|
||||
msg.context,
|
||||
&msg.context.sql,
|
||||
"UPDATE msgs SET param=? WHERE id=?;",
|
||||
params![(*msg).param.to_string(), (*msg).id as i32],
|
||||
params![msg.param.to_string(), msg.id as i32],
|
||||
)
|
||||
.is_ok()
|
||||
}
|
||||
@@ -1235,16 +1242,16 @@ pub fn dc_update_msg_move_state(
|
||||
.is_ok()
|
||||
}
|
||||
|
||||
pub unsafe fn dc_set_msg_failed(context: &Context, msg_id: uint32_t, error: *const libc::c_char) {
|
||||
pub unsafe fn dc_set_msg_failed(context: &Context, msg_id: u32, error: Option<impl AsRef<str>>) {
|
||||
let mut msg = dc_msg_new_untyped(context);
|
||||
|
||||
if dc_msg_load_from_db(msg, context, msg_id) {
|
||||
if (*msg).state.can_fail() {
|
||||
(*msg).state = MessageState::OutFailed;
|
||||
}
|
||||
if !error.is_null() {
|
||||
(*msg).param.set(Param::Error, as_str(error));
|
||||
error!(context, 0, "{}", as_str(error),);
|
||||
if let Some(error) = error {
|
||||
(*msg).param.set(Param::Error, error.as_ref());
|
||||
error!(context, 0, "{}", error.as_ref());
|
||||
}
|
||||
|
||||
if sql::execute(
|
||||
|
||||
@@ -14,7 +14,6 @@ use crate::chat::{self, Chat};
|
||||
use crate::constants::*;
|
||||
use crate::contact::*;
|
||||
use crate::context::Context;
|
||||
use crate::dc_job::*;
|
||||
use crate::dc_location::*;
|
||||
use crate::dc_mimeparser::*;
|
||||
use crate::dc_move::*;
|
||||
@@ -23,6 +22,7 @@ use crate::dc_securejoin::*;
|
||||
use crate::dc_strencode::*;
|
||||
use crate::dc_tools::*;
|
||||
use crate::error::Result;
|
||||
use crate::job::*;
|
||||
use crate::param::*;
|
||||
use crate::peerstate::*;
|
||||
use crate::sql;
|
||||
@@ -232,9 +232,9 @@ pub unsafe fn dc_receive_imf(
|
||||
}
|
||||
|
||||
if 0 != add_delete_job && !created_db_entries.is_empty() {
|
||||
dc_job_add(
|
||||
job_add(
|
||||
context,
|
||||
DC_JOB_DELETE_MSG_ON_IMAP,
|
||||
Action::DeleteMsgOnImap,
|
||||
created_db_entries[0].1 as i32,
|
||||
Params::new(),
|
||||
0,
|
||||
@@ -920,7 +920,7 @@ unsafe fn handle_reports(
|
||||
{
|
||||
param.set_int(Param::AlsoMove, 1);
|
||||
}
|
||||
dc_job_add(context, 120, 0, param, 0);
|
||||
job_add(context, Action::MarkseenMdnOnImap, 0, param, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1284,6 +1284,14 @@ pub fn as_str<'a>(s: *const libc::c_char) -> &'a str {
|
||||
as_str_safe(s).unwrap_or_else(|err| panic!("{}", err))
|
||||
}
|
||||
|
||||
/// Converts a C string to either a Rust `&str` or `None` if it is a null pointer.
|
||||
pub fn as_opt_str<'a>(s: *const libc::c_char) -> Option<&'a str> {
|
||||
if s.is_null() {
|
||||
return None;
|
||||
}
|
||||
Some(as_str(s))
|
||||
}
|
||||
|
||||
fn as_str_safe<'a>(s: *const libc::c_char) -> Result<&'a str, Error> {
|
||||
assert!(!s.is_null(), "cannot be used on null pointers");
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -30,6 +30,7 @@ pub mod constants;
|
||||
pub mod contact;
|
||||
pub mod context;
|
||||
mod imap;
|
||||
pub mod job;
|
||||
mod job_thread;
|
||||
pub mod key;
|
||||
pub mod keyring;
|
||||
@@ -50,7 +51,6 @@ pub mod dc_configure;
|
||||
mod dc_dehtml;
|
||||
mod dc_e2ee;
|
||||
pub mod dc_imex;
|
||||
pub mod dc_job;
|
||||
pub mod dc_location;
|
||||
mod dc_loginparam;
|
||||
mod dc_mimefactory;
|
||||
|
||||
Reference in New Issue
Block a user