From 8886ca6716c24ee04ed58b356fda29dac4884615 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Wed, 7 Sep 2016 17:24:16 +0900 Subject: [PATCH] Support user session path Change-Id: I758d16a7b8ff11c792a4cd00564e1b3f32d94a80 Signed-off-by: Minje Ahn --- CMakeLists.txt | 2 +- include/media_util_private.h | 1 + include_product/media_util_private.h | 1 + packaging/capi-content-media-content.spec | 3 +- src/media_bookmark.c | 6 +- src/media_content.c | 51 ++++++--- src/media_db.c | 23 ++++ src/media_folder.c | 36 ++++-- src/media_info.c | 176 ++++++++++++++++++++++++------ src/media_playlist.c | 34 +++++- src/media_util_private.c | 40 ++++++- 11 files changed, 304 insertions(+), 69 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c0c2148..8fc783f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ ELSE() ENDIF(TIZEN_PRODUCT_TV) INCLUDE_DIRECTORIES(${INC_DIR}) -SET(dependents "dlog libmedia-service media-thumbnail libmedia-utils capi-base-common capi-system-info vconf cynara-client cynara-creds-socket cynara-session") +SET(dependents "dlog libmedia-service media-thumbnail libmedia-utils capi-base-common capi-system-info vconf cynara-client cynara-creds-socket cynara-session storage") SET(pc_dependents "dlog capi-base-common") INCLUDE(FindPkgConfig) diff --git a/include/media_util_private.h b/include/media_util_private.h index 047bd35..f941f7d 100755 --- a/include/media_util_private.h +++ b/include/media_util_private.h @@ -34,6 +34,7 @@ int _media_util_check_file_exist(const char *path); int _media_util_check_ignore_file(const char *path, bool *ignore); int _media_util_check_ignore_dir(const char *dir_path, bool *ignore); int _media_content_replace_path(const char *path, char *replace_path); +int _media_content_rollback_path(const char *path, char *replace_path); diff --git a/include_product/media_util_private.h b/include_product/media_util_private.h index e53f6cf..0044de1 100755 --- a/include_product/media_util_private.h +++ b/include_product/media_util_private.h @@ -34,6 +34,7 @@ int _media_util_check_file_exist(const char *path); int _media_util_check_ignore_file(const char *path, bool *ignore); int _media_util_check_ignore_dir(const char *dir_path, bool *ignore); int _media_content_replace_path(const char *path, char *replace_path); +int _media_content_rollback_path(const char *path, char *replace_path); #ifdef _USE_SENIOR_MODE bool _media_content_is_support_senior_mode(); diff --git a/packaging/capi-content-media-content.spec b/packaging/capi-content-media-content.spec index 5dc12db..8c2ba3a 100755 --- a/packaging/capi-content-media-content.spec +++ b/packaging/capi-content-media-content.spec @@ -1,6 +1,6 @@ Name: capi-content-media-content Summary: A Media content library in Tizen Native API -Version: 0.2.82 +Version: 0.2.83 Release: 0 Group: Multimedia/API License: Apache-2.0 @@ -17,6 +17,7 @@ BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(cynara-client) BuildRequires: pkgconfig(cynara-session) +BuildRequires: pkgconfig(storage) %description A Media content library in Tizen Native API. diff --git a/src/media_bookmark.c b/src/media_bookmark.c index dba6eb9..c93b343 100755 --- a/src/media_bookmark.c +++ b/src/media_bookmark.c @@ -16,15 +16,19 @@ #include +#include int media_bookmark_insert_to_db(const char *media_id, time_t time, const char *thumbnail_path) { int ret = MEDIA_CONTENT_ERROR_NONE; char *sql = NULL; + char repl_path[MAX_QUERY_SIZE] = {0, }; if (STRING_VALID(media_id)) { - sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, media_id, time, thumbnail_path); + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(thumbnail_path, repl_path); + sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, media_id, time, repl_path); ret = _content_query_sql(sql); SQLITE3_SAFE_FREE(sql); } else { diff --git a/src/media_content.c b/src/media_content.c index 69dad9a..d0175f9 100755 --- a/src/media_content.c +++ b/src/media_content.c @@ -1092,25 +1092,29 @@ int media_content_scan_file(const char *path) char *folder_path = NULL; int check_file = MEDIA_CONTENT_ERROR_NONE; char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,}; + char repl_path[MAX_QUERY_SIZE] = {0,}; media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path"); media_content_sec_debug("Path : %s", path); + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); - ret = _media_util_check_ignore_file(path, &ignore_file); + ret = _media_util_check_ignore_file(repl_path, &ignore_file); media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path"); memset(storage_id, 0x00, sizeof(storage_id)); - ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id); + ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id); if (ret != MS_MEDIA_ERR_NONE) { media_content_error("media_svc_get_storage_id failed : %d", ret); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } - check_file = _media_util_check_file_exist(path); + check_file = _media_util_check_file_exist(repl_path); if (check_file == MEDIA_CONTENT_ERROR_NONE) { /* This means this path has to be inserted or refreshed */ - folder_path = g_path_get_dirname(path); + folder_path = g_path_get_dirname(repl_path); ret = _media_util_check_ignore_dir(folder_path, &ignore_dir); SAFE_FREE(folder_path); @@ -1118,15 +1122,15 @@ int media_content_scan_file(const char *path) media_svc_storage_type_e storage_type; - ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME)); + ret = media_svc_get_storage_type(repl_path, &storage_type, tzplatform_getuid(TZ_USER_NAME)); if (ret != MS_MEDIA_ERR_NONE) { - media_content_sec_error("media_svc_get_storage_type failed : %d (%s)", ret, path); + media_content_sec_error("media_svc_get_storage_type failed : %d (%s)", ret, repl_path); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } - ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), storage_id, path); + ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), storage_id, repl_path); if (ret == MS_MEDIA_ERR_NONE) { /* Refresh */ - ret = media_svc_refresh_item(_content_get_db_handle(), storage_id, storage_type, path, tzplatform_getuid(TZ_USER_NAME)); + ret = media_svc_refresh_item(_content_get_db_handle(), storage_id, storage_type, repl_path, tzplatform_getuid(TZ_USER_NAME)); if (ret != MS_MEDIA_ERR_NONE) { media_content_error("media_svc_refresh_item failed : %d", ret); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); @@ -1134,13 +1138,13 @@ int media_content_scan_file(const char *path) } else if (ret == MS_MEDIA_ERR_DB_NO_RECORD) { /* Insert */ - ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, storage_type, path, tzplatform_getuid(TZ_USER_NAME)); + ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, storage_type, repl_path, tzplatform_getuid(TZ_USER_NAME)); if (ret != MS_MEDIA_ERR_NONE) { if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) { - media_content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", path); + media_content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", repl_path); ret = MEDIA_CONTENT_ERROR_NONE; } else { - media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, path); + media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, repl_path); } return _content_error_capi(MEDIA_CONTENT_TYPE, ret); @@ -1155,7 +1159,7 @@ int media_content_scan_file(const char *path) } else { /* This means this path has to be deleted */ media_content_debug("This path doesn't exists in file system... So now start to delete it from DB"); - ret = media_svc_delete_item_by_path(_content_get_db_handle(), storage_id, path, tzplatform_getuid(TZ_USER_NAME)); + ret = media_svc_delete_item_by_path(_content_get_db_handle(), storage_id, repl_path, tzplatform_getuid(TZ_USER_NAME)); if (ret != MS_MEDIA_ERR_NONE) { media_content_error("media_svc_delete_item_by_path failed : %d", ret); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); @@ -1250,11 +1254,15 @@ int media_content_scan_folder(const char *path, bool is_recursive, media_scan_co int ret = MEDIA_CONTENT_ERROR_NONE; bool ignore_dir = FALSE; char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, }; + char repl_path[MAX_QUERY_SIZE] = {0, }; media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path"); + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); /* Temporary Code [remove after inserted gid patch by security part] */ - if (strncmp(path, "/opt/media", strlen("/opt/media")) == 0) { + if (strncmp(repl_path, "/opt/media", strlen("/opt/media")) == 0) { ret = __media_content_cynara_check("http://tizen.org/privilege/externalstorage"); media_content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission Denied"); } else { @@ -1264,12 +1272,12 @@ int media_content_scan_folder(const char *path, bool is_recursive, media_scan_co memset(storage_id, 0x00, sizeof(storage_id)); - ret = __media_content_check_dir(path); + ret = __media_content_check_dir(repl_path); media_content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission Denied"); if (ret == MEDIA_CONTENT_ERROR_NONE) { /* If directory exist check that's ignore directory or not*/ - ret = _media_util_check_ignore_dir(path, &ignore_dir); + ret = _media_util_check_ignore_dir(repl_path, &ignore_dir); media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path"); } else { /* This means this folder has to be deleted */ @@ -1283,10 +1291,10 @@ int media_content_scan_folder(const char *path, bool is_recursive, media_scan_co cb_data->callback = callback; cb_data->user_data = user_data; - ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id); + ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id); /*FIX ME. need to check ret value?*/ - ret = media_directory_scanning_async(path, storage_id, is_recursive, _media_content_scan_cb, cb_data, tzplatform_getuid(TZ_USER_NAME)); + ret = media_directory_scanning_async(repl_path, storage_id, is_recursive, _media_content_scan_cb, cb_data, tzplatform_getuid(TZ_USER_NAME)); if (ret != MS_MEDIA_ERR_NONE) media_content_error("media_directory_scanning_async failed : %d", ret); @@ -1330,8 +1338,15 @@ int media_content_scan_folder_v2(const char *path, bool is_recursive, media_scan int media_content_cancel_scan_folder(const char *path) { int ret = MEDIA_CONTENT_ERROR_NONE; + char repl_path[MAX_QUERY_SIZE] = {0, }; + + media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path"); + + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); - ret = media_directory_scanning_cancel(path, tzplatform_getuid(TZ_USER_NAME)); + ret = media_directory_scanning_cancel(repl_path, tzplatform_getuid(TZ_USER_NAME)); if (ret != MS_MEDIA_ERR_NONE) media_content_error("media_directory_scanning_async failed : %d", ret); diff --git a/src/media_db.c b/src/media_db.c index 6a6711e..3dda484 100755 --- a/src/media_db.c +++ b/src/media_db.c @@ -17,6 +17,7 @@ #include #include +#include static char * __media_db_get_group_name(media_group_e group); static int __media_db_make_query(filter_h filter, attribute_h attr, char *select_query, int select_query_size, char **condition_query, char **option_query); @@ -602,6 +603,8 @@ int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_d sqlite3_stmt *stmt = NULL; attribute_h attr = NULL; filter_s *_filter = (filter_s*)filter; + char *tmp_path = NULL; + char repl_path[MAX_QUERY_SIZE] = {0, }; attr = _content_get_alias_attirbute_handle(); memset(select_query, 0x00, sizeof(select_query)); @@ -630,7 +633,14 @@ int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_d } _folder->folder_id = g_strdup((const char *)sqlite3_column_text(stmt, 0)); +#ifdef _USE_TV_PROFILE _folder->path = g_strdup((const char *)sqlite3_column_text(stmt, 1)); +#else + tmp_path = g_strdup((const char *)sqlite3_column_text(stmt, 1)); + _media_content_rollback_path(tmp_path, repl_path); + _folder->path = g_strdup(repl_path); + SAFE_FREE(tmp_path); +#endif _folder->name = g_strdup((const char *)sqlite3_column_text(stmt, 2)); _folder->storage_type = (int)sqlite3_column_int(stmt, 3); _folder->modified_time = (int)sqlite3_column_int(stmt, 4); @@ -659,6 +669,8 @@ int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *us char *option_query = NULL; sqlite3_stmt *stmt = NULL; attribute_h attr = NULL; + char *tmp_path = NULL; + char repl_path[MAX_QUERY_SIZE] = {0, }; attr = _content_get_attirbute_handle(); memset(select_query, 0x00, sizeof(select_query)); @@ -687,7 +699,18 @@ int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *us _playlist->playlist_id = (int)sqlite3_column_int(stmt, 0); _playlist->name = g_strdup((const char *)sqlite3_column_text(stmt, 1)); +#ifdef _USE_TV_PROFILE _playlist->thumbnail_path = g_strdup((const char *)sqlite3_column_text(stmt, 2)); +#else + tmp_path = g_strdup((const char *)sqlite3_column_text(stmt, 2)); + if (STRING_VALID(tmp_path)) { + _media_content_rollback_path(tmp_path, repl_path); + _playlist->thumbnail_path = g_strdup(repl_path); + SAFE_FREE(tmp_path); + } else { + _playlist->thumbnail_path = NULL; + } +#endif if (callback((media_playlist_h)_playlist, user_data) == false) { media_playlist_destroy((media_playlist_h)_playlist); diff --git a/src/media_folder.c b/src/media_folder.c index 8bf71e9..6559108 100755 --- a/src/media_folder.c +++ b/src/media_folder.c @@ -343,6 +343,8 @@ int media_folder_get_folder_from_db(const char *folder_id, media_folder_h *folde int ret = MEDIA_CONTENT_ERROR_NONE; sqlite3_stmt *stmt = NULL; char select_query[DEFAULT_QUERY_SIZE]; + char *tmp_path = NULL; + char repl_path[MAX_QUERY_SIZE] = {0, }; if (!STRING_VALID(folder_id)) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -372,7 +374,15 @@ int media_folder_get_folder_from_db(const char *folder_id, media_folder_h *folde media_content_error("folder handle %x", _folder); _folder->folder_id = g_strdup((const char *)sqlite3_column_text(stmt, 0)); +#ifdef _USE_TV_PROFILE _folder->path = g_strdup((const char *)sqlite3_column_text(stmt, 1)); +#else + tmp_path = g_strdup((const char *)sqlite3_column_text(stmt, 1)); + _media_content_rollback_path(tmp_path, repl_path); + _folder->path = g_strdup(repl_path); + SAFE_FREE(tmp_path); +#endif + _folder->name = g_strdup((const char *)sqlite3_column_text(stmt, 2)); _folder->modified_time = (int)sqlite3_column_int(stmt, 3); _folder->storage_type = (int)sqlite3_column_int(stmt, 5); @@ -393,6 +403,7 @@ int media_folder_update_to_db(media_folder_h folder) int ret = MEDIA_CONTENT_ERROR_NONE; media_folder_s *_folder = (media_folder_s*)folder; char *sql = NULL; + char repl_path[MAX_QUERY_SIZE] = {0, }; if ((_folder == NULL) || (_folder->folder_id == NULL)) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -409,6 +420,8 @@ int media_folder_update_to_db(media_folder_h folder) char *name_pinyin = NULL; bool pinyin_support = FALSE; + ret = _media_content_replace_path(_folder->path, repl_path); + /* Set modified time */ time_t date; time(&date); @@ -420,7 +433,7 @@ int media_folder_update_to_db(media_folder_h folder) media_svc_get_pinyin(_folder->name, &name_pinyin); sql = sqlite3_mprintf("UPDATE %Q SET path='%q', name='%q', modified_time=%d, name_pinyin='%q' WHERE folder_uuid=%Q", - DB_TABLE_FOLDER, _folder->path, _folder->name, _folder->modified_time, name_pinyin, _folder->folder_id); + DB_TABLE_FOLDER, repl_path, _folder->name, _folder->modified_time, name_pinyin, _folder->folder_id); ret = _content_query_sql(sql); SQLITE3_SAFE_FREE(sql); @@ -435,7 +448,7 @@ int media_folder_update_to_db(media_folder_h folder) char dst_path_slash[MAX_QUERY_SIZE + 1] = {0, }; snprintf(src_path_slash, sizeof(src_path_slash), "%s/", g_src_path); - snprintf(dst_path_slash, sizeof(dst_path_slash), "%s/", _folder->path); + snprintf(dst_path_slash, sizeof(dst_path_slash), "%s/", repl_path); update_folder_path_sql = sqlite3_mprintf("UPDATE folder SET path = REPLACE( path, '%q', '%q');", src_path_slash, dst_path_slash); @@ -446,7 +459,7 @@ int media_folder_update_to_db(media_folder_h folder) return ret; } - ret = media_svc_rename_folder(_content_get_db_handle(), _folder->storage_uuid, g_src_path, _folder->path, tzplatform_getuid(TZ_USER_NAME)); + ret = media_svc_rename_folder(_content_get_db_handle(), _folder->storage_uuid, g_src_path, repl_path, tzplatform_getuid(TZ_USER_NAME)); SAFE_FREE(g_src_path); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); @@ -465,9 +478,14 @@ int media_folder_set_name(media_folder_h folder, const char *name) char *folder_path = NULL; char new_folder_path[MAX_QUERY_SIZE] = {0,}; bool ignore_dir = FALSE; + char repl_path[MAX_QUERY_SIZE] = {0, }; + + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(_folder->path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); - folder_path = g_path_get_dirname(_folder->path); - media_content_sec_debug("Existed Folder Path : %s", _folder->path); + folder_path = g_path_get_dirname(repl_path); + media_content_sec_debug("Existed Folder Path : %s", repl_path); snprintf(new_folder_path, sizeof(new_folder_path), "%s/%s", folder_path, name); media_content_sec_debug("New Path : %s", new_folder_path); @@ -479,12 +497,16 @@ int media_folder_set_name(media_folder_h folder, const char *name) } SAFE_FREE(g_src_path); - g_src_path = strdup(_folder->path); + g_src_path = strdup(repl_path); SAFE_FREE(_folder->path); SAFE_FREE(_folder->name); SAFE_FREE(folder_path); - _folder->path = strdup(new_folder_path); + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_rollback_path(new_folder_path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); + + _folder->path = strdup(repl_path); media_content_retvm_if(_folder->path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); } diff --git a/src/media_info.c b/src/media_info.c index 2108211..2741bab 100755 --- a/src/media_info.c +++ b/src/media_info.c @@ -264,9 +264,18 @@ static int __media_info_insert_batch(media_batch_insert_e insert_type, const cha void _media_info_item_get_detail(sqlite3_stmt* stmt, media_info_h media) { media_info_s *_media = (media_info_s*)media; + char *tmp_path = NULL; + char repl_path[MAX_QUERY_SIZE] = {0, }; _media->media_id = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_UUID)); +#ifdef _USE_TV_PROFILE _media->file_path = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_PATH)); +#else + tmp_path = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_PATH)); + _media_content_rollback_path(tmp_path, repl_path); + _media->file_path = g_strdup(repl_path); + SAFE_FREE(tmp_path); +#endif _media->display_name = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_FILE_NAME)); _media->media_type = (int)sqlite3_column_int(stmt, MEDIA_INFO_TYPE); _media->mime_type = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_MIME_TYPE)); @@ -397,63 +406,67 @@ int media_info_insert_to_db(const char *path, media_info_h *info) bool ignore_dir = FALSE; char *folder_path = NULL; char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, }; + char repl_path[MAX_QUERY_SIZE] = {0, }; int ret = MEDIA_CONTENT_ERROR_NONE; media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path"); media_content_retvm_if(info == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid info"); + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); - ret = _media_util_check_ignore_file(path, &ignore_file); + ret = _media_util_check_ignore_file(repl_path, &ignore_file); media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path"); - ret = _media_util_check_file_exist(path); + ret = _media_util_check_file_exist(repl_path); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - folder_path = g_path_get_dirname(path); + folder_path = g_path_get_dirname(repl_path); ret = _media_util_check_ignore_dir(folder_path, &ignore_dir); SAFE_FREE(folder_path); media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path"); memset(storage_id, 0x00, sizeof(storage_id)); - ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id); + ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id); if (ret != MS_MEDIA_ERR_NONE) { media_content_error("media_svc_get_storage_id failed : %d", ret); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } - ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), storage_id, path); + ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), storage_id, repl_path); if (ret == MS_MEDIA_ERR_DB_NO_RECORD) { - media_content_sec_debug("media_svc_check_item_exist_by_path : no record : %s", path); + media_content_sec_debug("media_svc_check_item_exist_by_path : no record : %s", repl_path); media_svc_storage_type_e storage_type = 0; - ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME)); + ret = media_svc_get_storage_type(repl_path, &storage_type, tzplatform_getuid(TZ_USER_NAME)); if (ret != MS_MEDIA_ERR_NONE) { media_content_sec_error("media_svc_get_storage_type failed : %d", ret); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } - ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, storage_type, path, tzplatform_getuid(TZ_USER_NAME)); + ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, storage_type, repl_path, tzplatform_getuid(TZ_USER_NAME)); if (ret != MS_MEDIA_ERR_NONE) { if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) { - media_content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", path); + media_content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", repl_path); ret = MEDIA_CONTENT_ERROR_NONE; } else { - media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, path); + media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, repl_path); } return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } } else if (ret != MS_MEDIA_ERR_NONE) { - media_content_sec_error("media_svc_check_item_exist_by_path failed : %d (%s)", ret, path); + media_content_sec_error("media_svc_check_item_exist_by_path failed : %d (%s)", ret, repl_path); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s)); media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); - ret = _media_info_get_media_info_from_db(path, DEFAULT_MEDIA_STORAGE_ID, (media_info_h)_media); + ret = _media_info_get_media_info_from_db(repl_path, DEFAULT_MEDIA_STORAGE_ID, (media_info_h)_media); *info = (media_info_h)_media; return ret; @@ -465,18 +478,64 @@ int media_info_insert_batch_to_db( media_insert_completed_cb completed_cb, void *user_data) { + char **repl_path_array = NULL; + int idx = 0; + int ret = MS_MEDIA_ERR_NONE; + char repl_path[MAX_QUERY_SIZE] = {0, }; + media_content_retvm_if(path_array == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path_array"); media_content_retvm_if(array_length <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid array_length"); - return __media_info_insert_batch(MEDIA_BATCH_INSERT_NORMAL, path_array, array_length, completed_cb, user_data); + repl_path_array = calloc(1, sizeof(char *) * array_length); + + for (idx = 0; idx < array_length; idx++) { + if (STRING_VALID(path_array[idx])) { + memset(repl_path, 0, sizeof(repl_path)); + _media_content_replace_path(path_array[idx], repl_path); + repl_path_array[idx] = strndup(repl_path, strlen(repl_path)); + } else { + media_content_error("path[%d] is invalid string", idx); + } + } + + ret = __media_info_insert_batch(MEDIA_BATCH_INSERT_NORMAL, (const char **)repl_path_array, array_length, completed_cb, user_data); + for (idx = 0; idx < array_length; idx++) + SAFE_FREE(repl_path_array[idx]); + + SAFE_FREE(repl_path_array); + + return ret; } int media_info_insert_burst_shot_to_db(const char **path_array, unsigned int array_length, media_insert_burst_shot_completed_cb callback, void *user_data) { + char **repl_path_array = NULL; + int idx = 0; + int ret = MS_MEDIA_ERR_NONE; + char repl_path[MAX_QUERY_SIZE] = {0, }; + media_content_retvm_if(path_array == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path_array"); media_content_retvm_if(array_length <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid array_length"); - return __media_info_insert_batch(MEDIA_BATCH_INSERT_BURSTSHOT, path_array, array_length, callback, user_data); + repl_path_array = calloc(1, sizeof(char *) * array_length); + + for (idx = 0; idx < array_length; idx++) { + if (STRING_VALID(path_array[idx])) { + memset(repl_path, 0, sizeof(repl_path)); + _media_content_replace_path(path_array[idx], repl_path); + repl_path_array[idx] = strndup(repl_path, strlen(repl_path)); + } else { + media_content_error("path[%d] is invalid string", idx); + } + } + + ret = __media_info_insert_batch(MEDIA_BATCH_INSERT_BURSTSHOT, (const char **)repl_path_array, array_length, callback, user_data); + for (idx = 0; idx < array_length; idx++) + SAFE_FREE(repl_path_array[idx]); + + SAFE_FREE(repl_path_array); + + return ret; } #ifdef _USE_SENIOR_MODE @@ -2790,6 +2849,7 @@ int media_info_refresh_metadata_to_db(const char *media_id) char *file_path = NULL; media_content_storage_e storage_type = 0; char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, }; + char repl_path[MAX_QUERY_SIZE] = {0, }; if (!STRING_VALID(media_id)) { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -2819,8 +2879,10 @@ int media_info_refresh_metadata_to_db(const char *media_id) media_info_destroy(media); return ret; } + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(file_path, repl_path); - ret = _media_util_check_file_exist(file_path); + ret = _media_util_check_file_exist(repl_path); if (ret != MEDIA_CONTENT_ERROR_NONE) { SAFE_FREE(file_path); media_info_destroy(media); @@ -2828,7 +2890,7 @@ int media_info_refresh_metadata_to_db(const char *media_id) } memset(storage_id, 0x00, sizeof(storage_id)); - ret = media_svc_get_storage_id(_content_get_db_handle(), file_path, storage_id); + ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id); if (ret != MS_MEDIA_ERR_NONE) { media_content_error("media_svc_get_storage_id failed : %d", ret); SAFE_FREE(file_path); @@ -2836,7 +2898,7 @@ int media_info_refresh_metadata_to_db(const char *media_id) return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } - ret = media_svc_refresh_item(_content_get_db_handle(), storage_id, storage_type, file_path, tzplatform_getuid(TZ_USER_NAME)); + ret = media_svc_refresh_item(_content_get_db_handle(), storage_id, storage_type, repl_path, tzplatform_getuid(TZ_USER_NAME)); if (ret != MS_MEDIA_ERR_NONE) ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret); @@ -2855,44 +2917,52 @@ int media_info_move_to_db(media_info_h media, const char* dst_path) media_svc_storage_type_e src_storage_type = 0; media_svc_storage_type_e dst_storage_type = 0; char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, }; + char repl_path[MAX_QUERY_SIZE] = {0, }; + char org_repl_path[MAX_QUERY_SIZE] = {0, }; media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media"); media_content_retvm_if(!STRING_VALID(dst_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid dst_path"); + memset(repl_path, 0, sizeof(repl_path)); + memset(org_repl_path, 0, sizeof(org_repl_path)); + ret = _media_content_replace_path(dst_path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); media_info_s *_media = (media_info_s*)media; - ret = _media_util_check_ignore_file(dst_path, &ignore_file); + ret = _media_util_check_ignore_file(repl_path, &ignore_file); media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path"); + ret = _media_content_replace_path(_media->file_path, org_repl_path); + media_content_retvm_if(!STRING_VALID(org_repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); - ret = _media_util_check_file_exist(dst_path); + ret = _media_util_check_file_exist(repl_path); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - folder_path = g_path_get_dirname(dst_path); + folder_path = g_path_get_dirname(repl_path); ret = _media_util_check_ignore_dir(folder_path, &ignore_dir); SAFE_FREE(folder_path); media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path"); - ret = media_svc_get_storage_type(_media->file_path, &src_storage_type, tzplatform_getuid(TZ_USER_NAME)); + ret = media_svc_get_storage_type(org_repl_path, &src_storage_type, tzplatform_getuid(TZ_USER_NAME)); if (ret != MS_MEDIA_ERR_NONE) { media_content_sec_error("media_svc_get_storage_type failed : %d", ret); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } - ret = media_svc_get_storage_type(dst_path, &dst_storage_type, tzplatform_getuid(TZ_USER_NAME)); + ret = media_svc_get_storage_type(repl_path, &dst_storage_type, tzplatform_getuid(TZ_USER_NAME)); if (ret != MS_MEDIA_ERR_NONE) { media_content_sec_error("media_svc_get_storage_type failed : %d", ret); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } memset(storage_id, 0x00, sizeof(storage_id)); - ret = media_svc_get_storage_id(_content_get_db_handle(), _media->file_path, storage_id); + ret = media_svc_get_storage_id(_content_get_db_handle(), org_repl_path, storage_id); if (ret != MS_MEDIA_ERR_NONE) { media_content_error("media_svc_get_storage_id failed : %d", ret); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } - ret = media_svc_move_item(_content_get_db_handle(), storage_id, src_storage_type, _media->file_path, dst_storage_type, dst_path, tzplatform_getuid(TZ_USER_NAME)); + ret = media_svc_move_item(_content_get_db_handle(), storage_id, src_storage_type, org_repl_path, dst_storage_type, repl_path, tzplatform_getuid(TZ_USER_NAME)); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } @@ -2900,9 +2970,14 @@ int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb { int ret = MEDIA_CONTENT_ERROR_NONE; static unsigned int req_id = 0; + char repl_path[MAX_QUERY_SIZE] = {0, }; media_info_s *_media = (media_info_s*)media; if (_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path)) { + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(_media->file_path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); + media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s*)calloc(1, sizeof(media_thumbnail_cb_s)); media_content_retvm_if(_thumb_cb == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); req_id++; @@ -2912,7 +2987,7 @@ int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb _thumb_cb->user_data = user_data; _thumb_cb->thumbnail_completed_cb = callback; - ret = thumbnail_request_from_db_async(_media->request_id, _media->file_path, (ThumbFunc)__media_info_thumbnail_completed_cb, (void *)_thumb_cb, tzplatform_getuid(TZ_USER_NAME)); + ret = thumbnail_request_from_db_async(_media->request_id, repl_path, (ThumbFunc)__media_info_thumbnail_completed_cb, (void *)_thumb_cb, tzplatform_getuid(TZ_USER_NAME)); ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret); } else { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -2926,9 +3001,14 @@ int media_info_cancel_thumbnail(media_info_h media) { int ret = MEDIA_CONTENT_ERROR_NONE; media_info_s *_media = (media_info_s*)media; + char repl_path[MAX_QUERY_SIZE] = {0, }; if (_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path) && _media->request_id > 0) { - ret = thumbnail_request_cancel_media(_media->request_id, _media->file_path); + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(_media->file_path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); + + ret = thumbnail_request_cancel_media(_media->request_id, repl_path); ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret); } else { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -2943,6 +3023,7 @@ int media_info_start_face_detection(media_info_h media, media_face_detection_com int ret = MEDIA_CONTENT_ERROR_NONE; static unsigned int req_id = 0; media_info_s *_media = (media_info_s*)media; + char repl_path[MAX_QUERY_SIZE] = {0, }; if (!__media_info_isFaceRecognition_feature_supported()) { media_content_error("NOT_SUPPORTED(0x%08x)", MEDIA_CONTENT_ERROR_NOT_SUPPORTED); @@ -2950,6 +3031,9 @@ int media_info_start_face_detection(media_info_h media, media_face_detection_com } if (_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path)) { + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(_media->file_path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); media_face_cb_s *_face_cb = (media_face_cb_s*)calloc(1, sizeof(media_face_cb_s)); media_content_retvm_if(_face_cb == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); req_id++; @@ -2959,7 +3043,7 @@ int media_info_start_face_detection(media_info_h media, media_face_detection_com _face_cb->user_data = user_data; _face_cb->face_completed_cb = callback; - ret = dcm_request_extract_face_async(_media->face_request_id, _media->file_path, (FaceFunc)__media_info_face_completed_cb, (void *)_face_cb, tzplatform_getuid(TZ_USER_NAME)); + ret = dcm_request_extract_face_async(_media->face_request_id, repl_path, (FaceFunc)__media_info_face_completed_cb, (void *)_face_cb, tzplatform_getuid(TZ_USER_NAME)); ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret); } else { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -2973,6 +3057,7 @@ int media_info_cancel_face_detection(media_info_h media) { int ret = MEDIA_CONTENT_ERROR_NONE; media_info_s *_media = (media_info_s*)media; + char repl_path[MAX_QUERY_SIZE] = {0, }; if (!__media_info_isFaceRecognition_feature_supported()) { media_content_error("NOT_SUPPORTED(0x%08x)", MEDIA_CONTENT_ERROR_NOT_SUPPORTED); @@ -2980,7 +3065,10 @@ int media_info_cancel_face_detection(media_info_h media) } if (_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path) && _media->face_request_id > 0) { - ret = dcm_request_cancel_face(_media->face_request_id, _media->file_path); + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(_media->file_path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); + ret = dcm_request_cancel_face(_media->face_request_id, repl_path); ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret); } else { media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); @@ -2993,11 +3081,21 @@ int media_info_cancel_face_detection(media_info_h media) static int __media_info_map_data_usr_to_svc(media_info_s *media, media_svc_content_info_s **service_content, media_content_storage_e storage_type) { media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle"); + char repl_path[MAX_QUERY_SIZE] = {0, }; + char *tmp_path = NULL; media_svc_content_info_s *svc_content_info = calloc(1, sizeof(media_svc_content_info_s)); media_content_retvm_if(svc_content_info == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + memset(repl_path, 0, sizeof(repl_path)); +#ifdef _USE_TV_PROFILE svc_content_info->path = g_strdup(media->file_path); +#else + tmp_path = g_strdup(media->file_path); + _media_content_replace_path(tmp_path, repl_path); + svc_content_info->path = g_strdup(repl_path); + SAFE_FREE(tmp_path); +#endif svc_content_info->file_name = g_strdup(media->display_name); svc_content_info->media_type = media->media_type; svc_content_info->mime_type = g_strdup(media->mime_type); @@ -3337,6 +3435,7 @@ static int __media_info_destroy(media_info_h media) int media_info_insert_to_db_with_data(media_info_h media) { int ret = MEDIA_CONTENT_ERROR_NONE; + char repl_path[MAX_QUERY_SIZE] = {0, }; media_info_s *_media = (media_info_s*)media; @@ -3377,7 +3476,10 @@ int media_info_insert_to_db_with_data(media_info_h media) SAFE_FREE(svc_content_info); /*Fill out the handle*/ - char *media_file_path = g_strdup(_media->file_path); + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(_media->file_path, repl_path); + char *media_file_path = g_strdup(repl_path); + char *media_string_uuid = g_strdup(_media->storage_uuid); __media_info_destroy(media); @@ -3397,34 +3499,38 @@ int media_info_create(const char *path, media_info_h *media) char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, }; media_svc_storage_type_e storage_type = 0; bool ignore_file = FALSE; + char repl_path[MAX_QUERY_SIZE] = {0, }; media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path"); media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media"); + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); - ret = _media_util_check_ignore_file(path, &ignore_file); + ret = _media_util_check_ignore_file(repl_path, &ignore_file); media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path"); memset(storage_id, 0x00, sizeof(storage_id)); - if (STRING_VALID(MEDIA_ROOT_PATH_CLOUD) && (strstr(path, MEDIA_ROOT_PATH_CLOUD) == NULL)) { + if (STRING_VALID(MEDIA_ROOT_PATH_CLOUD) && (strstr(repl_path, MEDIA_ROOT_PATH_CLOUD) == NULL)) { bool ignore_dir = FALSE; char *folder_path = NULL; - ret = _media_util_check_file_exist(path); + ret = _media_util_check_file_exist(repl_path); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - folder_path = g_path_get_dirname(path); + folder_path = g_path_get_dirname(repl_path); ret = _media_util_check_ignore_dir(folder_path, &ignore_dir); SAFE_FREE(folder_path); media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path"); - ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id); + ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id); if (ret != MS_MEDIA_ERR_NONE) { media_content_error("media_svc_get_storage_id failed : %d", ret); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } - ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME)); + ret = media_svc_get_storage_type(repl_path, &storage_type, tzplatform_getuid(TZ_USER_NAME)); if (ret != MS_MEDIA_ERR_NONE) { media_content_sec_error("media_svc_get_storage_type failed : %d", ret); return _content_error_capi(MEDIA_CONTENT_TYPE, ret); diff --git a/src/media_playlist.c b/src/media_playlist.c index 3eecc3b..fd21668 100755 --- a/src/media_playlist.c +++ b/src/media_playlist.c @@ -19,6 +19,8 @@ #include #include #include +#include + #define PLAYLIST_ARRAY_SIZE 20 #define PLAYLIST_ARRAY_EXPAND 10 @@ -232,6 +234,7 @@ static int __media_playlist_import_item_from_file(const char* playlist_path, cha char *buf = NULL; char *tmp_buf = NULL; char *tmp_str = NULL; + char repl_item[MAX_QUERY_SIZE] = {0, }; FILE *fp = NULL; long int file_size = 0; @@ -294,7 +297,11 @@ static int __media_playlist_import_item_from_file(const char* playlist_path, cha break; } - tmp_str_len = strlen(tmp_str); + memset(repl_item, 0, sizeof(repl_item)); + _media_content_replace_path(tmp_str, repl_item); + tmp_str_len = strlen(repl_item); + SAFE_FREE(tmp_str); + tmp_str = strndup(repl_item, tmp_str_len); if (tmp_str[0] != '#') { if (!(current_index < (current_max_size - 1))) { @@ -690,14 +697,19 @@ int media_playlist_set_thumbnail_path(media_playlist_h playlist, const char *pat { int ret = MEDIA_CONTENT_ERROR_NONE; media_playlist_s *_playlist = (media_playlist_s*)playlist; + char repl_path[MAX_QUERY_SIZE] = {0, }; if (_playlist != NULL && STRING_VALID(path)) { SAFE_FREE(_playlist->thumbnail_path); + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); + media_playlist_item_s *item = (media_playlist_item_s*)calloc(1, sizeof(media_playlist_item_s)); media_content_retvm_if(item == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); - item->thumbnail_path = strdup(path); + item->thumbnail_path = strdup(repl_path); item->function = MEDIA_PLAYLIST_UPDATE_THUMBNAIL_PATH; if (item->thumbnail_path == NULL) { SAFE_FREE(item); @@ -865,14 +877,18 @@ int media_playlist_import_from_file(const char *path, const char *playlist_name, char** import_item_list = NULL; int import_item_count = 0; int idx; + char repl_path[MAX_QUERY_SIZE] = {0, }; media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path"); media_content_retvm_if(!STRING_VALID(playlist_name), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid playlist_name"); + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); ret = media_playlist_insert_to_db(playlist_name, playlist); media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "media_playlist_insert_to_db fail"); - ret = __media_playlist_import_item_from_file(path, &import_item_list, &import_item_count); + ret = __media_playlist_import_item_from_file(repl_path, &import_item_list, &import_item_count); if (ret != MEDIA_CONTENT_ERROR_NONE) { __media_playlist_destroy_import_item(import_item_list, import_item_count); media_content_error("Fail to get playlist from file"); @@ -943,15 +959,20 @@ int media_playlist_export_to_file(media_playlist_h playlist, const char* path) media_playlist_s *_playlist = (media_playlist_s*)playlist; GList *item_list = NULL; unsigned int idx = 0; + char repl_path[MAX_QUERY_SIZE] = {0, }; + char repl_item[MAX_QUERY_SIZE] = {0, }; media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path"); media_content_retvm_if(_playlist == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid playlist"); media_content_retvm_if(_playlist->playlist_id <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid playlist_id"); + memset(repl_path, 0, sizeof(repl_path)); + ret = _media_content_replace_path(path, repl_path); + media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); ret = _media_db_get_playlist_item(_playlist->playlist_id, NULL, __media_playlist_member_cb, &item_list); media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "_media_db_get_playlist_item fail"); - ret = __media_playlist_reset_file(path); + ret = __media_playlist_reset_file(repl_path); if (ret != MEDIA_CONTENT_ERROR_NONE) { g_list_free_full(item_list, __media_playlist_destroy_export_item); media_content_error("Fail to init playlist file"); @@ -960,7 +981,10 @@ int media_playlist_export_to_file(media_playlist_h playlist, const char* path) for (idx = 0; idx < g_list_length(item_list); idx++) { char *item = g_list_nth_data(item_list, idx); - ret = __media_playlist_append_to_file(path, item); + memset(repl_item, 0, sizeof(repl_item)); + ret = _media_content_rollback_path(item, repl_item); + + ret = __media_playlist_append_to_file(repl_path, repl_item); if (ret != MEDIA_CONTENT_ERROR_NONE) { g_list_free_full(item_list, __media_playlist_destroy_export_item); media_content_error("Fail to export paths into file"); diff --git a/src/media_util_private.c b/src/media_util_private.c index 7764bc0..fa7b5c3 100755 --- a/src/media_util_private.c +++ b/src/media_util_private.c @@ -22,6 +22,7 @@ #include #include #include +#include #ifdef _USE_TV_PROFILE #include #endif @@ -173,7 +174,14 @@ int _media_util_check_ignore_dir(const char *dir_path, bool *ignore) int _media_content_replace_path(const char *path, char *replace_path) { - const char *old_path = "/opt/usr/media"; + int ret = MEDIA_CONTENT_ERROR_NONE; + char *old_path = NULL; + + ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &old_path); + if (ret != STORAGE_ERROR_NONE) { + media_content_error("storage_get_directory failed"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } if (strncmp(path, old_path, strlen(old_path)) == 0) { media_content_sec_debug("Old path[%s]", path); @@ -182,6 +190,36 @@ int _media_content_replace_path(const char *path, char *replace_path) snprintf(replace_path, MAX_QUERY_SIZE, "%s", path); } + SAFE_FREE(old_path); + + if (!STRING_VALID(replace_path)) { + media_content_error("replace failed"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + + return MEDIA_CONTENT_ERROR_NONE; +} + +int _media_content_rollback_path(const char *path, char *replace_path) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *old_path = NULL; + + ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &old_path); + if (ret != STORAGE_ERROR_NONE) { + media_content_error("storage_get_directory failed"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } + + if (strncmp(path, tzplatform_getenv(TZ_USER_CONTENT), strlen(tzplatform_getenv(TZ_USER_CONTENT))) == 0) { + media_content_sec_debug("new path[%s]", path); + snprintf(replace_path, MAX_QUERY_SIZE, "%s%s", old_path, path + strlen(tzplatform_getenv(TZ_USER_CONTENT))); + } else { + snprintf(replace_path, MAX_QUERY_SIZE, "%s", path); + } + + SAFE_FREE(old_path); + if (!STRING_VALID(replace_path)) { media_content_error("replace failed"); return MEDIA_CONTENT_ERROR_INVALID_OPERATION; -- 2.7.4