4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
27 #include <sys/types.h>
34 #include "menu_db_util.h"
35 #include "simple_util.h"
37 static int __match_content_with_regex(const char *content, regex_t *regex_preg)
39 if (regexec(regex_preg, content, 0, NULL, 0) == 0)
45 SLPAPI int aul_get_mime_from_content(const char *content, char *mimetype,
49 regex_tbl *miregex_tbl = NULL;
54 if ((miregex_tbl = miregex_get_regex_table()) == NULL) {
55 _E("load miregex_table fail\n");
60 if (__match_content_with_regex(content,
61 &(miregex_tbl->regex_preg))) {
62 founded = miregex_tbl->mimetype;
63 SECURE_LOGD("content %s => mimetype %s\n", content, founded);
66 miregex_tbl = miregex_tbl->next;
70 snprintf(mimetype, len, "%s", founded);
72 /* TODO : should to try to extract from share mime info's data*/
79 SLPAPI int aul_get_mime_description(const char *mimetype, char *desc, int len)
81 regex_tbl *miregex_tbl = NULL;
87 if ((miregex_tbl = miregex_get_regex_table()) == NULL) {
88 _E("load miregex_table fail\n");
93 if (strcmp(miregex_tbl->mimetype, mimetype) == 0) {
94 founded = miregex_tbl->desc;
95 _D("mimetype %s => desc %s\n", mimetype, founded);
98 miregex_tbl = miregex_tbl->next;
102 snprintf(desc, len, "%s", founded);
104 /* TODO : should to try to extract from
105 share mime info's comment */
112 SLPAPI int aul_get_mime_extension(const char *mimetype, char *ext, int len)
114 const char **extlist;
116 const char *unaliased_mimetype;
118 if (mimetype == NULL || ext == NULL || len <= 0)
121 unaliased_mimetype = xdg_mime_unalias_mime_type(mimetype);
122 if (unaliased_mimetype == NULL)
125 extlist = xdg_mime_get_file_names_from_mime_type(unaliased_mimetype);
129 if (extlist[0] == NULL)
133 while (*extlist != NULL) {
134 if (*(extlist + 1) == NULL) {
135 snprintf(&ext[totlen], len - totlen, "%s", *extlist);
138 snprintf(&ext[totlen], len - totlen, "%s,", *extlist);
139 if (strlen(*extlist) > len - totlen - 1)
141 totlen += strlen(*extlist) + 1;
149 SLPAPI int aul_get_mime_icon(const char *mimetype, char *iconname, int len)
152 const char *unaliased_mimetype;
154 if (mimetype == NULL || iconname == NULL || len <= 0)
157 unaliased_mimetype = xdg_mime_unalias_mime_type(mimetype);
158 if (unaliased_mimetype == NULL)
161 icon = xdg_mime_get_icon(unaliased_mimetype);
163 icon = xdg_mime_get_generic_icon(unaliased_mimetype);
166 snprintf(iconname, len, "%s", icon);
172 SLPAPI int aul_get_mime_from_file(const char *filename, char *mimetype, int len)
176 if (filename == NULL)
179 if (access(filename, F_OK) != 0) {
180 _E("access fail(%s)", strerror(errno));
184 if (stat(filename, &statbuf) != 0){
185 _E("Unable to get stat, error is %s", strerror(errno));
188 if(S_ISDIR(statbuf.st_mode))
191 mime = xdg_mime_get_mime_type_for_file(filename, 0);
192 if (strcmp(mime, "application/octet-stream") == 0) {
193 mime = xdg_mime_get_mime_type_from_file_name(filename);
196 snprintf(mimetype, len, "%s", mime);