mirror of
https://github.com/chatmail/core.git
synced 2026-05-19 23:06:32 +03:00
check that the w30 app is actually an zip-archive with an index.html
This commit is contained in:
@@ -3675,6 +3675,20 @@ char* dc_msg_get_filename (const dc_msg_t* msg);
|
||||
char* dc_msg_get_filemime (const dc_msg_t* msg);
|
||||
|
||||
|
||||
/**
|
||||
* Return file from inside an archive.
|
||||
* Currently, this works for W30 messages only.
|
||||
*
|
||||
* @param msg The W30 instance.
|
||||
* @param filename The name inside the archive,
|
||||
* must be given as a relative path (no leading `/`).
|
||||
* @param ret_bytes Pointer to a size_t. The size of the blob will be written here.
|
||||
* @return The blob must be released using dc_str_unref() after usage.
|
||||
* NULL if there is no such file in the archive or on errors.
|
||||
*/
|
||||
char* dc_msg_get_blob_from_archive (const dc_msg_t* msg, const char* filename, size_t* ret_bytes);
|
||||
|
||||
|
||||
/**
|
||||
* Get the size of the file. Returns the size of the file associated with a
|
||||
* message, if applicable.
|
||||
|
||||
@@ -3070,6 +3070,39 @@ pub unsafe extern "C" fn dc_msg_get_filename(msg: *mut dc_msg_t) -> *mut libc::c
|
||||
ffi_msg.message.get_filename().unwrap_or_default().strdup()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_msg_get_blob_from_archive(
|
||||
msg: *mut dc_msg_t,
|
||||
filename: *const libc::c_char,
|
||||
ret_bytes: *mut libc::size_t,
|
||||
) -> *mut libc::c_char {
|
||||
if msg.is_null() || filename.is_null() || ret_bytes.is_null() {
|
||||
eprintln!("ignoring careless call to dc_msg_get_blob_from_archive()");
|
||||
return ptr::null_mut();
|
||||
}
|
||||
let ffi_msg = &*msg;
|
||||
let ctx = &*ffi_msg.context;
|
||||
let blob = block_on(async move {
|
||||
ffi_msg
|
||||
.message
|
||||
.get_blob_from_archive(ctx, &to_string_lossy(filename))
|
||||
.await
|
||||
});
|
||||
match blob {
|
||||
Ok(blob) => {
|
||||
// TODO: introduce dc_blob_t to avoid malloc and returning size by pointer and to save copying data
|
||||
*ret_bytes = blob.len();
|
||||
let ptr = libc::malloc(*ret_bytes);
|
||||
libc::memcpy(ptr, blob.as_ptr() as *mut libc::c_void, *ret_bytes);
|
||||
ptr as *mut libc::c_char
|
||||
}
|
||||
Err(err) => {
|
||||
eprintln!("failed read blob from archive: {}", err);
|
||||
ptr::null_mut()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn dc_msg_get_filemime(msg: *mut dc_msg_t) -> *mut libc::c_char {
|
||||
if msg.is_null() {
|
||||
|
||||
Reference in New Issue
Block a user