diff --git a/src/config.rs b/src/config.rs
index 3c55c1fb4..ff7aa0905 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -4,9 +4,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_stock::*;
use crate::dc_tools::*;
use crate::error::Error;
+use crate::stock::StockMessage;
use crate::x::*;
/// The available configuration keys.
@@ -94,12 +94,7 @@ impl Context {
// Default values
match key {
- Config::Selfstatus => {
- let s = unsafe { dc_stock_str(self, 13) };
- let res = to_string(s);
- unsafe { free(s as *mut _) };
- Some(res)
- }
+ Config::Selfstatus => Some(self.stock_str(StockMessage::StatusLine).into_owned()),
_ => key.get_str("default").map(|s| s.to_string()),
}
}
@@ -129,15 +124,14 @@ impl Context {
ret
}
Config::Selfstatus => {
- let def = unsafe { dc_stock_str(self, 13) };
- let val = if value.is_none() || value.unwrap() == as_str(def) {
+ let def = self.stock_str(StockMessage::StatusLine);
+ let val = if value.is_none() || value.unwrap() == def {
None
} else {
value
};
let ret = self.sql.set_config(self, key, val);
- unsafe { free(def as *mut libc::c_void) };
ret
}
_ => self.sql.set_config(self, key, value),
diff --git a/src/dc_chat.rs b/src/dc_chat.rs
index 0b4307484..8f7ac8ddf 100644
--- a/src/dc_chat.rs
+++ b/src/dc_chat.rs
@@ -1,3 +1,5 @@
+use std::ffi::CString;
+
use crate::constants::*;
use crate::context::Context;
use crate::dc_array::*;
@@ -6,9 +8,9 @@ use crate::dc_contact::*;
use crate::dc_job::*;
use crate::dc_msg::*;
use crate::dc_param::*;
-use crate::dc_stock::*;
use crate::dc_tools::*;
use crate::sql::{self, Sql};
+use crate::stock::StockMessage;
use crate::types::*;
use crate::x::*;
@@ -167,27 +169,24 @@ pub fn dc_chat_load_from_db(chat: *mut Chat, chat_id: u32) -> bool {
match c.id {
1 => unsafe {
free((*chat).name as *mut libc::c_void);
- (*chat).name = dc_stock_str((*chat).context, 8);
+ (*chat).name = to_cstring((*chat).context.stock_str(StockMessage::DeadDrop));
},
6 => unsafe {
free((*chat).name as *mut libc::c_void);
- let tempname: *mut libc::c_char = dc_stock_str((*chat).context, 40);
- (*chat).name = dc_mprintf(
- b"%s (%i)\x00" as *const u8 as *const libc::c_char,
- tempname,
- dc_get_archived_cnt((*chat).context),
- );
- free(tempname as *mut libc::c_void);
+ let tempname = (*chat).context.stock_str(StockMessage::ArchivedChats);
+ let cnt = dc_get_archived_cnt((*chat).context);
+ (*chat).name = to_cstring(format!("{} ({})", tempname, cnt));
},
5 => unsafe {
free((*chat).name as *mut libc::c_void);
- (*chat).name = dc_stock_str((*chat).context, 41);
+ (*chat).name = to_cstring((*chat).context.stock_str(StockMessage::StarredMsgs));
},
_ => {
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);
+ (*chat).name =
+ to_cstring((*chat).context.stock_str(StockMessage::SelfMsg));
}
}
}
@@ -1498,10 +1497,10 @@ pub unsafe fn dc_create_group_chat(
if chat_name.is_null() || *chat_name.offset(0) as libc::c_int == 0 {
return 0;
}
-
- let draft_txt = dc_stock_str_repl_string(context, 14, chat_name);
+ let draft_txt =
+ CString::new(context.stock_string_repl_str(StockMessage::NewGroupDraft, as_str(chat_name)))
+ .unwrap();
let grpid = as_str(dc_create_id());
-
if sql::execute(
context,
&context.sql,
@@ -1518,15 +1517,12 @@ pub unsafe fn dc_create_group_chat(
if chat_id != 0 {
if 0 != dc_add_to_chat_contacts_table(context, chat_id, 1) {
let draft_msg = dc_msg_new(context, 10);
- dc_msg_set_text(draft_msg, draft_txt);
+ dc_msg_set_text(draft_msg, draft_txt.as_ptr());
set_draft_raw(context, chat_id, draft_msg);
dc_msg_unref(draft_msg);
}
}
}
-
- free(draft_txt as *mut libc::c_void);
-
if 0 != chat_id {
context.call_cb(Event::MSGS_CHANGED, 0 as uintptr_t, 0 as uintptr_t);
}
@@ -1633,13 +1629,12 @@ pub unsafe fn dc_add_contact_to_chat_ex(
if OK_TO_CONTINUE {
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0) == 0 {
(*msg).type_0 = DC_MSG_TEXT;
- (*msg).text = dc_stock_system_msg(
- context,
- 17,
- (*contact).addr,
- 0 as *const libc::c_char,
- 1 as uint32_t,
- );
+ (*msg).text = to_cstring(context.stock_system_msg(
+ StockMessage::MsgAddMember,
+ as_str((*contact).addr),
+ "",
+ DC_CONTACT_ID_SELF as uint32_t,
+ ));
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);
@@ -1745,21 +1740,19 @@ pub unsafe fn dc_remove_contact_from_chat(
(*msg).type_0 = DC_MSG_TEXT;
if (*contact).id == 1 as libc::c_uint {
dc_set_group_explicitly_left(context, (*chat).grpid);
- (*msg).text = dc_stock_system_msg(
- context,
- 19,
- 0 as *const libc::c_char,
- 0 as *const libc::c_char,
- 1 as uint32_t,
- )
+ (*msg).text = to_cstring(context.stock_system_msg(
+ StockMessage::MsgGroupLeft,
+ "",
+ "",
+ DC_CONTACT_ID_SELF as u32,
+ ));
} else {
- (*msg).text = dc_stock_system_msg(
- context,
- 18,
- (*contact).addr,
- 0 as *const libc::c_char,
- 1 as uint32_t,
- )
+ (*msg).text = to_cstring(context.stock_system_msg(
+ StockMessage::MsgDelMember,
+ as_str((*contact).addr),
+ "",
+ DC_CONTACT_ID_SELF as u32,
+ ));
}
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);
@@ -1858,14 +1851,13 @@ pub unsafe fn dc_set_chat_name(
{
if dc_param_get_int((*chat).param, DC_PARAM_UNPROMOTED as i32, 0i32) == 0i32 {
(*msg).type_0 = DC_MSG_TEXT;
- (*msg).text = dc_stock_system_msg(
- context,
- 15i32,
- (*chat).name,
- new_name,
- 1i32 as uint32_t,
- );
- dc_param_set_int((*msg).param, DC_PARAM_CMD as i32, 2i32);
+ (*msg).text = to_cstring(context.stock_system_msg(
+ StockMessage::MsgGrpName,
+ as_str((*chat).name),
+ as_str(new_name),
+ DC_CONTACT_ID_SELF as u32,
+ ));
+ dc_param_set_int((*msg).param, DC_PARAM_CMD as i32, 2);
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(
@@ -1927,17 +1919,16 @@ pub unsafe fn dc_set_chat_profile_image(
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 = DC_MSG_TEXT;
- (*msg).text = dc_stock_system_msg(
- context,
+ (*msg).text = to_cstring(context.stock_system_msg(
if !new_image_rel.is_null() {
- 16i32
+ StockMessage::MsgGrpImgChanged
} else {
- 33i32
+ StockMessage::MsgGrpImgDeleted
},
- 0 as *const libc::c_char,
- 0 as *const libc::c_char,
- 1i32 as uint32_t,
- );
+ "",
+ "",
+ DC_CONTACT_ID_SELF as uint32_t,
+ ));
(*msg).id = dc_send_msg(context, chat_id, msg);
context.call_cb(
Event::MSGS_CHANGED,
@@ -2116,7 +2107,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, DC_PARAM_SELFTALK as i32) {
- ret = dc_stock_str((*chat).context, 50)
+ ret = to_cstring((*chat).context.stock_str(StockMessage::SelfTalkSubTitle));
} else if (*chat).type_0 == 100 {
let ret_raw: String = (*chat)
.context
@@ -2133,10 +2124,14 @@ pub unsafe fn dc_chat_get_subtitle(chat: *const Chat) -> *mut libc::c_char {
ret = to_cstring(ret_raw);
} else if (*chat).type_0 == 120 || (*chat).type_0 == 130 {
if (*chat).id == 1 {
- ret = dc_stock_str((*chat).context, 8)
+ ret = to_cstring((*chat).context.stock_str(StockMessage::DeadDrop));
} else {
let cnt = dc_get_chat_contact_cnt((*chat).context, (*chat).id);
- ret = dc_stock_str_repl_int((*chat).context, 4, cnt)
+ ret = to_cstring(
+ (*chat)
+ .context
+ .stock_string_repl_int(StockMessage::Member, cnt),
+ );
}
}
return if !ret.is_null() {
diff --git a/src/dc_chatlist.rs b/src/dc_chatlist.rs
index 555416e3d..15df6aad3 100644
--- a/src/dc_chatlist.rs
+++ b/src/dc_chatlist.rs
@@ -4,8 +4,8 @@ use crate::dc_chat::*;
use crate::dc_contact::*;
use crate::dc_lot::*;
use crate::dc_msg::*;
-use crate::dc_stock::*;
use crate::dc_tools::*;
+use crate::stock::StockMessage;
use crate::types::*;
use crate::x::*;
@@ -375,7 +375,8 @@ pub unsafe fn dc_chatlist_get_summary<'a>(
if (*chat).id == 6i32 as libc::c_uint {
(*ret).text2 = dc_strdup(0 as *const libc::c_char)
} else if lastmsg.is_null() || (*lastmsg).from_id == 0i32 as libc::c_uint {
- (*ret).text2 = dc_stock_str((*chatlist).context, 1i32)
+ (*ret).text2 =
+ to_cstring((*chatlist).context.stock_str(StockMessage::NoMessages));
} else {
dc_lot_fill(ret, lastmsg, chat, lastcontact, (*chatlist).context);
}
diff --git a/src/dc_contact.rs b/src/dc_contact.rs
index 9fc72ba80..4a3a62afd 100644
--- a/src/dc_contact.rs
+++ b/src/dc_contact.rs
@@ -1,3 +1,5 @@
+use std::ffi::CString;
+
use crate::aheader::EncryptPreference;
use crate::config;
use crate::constants::*;
@@ -5,11 +7,11 @@ use crate::context::Context;
use crate::dc_array::*;
use crate::dc_e2ee::*;
use crate::dc_loginparam::*;
-use crate::dc_stock::*;
use crate::dc_tools::*;
use crate::key::*;
use crate::peerstate::*;
use crate::sql::{self, Sql};
+use crate::stock::StockMessage;
use crate::types::*;
use crate::x::*;
@@ -276,7 +278,7 @@ pub unsafe fn dc_contact_load_from_db(
if contact_id == 1 as libc::c_uint {
(*contact).id = contact_id;
- (*contact).name = dc_stock_str((*contact).context, 2);
+ (*contact).name = to_cstring((*contact).context.stock_str(StockMessage::SelfMsg));
(*contact).addr = to_cstring(
(*contact)
.context
@@ -575,16 +577,15 @@ pub fn dc_get_contacts(
.get_config(context, "displayname")
.unwrap_or_default();
- let self_name2 = unsafe { dc_stock_str(context, 2) };
+ let self_name2 = CString::new(context.stock_str(StockMessage::SelfMsg).as_ref()).unwrap();
if query.is_null()
|| self_addr.contains(as_str(query))
|| self_name.contains(as_str(query))
- || 0 != unsafe { dc_str_contains(self_name2, query) }
+ || 0 != unsafe { dc_str_contains(self_name2.as_ptr(), query) }
{
add_self = true;
}
- unsafe { free(self_name2 as *mut _) };
} else {
add_self = true;
@@ -650,7 +651,6 @@ pub unsafe fn dc_get_contact_encrinfo(
let mut fingerprint_self = 0 as *mut libc::c_char;
let mut fingerprint_other_verified = 0 as *mut libc::c_char;
let mut fingerprint_other_unverified = 0 as *mut libc::c_char;
- let mut p: *mut libc::c_char;
if !(!dc_contact_load_from_db(contact, &context.sql, contact_id)) {
let peerstate = Peerstate::from_addr(context, &context.sql, as_str((*contact).addr));
@@ -660,23 +660,18 @@ pub unsafe fn dc_get_contact_encrinfo(
if peerstate.is_some() && peerstate.as_ref().and_then(|p| p.peek_key(0)).is_some() {
let peerstate = peerstate.as_ref().unwrap();
- p = dc_stock_str(
- context,
- if peerstate.prefer_encrypt == EncryptPreference::Mutual {
- 34i32
- } else {
- 25i32
- },
- );
- ret += as_str(p);
- free(p as *mut libc::c_void);
+ let p = context.stock_str(if peerstate.prefer_encrypt == EncryptPreference::Mutual {
+ StockMessage::E2ePreferred
+ } else {
+ StockMessage::E2eAvailable
+ });
+ ret += &p;
if self_key.is_none() {
dc_ensure_secret_key_exists(context);
self_key = Key::from_self_public(context, &loginparam.addr, &context.sql);
}
- p = dc_stock_str(context, 30i32);
- ret += &format!(" {}:", as_str(p));
- free(p as *mut libc::c_void);
+ let p = context.stock_str(StockMessage::FingerPrints);
+ ret += &format!(" {}:", p);
fingerprint_self = self_key
.map(|k| k.formatted_fingerprint_c())
@@ -717,13 +712,9 @@ pub unsafe fn dc_get_contact_encrinfo(
);
}
} else if 0 == loginparam.server_flags & 0x400 && 0 == loginparam.server_flags & 0x40000 {
- p = dc_stock_str(context, 27);
- ret += as_str(p);
- free(p as *mut libc::c_void);
+ ret += &context.stock_str(StockMessage::EncrTransp);
} else {
- p = dc_stock_str(context, 28);
- ret += as_str(p);
- free(p as *mut libc::c_void);
+ ret += &context.stock_str(StockMessage::EncrNone);
}
}
diff --git a/src/dc_imex.rs b/src/dc_imex.rs
index 408806f40..b2bf84452 100644
--- a/src/dc_imex.rs
+++ b/src/dc_imex.rs
@@ -14,11 +14,11 @@ use crate::dc_e2ee::*;
use crate::dc_job::*;
use crate::dc_msg::*;
use crate::dc_param::*;
-use crate::dc_stock::*;
use crate::dc_tools::*;
use crate::key::*;
use crate::pgp::*;
use crate::sql::{self, Sql};
+use crate::stock::StockMessage;
use crate::types::*;
use crate::x::*;
@@ -260,25 +260,19 @@ pub unsafe extern "C" fn dc_render_setup_file(
replacement,
);
free(replacement as *mut libc::c_void);
- let setup_message_title: *mut libc::c_char = dc_stock_str(context, 42i32);
- let mut setup_message_body: *mut libc::c_char = dc_stock_str(context, 43i32);
- dc_str_replace(
- &mut setup_message_body,
- b"\r\x00" as *const u8 as *const libc::c_char,
- 0 as *const libc::c_char,
- );
- dc_str_replace(
- &mut setup_message_body,
- b"\n\x00" as *const u8 as *const libc::c_char,
- b"
\x00" as *const u8 as *const libc::c_char,
- );
+ let setup_message_title =
+ CString::new(context.stock_str(StockMessage::AcSetupMsgSubject).as_ref())
+ .unwrap();
+ let setup_message_body = context.stock_str(StockMessage::AcSetupMsgBody);
+ let msg_body_head: &str = setup_message_body.split('\r').next().unwrap();
+ let msg_body_html = CString::new(msg_body_head.replace("\n", "
")).unwrap();
ret_setupfilecontent =
dc_mprintf(b"\r\n\r\n
%s
\r\n\r\n%s\r\n\r\n\r\n\r\n\x00" - as *const u8 as *const libc::c_char, - setup_message_title, setup_message_title, - setup_message_body, encr_string); - free(setup_message_title as *mut libc::c_void); - free(setup_message_body as *mut libc::c_void); + as *const u8 as *const libc::c_char, + setup_message_title.as_ptr(), + setup_message_title.as_ptr(), + msg_body_html.as_ptr(), + encr_string); free(encr_string as *mut libc::c_void); } } diff --git a/src/dc_location.rs b/src/dc_location.rs index 542180d1f..2a89d84ab 100644 --- a/src/dc_location.rs +++ b/src/dc_location.rs @@ -1,3 +1,5 @@ +use std::ffi::CString; + use crate::constants::Event; use crate::context::*; use crate::dc_array::*; @@ -6,9 +8,9 @@ use crate::dc_job::*; use crate::dc_msg::*; use crate::dc_param::*; use crate::dc_saxparser::*; -use crate::dc_stock::*; use crate::dc_tools::*; use crate::sql; +use crate::stock::StockMessage; use crate::types::*; use crate::x::*; @@ -71,7 +73,6 @@ pub unsafe fn dc_send_locations_to_chat( ) { let now = time(); let mut msg: *mut dc_msg_t = 0 as *mut dc_msg_t; - let mut stock_str: *mut libc::c_char = 0 as *mut libc::c_char; let is_sending_locations_before: bool; if !(seconds < 0i32 || chat_id <= 9i32 as libc::c_uint) { is_sending_locations_before = dc_is_sending_locations_to_chat(context, chat_id); @@ -96,24 +97,23 @@ pub unsafe fn dc_send_locations_to_chat( { if 0 != seconds && !is_sending_locations_before { msg = dc_msg_new(context, 10i32); - (*msg).text = dc_stock_system_msg( - context, - 64, - 0 as *const libc::c_char, - 0 as *const libc::c_char, + (*msg).text = to_cstring(context.stock_system_msg( + StockMessage::MsgLocationEnabled, + "", + "", 0, - ); + )); dc_param_set_int((*msg).param, DC_PARAM_CMD as i32, 8); dc_send_msg(context, chat_id, msg); } else if 0 == seconds && is_sending_locations_before { - stock_str = dc_stock_system_msg( - context, - 65i32, - 0 as *const libc::c_char, - 0 as *const libc::c_char, - 0i32 as uint32_t, - ); - dc_add_device_msg(context, chat_id, stock_str); + let stock_str = CString::new(context.stock_system_msg( + StockMessage::MsgLocationDisabled, + "", + "", + 0, + )) + .unwrap(); + dc_add_device_msg(context, chat_id, stock_str.as_ptr()); } context.call_cb( Event::CHAT_MODIFIED, @@ -132,7 +132,6 @@ pub unsafe fn dc_send_locations_to_chat( } } } - free(stock_str as *mut libc::c_void); dc_msg_unref(msg); } @@ -736,7 +735,6 @@ pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOC_ENDED(context: &Context, job: &mut // if so, a device-message is added if not yet done. let chat_id = (*job).foreign_id; - let mut stock_str = 0 as *mut libc::c_char; if let Ok((send_begin, send_until)) = context.sql.query_row( "SELECT locations_send_begin, locations_send_until FROM chats WHERE id=?", @@ -753,14 +751,8 @@ pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOC_ENDED(context: &Context, job: &mut "UPDATE chats SET locations_send_begin=0, locations_send_until=0 WHERE id=?", params![chat_id as i32], ).is_ok() { - stock_str = dc_stock_system_msg( - context, - 65, - 0 as *const libc::c_char, - 0 as *const libc::c_char, - 0, - ); - dc_add_device_msg(context, chat_id, stock_str); + let stock_str = CString::new(context.stock_system_msg(StockMessage::MsgLocationDisabled, "", "", 0)).unwrap(); + dc_add_device_msg(context, chat_id, stock_str.as_ptr()); context.call_cb( Event::CHAT_MODIFIED, chat_id as usize, @@ -770,5 +762,4 @@ pub unsafe fn dc_job_do_DC_JOB_MAYBE_SEND_LOC_ENDED(context: &Context, job: &mut } } } - free(stock_str as *mut libc::c_void); } diff --git a/src/dc_lot.rs b/src/dc_lot.rs index cb1287e6f..69c517a1d 100644 --- a/src/dc_lot.rs +++ b/src/dc_lot.rs @@ -2,8 +2,8 @@ use crate::context::Context; use crate::dc_chat::*; use crate::dc_contact::*; use crate::dc_msg::*; -use crate::dc_stock::*; use crate::dc_tools::*; +use crate::stock::StockMessage; use crate::types::*; use crate::x::*; @@ -134,14 +134,14 @@ pub unsafe fn dc_lot_fill( return; } if (*msg).state == 19i32 { - (*lot).text1 = dc_stock_str(context, 3i32); + (*lot).text1 = to_cstring(context.stock_str(StockMessage::Draft)); (*lot).text1_meaning = 1i32 } else if (*msg).from_id == 1i32 as libc::c_uint { if 0 != dc_msg_is_info(msg) || 0 != dc_chat_is_self_talk(chat) { (*lot).text1 = 0 as *mut libc::c_char; (*lot).text1_meaning = 0i32 } else { - (*lot).text1 = dc_stock_str(context, 2i32); + (*lot).text1 = to_cstring(context.stock_str(StockMessage::SelfMsg)); (*lot).text1_meaning = 3i32 } } else if chat.is_null() { diff --git a/src/dc_mimefactory.rs b/src/dc_mimefactory.rs index 3c3ab5a1a..7fc45bb1f 100644 --- a/src/dc_mimefactory.rs +++ b/src/dc_mimefactory.rs @@ -1,3 +1,5 @@ +use std::ffi::CString; + use chrono::TimeZone; use mmime::mailimf_types::*; use mmime::mailimf_types_helper::*; @@ -16,9 +18,9 @@ use crate::dc_e2ee::*; use crate::dc_location::*; use crate::dc_msg::*; use crate::dc_param::*; -use crate::dc_stock::*; use crate::dc_strencode::*; use crate::dc_tools::*; +use crate::stock::StockMessage; use crate::types::*; use crate::x::*; @@ -282,7 +284,7 @@ unsafe fn load_from(mut factory: *mut dc_mimefactory_t) { .unwrap_or_default(), ); if (*factory).selfstatus.is_null() { - (*factory).selfstatus = dc_stock_str((*factory).context, 13) + (*factory).selfstatus = to_cstring((*factory).context.stock_str(StockMessage::StatusLine)); }; } @@ -677,7 +679,8 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc: strdup(b"v1\x00" as *const u8 as *const libc::c_char), ), ); - placeholdertext = dc_stock_str((*factory).context, 43) + placeholdertext = + to_cstring((*factory).context.stock_str(StockMessage::AcSetupMsgBody)); } if command == 7 { let step: *mut libc::c_char = dc_param_get( @@ -992,14 +995,18 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc: let p1: *mut libc::c_char; let p2: *mut libc::c_char; if 0 != dc_param_get_int((*(*factory).msg).param, DC_PARAM_GUARANTEE_E2EE as i32, 0) { - p1 = dc_stock_str((*factory).context, 24) + p1 = to_cstring((*factory).context.stock_str(StockMessage::EncryptedMsg)); } else { p1 = dc_msg_get_summarytext((*factory).msg, 32) } - p2 = dc_stock_str_repl_string((*factory).context, 32, p1); + p2 = to_cstring( + (*factory) + .context + .stock_string_repl_str(StockMessage::ReadRcptMailBody, as_str(p1)), + ); message_text = dc_mprintf(b"%s\r\n\x00" as *const u8 as *const libc::c_char, p2); - free(p2 as *mut libc::c_void); free(p1 as *mut libc::c_void); + free(p2 as *mut libc::c_void); let human_mime_part: *mut mailmime = build_body_text(message_text); mailmime_add_part(multipart, human_mime_part); message_text2 = @@ -1031,10 +1038,17 @@ pub unsafe fn dc_mimefactory_render(mut factory: *mut dc_mimefactory_t) -> libc: if (*factory).loaded as libc::c_uint == DC_MF_MDN_LOADED as libc::c_int as libc::c_uint { - let e: *mut libc::c_char = dc_stock_str((*factory).context, 31); - subject_str = - dc_mprintf(b"Chat: %s\x00" as *const u8 as *const libc::c_char, e); - free(e as *mut libc::c_void); + let e = CString::new( + (*factory) + .context + .stock_str(StockMessage::ReadRcpt) + .as_ref(), + ) + .unwrap(); + subject_str = dc_mprintf( + b"Chat: %s\x00" as *const u8 as *const libc::c_char, + e.as_ptr(), + ); } else { subject_str = get_subject((*factory).chat, (*factory).msg, afwd_email) } @@ -1118,7 +1132,7 @@ unsafe fn get_subject( b"\x00" as *const u8 as *const libc::c_char }; if dc_param_get_int((*msg).param, DC_PARAM_CMD as i32, 0) == 6 { - ret = dc_stock_str(context, 42) + ret = to_cstring(context.stock_str(StockMessage::AcSetupMsgSubject)) } else if (*chat).type_0 == DC_CHAT_TYPE_GROUP as libc::c_int || (*chat).type_0 == DC_CHAT_TYPE_VERIFIED_GROUP as libc::c_int { diff --git a/src/dc_mimeparser.rs b/src/dc_mimeparser.rs index b7a1ea1cb..6a7cd3040 100644 --- a/src/dc_mimeparser.rs +++ b/src/dc_mimeparser.rs @@ -1,5 +1,5 @@ use std::collections::{HashMap, HashSet}; -use std::ffi::CStr; +use std::ffi::{CStr, CString}; use charset::Charset; use mmime::mailimf::*; @@ -17,9 +17,9 @@ use crate::dc_e2ee::*; use crate::dc_location::*; use crate::dc_param::*; use crate::dc_simplify::*; -use crate::dc_stock::*; use crate::dc_strencode::*; use crate::dc_tools::*; +use crate::stock::StockMessage; use crate::types::*; use crate::x::*; @@ -667,11 +667,18 @@ unsafe fn dc_mimeparser_parse_mime_recursive( 40 => { let mut part: *mut dc_mimepart_t = dc_mimepart_new(); (*part).type_0 = 10i32; - let msg_body: *mut libc::c_char = dc_stock_str((*mimeparser).context, 29i32); - (*part).msg = - dc_mprintf(b"[%s]\x00" as *const u8 as *const libc::c_char, msg_body); + let msg_body = CString::new( + (*mimeparser) + .context + .stock_str(StockMessage::CantDecryptMsgBody) + .as_ref(), + ) + .unwrap(); + (*part).msg = dc_mprintf( + b"[%s]\x00" as *const u8 as *const libc::c_char, + msg_body.as_ptr(), + ); (*part).msg_raw = dc_strdup((*part).msg); - free(msg_body as *mut libc::c_void); carray_add( (*mimeparser).parts, part as *mut libc::c_void, diff --git a/src/dc_msg.rs b/src/dc_msg.rs index 79e01046f..2282ff7a4 100644 --- a/src/dc_msg.rs +++ b/src/dc_msg.rs @@ -1,3 +1,5 @@ +use std::ffi::CString; + use crate::constants::*; use crate::context::*; use crate::dc_chat::*; @@ -6,10 +8,10 @@ use crate::dc_job::*; use crate::dc_lot::dc_lot_t; use crate::dc_lot::*; use crate::dc_param::*; -use crate::dc_stock::*; use crate::dc_tools::*; use crate::pgp::*; use crate::sql; +use crate::stock::StockMessage; use crate::types::*; use crate::x::*; @@ -840,17 +842,16 @@ pub unsafe fn dc_msg_get_summarytext_by_raw( let mut ret; let mut prefix: *mut libc::c_char = 0 as *mut libc::c_char; let mut pathNfilename: *mut libc::c_char = 0 as *mut libc::c_char; - let mut label: *mut libc::c_char = 0 as *mut libc::c_char; let mut value: *mut libc::c_char = 0 as *mut libc::c_char; let mut append_text: libc::c_int = 1i32; match type_0 { - 20 => prefix = dc_stock_str(context, 9i32), - 21 => prefix = dc_stock_str(context, 23i32), - 50 => prefix = dc_stock_str(context, 10i32), - 41 => prefix = dc_stock_str(context, 7i32), + 20 => prefix = to_cstring(context.stock_str(StockMessage::Image)), + 21 => prefix = to_cstring(context.stock_str(StockMessage::Gif)), + 50 => prefix = to_cstring(context.stock_str(StockMessage::Video)), + 41 => prefix = to_cstring(context.stock_str(StockMessage::VoiceMessage)), 40 | 60 => { - if dc_param_get_int(param, DC_PARAM_CMD as i32, 0) == 6i32 { - prefix = dc_stock_str(context, 42i32); + if dc_param_get_int(param, DC_PARAM_CMD as i32, 0) == 6 { + prefix = to_cstring(context.stock_str(StockMessage::AcSetupMsgSubject)); append_text = 0i32 } else { pathNfilename = dc_param_get( @@ -859,24 +860,26 @@ pub unsafe fn dc_msg_get_summarytext_by_raw( b"ErrFilename\x00" as *const u8 as *const libc::c_char, ); value = dc_get_filename(pathNfilename); - label = dc_stock_str( - context, - if type_0 == DC_MSG_AUDIO as libc::c_int { - 11i32 - } else { - 12i32 - }, - ); + let label = CString::new( + context + .stock_str(if type_0 == DC_MSG_AUDIO { + StockMessage::Audio + } else { + StockMessage::File + }) + .as_ref(), + ) + .unwrap(); prefix = dc_mprintf( b"%s \xe2\x80\x93 %s\x00" as *const u8 as *const libc::c_char, - label, + label.as_ptr(), value, ) } } _ => { if dc_param_get_int(param, DC_PARAM_CMD as i32, 0) == 9i32 { - prefix = dc_stock_str(context, 66i32); + prefix = to_cstring(context.stock_str(StockMessage::Location)); append_text = 0i32 } } @@ -901,7 +904,6 @@ pub unsafe fn dc_msg_get_summarytext_by_raw( } free(prefix as *mut libc::c_void); free(pathNfilename as *mut libc::c_void); - free(label as *mut libc::c_void); free(value as *mut libc::c_void); if ret.is_null() { ret = dc_strdup(0 as *const libc::c_char) diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index d3775c957..3a346a8de 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -19,11 +19,11 @@ use crate::dc_move::*; use crate::dc_msg::*; use crate::dc_param::*; use crate::dc_securejoin::*; -use crate::dc_stock::*; use crate::dc_strencode::*; use crate::dc_tools::*; use crate::peerstate::*; use crate::sql; +use crate::stock::StockMessage; use crate::types::*; use crate::x::*; @@ -944,18 +944,13 @@ unsafe fn create_or_lookup_group( let mut X_MrAddToGrp: *mut libc::c_char = 0 as *mut libc::c_char; let mut X_MrGrpNameChanged: libc::c_int = 0; let mut X_MrGrpImageChanged: *const libc::c_char = 0 as *const libc::c_char; - let mut better_msg: *mut libc::c_char = 0 as *mut libc::c_char; + let mut better_msg: String = From::from(""); let mut failure_reason: *mut libc::c_char = 0 as *mut libc::c_char; - if mime_parser.is_system_message == 8 { - better_msg = dc_stock_system_msg( - context, - 64, - 0 as *const libc::c_char, - 0 as *const libc::c_char, - from_id as uint32_t, - ) + if mime_parser.is_system_message == 8i32 { + better_msg = + context.stock_system_msg(StockMessage::MsgLocationEnabled, "", "", from_id as u32) } - set_better_msg(mime_parser, &mut better_msg); + set_better_msg(mime_parser, &better_msg); /* search the grpid in the header */ let mut field: *mut mailimf_field; let mut optional_field: *mut mailimf_optional_field; @@ -1034,12 +1029,15 @@ unsafe fn create_or_lookup_group( let left_group: libc::c_int = (dc_lookup_contact_id_by_addr(context, X_MrRemoveFromGrp) == from_id as libc::c_uint) as libc::c_int; - better_msg = dc_stock_system_msg( - context, - if 0 != left_group { 19 } else { 18 }, - X_MrRemoveFromGrp, - 0 as *const libc::c_char, - from_id as uint32_t, + better_msg = context.stock_system_msg( + if 0 != left_group { + StockMessage::MsgGroupLeft + } else { + StockMessage::MsgDelMember + }, + as_str(X_MrRemoveFromGrp), + "", + from_id as u32, ) } else { optional_field = dc_mimeparser_lookup_optional_field( @@ -1056,12 +1054,11 @@ unsafe fn create_or_lookup_group( if !optional_field.is_null() { X_MrGrpImageChanged = (*optional_field).fld_value } - better_msg = dc_stock_system_msg( - context, - 17, - X_MrAddToGrp, - 0 as *const libc::c_char, - from_id as uint32_t, + better_msg = context.stock_system_msg( + StockMessage::MsgAddMember, + as_str(X_MrAddToGrp), + "", + from_id as u32, ) } else { optional_field = dc_mimeparser_lookup_optional_field( @@ -1069,14 +1066,13 @@ unsafe fn create_or_lookup_group( b"Chat-Group-Name-Changed\x00" as *const u8 as *const libc::c_char, ); if !optional_field.is_null() { - X_MrGrpNameChanged = 1; - mime_parser.is_system_message = 2; - better_msg = dc_stock_system_msg( - context, - 15, - (*optional_field).fld_value, - grpname, - from_id as uint32_t, + X_MrGrpNameChanged = 1i32; + mime_parser.is_system_message = 2i32; + better_msg = context.stock_system_msg( + StockMessage::MsgGrpName, + as_str((*optional_field).fld_value), + as_str(grpname), + from_id as u32, ) } else { optional_field = dc_mimeparser_lookup_optional_field( @@ -1086,26 +1082,25 @@ unsafe fn create_or_lookup_group( if !optional_field.is_null() { X_MrGrpImageChanged = (*optional_field).fld_value; mime_parser.is_system_message = 3; - better_msg = dc_stock_system_msg( - context, + better_msg = context.stock_system_msg( if strcmp( X_MrGrpImageChanged, b"0\x00" as *const u8 as *const libc::c_char, ) == 0 { - 33 + StockMessage::MsgGrpImgDeleted } else { - 16 + StockMessage::MsgGrpImgChanged }, - 0 as *const libc::c_char, - 0 as *const libc::c_char, - from_id as uint32_t, + "", + "", + from_id as u32, ) } } } } - set_better_msg(mime_parser, &mut better_msg); + set_better_msg(mime_parser, &better_msg); chat_id = dc_get_chat_id_by_grpid( context, grpid, @@ -1345,8 +1340,6 @@ unsafe fn create_or_lookup_group( } free(grpid as *mut libc::c_void); free(grpname as *mut libc::c_void); - - free(better_msg as *mut libc::c_void); free(failure_reason as *mut libc::c_void); if !ret_chat_id.is_null() { *ret_chat_id = chat_id @@ -1432,11 +1425,10 @@ unsafe fn create_or_lookup_adhoc_group( { grpname = dc_strdup(mime_parser.subject) } else { - grpname = dc_stock_str_repl_int( - context, - 4, + grpname = to_cstring(context.stock_string_repl_int( + StockMessage::Member, dc_array_get_cnt(member_ids) as libc::c_int, - ) + )); } chat_id = create_group_record(context, grpid, grpname, create_blocked, 0); @@ -1732,14 +1724,14 @@ unsafe fn check_verified_properties( 1 } -unsafe fn set_better_msg(mime_parser: &dc_mimeparser_t, better_msg: *mut *mut libc::c_char) { - if !(*better_msg).is_null() && carray_count((*mime_parser).parts) > 0 as libc::c_uint { +unsafe fn set_better_msg