Add user path to system session path
[platform/core/api/thumbnail-util.git] / src / thumbnail_util.c
index 8707fbc..e2fe74d 100755 (executable)
 #include <media-util.h>
 #include <thumbnail_util.h>
 #include <thumbnail_util_private.h>
+#include <storage.h>
 
 #define MAX_SIZE 16
+#define MAX_PATH_SIZE 4096
+
+int __thumbnail_util_replace_path(const char *path, char *replace_path)
+{
+       int ret = THUMBNAIL_UTIL_ERROR_NONE;
+       char *old_path = NULL;
+
+       ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &old_path);
+       if (ret != STORAGE_ERROR_NONE) {
+               thumbnail_util_error("storage_get_directory failed");
+               return THUMBNAIL_UTIL_ERROR_INVALID_OPERATION;
+       }
+
+       if (strncmp(path, old_path, strlen(old_path)) == 0) {
+               thumbnail_util_sec_debug("Old path[%s]", path);
+               snprintf(replace_path, MAX_PATH_SIZE, "%s%s", tzplatform_getenv(TZ_USER_CONTENT), path + strlen(old_path));
+       } else {
+               snprintf(replace_path, MAX_PATH_SIZE, "%s", path);
+       }
+
+       SAFE_FREE(old_path);
+
+       if (!STRING_VALID(replace_path)) {
+               thumbnail_util_error("replace failed");
+               return THUMBNAIL_UTIL_ERROR_INVALID_OPERATION;
+       }
+
+       return THUMBNAIL_UTIL_ERROR_NONE;
+}
 
 int __thumbnail_util_error_capi(int content_error)
 {
@@ -133,11 +163,19 @@ int thumbnail_util_extract(thumbnail_h thumb, thumbnail_extracted_cb callback, v
 int thumbnail_util_set_path(thumbnail_h thumb, const char *path)
 {
        int ret = THUMBNAIL_UTIL_ERROR_NONE;
+       char repl_path[MAX_PATH_SIZE + 1] = {0, };
        thumbnail_s *_thumb = (thumbnail_s *)thumb;
 
        if (_thumb != NULL && path != NULL) {
                SAFE_FREE(_thumb->file_path);
-               _thumb->file_path = strndup(path, strlen(path));
+               memset(repl_path, 0, sizeof(repl_path));
+               ret = __thumbnail_util_replace_path(path, repl_path);
+               if (ret != THUMBNAIL_UTIL_ERROR_NONE) {
+                       thumbnail_util_error("Convert path failed");
+                       _thumb->file_path = NULL;
+               } else {
+                       _thumb->file_path = strndup(repl_path, strlen(repl_path));
+               }
        } else {
                thumbnail_util_error("INVALID_PARAMETER(0x%08x)", THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER);
                ret = THUMBNAIL_UTIL_ERROR_INVALID_PARAMETER;