Remove path replacement function
[platform/core/api/media-content.git] / src / media_content.c
index 40cc5bf..8d20d33 100644 (file)
@@ -41,7 +41,7 @@ int _content_query_prepare(const char *select_query, const char *condition_query
        int ret = MEDIA_CONTENT_ERROR_NONE;
        char *query = NULL;
 
-       content_retvm_if(!STRING_VALID(select_query), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid select_query");
+       content_retip_if_fail(select_query);
 
        /* If 'option_query' is NULL, 'condition_query' is also NULL. */
        if (option_query) {
@@ -64,8 +64,8 @@ int _content_get_result(char *query, sqlite3_stmt **stmt)
 {
        int err = MEDIA_CONTENT_ERROR_NONE;
 
-       content_retvm_if(_content_get_db_handle() == NULL, MEDIA_CONTENT_ERROR_DB_FAILED, "database is not connected");
-       content_retvm_if(!STRING_VALID(query), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid query");
+       content_retip_if_fail(_content_get_db_handle());
+       content_retip_if_fail(query);
 
        content_sec_debug("Query[%s]", query);
 
@@ -83,62 +83,6 @@ int _content_get_result(char *query, sqlite3_stmt **stmt)
        return MEDIA_CONTENT_ERROR_NONE;
 }
 
-#ifdef _USE_SENIOR_MODE
-int _content_query_prepare_by_union_select(sqlite3_stmt **stmt, char *select_query1, char *condition_query1, char *option_query1, char *select_query2, char *condition_query2, char *option_query2)
-{
-       int len = 0;
-       int err = MEDIA_CONTENT_ERROR_NONE;
-       char query[MAX_QUERY_SIZE] = {0, };
-
-       content_retvm_if(_content_get_db_handle() == NULL, MEDIA_CONTENT_ERROR_DB_FAILED, "database is not connected");
-       content_retvm_if(!STRING_VALID(select_query1), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid select_query1");
-       content_retvm_if(!STRING_VALID(select_query2), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid select_query2");
-
-       if (!STRING_VALID(condition_query1))
-               condition_query1 = (char *)" ";
-
-       if (!STRING_VALID(option_query1))
-               option_query1 = (char *)" ";
-
-       if (!STRING_VALID(condition_query2))
-               condition_query2 = (char *)" ";
-
-       if (!STRING_VALID(option_query2))
-               option_query2 = (char *)" ";
-
-       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 < sizeof(query)) {
-               query[len] = '\0';
-       } else if (len >= sizeof(query)) {
-               query[MAX_QUERY_SIZE -1] = '\0';
-       } else {
-               content_error("snprintf failed");
-               return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
-       }
-
-       content_sec_debug("Query : [%s]", query);
-
-       err = sqlite3_prepare_v2(_content_get_db_handle(), query, strlen(query), stmt, NULL);
-       if (err != SQLITE_OK) {
-               content_error("DB_FAILED(0x%08x) fail to sqlite3_prepare(), %s", MEDIA_CONTENT_ERROR_DB_FAILED, sqlite3_errmsg(_content_get_db_handle()));
-
-               if (err == SQLITE_BUSY) {
-                       content_error(" BUSY ERROR");
-                       return MEDIA_CONTENT_ERROR_DB_BUSY;
-               } else if (err == SQLITE_PERM) {
-                       content_error("PERMISSION EROR");
-                       return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
-               } else {
-                       content_error("OTHER ERROR");
-                       return MEDIA_CONTENT_ERROR_DB_FAILED;
-               }
-       }
-
-       return MEDIA_CONTENT_ERROR_NONE;
-}
-#endif
-
 int _content_error_capi(int internal_error)
 {
        if (internal_error == MS_MEDIA_ERR_NONE)
@@ -251,47 +195,45 @@ 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_PATH_LEN] = {0,};
 
-       content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path");
+       content_retip_if_fail(STRING_VALID(path));
 
        content_sec_debug("Path : %s", path);
 
-       ret = _media_content_replace_path(path, repl_path);
-       content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
-
-       content_retvm_if(_media_util_is_ignorable_file(repl_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
+       content_retvm_if(_media_util_is_ignorable_file(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
 
-       ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id, _content_get_uid());
+       ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id, _content_get_uid());
        if (ret != MS_MEDIA_ERR_NONE) {
                content_error("media_svc_get_storage_id failed : %d", ret);
                return _content_error_capi(ret);
        }
 
-       check_file = _media_util_check_file_exist(repl_path);
+       check_file = _media_util_check_file_exist(path);
        if (check_file == MEDIA_CONTENT_ERROR_NONE) {
                /* This means this path has to be inserted or refreshed */
-               folder_path = g_path_get_dirname(repl_path);
+               folder_path = g_path_get_dirname(path);
 
                if (_media_util_is_ignorable_dir(folder_path)) {
                        g_free(folder_path);
                        return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
                }
 
+               g_free(folder_path);
+
                /* check feature */
-               content_retvm_if(!_media_util_check_support_media_type(repl_path), MEDIA_CONTENT_ERROR_NOT_SUPPORTED, "Unsupported media type");
+               content_retvm_if(!_media_util_check_support_media_type(path), MEDIA_CONTENT_ERROR_NOT_SUPPORTED, "Unsupported media type");
 
                ms_user_storage_type_e storage_type;
 
-               ret = ms_user_get_storage_type(_content_get_uid(), repl_path, &storage_type);
+               ret = ms_user_get_storage_type(_content_get_uid(), path, &storage_type);
                if (ret != MS_MEDIA_ERR_NONE) {
-                       content_sec_error("ms_user_get_storage_type failed : %d (%s)", ret, repl_path);
+                       content_sec_error("ms_user_get_storage_type failed : %d (%s)", ret, path);
                        return _content_error_capi(ret);
                }
-               ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), storage_id, repl_path);
+               ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), storage_id, path);
                if (ret == MS_MEDIA_ERR_NONE) {
                        /* Refresh */
-                       ret = media_svc_refresh_item(_content_get_db_handle(), false, storage_id, storage_type, repl_path, _content_get_uid());
+                       ret = media_svc_refresh_item(_content_get_db_handle(), false, storage_id, storage_type, path, _content_get_uid());
                        if (ret != MS_MEDIA_ERR_NONE) {
                                content_error("media_svc_refresh_item failed : %d", ret);
                                return _content_error_capi(ret);
@@ -299,13 +241,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, repl_path, _content_get_uid());
+                       ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, storage_type, path, _content_get_uid());
                        if (ret != MS_MEDIA_ERR_NONE) {
                                if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
-                                       content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", repl_path);
+                                       content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", path);
                                        ret = MEDIA_CONTENT_ERROR_NONE;
                                } else {
-                                       content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, repl_path);
+                                       content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, path);
                                }
 
                                return _content_error_capi(ret);
@@ -320,7 +262,7 @@ int media_content_scan_file(const char *path)
        } else {
                /* This means this path has to be deleted */
                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, repl_path, _content_get_uid());
+               ret = media_svc_delete_item_by_path(_content_get_db_handle(), storage_id, path, _content_get_uid());
                if (ret != MS_MEDIA_ERR_NONE) {
                        if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
                                content_error("Does not exist in media DB also... So, this is an invalid parameter");
@@ -351,7 +293,7 @@ void _media_content_scan_cb(media_request_result_s* result, void *user_data)
                        content_debug("end:User callback is being called now, result=%d", err);
                }
 
-               SAFE_FREE(cb_data);
+               g_free(cb_data);
        }
 #else
        if (cb_data && cb_data->callback) {
@@ -359,7 +301,7 @@ void _media_content_scan_cb(media_request_result_s* result, void *user_data)
                cb_data->callback(err, cb_data->user_data);
        }
 
-       SAFE_FREE(cb_data);
+       g_free(cb_data);
 #endif
 
        return;
@@ -393,7 +335,7 @@ void _media_content_scan_cb_v2(media_request_result_s* result, void *user_data)
        if ((result->request_type != MEDIA_REQUEST_SCAN_COMPLETE) &&
        (result->request_type != MEDIA_REQUEST_SCAN_PARTIAL) &&
        (result->request_type != MEDIA_RECURSIVE_START))
-               SAFE_FREE(cb_data);
+               g_free(cb_data);
 
        return;
 }
@@ -403,49 +345,45 @@ int media_content_scan_folder(const char *path, bool is_recursive, media_scan_co
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
        char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
-       char repl_path[MAX_PATH_LEN] = {0, };
        ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
 
-       content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
+       content_retip_if_fail(STRING_VALID(path));
+       content_retip_if_fail(callback);
 
-       ret = _media_content_replace_path(path, repl_path);
-       content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
-
-       ret = _media_content_check_dir(repl_path);
+       ret = _media_content_check_dir(path);
        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*/
-               content_retvm_if(_media_util_is_ignorable_dir(repl_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
+               content_retvm_if(_media_util_is_ignorable_dir(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
        } else {
                /* This means this folder has to be deleted */
                /* Or, it is real invalid path.. check storage type */
-               ret = ms_user_get_storage_type(_content_get_uid(), repl_path, &storage_type);
+               ret = ms_user_get_storage_type(_content_get_uid(), path, &storage_type);
                if (ret != MS_MEDIA_ERR_NONE) {
-                       content_sec_error("ms_user_get_storage_type failed : %d (%s)", ret, repl_path);
+                       content_sec_error("ms_user_get_storage_type failed : %d (%s)", ret, path);
                        return _content_error_capi(ret);
                }
 
                content_debug("This path doesn't exists in file system... So will be deleted it from DB");
        }
 
-       ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id, _content_get_uid());
+       ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id, _content_get_uid());
        if (ret != MS_MEDIA_ERR_NONE) {
                content_error("media_svc_get_storage_id failed : %d", ret);
                return _content_error_capi(ret);
        }
 
        media_content_scan_cb_data *cb_data = NULL;
-       cb_data = (media_content_scan_cb_data *)malloc(sizeof(media_content_scan_cb_data));
-       content_retvm_if(cb_data == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+       cb_data = g_new0(media_content_scan_cb_data, 1);
 
        cb_data->callback = callback;
        cb_data->user_data = user_data;
 
-       ret = media_directory_scanning_async(repl_path, storage_id, is_recursive, _media_content_scan_cb, cb_data, _content_get_uid());
+       ret = media_directory_scanning_async(path, storage_id, is_recursive, _media_content_scan_cb, cb_data, _content_get_uid());
        if (ret != MS_MEDIA_ERR_NONE) {
                content_error("media_directory_scanning_async failed : %d", ret);
-               SAFE_FREE(cb_data);
+               g_free(cb_data);
        }
 
        return _content_error_capi(ret);
@@ -457,7 +395,9 @@ int media_content_scan_folder_v2(const char *path, bool is_recursive, media_scan
        int ret = MEDIA_CONTENT_ERROR_NONE;
        char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
 
-       content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
+       content_retip_if_fail(STRING_VALID(path));
+       content_retip_if_fail(callback);
+
        content_retvm_if(_media_util_is_ignorable_dir(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
 
        ret = _media_content_check_dir(path);
@@ -465,8 +405,7 @@ int media_content_scan_folder_v2(const char *path, bool is_recursive, media_scan
        content_retvm_if(ret == MEDIA_CONTENT_ERROR_INVALID_PARAMETER, ret, "invalid path[%s]", path);
 
        media_content_scan_cb_data_v2* cb_data = NULL;
-       cb_data = (media_content_scan_cb_data_v2*)malloc(sizeof(media_content_scan_cb_data_v2));
-       content_retvm_if(cb_data == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+       cb_data = g_new0(media_content_scan_cb_data_v2, 1);
 
        cb_data->callback = callback;
        cb_data->user_data = user_data;
@@ -485,14 +424,10 @@ 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_PATH_LEN] = {0, };
-
-       content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
 
-       ret = _media_content_replace_path(path, repl_path);
-       content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
+       content_retip_if_fail(STRING_VALID(path));
 
-       ret = media_directory_scanning_cancel(repl_path, _content_get_uid());
+       ret = media_directory_scanning_cancel(path, _content_get_uid());
        if (ret != MS_MEDIA_ERR_NONE)
                content_error("media_directory_scanning_async failed : %d", ret);
 
@@ -529,18 +464,17 @@ int media_content_add_db_updated_cb(media_content_db_update_cb callback, void *u
        int ret = MEDIA_CONTENT_ERROR_NONE;
        media_noti_cb_s *noti_info = NULL;
 
-       content_retvm_if(noti_handle == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "handle is NULL");
-       content_retvm_if(callback == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "callback is NULL");
+       content_retip_if_fail(callback);
+       content_retip_if_fail(noti_handle);
 
-       noti_info = (media_noti_cb_s *)calloc(1, sizeof(media_noti_cb_s));
-       content_retvm_if(noti_info == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Failed to create noti info");
+       noti_info = g_new0(media_noti_cb_s, 1);
 
        noti_info->update_noti_cb = callback;
        noti_info->user_data = user_data;
 
-       ret = media_db_update_subscribe_internal((MediaNotiHandle*)noti_handle, _media_content_db_update_noti_cb, (void *)noti_info);
+       ret = media_db_update_subscribe((MediaNotiHandle*)noti_handle, _media_content_db_update_noti_cb, (void *)noti_info);
        if (ret != MS_MEDIA_ERR_NONE)
-               SAFE_FREE(noti_info);
+               g_free(noti_info);
 
        return _content_error_capi(ret);
 }
@@ -554,18 +488,11 @@ int media_content_set_db_updated_cb(media_content_db_update_cb callback, void *u
 }
 #endif
 
-static void __media_content_clear_user_data(void *user_data)
-{
-       media_noti_cb_s *noti_info = user_data;
-
-       SAFE_FREE(noti_info);
-}
-
 int media_content_remove_db_updated_cb(media_content_noti_h noti_handle)
 {
        int ret = MEDIA_CONTENT_ERROR_NONE;
 
-       ret = media_db_update_unsubscribe_internal((MediaNotiHandle)noti_handle, __media_content_clear_user_data);
+       ret = media_db_update_unsubscribe((MediaNotiHandle)noti_handle);
 
        return _content_error_capi(ret);
 }