This commit is contained in:
dignifiedquire
2019-07-10 17:38:54 +02:00
parent 808a0f2890
commit 9dda90dd5d

View File

@@ -88,9 +88,10 @@ pub unsafe extern "C" fn dc_set_config(
value: *mut libc::c_char, value: *mut libc::c_char,
) -> libc::c_int { ) -> libc::c_int {
assert!(!context.is_null()); assert!(!context.is_null());
assert!(!key.is_null(), "invalid key");
let context = &*context; let context = &*context;
context::dc_set_config(context, key, value) context::dc_set_config(context, dc_tools::as_str(key), as_opt_str(value))
} }
#[no_mangle] #[no_mangle]
@@ -99,9 +100,10 @@ pub unsafe extern "C" fn dc_get_config(
key: *mut libc::c_char, key: *mut libc::c_char,
) -> *mut libc::c_char { ) -> *mut libc::c_char {
assert!(!context.is_null()); assert!(!context.is_null());
assert!(!key.is_null(), "invalid key");
let context = &*context; let context = &*context;
context::dc_get_config(context, key) into_cstring(context::dc_get_config(context, dc_tools::as_str(key)))
} }
#[no_mangle] #[no_mangle]
@@ -411,7 +413,7 @@ pub unsafe extern "C" fn dc_marknoticed_chat(context: *mut dc_context_t, chat_id
assert!(!context.is_null()); assert!(!context.is_null());
let context = &*context; let context = &*context;
dc_chat::dc_marknoticed_chat(context, chat_id) dc_chat::dc_marknoticed_chat(context, chat_id);
} }
#[no_mangle] #[no_mangle]
@@ -419,7 +421,7 @@ pub unsafe extern "C" fn dc_marknoticed_all_chats(context: *mut dc_context_t) {
assert!(!context.is_null()); assert!(!context.is_null());
let context = &*context; let context = &*context;
dc_chat::dc_marknoticed_all_chats(context) dc_chat::dc_marknoticed_all_chats(context);
} }
#[no_mangle] #[no_mangle]
@@ -460,7 +462,7 @@ pub unsafe extern "C" fn dc_archive_chat(
assert!(!context.is_null()); assert!(!context.is_null());
let context = &*context; let context = &*context;
dc_chat::dc_archive_chat(context, chat_id, archive) dc_chat::dc_archive_chat(context, chat_id, archive);
} }
#[no_mangle] #[no_mangle]
@@ -641,7 +643,7 @@ pub unsafe extern "C" fn dc_markseen_msgs(
assert!(!context.is_null()); assert!(!context.is_null());
let context = &*context; let context = &*context;
dc_msg::dc_markseen_msgs(context, msg_ids, msg_cnt) dc_msg::dc_markseen_msgs(context, msg_ids, msg_cnt as usize);
} }
#[no_mangle] #[no_mangle]
@@ -654,7 +656,7 @@ pub unsafe extern "C" fn dc_star_msgs(
assert!(!context.is_null()); assert!(!context.is_null());
let context = &*context; let context = &*context;
dc_msg::dc_star_msgs(context, msg_ids, msg_cnt, star) dc_msg::dc_star_msgs(context, msg_ids, msg_cnt, star);
} }
#[no_mangle] #[no_mangle]
@@ -887,7 +889,7 @@ pub unsafe extern "C" fn dc_is_sending_locations_to_chat(
assert!(!context.is_null()); assert!(!context.is_null());
let context = &*context; let context = &*context;
dc_location::dc_is_sending_locations_to_chat(context, chat_id) dc_location::dc_is_sending_locations_to_chat(context, chat_id) as libc::c_int
} }
#[no_mangle] #[no_mangle]
@@ -928,7 +930,7 @@ pub unsafe extern "C" fn dc_delete_all_locations(context: *mut dc_context_t) {
assert!(!context.is_null()); assert!(!context.is_null());
let context = &*context; let context = &*context;
dc_location::dc_delete_all_locations(context) dc_location::dc_delete_all_locations(context);
} }
// dc_array_t // dc_array_t
@@ -1337,7 +1339,7 @@ pub unsafe extern "C" fn dc_msg_is_increation(msg: *mut dc_msg::dc_msg_t) -> lib
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn dc_msg_is_setupmessage(msg: *mut dc_msg::dc_msg_t) -> libc::c_int { pub unsafe extern "C" fn dc_msg_is_setupmessage(msg: *mut dc_msg::dc_msg_t) -> libc::c_int {
dc_msg::dc_msg_is_setupmessage(msg) dc_msg::dc_msg_is_setupmessage(msg) as libc::c_int
} }
#[no_mangle] #[no_mangle]
@@ -1524,3 +1526,15 @@ pub unsafe extern "C" fn dc_lot_get_timestamp(lot: *mut dc_lot::dc_lot_t) -> i64
pub unsafe extern "C" fn dc_str_unref(s: *mut libc::c_char) { pub unsafe extern "C" fn dc_str_unref(s: *mut libc::c_char) {
libc::free(s as *mut _) libc::free(s as *mut _)
} }
fn as_opt_str<'a>(s: *const libc::c_char) -> Option<&'a str> {
if s.is_null() {
return None;
}
Some(dc_tools::as_str(s))
}
unsafe fn into_cstring(s: impl AsRef<str>) -> *mut libc::c_char {
dc_tools::dc_strdup(dc_tools::to_cstring(s).as_ptr())
}