#include <media_info_private.h>
#include <media_util_private.h>
+#ifdef _USE_TVPD_MODE
+#include <media_content_type_product.h>
+#endif
static char *g_src_path = NULL;
media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
+#ifdef _USE_TVPD_MODE
+ g_mutex_lock(_content_get_db_mutex());
+#endif
ret = _media_db_get_group_count(filter, MEDIA_GROUP_FOLDER, folder_count);
+#ifdef _USE_TVPD_MODE
+ g_mutex_unlock(_content_get_db_mutex());
+#endif
+
+
return ret;
}
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
+#ifdef _USE_TVPD_MODE
+ g_mutex_lock(_content_get_db_mutex());
+#endif
+
ret = _media_db_get_folder(filter, callback, user_data);
+#ifdef _USE_TVPD_MODE
+ g_mutex_unlock(_content_get_db_mutex());
+#endif
+
return ret;
}
int ret = MEDIA_CONTENT_ERROR_NONE;
if (STRING_VALID(folder_id) && media_count) {
+#ifdef _USE_TVPD_MODE
+ g_mutex_lock(_content_get_db_mutex());
+#endif
+
ret = _media_db_get_group_item_count(folder_id, filter, MEDIA_GROUP_FOLDER, media_count);
+
+#ifdef _USE_TVPD_MODE
+ g_mutex_unlock(_content_get_db_mutex());
+#endif
+
} else {
media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
int ret = MEDIA_CONTENT_ERROR_NONE;
if ((callback != NULL) && STRING_VALID(folder_id)) {
+#ifdef _USE_TVPD_MODE
+ g_mutex_lock(_content_get_db_mutex());
+#endif
+
ret = _media_db_get_group_item(folder_id, filter, callback, user_data, MEDIA_GROUP_FOLDER);
+
+#ifdef _USE_TVPD_MODE
+ g_mutex_unlock(_content_get_db_mutex());
+#endif
+
} else {
media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
return ret;
}
+#ifdef _USE_SENIOR_MODE
+int media_folder_foreach_media_from_db_by_union_select(const char* folder_id, filter_h filter1, filter_h filter2, media_info_cb callback, void* user_data)
+{
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+
+ if ((callback != NULL) && STRING_VALID(folder_id)) {
+ ret = _media_db_get_group_item_by_union_select(folder_id, filter1, filter2, callback, user_data);
+ } else {
+ media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+ return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ }
+
+ return ret;
+}
+#endif
+
int media_folder_destroy(media_folder_h folder)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
SAFE_FREE(_folder->path);
SAFE_FREE(_folder->name);
SAFE_FREE(_folder->folder_id);
- SAFE_FREE(_folder->parent_folder_id);
SAFE_FREE(_folder->storage_uuid);
SAFE_FREE(_folder);
ret = MEDIA_CONTENT_ERROR_NONE;
}
}
- if (STRING_VALID(_src->parent_folder_id)) {
- _dst->parent_folder_id = strdup(_src->parent_folder_id);
- if (_dst->parent_folder_id == NULL) {
- media_folder_destroy((media_folder_h)_dst);
- media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
- return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
- }
- }
-
if (STRING_VALID(_src->name)) {
_dst->name = strdup(_src->name);
if (_dst->name == NULL) {
int media_folder_get_parent_folder_id(media_folder_h folder, char **parent_folder_id)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
+ media_content_warn("DEPRECATION WARNING: media_folder_get_parent_folder_id() is deprecated and will be removed from next release.");
media_folder_s *_folder = (media_folder_s*)folder;
+ sqlite3_stmt *stmt = NULL;
+ char tmp_path[MAX_PATH_LEN] = {0, };
+ char *parent_path = NULL;
+ char select_query[MAX_QUERY_SIZE] = {0, };
+ /* Usage is low. So, DB access when this function is called */
if (_folder) {
- if (STRING_VALID(_folder->parent_folder_id)) {
- *parent_folder_id = strdup(_folder->parent_folder_id);
- media_content_retvm_if(*parent_folder_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
- } else {
+ memset(tmp_path, 0x00, sizeof(tmp_path));
+ memset(select_query, 0x00, sizeof(select_query));
+
+ _media_content_replace_path(_folder->path, tmp_path);
+
+ parent_path = g_path_get_dirname(tmp_path);
+ snprintf(select_query, sizeof(select_query), SELECT_FOLDER_ID_BY_PATH, parent_path);
+ SAFE_FREE(parent_path);
+
+ ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
+ media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
+
+ if (sqlite3_step(stmt) == SQLITE_ROW)
+ *parent_folder_id = g_strdup((const char *)sqlite3_column_text(stmt, 0));
+ else
*parent_folder_id = NULL;
- }
+
+ SQLITE3_FINALIZE(stmt);
+
ret = MEDIA_CONTENT_ERROR_NONE;
} else {
media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
int media_folder_get_modified_time(media_folder_h folder, time_t* time)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
+ media_content_warn("DEPRECATION WARNING: media_folder_get_modified_time() is deprecated and will be removed from next release.");
media_folder_s *_folder = (media_folder_s*)folder;
if (_folder) {
int media_folder_get_storage_type(media_folder_h folder, media_content_storage_e* storage_type)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
+ media_content_warn("DEPRECATION WARNING: media_folder_get_storage_type() is deprecated and will be removed from next release. Use storage_get_type_dev() instead.");
media_folder_s *_folder = (media_folder_s*)folder;
if (_folder) {
int media_folder_get_storage_id(media_folder_h folder, char **storage_id)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
+ media_content_warn("DEPRECATION WARNING: media_folder_get_storage_id() is deprecated and will be removed from next release.");
media_folder_s *_folder = (media_folder_s*)folder;
if (_folder) {
int media_folder_get_order(media_folder_h folder, int *order)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
+ media_content_warn("DEPRECATION WARNING: media_folder_get_order() is deprecated and will be removed from next release.");
media_folder_s *_folder = (media_folder_s*)folder;
if (_folder) {
int ret = MEDIA_CONTENT_ERROR_NONE;
sqlite3_stmt *stmt = NULL;
char select_query[DEFAULT_QUERY_SIZE];
+ media_folder_s *_folder = NULL;
if (!STRING_VALID(folder_id)) {
media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
}
memset(select_query, 0x00, sizeof(select_query));
-
snprintf(select_query, sizeof(select_query), SELECT_FOLDER_FROM_FOLDER, folder_id);
ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
- media_folder_s *_folder = NULL;
-
- while (sqlite3_step(stmt) == SQLITE_ROW) {
- if (_folder)
- media_folder_destroy((media_folder_h)_folder);
-
+ if (sqlite3_step(stmt) == SQLITE_ROW) {
_folder = (media_folder_s*)calloc(1, sizeof(media_folder_s));
if (_folder == NULL) {
media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
- media_content_error("folder handle %x", _folder);
-
_folder->folder_id = g_strdup((const char *)sqlite3_column_text(stmt, 0));
_folder->path = g_strdup((const char *)sqlite3_column_text(stmt, 1));
_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);
+ _folder->storage_uuid = g_strdup((const char *)sqlite3_column_text(stmt, 6));
+ _folder->folder_order = (int)sqlite3_column_int(stmt, 7);
*folder = (media_folder_h)_folder;
}
int media_folder_update_to_db(media_folder_h folder)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
+ media_content_warn("DEPRECATION WARNING: media_folder_update_to_db() is deprecated and will be removed from next release.");
media_folder_s *_folder = (media_folder_s*)folder;
char *sql = NULL;
+ 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);
SQLITE3_SAFE_FREE(sql);
if (STRING_VALID(_folder->folder_id) && g_src_path) {
- char *name_pinyin = NULL;
- bool pinyin_support = FALSE;
-
- /* Set modified time */
- time_t date;
- time(&date);
- _folder->modified_time = date;
-
- /*Update Pinyin If Support Pinyin*/
- media_svc_check_pinyin_support(&pinyin_support);
- if (pinyin_support)
- 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);
-
- ret = _content_query_sql(sql);
- SQLITE3_SAFE_FREE(sql);
+ ret = _media_content_replace_path(_folder->path, repl_path);
if (ret != MEDIA_CONTENT_ERROR_NONE) {
SAFE_FREE(g_src_path);
return ret;
}
-
- /* 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, };
-
- snprintf(src_path_slash, sizeof(src_path_slash), "%s/", g_src_path);
- snprintf(dst_path_slash, sizeof(dst_path_slash), "%s/", _folder->path);
-
- update_folder_path_sql = sqlite3_mprintf("UPDATE folder SET path = REPLACE( path, '%q', '%q');", src_path_slash, dst_path_slash);
-
- ret = _content_query_sql(update_folder_path_sql);
- SQLITE3_SAFE_FREE(update_folder_path_sql);
- if (ret != MEDIA_CONTENT_ERROR_NONE) {
- SAFE_FREE(g_src_path);
- 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, _content_get_uid());
SAFE_FREE(g_src_path);
return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
int media_folder_set_name(media_folder_h folder, const char *name)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
+ media_content_warn("DEPRECATION WARNING: media_folder_set_name() is deprecated and will be removed from next release.");
media_folder_s *_folder = (media_folder_s*)folder;
- if (_folder != NULL && STRING_VALID(name)) {
+ if (_folder != NULL && STRING_VALID(name) && name[0] != '.') {
if (STRING_VALID(_folder->path) && STRING_VALID(_folder->name)) {
char *folder_path = NULL;
- char new_folder_path[MAX_QUERY_SIZE] = {0,};
- bool ignore_dir = FALSE;
+ char new_folder_path[MAX_PATH_LEN] = {0,};
+ char repl_path[MAX_PATH_LEN] = {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);
- ret = _media_util_check_ignore_dir(new_folder_path, &ignore_dir);
- if (ignore_dir == TRUE) {
- media_content_error("Invalid folder path");
- SAFE_FREE(folder_path);
- return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
- }
-
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);
media_content_retvm_if(_folder->path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+ _folder->name = strdup(name);
+ media_content_retvm_if(_folder->name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
+ } else {
+ media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+ ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
-
- _folder->name = strdup(name);
- media_content_retvm_if(_folder->name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
} else {
media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
int media_folder_set_order(media_folder_h folder, int order)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
+ media_content_warn("DEPRECATION WARNING: media_folder_set_order() is deprecated and will be removed from next release.");
media_folder_s *_folder = (media_folder_s*)folder;
if (_folder != NULL && order >= 0) {
return ret;
}
+#ifdef _USE_TVPD_MODE
+int media_folder_insert_to_db(const char *path)
+{
+ char repl_path[MAX_PATH_LEN] = {0, };
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
+ bool ignore_dir = FALSE;
+
+ 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_util_check_ignore_dir(repl_path, &ignore_dir);
+ media_content_retvm_if(ignore_dir, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
+
+ ret = _media_content_check_dir(repl_path);
+ media_content_retvm_if(ret == MEDIA_CONTENT_ERROR_PERMISSION_DENIED, ret, "Permission Denied");
+ media_content_retvm_if(ret == MEDIA_CONTENT_ERROR_INVALID_PARAMETER, ret, "invalid path[%s]", 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);
+ }
+
+ ret = media_svc_check_folder_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_folder_exist_by_path : no record : %s", repl_path);
+ media_svc_storage_type_e storage_type = 0;
+
+ ret = media_svc_get_storage_type(repl_path, &storage_type, _content_get_uid());
+ 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_folder(_content_get_db_handle(), storage_id, storage_type, repl_path, _content_get_uid());
+ 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)", repl_path);
+ ret = MEDIA_CONTENT_ERROR_NONE;
+ } else {
+ media_content_sec_error("media_svc_insert_folder failed : %d (%s)", ret, repl_path);
+ }
+
+ return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ }
+
+ ret = media_svc_set_folder_scan_status(storage_id, repl_path, MEDIA_DIR_SCAN_DONE, _content_get_uid());
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_content_sec_error("ms_set_folder_scan_status failed : %d", ret);
+ return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ }
+ } else if (ret != MS_MEDIA_ERR_NONE) {
+ media_content_sec_error("media_svc_check_folder_exist_by_path failed : %d (%s)", ret, repl_path);
+ return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ }
+
+ return ret;
+}
+
+int media_folder_get_scan_status(const char *storage_uuid, char* path, media_folder_scan_status_e *scan_status)
+{
+ int ret = MEDIA_CONTENT_ERROR_NONE;
+ int status = MEDIA_DIR_SCAN_NONE;
+
+ if (STRING_VALID(storage_uuid) && STRING_VALID(path)) {
+ ret = media_svc_get_folder_scan_status(_content_get_db_handle(), storage_uuid, path, &status);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_content_error("media_svc_get_folder_scan_status failed");
+ ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ } else {
+ *scan_status = status;
+ }
+ } else {
+ media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
+ ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
+ }
+
+ return ret;
+}
+#endif