diff options
-rw-r--r-- | include/media_info_private.h | 12 | ||||
-rw-r--r-- | include_product/media_info_private.h | 12 | ||||
-rw-r--r-- | packaging/capi-content-media-content.spec | 2 | ||||
-rwxr-xr-x | src/media_bookmark.c | 4 | ||||
-rwxr-xr-x | src/media_db.c | 8 | ||||
-rwxr-xr-x | src/media_folder.c | 3 | ||||
-rw-r--r-- | src/media_info.c | 16 | ||||
-rwxr-xr-x | src/media_util_private.c | 28 | ||||
-rwxr-xr-x | test/media-content_test.c | 1 |
9 files changed, 33 insertions, 53 deletions
diff --git a/include/media_info_private.h b/include/media_info_private.h index e7675a4..2dc8479 100644 --- a/include/media_info_private.h +++ b/include/media_info_private.h @@ -56,15 +56,9 @@ extern "C" { #define LOG_TAG "CAPI_CONTENT_MEDIA_CONTENT" -#define SAFE_STRLCPY(dst, src, n) g_strlcpy(dst, src, n); -#define SAFE_STRLCAT(dst, src, n) g_strlcat(dst, src, n); -#define SAFE_FREE(src) {if (src) {free(src); src = NULL; } } -#define STRING_VALID(str) ((str != NULL && strlen(str) > 0) ? TRUE : FALSE) -#define SQLITE3_FINALIZE(x) {if (x != NULL) sqlite3_finalize(x); } -#define SQLITE3_SAFE_FREE(x) {if (x != NULL) {sqlite3_free(x); x = NULL; } } - -#define MEDIA_CONTENT_INSERT_FILES_PATH "/tmp" -#define MEDIA_CONTENT_EMPTY_STRING "" +#define STRING_VALID(str) (str && strlen(str) > 0) +#define SQLITE3_FINALIZE(x) {if (x) sqlite3_finalize(x); } +#define SQLITE3_SAFE_FREE(x) {if (x) {sqlite3_free(x); x = NULL; } } #define MAX_QUERY_SIZE 4096 #define MAX_PATH_LEN 4096 diff --git a/include_product/media_info_private.h b/include_product/media_info_private.h index 6792781..7a7afc3 100644 --- a/include_product/media_info_private.h +++ b/include_product/media_info_private.h @@ -59,15 +59,9 @@ extern "C" { #define LOG_TAG "CAPI_CONTENT_MEDIA_CONTENT" -#define SAFE_STRLCPY(dst, src, n) g_strlcpy(dst, src, n); -#define SAFE_STRLCAT(dst, src, n) g_strlcat(dst, src, n); -#define SAFE_FREE(src) {if (src) {free(src); src = NULL; } } -#define STRING_VALID(str) ((str != NULL && strlen(str) > 0) ? TRUE : FALSE) -#define SQLITE3_FINALIZE(x) {if (x != NULL) sqlite3_finalize(x); } -#define SQLITE3_SAFE_FREE(x) {if (x != NULL) {sqlite3_free(x); x = NULL; } } - -#define MEDIA_CONTENT_INSERT_FILES_PATH "/tmp" -#define MEDIA_CONTENT_EMPTY_STRING "" +#define STRING_VALID(str) (str && strlen(str) > 0) +#define SQLITE3_FINALIZE(x) {if (x) sqlite3_finalize(x); } +#define SQLITE3_SAFE_FREE(x) {if (x) {sqlite3_free(x); x = NULL; } } #define MAX_QUERY_SIZE 4096 #define MAX_PATH_LEN 4096 diff --git a/packaging/capi-content-media-content.spec b/packaging/capi-content-media-content.spec index 0fac5ef..f7334e4 100644 --- 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.5.0 +Version: 0.5.1 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/media_bookmark.c b/src/media_bookmark.c index b98bb39..fdc16e0 100755 --- a/src/media_bookmark.c +++ b/src/media_bookmark.c @@ -50,7 +50,7 @@ int media_bookmark_insert_to_db(const char *media_id, time_t time, const char *t content_retip_if_fail(STRING_VALID(media_id)); - sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, media_id, time, thumbnail_path, MEDIA_CONTENT_EMPTY_STRING); + sql = sqlite3_mprintf(INSERT_BOOKMARK_TO_BOOKMARK, media_id, time, thumbnail_path, ""); ret = _content_query_sql(sql); SQLITE3_SAFE_FREE(sql); @@ -183,7 +183,7 @@ int media_bookmark_set_name(media_bookmark_h bookmark, const char *name) content_retip_if_fail(bookmark); g_free(_bookmark->name); - _bookmark->name = g_strdup(STRING_VALID(name) ? name : MEDIA_CONTENT_EMPTY_STRING); + _bookmark->name = g_strdup(STRING_VALID(name) ? name : ""); return MEDIA_CONTENT_ERROR_NONE; } diff --git a/src/media_db.c b/src/media_db.c index 112d846..62f001f 100755 --- a/src/media_db.c +++ b/src/media_db.c @@ -295,7 +295,7 @@ int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *g g_free(option_query); option_query = tmp_option; } else { - SAFE_STRLCAT(select_query, ")", sizeof(select_query)); + g_strlcat(select_query, ")", sizeof(select_query)); } ret = _content_query_prepare(select_query, condition_query, option_query, &stmt); @@ -1270,7 +1270,7 @@ int _media_db_get_media_group_item_count(const char *group_name, filter_h filter g_free(option_query); option_query = tmp_option; } else { - SAFE_STRLCAT(select_query, ")", sizeof(select_query)); + g_strlcat(select_query, ")", sizeof(select_query)); } ret = _content_query_prepare(select_query, condition_query, option_query, &stmt); @@ -1480,7 +1480,7 @@ int _media_db_get_pvr(filter_h filter, media_pvr_cb callback, void *user_data) if (_filter && STRING_VALID(_filter->storage_id)) snprintf(select_query, sizeof(select_query), SELECT_PVR_LIST_BY_STORAGE_ID, _filter->storage_id); else - SAFE_STRLCAT(select_query, SELECT_PVR_LIST, sizeof(select_query)); + g_strlcat(select_query, SELECT_PVR_LIST, sizeof(select_query)); ret = __media_db_make_query(filter, &condition_query, &option_query); content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); @@ -1553,7 +1553,7 @@ int _media_db_get_uhd(filter_h filter, media_uhd_cb callback, void *user_data) if (_filter && STRING_VALID(_filter->storage_id)) snprintf(select_query, sizeof(select_query), SELECT_UHD_LIST_BY_STORAGE_ID, _filter->storage_id); else - SAFE_STRLCAT(select_query, SELECT_UHD_LIST, sizeof(select_query)); + g_strlcat(select_query, SELECT_UHD_LIST, sizeof(select_query)); ret = __media_db_make_query(filter, &condition_query, &option_query); content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); diff --git a/src/media_folder.c b/src/media_folder.c index 6091798..2d51788 100755 --- a/src/media_folder.c +++ b/src/media_folder.c @@ -217,7 +217,8 @@ 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, _content_get_uid()); - SAFE_FREE(g_src_path); + g_free(g_src_path); + g_src_path = NULL; return _content_error_capi(ret); } diff --git a/src/media_info.c b/src/media_info.c index 15b625a..37d3199 100644 --- a/src/media_info.c +++ b/src/media_info.c @@ -76,7 +76,7 @@ static int __media_info_insert_batch(const char **path_array, int nwrites = 0; for (idx = 0; idx < BATCH_REQUEST_MAX; idx++) { - snprintf(list_path, BATCH_REQUEST_FILE_LEN, "%s/request-%ld-%d", MEDIA_CONTENT_INSERT_FILES_PATH, media_content_gettid(), idx); + snprintf(list_path, BATCH_REQUEST_FILE_LEN, "/tmp/request-%ld-%d", media_content_gettid(), idx); if (g_file_test(list_path, G_FILE_TEST_EXISTS)) { memset(list_path, 0x00, BATCH_REQUEST_FILE_LEN); @@ -1319,13 +1319,13 @@ int media_info_move_to_db(media_info_h media, const char* dst_path) media_info_s *_media = (media_info_s*)media; /* If dst_path is folder, append file_name */ - SAFE_STRLCPY(repl_path, dst_path, MAX_PATH_LEN); + g_strlcpy(repl_path, dst_path, MAX_PATH_LEN); if (g_file_test(repl_path, G_FILE_TEST_IS_DIR)) { if (repl_path[strlen(repl_path) - 1] != '/') - SAFE_STRLCAT(repl_path, "/", MAX_PATH_LEN); + g_strlcat(repl_path, "/", MAX_PATH_LEN); - SAFE_STRLCAT(repl_path, _media->display_name, MAX_PATH_LEN); + g_strlcat(repl_path, _media->display_name, MAX_PATH_LEN); } /* If the two paths are the same, do nothing */ @@ -1350,13 +1350,13 @@ int media_info_move_to_db(media_info_h media, const char* dst_path) ret = _media_info_get_media_info_from_db(repl_path, (media_info_h)_info); #endif - SAFE_FREE(_media->display_name); + g_free(_media->display_name); _media->display_name = g_strdup(_info->display_name); - SAFE_FREE(_media->file_path); + g_free(_media->file_path); _media->file_path = g_strdup(_info->file_path); - SAFE_FREE(_media->storage_uuid); + g_free(_media->storage_uuid); _media->storage_uuid = g_strdup(_info->storage_uuid); - SAFE_FREE(_media->thumbnail_path); + g_free(_media->thumbnail_path); _media->thumbnail_path = NULL; media_info_destroy((media_info_h)_info); diff --git a/src/media_util_private.c b/src/media_util_private.c index 3ccf413..552a679 100755 --- a/src/media_util_private.c +++ b/src/media_util_private.c @@ -80,9 +80,8 @@ int _media_util_get_file_time(const char *path) bool _media_util_is_ignorable_file(const char *path) { - char *tmp_path = NULL; + g_autofree gchar *real = NULL; g_autofree gchar *org_path = NULL; - #ifndef _USE_TVPD_MODE char replace[MAX_PATH_LEN] = {0, }; #endif @@ -99,34 +98,30 @@ bool _media_util_is_ignorable_file(const char *path) content_retvm_if(strstr(path, "/."), true, "hidden path"); /* Check symbolic directory */ - tmp_path = realpath(path, NULL); + real = realpath(path, NULL); /* Get trimmed path */ org_path = g_canonicalize_filename(path, NULL); #ifdef _USE_TVPD_MODE - if (g_strcmp0(tmp_path, org_path) != 0) { + if (g_strcmp0(real, org_path) != 0) { content_error("symbolic link(directory)"); - SAFE_FREE(tmp_path); return true; } #else - if (g_str_has_prefix(tmp_path, tzplatform_getenv(TZ_SYS_MEDIASHARED))) { + if (g_str_has_prefix(real, tzplatform_getenv(TZ_SYS_MEDIASHARED))) { /* If shared directory, it should be change path to TZ_USER_SHARE from realpath */ - snprintf(replace, MAX_PATH_LEN, "%s%s", tzplatform_getenv(TZ_USER_MEDIASHARED), tmp_path + strlen(tzplatform_getenv(TZ_SYS_MEDIASHARED))); + snprintf(replace, MAX_PATH_LEN, "%s%s", tzplatform_getenv(TZ_USER_MEDIASHARED), real + strlen(tzplatform_getenv(TZ_SYS_MEDIASHARED))); if (g_strcmp0(replace, org_path) != 0) { content_error("symbolic link(directory)"); - SAFE_FREE(tmp_path); return true; } } else { - if (g_strcmp0(tmp_path, org_path) != 0) { + if (g_strcmp0(real, org_path) != 0) { content_error("symbolic link(directory)"); - SAFE_FREE(tmp_path); return true; } } #endif - SAFE_FREE(tmp_path); return false; } @@ -165,9 +160,9 @@ bool _media_util_is_ignorable_dir(const char *dir_path) char *leaf_path = NULL; char search_path[MAX_PATH_LEN] = {0, }; - SAFE_STRLCPY(search_path, dir_path, sizeof(search_path)); + g_strlcpy(search_path, dir_path, sizeof(search_path)); - while (STRING_VALID(search_path)) { + while (strlen(search_path) > 0) { if (__is_scan_ignore_exist(search_path)) return true; @@ -184,7 +179,7 @@ bool _media_util_is_ignorable_dir(const char *dir_path) int _media_content_check_dir(const char *path) { DIR *dp = NULL; - char *real = NULL; + g_autofree gchar *real = NULL; g_autofree gchar *origin = NULL; #ifndef _USE_TVPD_MODE char result_path[MAX_PATH_LEN] = {0, }; @@ -210,7 +205,6 @@ int _media_content_check_dir(const char *path) #ifdef _USE_TVPD_MODE if (g_strcmp0(real, origin) != 0) { content_error("symbolic link(directory)"); - SAFE_FREE(real); return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } #else @@ -219,19 +213,15 @@ int _media_content_check_dir(const char *path) snprintf(result_path, MAX_PATH_LEN, "%s%s", tzplatform_getenv(TZ_USER_MEDIASHARED), real + strlen(tzplatform_getenv(TZ_SYS_MEDIASHARED))); if (g_strcmp0(result_path, origin) != 0) { content_error("symbolic link(directory)"); - SAFE_FREE(real); return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } } else { if (g_strcmp0(real, origin) != 0) { content_error("symbolic link(directory)"); - SAFE_FREE(real); return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } } #endif - SAFE_FREE(real); - return MEDIA_CONTENT_ERROR_NONE; } diff --git a/test/media-content_test.c b/test/media-content_test.c index b053f0f..1992911 100755 --- a/test/media-content_test.c +++ b/test/media-content_test.c @@ -32,6 +32,7 @@ static GMainLoop *g_loop = NULL; #define test_audio_id "3304285f-1070-41af-8b4e-f0086cc768f3" #define test_video_id "53c43e7e-53d2-4194-80a6-55d5dcde0def" #define test_image_id "db1c184c-6f31-43b4-b924-8c00ac5b6197" +#define SAFE_FREE(src) { if (src) { free(src); src = NULL; } } static void get_audio_meta(media_info_h media) { |