Use Common API in libmedia-util to get User path 39/129939/1 submit/tizen/20170519.020113
authorHaejeong Kim <backto.kim@samsung.com>
Thu, 18 May 2017 11:23:59 +0000 (20:23 +0900)
committerHaejeong Kim <backto.kim@samsung.com>
Thu, 18 May 2017 11:23:59 +0000 (20:23 +0900)
Change-Id: I5c47f85fc06599b9fe39c3020b7f38afd2852ccb

CMakeLists.txt
packaging/libmedia-service.spec
src/common/media-svc-db-utils.c
src/common/media-svc-media-folder.c
src/common/media-svc-storage.c
src/common/media-svc-util.c
src/common/media-svc.c
src/include/common/media-svc-db-utils.h
src/include/common/media-svc-util.h

index d71de32..fb3aa19 100755 (executable)
@@ -61,7 +61,7 @@ FOREACH(flag ${pkgs_CFLAGS})
        SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
 ENDFOREACH(flag)
 
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror -Wno-deprecated-declarations")
 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
 SET(CMAKE_C_FLAGS_RELEASE "-O2 -fPIC")
 
index 632f9ee..4462d87 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmedia-service
 Summary:    Media information service library for multimedia applications
-Version: 0.3.2
+Version: 0.3.3
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0 and PD
index 739f61a..7a5dfa6 100755 (executable)
@@ -39,24 +39,6 @@ static int __media_svc_rebuild_view_query(sqlite3 *db_handle, uid_t uid);
 static GHashTable *table;
 static GSList *column_list[MEDIA_SVC_DB_LIST_MAX];
 
-char *_media_svc_get_path(uid_t uid)
-{
-       int ret = 0;
-       char *result_path = NULL;
-
-       ret = tzplatform_set_user(uid);
-       if (ret != 0) {
-               media_svc_error("Invalid UID[%d]", uid);
-               return NULL;
-       } else {
-               const char *result = tzplatform_getenv(TZ_USER_CONTENT);
-               result_path = strndup(result, strlen(result));
-               tzplatform_reset_user();
-       }
-
-       return result_path;
-}
-
 int __media_svc_add_table_info(const char *name, const char *trigger_name, const char *event_table, const char *action_table, const char *view_name)
 {
        table_info_s *tbl = NULL;
index a863996..e00719f 100755 (executable)
@@ -40,7 +40,11 @@ static int __media_svc_is_root_path(const char *folder_path, bool *is_root, uid_
        int i = 0;
        int start_len = 0;
        int path_len = 0;
-       char *internal_path = _media_svc_get_path(uid);
+       char *internal_path = NULL;
+       int ret = MS_MEDIA_ERR_NONE;
+
+       ret = ms_user_get_internal_root_path(uid, &internal_path);
+       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get root path");
 
        if (STRING_VALID(internal_path) && (strcmp(folder_path, internal_path) == 0)) {
                media_svc_debug("ROOT PATH [%s]", folder_path);
@@ -249,7 +253,8 @@ static int __media_svc_get_and_append_parent_folder(sqlite3 *handle, const char
        char *internal_path = NULL;
 
        memset(parent_folder_uuid, 0, sizeof(parent_folder_uuid));
-       internal_path = _media_svc_get_path(uid);
+       ret = ms_user_get_internal_root_path(uid, &internal_path);
+       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get root path");
 
        if (STRING_VALID(internal_path) && (strncmp(path, internal_path, strlen(internal_path)) == 0))
                next_pos = strlen(internal_path);
index c4d4b4b..33c7abb 100755 (executable)
@@ -42,7 +42,10 @@ int _media_svc_init_storage(sqlite3 *handle, uid_t uid)
        SQLITE3_FINALIZE(sql_stmt);
 
        if (storage_cnt == 0) {
-               char *internal_path = _media_svc_get_path(uid);
+               char *internal_path = NULL;
+               ret = ms_user_get_internal_root_path(uid, &internal_path);
+               media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get root path");
+
                sql = sqlite3_mprintf("INSERT INTO %s (storage_uuid, storage_name, storage_path, storage_type) VALUES ('%s', '%s', '%s', 0);",
                                                MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_MEDIA, internal_path);
 
@@ -228,7 +231,8 @@ int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage
        int remain_len = 0;
        char *internal_path = NULL;
 
-       internal_path = _media_svc_get_path(uid);
+       ret = ms_user_get_internal_root_path(uid, &internal_path);
+       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get root path");
 
        if (STRING_VALID(internal_path) && strncmp(path, internal_path, strlen(internal_path)) == 0) {
                _strncpy_safe(storage_id, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_UUID_SIZE+1);
index 6ae5d0e..e40b711 100755 (executable)
@@ -577,24 +577,6 @@ static int __media_svc_get_location_value(MMHandleType tag, double *longitude, d
        return MS_MEDIA_ERR_NONE;
 }
 
-static char *__media_svc_get_thumb_path(uid_t uid)
-{
-       int ret = 0;
-       char *result_path = NULL;
-
-       ret = tzplatform_set_user(uid);
-       if (ret != 0) {
-               media_svc_error("Invalid UID[%d]", uid);
-               return NULL;
-       } else {
-               const char *result = tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb");
-               result_path = strndup(result, strlen(result));
-               tzplatform_reset_user();
-       }
-
-       return result_path;
-}
-
 static int __media_svc_encode_jpeg(unsigned char *src, unsigned long width, unsigned long height, image_util_colorspace_e colorspace, int quality, unsigned char **dst, unsigned long long *dst_size)
 {
        int res = IMAGE_UTIL_ERROR_NONE;
@@ -833,6 +815,8 @@ static int __media_svc_safe_atoi(char *buffer, int *si)
 
 static int _media_svc_save_image(unsigned char *image, unsigned int size, char *image_path, uid_t uid)
 {
+       int ret = MS_MEDIA_ERR_NONE;
+
        media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
 
        if (!image) {
@@ -841,11 +825,9 @@ static int _media_svc_save_image(unsigned char *image, unsigned int size, char *
        }
 
        struct statfs fs;
-       char *thumb_path = __media_svc_get_thumb_path(uid);
-       if (!STRING_VALID(thumb_path)) {
-               media_svc_error("fail to get thumb_path");
-               return MS_MEDIA_ERR_INTERNAL;
-       }
+       char *thumb_path = NULL;
+       ret = ms_user_get_root_thumb_store_path(uid, &thumb_path);
+       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_root_thumb_store_path fail");
 
        if (-1 == statfs(thumb_path, &fs)) {
                media_svc_error("error in statfs");
@@ -859,7 +841,7 @@ static int _media_svc_save_image(unsigned char *image, unsigned int size, char *
 
        if ((bsize_kbytes * fs.f_bavail) < 1024) {
                media_svc_error("not enought space...");
-               return MS_MEDIA_ERR_INTERNAL;
+               return MS_MEDIA_ERR_NOT_ENOUGH_SPACE;
        }
 
        FILE *fp = NULL;
@@ -997,42 +979,6 @@ int _media_svc_remove_all_files_in_dir(const char *dir_path)
        return MS_MEDIA_ERR_NONE;
 }
 
-char *_media_svc_get_thumb_internal_path(uid_t uid)
-{
-       int ret = 0;
-       char *result_path = NULL;
-
-       ret = tzplatform_set_user(uid);
-       if (ret != 0) {
-               media_svc_error("Invalid UID[%d]", uid);
-               return NULL;
-       } else {
-               const char *result = tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb/phone");
-               result_path = strndup(result, strlen(result));
-               tzplatform_reset_user();
-       }
-
-       return result_path;
-}
-
-char *_media_svc_get_thumb_external_path(uid_t uid)
-{
-       int ret = 0;
-       char *result_path = NULL;
-
-       ret = tzplatform_set_user(uid);
-       if (ret != 0) {
-               media_svc_error("Invalid UID[%d]", uid);
-               return NULL;
-       } else {
-               const char *result = tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb/mmc");
-               result_path = strndup(result, strlen(result));
-               tzplatform_reset_user();
-       }
-
-       return result_path;
-}
-
 static int __media_svc_check_thumb_dir(const char *thumb_dir)
 {
        DIR *dir = NULL;
@@ -1054,8 +1000,11 @@ int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *t
        char *thumb_dir = NULL;
        char hash[255 + 1] = {0, };
        char *thumbfile_ext = NULL;
-       char *internal_thumb_path = _media_svc_get_thumb_internal_path(uid);
-       char *external_thumb_path = _media_svc_get_thumb_external_path(uid);
+       char *internal_thumb_path = NULL;
+       char *external_thumb_path = NULL;
+
+       ret = ms_user_get_default_thumb_store_path(uid, &internal_thumb_path);
+       ret = ms_user_get_mmc_thumb_store_path(uid, &external_thumb_path);
 
        if (!STRING_VALID(internal_thumb_path) || !STRING_VALID(external_thumb_path)) {
                media_svc_error("fail to get thumbnail path");
@@ -2319,33 +2268,6 @@ void _media_svc_destroy_content_info(media_svc_content_info_s *content_info)
        return;
 }
 
-int _media_svc_get_storage_type_by_path(const char *path, media_svc_storage_type_e *storage_type, uid_t uid)
-{
-       if (STRING_VALID(path)) {
-               char *internal_path = _media_svc_get_path(uid);
-               if (STRING_VALID(internal_path) && (strncmp(path, internal_path, strlen(internal_path)) == 0)) {
-                       *storage_type = MEDIA_SVC_STORAGE_INTERNAL;
-               } else if (STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)) {
-                       *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
-               } else if (STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0)) {
-                       *storage_type = MEDIA_SVC_STORAGE_EXTERNAL_USB;
-               } else if (STRING_VALID(MEDIA_ROOT_PATH_DISC) && (strncmp(path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0)) {
-                       *storage_type = MEDIA_SVC_STORAGE_EXTERNAL;
-               } else {
-                       media_svc_error("Invalid Path");
-                       media_svc_sec_error("Invalid Path [%s], internal_path [%s]", path, internal_path);
-                       SAFE_FREE(internal_path);
-                       return MS_MEDIA_ERR_INVALID_PARAMETER;
-               }
-               SAFE_FREE(internal_path);
-       } else {
-               media_svc_error("INVALID parameter");
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
-
-       return MS_MEDIA_ERR_NONE;
-}
-
 char *_media_svc_replace_path(char *s, const char *olds, const char *news)
 {
        char result[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
index a344ad5..1aac544 100755 (executable)
@@ -249,10 +249,10 @@ ERROR:
 int media_svc_get_storage_type(const char *path, media_svc_storage_type_e *storage_type, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
-       media_svc_storage_type_e type;
+       ms_user_storage_type_t type = -1;
 
-       ret = _media_svc_get_storage_type_by_path(path, &type, uid);
-       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_storage_type_by_path failed : %d", ret);
+       ret = ms_user_get_storage_type(uid, path, &type);
+       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "ms_user_get_storage_type failed : %d", ret);
 
        *storage_type = type;
 
@@ -823,9 +823,18 @@ int media_svc_delete_all_items_in_storage(const char *storage_id, media_svc_stor
        media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
 
        if (storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB) {
-               char *internal_thumb_path = _media_svc_get_thumb_internal_path(uid);
-               char *external_thumb_path = _media_svc_get_thumb_external_path(uid);
+               char *internal_thumb_path = NULL;
+               char *external_thumb_path = NULL;
 
+               ret = ms_user_get_default_thumb_store_path(uid, &internal_thumb_path);
+               ret = ms_user_get_mmc_thumb_store_path(uid, &external_thumb_path);
+
+               if (!STRING_VALID(internal_thumb_path) || !STRING_VALID(external_thumb_path)) {
+                       media_svc_error("fail to get thumbnail path");
+                       SAFE_FREE(internal_thumb_path);
+                       SAFE_FREE(external_thumb_path);
+                       return MS_MEDIA_ERR_INTERNAL;
+               }
                const char *dirpath = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? internal_thumb_path : external_thumb_path;
 
                /* remove thumbnails */
@@ -1079,7 +1088,7 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
                }
 
                media_svc_debug("New media path : %s", replaced_path);
-               media_svc_storage_type_e storage_type;
+               ms_user_storage_type_t storage_type = -1;
 
                if (!no_thumb) {
                        /* If old thumb path is default or not */
@@ -1087,9 +1096,9 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons
                        if (STRING_VALID(default_thumbnail_path) && (strncmp(media_thumb_path, default_thumbnail_path, strlen(default_thumbnail_path)) == 0)) {
                                _strncpy_safe(media_new_thumb_path, default_thumbnail_path, sizeof(media_new_thumb_path));
                        } else {
-                               ret = _media_svc_get_storage_type_by_path(replaced_path, &storage_type, uid);
+                               ret = ms_user_get_storage_type(uid, replaced_path, &storage_type);
                                if (ret != MS_MEDIA_ERR_NONE) {
-                                       media_svc_error("_media_svc_get_storage_type_by_path failed : %d", ret);
+                                       media_svc_sec_error("ms_user_get_storage_type failed : [%d], path[%s] storage_type[%d]", ret, replaced_path, storage_type);
                                        SAFE_FREE(replaced_path);
                                        SAFE_FREE(default_thumbnail_path);
                                        _media_svc_sql_rollback_trans(uid);
@@ -1819,7 +1828,7 @@ int media_svc_delete_storage(MediaSvcHandle *handle, const char *storage_id, con
        media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
 
        ret = _media_svc_get_storage_type(db_handle, storage_id, &storage_type);
-       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_storage_type_by_path failed : %d", ret);
+       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_get_storage_type failed : %d", ret);
 
        ret = _media_svc_delete_storage(storage_id, storage_name, uid);
        media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "remove storage failed : %d", ret);
index 44af1dc..74fdc99 100755 (executable)
@@ -48,7 +48,5 @@ void _media_svc_sql_query_add(GList **query_list, char **query);
 void _media_svc_sql_query_release(GList **query_list);
 int _media_svc_check_db_upgrade(sqlite3 *db_handle, int user_version, uid_t uid);
 int _media_db_check_corrupt(sqlite3 *db_handle);
-char *_media_svc_get_path(uid_t uid);
-
 
 #endif /*_MEDIA_SVC_DB_UTILS_H_*/
index f3e195c..922930a 100755 (executable)
@@ -63,10 +63,7 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s
 int __media_svc_malloc_and_strncpy(char **dst, const char *src);
 time_t __media_svc_get_timeline_from_str(const char *timstr);
 void _media_svc_destroy_content_info(media_svc_content_info_s *content_info);
-int _media_svc_get_storage_type_by_path(const char *path, media_svc_storage_type_e *storage_type, uid_t uid);
 char *_media_svc_replace_path(char *s, const char *olds, const char *news);
-char *_media_svc_get_thumb_internal_path(uid_t uid);
-char *_media_svc_get_thumb_external_path(uid_t uid);
 bool _media_svc_is_drm_file(const char *path);
 int _media_svc_request_thumbnail_with_origin_size(const char *path, char *thumb_path, int max_length, int *origin_width, int *origin_height, uid_t uid);
 int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str);