continue rustification

This commit is contained in:
dignifiedquire
2019-05-01 14:50:09 +02:00
parent 72e9fe6150
commit 75319dbf67
23 changed files with 2091 additions and 2120 deletions

View File

@@ -15,27 +15,27 @@ use crate::x::*;
/* * the structure behind dc_chatlist_t */
#[derive(Copy, Clone)]
#[repr(C)]
pub struct dc_chatlist_t {
pub struct dc_chatlist_t<'a> {
pub magic: uint32_t,
pub context: &dc_context_t,
pub context: &'a dc_context_t,
pub cnt: size_t,
pub chatNlastmsg_ids: *mut dc_array_t,
}
// handle chatlists
pub unsafe fn dc_get_chatlist(
mut context: &dc_context_t,
pub unsafe fn dc_get_chatlist<'a>(
mut context: &'a dc_context_t,
mut listflags: libc::c_int,
mut query_str: *const libc::c_char,
mut query_id: uint32_t,
) -> *mut dc_chatlist_t {
) -> *mut dc_chatlist_t<'a> {
let mut success: libc::c_int = 0i32;
let mut obj: *mut dc_chatlist_t = dc_chatlist_new(context);
if !(context.is_null() || (*context).magic != 0x11a11807i32 as libc::c_uint) {
if !(0 == dc_chatlist_load_from_db(obj, listflags, query_str, query_id)) {
success = 1i32
}
if !(0 == dc_chatlist_load_from_db(obj, listflags, query_str, query_id)) {
success = 1i32
}
if 0 != success {
return obj;
} else {
@@ -89,7 +89,7 @@ pub unsafe fn dc_chatlist_new(mut context: &dc_context_t) -> *mut dc_chatlist_t
}
(*chatlist).magic = 0xc4a71157u32;
(*chatlist).context = context;
(*chatlist).chatNlastmsg_ids = dc_array_new(context, 128i32 as size_t);
(*chatlist).chatNlastmsg_ids = dc_array_new(128i32 as size_t);
if (*chatlist).chatNlastmsg_ids.is_null() {
exit(32i32);
}
@@ -129,8 +129,7 @@ unsafe fn dc_chatlist_load_from_db(
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
let mut strLikeCmd: *mut libc::c_char = 0 as *mut libc::c_char;
let mut query: *mut libc::c_char = 0 as *mut libc::c_char;
if !(chatlist.is_null() || (*chatlist).magic != 0xc4a71157u32 || (*chatlist).context.is_null())
{
if !(chatlist.is_null() || (*chatlist).magic != 0xc4a71157u32) {
dc_chatlist_empty(chatlist);
// select with left join and minimum:
// - the inner select must use `hidden` and _not_ `m.hidden`
@@ -144,14 +143,14 @@ unsafe fn dc_chatlist_load_from_db(
// shown at all permanent in the chatlist.
if 0 != query_contact_id {
stmt =
dc_sqlite3_prepare((*(*chatlist).context).sql,
dc_sqlite3_prepare(&mut (*chatlist).context.sql.lock().unwrap(),
b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.id IN(SELECT chat_id FROM chats_contacts WHERE contact_id=?) GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00"
as *const u8 as *const libc::c_char);
sqlite3_bind_int(stmt, 1i32, query_contact_id as libc::c_int);
current_block = 3437258052017859086;
} else if 0 != listflags & 0x1i32 {
stmt =
dc_sqlite3_prepare((*(*chatlist).context).sql,
dc_sqlite3_prepare(&mut (*chatlist).context.sql.lock().unwrap(),
b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.archived=1 GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00"
as *const u8 as *const libc::c_char);
current_block = 3437258052017859086;
@@ -166,7 +165,7 @@ unsafe fn dc_chatlist_load_from_db(
add_archived_link_item = 1i32
}
stmt =
dc_sqlite3_prepare((*(*chatlist).context).sql,
dc_sqlite3_prepare(&mut (*chatlist).context.sql.lock().unwrap(),
b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.archived=0 GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00"
as *const u8 as *const libc::c_char);
current_block = 3437258052017859086;
@@ -179,7 +178,7 @@ unsafe fn dc_chatlist_load_from_db(
} else {
strLikeCmd = dc_mprintf(b"%%%s%%\x00" as *const u8 as *const libc::c_char, query);
stmt =
dc_sqlite3_prepare((*(*chatlist).context).sql,
dc_sqlite3_prepare(&mut (*chatlist).context.sql.lock().unwrap(),
b"SELECT c.id, m.id FROM chats c LEFT JOIN msgs m ON c.id=m.chat_id AND m.timestamp=( SELECT MAX(timestamp) FROM msgs WHERE chat_id=c.id AND (hidden=0 OR (hidden=1 AND state=19))) WHERE c.id>9 AND c.blocked=0 AND c.name LIKE ? GROUP BY c.id ORDER BY IFNULL(m.timestamp,0) DESC, m.id DESC;\x00"
as *const u8 as
*const libc::c_char);
@@ -224,7 +223,7 @@ unsafe fn dc_chatlist_load_from_db(
pub unsafe fn dc_get_archived_cnt(mut context: &dc_context_t) -> libc::c_int {
let mut ret: libc::c_int = 0i32;
let mut stmt: *mut sqlite3_stmt = dc_sqlite3_prepare(
(*context).sql,
&mut context.sql.lock().unwrap(),
b"SELECT COUNT(*) FROM chats WHERE blocked=0 AND archived=1;\x00" as *const u8
as *const libc::c_char,
);
@@ -238,7 +237,7 @@ unsafe fn get_last_deaddrop_fresh_msg(mut context: &dc_context_t) -> uint32_t {
let mut ret: uint32_t = 0i32 as uint32_t;
let mut stmt: *mut sqlite3_stmt = 0 as *mut sqlite3_stmt;
stmt =
dc_sqlite3_prepare((*context).sql,
dc_sqlite3_prepare(&mut context.sql.lock().unwrap(),
b"SELECT m.id FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id WHERE m.state=10 AND m.hidden=0 AND c.blocked=2 ORDER BY m.timestamp DESC, m.id DESC;\x00"
as *const u8 as *const libc::c_char);
/* we have an index over the state-column, this should be sufficient as there are typically only few fresh messages */
@@ -283,10 +282,10 @@ pub unsafe fn dc_chatlist_get_msg_id(
index.wrapping_mul(2).wrapping_add(1),
);
}
pub unsafe fn dc_chatlist_get_summary(
mut chatlist: *const dc_chatlist_t,
pub unsafe fn dc_chatlist_get_summary<'a>(
mut chatlist: *const dc_chatlist_t<'a>,
mut index: size_t,
mut chat: *mut dc_chat_t,
mut chat: *mut dc_chat_t<'a>,
) -> *mut dc_lot_t {
let mut current_block: u64;
/* The summary is created by the chat, not by the last message.
@@ -335,7 +334,7 @@ pub unsafe fn dc_chatlist_get_summary(
lastcontact = dc_contact_new((*chatlist).context);
dc_contact_load_from_db(
lastcontact,
(*(*chatlist).context).sql,
&mut (*chatlist).context.sql.lock().unwrap(),
(*lastmsg).from_id,
);
}
@@ -355,9 +354,8 @@ pub unsafe fn dc_chatlist_get_summary(
dc_chat_unref(chat_to_delete);
return ret;
}
pub unsafe fn dc_chatlist_get_context(mut chatlist: *mut dc_chatlist_t) -> &dc_context_t {
if chatlist.is_null() || (*chatlist).magic != 0xc4a71157u32 {
return 0 as *mut dc_context_t;
}
return (*chatlist).context;
pub unsafe fn dc_chatlist_get_context<'a>(chatlist: *mut dc_chatlist_t<'a>) -> &'a dc_context_t {
assert!(!chatlist.is_null());
(*chatlist).context
}