mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
Construct dc_array_t id arrays using safe methods
This commit is contained in:
@@ -521,13 +521,13 @@ pub fn dc_get_fresh_msgs(context: &Context) -> *mut dc_array_t {
|
|||||||
&[10, 9, if 0 != show_deaddrop { 2 } else { 0 }],
|
&[10, 9, if 0 != show_deaddrop { 2 } else { 0 }],
|
||||||
|row| row.get(0),
|
|row| row.get(0),
|
||||||
|rows| {
|
|rows| {
|
||||||
let ret = dc_array_new(128 as size_t);
|
let mut ret = dc_array_t::new(128);
|
||||||
|
|
||||||
for row in rows {
|
for row in rows {
|
||||||
let id = row?;
|
let id = row?;
|
||||||
unsafe { dc_array_add_id(ret, id) };
|
ret.add_id(id);
|
||||||
}
|
}
|
||||||
Ok(ret)
|
Ok(ret.as_ptr())
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@@ -560,7 +560,7 @@ pub fn dc_search_msgs(
|
|||||||
AND ct.blocked=0 AND (m.txt LIKE ? OR ct.name LIKE ?) ORDER BY m.timestamp DESC,m.id DESC;"
|
AND ct.blocked=0 AND (m.txt LIKE ? OR ct.name LIKE ?) ORDER BY m.timestamp DESC,m.id DESC;"
|
||||||
};
|
};
|
||||||
|
|
||||||
let ret = dc_array_new(100 as size_t);
|
let mut ret = dc_array_t::new(100);
|
||||||
|
|
||||||
let success = context
|
let success = context
|
||||||
.sql
|
.sql
|
||||||
@@ -570,7 +570,7 @@ pub fn dc_search_msgs(
|
|||||||
|row| row.get::<_, i32>(0),
|
|row| row.get::<_, i32>(0),
|
||||||
|rows| {
|
|rows| {
|
||||||
for id in rows {
|
for id in rows {
|
||||||
unsafe { dc_array_add_id(ret, id? as u32) };
|
ret.add_id(id? as u32);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
@@ -578,12 +578,9 @@ pub fn dc_search_msgs(
|
|||||||
.is_ok();
|
.is_ok();
|
||||||
|
|
||||||
if success {
|
if success {
|
||||||
return ret;
|
return ret.as_ptr();
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ret.is_null() {
|
|
||||||
unsafe { dc_array_unref(ret) };
|
|
||||||
}
|
|
||||||
std::ptr::null_mut()
|
std::ptr::null_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1094,14 +1094,13 @@ pub unsafe fn dc_get_draft(context: &Context, chat_id: uint32_t) -> *mut dc_msg_
|
|||||||
draft_msg
|
draft_msg
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn dc_get_chat_msgs(
|
pub fn dc_get_chat_msgs(
|
||||||
context: &Context,
|
context: &Context,
|
||||||
chat_id: uint32_t,
|
chat_id: uint32_t,
|
||||||
flags: uint32_t,
|
flags: uint32_t,
|
||||||
marker1before: uint32_t,
|
marker1before: uint32_t,
|
||||||
) -> *mut dc_array_t {
|
) -> *mut dc_array_t {
|
||||||
let ret = dc_array_new(512);
|
let mut ret = dc_array_t::new(512);
|
||||||
assert!(!ret.is_null());
|
|
||||||
|
|
||||||
let mut last_day = 0;
|
let mut last_day = 0;
|
||||||
let cnv_to_local = dc_gm2local_offset();
|
let cnv_to_local = dc_gm2local_offset();
|
||||||
@@ -1111,17 +1110,17 @@ pub unsafe fn dc_get_chat_msgs(
|
|||||||
for row in rows {
|
for row in rows {
|
||||||
let (curr_id, ts) = row?;
|
let (curr_id, ts) = row?;
|
||||||
if curr_id as u32 == marker1before {
|
if curr_id as u32 == marker1before {
|
||||||
dc_array_add_id(ret, 1);
|
ret.add_id(1);
|
||||||
}
|
}
|
||||||
if 0 != flags & 0x1 {
|
if 0 != flags & 0x1 {
|
||||||
let curr_local_timestamp = ts + cnv_to_local;
|
let curr_local_timestamp = ts + cnv_to_local;
|
||||||
let curr_day = (curr_local_timestamp / 86400) as libc::c_int;
|
let curr_day = (curr_local_timestamp / 86400) as libc::c_int;
|
||||||
if curr_day != last_day {
|
if curr_day != last_day {
|
||||||
dc_array_add_id(ret, 9);
|
ret.add_id(9);
|
||||||
last_day = curr_day;
|
last_day = curr_day;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dc_array_add_id(ret, curr_id as u32);
|
ret.add_id(curr_id as u32);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
};
|
};
|
||||||
@@ -1169,11 +1168,8 @@ pub unsafe fn dc_get_chat_msgs(
|
|||||||
};
|
};
|
||||||
|
|
||||||
if success.is_ok() {
|
if success.is_ok() {
|
||||||
ret
|
ret.as_ptr()
|
||||||
} else {
|
} else {
|
||||||
if !ret.is_null() {
|
|
||||||
dc_array_unref(ret);
|
|
||||||
}
|
|
||||||
0 as *mut dc_array_t
|
0 as *mut dc_array_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1285,11 +1281,11 @@ pub fn dc_get_chat_media(
|
|||||||
],
|
],
|
||||||
|row| row.get::<_, i32>(0),
|
|row| row.get::<_, i32>(0),
|
||||||
|ids| {
|
|ids| {
|
||||||
let ret = dc_array_new(100);
|
let mut ret = dc_array_t::new(100);
|
||||||
for id in ids {
|
for id in ids {
|
||||||
unsafe { dc_array_add_id(ret, id? as u32) };
|
ret.add_id(id? as u32);
|
||||||
}
|
}
|
||||||
Ok(ret)
|
Ok(ret.as_ptr())
|
||||||
}
|
}
|
||||||
).unwrap_or_else(|_| std::ptr::null_mut())
|
).unwrap_or_else(|_| std::ptr::null_mut())
|
||||||
}
|
}
|
||||||
@@ -1458,13 +1454,13 @@ pub fn dc_get_chat_contacts(context: &Context, chat_id: u32) -> *mut dc_array_t
|
|||||||
params![chat_id as i32],
|
params![chat_id as i32],
|
||||||
|row| row.get::<_, i32>(0),
|
|row| row.get::<_, i32>(0),
|
||||||
|ids| {
|
|ids| {
|
||||||
let ret = dc_array_new(100);
|
let mut ret = dc_array_t::new(100);
|
||||||
|
|
||||||
for id in ids {
|
for id in ids {
|
||||||
unsafe { dc_array_add_id(ret, id? as u32) };
|
ret.add_id(id? as u32);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(ret)
|
Ok(ret.as_ptr())
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap_or_else(|_| std::ptr::null_mut())
|
.unwrap_or_else(|_| std::ptr::null_mut())
|
||||||
|
|||||||
@@ -537,7 +537,7 @@ pub fn dc_get_contacts(
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let mut add_self = false;
|
let mut add_self = false;
|
||||||
let ret = dc_array_new(100);
|
let mut ret = dc_array_t::new(100);
|
||||||
|
|
||||||
if (listflags & DC_GCL_VERIFIED_ONLY) > 0 || !query.is_null() {
|
if (listflags & DC_GCL_VERIFIED_ONLY) > 0 || !query.is_null() {
|
||||||
let s3strLikeCmd = format!("%{}%", if !query.is_null() { as_str(query) } else { "" });
|
let s3strLikeCmd = format!("%{}%", if !query.is_null() { as_str(query) } else { "" });
|
||||||
@@ -565,7 +565,7 @@ pub fn dc_get_contacts(
|
|||||||
|row| row.get::<_, i32>(0),
|
|row| row.get::<_, i32>(0),
|
||||||
|ids| {
|
|ids| {
|
||||||
for id in ids {
|
for id in ids {
|
||||||
unsafe { dc_array_add_id(ret, id? as u32) };
|
ret.add_id(id? as u32);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
@@ -595,7 +595,7 @@ pub fn dc_get_contacts(
|
|||||||
|row| row.get::<_, i32>(0),
|
|row| row.get::<_, i32>(0),
|
||||||
|ids| {
|
|ids| {
|
||||||
for id in ids {
|
for id in ids {
|
||||||
unsafe { dc_array_add_id(ret, id? as u32) };
|
ret.add_id(id? as u32);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -603,10 +603,10 @@ pub fn dc_get_contacts(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if 0 != listflags & 0x2 && add_self {
|
if 0 != listflags & 0x2 && add_self {
|
||||||
unsafe { dc_array_add_id(ret, 1) };
|
ret.add_id(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret
|
ret.as_ptr()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dc_get_blocked_cnt(context: &Context) -> libc::c_int {
|
pub fn dc_get_blocked_cnt(context: &Context) -> libc::c_int {
|
||||||
@@ -629,13 +629,13 @@ pub fn dc_get_blocked_contacts(context: &Context) -> *mut dc_array_t {
|
|||||||
params![9],
|
params![9],
|
||||||
|row| row.get::<_, i32>(0),
|
|row| row.get::<_, i32>(0),
|
||||||
|ids| {
|
|ids| {
|
||||||
let ret = dc_array_new(100);
|
let mut ret = dc_array_t::new(100);
|
||||||
|
|
||||||
for id in ids {
|
for id in ids {
|
||||||
unsafe { dc_array_add_id(ret, id? as u32) };
|
ret.add_id(id? as u32);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(ret)
|
Ok(ret.as_ptr())
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.unwrap_or_else(|_| std::ptr::null_mut())
|
.unwrap_or_else(|_| std::ptr::null_mut())
|
||||||
|
|||||||
Reference in New Issue
Block a user