mirror of
https://github.com/chatmail/core.git
synced 2026-04-28 02:46:29 +03:00
fix some locking issues, start rust-imap impl
This commit is contained in:
committed by
Lars-Magnus Skog
parent
0b3a4b4c13
commit
e7d72dfdd4
@@ -648,7 +648,7 @@ pub unsafe extern "C" fn dc_cmdline(
|
||||
)
|
||||
}
|
||||
} else if strcmp(cmd, b"has-backup\x00" as *const u8 as *const libc::c_char) == 0i32 {
|
||||
ret = dc_imex_has_backup(&context, context.blobdir);
|
||||
ret = dc_imex_has_backup(&context, context.get_blobdir());
|
||||
if ret.is_null() {
|
||||
ret = dc_strdup(b"No backup found.\x00" as *const u8 as *const libc::c_char)
|
||||
}
|
||||
@@ -657,7 +657,12 @@ pub unsafe extern "C" fn dc_cmdline(
|
||||
b"export-backup\x00" as *const u8 as *const libc::c_char,
|
||||
) == 0i32
|
||||
{
|
||||
dc_imex(&context, 11i32, context.blobdir, 0 as *const libc::c_char);
|
||||
dc_imex(
|
||||
&context,
|
||||
11i32,
|
||||
context.get_blobdir(),
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
ret = 2i32 as *mut libc::c_char
|
||||
} else if strcmp(
|
||||
cmd,
|
||||
@@ -673,16 +678,26 @@ pub unsafe extern "C" fn dc_cmdline(
|
||||
)
|
||||
}
|
||||
} else if strcmp(cmd, b"export-keys\x00" as *const u8 as *const libc::c_char) == 0i32 {
|
||||
dc_imex(&context, 1i32, context.blobdir, 0 as *const libc::c_char);
|
||||
dc_imex(
|
||||
&context,
|
||||
1i32,
|
||||
context.get_blobdir(),
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
ret = 2i32 as *mut libc::c_char
|
||||
} else if strcmp(cmd, b"import-keys\x00" as *const u8 as *const libc::c_char) == 0i32 {
|
||||
dc_imex(&context, 2i32, context.blobdir, 0 as *const libc::c_char);
|
||||
dc_imex(
|
||||
&context,
|
||||
2i32,
|
||||
context.get_blobdir(),
|
||||
0 as *const libc::c_char,
|
||||
);
|
||||
ret = 2i32 as *mut libc::c_char
|
||||
} else if strcmp(cmd, b"export-setup\x00" as *const u8 as *const libc::c_char) == 0i32 {
|
||||
let mut setup_code_0: *mut libc::c_char = dc_create_setup_code(&context);
|
||||
let mut file_name: *mut libc::c_char = dc_mprintf(
|
||||
b"%s/autocrypt-setup-message.html\x00" as *const u8 as *const libc::c_char,
|
||||
context.blobdir,
|
||||
context.get_blobdir(),
|
||||
);
|
||||
let mut file_content: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
file_content = dc_render_setup_file(&context, setup_code_0);
|
||||
|
||||
@@ -150,7 +150,7 @@ unsafe extern "C" fn receive_event(
|
||||
let mut ret: *mut libc::c_char = 0 as *mut libc::c_char;
|
||||
let mut tempFile: *mut libc::c_char = dc_get_fine_pathNfilename(
|
||||
context,
|
||||
(*context).blobdir,
|
||||
context.get_blobdir(),
|
||||
b"curl.result\x00" as *const u8 as *const libc::c_char,
|
||||
);
|
||||
let mut cmd: *mut libc::c_char = if event == Event::HTTP_GET {
|
||||
@@ -279,12 +279,16 @@ unsafe fn start_threads(
|
||||
run_threads = 1;
|
||||
let context = c.clone();
|
||||
let h1 = std::thread::spawn(move || {
|
||||
let ctx = context.clone();
|
||||
let context = ctx.read().unwrap();
|
||||
while 0 != run_threads {
|
||||
let ctx = context.clone();
|
||||
let context = ctx.read().unwrap();
|
||||
|
||||
println!("-- imap jobs");
|
||||
dc_perform_imap_jobs(&context);
|
||||
println!("-- imap fetch");
|
||||
dc_perform_imap_fetch(&context);
|
||||
if 0 != run_threads {
|
||||
println!("-- imap idle");
|
||||
dc_perform_imap_idle(&context);
|
||||
}
|
||||
}
|
||||
@@ -292,38 +296,38 @@ unsafe fn start_threads(
|
||||
|
||||
let context = c.clone();
|
||||
let h2 = std::thread::spawn(move || {
|
||||
let ctx = context.clone();
|
||||
let context = ctx.read().unwrap();
|
||||
while 0 != run_threads {
|
||||
dc_perform_mvbox_fetch(&context);
|
||||
if 0 != run_threads {
|
||||
dc_perform_mvbox_idle(&context);
|
||||
}
|
||||
}
|
||||
// let ctx = context.clone();
|
||||
// let context = ctx.read().unwrap();
|
||||
// while 0 != run_threads {
|
||||
// dc_perform_mvbox_fetch(&context);
|
||||
// if 0 != run_threads {
|
||||
// dc_perform_mvbox_idle(&context);
|
||||
// }
|
||||
// }
|
||||
});
|
||||
|
||||
let context = c.clone();
|
||||
let h3 = std::thread::spawn(move || {
|
||||
let ctx = context.clone();
|
||||
let context = ctx.read().unwrap();
|
||||
while 0 != run_threads {
|
||||
dc_perform_sentbox_fetch(&context);
|
||||
if 0 != run_threads {
|
||||
dc_perform_sentbox_idle(&context);
|
||||
}
|
||||
}
|
||||
// let ctx = context.clone();
|
||||
// let context = ctx.read().unwrap();
|
||||
// while 0 != run_threads {
|
||||
// dc_perform_sentbox_fetch(&context);
|
||||
// if 0 != run_threads {
|
||||
// dc_perform_sentbox_idle(&context);
|
||||
// }
|
||||
// }
|
||||
});
|
||||
|
||||
let context = c.clone();
|
||||
let h4 = std::thread::spawn(move || {
|
||||
let ctx = context.clone();
|
||||
let context = ctx.read().unwrap();
|
||||
while 0 != run_threads {
|
||||
dc_perform_smtp_jobs(&context);
|
||||
if 0 != run_threads {
|
||||
dc_perform_smtp_idle(&context);
|
||||
}
|
||||
}
|
||||
// let ctx = context.clone();
|
||||
// let context = ctx.read().unwrap();
|
||||
// while 0 != run_threads {
|
||||
// dc_perform_smtp_jobs(&context);
|
||||
// if 0 != run_threads {
|
||||
// dc_perform_smtp_idle(&context);
|
||||
// }
|
||||
// }
|
||||
});
|
||||
|
||||
(h1, h2, h3, h4)
|
||||
@@ -391,8 +395,6 @@ unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> lib
|
||||
let ctx = Arc::new(RwLock::new(context));
|
||||
|
||||
loop {
|
||||
let ctx = ctx.clone();
|
||||
|
||||
/* read command */
|
||||
let cmdline = read_cmd();
|
||||
free(cmd as *mut libc::c_void);
|
||||
@@ -426,10 +428,7 @@ unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> lib
|
||||
dc_perform_imap_jobs(&ctx.read().unwrap());
|
||||
}
|
||||
} else if strcmp(cmd, b"configure\x00" as *const u8 as *const libc::c_char) == 0i32 {
|
||||
handles = {
|
||||
let ctx = ctx.clone();
|
||||
Some(start_threads(ctx))
|
||||
};
|
||||
handles = { Some(start_threads(ctx.clone())) };
|
||||
dc_configure(&ctx.read().unwrap());
|
||||
} else if strcmp(cmd, b"oauth2\x00" as *const u8 as *const libc::c_char) == 0i32 {
|
||||
let mut addr: *mut libc::c_char = dc_get_config(
|
||||
@@ -463,10 +462,7 @@ unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> lib
|
||||
} else if strcmp(cmd, b"getqr\x00" as *const u8 as *const libc::c_char) == 0i32
|
||||
|| strcmp(cmd, b"getbadqr\x00" as *const u8 as *const libc::c_char) == 0i32
|
||||
{
|
||||
handles = {
|
||||
let ctx = ctx.clone();
|
||||
Some(start_threads(ctx))
|
||||
};
|
||||
handles = Some(start_threads(ctx.clone()));
|
||||
let mut qrstr: *mut libc::c_char = dc_get_securejoin_qr(
|
||||
&ctx.read().unwrap(),
|
||||
(if !arg1.is_null() { atoi(arg1) } else { 0i32 }) as uint32_t,
|
||||
@@ -491,10 +487,7 @@ unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> lib
|
||||
}
|
||||
free(qrstr as *mut libc::c_void);
|
||||
} else if strcmp(cmd, b"joinqr\x00" as *const u8 as *const libc::c_char) == 0i32 {
|
||||
handles = {
|
||||
let ctx = ctx.clone();
|
||||
Some(start_threads(ctx))
|
||||
};
|
||||
handles = Some(start_threads(ctx.clone()));
|
||||
if !arg1.is_null() {
|
||||
dc_join_securejoin(&ctx.read().unwrap(), arg1);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
extern crate deltachat;
|
||||
|
||||
use std::ffi::{CStr, CString};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use std::sync::Arc;
|
||||
use tempfile::tempdir;
|
||||
|
||||
use deltachat::constants::Event;
|
||||
@@ -20,6 +20,10 @@ extern "C" fn cb(_ctx: &dc_context_t, event: Event, data1: usize, data2: usize)
|
||||
println!("[{:?}]", event);
|
||||
|
||||
match event {
|
||||
Event::CONFIGURE_PROGRESS => {
|
||||
println!(" progress: {}", data1);
|
||||
0
|
||||
}
|
||||
Event::HTTP_GET => {
|
||||
let url = unsafe { CStr::from_ptr(data1 as *const _).to_str().unwrap() };
|
||||
|
||||
@@ -56,19 +60,20 @@ fn main() {
|
||||
let info_s = CStr::from_ptr(info);
|
||||
println!("info: {}", info_s.to_str().unwrap());
|
||||
|
||||
let ctx = Arc::new(RwLock::new(ctx));
|
||||
|
||||
let ctx = Arc::new(ctx);
|
||||
let ctx1 = ctx.clone();
|
||||
let t1 = std::thread::spawn(move || loop {
|
||||
dc_perform_imap_jobs(&ctx1.clone().read().unwrap());
|
||||
dc_perform_imap_fetch(&ctx1.clone().read().unwrap());
|
||||
dc_perform_imap_idle(&ctx1.clone().read().unwrap());
|
||||
dc_perform_imap_jobs(&ctx1);
|
||||
dc_perform_imap_fetch(&ctx1);
|
||||
std::thread::sleep_ms(1000);
|
||||
|
||||
// dc_perform_imap_idle(&ctx1);
|
||||
});
|
||||
|
||||
let ctx1 = ctx.clone();
|
||||
let t2 = std::thread::spawn(move || loop {
|
||||
dc_perform_smtp_jobs(&ctx1.clone().read().unwrap());
|
||||
dc_perform_smtp_idle(&ctx1.clone().read().unwrap());
|
||||
// dc_perform_smtp_jobs(&ctx1);
|
||||
// dc_perform_smtp_idle(&ctx1);
|
||||
});
|
||||
|
||||
let dir = tempdir().unwrap();
|
||||
@@ -76,42 +81,31 @@ fn main() {
|
||||
|
||||
println!("opening database {:?}", dbfile);
|
||||
|
||||
dc_open(
|
||||
&mut ctx.clone().write().unwrap(),
|
||||
dbfile.as_ptr(),
|
||||
std::ptr::null(),
|
||||
);
|
||||
dc_open(&ctx, dbfile.as_ptr(), std::ptr::null());
|
||||
|
||||
println!("configuring");
|
||||
dc_set_config(
|
||||
&ctx.clone().read().unwrap(),
|
||||
&ctx,
|
||||
CString::new("addr").unwrap().as_ptr(),
|
||||
CString::new("d@testrun.org").unwrap().as_ptr(),
|
||||
);
|
||||
dc_set_config(
|
||||
&ctx.clone().read().unwrap(),
|
||||
&ctx,
|
||||
CString::new("mail_pw").unwrap().as_ptr(),
|
||||
CString::new("***").unwrap().as_ptr(),
|
||||
);
|
||||
dc_configure(&ctx.clone().read().unwrap());
|
||||
dc_configure(&ctx);
|
||||
|
||||
std::thread::sleep_ms(4000);
|
||||
|
||||
let email = CString::new("dignifiedquire@gmail.com").unwrap();
|
||||
println!("sending a message");
|
||||
let contact_id = dc_create_contact(
|
||||
&ctx.clone().read().unwrap(),
|
||||
std::ptr::null(),
|
||||
email.as_ptr(),
|
||||
);
|
||||
let chat_id = dc_create_chat_by_contact_id(&ctx.clone().read().unwrap(), contact_id);
|
||||
let contact_id = dc_create_contact(&ctx, std::ptr::null(), email.as_ptr());
|
||||
let chat_id = dc_create_chat_by_contact_id(&ctx, contact_id);
|
||||
let msg_text = CString::new("Hi, here is my first message!").unwrap();
|
||||
dc_send_text_msg(&ctx.clone().read().unwrap(), chat_id, msg_text.as_ptr());
|
||||
dc_send_text_msg(&ctx, chat_id, msg_text.as_ptr());
|
||||
|
||||
println!("fetching chats..");
|
||||
let ctx1 = ctx.clone();
|
||||
let ctx = ctx1.read().unwrap();
|
||||
|
||||
let chats = dc_get_chatlist(&ctx, 0, std::ptr::null(), 0);
|
||||
|
||||
for i in 0..dc_chatlist_get_cnt(chats) {
|
||||
@@ -134,7 +128,7 @@ fn main() {
|
||||
}
|
||||
dc_chatlist_unref(chats);
|
||||
|
||||
// let msglist = dc_get_chat_msgs(&ctx.clone().read().unwrap(), chat_id, 0, 0);
|
||||
// let msglist = dc_get_chat_msgs(&ctx, chat_id, 0, 0);
|
||||
// for i in 0..dc_array_get_cnt(msglist) {
|
||||
// let msg_id = dc_array_get_id(msglist, i);
|
||||
// let msg = dc_get_msg(context, msg_id);
|
||||
|
||||
Reference in New Issue
Block a user