Use DC_PARAM_* constants everywhere

Also document each type they store.  This makes existing code a little
more readable and gives some hints towards refactoring this.
This commit is contained in:
Floris Bruynooghe
2019-07-21 20:25:52 +02:00
parent 3dfd623db7
commit 7774052911
12 changed files with 318 additions and 184 deletions

View File

@@ -164,7 +164,7 @@ pub fn dc_chat_load_from_db(chat: *mut Chat, chat_id: u32) -> bool {
(*chat).name = dc_stock_str((*chat).context, 41);
},
_ => {
if 0 != unsafe { dc_param_exists((*chat).param, 'K' as i32) } {
if 0 != unsafe { dc_param_exists((*chat).param, DC_PARAM_SELFTALK as i32) } {
unsafe {
free((*chat).name as *mut libc::c_void);
(*chat).name = dc_stock_str((*chat).context, 2);
@@ -379,7 +379,7 @@ unsafe fn prepare_msg_common<'a>(
|| (*msg).type_0 == 50i32
|| (*msg).type_0 == 60i32
{
pathNfilename = dc_param_get((*msg).param, 'f' as i32, 0 as *const libc::c_char);
pathNfilename = dc_param_get((*msg).param, DC_PARAM_FILE as i32, 0 as *const libc::c_char);
if pathNfilename.is_null() {
error!(
context,
@@ -394,24 +394,24 @@ unsafe fn prepare_msg_common<'a>(
} else if 0 == dc_make_rel_and_copy(context, &mut pathNfilename) {
current_block = 2171833246886114521;
} else {
dc_param_set((*msg).param, 'f' as i32, pathNfilename);
dc_param_set((*msg).param, DC_PARAM_FILE as i32, pathNfilename);
if (*msg).type_0 == 60i32 || (*msg).type_0 == 20i32 {
let mut better_type: libc::c_int = 0i32;
let mut better_mime: *mut libc::c_char = 0 as *mut libc::c_char;
dc_msg_guess_msgtype_from_suffix(pathNfilename, &mut better_type, &mut better_mime);
if 0 != better_type {
(*msg).type_0 = better_type;
dc_param_set((*msg).param, 'm' as i32, better_mime);
dc_param_set((*msg).param, DC_PARAM_MIMETYPE as i32, better_mime);
}
free(better_mime as *mut libc::c_void);
} else if 0 == dc_param_exists((*msg).param, 'm' as i32) {
} else if 0 == dc_param_exists((*msg).param, DC_PARAM_MIMETYPE as i32) {
let mut better_mime_0: *mut libc::c_char = 0 as *mut libc::c_char;
dc_msg_guess_msgtype_from_suffix(
pathNfilename,
0 as *mut libc::c_int,
&mut better_mime_0,
);
dc_param_set((*msg).param, 'm' as i32, better_mime_0);
dc_param_set((*msg).param, DC_PARAM_MIMETYPE as i32, better_mime_0);
free(better_mime_0 as *mut libc::c_void);
}
info!(
@@ -519,8 +519,12 @@ unsafe fn prepare_msg_raw(
}
} else {
if (*chat).type_0 == 120 || (*chat).type_0 == 130 {
if dc_param_get_int((*chat).param, 'U' as i32, 0) == 1 {
dc_param_set((*chat).param, 'U' as i32, 0 as *const libc::c_char);
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0) == 1 {
dc_param_set(
(*chat).param,
DC_PARAM_UNPROMOTED as i32,
0 as *const libc::c_char,
);
dc_chat_update_param(chat);
}
}
@@ -538,7 +542,9 @@ unsafe fn prepare_msg_raw(
.sql
.get_config_int(context, "e2ee_enabled")
.unwrap_or_else(|| 1);
if 0 != e2ee_enabled && dc_param_get_int((*msg).param, 'u' as i32, 0) == 0 {
if 0 != e2ee_enabled
&& dc_param_get_int((*msg).param, DC_PARAM_FORCE_PLAINTEXT as i32, 0) == 0
{
let mut can_encrypt = 1;
let mut all_mutual = 1;
@@ -593,9 +599,13 @@ unsafe fn prepare_msg_raw(
}
}
if 0 != do_guarantee_e2ee {
dc_param_set_int((*msg).param, 'c' as i32, 1);
dc_param_set_int((*msg).param, DC_PARAM_GUARANTEE_E2EE as i32, 1);
}
dc_param_set((*msg).param, 'e' as i32, 0 as *const libc::c_char);
dc_param_set(
(*msg).param,
DC_PARAM_ERRONEOUS_E2EE as i32,
0 as *const libc::c_char,
);
if 0 == dc_chat_is_self_talk(chat)
&& 0 != get_parent_mime_headers(
chat,
@@ -798,7 +808,7 @@ pub unsafe fn dc_chat_is_self_talk(chat: *const Chat) -> libc::c_int {
if chat.is_null() || (*chat).magic != 0xc4a7c4a7u32 {
return 0i32;
}
dc_param_exists((*chat).param, 'K' as i32)
dc_param_exists((*chat).param, DC_PARAM_SELFTALK as i32)
}
/*******************************************************************************
@@ -825,7 +835,7 @@ unsafe fn last_msg_in_chat_encrypted(
let packed_c = to_cstring(packed);
dc_param_set_packed(msg_param, packed_c.as_ptr());
if 0 != dc_param_exists(msg_param, 'c' as i32) {
if 0 != dc_param_exists(msg_param, DC_PARAM_GUARANTEE_E2EE as i32) {
last_is_encrypted = 1;
}
dc_param_unref(msg_param);
@@ -903,7 +913,11 @@ pub unsafe fn dc_send_msg<'a>(
}
if 0 == chat_id {
let forwards = dc_param_get((*msg).param, 'P' as i32, 0 as *const libc::c_char);
let forwards = dc_param_get(
(*msg).param,
DC_PARAM_PREP_FORWARDS as i32,
0 as *const libc::c_char,
);
if !forwards.is_null() {
let mut p = forwards;
while 0 != *p {
@@ -919,7 +933,11 @@ pub unsafe fn dc_send_msg<'a>(
dc_msg_unref(copy);
}
}
dc_param_set((*msg).param, 'P' as i32, 0 as *const libc::c_char);
dc_param_set(
(*msg).param,
DC_PARAM_PREP_FORWARDS as i32,
0 as *const libc::c_char,
);
dc_msg_save_param_to_disk(msg);
}
free(forwards as *mut libc::c_void);
@@ -979,7 +997,8 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
|| (*msg).type_0 == 50i32
|| (*msg).type_0 == 60i32
{
pathNfilename = dc_param_get((*msg).param, 'f' as i32, 0 as *const libc::c_char);
pathNfilename =
dc_param_get((*msg).param, DC_PARAM_FILE as i32, 0 as *const libc::c_char);
if pathNfilename.is_null() {
current_block = 14513523936503887211;
} else if 0 != dc_msg_is_increation(msg)
@@ -989,7 +1008,7 @@ unsafe fn set_draft_raw(context: &Context, chat_id: uint32_t, msg: *mut dc_msg_t
} else if 0 == dc_make_rel_and_copy(context, &mut pathNfilename) {
current_block = 14513523936503887211;
} else {
dc_param_set((*msg).param, 'f' as i32, pathNfilename);
dc_param_set((*msg).param, DC_PARAM_FILE as i32, pathNfilename);
current_block = 4495394744059808450;
}
} else {
@@ -1551,8 +1570,14 @@ pub unsafe fn dc_add_contact_to_chat_ex(
);
} else {
/* we shoud respect this - whatever we send to the group, it gets discarded anyway! */
if 0 != flags & 0x1 && dc_param_get_int((*chat).param, 'U' as i32, 0) == 1 {
dc_param_set((*chat).param, 'U' as i32, 0 as *const libc::c_char);
if 0 != flags & 0x1
&& dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0) == 1
{
dc_param_set(
(*chat).param,
DC_PARAM_UNPROMOTED as i32,
0 as *const libc::c_char,
);
dc_chat_update_param(chat);
}
let self_addr = context
@@ -1600,7 +1625,7 @@ pub unsafe fn dc_add_contact_to_chat_ex(
match current_block {
12326129973959287090 => {}
_ => {
if dc_param_get_int((*chat).param, 'U' as i32, 0) == 0 {
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0) == 0 {
(*msg).type_0 = 10;
(*msg).text = dc_stock_system_msg(
context,
@@ -1609,9 +1634,13 @@ pub unsafe fn dc_add_contact_to_chat_ex(
0 as *const libc::c_char,
1 as uint32_t,
);
dc_param_set_int((*msg).param, 'S' as i32, 4);
dc_param_set((*msg).param, 'E' as i32, (*contact).addr);
dc_param_set_int((*msg).param, 'F' as i32, flags);
dc_param_set_int((*msg).param, DC_PARAM_CMD as i32, 4);
dc_param_set(
(*msg).param,
DC_PARAM_CMD_ARG as i32,
(*contact).addr,
);
dc_param_set_int((*msg).param, DC_PARAM_CMD_ARG2 as i32, flags);
(*msg).id = dc_send_msg(context, chat_id, msg);
context.call_cb(
Event::MSGS_CHANGED,
@@ -1712,7 +1741,7 @@ pub unsafe fn dc_remove_contact_from_chat(
} else {
/* we shoud respect this - whatever we send to the group, it gets discarded anyway! */
if !contact.is_null() {
if dc_param_get_int((*chat).param, 'U' as i32, 0) == 0 {
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0) == 0 {
(*msg).type_0 = 10;
if (*contact).id == 1 as libc::c_uint {
dc_set_group_explicitly_left(context, (*chat).grpid);
@@ -1732,8 +1761,8 @@ pub unsafe fn dc_remove_contact_from_chat(
1 as uint32_t,
)
}
dc_param_set_int((*msg).param, 'S' as i32, 5);
dc_param_set((*msg).param, 'E' as i32, (*contact).addr);
dc_param_set_int((*msg).param, DC_PARAM_CMD as i32, 5);
dc_param_set((*msg).param, DC_PARAM_CMD_ARG as i32, (*contact).addr);
(*msg).id = dc_send_msg(context, chat_id, msg);
context.call_cb(
Event::MSGS_CHANGED,
@@ -1825,7 +1854,7 @@ pub unsafe fn dc_set_chat_name(
)
.is_ok()
{
if dc_param_get_int((*chat).param, 'U' as i32, 0i32) == 0i32 {
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0i32) == 0i32 {
(*msg).type_0 = 10i32;
(*msg).text = dc_stock_system_msg(
context,
@@ -1834,8 +1863,8 @@ pub unsafe fn dc_set_chat_name(
new_name,
1i32 as uint32_t,
);
dc_param_set_int((*msg).param, 'S' as i32, 2i32);
dc_param_set((*msg).param, 'E' as i32, (*chat).name);
dc_param_set_int((*msg).param, DC_PARAM_CMD as i32, 2i32);
dc_param_set((*msg).param, DC_PARAM_CMD_ARG as i32, (*chat).name);
(*msg).id = dc_send_msg(context, chat_id, msg);
context.call_cb(
Event::MSGS_CHANGED,
@@ -1895,11 +1924,13 @@ pub unsafe fn dc_set_chat_profile_image(
match current_block {
14766584022300871387 => {}
_ => {
dc_param_set((*chat).param, 'i' as i32, new_image_rel);
dc_param_set((*chat).param, DC_PARAM_PROFILE_IMAGE as i32, new_image_rel);
if !(0 == dc_chat_update_param(chat)) {
if dc_param_get_int((*chat).param, 'U' as i32, 0i32) == 0i32 {
dc_param_set_int((*msg).param, 'S' as i32, 3i32);
dc_param_set((*msg).param, 'E' as i32, new_image_rel);
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0i32)
== 0i32
{
dc_param_set_int((*msg).param, DC_PARAM_CMD as i32, 3i32);
dc_param_set((*msg).param, DC_PARAM_CMD_ARG as i32, new_image_rel);
(*msg).type_0 = 10i32;
(*msg).text = dc_stock_system_msg(
context,
@@ -1979,11 +2010,19 @@ pub unsafe fn dc_forward_msgs(
}
dc_param_set_packed(original_param, (*(*msg).param).packed);
if (*msg).from_id != 1i32 as libc::c_uint {
dc_param_set_int((*msg).param, 'a' as i32, 1i32);
dc_param_set_int((*msg).param, DC_PARAM_FORWARDED as i32, 1i32);
}
dc_param_set((*msg).param, 'c' as i32, 0 as *const libc::c_char);
dc_param_set((*msg).param, 'u' as i32, 0 as *const libc::c_char);
dc_param_set((*msg).param, 'S' as i32, 0 as *const libc::c_char);
dc_param_set(
(*msg).param,
DC_PARAM_GUARANTEE_E2EE as i32,
0 as *const libc::c_char,
);
dc_param_set(
(*msg).param,
DC_PARAM_FORCE_PLAINTEXT as i32,
0 as *const libc::c_char,
);
dc_param_set((*msg).param, DC_PARAM_CMD as i32, 0 as *const libc::c_char);
let new_msg_id: uint32_t;
if (*msg).state == 18i32 {
let fresh9 = curr_timestamp;
@@ -1994,7 +2033,7 @@ pub unsafe fn dc_forward_msgs(
(*msg).id = src_msg_id as uint32_t;
let old_fwd: *mut libc::c_char = dc_param_get(
(*msg).param,
'P' as i32,
DC_PARAM_PREP_FORWARDS as i32,
b"\x00" as *const u8 as *const libc::c_char,
);
let new_fwd: *mut libc::c_char = dc_mprintf(
@@ -2002,7 +2041,7 @@ pub unsafe fn dc_forward_msgs(
old_fwd,
new_msg_id,
);
dc_param_set((*msg).param, 'P' as i32, new_fwd);
dc_param_set((*msg).param, DC_PARAM_PREP_FORWARDS as i32, new_fwd);
dc_msg_save_param_to_disk(msg);
free(new_fwd as *mut libc::c_void);
free(old_fwd as *mut libc::c_void);
@@ -2079,7 +2118,7 @@ pub unsafe fn dc_chat_get_subtitle(chat: *const Chat) -> *mut libc::c_char {
}
let mut ret: *mut libc::c_char = std::ptr::null_mut();
if (*chat).type_0 == 100 && 0 != dc_param_exists((*chat).param, 'K' as i32) {
if (*chat).type_0 == 100 && 0 != dc_param_exists((*chat).param, DC_PARAM_SELFTALK as i32) {
ret = dc_stock_str((*chat).context, 50)
} else if (*chat).type_0 == 100 {
let ret_raw: String = (*chat)
@@ -2128,7 +2167,11 @@ pub unsafe fn dc_chat_get_profile_image(chat: *const Chat) -> *mut libc::c_char
let mut contacts: *mut dc_array_t = 0 as *mut dc_array_t;
let mut contact: *mut dc_contact_t = 0 as *mut dc_contact_t;
if !(chat.is_null() || (*chat).magic != 0xc4a7c4a7u32) {
image_rel = dc_param_get((*chat).param, 'i' as i32, 0 as *const libc::c_char);
image_rel = dc_param_get(
(*chat).param,
DC_PARAM_PROFILE_IMAGE as i32,
0 as *const libc::c_char,
);
if !image_rel.is_null() && 0 != *image_rel.offset(0isize) as libc::c_int {
image_abs = dc_get_abs_path((*chat).context, image_rel)
} else if (*chat).type_0 == 100i32 {
@@ -2188,7 +2231,7 @@ pub unsafe fn dc_chat_is_unpromoted(chat: *const Chat) -> libc::c_int {
if chat.is_null() || (*chat).magic != 0xc4a7c4a7u32 {
return 0i32;
}
dc_param_get_int((*chat).param, 'U' as i32, 0i32)
dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0i32)
}
// TODO should return bool /rtn