Add define MAX_PATH_LEN and rearrage MAX_QUERY_SIZE related code 79/125379/1
authorHaejeong Kim <backto.kim@samsung.com>
Mon, 17 Apr 2017 06:53:30 +0000 (15:53 +0900)
committerHaejeong Kim <backto.kim@samsung.com>
Mon, 17 Apr 2017 06:53:30 +0000 (15:53 +0900)
Change-Id: If4c9cd98bd9c882b49970c23058bdcea3a881692

include/media_info_private.h
packaging/capi-content-media-content.spec
src/media_content.c
src/media_db.c
src/media_filter.c
src/media_folder.c
src/media_info.c
src/media_playlist.c
src/media_util_private.c

index 5678989..8447e34 100755 (executable)
@@ -69,6 +69,7 @@ extern "C" {
 #define MEDIA_CONTENT_EMPTY_STRING                     ""
 
 #define MAX_QUERY_SIZE 4096
+#define MAX_PATH_LEN 4096
 #define DEFAULT_QUERY_SIZE 1024
 #define COLLATE_STR_SIZE 32
 #define MEDIA_CONTENT_UUID_SIZE        36
index edd7bb1..1d2f70b 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-content-media-content
 Summary:    A Media content library in Tizen Native API
-Version:    0.3.4
+Version:    0.3.5
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 43a0164..2c79406 100755 (executable)
@@ -792,9 +792,9 @@ int _content_query_prepare(sqlite3_stmt **stmt, char *select_query, char *condit
 
        /*query = sqlite3_mprintf("%s %s %s", select_query, condition_query, option_query);*/
        len = snprintf(query, sizeof(query), "%s %s %s", select_query, condition_query, option_query);
-       if (len > 0 && len < MAX_QUERY_SIZE)
+       if (len > 0 && len < sizeof(query))
                query[len] = '\0';
-       else if (len >= MAX_QUERY_SIZE)
+       else if (len >= sizeof(query))
                query[MAX_QUERY_SIZE -1] = '\0';
        else {
                media_content_error("snprintf failed");
@@ -848,9 +848,9 @@ int _content_query_prepare_by_union_select(sqlite3_stmt **stmt, char *select_que
 
        len = snprintf(query, sizeof(query), "SELECT * FROM (%s %s %s) as table1 UNION ALL SELECT * FROM (%s %s %s) as table2",
                        select_query1, condition_query1, option_query1, select_query2, condition_query2, option_query2);
-       if (len > 0 && len < MAX_QUERY_SIZE) {
+       if (len > 0 && len < sizeof(query)) {
                query[len] = '\0';
-       } else if (len >= MAX_QUERY_SIZE) {
+       } else if (len >= sizeof(query)) {
                query[MAX_QUERY_SIZE -1] = '\0';
        } else {
                media_content_error("snprintf failed");
@@ -1027,7 +1027,7 @@ 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,};
+       char repl_path[MAX_PATH_LEN] = {0,};
 
        media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path");
 
@@ -1189,7 +1189,7 @@ 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, };
+       char repl_path[MAX_PATH_LEN] = {0, };
 
        media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
        memset(repl_path, 0, sizeof(repl_path));
@@ -1264,7 +1264,7 @@ 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, };
+       char repl_path[MAX_PATH_LEN] = {0, };
 
        media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
 
index ed3385b..ad5379b 100755 (executable)
@@ -214,9 +214,9 @@ static int __media_db_make_query(filter_h filter, attribute_h attr, char *select
                        char bracket_added_condition[MAX_QUERY_SIZE] = {0, };
                        memset(bracket_added_condition, 0x00, sizeof(bracket_added_condition));
 
-                       SAFE_STRLCAT(bracket_added_condition, QUERY_KEYWORD_OPEN_BRACKET, MAX_QUERY_SIZE);
-                       SAFE_STRLCAT(bracket_added_condition, _filter->condition, MAX_QUERY_SIZE);
-                       SAFE_STRLCAT(bracket_added_condition, QUERY_KEYWORD_BRACKET, MAX_QUERY_SIZE);
+                       SAFE_STRLCAT(bracket_added_condition, QUERY_KEYWORD_OPEN_BRACKET, sizeof(bracket_added_condition));
+                       SAFE_STRLCAT(bracket_added_condition, _filter->condition, sizeof(bracket_added_condition));
+                       SAFE_STRLCAT(bracket_added_condition, QUERY_KEYWORD_BRACKET, sizeof(bracket_added_condition));
 
                        ret = _media_filter_attribute_generate(attr, bracket_added_condition, _filter->condition_collate_type, condition_query);
                        media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
@@ -589,7 +589,7 @@ int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_d
        attribute_h attr = NULL;
        filter_s *_filter = (filter_s*)filter;
        char *tmp_path = NULL;
-       char repl_path[MAX_QUERY_SIZE] = {0, };
+       char repl_path[MAX_PATH_LEN] = {0, };
 
        attr = _content_get_alias_attirbute_handle();
        memset(select_query, 0x00, sizeof(select_query));
@@ -653,7 +653,7 @@ int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *us
        sqlite3_stmt *stmt = NULL;
        attribute_h attr = NULL;
        char *tmp_path = NULL;
-       char repl_path[MAX_QUERY_SIZE] = {0, };
+       char repl_path[MAX_PATH_LEN] = {0, };
 
        attr = _content_get_attirbute_handle();
        memset(select_query, 0x00, sizeof(select_query));
index b9fce87..76ebf4c 100755 (executable)
@@ -937,7 +937,7 @@ int media_filter_set_condition(filter_h filter, const char *condition, media_con
                        SAFE_FREE(_filter->condition);
 
                char new_condition[MAX_QUERY_SIZE] = {0, };
-               memset(new_condition, 0, MAX_QUERY_SIZE);
+               memset(new_condition, 0, sizeof(new_condition));
                ret = _media_content_replace_path_in_condition(condition, new_condition);
                media_content_retvm_if(!STRING_VALID(new_condition), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
 
@@ -1028,7 +1028,7 @@ int media_filter_get_condition(filter_h filter, char **condition, media_content_
        if (_filter) {
                if (STRING_VALID(_filter->condition)) {
                        char new_condition[MAX_QUERY_SIZE] = {0, };
-                       memset(new_condition, 0, MAX_QUERY_SIZE);
+                       memset(new_condition, 0, sizeof(new_condition));
                        ret = _media_content_rollback_path_in_condition(_filter->condition, new_condition);
                        media_content_retvm_if(!STRING_VALID(new_condition), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
 
index 95f8738..965bcf2 100755 (executable)
@@ -352,7 +352,7 @@ int media_folder_get_folder_from_db(const char *folder_id, media_folder_h *folde
        sqlite3_stmt *stmt = NULL;
        char select_query[DEFAULT_QUERY_SIZE];
        char *tmp_path = NULL;
-       char repl_path[MAX_QUERY_SIZE] = {0, };
+       char repl_path[MAX_PATH_LEN] = {0, };
 
        if (!STRING_VALID(folder_id)) {
                media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
@@ -408,7 +408,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, };
+       char repl_path[MAX_PATH_LEN] = {0, };
 
        if ((_folder == NULL) || (_folder->folder_id == NULL)) {
                media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
@@ -449,8 +449,8 @@ int media_folder_update_to_db(media_folder_h folder)
 
                /* Update all folder record's path, which are matched by old parent path */
                char *update_folder_path_sql = NULL;
-               char src_path_slash[MAX_QUERY_SIZE + 1] = {0, };
-               char dst_path_slash[MAX_QUERY_SIZE + 1] = {0, };
+               char src_path_slash[MAX_PATH_LEN + 1] = {0, };
+               char dst_path_slash[MAX_PATH_LEN + 1] = {0, };
 
                snprintf(src_path_slash, sizeof(src_path_slash), "%s/", g_src_path);
                snprintf(dst_path_slash, sizeof(dst_path_slash), "%s/", repl_path);
@@ -481,9 +481,9 @@ int media_folder_set_name(media_folder_h folder, const char *name)
        if (_folder != NULL && STRING_VALID(name)) {
                if (STRING_VALID(_folder->path) && STRING_VALID(_folder->name)) {
                        char *folder_path = NULL;
-                       char new_folder_path[MAX_QUERY_SIZE] = {0,};
+                       char new_folder_path[MAX_PATH_LEN] = {0,};
                        bool ignore_dir = FALSE;
-                       char repl_path[MAX_QUERY_SIZE] = {0, };
+                       char repl_path[MAX_PATH_LEN] = {0, };
 
                        memset(repl_path, 0, sizeof(repl_path));
                        ret = _media_content_replace_path(_folder->path, repl_path);
index 961915c..c339bf0 100755 (executable)
@@ -274,7 +274,7 @@ 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, };
+       char repl_path[MAX_PATH_LEN] = {0, };
 
        _media->media_id = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_UUID));
 
@@ -419,7 +419,7 @@ 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, };
+       char repl_path[MAX_PATH_LEN] = {0, };
        int ret = MEDIA_CONTENT_ERROR_NONE;
 
        media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path");
@@ -497,7 +497,7 @@ int media_info_insert_batch_to_db(
        char **repl_path_array = NULL;
        int idx = 0;
        int ret = MS_MEDIA_ERR_NONE;
-       char repl_path[MAX_QUERY_SIZE] = {0, };
+       char repl_path[MAX_PATH_LEN] = {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");
@@ -528,7 +528,7 @@ int media_info_insert_burst_shot_to_db(const char **path_array, unsigned int arr
        char **repl_path_array = NULL;
        int idx = 0;
        int ret = MS_MEDIA_ERR_NONE;
-       char repl_path[MAX_QUERY_SIZE] = {0, };
+       char repl_path[MAX_PATH_LEN] = {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");
@@ -2903,7 +2903,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, };
+       char repl_path[MAX_PATH_LEN] = {0, };
 
        if (!STRING_VALID(media_id)) {
                media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
@@ -2971,8 +2971,8 @@ 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, };
+       char repl_path[MAX_PATH_LEN] = {0, };
+       char org_repl_path[MAX_PATH_LEN] = {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");
@@ -3024,7 +3024,7 @@ 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, };
+       char repl_path[MAX_PATH_LEN] = {0, };
        media_info_s *_media = (media_info_s*)media;
 
        if (_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path)) {
@@ -3055,7 +3055,7 @@ 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, };
+       char repl_path[MAX_PATH_LEN] = {0, };
 
        if (_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path) && _media->request_id > 0) {
                memset(repl_path, 0, sizeof(repl_path));
@@ -3077,7 +3077,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, };
+       char repl_path[MAX_PATH_LEN] = {0, };
 
        if (!__media_info_isFaceRecognition_feature_supported()) {
                media_content_error("NOT_SUPPORTED(0x%08x)", MEDIA_CONTENT_ERROR_NOT_SUPPORTED);
@@ -3111,7 +3111,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, };
+       char repl_path[MAX_PATH_LEN] = {0, };
 
        if (!__media_info_isFaceRecognition_feature_supported()) {
                media_content_error("NOT_SUPPORTED(0x%08x)", MEDIA_CONTENT_ERROR_NOT_SUPPORTED);
@@ -3135,7 +3135,7 @@ 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 repl_path[MAX_PATH_LEN] = {0, };
        char *tmp_path = NULL;
 
        media_svc_content_info_s *svc_content_info = calloc(1, sizeof(media_svc_content_info_s));
@@ -3487,7 +3487,7 @@ int media_info_insert_to_db_with_data(media_info_h media)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
        int ret_cnt = 0;
-       char repl_path[MAX_QUERY_SIZE] = {0, };
+       char repl_path[MAX_PATH_LEN] = {0, };
 
        media_info_s *_media = (media_info_s*)media;
 
@@ -3558,7 +3558,7 @@ 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, };
+       char repl_path[MAX_PATH_LEN] = {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");
index b8c6c5e..28b9e87 100755 (executable)
@@ -259,7 +259,7 @@ static int __media_playlist_import_item_from_file(const char* playlist_path, cha
                media_content_error("Out of Memory");
                return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
        }
-       memset(tmp_str, 0, sizeof(MAX_QUERY_SIZE));
+       memset(tmp_str, 0, sizeof(tmp_str));
 
        while (fgets(tmp_str, MAX_QUERY_SIZE, fp) != NULL) {
                memset(repl_item, 0, sizeof(repl_item));
@@ -835,7 +835,7 @@ 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, };
+       char repl_path[MAX_PATH_LEN] = {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");
@@ -917,7 +917,7 @@ 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_path[MAX_PATH_LEN] = {0, };
        char repl_item[MAX_QUERY_SIZE] = {0, };
 
        media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
index c704de2..d955826 100755 (executable)
@@ -95,9 +95,9 @@ int _media_util_check_ignore_dir(const char *dir_path, bool *ignore)
        struct dirent *result = NULL;
 
        char *leaf_path = NULL;
-       char search_path[4096] = {0, };
+       char search_path[MAX_PATH_LEN] = {0, };
 
-       strncpy(search_path, dir_path, strlen(dir_path));
+       strncpy(search_path, dir_path, sizeof(search_path));
        while (STRING_VALID(search_path)) {
                dp = opendir(search_path);
                if (dp == NULL) {
@@ -287,7 +287,7 @@ int _media_content_replace_path(const char *path, char *replace_path)
        int ret = MEDIA_CONTENT_ERROR_NONE;
 
 #ifdef _USE_TV_PROFILE
-       snprintf(replace_path, MAX_QUERY_SIZE, "%s", path);
+       snprintf(replace_path, MAX_PATH_LEN, "%s", path);
 #else
        if (!STRING_VALID(g_old_path)) {
                ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &g_old_path);
@@ -299,9 +299,9 @@ int _media_content_replace_path(const char *path, char *replace_path)
 
        if (strncmp(path, g_old_path, strlen(g_old_path)) == 0) {
                media_content_sec_debug("Old path[%s]", path);
-               snprintf(replace_path, MAX_QUERY_SIZE, "%s%s", tzplatform_getenv(TZ_USER_CONTENT), path + strlen(g_old_path));
+               snprintf(replace_path, MAX_PATH_LEN, "%s%s", tzplatform_getenv(TZ_USER_CONTENT), path + strlen(g_old_path));
        } else {
-               snprintf(replace_path, MAX_QUERY_SIZE, "%s", path);
+               snprintf(replace_path, MAX_PATH_LEN, "%s", path);
        }
 #endif
 
@@ -318,7 +318,7 @@ int _media_content_rollback_path(const char *path, char *replace_path)
        int ret = MEDIA_CONTENT_ERROR_NONE;
 
 #ifdef _USE_TV_PROFILE
-               snprintf(replace_path, MAX_QUERY_SIZE, "%s", path);
+               snprintf(replace_path, MAX_PATH_LEN, "%s", path);
 #else
 
        if (!STRING_VALID(g_old_path)) {
@@ -331,9 +331,9 @@ int _media_content_rollback_path(const char *path, char *replace_path)
 
        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", g_old_path, path + strlen(tzplatform_getenv(TZ_USER_CONTENT)));
+               snprintf(replace_path, MAX_PATH_LEN, "%s%s", g_old_path, path + strlen(tzplatform_getenv(TZ_USER_CONTENT)));
        } else {
-               snprintf(replace_path, MAX_QUERY_SIZE, "%s", path);
+               snprintf(replace_path, MAX_PATH_LEN, "%s", path);
        }
 #endif