return content_g_uid;
}
-int _content_query_prepare(sqlite3_stmt **stmt, char *select_query, char *condition_query, char *option_query)
+int _content_query_prepare(const char *select_query, const char *condition_query, const char *option_query, sqlite3_stmt **stmt)
{
- int len = 0;
- int err = MEDIA_CONTENT_ERROR_NONE;
- char query[MAX_QUERY_SIZE] = {0, };
- memset(query, '\0', sizeof(query));
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ char *query = NULL;
- media_content_retvm_if(db_handle == NULL, MEDIA_CONTENT_ERROR_DB_FAILED, "database is not connected");
media_content_retvm_if(!STRING_VALID(select_query), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid select_query");
- if (!STRING_VALID(condition_query))
- condition_query = (char *)" ";
+ if (STRING_VALID(condition_query)) {
+ if (STRING_VALID(option_query))
+ query = sqlite3_mprintf("%s AND %s %s", select_query, condition_query, option_query);
+ else
+ query = sqlite3_mprintf("%s AND %s", select_query, condition_query);
+ } else {
+ if (STRING_VALID(option_query))
+ query = sqlite3_mprintf("%s %s", select_query, option_query);
+ else
+ query = sqlite3_mprintf("%s", select_query);
+ }
- if (!STRING_VALID(option_query))
- option_query = (char *)" ";
+ ret = _content_get_result(query, stmt);
+ SQLITE3_SAFE_FREE(query);
- /*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 < sizeof(query))
- query[len] = '\0';
- else if (len >= sizeof(query))
- query[MAX_QUERY_SIZE -1] = '\0';
- else {
- media_content_error("snprintf failed");
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ return ret;
+}
- media_content_sec_debug("Query : [%s]", query);
+int _content_get_result(char *query, sqlite3_stmt **stmt)
+{
+ int err = MEDIA_CONTENT_ERROR_NONE;
- err = sqlite3_prepare_v2(db_handle, query, strlen(query), stmt, NULL);
- if (err != SQLITE_OK) {
- media_content_error("DB_FAILED(0x%08x) fail to sqlite3_prepare(), %s", MEDIA_CONTENT_ERROR_DB_FAILED, sqlite3_errmsg(db_handle));
+ media_content_retvm_if(_content_get_db_handle() == NULL, MEDIA_CONTENT_ERROR_DB_FAILED, "database is not connected");
+ media_content_retvm_if(!STRING_VALID(query), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid query");
- if (err == SQLITE_BUSY) {
- media_content_error(" BUSY ERROR");
+ media_content_sec_debug("Query[%s]", query);
+
+ err = sqlite3_prepare_v2(_content_get_db_handle(), query, strlen(query), stmt, NULL);
+ if (err != SQLITE_OK) {
+ media_content_error("Failed to sqlite3_prepare_v2[%s]", sqlite3_errmsg(_content_get_db_handle()));
+ if (err == SQLITE_BUSY)
return MEDIA_CONTENT_ERROR_DB_BUSY;
- } else if (err == SQLITE_PERM) {
- media_content_error("PERMISSION EROR");
+ else if (err == SQLITE_PERM)
return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
- } else {
- media_content_error("OTHER ERROR");
+ else
return MEDIA_CONTENT_ERROR_DB_FAILED;
- }
}
return MEDIA_CONTENT_ERROR_NONE;
char query[MAX_QUERY_SIZE] = {0, };
memset(query, '\0', sizeof(query));
- media_content_retvm_if(db_handle == NULL, MEDIA_CONTENT_ERROR_DB_FAILED, "database is not connected");
+ media_content_retvm_if(_content_get_db_handle() == NULL, MEDIA_CONTENT_ERROR_DB_FAILED, "database is not connected");
media_content_retvm_if(!STRING_VALID(select_query1), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid select_query1");
media_content_retvm_if(!STRING_VALID(select_query2), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid select_query2");
media_content_sec_debug("Query : [%s]", query);
- err = sqlite3_prepare_v2(db_handle, query, strlen(query), stmt, NULL);
+ err = sqlite3_prepare_v2(_content_get_db_handle(), query, strlen(query), stmt, NULL);
if (err != SQLITE_OK) {
- media_content_error("DB_FAILED(0x%08x) fail to sqlite3_prepare(), %s", MEDIA_CONTENT_ERROR_DB_FAILED, sqlite3_errmsg(db_handle));
+ media_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) {
media_content_error(" BUSY ERROR");
}
#endif
-int _content_error_capi(int type, int content_error)
+int _content_error_capi(int internal_error)
{
- if (content_error != MEDIA_CONTENT_ERROR_NONE)
- media_content_error("[type : %d] content_error : %d ", type, content_error);
-
- /*Error None*/
- if (content_error == MS_MEDIA_ERR_NONE)
+ if (internal_error == MS_MEDIA_ERR_NONE)
return MEDIA_CONTENT_ERROR_NONE;
- /* Internal operation error*/
- else if ((content_error == MS_MEDIA_ERR_INVALID_PARAMETER) ||
- (content_error == MS_MEDIA_ERR_INVALID_PATH) ||
- (content_error == MS_MEDIA_ERR_THUMB_DUPLICATED_REQUEST))
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ media_content_error("MS Error[%d]", internal_error);
- else if (content_error == MS_MEDIA_ERR_OUT_OF_MEMORY)
+ switch (internal_error) {
+ case MS_MEDIA_ERR_INVALID_PARAMETER:
+ return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ case MS_MEDIA_ERR_OUT_OF_MEMORY:
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
-
- /* DB operation error*/
- else if (content_error == MS_MEDIA_ERR_DB_BUSY_FAIL)
+ case MS_MEDIA_ERR_DB_BUSY_FAIL:
return MEDIA_CONTENT_ERROR_DB_BUSY;
-
- else if ((content_error <= MS_MEDIA_ERR_DB_CONNECT_FAIL) && (content_error >= MS_MEDIA_ERR_DB_INTERNAL))
+ case MS_MEDIA_ERR_DB_CONSTRAINT_FAIL:
+ case MS_MEDIA_ERR_DB_NO_RECORD:
+ case MS_MEDIA_ERR_DB_CORRUPT:
+ case MS_MEDIA_ERR_DB_FULL_FAIL:
+ case MS_MEDIA_ERR_DB_RESET:
+ case MS_MEDIA_ERR_DB_INTERNAL:
return MEDIA_CONTENT_ERROR_DB_FAILED;
-
- /* IPC operation error*/
- else if ((content_error <= MS_MEDIA_ERR_SOCKET_CONN) && (content_error >= MS_MEDIA_ERR_SOCKET_INTERNAL))
+ case MS_MEDIA_ERR_IPC:
return MEDIA_CONTENT_ERROR_NETWORK;
-
- /* MEDIA SERVER error*/
- else if (content_error == MS_MEDIA_ERR_PERMISSION_DENIED)
+ case MS_MEDIA_ERR_PERMISSION_DENIED:
return MEDIA_CONTENT_ERROR_PERMISSION_DENIED;
-
- /* Thumbnail error*/
- else if ((content_error == MS_MEDIA_ERR_THUMB_TOO_BIG) || (content_error == MS_MEDIA_ERR_THUMB_UNSUPPORTED))
- return MEDIA_CONTENT_ERROR_UNSUPPORTED_CONTENT;
-
- /*ETC*/
- return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ case MS_MEDIA_ERR_THUMB_TOO_BIG:
+ case MS_MEDIA_ERR_THUMB_UNSUPPORTED:
+ return MEDIA_CONTENT_ERROR_UNSUPPORTED_CONTENT;
+ default:
+ return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
+ }
}
int _content_query_sql(char *query_str)
/*DB will be updated by Media Server.*/
ret = media_db_request_update_db(query_str, _content_get_uid());
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
int media_content_connect(void)
if (ref_count == 0) {
if (db_handle == NULL) {
ret = media_db_connect(&db_handle, _content_get_uid(), false);
- ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ ret = _content_error_capi(ret);
if (ret == MEDIA_CONTENT_ERROR_NONE)
ref_count++;
} else {
int media_content_disconnect(void)
{
- int ret = MEDIA_CONTENT_ERROR_NONE;
-
g_mutex_lock(&db_mutex);
media_content_debug("ref count : %d", ref_count);
- if (ref_count > 0) {
- if (db_handle != NULL) {
- ref_count--;
- } else {
- media_content_error("Wrong DB Handle status");
- ret = MEDIA_CONTENT_ERROR_DB_FAILED;
+
+ if (db_handle && ref_count > 0) {
+ if (--ref_count == 0) {
+ media_db_disconnect(db_handle);
+ db_handle = NULL;
}
} else {
- media_content_error("DB_FAILED(0x%08x) database is not connected", MEDIA_CONTENT_ERROR_DB_FAILED);
+ media_content_error("Database is not connected");
g_mutex_unlock(&db_mutex);
return MEDIA_CONTENT_ERROR_DB_FAILED;
}
- if (ref_count == 0) {
- if (db_handle != NULL) {
- ret = media_db_disconnect(db_handle);
- ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
- if (ret == MEDIA_CONTENT_ERROR_NONE) {
- db_handle = NULL;
- } else {
- media_content_error("database disconnect fail");
- ref_count++;
- }
- } else {
- media_content_error("Wrong DB Handle status");
- ret = MEDIA_CONTENT_ERROR_DB_FAILED;
- }
-
- g_mutex_unlock(&db_mutex);
-
- media_content_info("ref count changed to: %d", ref_count);
-
- return ret;
- }
-
g_mutex_unlock(&db_mutex);
media_content_info("ref count changed to: %d", ref_count);
- return ret;
+ return MEDIA_CONTENT_ERROR_NONE;
}
int media_content_scan_file(const char *path)
ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id, _content_get_uid());
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);
+ return _content_error_capi(ret);
}
check_file = _media_util_check_file_exist(repl_path);
/* This means this path has to be inserted or refreshed */
folder_path = g_path_get_dirname(repl_path);
ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
- SAFE_FREE(folder_path);
+ g_free(folder_path);
media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
/* check feature */
ret = ms_user_get_storage_type(_content_get_uid(), repl_path, &storage_type);
if (ret != MS_MEDIA_ERR_NONE) {
media_content_sec_error("ms_user_get_storage_type failed : %d (%s)", ret, repl_path);
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
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, repl_path, _content_get_uid());
+ ret = media_svc_refresh_item(_content_get_db_handle(), false, storage_id, storage_type, repl_path, _content_get_uid());
if (ret != MS_MEDIA_ERR_NONE) {
media_content_error("media_svc_refresh_item failed : %d", ret);
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
} else if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, repl_path);
}
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
} else {
media_content_error("media_svc_check_item_exist_by_path failed : %d", ret);
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
} else if (check_file == MEDIA_CONTENT_ERROR_PERMISSION_DENIED) {
media_content_error("You have no permission for this file %d", ret);
}
media_content_error("media_svc_delete_item_by_path failed : %d", ret);
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
}
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
void _media_content_scan_cb(media_request_result_s* result, void *user_data)
int err = -1;
media_content_scan_cb_data *cb_data = user_data;
- err = _content_error_capi(MEDIA_REGISTER_TYPE, result->result);
+ err = _content_error_capi(result->result);
#ifdef _USE_TVPD_MODE
if (result->request_type != MEDIA_REQUEST_SCAN_COMPLETE &&
- result->request_type != MEDIA_REQUEST_SCAN_PARTIAL) {
+ result->request_type != MEDIA_REQUEST_SCAN_PARTIAL &&
+ result->request_type != MEDIA_RECURSIVE_START) {
if (cb_data && cb_data->callback) {
media_content_debug("begin:User callback is being called now, result=%d", err);
cb_data->callback(err, cb_data->user_data);
media_content_complete_phase_e complete_phase = -1;
if (!cb_data)
media_content_debug("cb_data is NULL");
- err = _content_error_capi(MEDIA_REGISTER_TYPE, result->result);
+ err = _content_error_capi(result->result);
media_content_debug("result is %d", err);
if (result->request_type == MEDIA_REQUEST_SCAN_PARTIAL)
complete_phase = MEDIA_CONTENT_SCAN_COMPLETE;
else if (result->request_type == MEDIA_REQUEST_EXTRACT_COMPLETE)
complete_phase = MEDIA_CONTENT_EXTRACT_COMPLETE;
+ else if (result->request_type == MEDIA_RECURSIVE_START)
+ complete_phase = MEDIA_CONTENT_RECURSIVE_START;
if (cb_data && cb_data->callback)
cb_data->callback(err, complete_phase, cb_data->user_data);
media_content_debug("run error");
if ((result->request_type != MEDIA_REQUEST_SCAN_COMPLETE) &&
- (result->request_type != MEDIA_REQUEST_SCAN_PARTIAL))
+ (result->request_type != MEDIA_REQUEST_SCAN_PARTIAL) &&
+ (result->request_type != MEDIA_RECURSIVE_START))
SAFE_FREE(cb_data);
return;
ret = ms_user_get_storage_type(_content_get_uid(), repl_path, &storage_type);
if (ret != MS_MEDIA_ERR_NONE) {
media_content_sec_error("ms_user_get_storage_type failed : %d (%s)", ret, repl_path);
- return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ return _content_error_capi(ret);
}
media_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());
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);
+ return _content_error_capi(ret);
}
media_content_scan_cb_data *cb_data = NULL;
SAFE_FREE(cb_data);
}
- return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
+ return _content_error_capi(ret);
}
#ifdef _USE_TVPD_MODE
if (ret != MS_MEDIA_ERR_NONE)
media_content_error("media_directory_scanning_async failed : %d", ret);
- return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
+ return _content_error_capi(ret);
}
#endif
if (ret != MS_MEDIA_ERR_NONE)
media_content_error("media_directory_scanning_async failed : %d", ret);
- return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
+ return _content_error_capi(ret);
}
void _media_content_db_update_noti_cb(
char *mime_type,
void *user_data)
{
- int error_value = MEDIA_CONTENT_ERROR_NONE;
-
media_noti_cb_s *_noti_info = (media_noti_cb_s *)user_data;
- if (_noti_info != NULL) {
- if (_noti_info->update_noti_cb)
- _noti_info->update_noti_cb(error_value, pid, item, update_type, content_type, uuid, path, mime_type, _noti_info->user_data);
- }
-
- return;
+ if (_noti_info != NULL && _noti_info->update_noti_cb)
+ _noti_info->update_noti_cb(
+ MEDIA_CONTENT_ERROR_NONE,
+ pid,
+ item,
+ update_type,
+ content_type,
+ uuid,
+ path,
+ mime_type,
+ _noti_info->user_data);
}
int media_content_add_db_updated_cb(media_content_db_update_cb callback, void *user_data, media_content_noti_h *noti_handle)
int ret = MEDIA_CONTENT_ERROR_NONE;
media_noti_cb_s *noti_info = NULL;
- if (noti_handle == NULL) {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
-
- if (callback == NULL) {
- media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
+ media_content_retvm_if(noti_handle == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "handle is NULL");
+ media_content_retvm_if(callback == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "callback is NULL");
noti_info = (media_noti_cb_s *)calloc(1, sizeof(media_noti_cb_s));
- if (noti_info == NULL) {
- media_content_error("Failed to create noti info");
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
+ media_content_retvm_if(noti_info == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "Failed to create noti info");
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);
+ if (ret != MS_MEDIA_ERR_NONE)
+ SAFE_FREE(noti_info);
- return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
+ return _content_error_capi(ret);
}
+#ifdef TIZEN_FEATURE_COMPATIBILITY
+int media_content_set_db_updated_cb(media_content_db_update_cb callback, void *user_data)
+{
+ media_content_warn("DEPRECATION WARNING: media_content_set_db_updated_cb() is removed from 5.0.");
+
+ return MEDIA_CONTENT_ERROR_NONE;
+}
+#endif
+
void __media_content_clear_user_data(void *user_data)
{
media_noti_cb_s *noti_info = user_data;
ret = media_db_update_unsubscribe_internal((MediaNotiHandle)noti_handle, __media_content_clear_user_data);
- return _content_error_capi(MEDIA_REGISTER_TYPE, ret);
+ return _content_error_capi(ret);
}
#ifdef _USE_TVPD_MODE
GMutex* _content_get_db_mutex(void)