2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <sys/types.h>
22 #include <media_util_private.h>
23 #include <media_info_private.h>
24 #include <media_content_type.h>
25 #ifdef _USE_TV_PROFILE
26 #include <system_info.h>
29 int _media_util_check_file_exist(const char *path)
33 /* check the file exits actually */
34 exist = open(path, O_RDONLY);
36 media_content_sec_debug("path [%s]", path);
37 media_content_stderror("open file fail");
38 if (errno == EACCES || errno == EPERM)
39 return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
41 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
46 return MEDIA_CONTENT_ERROR_NONE;
49 int _media_util_check_ignore_file(const char *path, bool *ignore)
51 media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path");
55 if (strstr(path, "/.") != NULL) {
57 media_content_error("hidden path");
58 media_content_sec_debug("path : %s", path);
61 return MEDIA_CONTENT_ERROR_NONE;
64 int _media_util_check_ignore_dir(const char *dir_path, bool *ignore)
66 int ret = MEDIA_CONTENT_ERROR_NONE;
67 media_svc_storage_type_e storage_type = 0;
68 const char *scan_ignore = ".scan_ignore";
71 media_content_sec_debug("dir_path : %s", dir_path);
73 media_content_retvm_if(!STRING_VALID(dir_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid dir_path");
76 /*1. Check Hidden Directory*/
77 if (strstr(dir_path, "/.") != NULL) {
79 media_content_error("hidden path");
80 return MEDIA_CONTENT_ERROR_NONE;
83 /*2. Check Scan Ignore Directory*/
84 ret = media_svc_get_storage_type(dir_path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
85 if (ret != MS_MEDIA_ERR_NONE) {
86 media_content_error("media_svc_get_storage_type failed : %d", ret);
87 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
92 struct dirent *result = NULL;
94 char *leaf_path = NULL;
95 char search_path[4096] = {0, };
97 strncpy(search_path, dir_path, strlen(dir_path));
98 while (STRING_VALID(search_path)) {
99 dp = opendir(search_path);
102 media_content_error("Open Directory fail");
103 media_content_sec_debug("Open fail path[%s]", search_path);
104 if (errno == EACCES || errno == EPERM)
105 return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
107 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
110 media_content_retvm_if(dp == NULL, MEDIA_CONTENT_ERROR_INVALID_OPERATION, "Open Directory fail");
112 while (!readdir_r(dp, &entry, &result)) {
116 if (STRING_VALID(entry.d_name) && (strcmp(entry.d_name, scan_ignore) == 0)) {
117 media_content_error("Find Ignore path");
118 media_content_sec_debug("Ignore path[%s]", search_path);
122 /*media_content_sec_debug("entry.d_name[%s]", entry.d_name);*/
127 if (dp) closedir(dp);
134 /*If root path, Stop Scanning*/
135 if ((storage_type == MEDIA_SVC_STORAGE_INTERNAL) && (STRING_VALID(MEDIA_ROOT_PATH_INTERNAL) && strcmp(search_path, MEDIA_ROOT_PATH_INTERNAL) == 0)) {
137 } else if ((storage_type == MEDIA_SVC_STORAGE_EXTERNAL) && (STRING_VALID(MEDIA_ROOT_PATH_SDCARD)) && (strcmp(search_path, MEDIA_ROOT_PATH_SDCARD) == 0)) {
139 } else if (storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB) {
140 char *parent_folder_path = NULL;
141 bool is_root = FALSE;
143 parent_folder_path = g_path_get_dirname(search_path);
144 if (STRING_VALID(MEDIA_ROOT_PATH_USB) && (strcmp(parent_folder_path, MEDIA_ROOT_PATH_USB) == 0))
147 SAFE_FREE(parent_folder_path);
152 #ifdef _USE_SENIOR_MODE
153 if (_media_content_is_support_senior_mode()) {
154 if ((storage_type == MEDIA_SVC_STORAGE_EXTERNAL) && (strcmp(search_path, MEDIA_ROOT_PATH_SENIOR_MODE) == 0))
159 leaf_path = strrchr(search_path, '/');
160 if (leaf_path != NULL) {
161 int seek_len = leaf_path -search_path;
162 search_path[seek_len] = '\0';
163 /*media_content_sec_debug("go to other dir [%s]", search_path);*/
165 media_content_debug("Fail to find leaf path");
171 return MEDIA_CONTENT_ERROR_NONE;
174 int _media_content_replace_path(const char *path, char *replace_path)
176 const char *old_path = "/opt/usr/media";
178 if (strncmp(path, old_path, strlen(old_path)) == 0) {
179 media_content_sec_debug("Old path[%s]", path);
180 snprintf(replace_path, MAX_QUERY_SIZE, "%s%s", tzplatform_getenv(TZ_USER_CONTENT), path + strlen(old_path));
182 snprintf(replace_path, MAX_QUERY_SIZE, "%s", path);
185 if (!STRING_VALID(replace_path)) {
186 media_content_error("replace failed");
187 return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
190 return MEDIA_CONTENT_ERROR_NONE;
193 #ifdef _USE_SENIOR_MODE
194 bool _media_content_is_support_senior_mode()
196 bool bSupportSeniorMode = false;
198 if (system_info_get_value_bool(SYSTEM_INFO_KEY_GET_SENIOR_MODE_SUPPORTED, &bSupportSeniorMode) != SYSTEM_INFO_ERROR_NONE) {
199 media_content_debug("Get senior mode support failed");
202 /* media_content_debug("Senior mode Support : [%d]", bSupportSeniorMode); */
203 return bSupportSeniorMode;