Change type of dc_msg_t.text to String

Also, remove `send-garbage' command from REPL, since it is not possible to send
non-utf8 string anymore.
This commit is contained in:
Dmitry Bogatov
2019-08-03 11:53:46 +00:00
committed by Floris Bruynooghe
parent d4650ba4a9
commit 765ac2005e
11 changed files with 117 additions and 124 deletions

View File

@@ -914,30 +914,17 @@ pub unsafe fn dc_cmdline(context: &Context, line: &str) -> Result<(), failure::E
ensure!(!sel_chat.is_null(), "No chat selected.");
ensure!(!arg1.is_empty(), "No message text given.");
let msg = CString::yolo(format!("{} {}", arg1, arg2));
let msg = format!("{} {}", arg1, arg2);
if 0 != dc_send_text_msg(context, dc_chat_get_id(sel_chat), msg.as_ptr()) {
if 0 != dc_send_text_msg(context, dc_chat_get_id(sel_chat), msg) {
println!("Message sent.");
} else {
bail!("Sending failed.");
}
}
"send-garbage" => {
ensure!(!sel_chat.is_null(), "No chat selected.");
let msg = b"\xff\x00"; // NUL-terminated C-string, that is malformed utf-8
if 0 != dc_send_text_msg(context, dc_chat_get_id(sel_chat), msg.as_ptr().cast()) {
println!("Malformed utf-8 succesfully send. Not nice.");
} else {
bail!("Garbage sending failed, as expected.");
}
}
"sendempty" => {
ensure!(!sel_chat.is_null(), "No chat selected.");
if 0 != dc_send_text_msg(
context,
dc_chat_get_id(sel_chat),
b"\x00" as *const u8 as *const libc::c_char,
) {
if 0 != dc_send_text_msg(context, dc_chat_get_id(sel_chat), "".into()) {
println!("Message sent.");
} else {
bail!("Sending failed.");