refactor: unsafe, CStr and libc moved out

This commit is contained in:
dignifiedquire
2019-12-02 15:29:47 +01:00
parent 43074464ac
commit db88212a64
17 changed files with 398 additions and 459 deletions

View File

@@ -457,7 +457,7 @@ impl Message {
return ret;
};
let contact = if self.from_id != DC_CONTACT_ID_SELF as libc::c_uint
let contact = if self.from_id != DC_CONTACT_ID_SELF as u32
&& (chat.typ == Chattype::Group || chat.typ == Chattype::VerifiedGroup)
{
Contact::get_by_id(context, self.from_id).ok()
@@ -502,8 +502,8 @@ impl Message {
pub fn is_info(&self) -> bool {
let cmd = self.param.get_cmd();
self.from_id == DC_CONTACT_ID_INFO as libc::c_uint
|| self.to_id == DC_CONTACT_ID_INFO as libc::c_uint
self.from_id == DC_CONTACT_ID_INFO as u32
|| self.to_id == DC_CONTACT_ID_INFO as u32
|| cmd != SystemMessage::Unknown && cmd != SystemMessage::AutocryptSetupMessage
}
@@ -730,7 +730,7 @@ pub fn get_msg_info(context: &Context, msg_id: MsgId) -> String {
ret += &format!(" by {}", name);
ret += "\n";
if msg.from_id != DC_CONTACT_ID_SELF as libc::c_uint {
if msg.from_id != DC_CONTACT_ID_SELF as u32 {
let s = dc_timestamp_to_str(if 0 != msg.timestamp_rcvd {
msg.timestamp_rcvd
} else {
@@ -1227,7 +1227,7 @@ pub fn mdn_from_ext(
}
/// The number of messages assigned to real chat (!=deaddrop, !=trash)
pub fn get_real_msg_cnt(context: &Context) -> libc::c_int {
pub fn get_real_msg_cnt(context: &Context) -> i32 {
match context.sql.query_row(
"SELECT COUNT(*) \
FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id \
@@ -1243,7 +1243,7 @@ pub fn get_real_msg_cnt(context: &Context) -> libc::c_int {
}
}
pub fn get_deaddrop_msg_cnt(context: &Context) -> libc::size_t {
pub fn get_deaddrop_msg_cnt(context: &Context) -> usize {
match context.sql.query_row(
"SELECT COUNT(*) \
FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id \
@@ -1251,7 +1251,7 @@ pub fn get_deaddrop_msg_cnt(context: &Context) -> libc::size_t {
rusqlite::NO_PARAMS,
|row| row.get::<_, isize>(0),
) {
Ok(res) => res as libc::size_t,
Ok(res) => res as usize,
Err(err) => {
error!(context, "dc_get_deaddrop_msg_cnt() failed. {}", err);
0
@@ -1259,7 +1259,7 @@ pub fn get_deaddrop_msg_cnt(context: &Context) -> libc::size_t {
}
}
pub fn rfc724_mid_cnt(context: &Context, rfc724_mid: &str) -> libc::c_int {
pub fn rfc724_mid_cnt(context: &Context, rfc724_mid: &str) -> i32 {
// check the number of messages with the same rfc724_mid
match context.sql.query_row(
"SELECT COUNT(*) FROM msgs WHERE rfc724_mid=?;",