int media_db_request_update_db_batch_clear(void);
-int media_db_get_media_db_path(uid_t uid, char **db_path);
-
/**
* @}
*/
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
}
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;
}
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) {
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;
-}
}
#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");
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");
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;
+}
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
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);
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);
{
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*/
{
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*/
{
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*/
{
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*/
{
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*/
{
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*/
{
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);
{
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();
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;
{
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);
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;
}
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;
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;
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;
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;
}
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) {
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;
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);
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. */
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;
}
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);
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;
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");
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);
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;
}
/*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);
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;
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) {
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");
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;
}
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
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();