From 5917d053059777c8d69440d9da5474e126eb6a7b Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Wed, 14 Aug 2019 17:39:27 +0000 Subject: [PATCH] Drop old version of {dc_msg_guess_msgtype_from_suffix} --- src/dc_msg.rs | 175 ++------------------------------------------------ 1 file changed, 4 insertions(+), 171 deletions(-) diff --git a/src/dc_msg.rs b/src/dc_msg.rs index bb6b578ef..ecc086078 100644 --- a/src/dc_msg.rs +++ b/src/dc_msg.rs @@ -285,61 +285,6 @@ pub unsafe fn dc_msg_get_filemime(msg: *const dc_msg_t) -> *mut libc::c_char { "application/octet-stream".strdup() } -#[allow(non_snake_case)] -pub unsafe fn dc_msg_guess_msgtype_from_suffix0( - pathNfilename: *const libc::c_char, - mut ret_msgtype: *mut Viewtype, - mut ret_mime: *mut *mut libc::c_char, -) { - let mut suffix: *mut libc::c_char = 0 as *mut libc::c_char; - let mut dummy_msgtype = Viewtype::Unknown; - let mut dummy_buf: *mut libc::c_char = 0 as *mut libc::c_char; - if !pathNfilename.is_null() { - if ret_msgtype.is_null() { - ret_msgtype = &mut dummy_msgtype - } - if ret_mime.is_null() { - ret_mime = &mut dummy_buf - } - *ret_msgtype = Viewtype::Unknown; - *ret_mime = 0 as *mut libc::c_char; - suffix = dc_get_filesuffix_lc(pathNfilename); - if !suffix.is_null() { - if strcmp(suffix, b"mp3\x00" as *const u8 as *const libc::c_char) == 0i32 { - *ret_msgtype = Viewtype::Audio; - *ret_mime = dc_strdup(b"audio/mpeg\x00" as *const u8 as *const libc::c_char) - } else if strcmp(suffix, b"aac\x00" as *const u8 as *const libc::c_char) == 0i32 { - *ret_msgtype = Viewtype::Audio; - *ret_mime = dc_strdup(b"audio/aac\x00" as *const u8 as *const libc::c_char) - } else if strcmp(suffix, b"mp4\x00" as *const u8 as *const libc::c_char) == 0i32 { - *ret_msgtype = Viewtype::Video; - *ret_mime = dc_strdup(b"video/mp4\x00" as *const u8 as *const libc::c_char) - } else if strcmp(suffix, b"jpg\x00" as *const u8 as *const libc::c_char) == 0i32 - || strcmp(suffix, b"jpeg\x00" as *const u8 as *const libc::c_char) == 0i32 - { - *ret_msgtype = Viewtype::Image; - *ret_mime = dc_strdup(b"image/jpeg\x00" as *const u8 as *const libc::c_char) - } else if strcmp(suffix, b"png\x00" as *const u8 as *const libc::c_char) == 0i32 { - *ret_msgtype = Viewtype::Image; - *ret_mime = dc_strdup(b"image/png\x00" as *const u8 as *const libc::c_char) - } else if strcmp(suffix, b"webp\x00" as *const u8 as *const libc::c_char) == 0i32 { - *ret_msgtype = Viewtype::Image; - *ret_mime = dc_strdup(b"image/webp\x00" as *const u8 as *const libc::c_char) - } else if strcmp(suffix, b"gif\x00" as *const u8 as *const libc::c_char) == 0i32 { - *ret_msgtype = Viewtype::Gif; - *ret_mime = dc_strdup(b"image/gif\x00" as *const u8 as *const libc::c_char) - } else if strcmp(suffix, b"vcf\x00" as *const u8 as *const libc::c_char) == 0i32 - || strcmp(suffix, b"vcard\x00" as *const u8 as *const libc::c_char) == 0i32 - { - *ret_msgtype = Viewtype::File; - *ret_mime = dc_strdup(b"text/vcard\x00" as *const u8 as *const libc::c_char) - } - } - } - free(suffix as *mut libc::c_void); - free(dummy_buf as *mut libc::c_void); -} - pub fn dc_msg_guess_msgtype_from_suffix(path: &Path) -> Option<(Viewtype, &str)> { let known = hashmap! { "mp3" => (Viewtype::Audio, "audio/mpeg"), @@ -1446,125 +1391,13 @@ pub fn dc_update_server_uid( mod tests { use super::*; use crate::test_utils as test; - use std::ffi::CStr; #[test] fn test_dc_msg_guess_msgtype_from_suffix() { - unsafe { - let mut type_0 = Viewtype::Unknown; - let mut mime_0: *mut libc::c_char = 0 as *mut libc::c_char; - - dc_msg_guess_msgtype_from_suffix( - b"foo/bar-sth.mp3\x00" as *const u8 as *const libc::c_char, - &mut type_0, - &mut mime_0, - ); - assert_eq!(type_0, Viewtype::Audio); - assert_eq!(as_str(mime_0 as *const libc::c_char), "audio/mpeg"); - free(mime_0 as *mut libc::c_void); - - dc_msg_guess_msgtype_from_suffix( - b"foo/bar-sth.aac\x00" as *const u8 as *const libc::c_char, - &mut type_0, - &mut mime_0, - ); - assert_eq!(type_0, Viewtype::Audio); - assert_eq!(as_str(mime_0 as *const libc::c_char), "audio/aac"); - free(mime_0 as *mut libc::c_void); - - dc_msg_guess_msgtype_from_suffix( - b"foo/bar-sth.mp4\x00" as *const u8 as *const libc::c_char, - &mut type_0, - &mut mime_0, - ); - assert_eq!(type_0, Viewtype::Video); - assert_eq!(as_str(mime_0 as *const libc::c_char), "video/mp4"); - free(mime_0 as *mut libc::c_void); - - dc_msg_guess_msgtype_from_suffix( - b"foo/bar-sth.jpg\x00" as *const u8 as *const libc::c_char, - &mut type_0, - &mut mime_0, - ); - assert_eq!(type_0, Viewtype::Image); - assert_eq!( - CStr::from_ptr(mime_0 as *const libc::c_char) - .to_str() - .unwrap(), - "image/jpeg" - ); - free(mime_0 as *mut libc::c_void); - - dc_msg_guess_msgtype_from_suffix( - b"foo/bar-sth.jpeg\x00" as *const u8 as *const libc::c_char, - &mut type_0, - &mut mime_0, - ); - assert_eq!(type_0, Viewtype::Image); - assert_eq!( - CStr::from_ptr(mime_0 as *const libc::c_char) - .to_str() - .unwrap(), - "image/jpeg" - ); - free(mime_0 as *mut libc::c_void); - - dc_msg_guess_msgtype_from_suffix( - b"foo/bar-sth.png\x00" as *const u8 as *const libc::c_char, - &mut type_0, - &mut mime_0, - ); - assert_eq!(type_0, Viewtype::Image); - assert_eq!( - CStr::from_ptr(mime_0 as *const libc::c_char) - .to_str() - .unwrap(), - "image/png" - ); - free(mime_0 as *mut libc::c_void); - - dc_msg_guess_msgtype_from_suffix( - b"foo/bar-sth.webp\x00" as *const u8 as *const libc::c_char, - &mut type_0, - &mut mime_0, - ); - assert_eq!(type_0, Viewtype::Image); - assert_eq!( - CStr::from_ptr(mime_0 as *const libc::c_char) - .to_str() - .unwrap(), - "image/webp" - ); - free(mime_0 as *mut libc::c_void); - - dc_msg_guess_msgtype_from_suffix( - b"foo/bar-sth.gif\x00" as *const u8 as *const libc::c_char, - &mut type_0, - &mut mime_0, - ); - assert_eq!(type_0, Viewtype::Gif); - assert_eq!( - CStr::from_ptr(mime_0 as *const libc::c_char) - .to_str() - .unwrap(), - "image/gif" - ); - free(mime_0 as *mut libc::c_void); - - dc_msg_guess_msgtype_from_suffix( - b"foo/bar-sth.vcf\x00" as *const u8 as *const libc::c_char, - &mut type_0, - &mut mime_0, - ); - assert_eq!(type_0, Viewtype::File); - assert_eq!( - CStr::from_ptr(mime_0 as *const libc::c_char) - .to_str() - .unwrap(), - "text/vcard" - ); - free(mime_0 as *mut libc::c_void); - } + assert_eq!( + dc_msg_guess_msgtype_from_suffix(Path::new("foo/bar-sth.mp3")), + Some((Viewtype::Audio, "audio/mpeg")) + ); } #[test]