Add to replace path in condition 06/89106/5 accepted/tizen/common/20160922.120955 accepted/tizen/ivi/20160923.090021 accepted/tizen/mobile/20160923.085927 accepted/tizen/tv/20160923.085947 accepted/tizen/wearable/20160923.090004 submit/tizen/20160922.083937
authorJiyong Min <jiyong.min@samsung.com>
Thu, 22 Sep 2016 07:31:43 +0000 (16:31 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Thu, 22 Sep 2016 08:13:49 +0000 (17:13 +0900)
 - PROBLEM
The query of application did not work properly.

[solution] Add to replace path from storage path to platform path in condition

Change-Id: If6c6847ea7664990f3857661148badc8299695ff
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
include/media_util_private.h
include_product/media_util_private.h
packaging/capi-content-media-content.spec
src/media_filter.c
src/media_util_private.c

index f941f7d..d8c7666 100755 (executable)
@@ -33,6 +33,7 @@ extern "C" {
 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_replace_path(const char *path, char *replace_path);
 int _media_content_rollback_path(const char *path, char *replace_path);
 
index 0044de1..1bfee05 100755 (executable)
@@ -33,6 +33,7 @@ extern "C" {
 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_replace_path(const char *path, char *replace_path);
 int _media_content_rollback_path(const char *path, char *replace_path);
 
index 8c2ba3a..02005f7 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-content-media-content
 Summary:    A Media content library in Tizen Native API
-Version:    0.2.83
+Version:    0.2.84
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 93609ff..11e8d53 100755 (executable)
@@ -16,6 +16,7 @@
 
 
 #include <media_info_private.h>
+#include <media_util_private.h>
 #include <vconf.h>
 
 static const char *media_token[] = {
@@ -935,7 +936,12 @@ int media_filter_set_condition(filter_h filter, const char *condition, media_con
                if (STRING_VALID(_filter->condition))
                        SAFE_FREE(_filter->condition);
 
-               _filter->condition = strdup(condition);
+               char new_condition[MAX_QUERY_SIZE] = {0, };
+               memset(new_condition, 0, MAX_QUERY_SIZE);
+               ret = _media_content_replace_path_in_condition(condition, new_condition);
+               media_content_retvm_if(!STRING_VALID(new_condition), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
+
+               _filter->condition = strdup(new_condition);
                media_content_retvm_if(_filter->condition == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
 
                media_content_sec_debug("Condition string : %s", _filter->condition);
index fa7b5c3..7adb130 100755 (executable)
@@ -172,6 +172,61 @@ int _media_util_check_ignore_dir(const char *dir_path, bool *ignore)
        return MEDIA_CONTENT_ERROR_NONE;
 }
 
+int _media_content_replace_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, old_path) != 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(old_path)) {
+                               memcpy(repl_cond_ptr, cond_ptr, strlen(cond_ptr));
+                               break;
+                       }
+                       /* replace path only and keep other condition */
+                       if (memcmp(cond_ptr, old_path, strlen(old_path)) == 0) {
+                               memcpy(repl_cond_ptr, tzplatform_getenv(TZ_USER_CONTENT), strlen(tzplatform_getenv(TZ_USER_CONTENT)));
+                               cond_ptr += strlen(old_path);
+                               repl_cond_ptr += strlen(tzplatform_getenv(TZ_USER_CONTENT));
+                       } 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;