Code cleanup 57/272757/4 accepted/tizen/unified/20220328.131526 submit/tizen/20220327.230612
authorMinje Ahn <minje.ahn@samsung.com>
Thu, 24 Mar 2022 00:44:55 +0000 (09:44 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Thu, 24 Mar 2022 07:44:49 +0000 (16:44 +0900)
Change-Id: Ie013a7e07866b2b1b345d9f50756c0b6bd505119
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
lib/media-util-user.c
packaging/media-server.spec

index dc6342d..b473dcc 100755 (executable)
@@ -25,6 +25,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
+#define USER_BAND 5000;
+
 static GMutex tzplatform_mutex;
 
 typedef enum {
@@ -40,26 +42,23 @@ static int __ms_user_get_path(ms_user_path_type_e type, uid_t uid, char **path)
        int ret = MS_MEDIA_ERR_NONE;
        const char *result = NULL;
        struct tzplatform_context *context[128];
-       int idx = 0;
+       int idx = uid - USER_BAND;
+       g_autoptr(GMutexLocker) locker = NULL;
 
-       idx = uid - 5000;
        MSAPI_RETVM_IF(idx < 0 || idx > 127, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid uid");
        MSAPI_RETVM_IF(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
 
-       g_mutex_lock(&tzplatform_mutex);
+       locker = g_mutex_locker_new(&tzplatform_mutex);
 
-       ret = tzplatform_context_create(&context[idx]);
-       if (ret != 0) {
+       if (tzplatform_context_create(&context[idx]) != 0) {
                MSAPI_DBG_ERR("Fail tzplatform_context_create");
-               ret = MS_MEDIA_ERR_INTERNAL;
-               goto ERROR;
+               return MS_MEDIA_ERR_INTERNAL;
        }
 
-       ret = tzplatform_context_set_user(context[idx], uid);
-       if (ret != 0) {
+       if (tzplatform_context_set_user(context[idx], uid) != 0) {
                MSAPI_DBG_ERR("Fail tzplatform_context_set_user");
-               ret = MS_MEDIA_ERR_INTERNAL;
-               goto ERROR;
+               tzplatform_context_destroy(context[idx]);
+               return MS_MEDIA_ERR_INTERNAL;
        }
 
        switch (type) {
@@ -81,61 +80,45 @@ static int __ms_user_get_path(ms_user_path_type_e type, uid_t uid, char **path)
                break;
 #endif
        default:
-               MSAPI_DBG_ERR("Invalid type");
                ret = MS_MEDIA_ERR_INTERNAL;
                break;
        }
 
-       if (MS_STRING_VALID(result)) {
-               *path = g_strdup(result);
-       } else {
-               MSAPI_DBG_ERR("Fail to get the path");
-               ret = MS_MEDIA_ERR_INTERNAL;
-       }
-
-ERROR:
        tzplatform_context_destroy(context[idx]);
 
-       g_mutex_unlock(&tzplatform_mutex);
+       MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Invalid type");
+       MSAPI_RETVM_IF(!MS_STRING_VALID(result), MS_MEDIA_ERR_INTERNAL, "Fail to get the path");
+
+       *path = g_strdup(result);
 
        return ret;
 }
 
 int ms_user_get_internal_root_path(uid_t uid, char **path)
 {
-       int ret = MS_MEDIA_ERR_NONE;
-
-       if (uid == getuid())
-               *path = g_strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
-       else
-               ret = __ms_user_get_path(INTERNAL_ROOT, uid, path);
+       if (uid != getuid())
+               return __ms_user_get_path(INTERNAL_ROOT, uid, path);
 
-       //MSAPI_DBG_SLOG("internal root path [%s]", *path);
+       *path = g_strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
 
-       return ret;
+       return MS_MEDIA_ERR_NONE;
 }
 
 int ms_user_get_storage_type(uid_t uid, const char *path, ms_user_storage_type_e *storage_type)
 {
        int ret = MS_MEDIA_ERR_NONE;
        char *internal_path = NULL;
-       int path_len = 0;
 
-       if (!MS_STRING_VALID(path)) {
-               MSAPI_DBG_ERR("Invalid path");
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
+       MSAPI_RETVM_IF(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
 
        ret = ms_user_get_internal_root_path(uid, &internal_path);
-       MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail get internal root path");
-
-       path_len = strlen(internal_path);
+       MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get internal root path");
 
-       if (strncmp(path, internal_path, path_len) == 0) {
+       if (g_str_has_prefix(path, internal_path)) {
                *storage_type = MS_USER_STORAGE_INTERNAL;
-       } else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)) {
+       } else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && g_str_has_prefix(path, MEDIA_ROOT_PATH_SDCARD)) {
                *storage_type = MS_USER_STORAGE_EXTERNAL;
-       } else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0)) {
+       } else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && g_str_has_prefix(path, MEDIA_ROOT_PATH_USB)) {
                *storage_type = MS_USER_STORAGE_EXTERNAL_USB;
        } else {
                MSAPI_DBG_ERR("[%s][%s][%s]", MEDIA_ROOT_PATH_SDCARD, MEDIA_ROOT_PATH_USB, path);
@@ -149,58 +132,42 @@ int ms_user_get_storage_type(uid_t uid, const char *path, ms_user_storage_type_e
 
 int ms_user_get_root_thumb_store_path(uid_t uid, char **path)
 {
-       int ret = MS_MEDIA_ERR_NONE;
-
-       if (uid == getuid())
-               *path = g_strdup(tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb"));
-       else
-               ret = __ms_user_get_path(THUMB_ROOT, uid, path);
+       if (uid != getuid())
+               return __ms_user_get_path(THUMB_ROOT, uid, path);
 
-       //MSAPI_DBG_SLOG("thumb path [%s]", *path);
+       *path = g_strdup(tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb"));
 
-       return ret;
+       return MS_MEDIA_ERR_NONE;
 }
 
 int ms_user_get_media_db_path(uid_t uid, char **path)
 {
-       int ret = MS_MEDIA_ERR_NONE;
+       if (uid != getuid())
+               return __ms_user_get_path(MEDIA_DB, uid, path);
 
-       if (uid == getuid())
-               *path = g_strdup(tzplatform_mkpath(TZ_USER_DB, ".media.db"));
-       else
-               ret = __ms_user_get_path(MEDIA_DB, uid, path);
+       *path = g_strdup(tzplatform_mkpath(TZ_USER_DB, ".media.db"));
 
-       //MSAPI_DBG_SLOG("DB path [%s]", *path);
-
-       return ret;
+       return MS_MEDIA_ERR_NONE;
 }
 
 int ms_user_get_wordbook_db_path(uid_t uid, char **path)
 {
-       int ret = MS_MEDIA_ERR_NONE;
+       if (uid != getuid())
+               return __ms_user_get_path(WORDBOOK_DB, uid, path);
 
-       if (uid == getuid())
-               *path = g_strdup(tzplatform_mkpath(TZ_USER_SHARE, "media/.ebook/.wordbook.db"));
-       else
-               ret = __ms_user_get_path(WORDBOOK_DB, uid, path);
+       *path = g_strdup(tzplatform_mkpath(TZ_USER_SHARE, "media/.ebook/.wordbook.db"));
 
-       //MSAPI_DBG_SLOG("DB path [%s]", *path);
-
-       return ret;
+       return MS_MEDIA_ERR_NONE;
 }
 
 #ifndef _USE_TVPD_MODE
 int ms_user_get_mediashared_path(uid_t uid, char **path)
 {
-       int ret = MS_MEDIA_ERR_NONE;
+       if (uid != getuid())
+               return __ms_user_get_path(MEDIA_SHARED, uid, path);
 
-       if (uid == getuid())
-               *path = g_strdup(tzplatform_getenv(TZ_USER_MEDIASHARED));
-       else
-               ret = __ms_user_get_path(MEDIA_SHARED, uid, path);
+       *path = g_strdup(tzplatform_getenv(TZ_USER_MEDIASHARED));
 
-       //MSAPI_DBG_SLOG("DB path [%s]", *path);
-
-       return ret;
+       return MS_MEDIA_ERR_NONE;
 }
-#endif
+#endif
\ No newline at end of file
index d4cffff..ebd4eb9 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       media-server
 Summary:    A server for media content management
-Version:    0.4.21
+Version:    0.4.22
 Release:    0
 Group:      Multimedia/Service
 License:    Apache-2.0