Implement Rust version of {dc_msg_guess_msgtype_from_suffix}

This commit is contained in:
Dmitry Bogatov
2019-08-14 06:07:20 +00:00
committed by holger krekel
parent 2bb2ef07e9
commit 8f0e554bc4
4 changed files with 29 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
use std::ffi::CString;
use std::path::Path;
use crate::constants::*;
use crate::contact::*;
@@ -352,6 +353,24 @@ pub unsafe fn dc_msg_guess_msgtype_from_suffix(
free(dummy_buf as *mut libc::c_void);
}
pub fn dc_msg_guess_msgtype_from_suffix2(path: &Path) -> Option<(Viewtype, &str)> {
let known = hashmap! {
"mp3" => (Viewtype::Audio, "audio/mpeg"),
"aac" => (Viewtype::Audio, "audio/aac"),
"mp4" => (Viewtype::Video, "video/mp4"),
"jpg" => (Viewtype::Image, "image/jpeg"),
"jpeg" => (Viewtype::Image, "image/jpeg"),
"png" => (Viewtype::Image, "image/png"),
"webp" => (Viewtype::Image, "image/webp"),
"gif" => (Viewtype::Gif, "image/gif"),
"vcf" => (Viewtype::File, "text/vcard"),
"vcard" => (Viewtype::File, "text/vcard"),
};
let extension = path.extension()?.to_str()?;
known.get(extension).map(|x| *x)
}
pub unsafe fn dc_msg_get_file(msg: *const dc_msg_t) -> *mut libc::c_char {
let mut file_abs = 0 as *mut libc::c_char;

View File

@@ -16,6 +16,8 @@ extern crate rusqlite;
extern crate strum;
#[macro_use]
extern crate strum_macros;
#[macro_use]
extern crate maplit;
#[macro_use]
mod log;