4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@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.
22 #include "media-svc-util.h"
23 #include "media-svc-debug.h"
24 #include "media-svc-error.h"
25 #include "minfo-types.h"
26 #include "media-svc-structures.h"
29 #include <vconf-keys.h>
30 #include <drm-service.h>
34 bool _mb_svc_get_file_display_name(const char *file_path, char *file_name)
38 if ((result = strrchr(file_path, '/'))) {
39 strncpy(file_name, (result + 1), MB_SVC_FILE_NAME_LEN_MAX + 1);
43 strncpy(file_name, file_path, MB_SVC_FILE_NAME_LEN_MAX + 1);
44 file_name[MB_SVC_FILE_NAME_LEN_MAX] = '\0';
49 bool _mb_svc_get_file_parent_path(const char *file_path, char *parent_path)
51 char file_name[MB_SVC_FILE_NAME_LEN_MAX + 1] = { 0 };
53 _mb_svc_get_file_display_name(file_path, file_name);
54 strncpy(parent_path, file_path, MB_SVC_FILE_PATH_LEN_MAX + 1);
55 parent_path[strlen(file_path) - strlen(file_name) - 1] = '\0';
57 if (strlen(parent_path) == 0) {
58 strncpy(parent_path, "/", MB_SVC_FILE_PATH_LEN_MAX + 1);
64 bool _mb_svc_get_dir_display_name(const char *dir_path, char *dir_name)
66 char path[MB_SVC_DIR_PATH_LEN_MAX + 1] = { 0 };
69 strncpy(path, dir_path, sizeof(path));
71 if ((result = strrchr(path, '/'))) {
72 if (*(result + 1) == '\0') {
77 if (strncmp(dir_path, MB_SVC_PATH_MMC, strlen(dir_path)) == 0
78 || strncmp(dir_path, MB_SVC_PATH_PHONE, strlen(dir_path)) == 0) {
79 mb_svc_debug("dir path is empty because path is root");
80 strncpy(dir_name, "", MB_SVC_FILE_NAME_LEN_MAX + 1);
84 if ((result = strrchr(path, '/'))) {
85 strncpy(dir_name, (result + 1), MB_SVC_FILE_NAME_LEN_MAX + 1);
89 strncpy(dir_name, path, MB_SVC_FILE_NAME_LEN_MAX + 1);
90 dir_name[MB_SVC_FILE_NAME_LEN_MAX] = '\0';
96 ** in this funtion, if dir_path equals "/01/02/03", parent path is "/01/02/", not "01/02"
97 ** if dir_path equals "/01", its parent path is "/"
99 bool _mb_svc_get_dir_parent_path(const char *dir_path, char *parent_path)
101 char dir_name[MB_SVC_DIR_PATH_LEN_MAX + 1] = { 0 };
103 _mb_svc_get_dir_display_name(dir_path, dir_name);
104 strncpy(parent_path, dir_path, MB_SVC_DIR_PATH_LEN_MAX + 1);
105 parent_path[strlen(parent_path) - strlen(dir_name)] = '\0';
106 mb_svc_debug("parent_path is %s", parent_path);
110 int _mb_svc_get_file_dir_modified_date(const char *full_path)
112 struct stat statbuf = { 0 };
116 fd = stat(full_path, &statbuf);
119 mb_svc_debug("stat(%s) fails. err[%d]", full_path, err);
120 return MB_SVC_ERROR_INTERNAL;
123 return statbuf.st_mtime;
127 _mb_svc_get_full_path(const char *path, minfo_store_type storage_type,
130 if (path == NULL || full_path == NULL) {
131 mb_svc_debug("path == NULL || full_path == NULL ");
135 switch (storage_type) {
137 strncpy(full_path, MB_SVC_PATH_MMC, MB_SVC_FILE_PATH_LEN_MAX + 1);
141 strncpy(full_path, MB_SVC_PATH_PHONE, MB_SVC_FILE_PATH_LEN_MAX + 1);
144 if (strncmp(path, "/", MB_SVC_FILE_PATH_LEN_MAX + 1) != 0) {
145 strcat(full_path, path);
151 bool _mb_svc_is_valid_path(const char *full_path)
153 char phone_root_path[MB_SVC_DIR_PATH_LEN_MAX + 1] = { 0 };
154 char mmc_root_path[MB_SVC_DIR_PATH_LEN_MAX + 1] = { 0 };
156 if (strlen(full_path) == 0) {
160 _mb_svc_get_full_path("/", MINFO_PHONE, phone_root_path);
161 _mb_svc_get_full_path("/", MINFO_MMC, mmc_root_path);
163 if (strncmp(full_path, phone_root_path, strlen(phone_root_path)) == 0) {
164 /* like "/mnt/ums/.message" isn't valid mesage, shoud filter */
165 if (strlen(full_path) > strlen(phone_root_path) + 1 && full_path[strlen(phone_root_path) + 1] == '.') {
172 if (strncmp(full_path, mmc_root_path, strlen(mmc_root_path)) == 0) {
179 int _mb_svc_get_store_type_by_full(const char *full_path)
181 if (full_path != NULL) {
183 (full_path, MB_SVC_PATH_PHONE,
184 strlen(MB_SVC_PATH_PHONE)) == 0) {
188 (full_path, MB_SVC_PATH_MMC,
189 strlen(MB_SVC_PATH_MMC)) == 0) {
194 return MB_SVC_ERROR_INTERNAL;
197 int _mb_svc_get_rel_path_by_full(const char *full_path, char *path)
200 minfo_store_type store_type = 0;
202 store_type = _mb_svc_get_store_type_by_full(full_path);
204 switch (store_type) {
206 root_len = strlen(MB_SVC_PATH_PHONE);
209 root_len = strlen(MB_SVC_PATH_MMC);
212 return MB_SVC_ERROR_INTERNAL;
214 if (*(full_path + root_len) != '\0') {
215 strncpy(path, full_path + root_len, MB_SVC_FILE_PATH_LEN_MAX + 1);
217 strncpy(path, "/", MB_SVC_FILE_PATH_LEN_MAX + 1);
223 bool _mb_svc_get_file_ext(const char *file_path, char *file_ext)
227 for (i = strlen(file_path); i >= 0; i--) {
228 if ((file_path[i] == '.') && (i < MB_SVC_FILE_PATH_LEN_MAX)) {
229 strncpy(file_ext, &file_path[i + 1],
230 MB_SVC_FILE_EXT_LEN_MAX + 1);
234 if (file_path[i] == '/') { /* meet the dir. no ext */
241 bool _mb_svc_glist_free(GList **glist, bool is_free_element)
247 if (*glist == NULL) {
251 if (is_free_element) {
252 length = g_list_length(*glist);
253 for (i = 0; i < length; i++) {
254 p = g_list_nth_data(*glist, i);
260 if (*glist != NULL) {
267 int _mb_svc_get_file_type(const char *file_full_path)
272 if (file_full_path == NULL)
273 return MB_SVC_ERROR_INVALID_PARAMETER;
275 if (drm_svc_is_drm_file(file_full_path) == DRM_TRUE) {
276 DRM_FILE_TYPE drm_type = DRM_FILE_TYPE_NONE;
277 drm_type = drm_svc_get_drm_type(file_full_path);
278 if (drm_type == DRM_FILE_TYPE_NONE) {
279 return MINFO_ITEM_NONE;
282 drm_content_info_t contentInfo = { 0 };
284 ret = drm_svc_get_content_info(file_full_path, &contentInfo);
285 if (ret != DRM_RESULT_SUCCESS) {
286 mb_svc_debug("drm_svc_get_content_info() fails. ");
287 return MINFO_ITEM_NONE;
290 strncpy(mimetype, contentInfo.contentType, sizeof(mimetype));
293 /* get content type and mime type from file. */
295 aul_get_mime_from_file(file_full_path, mimetype, sizeof(mimetype));
298 ("aul_get_mime_from_file fail.. Now trying to get type by extension");
300 char ext[MB_SVC_FILE_EXT_LEN_MAX + 1] = { 0 };
301 _mb_svc_get_file_ext(file_full_path, ext);
303 if (strcasecmp(ext, "JPG") == 0 ||
304 strcasecmp(ext, "JPEG") == 0 ||
305 strcasecmp(ext, "PNG") == 0 ||
306 strcasecmp(ext, "GIF") == 0 ||
307 strcasecmp(ext, "AGIF") == 0 ||
308 strcasecmp(ext, "XWD") == 0 ||
309 strcasecmp(ext, "BMP") == 0 ||
310 strcasecmp(ext, "TIF") == 0 ||
311 strcasecmp(ext, "TIFF") == 0 ||
312 strcasecmp(ext, "WBMP") == 0) {
313 return MINFO_ITEM_IMAGE;
314 } else if (strcasecmp(ext, "AVI") == 0 ||
315 strcasecmp(ext, "MPEG") == 0 ||
316 strcasecmp(ext, "MP4") == 0 ||
317 strcasecmp(ext, "DCF") == 0 ||
318 strcasecmp(ext, "WMV") == 0 ||
319 strcasecmp(ext, "ASF") == 0 ||
320 strcasecmp(ext, "DIVX") == 0 ||
321 strcasecmp(ext, "3GPP") == 0 ||
322 strcasecmp(ext, "3GP") == 0) {
323 return MINFO_ITEM_VIDEO;
325 return MINFO_ITEM_NONE;
330 mb_svc_debug("mime type : %s", mimetype);
332 /* categorize from mimetype */
333 if (strstr(mimetype, "image") != NULL) {
334 return MINFO_ITEM_IMAGE;
335 } else if (strstr(mimetype, "video") != NULL) {
336 return MINFO_ITEM_VIDEO;
339 return MINFO_ITEM_NONE;