chat magic to const

This commit is contained in:
Simon Laux
2019-08-11 04:59:13 +02:00
committed by holger krekel
parent 91fec77f4b
commit 91bf948d1e
2 changed files with 20 additions and 18 deletions

View File

@@ -87,6 +87,8 @@ pub const DC_CHAT_TYPE_SINGLE: i32 = 100;
pub const DC_CHAT_TYPE_GROUP: i32 = 120;
pub const DC_CHAT_TYPE_VERIFIED_GROUP: i32 = 130;
pub const DC_CHAT_MAGIC: u32 = 0xc4a7c4a7;
pub const DC_MSG_ID_MARKER1: usize = 1;
pub const DC_MSG_ID_DAYMARKER: usize = 9;
pub const DC_MSG_ID_LAST_SPECIAL: usize = 9;

View File

@@ -24,7 +24,7 @@ use crate::x::*;
*/
#[derive(Clone)]
pub struct Chat<'a> {
magic: uint32_t,
magic: u32,
pub id: uint32_t,
pub type_0: libc::c_int,
pub name: *mut libc::c_char,
@@ -65,7 +65,7 @@ pub unsafe fn dc_create_chat_by_msg_id(context: &Context, msg_id: uint32_t) -> u
pub unsafe fn dc_chat_new<'a>(context: &'a Context) -> *mut Chat<'a> {
let chat = Chat {
magic: 0xc4a7c4a7,
magic: DC_CHAT_MAGIC,
id: 0,
type_0: 0,
name: std::ptr::null_mut(),
@@ -82,7 +82,7 @@ pub unsafe fn dc_chat_new<'a>(context: &'a Context) -> *mut Chat<'a> {
}
pub unsafe fn dc_chat_unref(mut chat: *mut Chat) {
if chat.is_null() || (*chat).magic != 0xc4a7c4a7u32 {
if chat.is_null() || (*chat).magic != DC_CHAT_MAGIC {
return;
}
dc_chat_empty(chat);
@@ -91,7 +91,7 @@ pub unsafe fn dc_chat_unref(mut chat: *mut Chat) {
}
pub unsafe fn dc_chat_empty(mut chat: *mut Chat) {
if chat.is_null() || (*chat).magic != 0xc4a7c4a7u32 {
if chat.is_null() || (*chat).magic != DC_CHAT_MAGIC {
return;
}
free((*chat).name as *mut libc::c_void);
@@ -120,7 +120,7 @@ pub fn dc_block_chat(context: &Context, chat_id: u32, new_blocking: libc::c_int)
}
pub fn dc_chat_load_from_db(chat: *mut Chat, chat_id: u32) -> bool {
if chat.is_null() || unsafe { (*chat).magic != 0xc4a7c4a7u32 } {
if chat.is_null() || unsafe { (*chat).magic != DC_CHAT_MAGIC } {
return false;
}
unsafe { dc_chat_empty(chat) };
@@ -810,7 +810,7 @@ unsafe fn get_parent_mime_headers(
}
pub unsafe fn dc_chat_is_self_talk(chat: *const Chat) -> libc::c_int {
if chat.is_null() || (*chat).magic != 0xc4a7c4a7u32 {
if chat.is_null() || (*chat).magic != DC_CHAT_MAGIC {
return 0;
}
(*chat).param.exists(Param::Selftalk) as libc::c_int
@@ -2020,21 +2020,21 @@ pub unsafe fn dc_forward_msgs(
}
pub unsafe fn dc_chat_get_id(chat: *const Chat) -> uint32_t {
if chat.is_null() || (*chat).magic != 0xc4a7c4a7u32 {
if chat.is_null() || (*chat).magic != DC_CHAT_MAGIC {
return 0i32 as uint32_t;
}
(*chat).id
}
pub unsafe fn dc_chat_get_type(chat: *const Chat) -> libc::c_int {
if chat.is_null() || (*chat).magic != 0xc4a7c4a7u32 {
if chat.is_null() || (*chat).magic != DC_CHAT_MAGIC {
return 0i32;
}
(*chat).type_0
}
pub unsafe fn dc_chat_get_name(chat: *const Chat) -> *mut libc::c_char {
if chat.is_null() || (*chat).magic != 0xc4a7c4a7u32 {
if chat.is_null() || (*chat).magic != DC_CHAT_MAGIC {
return dc_strdup(b"Err\x00" as *const u8 as *const libc::c_char);
}
dc_strdup((*chat).name)
@@ -2042,7 +2042,7 @@ pub unsafe fn dc_chat_get_name(chat: *const Chat) -> *mut libc::c_char {
pub unsafe fn dc_chat_get_subtitle(chat: *const Chat) -> *mut libc::c_char {
/* returns either the address or the number of chat members */
if chat.is_null() || (*chat).magic != 0xc4a7c4a7u32 {
if chat.is_null() || (*chat).magic != DC_CHAT_MAGIC {
return dc_strdup(b"Err\x00" as *const u8 as *const libc::c_char);
}
@@ -2101,7 +2101,7 @@ pub unsafe fn dc_chat_get_profile_image(chat: *const Chat) -> *mut libc::c_char
let mut image_abs: *mut libc::c_char = 0 as *mut libc::c_char;
let mut contacts: *mut dc_array_t = 0 as *mut dc_array_t;
if !(chat.is_null() || (*chat).magic != 0xc4a7c4a7u32) {
if !(chat.is_null() || (*chat).magic != DC_CHAT_MAGIC) {
image_rel = (*chat)
.param
.get(Param::ProfileImage)
@@ -2109,7 +2109,7 @@ pub unsafe fn dc_chat_get_profile_image(chat: *const Chat) -> *mut libc::c_char
.strdup();
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 {
} else if (*chat).type_0 == DC_CHAT_TYPE_SINGLE {
contacts = dc_get_chat_contacts((*chat).context, (*chat).id);
if !(*contacts).is_empty() {
if let Ok(contact) = Contact::get_by_id((*chat).context, (*contacts).get_id(0)) {
@@ -2131,8 +2131,8 @@ pub unsafe fn dc_chat_get_color(chat: *const Chat) -> uint32_t {
let mut color: uint32_t = 0i32 as uint32_t;
let mut contacts: *mut dc_array_t = 0 as *mut dc_array_t;
if !(chat.is_null() || (*chat).magic != 0xc4a7c4a7u32) {
if (*chat).type_0 == 100i32 {
if !(chat.is_null() || (*chat).magic != DC_CHAT_MAGIC) {
if (*chat).type_0 == DC_CHAT_TYPE_SINGLE {
contacts = dc_get_chat_contacts((*chat).context, (*chat).id);
if !(*contacts).is_empty() {
if let Ok(contact) = Contact::get_by_id((*chat).context, (*contacts).get_id(0)) {
@@ -2151,7 +2151,7 @@ pub unsafe fn dc_chat_get_color(chat: *const Chat) -> uint32_t {
// TODO should return bool /rtn
pub unsafe fn dc_chat_get_archived(chat: *const Chat) -> libc::c_int {
if chat.is_null() || (*chat).magic != 0xc4a7c4a7u32 {
if chat.is_null() || (*chat).magic != DC_CHAT_MAGIC {
return 0i32;
}
(*chat).archived
@@ -2159,7 +2159,7 @@ pub unsafe fn dc_chat_get_archived(chat: *const Chat) -> libc::c_int {
// TODO should return bool /rtn
pub unsafe fn dc_chat_is_unpromoted(chat: *const Chat) -> libc::c_int {
if chat.is_null() || (*chat).magic != 0xc4a7c4a7u32 {
if chat.is_null() || (*chat).magic != DC_CHAT_MAGIC {
return 0;
}
(*chat).param.get_int(Param::Unpromoted).unwrap_or_default() as libc::c_int
@@ -2167,7 +2167,7 @@ pub unsafe fn dc_chat_is_unpromoted(chat: *const Chat) -> libc::c_int {
// TODO should return bool /rtn
pub unsafe fn dc_chat_is_verified(chat: *const Chat) -> libc::c_int {
if chat.is_null() || (*chat).magic != 0xc4a7c4a7u32 {
if chat.is_null() || (*chat).magic != DC_CHAT_MAGIC {
return 0i32;
}
((*chat).type_0 == 130i32) as libc::c_int
@@ -2175,7 +2175,7 @@ pub unsafe fn dc_chat_is_verified(chat: *const Chat) -> libc::c_int {
// TODO should return bool /rtn
pub unsafe fn dc_chat_is_sending_locations(chat: *const Chat) -> libc::c_int {
if chat.is_null() || (*chat).magic != 0xc4a7c4a7u32 {
if chat.is_null() || (*chat).magic != DC_CHAT_MAGIC {
return 0i32;
}
(*chat).is_sending_locations