Compare commits

...

2 Commits

Author SHA1 Message Date
holger krekel
3a602ee313 fix ffi 2019-09-09 18:43:03 +02:00
Alexander Krotov
e0c1b91a7a Make dc_msg_get_filemime safe 2019-09-09 18:34:25 +03:00
2 changed files with 7 additions and 10 deletions

View File

@@ -2019,7 +2019,7 @@ pub unsafe extern "C" fn dc_msg_get_filemime(msg: *mut dc_msg_t) -> *mut libc::c
}
let msg = &*msg;
message::dc_msg_get_filemime(msg)
message::dc_msg_get_filemime(msg).strdup()
}
#[no_mangle]

View File

@@ -165,7 +165,6 @@ pub struct Message<'a> {
// handle messages
pub unsafe fn dc_get_msg_info(context: &Context, msg_id: u32) -> *mut libc::c_char {
let mut p: *mut libc::c_char;
let mut ret = String::new();
let msg = dc_msg_load_from_db(context, msg_id);
@@ -271,7 +270,7 @@ pub unsafe fn dc_get_msg_info(context: &Context, msg_id: u32) -> *mut libc::c_ch
_ => {}
}
p = dc_msg_get_file(&msg);
let p = dc_msg_get_file(&msg);
if !p.is_null() && 0 != *p.offset(0isize) as libc::c_int {
ret += &format!(
"\nFile: {}, {}, bytes\n",
@@ -285,9 +284,7 @@ pub unsafe fn dc_get_msg_info(context: &Context, msg_id: u32) -> *mut libc::c_ch
ret += "Type: ";
ret += &format!("{}", msg.type_0);
ret += "\n";
p = dc_msg_get_filemime(&msg);
ret += &format!("Mimetype: {}\n", as_str(p));
free(p as *mut libc::c_void);
ret += &format!("Mimetype: {}\n", &dc_msg_get_filemime(&msg));
}
let w = msg.param.get_int(Param::Width).unwrap_or_default();
let h = msg.param.get_int(Param::Height).unwrap_or_default();
@@ -353,16 +350,16 @@ impl<'a> Drop for Message<'a> {
}
}
pub unsafe fn dc_msg_get_filemime(msg: &Message) -> *mut libc::c_char {
pub fn dc_msg_get_filemime(msg: &Message) -> String {
if let Some(m) = msg.param.get(Param::MimeType) {
return m.strdup();
return m.to_string();
} else if let Some(file) = msg.param.get(Param::File) {
if let Some((_, mime)) = dc_msg_guess_msgtype_from_suffix(Path::new(file)) {
return mime.strdup();
return mime.to_string();
}
}
"application/octet-stream".strdup()
"application/octet-stream".to_string()
}
pub fn dc_msg_guess_msgtype_from_suffix(path: &Path) -> Option<(Viewtype, &str)> {