int _content_query_sql(char *query_str);
sqlite3 * _content_get_db_handle(void);
uid_t _content_get_uid(void);
+bool _content_is_valid_path(const char *path);
+int _content_scan_filepath(const char *path);
int _media_info_get_media_info_from_db(const char *path, media_info_h media);
void _media_info_item_get_detail(sqlite3_stmt *stmt, media_info_h media);
int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count);
+++ /dev/null
-/*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-
-#ifndef __TIZEN_CONTENT_MEDIA_UTIL_PRIVATE_H__
-#define __TIZEN_CONTENT_MEDIA_UTIL_PRIVATE_H__
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-#include <stdbool.h>
-
-
-/**
- *@internal
- */
-int _media_util_check_file_exist(const char *path);
-int _media_util_get_file_time(const char *path);
-bool _media_util_is_ignorable_file(const char *path);
-bool _media_util_is_ignorable_dir(const char *dir_path);
-int _media_content_check_dir(const char *path);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*__TIZEN_CONTENT_MEDIA_UTIL_PRIVATE_H__*/
int _content_query_sql(char *query_str);
sqlite3 * _content_get_db_handle(void);
uid_t _content_get_uid(void);
+bool _content_is_valid_path(const char *path);
+int _content_scan_filepath(const char *path);
int _media_info_get_media_info_from_db(const char *path, media_info_h media);
void _media_info_item_get_detail(sqlite3_stmt *stmt, media_info_h media);
int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count);
+++ /dev/null
-/*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-
-#ifndef __TIZEN_CONTENT_MEDIA_UTIL_PRIVATE_H__
-#define __TIZEN_CONTENT_MEDIA_UTIL_PRIVATE_H__
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-#include <stdbool.h>
-
-
-/**
- *@internal
- */
-int _media_util_check_file_exist(const char *path);
-int _media_util_get_file_time(const char *path);
-bool _media_util_is_ignorable_file(const char *path);
-bool _media_util_is_ignorable_dir(const char *dir_path);
-int _media_content_check_dir(const char *path);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-#endif /*__TIZEN_CONTENT_MEDIA_UTIL_PRIVATE_H__*/
*/
#include <media_info_private.h>
-#include <media_util_private.h>
-#include <mntent.h>
#include <tzplatform_config.h>
+#ifdef _USE_TVPD_MODE
+#include <mntent.h>
+#endif
static sqlite3 *db_handle = NULL;
static int ref_count = 0;
return _content_error_capi(media_db_request_update_db(query_str, _content_get_uid()));
}
+bool _content_is_valid_path(const char *path)
+{
+ g_autofree gchar *real = NULL;
+ g_autofree gchar *org_path = NULL;
+#ifndef _USE_TVPD_MODE
+ char replace[MAX_PATH_LEN] = {0, };
+#endif
+ real = realpath(path, NULL);
+ org_path = g_canonicalize_filename(path, NULL);
+#ifndef _USE_TVPD_MODE
+ if (g_str_has_prefix(real, tzplatform_getenv(TZ_SYS_MEDIASHARED))) {
+ snprintf(replace, MAX_PATH_LEN, "%s%s", tzplatform_getenv(TZ_USER_MEDIASHARED), real + strlen(tzplatform_getenv(TZ_SYS_MEDIASHARED)));
+ g_free(real);
+ real = g_strdup(replace);
+ }
+#endif
+ content_retvm_if(g_strcmp0(real, org_path) != 0, false, "symbolic link(directory)");
+
+ return true;
+}
+
+int _content_scan_filepath(const char *path)
+{
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+
+ content_retip_if_fail(STRING_VALID(path));
+ content_retip_if_fail(!strstr(path, "/."));
+ content_retip_if_fail(ms_user_is_valid_path(_content_get_uid(), path));
+
+ content_sec_debug("Path : %s", path);
+
+ if (access(path, R_OK) == -1) {
+ content_retvm_if(errno == EACCES || errno == EPERM, MEDIA_CONTENT_ERROR_PERMISSION_DENIED, "permission denied");
+ if (errno == ENOENT) {
+ content_debug("No file. Try to delete from DB");
+ ret = media_svc_delete_item_by_path(_content_get_db_handle(), path, _content_get_uid());
+ content_retvm_if(ret == MS_MEDIA_ERR_DB_NO_RECORD, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
+ return _content_error_capi(ret);
+ }
+ content_stderror("access failed");
+ return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ }
+
+ content_retip_if_fail(_content_is_valid_path(path));
+
+ ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), path);
+ if (ret == MS_MEDIA_ERR_NONE) {
+ ret = media_svc_refresh_item(_content_get_db_handle(), false, path, _content_get_uid());
+ if (ret != MS_MEDIA_ERR_NONE) {
+ content_error("media_svc_refresh_item failed : %d", ret);
+ return _content_error_capi(ret);
+ }
+ } else if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
+ ret = media_svc_insert_item_immediately(_content_get_db_handle(), path, _content_get_uid());
+ if (ret != MS_MEDIA_ERR_NONE) {
+ if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
+ content_info("This item is already inserted. This may be normal operation because other process already did this");
+ ret = MEDIA_CONTENT_ERROR_NONE;
+ } else {
+ content_error("media_svc_insert_item_immediately failed : %d", ret);
+ }
+
+ return _content_error_capi(ret);
+ }
+ } else {
+ content_error("media_svc_get_modified_time failed : %d", ret);
+ return _content_error_capi(ret);
+ }
+
+ return MEDIA_CONTENT_ERROR_NONE;
+}
+
int media_content_connect(void)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
int media_content_scan_file(const char *path)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- g_autofree gchar *folder_path = NULL;
- char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,};
-
- content_retip_if_fail(STRING_VALID(path));
-
- content_sec_debug("Path : %s", path);
-
- content_retvm_if(_media_util_is_ignorable_file(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
-
- ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id, _content_get_uid());
- if (ret != MS_MEDIA_ERR_NONE) {
- content_error("media_svc_get_storage_id failed : %d", ret);
- return _content_error_capi(ret);
- }
-
- ret = _media_util_check_file_exist(path);
- content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission denied");
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- content_debug("No file. Try to delete from DB");
- ret = media_svc_delete_item_by_path(_content_get_db_handle(), path, _content_get_uid());
- content_retvm_if(ret == MS_MEDIA_ERR_DB_NO_RECORD, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
- return _content_error_capi(ret);
- }
-
- folder_path = g_path_get_dirname(path);
- content_retv_if(_media_util_is_ignorable_dir(folder_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-
- ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), path);
- if (ret == MS_MEDIA_ERR_NONE) {
- /* Refresh */
- ret = media_svc_refresh_item(_content_get_db_handle(), false, path, _content_get_uid());
- content_retvm_if(ret != MS_MEDIA_ERR_NONE, _content_error_capi(ret), "Refresh failed");
- return MEDIA_CONTENT_ERROR_NONE;
- }
-
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
- /* Insert */
- ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, path, _content_get_uid());
- content_retvm_if(ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL, MEDIA_CONTENT_ERROR_NONE, "[No error] Already inserted");
- content_retvm_if(ret != MS_MEDIA_ERR_NONE, _content_error_capi(ret), "Insertion failed");
- return MEDIA_CONTENT_ERROR_NONE;
- }
-
- content_error("media_svc_check_item_exist_by_path failed : %d", ret);
-
- return _content_error_capi(ret);
+ return _content_scan_filepath(path);
}
static void __media_content_scan_cb(media_request_result_s *result, void *user_data)
#endif
}
-int media_content_scan_folder(const char *path, bool is_recursive, media_scan_completed_cb callback, void *user_data)
+static int __media_content_verify_folderpath(const char *folderpath)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
- char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
+ content_retip_if_fail(STRING_VALID(folderpath));
+ content_retip_if_fail(!strstr(folderpath, "/."));
+ content_retip_if_fail(ms_user_is_valid_path(_content_get_uid(), folderpath));
- content_retip_if_fail(STRING_VALID(path));
- content_retip_if_fail(callback);
+ content_sec_debug("folder path : %s", folderpath);
- ret = _media_content_check_dir(path);
- content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission denied");
+ if (access(folderpath, R_OK | X_OK) == -1) {
+ content_retvm_if(errno == EACCES || errno == EPERM, MEDIA_CONTENT_ERROR_PERMISSION_DENIED, "permission denied");
+ content_retvm_if(errno == ENOENT, MEDIA_CONTENT_ERROR_NONE, "removed path");
+ content_stderror("access failed");
+ return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ }
- content_sec_debug("Path : %s", path);
+ content_retip_if_fail(_content_is_valid_path(folderpath));
- if (ret == MEDIA_CONTENT_ERROR_NONE) {
- /* If directory exist check that's ignore directory or not*/
- content_retvm_if(_media_util_is_ignorable_dir(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
- } else {
- /* This means this folder has to be deleted */
- /* Or, it is real invalid path.. check storage type */
- content_retvm_if(!ms_user_is_valid_path(_content_get_uid(), path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
+ return MEDIA_CONTENT_ERROR_NONE;
+}
- content_debug("No directory. Try to remove from DB");
- }
+int media_content_scan_folder(const char *path, bool is_recursive, media_scan_completed_cb callback, void *user_data)
+{
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
+
+ content_retip_if_fail(callback);
+ ret = __media_content_verify_folderpath(path);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id, _content_get_uid());
content_retvm_if(ret != MS_MEDIA_ERR_NONE, _content_error_capi(ret), "Failed to get storage id");
int ret = MEDIA_CONTENT_ERROR_NONE;
char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
- content_retip_if_fail(STRING_VALID(path));
content_retip_if_fail(callback);
-
- content_sec_debug("Path : %s", path);
+ ret = __media_content_verify_folderpath(path);
+ content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
content_retvm_if(!_is_mounted(path), MEDIA_CONTENT_ERROR_PERMISSION_DENIED, "path is not mounted");
- content_retvm_if(_media_util_is_ignorable_dir(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
-
- ret = _media_content_check_dir(path);
- content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission Denied");
- content_retvm_if(ret == MEDIA_CONTENT_ERROR_INVALID_PARAMETER, ret, "invalid path[%s]", path);
- media_content_scan_cb_data_v2* cb_data = NULL;
+ media_content_scan_cb_data_v2 *cb_data = NULL;
cb_data = g_new0(media_content_scan_cb_data_v2, 1);
cb_data->callback = callback;
#include <media_info.h>
#include <media_info_private.h>
-#include <media_util_private.h>
static int __media_info_check_file_validity(const char *path)
{
- g_autofree gchar *folder_path = NULL;
- int ret = MEDIA_CONTENT_ERROR_NONE;
-
content_retip_if_fail(path);
- content_retvm_if(_media_util_is_ignorable_file(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid ignore path");
+ content_retip_if_fail(!strstr(path, "/."));
+ content_retip_if_fail(ms_user_is_valid_path(_content_get_uid(), path));
- ret = _media_util_check_file_exist(path);
- content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "invalid path");
-
- folder_path = g_path_get_dirname(path);
- if (_media_util_is_ignorable_dir(folder_path))
+ if (access(path, R_OK) == -1) {
+ content_retvm_if(errno == EACCES || errno == EPERM, MEDIA_CONTENT_ERROR_PERMISSION_DENIED, "permission denied");
+ content_stderror("open file failed");
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ }
+
+ content_retip_if_fail(_content_is_valid_path(path));
return MEDIA_CONTENT_ERROR_NONE;
}
int media_info_insert_to_db(const char *path, media_info_h *info)
{
- char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
int ret = MEDIA_CONTENT_ERROR_NONE;
- int modified_time = 0;
- content_retip_if_fail(STRING_VALID(path));
content_retip_if_fail(info);
- content_sec_debug("path [%s]", path);
-
- ret = __media_info_check_file_validity(path);
+ ret = _content_scan_filepath(path);
content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
- ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id, _content_get_uid());
- if (ret != MS_MEDIA_ERR_NONE) {
- content_error("media_svc_get_storage_id failed : %d", ret);
- return _content_error_capi(ret);
- }
-
- /* Get modified time for check exists */
- ret = media_svc_get_modified_time(_content_get_db_handle(), path, &modified_time);
- if (ret == MS_MEDIA_ERR_NONE) {
- /* Refresh if need */
- if (modified_time != _media_util_get_file_time(path)) {
- ret = media_svc_refresh_item(_content_get_db_handle(), false, path, _content_get_uid());
- if (ret != MS_MEDIA_ERR_NONE) {
- content_error("media_svc_refresh_item failed : %d", ret);
- return _content_error_capi(ret);
- }
- }
- } else if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
- ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, path, _content_get_uid());
- if (ret != MS_MEDIA_ERR_NONE) {
- if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
- content_info("This item is already inserted. This may be normal operation because other process already did this");
- ret = MEDIA_CONTENT_ERROR_NONE;
- } else {
- content_error("media_svc_insert_item_immediately failed : %d", ret);
- }
-
- return _content_error_capi(ret);
- }
- } else {
- content_error("media_svc_get_modified_time failed : %d", ret);
- return _content_error_capi(ret);
- }
-
media_info_s *_media = g_new0(media_info_s, 1);
ret = _media_info_get_media_info_from_db(path, (media_info_h)_media);
int ret = MEDIA_CONTENT_ERROR_NONE;
media_info_s *_media = NULL;
- content_retip_if_fail(STRING_VALID(path));
content_retip_if_fail(media);
- ret = _media_util_check_file_exist(path);
- content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "_media_util_check_file_exist failed : %d", ret);
+ ret = __media_info_check_file_validity(path);
+ content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "invalid path : %d", ret);
_media = g_new0(media_info_s, 1);
ret = _media_info_get_media_info_from_db(path, (media_info_h)_media);
+++ /dev/null
-/*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-
-#include <dirent.h>
-#include <fcntl.h>
-#include <media_info_private.h>
-#include <sys/stat.h>
-
-int _media_util_check_file_exist(const char *path)
-{
- int fd = open(path, O_RDONLY);
- if (fd < 0) {
- content_retvm_if(errno == EACCES || errno == EPERM, MEDIA_CONTENT_ERROR_PERMISSION_DENIED, "permission denied");
- content_stderror("open file failed");
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
-
- close(fd);
-
- return MEDIA_CONTENT_ERROR_NONE;
-}
-
-int _media_util_get_file_time(const char *path)
-{
- struct stat statbuf = { 0, };
-
- content_retvm_if(stat(path, &statbuf) == -1, 0, "stat failed");
-
- return statbuf.st_mtime;
-}
-
-static bool __media_util_is_valid_path(const char *path)
-{
- g_autofree gchar *real = NULL;
- g_autofree gchar *org_path = NULL;
-#ifndef _USE_TVPD_MODE
- char replace[MAX_PATH_LEN] = {0, };
-#endif
- content_retv_if(!STRING_VALID(path), false);
-
- real = realpath(path, NULL);
- org_path = g_canonicalize_filename(path, NULL);
-
-#ifndef _USE_TVPD_MODE
- if (g_str_has_prefix(real, tzplatform_getenv(TZ_SYS_MEDIASHARED))) {
- snprintf(replace, MAX_PATH_LEN, "%s%s", tzplatform_getenv(TZ_USER_MEDIASHARED), real + strlen(tzplatform_getenv(TZ_SYS_MEDIASHARED)));
- g_free(real);
- real = g_strdup(replace);
- }
-#endif
- content_retvm_if(g_strcmp0(real, org_path) != 0, false, "symbolic link(directory)");
-
- return true;
-}
-
-bool _media_util_is_ignorable_file(const char *path)
-{
- content_retv_if(!STRING_VALID(path), true);
- content_retvm_if(!g_file_test(path, G_FILE_TEST_EXISTS), false, "[no error] removed path");
- content_retvm_if(g_file_test(path, G_FILE_TEST_IS_SYMLINK), true, "[no error] symbolic link(file)");
- content_retvm_if(strstr(path, "/."), true, "[no error] hidden path");
-
- return (!__media_util_is_valid_path(path));
-}
-
-bool _media_util_is_ignorable_dir(const char *dir_path)
-{
- content_retv_if(!STRING_VALID(dir_path), true);
- content_retvm_if(strstr(dir_path, "/."), true, "hidden path");
- content_retvm_if(!ms_user_is_valid_path(_content_get_uid(), dir_path), true, "ms_user_is_valid_path failed");
-
- return false;
-}
-
-int _media_content_check_dir(const char *path)
-{
- DIR *d = opendir(path);
- if (!d) {
- content_retvm_if(errno == EACCES, MEDIA_CONTENT_ERROR_PERMISSION_DENIED, "permission denied");
- content_stderror("opendir failed");
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
-
- closedir(d);
-
- content_retv_if(!__media_util_is_valid_path(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
-
- return MEDIA_CONTENT_ERROR_NONE;
-}