Make dc_msg_get_file return PathBuf, not char*

Adjust call sites as apporiate:

 * src/dc_imex.rs(dc_continue_key_transfer): use if-let pattern
   with dc_read_file_safe() and dc_msg_get_file()

 * src/message.rs(dc_msg_get_setupcodebegin): ditto

 * src/message.rs(dc_get_msg_info): simplify code to print information
   about file inside a message.

 * src/message.rs(dc_msg_get_file): simplify function using
   dc_get_abs_path_safe()

 * deltachat-ffi/src/lib.rs(dc_msg_get_file): convert PathBuf to `char *`
   to preserve C API
This commit is contained in:
Dmitry Bogatov
2019-09-11 22:45:54 +00:00
parent aefddf7f5e
commit 477470ff70
3 changed files with 47 additions and 77 deletions

View File

@@ -17,7 +17,7 @@ use std::ptr;
use std::str::FromStr;
use deltachat::contact::Contact;
use deltachat::dc_tools::{as_str, dc_strdup, StrExt};
use deltachat::dc_tools::{as_str, dc_strdup, OsStrExt, StrExt};
use deltachat::*;
// as C lacks a good and portable error handling,
@@ -2013,6 +2013,9 @@ pub unsafe extern "C" fn dc_msg_get_file(msg: *mut dc_msg_t) -> *mut libc::c_cha
}
let ffi_msg = &*msg;
message::dc_msg_get_file(&*ffi_msg.context, &ffi_msg.message)
.and_then(|p| p.to_c_string().ok())
.map(|cs| dc_strdup(cs.as_ptr()))
.unwrap_or_else(|| dc_strdup(ptr::null()))
}
#[no_mangle]