Use ms_user_XXX APIs instead of each local code 84/130084/2 accepted/tizen/unified/20170519.200058 submit/tizen/20170519.061906
authorHaejeong Kim <backto.kim@samsung.com>
Fri, 19 May 2017 05:20:39 +0000 (14:20 +0900)
committerHaejeong Kim <backto.kim@samsung.com>
Fri, 19 May 2017 05:33:00 +0000 (14:33 +0900)
Change-Id: I69f63a452b31dc62146abc58105da6d06e000db0

14 files changed:
lib/include/media-util-db.h
lib/include/media-util-user.h
lib/media-util-db.c
lib/media-util-register.c
lib/media-util-user.c
packaging/media-server.spec
src/common/include/media-common-utils.h
src/common/media-common-db-svc.c
src/common/media-common-utils.c
src/scanner-v2/media-scanner-extract-v2.c
src/scanner-v2/media-scanner-scan-v2.c
src/scanner/media-scanner-scan.c
src/server/media-server-db-manage.c
src/server/media-server-main.c

index fa4f5fa..f0f807a 100755 (executable)
@@ -44,8 +44,6 @@ int media_db_request_update_db_batch_end(const char *query_str, uid_t uid);
 
 int media_db_request_update_db_batch_clear(void);
 
-int media_db_get_media_db_path(uid_t uid, char **db_path);
-
 /**
 * @}
 */
index 723314e..68cd3e5 100755 (executable)
@@ -35,6 +35,7 @@ int ms_user_get_storage_type(uid_t uid, const char *path, ms_user_storage_type_t
 int ms_user_get_root_thumb_store_path(uid_t uid, char **path);
 int ms_user_get_default_thumb_store_path(uid_t uid, char **path);
 int ms_user_get_mmc_thumb_store_path(uid_t uid, char **path);
+int ms_user_get_media_db_path(uid_t uid, char **path);
 
 #ifdef __cplusplus
 }
index 0d509f2..daba2a4 100755 (executable)
@@ -64,107 +64,26 @@ static int __media_db_busy_handler(void *pData, int count)
        return 200 - count;
 }
 
-static char* __media_get_media_DB(uid_t uid)
-{
-       int len = 0;
-       char *result_passwd = NULL;
-
-       struct group grpinfo;
-       struct group* grpresult = NULL;
-       char* grpbuf;
-       size_t grpbufsize;
-       int ret = -1;
-
-       grpbufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
-       if (grpbufsize == -1)           /* Value was indeterminate */
-               grpbufsize = 16384;             /* Should be more than enough (16*1024) */
-
-       grpbuf = malloc(grpbufsize);
-       if (grpbuf == NULL) {
-               MSAPI_DBG_ERR("malloc grpbuf grpbufsize[%d] failed", grpbufsize);
-               return NULL;
-       }
-
-       ret = getgrnam_r("users", &grpinfo, grpbuf, grpbufsize, &grpresult);
-       if ((ret == 0) && (grpresult != NULL)) {
-               /*MSAPI_DBG("getgrnam_r users success...\n");*/
-       } else {
-               MSAPI_DBG_ERR("getgrnam_r users failed ret[%d]", ret);
-               goto END;
-       }
-
-       if (uid == getuid()) {
-               if (MS_STRING_VALID(MEDIA_DB_NAME)) {
-                       /*MSAPI_DBG("MS_STRING_VALID MEDIA_DB_NAME valid...\n");*/
-                       result_passwd = strdup(MEDIA_DB_NAME);
-               } else {
-                       MSAPI_DBG_ERR("MS_STRING_VALID MEDIA_DB_NAME invalid...\n");
-                       goto END;
-               }
-       } else {
-               char passwd_str[MAX_FILEPATH_LEN] = {0, };
-               struct passwd pwdinfo;
-               struct passwd* pwdresult = NULL;
-               char* pwdbuf;
-               size_t pwdbufsize;
-
-               pwdbufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
-               if (pwdbufsize == -1)           /* Value was indeterminate */
-                       pwdbufsize = 16384;             /* Should be more than enough (16*1024) */
-
-               pwdbuf = malloc(pwdbufsize);
-               if (pwdbuf == NULL) {
-                       MSAPI_DBG_ERR("malloc pwdbuf pwdbufsize[%d] failed", pwdbufsize);
-                       goto END;
-               }
-
-               ret = getpwuid_r(uid, &pwdinfo, pwdbuf, pwdbufsize, &pwdresult);
-               if ((ret == 0) && (pwdresult != NULL)) {
-                       /*MSAPI_DBG("getpwuid uid[%d] success\n", uid);*/
-               } else {
-                       MSAPI_DBG_ERR("getpwuid uid[%d] failed ret[%d]", uid, ret);
-                       MS_SAFE_FREE(pwdbuf);
-                       goto END;
-               }
-
-               if (grpinfo.gr_gid != pwdinfo.pw_gid) {
-                       MSAPI_DBG_ERR("UID [%d] does not belong to 'users' group![%d][%d]", uid, grpinfo.gr_gid, pwdinfo.pw_gid);
-                       MS_SAFE_FREE(pwdbuf);
-                       goto END;
-               }
-
-               len = snprintf(passwd_str, sizeof(passwd_str), "%s/.applications/dbspace/.media.db", pwdinfo.pw_dir);
-               if (len > 0)
-                       result_passwd = strndup(passwd_str, len);
-
-               MS_SAFE_FREE(pwdbuf);
-       }
-END:
-       MS_SAFE_FREE(grpbuf);
-
-       return result_passwd;
-}
-
 static int __media_db_connect_db_with_handle(sqlite3 **db_handle, uid_t uid, bool need_write)
 {
        int ret = SQLITE_OK;
-       char *db_info = __media_get_media_DB(uid);
+       char *db_path = NULL;
        char *sql = NULL;
 
-       if (!MS_STRING_VALID(db_info)) {
-               MSAPI_DBG_ERR("__media_get_media_DB failed");
-               return MS_MEDIA_ERR_DB_CONNECT_FAIL;
-       }
+       ret = ms_user_get_media_db_path(uid, &db_path);
+       MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_DB_CONNECT_FAIL, "ms_user_get_media_db_path failed");
 
        /*Connect DB*/
        if (need_write) {
-               ret = db_util_open_with_options(db_info, db_handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
+               ret = db_util_open_with_options(db_path, db_handle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
        } else {
-               ret = db_util_open_with_options(db_info, db_handle, SQLITE_OPEN_READONLY, NULL);
+               ret = db_util_open_with_options(db_path, db_handle, SQLITE_OPEN_READONLY, NULL);
        }
-       MS_SAFE_FREE(db_info);
+
+       MS_SAFE_FREE(db_path);
+
        if (SQLITE_OK != ret) {
-               MSAPI_DBG_ERR("error when db open [%s]", __media_get_media_DB(uid));
+               MSAPI_DBG_ERR("error when db open [%s]", db_path);
                *db_handle = NULL;
                return MS_MEDIA_ERR_DB_CONNECT_FAIL;
        }
@@ -714,12 +633,8 @@ static int __media_db_request_recovery(uid_t uid)
        int retry_count = 0;
        char *db_path = NULL;
 
-       media_db_get_media_db_path(uid, &db_path);
-
-       if (!MS_STRING_VALID(db_path)) {
-               MSAPI_DBG_ERR("invalid query");
-               return MS_MEDIA_ERR_INVALID_PARAMETER;
-       }
+       ret = ms_user_get_media_db_path(uid, &db_path);
+       MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_INVALID_PARAMETER, "ms_user_get_media_db_path failed");
 
        request_msg_size = strlen(db_path);
        if (request_msg_size >= MAX_MSG_SIZE) {
@@ -801,17 +716,3 @@ RETRY:
 
        return ret;
 }
-
-int media_db_get_media_db_path(uid_t uid, char **db_path)
-{
-       int ret = MS_MEDIA_ERR_NONE;
-       *db_path = NULL;
-
-       *db_path = __media_get_media_DB(uid);
-       if (*db_path == NULL) {
-               MSAPI_DBG_ERR("__media_get_media_DB failed", uid);
-               ret = MS_MEDIA_ERR_INTERNAL;
-       }
-
-       return ret;
-}
index 701f2e1..f471af6 100755 (executable)
@@ -75,129 +75,15 @@ bool media_util_is_support_senior_mode()
 }
 #endif
 
-static char* __media_get_path(uid_t uid)
-{
-       int ret = -1;
-       char *grpbuf = NULL;
-       char *result_passwd = NULL;
-       struct group grpinfo;
-       struct group *grpresult = NULL;
-       size_t grpbufsize;
-
-       grpbufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
-       if (grpbufsize == -1)           /* Value was indeterminate */
-               grpbufsize = 16384;             /* Should be more than enough (16*1024) */
-
-       grpbuf = malloc(grpbufsize);
-       if (grpbuf == NULL) {
-               MSAPI_DBG_ERR("malloc grpbuf grpbufsize[%d] failed", grpbufsize);
-               goto END;
-       }
-
-       ret = getgrnam_r("users", &grpinfo, grpbuf, grpbufsize, &grpresult);
-       if ((ret == 0) && (grpresult != NULL)) {
-               /*MSAPI_DBG("getgrnam_r users success...\n");*/
-       } else {
-               MSAPI_DBG_ERR("getgrnam_r users failed ret[%d]", ret);
-               goto END;
-       }
-
-       if (uid == getuid()) {
-               if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
-                       result_passwd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
-       } else {
-               struct passwd pwdinfo;
-               struct passwd *pwdresult = NULL;
-               char *pwdbuf;
-               size_t pwdbufsize;
-
-               pwdbufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
-               if (pwdbufsize == -1)           /* Value was indeterminate */
-                       pwdbufsize = 16384;             /* Should be more than enough (16*1024) */
-
-               pwdbuf = malloc(pwdbufsize);
-               if (pwdbuf == NULL) {
-                       MSAPI_DBG_ERR("malloc pwdbuf pwdbufsize[%d] failed", pwdbufsize);
-                       goto END;
-               }
-
-               ret = getpwuid_r(uid, &pwdinfo, pwdbuf, pwdbufsize, &pwdresult);
-               if ((ret == 0) && (pwdresult != NULL)) {
-                       /*MSAPI_DBG("getpwuid uid[%d] success\n", uid);*/
-               } else {
-                       MSAPI_DBG_ERR("getpwuid uid[%d] failed ret[%d]", uid, ret);
-                       MS_SAFE_FREE(pwdbuf);
-                       goto END;
-               }
-
-               /* Compare git_t type and not group name */
-               if (grpinfo.gr_gid != pwdinfo.pw_gid) {
-                       MSAPI_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
-                       MS_SAFE_FREE(pwdbuf);
-                       goto END;
-               }
-               result_passwd = strndup(pwdinfo.pw_dir, strlen(pwdinfo.pw_dir));
-
-               MS_SAFE_FREE(pwdbuf);
-       }
-
-END:
-       MS_SAFE_FREE(grpbuf);
-
-       return result_passwd;
-}
-
-static bool _is_valid_path(const char *path, uid_t uid)
-{
-       bool ret = false;
-       int length_path;
-       char *user_path = NULL;
-
-       if (path == NULL)
-               return false;
-
-#ifdef _USE_SENIOR_MODE
-       if (media_util_is_support_senior_mode()) {
-               if (strncmp(path, MEDIA_ROOT_PATH_SENIOR_MODE, strlen(MEDIA_ROOT_PATH_SENIOR_MODE)) == 0)
-                       return true;
-       }
-#endif
-
-       user_path = __media_get_path(uid);
-       if (user_path == NULL)
-               return false;
-
-       length_path = strlen(user_path);
-
-       if (strncmp(path, user_path, length_path) == 0)
-               ret = true;
-       else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0))
-               ret = true;
-       else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0))
-               ret = true;
-       else if (MS_STRING_VALID(MEDIA_ROOT_PATH_DISC) && (strncmp(path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0))
-               ret = true;
-#ifdef _USE_SENIOR_MODE
-       else if (strncmp(path, MEDIA_ROOT_PATH_SENIOR_MODE, strlen(MEDIA_ROOT_PATH_SENIOR_MODE)) == 0)
-               return true;
-#endif
-       else
-               ret = false;
-
-       MS_SAFE_FREE(user_path);
-
-       return ret;
-}
-
 static int _check_dir_path(const char *dir_path, uid_t uid)
 {
        struct stat sb;
        DIR *dp = NULL;
+       ms_user_storage_type_t storage_type;
+       int ret = MS_MEDIA_ERR_NONE;
 
-       if (!_is_valid_path(dir_path, uid)) {
-               MSAPI_DBG("Invalid path : %s", dir_path);
-               return MS_MEDIA_ERR_INVALID_PATH;
-       }
+       ret = ms_user_get_storage_type(uid, dir_path, &storage_type);
+       MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_INVALID_PATH, "Invalid path");
 
        if (stat(dir_path, &sb) == -1) {
                MSAPI_DBG("stat failed");
index 9bd06bb..6619752 100755 (executable)
@@ -55,6 +55,15 @@ int ms_user_get_storage_type(uid_t uid, const char *path, ms_user_storage_type_t
                return MS_MEDIA_ERR_INVALID_PARAMETER;
        }
 
+#ifdef _USE_SENIOR_MODE
+       if (ms_is_support_senior_mode()) {
+               if (strncmp(path, MEDIA_ROOT_PATH_SENIOR_MODE, strlen(MEDIA_ROOT_PATH_SENIOR_MODE)) == 0) {
+                       *storage_type = MS_USER_STORAGE_EXTERNAL;
+                       return MS_MEDIA_ERR_NONE;
+               }
+       }
+#endif
+
        ret = ms_user_get_internal_root_path(uid, &internal_path);
        MSAPI_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail get internal root path");
 
@@ -142,3 +151,25 @@ int ms_user_get_mmc_thumb_store_path(uid_t uid, char **path)
 
        return ret;
 }
+
+int ms_user_get_media_db_path(uid_t uid, char **path)
+{
+       int ret = MS_MEDIA_ERR_NONE;
+
+       if (uid == getuid()) {
+               if (MS_STRING_VALID(MEDIA_DB_NAME))
+                       *path = g_strndup(MEDIA_DB_NAME, strlen(MEDIA_DB_NAME));
+       } else {
+               ret = tzplatform_set_user(uid);
+               MSAPI_RETVM_IF(ret != 0, MS_MEDIA_ERR_INTERNAL, "Invalid UID[%d]", uid);
+
+               if (MS_STRING_VALID(MEDIA_DB_NAME))
+                       *path = g_strndup(MEDIA_DB_NAME, strlen(MEDIA_DB_NAME));
+
+               tzplatform_reset_user();
+       }
+
+       //MSAPI_DBG_SLOG("DB path [%s]", *path);
+
+       return ret;
+}
index a0567df..fc1948c 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       media-server
 Summary:    A server for media content management
-Version:    0.3.38
+Version:    0.3.39
 Release:    0
 Group:      Multimedia/Service
 License:    Apache-2.0
index 1ccbcf7..73593b1 100755 (executable)
@@ -30,7 +30,6 @@ bool ms_is_mmc_inserted(void);
 void ms_usb_vconf_cb(void *data);
 int ms_start(bool need_db_create);
 void ms_end(void);
-ms_storage_type_t ms_get_storage_type_by_full(const char *path, uid_t uid);
 int ms_strappend(char *res, const int size, const char *pattern, const char *str1, const char *str2);
 int ms_strcopy(char *res, const int size, const char *pattern, const char *str1);
 bool ms_config_get_int(const char *key, int *value);
@@ -51,9 +50,7 @@ bool ms_is_support_senior_mode(void);
 int ms_check_file_path(const char *file_path, uid_t uid);
 int ms_check_ignore_dir(const char *full_path, uid_t uid);
 int ms_check_scan_ignore(char * path);
-char* ms_get_path(uid_t uid);
 bool ms_storage_mount_status(const char* start_path);
-bool ms_is_valid_path(const char *path, uid_t uid);
 int ms_set_db_status(ms_db_status_type_t status, ms_storage_type_t storage_type);
 int ms_set_power_mode(ms_db_status_type_t status);
 void ms_trim_dir_path(char *dir_path);
index 224e897..61a3239 100755 (executable)
@@ -539,13 +539,14 @@ int ms_insert_item_batch(void **handle, const char* storage_id, const char *path
 {
        int lib_index;
        int res = MS_MEDIA_ERR_NONE;
-       int ret;
+       int ret = MS_MEDIA_ERR_NONE;
        char *err_msg = NULL;
-       ms_storage_type_t storage_type;
+       ms_user_storage_type_t storage_type = -1;
 
        MS_DBG_FENTER();
 
-       storage_type = ms_get_storage_type_by_full(path, uid);
+       ret = ms_user_get_storage_type(uid, path, &storage_type);
+       MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get storage type");
 
        for (lib_index = 0; lib_index < lib_num; lib_index++) {
                ret = ((INSERT_ITEM)func_array[lib_index][eINSERT_BATCH])(handle[lib_index], storage_id, path, storage_type, uid, &err_msg); /*dlopen*/
@@ -563,13 +564,14 @@ int ms_scan_item_batch(void **handle, const char* storage_id, const char *path,
 {
        int lib_index;
        int res = MS_MEDIA_ERR_NONE;
-       int ret;
+       int ret = MS_MEDIA_ERR_NONE;
        char *err_msg = NULL;
-       ms_storage_type_t storage_type;
+       ms_user_storage_type_t storage_type;
 
        MS_DBG_FENTER();
 
-       storage_type = ms_get_storage_type_by_full(path, uid);
+       ret = ms_user_get_storage_type(uid, path, &storage_type);
+       MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get storage type");
 
        for (lib_index = 0; lib_index < lib_num; lib_index++) {
                ret = ((INSERT_ITEM_SCAN)func_array[lib_index][eINSERT_SCAN])(handle[lib_index], storage_id, path, storage_type, uid, &err_msg); /*dlopen*/
@@ -587,11 +589,12 @@ int ms_insert_item_pass2(void **handle, const char* storage_id, const char *path
 {
        int lib_index;
        int res = MS_MEDIA_ERR_NONE;
-       int ret;
+       int ret = MS_MEDIA_ERR_NONE;
        char *err_msg = NULL;
-       ms_storage_type_t storage_type;
+       ms_user_storage_type_t storage_type;
 
-       storage_type = ms_get_storage_type_by_full(path, uid);
+       ret = ms_user_get_storage_type(uid, path, &storage_type);
+       MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get storage type");
 
        for (lib_index = 0; lib_index < lib_num; lib_index++) {
                ret = ((UPDATE_ITEM_EXTRACT)func_array[lib_index][eUPDATE_EXTRACT])(handle[lib_index], storage_id, storage_type, scan_type, uid, path, burst, &err_msg); /*dlopen*/
@@ -670,11 +673,12 @@ int ms_insert_item_immediately(void **handle, const char *storage_id, const char
 {
        int lib_index;
        int res = MS_MEDIA_ERR_NONE;
-       int ret;
+       int ret = MS_MEDIA_ERR_NONE;
        char *err_msg = NULL;
-       ms_storage_type_t storage_type;
+       ms_user_storage_type_t storage_type;
 
-       storage_type = ms_get_storage_type_by_full(path, uid);
+       ret = ms_user_get_storage_type(uid, path, &storage_type);
+       MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get storage type");
 
        for (lib_index = 0; lib_index < lib_num; lib_index++) {
                ret = ((INSERT_ITEM_IMMEDIATELY)func_array[lib_index][eINSERT_ITEM_IMMEDIATELY])(handle[lib_index], storage_id, path, storage_type, uid, &err_msg); /*dlopen*/
@@ -692,11 +696,12 @@ int ms_insert_burst_item(void **handle, const char *storage_id, const char *path
 {
        int lib_index;
        int res = MS_MEDIA_ERR_NONE;
-       int ret;
+       int ret = MS_MEDIA_ERR_NONE;
        char *err_msg = NULL;
-       ms_storage_type_t storage_type;
+       ms_user_storage_type_t storage_type;
 
-       storage_type = ms_get_storage_type_by_full(path, uid);
+       ret = ms_user_get_storage_type(uid, path, &storage_type);
+       MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get storage type");
 
        for (lib_index = 0; lib_index < lib_num; lib_index++) {
                ret = ((INSERT_BURST_ITEM)func_array[lib_index][eINSERT_BURST])(handle[lib_index], storage_id, path, storage_type, uid, &err_msg); /*dlopen*/
@@ -1032,10 +1037,12 @@ int ms_insert_folder(void **handle, const char *storage_id, const char *path, ui
 {
        int lib_index;
        int res = MS_MEDIA_ERR_NONE;
-       int ret;
+       int ret = MS_MEDIA_ERR_NONE;
        char *err_msg = NULL;
-       ms_storage_type_t storage_type;
-       storage_type = ms_get_storage_type_by_full(path, uid);
+       ms_user_storage_type_t storage_type;
+
+       ret = ms_user_get_storage_type(uid, path, &storage_type);
+       MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get storage type");
 
        for (lib_index = 0; lib_index < lib_num; lib_index++) {
                ret = ((INSERT_FOLDER)func_array[lib_index][eINSERT_FOLDER])(handle[lib_index], storage_id, path, storage_type, uid, &err_msg); /*dlopen*/
@@ -1175,13 +1182,14 @@ int ms_insert_storage(void **handle, const char *storage_id, const char *storage
 {
        int lib_index = 0;
        int res = MS_MEDIA_ERR_NONE;
-       int ret = 0;
+       int ret = MS_MEDIA_ERR_NONE;
        char *err_msg = NULL;
-       ms_storage_type_t storage_type;
+       ms_user_storage_type_t storage_type;
 
        MS_DBG("ms_insert_storage Start");
 
-       storage_type = ms_get_storage_type_by_full(storage_path, uid);
+       ret = ms_user_get_storage_type(uid, storage_path, &storage_type);
+       MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get storage type");
 
        for (lib_index = 0; lib_index < lib_num; lib_index++) {
                ret = ((INSERT_STORAGE)func_array[lib_index][eINSERT_STORAGE])(handle[lib_index], storage_id, storage_type, storage_name, storage_path, uid, &err_msg);
@@ -1285,11 +1293,12 @@ int ms_update_meta_batch(void **handle, const char *path, const char *storage_id
 {
        int lib_index;
        int res = MS_MEDIA_ERR_NONE;
-       int ret;
+       int ret = MS_MEDIA_ERR_NONE;
        char *err_msg = NULL;
-       ms_storage_type_t storage_type;
+       ms_user_storage_type_t storage_type;
 
-       storage_type = ms_get_storage_type_by_full(path, uid);
+       ret = ms_user_get_storage_type(uid, path, &storage_type);
+       MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get storage type");
 
        MS_DBG_FENTER();
 
index f58fc20..4ab2570 100755 (executable)
@@ -91,120 +91,6 @@ bool ms_is_mmc_inserted(void)
        return ret;
 }
 
-static char* __media_get_path(uid_t uid)
-{
-       int ret = -1;
-       char *grpbuf = NULL;
-       char *result_passwd = NULL;
-       struct group grpinfo;
-       struct group *grpresult = NULL;
-       size_t grpbufsize;
-
-       grpbufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
-       if (grpbufsize == -1)           /* Value was indeterminate */
-               grpbufsize = 16384;             /* Should be more than enough (16*1024) */
-
-       grpbuf = malloc(grpbufsize);
-       if (grpbuf == NULL) {
-               MS_DBG_ERR("malloc grpbuf grpbufsize[%d] failed", grpbufsize);
-               goto END;
-       }
-
-       ret = getgrnam_r("users", &grpinfo, grpbuf, grpbufsize, &grpresult);
-       if ((ret == 0) && (grpresult != NULL)) {
-//             MS_DBG("getgrnam_r users success...\n");
-       } else {
-               MS_DBG_ERR("getgrnam_r users failed ret[%d]", ret);
-               goto END;
-       }
-
-       if (uid == getuid()) {
-               if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
-                       result_passwd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
-       } else {
-               struct passwd pwdinfo;
-               struct passwd *pwdresult = NULL;
-               char *pwdbuf;
-               size_t pwdbufsize;
-
-               pwdbufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
-               if (pwdbufsize == -1)           /* Value was indeterminate */
-                       pwdbufsize = 16384;             /* Should be more than enough (16*1024) */
-
-               pwdbuf = malloc(pwdbufsize);
-               if (pwdbuf == NULL) {
-                       MS_DBG_ERR("malloc pwdbuf pwdbufsize[%d] failed", pwdbufsize);
-                       goto END;
-               }
-
-               ret = getpwuid_r(uid, &pwdinfo, pwdbuf, pwdbufsize, &pwdresult);
-               if ((ret == 0) && (pwdresult != NULL)) {
-//                     MS_DBG("getpwuid uid[%d] success\n", uid);
-               } else {
-                       MS_DBG_ERR("getpwuid uid[%d] failed ret[%d]", uid, ret);
-                       MS_SAFE_FREE(pwdbuf);
-                       goto END;
-               }
-
-               // Compare git_t type and not group name
-               if (grpinfo.gr_gid != pwdinfo.pw_gid) {
-                       MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
-                       MS_SAFE_FREE(pwdbuf);
-                       goto END;
-               }
-               result_passwd = strndup(pwdinfo.pw_dir, strlen(pwdinfo.pw_dir));
-
-               MS_SAFE_FREE(pwdbuf);
-       }
-
-END:
-       MS_SAFE_FREE(grpbuf);
-
-       return result_passwd;
-}
-
-
-ms_storage_type_t ms_get_storage_type_by_full(const char *path, uid_t uid)
-{
-       int length_path;
-       int ret = MS_MEDIA_ERR_NONE;
-       char * user_path = NULL;
-
-       if (path == NULL)
-               return MS_MEDIA_ERR_INVALID_PATH;
-
-#ifdef _USE_SENIOR_MODE
-       if (ms_is_support_senior_mode()) {
-               if (strncmp(path, MEDIA_ROOT_PATH_SENIOR_MODE, strlen(MEDIA_ROOT_PATH_SENIOR_MODE)) == 0) {
-                       return MS_STORAGE_EXTERNAL;
-               }
-       }
-#endif
-
-       user_path = __media_get_path(uid);
-       if (user_path == NULL)
-               return MS_MEDIA_ERR_OUT_OF_MEMORY;
-
-       length_path = strlen(user_path);
-
-       if (strncmp(path, user_path, length_path) == 0) {
-               ret = MS_STORAGE_INTERNAL;
-       } else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)) {
-               ret = MS_STORAGE_EXTERNAL;
-       } else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0)) {
-               ret = MS_STORAGE_EXTERNAL_USB;
-       } else if (MS_STRING_VALID(MEDIA_ROOT_PATH_DISC) && (strncmp(path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0)) {
-               ret = MS_STORAGE_EXTERNAL_USB;
-       } else {
-               MS_DBG_ERR("[%s][%s][%s]", MEDIA_ROOT_PATH_SDCARD, MEDIA_ROOT_PATH_USB, path);
-               ret = MS_MEDIA_ERR_INVALID_PATH;
-       }
-
-       MS_SAFE_FREE(user_path);
-
-       return ret;
-}
-
 int ms_strappend(char *res, const int size, const char *pattern, const char *str1, const char *str2)
 {
        int len = 0;
@@ -430,13 +316,13 @@ int ms_check_file_path(const char *file_path, uid_t uid)
 {
        int exist;
        struct stat file_st;
+       ms_user_storage_type_t storage_type = -1;
+       int ret = MS_MEDIA_ERR_NONE;
 
        /* check location of file */
        /* file must exists under "/opt/usr/media" or "/opt/storage/sdcard" */
-       if (!ms_is_valid_path(file_path, uid)) {
-               MS_DBG_ERR("Invalid path : %s", file_path);
-               return MS_MEDIA_ERR_INVALID_PATH;
-       }
+       ret = ms_user_get_storage_type(uid, file_path, &storage_type);
+       MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_INVALID_PATH, "Invalid path");
 
        /* check the file exits actually */
        exist = open(file_path, O_RDONLY);
@@ -483,9 +369,9 @@ int ms_check_ignore_dir(const char *full_path, uid_t uid)
                return MS_MEDIA_ERR_INVALID_PATH;
        }
 
-       usr_path = ms_get_path(uid);
-       if (usr_path == NULL) {
-               MS_DBG_ERR("ms_get_path() fail");
+       ret = ms_user_get_internal_root_path(uid, &usr_path);
+       if (ret != MS_MEDIA_ERR_NONE) {
+               MS_DBG_ERR("ms_user_get_internal_root_path() fail");
                MS_SAFE_FREE(dir_path);
                return MS_MEDIA_ERR_INTERNAL;
        }
@@ -607,83 +493,6 @@ ERROR:
        return ret;
 }
 
-char* ms_get_path(uid_t uid)
-{
-       int len = 0;
-       char *result_passwd = NULL;
-       int ret = -1;
-       char* grpbuf;
-       struct group grpinfo;
-       struct group* grpresult = NULL;
-       size_t grpbufsize;
-
-       grpbufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
-       if (grpbufsize == -1)           /* Value was indeterminate */
-               grpbufsize = 16384;             /* Should be more than enough (16*1024) */
-
-       grpbuf = malloc(grpbufsize);
-       if (grpbuf == NULL) {
-               MS_DBG_ERR("malloc grpbuf grpbufsize[%d] failed", grpbufsize);
-               return NULL;
-       }
-
-       ret = getgrnam_r("users", &grpinfo, grpbuf, grpbufsize, &grpresult);
-       if ((ret == 0) && (grpresult != NULL)) {
-//             MS_DBG("getgrnam_r users success...\n");
-       } else {
-               MS_DBG_ERR("getgrnam_r users failed ret[%d]", ret);
-               goto END;
-       }
-
-       if (uid == getuid()) {
-               if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
-                       result_passwd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
-       } else {
-               char passwd_str[MAX_FILEPATH_LEN] = {0, };
-               struct passwd pwdinfo;
-               struct passwd* pwdresult = NULL;
-               char* pwdbuf;
-               size_t pwdbufsize;
-
-               pwdbufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
-               if (pwdbufsize == -1)           /* Value was indeterminate */
-                       pwdbufsize = 16384;             /* Should be more than enough (16*1024) */
-
-               pwdbuf = malloc(pwdbufsize);
-               if (pwdbuf == NULL) {
-                       MS_DBG_ERR("malloc pwdbuf pwdbufsize[%d] failed", pwdbufsize);
-                       goto END;
-               }
-
-               ret = getpwuid_r(uid, &pwdinfo, pwdbuf, pwdbufsize, &pwdresult);
-               if ((ret == 0) && (pwdresult != NULL)) {
-//                     MS_DBG("getpwuid uid[%d] success\n", uid);
-               } else {
-                       MS_DBG_ERR("getpwuid uid[%d] failed ret[%d]", uid, ret);
-                       MS_SAFE_FREE(pwdbuf);
-                       goto END;
-               }
-
-               // Compare git_t type and not group name
-               if (grpinfo.gr_gid != pwdinfo.pw_gid) {
-                       MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
-                       MS_SAFE_FREE(pwdbuf);
-                       goto END;
-               }
-
-               len = snprintf(passwd_str, sizeof(passwd_str), "%s/%s", pwdinfo.pw_dir, MEDIA_CONTENT_PATH);
-               if (len > 0)
-                       result_passwd = strndup(passwd_str, len);
-
-               MS_SAFE_FREE(pwdbuf);
-       }
-
-END:
-       MS_SAFE_FREE(grpbuf);
-
-       return result_passwd;
-}
-
 bool ms_storage_mount_status(const char* start_path)
 {
        bool ret = false;
@@ -753,41 +562,6 @@ bool ms_storage_mount_status(const char* start_path)
        return ret;
 }
 
-bool ms_is_valid_path(const char *path, uid_t uid)
-{
-       bool ret = false;
-       char *usr_path = NULL;
-
-       if (path == NULL)
-               return false;
-
-       usr_path = ms_get_path(uid);
-       if (usr_path == NULL)
-               return false;
-
-#ifdef _USE_SENIOR_MODE
-       if (ms_is_support_senior_mode()) {
-               if (strncmp(path, MEDIA_ROOT_PATH_SENIOR_MODE, strlen(MEDIA_ROOT_PATH_SENIOR_MODE)) == 0)
-                       return true;
-       }
-#endif
-
-       if (strncmp(path, usr_path, strlen(usr_path)) == 0)
-               ret = true;
-       else if (MS_STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0))
-               ret = true;
-       else if (MS_STRING_VALID(MEDIA_ROOT_PATH_USB) && (strncmp(path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0))
-               ret = true;
-       else if (MS_STRING_VALID(MEDIA_ROOT_PATH_DISC) && (strncmp(path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0))
-               ret = true;
-       else
-               ret = false;
-
-       MS_SAFE_FREE(usr_path);
-
-       return ret;
-}
-
 int ms_set_db_status(ms_db_status_type_t status, ms_storage_type_t storage_type)
 {
        int res = MS_MEDIA_ERR_NONE;
@@ -882,7 +656,7 @@ int ms_check_size_mediadb(uid_t uid, double *db_size)
        char *db_path = NULL;
        struct stat buf;
 
-       ret = media_db_get_media_db_path(uid, &db_path);
+       ret = ms_user_get_media_db_path(uid, &db_path);
 
        if (stat(db_path, &buf) == 0) {
                *db_size = buf.st_size;
index 6d4f686..50200af 100755 (executable)
@@ -187,7 +187,7 @@ gboolean msc_folder_extract_thread(void *data)
        int ret;
        void **handle = NULL;
        int scan_type;
-       int storage_type;
+       ms_user_storage_type_t storage_type;
        char *storage_id = NULL;
        char *update_path = NULL;
        unsigned int io_err_count = 0;
@@ -242,7 +242,10 @@ gboolean msc_folder_extract_thread(void *data)
                }
                end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
 
-               storage_type = ms_get_storage_type_by_full(extract_data->msg, uid);
+               ret = ms_user_get_storage_type(uid, extract_data->msg, &storage_type);
+               if (err != MS_MEDIA_ERR_NONE)
+                       MS_DBG_ERR("ms_user_get_storage_type failed");
+
                ret = __msc_check_extract_stop_status(extract_data->msg_type, storage_type, update_path, extract_data->pid, end_flag);
 
                if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
@@ -329,7 +332,7 @@ gboolean msc_storage_extract_thread(void *data)
        int ret;
        int err;
        void **handle = NULL;
-       ms_storage_type_t storage_type = MS_STORAGE_INTERNAL;
+       ms_user_storage_type_t storage_type = MS_STORAGE_INTERNAL;
        int scan_type;
        //bool valid_status = TRUE;
        char *update_path = NULL;
@@ -424,7 +427,9 @@ gboolean msc_storage_extract_thread(void *data)
                        goto NEXT;
                }
 
-               storage_type = ms_get_storage_type_by_full(extract_data->msg, uid);
+               ret = ms_user_get_storage_type(uid, extract_data->msg, &storage_type);
+               if (err != MS_MEDIA_ERR_NONE)
+                       MS_DBG_ERR("ms_user_get_storage_type failed");
 
                /*extract meta*/
                //ret = ms_insert_item_pass2(handle, extract_data->storage_id, storage_type, update_path, scan_type, end_flag);
index 6c2ba94..99286e9 100755 (executable)
@@ -1017,9 +1017,12 @@ static int __msc_db_update(void **handle, const char *storage_id, const ms_comm_
        int scan_type;
        int err = MS_MEDIA_ERR_NONE;
        char *start_path = NULL;
-       ms_storage_type_t storage_type;
+       ms_user_storage_type_t storage_type;
+
+       err = ms_user_get_storage_type(scan_data->uid, scan_data->msg, &storage_type);
+       if (err != MS_MEDIA_ERR_NONE)
+               MS_DBG_ERR("ms_user_get_storage_type failed");
 
-       storage_type = ms_get_storage_type_by_full(scan_data->msg, scan_data->uid);
        scan_type = scan_data->msg_type;
 
        /*if scan type is not MS_SCAN_NONE, check data in db. */
@@ -1061,7 +1064,7 @@ gboolean msc_directory_scan_thread(void *data)
        char *storage_id = NULL;
        bool modified = FALSE;
        int index = 0;
-       ms_storage_type_t storage_type = MS_STORAGE_INTERNAL;
+       ms_user_storage_type_t storage_type = MS_STORAGE_INTERNAL;
        ms_dir_scan_status_e scan_status = MS_DIR_SCAN_NONE;
        ms_noti_type_e noti_type = MS_ITEM_INSERT;
        int before_count = 0;
@@ -1101,7 +1104,10 @@ gboolean msc_directory_scan_thread(void *data)
                }
 
                scan_type = scan_data->msg_type;
-               storage_type = ms_get_storage_type_by_full(scan_data->msg, uid);
+               err = ms_user_get_storage_type(uid, scan_data->msg, &storage_type);
+               if (err != MS_MEDIA_ERR_NONE)
+                       MS_DBG_ERR("ms_user_get_storage_type failed");
+
                ms_reset_insert_count();
 
                storage_id = strdup(scan_data->storage_id);
@@ -1570,7 +1576,7 @@ gboolean msc_storage_scan_thread(void *data)
        int ret;
        int err;
        void **handle = NULL;
-       ms_storage_type_t storage_type = MS_STORAGE_INTERNAL;
+       ms_user_storage_type_t storage_type = MS_STORAGE_INTERNAL;
        int scan_type;
        bool valid_status = TRUE;
        char *update_path = NULL;
@@ -1604,7 +1610,10 @@ gboolean msc_storage_scan_thread(void *data)
                if (err != MS_MEDIA_ERR_NONE)
                        continue;
 
-               storage_type = ms_get_storage_type_by_full(scan_data->msg, uid);
+               err = ms_user_get_storage_type(uid, scan_data->msg, &storage_type);
+               if (err != MS_MEDIA_ERR_NONE)
+                       MS_DBG_ERR("ms_user_get_storage_type failed");
+
                update_path = g_strndup(scan_data->msg, scan_data->msg_size);
                if (!MS_STRING_VALID(update_path)) {
                        MS_DBG_ERR("Invalid update_path");
index 9f8f687..5b68bcf 100755 (executable)
@@ -432,9 +432,11 @@ static int __msc_db_update(void **handle, const char *storage_id, const ms_comm_
        int scan_type;
        int err = MS_MEDIA_ERR_NONE;
        char *start_path = NULL;
-       ms_storage_type_t storage_type;
+       ms_user_storage_type_t storage_type;
+
+       err = ms_user_get_storage_type(scan_data->uid, scan_data->msg, &storage_type);
+       MS_DBG_RETVM_IF(err != MS_MEDIA_ERR_NONE, err, "Fail to get storage type");
 
-       storage_type = ms_get_storage_type_by_full(scan_data->msg, scan_data->uid);
        scan_type = scan_data->msg_type;
        start_path = strndup(scan_data->msg, scan_data->msg_size);
 
@@ -474,7 +476,7 @@ gboolean msc_directory_scan_thread(void *data)
        char *storage_id = NULL;
        bool is_recursive = true;
        char *start_path = NULL;
-       ms_storage_type_t storage_type;
+       ms_user_storage_type_t storage_type;
        ms_noti_type_e noti_type = MS_ITEM_INSERT;
        int before_count = 0;
        int after_count = 0;
@@ -568,7 +570,10 @@ gboolean msc_directory_scan_thread(void *data)
                }
 
                /*insert data into media db */
-               storage_type = ms_get_storage_type_by_full(scan_data->msg, scan_data->uid);
+               ret = ms_user_get_storage_type(scan_data->uid, scan_data->msg, &storage_type);
+               if (ret != MS_MEDIA_ERR_NONE)
+                       MS_DBG_ERR("ms_user_get_storage_type failed");
+
                start_path = strndup(scan_data->msg, scan_data->msg_size);
 
                ret = __msc_dir_scan(handle, storage_id, start_path, storage_type, scan_data->msg_type, is_recursive, scan_data->uid);
@@ -828,7 +833,7 @@ gboolean msc_storage_scan_thread(void *data)
        int ret;
        int err;
        void **handle = NULL;
-       ms_storage_type_t storage_type = MS_STORAGE_INTERNAL;
+       ms_user_storage_type_t storage_type = MS_STORAGE_INTERNAL;
        int scan_type;
        bool valid_status = TRUE;
        char *update_path = NULL;
@@ -860,7 +865,10 @@ gboolean msc_storage_scan_thread(void *data)
                if (err != MS_MEDIA_ERR_NONE)
                        continue;
 
-               storage_type = ms_get_storage_type_by_full(scan_data->msg, scan_data->uid);
+               err = ms_user_get_storage_type(scan_data->uid, scan_data->msg, &storage_type);
+               if (err != MS_MEDIA_ERR_NONE)
+                       MS_DBG_ERR("ms_user_get_storage_type failed");
+
                update_path = strndup(scan_data->msg, scan_data->msg_size);
 
                if (strlen(scan_data->storage_id) > 0) {
@@ -1383,6 +1391,7 @@ gboolean msc_metadata_update(void *data)
        ms_storage_type_t storage_type = MS_STORAGE_INTERNAL;
        GArray *storage_list = NULL;
        ms_stg_info_s *stg_info = NULL;
+       char *usr_path = NULL;
 
        MS_DBG_INFO("META UPDATE START");
 
@@ -1395,9 +1404,9 @@ gboolean msc_metadata_update(void *data)
        ms_update_start(handle);
 
        /*insert data into media db */
-       char *usr_path = ms_get_path(scan_data->uid);
-       if (usr_path == NULL) {
-               MS_DBG_ERR("ms_get_path() fail");
+       ret = ms_user_get_internal_root_path(scan_data->uid, &usr_path);
+       if (ret != MS_MEDIA_ERR_NONE) {
+               MS_DBG_ERR("ms_user_get_internal_root_path() fail");
                if (handle) ms_disconnect_db(&handle);
                return MS_MEDIA_ERR_INTERNAL;
        }
index ba954f7..fdf9e06 100755 (executable)
@@ -41,7 +41,7 @@ int ms_reset_mediadb(uid_t uid)
        char *dummy_path = MS_DUMMY_MEDIA_DB_PATH;\r
        char *db_path = NULL;\r
 \r
-       ret = media_db_get_media_db_path(uid, &db_path);\r
+       ret = ms_user_get_media_db_path(uid, &db_path);\r
        if ((ret == MS_MEDIA_ERR_NONE) && (db_path != NULL)) {\r
                char command_line[MS_FILE_PATH_LEN_MAX] = {0,};\r
                snprintf(command_line, sizeof(command_line), "%s %s %s", command, dummy_path, db_path);\r
index 441c938..d4f2b93 100755 (executable)
@@ -837,10 +837,7 @@ static void __ms_check_mediadb(void)
        ms_disconnect_db(&db_handle);
        ms_unload_functions();
 #endif
-/*
-       ms_sys_get_uid(&uid);
-       ms_send_storage_scan_request(ms_get_path(uid), INTERNAL_STORAGE_ID, MS_SCAN_PART, uid);
-*/
+
        /* update external storage */
        if (_USE_SDCARD)
                __ms_check_mmc_status();