Name: libmedia-service
Summary: Media information service library for multimedia applications
-Version: 0.2.56
+Version: 0.2.57
Release: 3
Group: System/Libraries
License: Apache-2.0 and public domain
char *_media_svc_get_path(uid_t uid)
{
- char *result_psswd = NULL;
+ char *result_passwd = NULL;
struct group *grpinfo = NULL;
if (uid == getuid()) {
- result_psswd = strdup(MEDIA_ROOT_PATH_INTERNAL);
grpinfo = getgrnam("users");
if (grpinfo == NULL) {
media_svc_error("getgrnam(users) returns NULL !");
return NULL;
}
+ result_passwd = g_strdup(MEDIA_ROOT_PATH_INTERNAL);
} else {
+ char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
struct passwd *userinfo = getpwuid(uid);
if (userinfo == NULL) {
media_svc_error("getpwuid(%d) returns NULL !", uid);
media_svc_error("UID [%d] does not belong to 'users' group!", uid);
return NULL;
}
- asprintf(&result_psswd, "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
+ sprintf(passwd_str, "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
+ result_passwd = g_strdup(passwd_str);
}
- return result_psswd;
+ return result_passwd;
}
int __media_svc_add_table_info(const char *name, const char *triggerName, const char *eventTable, const char *actionTable, const char *viewName)
*is_root = FALSE;
- if (strcmp(folder_path, _media_svc_get_path(uid)) == 0 ||
+ char *internal_path = _media_svc_get_path(uid);
+
+ if ((STRING_VALID(internal_path) && (strcmp(folder_path, internal_path) == 0)) ||
strcmp(folder_path, MEDIA_ROOT_PATH_SDCARD) == 0 ||
- strcmp(folder_path, MEDIA_ROOT_PATH_CLOUD) == 0) {
+ (STRING_VALID(MEDIA_ROOT_PATH_CLOUD) && strcmp(folder_path, MEDIA_ROOT_PATH_CLOUD) == 0)) {
media_svc_debug("ROOT PATH [%s]", folder_path);
*is_root = TRUE;
}
+ SAFE_FREE(internal_path);
return MS_MEDIA_ERR_NONE;
}
return MS_MEDIA_ERR_OUT_OF_MEMORY;
}
- if (strcmp(parent_folder_path, MEDIA_ROOT_PATH_EXTERNAL) == 0) {
+ if (STRING_VALID(MEDIA_ROOT_PATH_EXTERNAL) && (strcmp(parent_folder_path, MEDIA_ROOT_PATH_EXTERNAL) == 0)) {
media_svc_debug("parent folder is ROOT PATH [%s]", parent_folder_path);
*is_root = TRUE;
}
char *folder_uuid = NULL;
char parent_folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
bool folder_search_end = FALSE;
+ char *internal_path = NULL;
memset(parent_folder_uuid, 0, sizeof(parent_folder_uuid));
+ internal_path = _media_svc_get_path(uid);
- if (strncmp(path, _media_svc_get_path(uid), strlen(_media_svc_get_path(uid))) == 0)
- next_pos = strlen(_media_svc_get_path(uid));
+ if (STRING_VALID(internal_path) && (strncmp(path, internal_path, strlen(internal_path)) == 0))
+ next_pos = strlen(internal_path);
else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0)
next_pos = strlen(MEDIA_ROOT_PATH_SDCARD);
- else if (strncmp(path, MEDIA_ROOT_PATH_CLOUD, strlen(MEDIA_ROOT_PATH_CLOUD)) == 0)
+ else if (STRING_VALID(MEDIA_ROOT_PATH_CLOUD) && (strncmp(path, MEDIA_ROOT_PATH_CLOUD, strlen(MEDIA_ROOT_PATH_CLOUD)) == 0))
next_pos = strlen(MEDIA_ROOT_PATH_CLOUD);
else if (strncmp(path, MEDIA_ROOT_PATH_EXTERNAL, strlen(MEDIA_ROOT_PATH_EXTERNAL)) == 0)
next_pos = strlen(MEDIA_ROOT_PATH_EXTERNAL);
else {
media_svc_error("Invalid Path");
+ SAFE_FREE(internal_path);
return MS_MEDIA_ERR_INTERNAL;
}
+ SAFE_FREE(internal_path);
+
while (!folder_search_end) {
next = strstr(path + next_pos, token);
if (next != NULL) {
media_svc_error("[No-Error] End Path [%s]", dir_path);
}
- if (strcmp(dir_path, MEDIA_ROOT_PATH_EXTERNAL) == 0) {
+ if (STRING_VALID(MEDIA_ROOT_PATH_EXTERNAL) && (strcmp(dir_path, MEDIA_ROOT_PATH_EXTERNAL) == 0)) {
/*To avoid insert MEDIA_ROOT_PATH_EXTERNAL path*/
continue;
}
char *_media_svc_get_thumb_default_path(uid_t uid)
{
- char *result_psswd = NULL;
+ char *result_passwd = NULL;
struct group *grpinfo = NULL;
if (uid == getuid()) {
- result_psswd = strdup(MEDIA_SVC_THUMB_DEFAULT_PATH);
grpinfo = getgrnam("users");
if (grpinfo == NULL) {
media_svc_error("getgrnam(users) returns NULL !");
- if(result_psswd)
- free(result_psswd);
return NULL;
}
+ result_passwd = g_strdup(MEDIA_SVC_THUMB_DEFAULT_PATH);
} else {
+ char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
struct passwd *userinfo = getpwuid(uid);
if (userinfo == NULL) {
media_svc_error("getpwuid(%d) returns NULL !", uid);
media_svc_error("UID [%d] does not belong to 'users' group!", uid);
return NULL;
}
- asprintf(&result_psswd, "%s/share/media/.thumb/thumb_default.png", userinfo->pw_dir);
+ sprintf(passwd_str, "%s/share/media/.thumb/thumb_default.png", userinfo->pw_dir);
+ result_passwd = g_strdup(passwd_str);
}
- return result_psswd;
+ return result_passwd;
}
int _media_svc_insert_item_with_data(sqlite3 *handle, const char *storage_id, media_svc_content_info_s *content_info, int is_burst, bool stack_query, uid_t uid)
}
/*Delete thumbnails*/
+ char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
for (idx = 0; idx < invalid_count; idx++) {
- if ((strlen(thumbpath_record[idx].thumbnail_path) > 0) && (strncmp(thumbpath_record[idx].thumbnail_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) {
+ if ((strlen(thumbpath_record[idx].thumbnail_path) > 0) && (STRING_VALID(default_thumbnail_path)) && (strncmp(thumbpath_record[idx].thumbnail_path,default_thumbnail_path, strlen(default_thumbnail_path)) != 0)) {
ret = _media_svc_remove_file(thumbpath_record[idx].thumbnail_path);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("fail to remove thumbnail file.");
}
SAFE_FREE(thumbpath_record);
+ SAFE_FREE(default_thumbnail_path);
return MS_MEDIA_ERR_NONE;
}
/*Delete thumbnails*/
if (thumbpath_record != NULL) {
- for (idx = 0; idx < invalid_count; idx++) {
- if ((strlen(thumbpath_record[idx].thumbnail_path) > 0) && (strncmp(thumbpath_record[idx].thumbnail_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) {
- ret = _media_svc_remove_file(thumbpath_record[idx].thumbnail_path);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("fail to remove thumbnail file.");
+ char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
+ if (STRING_VALID(default_thumbnail_path)) {
+ for (idx = 0; idx < invalid_count; idx++) {
+ if ((strlen(thumbpath_record[idx].thumbnail_path) > 0) && (strncmp(thumbpath_record[idx].thumbnail_path, default_thumbnail_path, strlen(default_thumbnail_path)) != 0)) {
+ ret = _media_svc_remove_file(thumbpath_record[idx].thumbnail_path);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("fail to remove thumbnail file.");
+ }
}
}
}
SAFE_FREE(thumbpath_record);
+ SAFE_FREE(default_thumbnail_path);
}
return MS_MEDIA_ERR_NONE;
SQLITE3_FINALIZE(sql_stmt);
if (storage_cnt == 0) {
+ char *internal_path = _media_svc_get_path(uid);
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, _media_svc_get_path(uid));
+ MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_MEDIA, internal_path);
ret = _media_svc_sql_query(handle, sql, uid);
sqlite3_free(sql);
+ SAFE_FREE(internal_path);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
}
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- remain_path = strstr(path+strlen(MEDIA_ROOT_PATH_USB) +1, "/");
+ remain_path = strstr(path + (STRING_VALID(MEDIA_ROOT_PATH_USB) ? strlen(MEDIA_ROOT_PATH_USB) : 0) + 1, "/");
if (remain_path != NULL)
remain_len = strlen(remain_path);
MEDIA_SVC_EXTRACTED_FIELD_ALBUM_ARTIST = MEDIA_SVC_EXTRACTED_FIELD_NONE << 11,
} media_svc_extracted_field_e;
-static char *_media_svc_get_thumb_path(uid_t uid);
-
char *_media_info_generate_uuid(void)
{
uuid_t uuid_value;
return MS_MEDIA_ERR_NONE;
}
+static char *__media_svc_get_thumb_path(uid_t uid)
+{
+ char *result_passwd = NULL;
+ struct group *grpinfo = NULL;
+ if (uid == getuid()) {
+ grpinfo = getgrnam("users");
+ if (grpinfo == NULL) {
+ media_svc_error("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ result_passwd = g_strdup(MEDIA_SVC_THUMB_PATH_PREFIX);
+ } else {
+ char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
+ struct passwd *userinfo = getpwuid(uid);
+ if (userinfo == NULL) {
+ media_svc_error("getpwuid(%d) returns NULL !", uid);
+ return NULL;
+ }
+ grpinfo = getgrnam("users");
+ if (grpinfo == NULL) {
+ media_svc_error("getgrnam(users) returns NULL !");
+ return NULL;
+ }
+ /* Compare git_t type and not group name */
+ if (grpinfo->gr_gid != userinfo->pw_gid) {
+ media_svc_error("UID [%d] does not belong to 'users' group!", uid);
+ return NULL;
+ }
+ sprintf(passwd_str, "%s/share/media/.thumb", userinfo->pw_dir);
+ result_passwd = g_strdup(passwd_str);
+ }
+
+ return result_passwd;
+}
+
static int _media_svc_save_image(void *image, int size, char *image_path, uid_t uid)
{
media_svc_debug("start save image, path [%s] image size [%d]", image_path, size);
}
struct statfs fs;
- if (-1 == statfs(_media_svc_get_thumb_path(uid), &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;
+ }
+
+ if (-1 == statfs(thumb_path, &fs)) {
media_svc_error("error in statfs");
+ SAFE_FREE(thumb_path);
return MS_MEDIA_ERR_INTERNAL;
}
+ SAFE_FREE(thumb_path);
+
long bsize_kbytes = fs.f_bsize >> 10;
if ((bsize_kbytes * fs.f_bavail) < 1024) {
char *_media_svc_get_thumb_internal_path(uid_t uid)
{
- char *result_psswd = NULL;
+ char *result_passwd = NULL;
struct group *grpinfo = NULL;
if (uid == getuid()) {
- result_psswd = strdup(MEDIA_SVC_THUMB_INTERNAL_PATH);
grpinfo = getgrnam("users");
if (grpinfo == NULL) {
media_svc_error("getgrnam(users) returns NULL !");
- if(result_psswd)
- free(result_psswd);
return NULL;
}
+ result_passwd = g_strdup(MEDIA_SVC_THUMB_INTERNAL_PATH);
} else {
+ char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
struct passwd *userinfo = getpwuid(uid);
if (userinfo == NULL) {
media_svc_error("getpwuid(%d) returns NULL !", uid);
media_svc_error("UID [%d] does not belong to 'users' group!", uid);
return NULL;
}
- asprintf(&result_psswd, "%s/share/media/.thumb/phone", userinfo->pw_dir);
+ sprintf(passwd_str, "%s/share/media/.thumb/phone", userinfo->pw_dir);
+ result_passwd = g_strdup(passwd_str);
}
- return result_psswd;
+ return result_passwd;
}
char *_media_svc_get_thumb_external_path(uid_t uid)
{
- char *result_psswd = NULL;
+ char *result_passwd = NULL;
struct group *grpinfo = NULL;
if (uid == getuid()) {
- result_psswd = strdup(MEDIA_SVC_THUMB_EXTERNAL_PATH);
grpinfo = getgrnam("users");
if (grpinfo == NULL) {
media_svc_error("getgrnam(users) returns NULL !");
- if(result_psswd)
- free(result_psswd);
return NULL;
}
+ result_passwd = g_strdup(MEDIA_SVC_THUMB_EXTERNAL_PATH);
} else {
+ char passwd_str[MEDIA_SVC_PATHNAME_SIZE] = {0, };
struct passwd *userinfo = getpwuid(uid);
if (userinfo == NULL) {
media_svc_error("getpwuid(%d) returns NULL !", uid);
media_svc_error("UID [%d] does not belong to 'users' group!", uid);
return NULL;
}
- asprintf(&result_psswd, "%s/share/media/.thumb/mmc", userinfo->pw_dir);
+ sprintf(passwd_str, "%s/share/media/.thumb/mmc", userinfo->pw_dir);
+ result_passwd = g_strdup(passwd_str);
}
- return result_psswd;
+ return result_passwd;
}
static int __media_svc_check_thumb_dir(const char *thumb_dir)
return -1;
}
-static char *_media_svc_get_thumb_path(uid_t uid)
-{
- char *result_psswd = NULL;
- struct group *grpinfo = NULL;
- if (uid == getuid()) {
- result_psswd = strdup(MEDIA_SVC_THUMB_PATH_PREFIX);
- grpinfo = getgrnam("users");
- if (grpinfo == NULL) {
- media_svc_error("getgrnam(users) returns NULL !");
- if(result_psswd)
- free(result_psswd);
- return NULL;
- }
- } else {
- struct passwd *userinfo = getpwuid(uid);
- if (userinfo == NULL) {
- media_svc_error("getpwuid(%d) returns NULL !", uid);
- return NULL;
- }
- grpinfo = getgrnam("users");
- if (grpinfo == NULL) {
- media_svc_error("getgrnam(users) returns NULL !");
- return NULL;
- }
- /* Compare git_t type and not group name */
- if (grpinfo->gr_gid != userinfo->pw_gid) {
- media_svc_error("UID [%d] does not belong to 'users' group!", uid);
- return NULL;
- }
- asprintf(&result_psswd, "%s/share/media/.thumb", userinfo->pw_dir);
- }
-
- return result_psswd;
-}
-
int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
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);
- thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? _media_svc_get_thumb_internal_path(uid) : _media_svc_get_thumb_external_path(uid);
+ 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;
+ }
+
+ thumb_dir = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? internal_thumb_path : external_thumb_path;
ret = __media_svc_check_thumb_dir(thumb_dir);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("__media_svc_check_thumb_dir");
+ SAFE_FREE(internal_thumb_path);
+ SAFE_FREE(external_thumb_path);
return MS_MEDIA_ERR_INTERNAL;
}
ret = mb_svc_generate_hash_code(pathname, hash, sizeof(hash));
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("mb_svc_generate_hash_code failed : %d", ret);
+ SAFE_FREE(internal_thumb_path);
+ SAFE_FREE(external_thumb_path);
return MS_MEDIA_ERR_INTERNAL;
}
thumbfile_ext = (char *)"bmp";
} else {
media_svc_error("Not proper img format");
+ SAFE_FREE(internal_thumb_path);
+ SAFE_FREE(external_thumb_path);
return MS_MEDIA_ERR_INTERNAL;
}
_strncpy_safe(thumb_path, savename, MEDIA_SVC_PATHNAME_SIZE);
/*media_svc_debug("thumb_path is [%s]", thumb_path); */
+ SAFE_FREE(internal_thumb_path);
+ SAFE_FREE(external_thumb_path);
+
return MS_MEDIA_ERR_NONE;
}
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)) {
- if (strncmp(path, _media_svc_get_path(uid), strlen(_media_svc_get_path(uid))) == 0) {
+ char *internal_path = _media_svc_get_path(uid);
+ if (strncmp(path, internal_path, strlen(internal_path)) == 0) {
*storage_type = MEDIA_SVC_STORAGE_INTERNAL;
- } else if (strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0) {
+ } 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 (strncmp (path, MEDIA_ROOT_PATH_USB, strlen(MEDIA_ROOT_PATH_USB)) == 0) {
+ } 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 {
media_svc_error("Invalid 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;
}
/* If old thumb path is default or not */
- if (strncmp(old_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) == 0) {
- strncpy(new_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(new_thumb_path));
+ char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
+ if (STRING_VALID(default_thumbnail_path) && (strncmp(old_thumb_path, default_thumbnail_path, strlen(default_thumbnail_path)) == 0)) {
+ strncpy(new_thumb_path, default_thumbnail_path, sizeof(new_thumb_path));
} else {
_media_svc_get_thumbnail_path(dest_storage, new_thumb_path, dest_path, THUMB_EXT, uid);
}
+ SAFE_FREE(default_thumbnail_path);
}
if (g_media_svc_move_item_data_cnt == 1) {
/*rename thumbnail file*/
/* if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) { */
- if ((strlen(old_thumb_path) > 0) && (strncmp(old_thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, sizeof(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) {
+ if ((strlen(old_thumb_path) > 0) && (STRING_VALID(MEDIA_SVC_THUMB_DEFAULT_PATH)) && (strncmp(old_thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, strlen(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) {
ret = _media_svc_rename_file(old_thumb_path, new_thumb_path);
if (ret != MS_MEDIA_ERR_NONE)
media_svc_error("_media_svc_rename_file failed : %d", ret);
}
/*Delete thumbnail*/
- if ((strlen(thumb_path) > 0) && (strncmp(thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) {
+ char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
+ if ((strlen(thumb_path) > 0) && ((STRING_VALID(default_thumbnail_path)) && (strncmp(thumb_path, default_thumbnail_path, strlen(default_thumbnail_path)) != 0))) {
/*
int thumb_count = 1;
// Get count of media, which contains same thumbnail for music
// }
}
+ SAFE_FREE(default_thumbnail_path);
+
return MS_MEDIA_ERR_NONE;
}
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
if (storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB) {
- const char *dirpath = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? MEDIA_SVC_THUMB_INTERNAL_PATH : MEDIA_SVC_THUMB_EXTERNAL_PATH;
+ char *internal_thumb_path = _media_svc_get_thumb_internal_path(uid);
+ char *external_thumb_path = _media_svc_get_thumb_external_path(uid);
+
+ const char *dirpath = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? internal_thumb_path : external_thumb_path;
/* remove thumbnails */
ret = _media_svc_remove_all_files_in_dir(dirpath);
+ SAFE_FREE(internal_thumb_path);
+ SAFE_FREE(external_thumb_path);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
}
return ret;
}
- if (g_file_test(thumb_path, G_FILE_TEST_EXISTS) && (strncmp(thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, sizeof(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) {
+ if (g_file_test(thumb_path, G_FILE_TEST_EXISTS) && (STRING_VALID(MEDIA_SVC_THUMB_DEFAULT_PATH)) && (strncmp(thumb_path, MEDIA_SVC_THUMB_DEFAULT_PATH, strlen(MEDIA_SVC_THUMB_DEFAULT_PATH)) != 0)) {
ret = _media_svc_remove_file(thumb_path);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_remove_file failed : %s", thumb_path);
if (!no_thumb) {
/* If old thumb path is default or not */
- if (strncmp(media_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) == 0) {
- strncpy(media_new_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(media_new_thumb_path));
+ char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
+ if (STRING_VALID(default_thumbnail_path) && (strncmp(media_thumb_path, default_thumbnail_path, strlen(default_thumbnail_path)) == 0)) {
+ strncpy(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);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_get_storage_type_by_path failed : %d", ret);
SAFE_FREE(replaced_path);
+ SAFE_FREE(default_thumbnail_path);
_media_svc_sql_rollback_trans(db_handle, uid);
return ret;
}
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_get_thumbnail_path failed : %d", ret);
SAFE_FREE(replaced_path);
+ SAFE_FREE(default_thumbnail_path);
SQLITE3_FINALIZE(sql_stmt);
_media_svc_sql_rollback_trans(db_handle, uid);
return ret;
}
}
+ SAFE_FREE(default_thumbnail_path);
+
/*media_svc_debug("New media thumbnail path : %s", media_new_thumb_path); */
}
}
/* Rename thumbnail file of file system */
-/* if ((!no_thumb) && (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) */
-/* && (strncmp(media_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) { */
- if ((!no_thumb) && (strncmp(media_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) {
+ char *default_thumbnail_path = _media_svc_get_thumb_default_path(uid);
+ if ((!no_thumb) && (strncmp(media_thumb_path, default_thumbnail_path, strlen(default_thumbnail_path)) != 0)) {
ret = _media_svc_rename_file(media_thumb_path, media_new_thumb_path);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("_media_svc_rename_file failed : %d", ret);
}
}
+
+ SAFE_FREE(default_thumbnail_path);
}
SQLITE3_FINALIZE(sql_stmt);