📄 app_mime.c
字号:
/*****************************************************************************
* FUNCTION
* mime_tolower
* DESCRIPTION
* Convert a charcater to lower case
* PARAMETERS
* ch [IN] Charcater to be converted
* RETURNS
* lower case character
*****************************************************************************/
kal_uint8 mime_tolower(kal_uint8 ch)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (ch >= 'A' && ch <= 'Z')
{
return (kal_uint8) (ch + ('a' - 'A'));
}
return ch;
}
/*****************************************************************************
* FUNCTION
* mime_strnicmp
* DESCRIPTION
* Compare two string without case with maximum length
* PARAMETERS
* src [IN] String pointer to be compared
* dest [IN] String pointer to be compared
* maxlen [IN] Lengh to be compared
* RETURNS
* Ture if two string is identical, otherwise, 0
*****************************************************************************/
kal_uint8 mime_strnicmp(kal_char *src, kal_char *dest, kal_int32 maxlen)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint8 ch1, ch2;
kal_char *s1, *s2;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
s1 = src;
s2 = dest;
while (maxlen-- > 0)
{
ch1 = mime_tolower((kal_uint8) * s1++);
ch2 = mime_tolower((kal_uint8) * s2++);
if (ch1 != ch2)
{
return 1;
}
}
return 0;
}
/*****************************************************************************
* FUNCTION
* mime_stricmp
* DESCRIPTION
* Compare two strings without case
* PARAMETERS
* src [IN] String pointer to be compared
* dest [IN] String pointer to be compared
* RETURNS
* Ture if two string is identical, otherwise, 0
*****************************************************************************/
kal_int8 mime_stricmp(kal_char *src, kal_char *dest)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_int32 len_src = strlen(src);
kal_int32 len_dest = strlen(dest);
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (len_src != len_dest)
{
return 1;
}
else
{
return mime_strnicmp(src, dest, len_src);
}
}
/*****************************************************************************
* FUNCTION
* mime_string_start_with
* DESCRIPTION
* Search if str2 is start with srt1
* str1: audio/amr-wb str2: audio/amr-wb;case1.... => MATCH
* str1: audio/amr str2: audio/amr-wb;case2.... => NOT MATCH
* PARAMETERS
* str1 [IN] String pointer to be compared
* str2 [IN] String pointer to be find
* RETURNS
* Ture if one string exist in another string, otherwise, 0
*****************************************************************************/
static kal_bool mime_string_start_with(kal_char *str1, kal_char *str2)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_int32 str1_len;
kal_int32 str2_len;
kal_int32 i;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (str1 == NULL || str2 == NULL)
{
return KAL_FALSE;
}
str1_len = strlen(str1);
str2_len = strlen(str2);
if (str1_len > str2_len)
{
return KAL_FALSE;
}
for (i = 0; i < str1_len; i++)
{
if (mime_tolower((kal_uint8) str1[i]) != mime_tolower((kal_uint8) str2[i]))
{
return KAL_FALSE;
}
}
if(str1_len < str2_len)
{
if( str2[i]!= ';' && str2[i]!=',')
{
return KAL_FALSE;
}
}
return KAL_TRUE;
}
/*****************************************************************************
* FUNCTION
* mime_type_look_up
* DESCRIPTION
* Look up mime-type table. The user can pass some of search criteria for searching
* PARAMETERS
* mime_string [IN] String of mime type, NULL if this element is not provided.
* file_ext [IN] File extension, NULL if this element is not provided.
* mime_type [IN] Mime type, 0XFF if this element is not provided.
* mime_subtype [IN] Mime subtype, 0XFF if this element is not provided
* RETURNS
* pointer to the result element. NULL if not found.
*****************************************************************************/
applib_mime_type_struct *mime_type_look_up_ext(kal_char *mime_string, kal_char *mime_type_string, kal_char *mime_subtype_string, kal_char *file_ext, applib_mime_type_enum mime_type, applib_mime_subtype_enum mime_subtype)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_int32 i;
kal_int32 tbl_size = sizeof(g_applib_mime_tbl) / sizeof(applib_mime_type_struct);
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if(mime_type == 0 && mime_subtype == 0 && file_ext == NULL &&
mime_string == NULL && mime_type_string == NULL && mime_subtype_string == NULL)
{
return NULL;
}
for(i = 0; i < tbl_size; i++)
{
if (mime_type != 0)
if (g_applib_mime_tbl[i].mime_type != mime_type)
{
continue;
}
if (mime_subtype != 0)
if (g_applib_mime_tbl[i].mime_subtype != mime_subtype)
{
continue;
}
if (mime_string != NULL)
if (mime_string_start_with( g_applib_mime_tbl[i].mime_string, mime_string) == KAL_FALSE)
{
continue;
}
if(file_ext != NULL)
{
if(mime_stricmp(file_ext, g_applib_mime_tbl[i].file_ext))
continue;
}
if(mime_type_string != NULL)
{
kal_char *s;
s = strchr(g_applib_mime_tbl[i].mime_string, '/');
ASSERT(s);
if(mime_strnicmp(mime_type_string, g_applib_mime_tbl[i].mime_string, s-g_applib_mime_tbl[i].mime_string))
continue;
}
if(mime_subtype_string != NULL)
{
kal_char *s;
s = strchr(g_applib_mime_tbl[i].mime_string, '/');
ASSERT(s);
if(mime_stricmp(mime_subtype_string, s+1))
continue;
}
break;
}
if (i == tbl_size)
{
return NULL;
}
else
{
return (applib_mime_type_struct*) & g_applib_mime_tbl[i];
}
} /* end of mime_type_look_up_ext */
/*****************************************************************************
* FUNCTION
* mime_type_look_up
* DESCRIPTION
* Look up mime-type table. The user can pass some of search criteria for searching
* PARAMETERS
* mime_string [IN] String of mime type, NULL if this element is not provided.
* file_ext [IN] File extension, NULL if this element is not provided.
* mime_type [IN] Mime type, 0XFF if this element is not provided.
* mime_subtype [IN] Mime subtype, 0XFF if this element is not provided
* RETURNS
* pointer to the result element. NULL if not found.
*****************************************************************************/
applib_mime_type_struct *mime_type_look_up(
kal_char *mime_string,
kal_char *file_ext,
applib_mime_type_enum mime_type,
applib_mime_subtype_enum mime_subtype)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
return mime_type_look_up_ext(mime_string, NULL, NULL, file_ext, mime_type, mime_subtype);
}
/*****************************************************************************
* FUNCTION
* mmi_da_get_extension
* DESCRIPTION
* get extension file name of a file path
* PARAMETERS
* file_path IN The file path
* RETURNS
* Return the pointer where the extension file name start.
* Return NULL if the file_path do not have extension file name.
*****************************************************************************/
kal_wchar *mime_get_extension(kal_wchar *file_path)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_int32 length, i;
kal_wchar *ptr = NULL;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
length = kal_wstrlen(file_path);
/* search from tail until "." */
for (i = length - 1; i >= 0; i--)
{
if (file_path[i] == '.')
{
return &file_path[i + 1];
}
}
return ptr;
}
/*****************************************************************************
* FUNCTION
* mime_get_file_type
* DESCRIPTION
* Result of table look-up. NULL if no matched column found.
* PARAMETERS
* file_path [IN] Path of file to be looked up
* RETURNS
* pointer to the result element. NULL if not found.
*****************************************************************************/
applib_mime_type_struct *mime_get_file_type(kal_wchar *file_path)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
applib_mime_type_struct *mime;
kal_wchar *ptr;
kal_char file_ext[32];
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
ptr = mime_get_extension(file_path);
app_unicode_to_ansii((kal_int8*)file_ext,(kal_int8*) ptr);
mime = mime_type_look_up(NULL, file_ext, 0, 0);
return mime;
}
applib_mime_type_enum mime_get_mime_type(kal_char *mime_type)
{
kal_uint8 i;
for (i = 0;(i <= MIME_TYPE_MAX_NUM) && g_applib_mime_string[i] && mime_stricmp(mime_type, (kal_char*)g_applib_mime_string[i]); i++);
if (i <= MIME_TYPE_MAX_NUM)
{
return (applib_mime_type_enum) i;
}
return MIME_TYPE_UNKNOWN;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -