From 9c0688ff510a2d51302b5dcac8672055be9d5757 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Thu, 24 Nov 2016 12:23:35 +0900 Subject: [PATCH] Add user path to system session path Change-Id: I27b33c2f272a71945cb718fc33eed8fb73786ed2 Signed-off-by: Minje Ahn --- CMakeLists.txt | 2 +- packaging/capi-media-thumbnail-util.spec | 3 ++- src/thumbnail_util.c | 40 +++++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5dd6f4a..20e0513 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ SET(service "media") SET(submodule "thumbnail-util") # for package file -SET(dependents "dlog glib-2.0 capi-base-common media-thumbnail libmedia-utils") +SET(dependents "dlog glib-2.0 capi-base-common media-thumbnail libmedia-utils storage") SET(fw_name "${project_prefix}-${service}-${submodule}") PROJECT(${fw_name}) diff --git a/packaging/capi-media-thumbnail-util.spec b/packaging/capi-media-thumbnail-util.spec index 097070e..3329fbf 100755 --- a/packaging/capi-media-thumbnail-util.spec +++ b/packaging/capi-media-thumbnail-util.spec @@ -1,6 +1,6 @@ Name: capi-media-thumbnail-util Summary: A media thumbnail util library in Tizen Native API -Version: 0.1.4 +Version: 0.1.5 Release: 1 Group: Multimedia/API License: Apache-2.0 @@ -11,6 +11,7 @@ BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(libmedia-utils) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(media-thumbnail) +BuildRequires: pkgconfig(storage) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig diff --git a/src/thumbnail_util.c b/src/thumbnail_util.c index 8707fbc..e2fe74d 100755 --- a/src/thumbnail_util.c +++ b/src/thumbnail_util.c @@ -18,8 +18,38 @@ #include #include #include +#include #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; -- 2.7.4