fix locking in the repl

This commit is contained in:
dignifiedquire
2019-05-07 15:18:42 +01:00
parent b0da2533ec
commit eac0c201bd
3 changed files with 122 additions and 132 deletions

View File

@@ -515,10 +515,7 @@ unsafe extern "C" fn chat_prefix(mut chat: *const dc_chat_t) -> *const libc::c_c
};
}
#[no_mangle]
pub unsafe extern "C" fn dc_cmdline(
context: &mut dc_context_t,
cmdline: &str,
) -> *mut libc::c_char {
pub unsafe extern "C" fn dc_cmdline(context: &dc_context_t, cmdline: &str) -> *mut libc::c_char {
let mut cmd: *mut libc::c_char;
let mut arg1: *mut libc::c_char;
let mut ret: *mut libc::c_char = 1i32 as *mut libc::c_char;
@@ -546,7 +543,7 @@ pub unsafe extern "C" fn dc_cmdline(
} else if 0 == s_is_auth {
if strcmp(cmd, b"auth\x00" as *const u8 as *const libc::c_char) == 0i32 {
let mut is_pw: *mut libc::c_char =
dc_get_config(&context, b"mail_pw\x00" as *const u8 as *const libc::c_char);
dc_get_config(context, b"mail_pw\x00" as *const u8 as *const libc::c_char);
if strcmp(arg1, is_pw) == 0i32 {
s_is_auth = 1i32;
ret = 2i32 as *mut libc::c_char
@@ -582,7 +579,7 @@ pub unsafe extern "C" fn dc_cmdline(
b"initiate-key-transfer\x00" as *const u8 as *const libc::c_char,
) == 0i32
{
let mut setup_code: *mut libc::c_char = dc_initiate_key_transfer(&context);
let mut setup_code: *mut libc::c_char = dc_initiate_key_transfer(context);
ret = if !setup_code.is_null() {
dc_mprintf(
b"Setup code for the transferred setup message: %s\x00" as *const u8
@@ -600,7 +597,7 @@ pub unsafe extern "C" fn dc_cmdline(
{
if !arg1.is_null() {
let mut msg_id: uint32_t = atoi(arg1) as uint32_t;
let mut msg: *mut dc_msg_t = dc_get_msg(&context, msg_id);
let mut msg: *mut dc_msg_t = dc_get_msg(context, msg_id);
if 0 != dc_msg_is_setupmessage(msg) {
let mut setupcodebegin: *mut libc::c_char = dc_msg_get_setupcodebegin(msg);
ret = dc_mprintf(
@@ -634,7 +631,7 @@ pub unsafe extern "C" fn dc_cmdline(
if !arg1.is_null() && !arg2.is_null() {
*arg2 = 0i32 as libc::c_char;
arg2 = arg2.offset(1isize);
ret = if 0 != dc_continue_key_transfer(&context, atoi(arg1) as uint32_t, arg2) {
ret = if 0 != dc_continue_key_transfer(context, atoi(arg1) as uint32_t, arg2) {
2i32 as *mut libc::c_char
} else {
1i32 as *mut libc::c_char
@@ -646,7 +643,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.get_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)
}
@@ -656,7 +653,7 @@ pub unsafe extern "C" fn dc_cmdline(
) == 0i32
{
dc_imex(
&context,
context,
11i32,
context.get_blobdir(),
0 as *const libc::c_char,
@@ -668,7 +665,7 @@ pub unsafe extern "C" fn dc_cmdline(
) == 0i32
{
if !arg1.is_null() {
dc_imex(&context, 12i32, arg1, 0 as *const libc::c_char);
dc_imex(context, 12i32, arg1, 0 as *const libc::c_char);
ret = 2i32 as *mut libc::c_char
} else {
ret = dc_strdup(
@@ -677,7 +674,7 @@ 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,
context,
1i32,
context.get_blobdir(),
0 as *const libc::c_char,
@@ -685,23 +682,23 @@ pub unsafe extern "C" fn dc_cmdline(
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,
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 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.get_blobdir(),
);
let mut file_content: *mut libc::c_char;
file_content = dc_render_setup_file(&context, setup_code_0);
file_content = dc_render_setup_file(context, setup_code_0);
if !file_content.is_null()
&& 0 != dc_write_file(
&context,
context,
file_name,
file_content as *const libc::c_void,
strlen(file_content),
@@ -720,7 +717,7 @@ pub unsafe extern "C" fn dc_cmdline(
free(file_name as *mut libc::c_void);
free(setup_code_0 as *mut libc::c_void);
} else if strcmp(cmd, b"poke\x00" as *const u8 as *const libc::c_char) == 0i32 {
ret = if 0 != poke_spec(&context, arg1) {
ret = if 0 != poke_spec(context, arg1) {
2i32 as *mut libc::c_char
} else {
1i32 as *mut libc::c_char
@@ -733,7 +730,7 @@ pub unsafe extern "C" fn dc_cmdline(
b"ERROR: <bits> must be lower than 16.\x00" as *const u8 as *const libc::c_char,
)
} else {
ret = if 0 != dc_reset_tables(&context, bits) {
ret = if 0 != dc_reset_tables(context, bits) {
2i32 as *mut libc::c_char
} else {
1i32 as *mut libc::c_char
@@ -745,7 +742,7 @@ pub unsafe extern "C" fn dc_cmdline(
as *const u8 as *const libc::c_char)
}
} else if strcmp(cmd, b"stop\x00" as *const u8 as *const libc::c_char) == 0i32 {
dc_stop_ongoing_process(&context);
dc_stop_ongoing_process(context);
ret = 2i32 as *mut libc::c_char
} else if strcmp(cmd, b"set\x00" as *const u8 as *const libc::c_char) == 0i32 {
if !arg1.is_null() {
@@ -754,7 +751,7 @@ pub unsafe extern "C" fn dc_cmdline(
*arg2_0 = 0i32 as libc::c_char;
arg2_0 = arg2_0.offset(1isize)
}
ret = if 0 != dc_set_config(&context, arg1, arg2_0) {
ret = if 0 != dc_set_config(context, arg1, arg2_0) {
2i32 as *mut libc::c_char
} else {
1i32 as *mut libc::c_char
@@ -765,7 +762,7 @@ pub unsafe extern "C" fn dc_cmdline(
}
} else if strcmp(cmd, b"get\x00" as *const u8 as *const libc::c_char) == 0i32 {
if !arg1.is_null() {
let mut val: *mut libc::c_char = dc_get_config(&context, arg1);
let mut val: *mut libc::c_char = dc_get_config(context, arg1);
ret = dc_mprintf(b"%s=%s\x00" as *const u8 as *const libc::c_char, arg1, val);
free(val as *mut libc::c_void);
} else {
@@ -773,15 +770,15 @@ pub unsafe extern "C" fn dc_cmdline(
dc_strdup(b"ERROR: Argument <key> missing.\x00" as *const u8 as *const libc::c_char)
}
} else if strcmp(cmd, b"info\x00" as *const u8 as *const libc::c_char) == 0i32 {
ret = dc_get_info(&context);
ret = dc_get_info(context);
if ret.is_null() {
ret = 1i32 as *mut libc::c_char
}
} else if strcmp(cmd, b"maybenetwork\x00" as *const u8 as *const libc::c_char) == 0i32 {
dc_maybe_network(&context);
dc_maybe_network(context);
ret = 2i32 as *mut libc::c_char
} else if strcmp(cmd, b"housekeeping\x00" as *const u8 as *const libc::c_char) == 0i32 {
dc_housekeeping(&context);
dc_housekeeping(context);
ret = 2i32 as *mut libc::c_char
} else if strcmp(cmd, b"listchats\x00" as *const u8 as *const libc::c_char) == 0i32
|| strcmp(cmd, b"listarchived\x00" as *const u8 as *const libc::c_char) == 0i32
@@ -795,30 +792,30 @@ pub unsafe extern "C" fn dc_cmdline(
};
let mut chatlist: *mut dc_chatlist_t =
dc_get_chatlist(&context, listflags, arg1, 0i32 as uint32_t);
dc_get_chatlist(context, listflags, arg1, 0i32 as uint32_t);
if !chatlist.is_null() {
let mut i: libc::c_int;
let mut cnt: libc::c_int = dc_chatlist_get_cnt(chatlist) as libc::c_int;
if cnt > 0i32 {
dc_log_info(&context, 0i32,
dc_log_info(context, 0i32,
b"================================================================================\x00"
as *const u8 as *const libc::c_char);
i = cnt - 1i32;
while i >= 0i32 {
let mut chat: *mut dc_chat_t =
dc_get_chat(&context, dc_chatlist_get_chat_id(chatlist, i as size_t));
dc_get_chat(context, dc_chatlist_get_chat_id(chatlist, i as size_t));
let mut temp_subtitle: *mut libc::c_char = dc_chat_get_subtitle(chat);
let mut temp_name: *mut libc::c_char = dc_chat_get_name(chat);
dc_log_info(
&context,
context,
0i32,
b"%s#%i: %s [%s] [%i fresh]\x00" as *const u8 as *const libc::c_char,
chat_prefix(chat),
dc_chat_get_id(chat) as libc::c_int,
temp_name,
temp_subtitle,
dc_get_fresh_msg_cnt(&context, dc_chat_get_id(chat)) as libc::c_int,
dc_get_fresh_msg_cnt(context, dc_chat_get_id(chat)) as libc::c_int,
);
free(temp_subtitle as *mut libc::c_void);
free(temp_name as *mut libc::c_void);
@@ -847,7 +844,7 @@ pub unsafe extern "C" fn dc_cmdline(
let mut text1: *mut libc::c_char = dc_lot_get_text1(lot);
let mut text2: *mut libc::c_char = dc_lot_get_text2(lot);
dc_log_info(
&context,
context,
0i32,
b"%s%s%s%s [%s]%s\x00" as *const u8 as *const libc::c_char,
if !text1.is_null() {
@@ -878,15 +875,15 @@ pub unsafe extern "C" fn dc_cmdline(
free(timestr as *mut libc::c_void);
dc_lot_unref(lot);
dc_chat_unref(chat);
dc_log_info(&context, 0i32,
dc_log_info(context, 0i32,
b"================================================================================\x00"
as *const u8 as *const libc::c_char);
i -= 1
}
}
if 0 != dc_is_sending_locations_to_chat(&context, 0i32 as uint32_t) {
if 0 != dc_is_sending_locations_to_chat(context, 0i32 as uint32_t) {
dc_log_info(
&context,
context,
0i32,
b"Location streaming enabled.\x00" as *const u8 as *const libc::c_char,
);
@@ -906,17 +903,17 @@ pub unsafe extern "C" fn dc_cmdline(
sel_chat = 0 as *mut dc_chat_t
}
context.cmdline_sel_chat_id = if sel_chat.is_null() {
*context.cmdline_sel_chat_id.write().unwrap() = if sel_chat.is_null() {
0
} else {
atoi(arg1) as uint32_t
};
sel_chat = dc_get_chat(&context, context.cmdline_sel_chat_id);
sel_chat = dc_get_chat(context, *context.cmdline_sel_chat_id.read().unwrap());
}
if !sel_chat.is_null() {
let mut msglist: *mut dc_array_t = dc_get_chat_msgs(
&context,
context,
dc_chat_get_id(sel_chat),
0x1i32 as uint32_t,
0i32 as uint32_t,
@@ -924,7 +921,7 @@ pub unsafe extern "C" fn dc_cmdline(
let mut temp2: *mut libc::c_char = dc_chat_get_subtitle(sel_chat);
let mut temp_name_0: *mut libc::c_char = dc_chat_get_name(sel_chat);
dc_log_info(
&context,
context,
0i32,
b"%s#%i: %s [%s]%s\x00" as *const u8 as *const libc::c_char,
chat_prefix(sel_chat),
@@ -940,13 +937,13 @@ pub unsafe extern "C" fn dc_cmdline(
free(temp_name_0 as *mut libc::c_void);
free(temp2 as *mut libc::c_void);
if !msglist.is_null() {
log_msglist(&context, msglist);
log_msglist(context, msglist);
dc_array_unref(msglist);
}
let mut draft: *mut dc_msg_t = dc_get_draft(&context, dc_chat_get_id(sel_chat));
let mut draft: *mut dc_msg_t = dc_get_draft(context, dc_chat_get_id(sel_chat));
if !draft.is_null() {
log_msg(
&context,
context,
b"Draft\x00" as *const u8 as *const libc::c_char,
draft,
);
@@ -954,9 +951,9 @@ pub unsafe extern "C" fn dc_cmdline(
}
ret = dc_mprintf(
b"%i messages.\x00" as *const u8 as *const libc::c_char,
dc_get_msg_cnt(&context, dc_chat_get_id(sel_chat)),
dc_get_msg_cnt(context, dc_chat_get_id(sel_chat)),
);
dc_marknoticed_chat(&context, dc_chat_get_id(sel_chat));
dc_marknoticed_chat(context, dc_chat_get_id(sel_chat));
} else {
ret = dc_strdup(b"No chat selected.\x00" as *const u8 as *const libc::c_char)
}
@@ -964,7 +961,7 @@ pub unsafe extern "C" fn dc_cmdline(
if !arg1.is_null() {
let mut contact_id: libc::c_int = atoi(arg1);
let mut chat_id: libc::c_int =
dc_create_chat_by_contact_id(&context, contact_id as uint32_t) as libc::c_int;
dc_create_chat_by_contact_id(context, contact_id as uint32_t) as libc::c_int;
ret = if chat_id != 0i32 {
dc_mprintf(
b"Single#%lu created successfully.\x00" as *const u8 as *const libc::c_char,
@@ -986,9 +983,9 @@ pub unsafe extern "C" fn dc_cmdline(
if !arg1.is_null() {
let mut msg_id_0: libc::c_int = atoi(arg1);
let mut chat_id_0: libc::c_int =
dc_create_chat_by_msg_id(&context, msg_id_0 as uint32_t) as libc::c_int;
dc_create_chat_by_msg_id(context, msg_id_0 as uint32_t) as libc::c_int;
if chat_id_0 != 0i32 {
let mut chat_0: *mut dc_chat_t = dc_get_chat(&context, chat_id_0 as uint32_t);
let mut chat_0: *mut dc_chat_t = dc_get_chat(context, chat_id_0 as uint32_t);
ret = dc_mprintf(
b"%s#%lu created successfully.\x00" as *const u8 as *const libc::c_char,
chat_prefix(chat_0),
@@ -1006,7 +1003,7 @@ pub unsafe extern "C" fn dc_cmdline(
} else if strcmp(cmd, b"creategroup\x00" as *const u8 as *const libc::c_char) == 0i32 {
if !arg1.is_null() {
let mut chat_id_1: libc::c_int =
dc_create_group_chat(&context, 0i32, arg1) as libc::c_int;
dc_create_group_chat(context, 0i32, arg1) as libc::c_int;
ret = if chat_id_1 != 0i32 {
dc_mprintf(
b"Group#%lu created successfully.\x00" as *const u8 as *const libc::c_char,
@@ -1027,7 +1024,7 @@ pub unsafe extern "C" fn dc_cmdline(
{
if !arg1.is_null() {
let mut chat_id_2: libc::c_int =
dc_create_group_chat(&context, 1i32, arg1) as libc::c_int;
dc_create_group_chat(context, 1i32, arg1) as libc::c_int;
ret = if chat_id_2 != 0i32 {
dc_mprintf(
b"VerifiedGroup#%lu created successfully.\x00" as *const u8
@@ -1047,7 +1044,7 @@ pub unsafe extern "C" fn dc_cmdline(
if !arg1.is_null() {
let mut contact_id_0: libc::c_int = atoi(arg1);
if 0 != dc_add_contact_to_chat(
&context,
context,
dc_chat_get_id(sel_chat),
contact_id_0 as uint32_t,
) {
@@ -1073,7 +1070,7 @@ pub unsafe extern "C" fn dc_cmdline(
if !arg1.is_null() {
let mut contact_id_1: libc::c_int = atoi(arg1);
if 0 != dc_remove_contact_from_chat(
&context,
context,
dc_chat_get_id(sel_chat),
contact_id_1 as uint32_t,
) {
@@ -1097,7 +1094,7 @@ pub unsafe extern "C" fn dc_cmdline(
} else if strcmp(cmd, b"groupname\x00" as *const u8 as *const libc::c_char) == 0i32 {
if !sel_chat.is_null() {
if !arg1.is_null() && 0 != *arg1.offset(0isize) as libc::c_int {
ret = if 0 != dc_set_chat_name(&context, dc_chat_get_id(sel_chat), arg1) {
ret = if 0 != dc_set_chat_name(context, dc_chat_get_id(sel_chat), arg1) {
2i32 as *mut libc::c_char
} else {
1i32 as *mut libc::c_char
@@ -1114,7 +1111,7 @@ pub unsafe extern "C" fn dc_cmdline(
if !sel_chat.is_null() {
ret = if 0
!= dc_set_chat_profile_image(
&context,
context,
dc_chat_get_id(sel_chat),
if !arg1.is_null() && 0 != *arg1.offset(0isize) as libc::c_int {
arg1
@@ -1132,18 +1129,18 @@ pub unsafe extern "C" fn dc_cmdline(
} else if strcmp(cmd, b"chatinfo\x00" as *const u8 as *const libc::c_char) == 0i32 {
if !sel_chat.is_null() {
let mut contacts: *mut dc_array_t =
dc_get_chat_contacts(&context, dc_chat_get_id(sel_chat));
dc_get_chat_contacts(context, dc_chat_get_id(sel_chat));
if !contacts.is_null() {
dc_log_info(
&context,
context,
0i32,
b"Memberlist:\x00" as *const u8 as *const libc::c_char,
);
log_contactlist(&context, contacts);
log_contactlist(context, contacts);
ret = dc_mprintf(
b"%i contacts\nLocation streaming: %i\x00" as *const u8 as *const libc::c_char,
dc_array_get_cnt(contacts) as libc::c_int,
dc_is_sending_locations_to_chat(&context, dc_chat_get_id(sel_chat)),
dc_is_sending_locations_to_chat(context, dc_chat_get_id(sel_chat)),
);
dc_array_unref(contacts);
} else {
@@ -1155,7 +1152,7 @@ pub unsafe extern "C" fn dc_cmdline(
} else if strcmp(cmd, b"getlocations\x00" as *const u8 as *const libc::c_char) == 0i32 {
let mut contact_id_2: libc::c_int = if !arg1.is_null() { atoi(arg1) } else { 0i32 };
let mut loc: *mut dc_array_t = dc_get_locations(
&context,
context,
dc_chat_get_id(sel_chat),
contact_id_2 as uint32_t,
0i32 as time_t,
@@ -1167,7 +1164,7 @@ pub unsafe extern "C" fn dc_cmdline(
dc_timestamp_to_str(dc_array_get_timestamp(loc, j as size_t));
let mut marker: *mut libc::c_char = dc_array_get_marker(loc, j as size_t);
dc_log_info(
&context,
context,
0i32,
b"Loc#%i: %s: lat=%f lng=%f acc=%f Chat#%i Contact#%i Msg#%i %s\x00" as *const u8
as *const libc::c_char,
@@ -1191,7 +1188,7 @@ pub unsafe extern "C" fn dc_cmdline(
}
if dc_array_get_cnt(loc) == 0 {
dc_log_info(
&context,
context,
0i32,
b"No locations.\x00" as *const u8 as *const libc::c_char,
);
@@ -1206,7 +1203,7 @@ pub unsafe extern "C" fn dc_cmdline(
if !sel_chat.is_null() {
if !arg1.is_null() && 0 != *arg1.offset(0isize) as libc::c_int {
let mut seconds: libc::c_int = atoi(arg1);
dc_send_locations_to_chat(&context, dc_chat_get_id(sel_chat), seconds);
dc_send_locations_to_chat(context, dc_chat_get_id(sel_chat), seconds);
ret =
dc_mprintf(b"Locations will be sent to Chat#%i for %i seconds. Use \'setlocation <lat> <lng>\' to play around.\x00"
as *const u8 as *const libc::c_char,
@@ -1228,7 +1225,7 @@ pub unsafe extern "C" fn dc_cmdline(
let mut latitude: libc::c_double = atof(arg1);
let mut longitude: libc::c_double = atof(arg2_1);
let mut continue_streaming: libc::c_int =
dc_set_location(&context, latitude, longitude, 0.0f64);
dc_set_location(context, latitude, longitude, 0.0f64);
ret = dc_strdup(if 0 != continue_streaming {
b"Success, streaming should be continued.\x00" as *const u8 as *const libc::c_char
} else {
@@ -1240,12 +1237,12 @@ pub unsafe extern "C" fn dc_cmdline(
)
}
} else if strcmp(cmd, b"dellocations\x00" as *const u8 as *const libc::c_char) == 0i32 {
dc_delete_all_locations(&context);
dc_delete_all_locations(context);
ret = 2i32 as *mut libc::c_char
} else if strcmp(cmd, b"send\x00" as *const u8 as *const libc::c_char) == 0i32 {
if !sel_chat.is_null() {
if !arg1.is_null() && 0 != *arg1.offset(0isize) as libc::c_int {
if 0 != dc_send_text_msg(&context, dc_chat_get_id(sel_chat), arg1) {
if 0 != dc_send_text_msg(context, dc_chat_get_id(sel_chat), arg1) {
ret = dc_strdup(b"Message sent.\x00" as *const u8 as *const libc::c_char)
} else {
ret =
@@ -1262,7 +1259,7 @@ pub unsafe extern "C" fn dc_cmdline(
} else if strcmp(cmd, b"sendempty\x00" as *const u8 as *const libc::c_char) == 0i32 {
if !sel_chat.is_null() {
if 0 != dc_send_text_msg(
&context,
context,
dc_chat_get_id(sel_chat),
b"\x00" as *const u8 as *const libc::c_char,
) {
@@ -1284,7 +1281,7 @@ pub unsafe extern "C" fn dc_cmdline(
arg2_2 = arg2_2.offset(1isize)
}
let mut msg_0: *mut dc_msg_t = dc_msg_new(
&context,
context,
if strcmp(cmd, b"sendimage\x00" as *const u8 as *const libc::c_char) == 0i32 {
20i32
} else {
@@ -1293,7 +1290,7 @@ pub unsafe extern "C" fn dc_cmdline(
);
dc_msg_set_file(msg_0, arg1, 0 as *const libc::c_char);
dc_msg_set_text(msg_0, arg2_2);
dc_send_msg(&context, dc_chat_get_id(sel_chat), msg_0);
dc_send_msg(context, dc_chat_get_id(sel_chat), msg_0);
dc_msg_unref(msg_0);
ret = 2i32 as *mut libc::c_char
} else {
@@ -1305,7 +1302,7 @@ pub unsafe extern "C" fn dc_cmdline(
} else if strcmp(cmd, b"listmsgs\x00" as *const u8 as *const libc::c_char) == 0i32 {
if !arg1.is_null() {
let mut msglist_0: *mut dc_array_t = dc_search_msgs(
&context,
context,
if !sel_chat.is_null() {
dc_chat_get_id(sel_chat)
} else {
@@ -1314,7 +1311,7 @@ pub unsafe extern "C" fn dc_cmdline(
arg1,
);
if !msglist_0.is_null() {
log_msglist(&context, msglist_0);
log_msglist(context, msglist_0);
ret = dc_mprintf(
b"%i messages.\x00" as *const u8 as *const libc::c_char,
dc_array_get_cnt(msglist_0) as libc::c_int,
@@ -1329,13 +1326,13 @@ pub unsafe extern "C" fn dc_cmdline(
} else if strcmp(cmd, b"draft\x00" as *const u8 as *const libc::c_char) == 0i32 {
if !sel_chat.is_null() {
if !arg1.is_null() && 0 != *arg1.offset(0isize) as libc::c_int {
let mut draft_0: *mut dc_msg_t = dc_msg_new(&context, 10i32);
let mut draft_0: *mut dc_msg_t = dc_msg_new(context, 10i32);
dc_msg_set_text(draft_0, arg1);
dc_set_draft(&context, dc_chat_get_id(sel_chat), draft_0);
dc_set_draft(context, dc_chat_get_id(sel_chat), draft_0);
dc_msg_unref(draft_0);
ret = dc_strdup(b"Draft saved.\x00" as *const u8 as *const libc::c_char)
} else {
dc_set_draft(&context, dc_chat_get_id(sel_chat), 0 as *mut dc_msg_t);
dc_set_draft(context, dc_chat_get_id(sel_chat), 0 as *mut dc_msg_t);
ret = dc_strdup(b"Draft deleted.\x00" as *const u8 as *const libc::c_char)
}
} else {
@@ -1344,7 +1341,7 @@ pub unsafe extern "C" fn dc_cmdline(
} else if strcmp(cmd, b"listmedia\x00" as *const u8 as *const libc::c_char) == 0i32 {
if !sel_chat.is_null() {
let mut images: *mut dc_array_t =
dc_get_chat_media(&context, dc_chat_get_id(sel_chat), 20i32, 21i32, 50i32);
dc_get_chat_media(context, dc_chat_get_id(sel_chat), 20i32, 21i32, 50i32);
let mut i_0: libc::c_int;
let mut icnt: libc::c_int = dc_array_get_cnt(images) as libc::c_int;
ret = dc_mprintf(
@@ -1377,7 +1374,7 @@ pub unsafe extern "C" fn dc_cmdline(
if !arg1.is_null() {
let mut chat_id_3: libc::c_int = atoi(arg1);
dc_archive_chat(
&context,
context,
chat_id_3 as uint32_t,
if strcmp(cmd, b"archive\x00" as *const u8 as *const libc::c_char) == 0i32 {
1i32
@@ -1394,7 +1391,7 @@ pub unsafe extern "C" fn dc_cmdline(
} else if strcmp(cmd, b"delchat\x00" as *const u8 as *const libc::c_char) == 0i32 {
if !arg1.is_null() {
let mut chat_id_4: libc::c_int = atoi(arg1);
dc_delete_chat(&context, chat_id_4 as uint32_t);
dc_delete_chat(context, chat_id_4 as uint32_t);
ret = 2i32 as *mut libc::c_char
} else {
ret = dc_strdup(
@@ -1404,16 +1401,16 @@ pub unsafe extern "C" fn dc_cmdline(
} else if strcmp(cmd, b"msginfo\x00" as *const u8 as *const libc::c_char) == 0i32 {
if !arg1.is_null() {
let mut id: libc::c_int = atoi(arg1);
ret = dc_get_msg_info(&context, id as uint32_t)
ret = dc_get_msg_info(context, id as uint32_t)
} else {
ret = dc_strdup(
b"ERROR: Argument <msg-id> missing.\x00" as *const u8 as *const libc::c_char,
)
}
} else if strcmp(cmd, b"listfresh\x00" as *const u8 as *const libc::c_char) == 0i32 {
let mut msglist_1: *mut dc_array_t = dc_get_fresh_msgs(&context);
let mut msglist_1: *mut dc_array_t = dc_get_fresh_msgs(context);
if !msglist_1.is_null() {
log_msglist(&context, msglist_1);
log_msglist(context, msglist_1);
ret = dc_mprintf(
b"%i fresh messages.\x00" as *const u8 as *const libc::c_char,
dc_array_get_cnt(msglist_1) as libc::c_int,
@@ -1431,7 +1428,7 @@ pub unsafe extern "C" fn dc_cmdline(
let mut msg_ids: [uint32_t; 1] = [0; 1];
let mut chat_id_5: uint32_t = atoi(arg2_3) as uint32_t;
msg_ids[0usize] = atoi(arg1) as uint32_t;
dc_forward_msgs(&context, msg_ids.as_mut_ptr(), 1i32, chat_id_5);
dc_forward_msgs(context, msg_ids.as_mut_ptr(), 1i32, chat_id_5);
ret = 2i32 as *mut libc::c_char
} else {
ret = dc_strdup(
@@ -1443,7 +1440,7 @@ pub unsafe extern "C" fn dc_cmdline(
if !arg1.is_null() {
let mut msg_ids_0: [uint32_t; 1] = [0; 1];
msg_ids_0[0usize] = atoi(arg1) as uint32_t;
dc_markseen_msgs(&context, msg_ids_0.as_mut_ptr(), 1i32);
dc_markseen_msgs(context, msg_ids_0.as_mut_ptr(), 1i32);
ret = 2i32 as *mut libc::c_char
} else {
ret = dc_strdup(
@@ -1457,7 +1454,7 @@ pub unsafe extern "C" fn dc_cmdline(
let mut msg_ids_1: [uint32_t; 1] = [0; 1];
msg_ids_1[0usize] = atoi(arg1) as uint32_t;
dc_star_msgs(
&context,
context,
msg_ids_1.as_mut_ptr(),
1i32,
if strcmp(cmd, b"star\x00" as *const u8 as *const libc::c_char) == 0i32 {
@@ -1476,7 +1473,7 @@ pub unsafe extern "C" fn dc_cmdline(
if !arg1.is_null() {
let mut ids: [uint32_t; 1] = [0; 1];
ids[0usize] = atoi(arg1) as uint32_t;
dc_delete_msgs(&context, ids.as_mut_ptr(), 1i32);
dc_delete_msgs(context, ids.as_mut_ptr(), 1i32);
ret = 2i32 as *mut libc::c_char
} else {
ret = dc_strdup(
@@ -1488,7 +1485,7 @@ pub unsafe extern "C" fn dc_cmdline(
|| strcmp(cmd, b"listverified\x00" as *const u8 as *const libc::c_char) == 0i32
{
let mut contacts_0: *mut dc_array_t = dc_get_contacts(
&context,
context,
(if strcmp(cmd, b"listverified\x00" as *const u8 as *const libc::c_char) == 0i32 {
0x1i32 | 0x2i32
} else {
@@ -1497,7 +1494,7 @@ pub unsafe extern "C" fn dc_cmdline(
arg1,
);
if !contacts_0.is_null() {
log_contactlist(&context, contacts_0);
log_contactlist(context, contacts_0);
ret = dc_mprintf(
b"%i contacts.\x00" as *const u8 as *const libc::c_char,
dc_array_get_cnt(contacts_0) as libc::c_int,
@@ -1520,11 +1517,11 @@ pub unsafe extern "C" fn dc_cmdline(
arg1,
arg2_4,
);
dc_add_address_book(&context, book);
dc_add_address_book(context, book);
ret = 2i32 as *mut libc::c_char;
free(book as *mut libc::c_void);
} else if !arg1.is_null() {
ret = if 0 != dc_create_contact(&context, 0 as *const libc::c_char, arg1) {
ret = if 0 != dc_create_contact(context, 0 as *const libc::c_char, arg1) {
2i32 as *mut libc::c_char
} else {
1i32 as *mut libc::c_char
@@ -1546,7 +1543,7 @@ pub unsafe extern "C" fn dc_cmdline(
};
dc_strbuilder_init(&mut strbuilder, 0i32);
let mut contact: *mut dc_contact_t = dc_get_contact(&context, contact_id_3 as uint32_t);
let mut contact: *mut dc_contact_t = dc_get_contact(context, contact_id_3 as uint32_t);
let mut nameNaddr: *mut libc::c_char = dc_contact_get_name_n_addr(contact);
dc_strbuilder_catf(
&mut strbuilder as *mut dc_strbuilder_t,
@@ -1556,11 +1553,11 @@ pub unsafe extern "C" fn dc_cmdline(
free(nameNaddr as *mut libc::c_void);
dc_contact_unref(contact);
let mut encrinfo: *mut libc::c_char =
dc_get_contact_encrinfo(&context, contact_id_3 as uint32_t);
dc_get_contact_encrinfo(context, contact_id_3 as uint32_t);
dc_strbuilder_cat(&mut strbuilder, encrinfo);
free(encrinfo as *mut libc::c_void);
let mut chatlist_0: *mut dc_chatlist_t = dc_get_chatlist(
&context,
context,
0i32,
0 as *const libc::c_char,
contact_id_3 as uint32_t,
@@ -1583,7 +1580,7 @@ pub unsafe extern "C" fn dc_cmdline(
);
}
let mut chat_1: *mut dc_chat_t =
dc_get_chat(&context, dc_chatlist_get_chat_id(chatlist_0, i_1 as size_t));
dc_get_chat(context, dc_chatlist_get_chat_id(chatlist_0, i_1 as size_t));
dc_strbuilder_catf(
&mut strbuilder as *mut dc_strbuilder_t,
b"%s#%i\x00" as *const u8 as *const libc::c_char,
@@ -1603,7 +1600,7 @@ pub unsafe extern "C" fn dc_cmdline(
}
} else if strcmp(cmd, b"delcontact\x00" as *const u8 as *const libc::c_char) == 0i32 {
if !arg1.is_null() {
ret = if 0 != dc_delete_contact(&context, atoi(arg1) as uint32_t) {
ret = if 0 != dc_delete_contact(context, atoi(arg1) as uint32_t) {
2i32 as *mut libc::c_char
} else {
1i32 as *mut libc::c_char
@@ -1615,7 +1612,7 @@ pub unsafe extern "C" fn dc_cmdline(
}
} else if strcmp(cmd, b"getqr\x00" as *const u8 as *const libc::c_char) == 0i32 {
ret = dc_get_securejoin_qr(
&context,
context,
(if !arg1.is_null() { atoi(arg1) } else { 0i32 }) as uint32_t,
);
if ret.is_null() || *ret.offset(0isize) as libc::c_int == 0i32 {
@@ -1624,7 +1621,7 @@ pub unsafe extern "C" fn dc_cmdline(
}
} else if strcmp(cmd, b"checkqr\x00" as *const u8 as *const libc::c_char) == 0i32 {
if !arg1.is_null() {
let mut res: *mut dc_lot_t = dc_check_qr(&context, arg1);
let mut res: *mut dc_lot_t = dc_check_qr(context, arg1);
ret = dc_mprintf(
b"state=%i, id=%i, text1=%s, text2=%s\x00" as *const u8 as *const libc::c_char,
(*res).state as libc::c_int,
@@ -1650,7 +1647,7 @@ pub unsafe extern "C" fn dc_cmdline(
if !arg1.is_null() {
let mut event = Event::from_u32(atoi(arg1) as u32).unwrap();
let mut r: uintptr_t =
(&context.cb)(&context, event, 0i32 as uintptr_t, 0i32 as uintptr_t);
(context.cb)(context, event, 0i32 as uintptr_t, 0i32 as uintptr_t);
ret = dc_mprintf(
b"Sending event %i, received value %i.\x00" as *const u8 as *const libc::c_char,
event as libc::c_int,
@@ -1668,7 +1665,7 @@ pub unsafe extern "C" fn dc_cmdline(
let mut h: uint32_t = 0;
if 0 != dc_read_file(
&context,
context,
arg1,
&mut buf as *mut *mut libc::c_uchar as *mut *mut libc::c_void,
&mut buf_bytes,
@@ -1707,5 +1704,5 @@ pub unsafe extern "C" fn dc_cmdline(
dc_chat_unref(sel_chat);
}
free(cmd as *mut libc::c_void);
return ret;
ret
}

View File

@@ -274,57 +274,50 @@ unsafe fn start_threads(
std::thread::JoinHandle<()>,
) {
run_threads = 1;
let context = c.clone();
let h1 = std::thread::spawn(move || {
while 0 != run_threads {
let ctx = context.clone();
let context = ctx.read().unwrap();
println!("-- imap jobs");
let ctx = c.clone();
let h1 = std::thread::spawn(move || {
let context = ctx.read().unwrap();
while 0 != run_threads {
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);
}
}
});
let _context = c.clone();
let ctx = 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 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 ctx = 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 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 ctx = 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 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)
@@ -494,7 +487,7 @@ unsafe fn main_0(mut argc: libc::c_int, mut argv: *mut *mut libc::c_char) -> lib
}
if !(*cmd.offset(0isize) as libc::c_int == 0i32) {
let mut execute_result: *mut libc::c_char =
dc_cmdline(&mut ctx.clone().write().unwrap(), &cmdline);
dc_cmdline(&ctx.read().unwrap(), &cmdline);
if !execute_result.is_null() {
printf(
b"%s\n\x00" as *const u8 as *const libc::c_char,