From 2404744c02589b51db0d5ac9282f4d759ca32ed4 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Thu, 27 Oct 2016 15:57:33 +0900 Subject: [PATCH] Add some code for replace path Change-Id: I6c96f4bfccdf529b41d81c93c2860da01d3e1a61 Signed-off-by: Minje Ahn --- include/media_util_private.h | 1 + include_product/media_util_private.h | 1 + packaging/capi-content-media-content.spec | 2 +- src/media_filter.c | 7 +++- src/media_util_private.c | 55 +++++++++++++++++++++++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-) diff --git a/include/media_util_private.h b/include/media_util_private.h index d8c7666..9c01ce2 100755 --- a/include/media_util_private.h +++ b/include/media_util_private.h @@ -34,6 +34,7 @@ int _media_util_check_file_exist(const char *path); int _media_util_check_ignore_file(const char *path, bool *ignore); int _media_util_check_ignore_dir(const char *dir_path, bool *ignore); int _media_content_replace_path_in_condition(const char *condition, char *replace_condition); +int _media_content_rollback_path_in_condition(const char *condition, char *replace_condition); int _media_content_replace_path(const char *path, char *replace_path); int _media_content_rollback_path(const char *path, char *replace_path); diff --git a/include_product/media_util_private.h b/include_product/media_util_private.h index 1bfee05..b2ba51b 100755 --- a/include_product/media_util_private.h +++ b/include_product/media_util_private.h @@ -34,6 +34,7 @@ int _media_util_check_file_exist(const char *path); int _media_util_check_ignore_file(const char *path, bool *ignore); int _media_util_check_ignore_dir(const char *dir_path, bool *ignore); int _media_content_replace_path_in_condition(const char *condition, char *replace_condition); +int _media_content_rollback_path_in_condition(const char *condition, char *replace_condition); int _media_content_replace_path(const char *path, char *replace_path); int _media_content_rollback_path(const char *path, char *replace_path); diff --git a/packaging/capi-content-media-content.spec b/packaging/capi-content-media-content.spec index 7b390d8..e31f614 100755 --- a/packaging/capi-content-media-content.spec +++ b/packaging/capi-content-media-content.spec @@ -1,6 +1,6 @@ Name: capi-content-media-content Summary: A Media content library in Tizen Native API -Version: 0.2.87 +Version: 0.2.88 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/media_filter.c b/src/media_filter.c index 11e8d53..8428cdc 100755 --- a/src/media_filter.c +++ b/src/media_filter.c @@ -1027,7 +1027,12 @@ int media_filter_get_condition(filter_h filter, char **condition, media_content_ if (_filter) { if (STRING_VALID(_filter->condition)) { - *condition = strdup(_filter->condition); + char new_condition[MAX_QUERY_SIZE] = {0, }; + memset(new_condition, 0, MAX_QUERY_SIZE); + ret = _media_content_rollback_path_in_condition(_filter->condition, new_condition); + media_content_retvm_if(!STRING_VALID(new_condition), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); + + *condition = strdup(new_condition); media_content_retvm_if(*condition == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); } else { *condition = NULL; diff --git a/src/media_util_private.c b/src/media_util_private.c index 7adb130..9d6cb27 100755 --- a/src/media_util_private.c +++ b/src/media_util_private.c @@ -227,6 +227,61 @@ int _media_content_replace_path_in_condition(const char *condition, char *replac return MEDIA_CONTENT_ERROR_NONE; } +int _media_content_rollback_path_in_condition(const char *condition, char *replace_condition) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *old_path = NULL; + + ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &old_path); + if (ret != STORAGE_ERROR_NONE) { + media_content_error("storage_get_directory failed"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + + media_content_sec_debug("Old condition[%s]", condition); + if (((strstr(condition, "PATH") != NULL) || (strstr(condition, "path") != NULL)) && (strstr(condition, tzplatform_getenv(TZ_USER_CONTENT)) != NULL)) { + char *cond = strdup(condition); + char *repl_cond_ptr = replace_condition; + char *cond_ptr = cond; + + if (cond_ptr == NULL) { + SAFE_FREE(old_path); + media_content_error("memory allocation failed"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + while(*cond_ptr != '\0') { + if (strlen(cond_ptr) < strlen(tzplatform_getenv(TZ_USER_CONTENT))) { + memcpy(repl_cond_ptr, cond_ptr, strlen(cond_ptr)); + break; + } + /* replace path only and keep other condition */ + if (memcmp(cond_ptr, tzplatform_getenv(TZ_USER_CONTENT), strlen(tzplatform_getenv(TZ_USER_CONTENT))) == 0) { + memcpy(repl_cond_ptr, old_path, strlen(old_path)); + cond_ptr += strlen(tzplatform_getenv(TZ_USER_CONTENT)); + repl_cond_ptr += strlen(old_path); + } else { + *repl_cond_ptr = *cond_ptr; + cond_ptr++; + repl_cond_ptr++; + } + } + SAFE_FREE(cond); + } else { + snprintf(replace_condition, MAX_QUERY_SIZE, "%s", condition); + } + + SAFE_FREE(old_path); + + if (!STRING_VALID(replace_condition)) { + media_content_error("replace failed"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + + media_content_sec_debug("repl cond[%s]", replace_condition); + + return MEDIA_CONTENT_ERROR_NONE; +} + int _media_content_replace_path(const char *path, char *replace_path) { int ret = MEDIA_CONTENT_ERROR_NONE; -- 2.7.4