*
* Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
*
- * Contact: Hyunjun Ko <zzoon.ko@samsung.com>, Haejeong Kim <backto.kim@samsung.com>
- *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
#include "media-svc-util.h"
#include "media-svc-storage.h"
-int _media_svc_init_storage(sqlite3 *handle, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *sql = NULL;
- sqlite3_stmt *sql_stmt = NULL;
- int storage_cnt = 0;
-
- /*Add Internal storage*/
- sql = sqlite3_mprintf("SELECT COUNT(*) FROM '%s' WHERE storage_uuid='%s' AND storage_name='%s'", MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_MEDIA);
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- storage_cnt = sqlite3_column_int(sql_stmt, 0);
- SQLITE3_FINALIZE(sql_stmt);
-
- if (storage_cnt == 0) {
- char *internal_path = NULL;
- ret = ms_user_get_internal_root_path(uid, &internal_path);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get root path");
-
- sql = sqlite3_mprintf("INSERT INTO %s (storage_uuid, storage_name, storage_path, storage_type) VALUES ('%s', '%s', '%s', 0);",
- MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_DB_TABLE_MEDIA, internal_path);
-
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
- SAFE_FREE(internal_path);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- }
-
- return ret;
-}
-
-int _media_svc_get_mmc_info(MediaSvcHandle *handle, char **storage_name, char **storage_path, int *validity, bool *info_exist)
+int _media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
char *sql = NULL;
- sql = sqlite3_mprintf("SELECT * FROM '%s' WHERE storage_uuid=%Q", MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_MEDIA);
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- if (ret != MS_MEDIA_ERR_NONE) {
- *storage_name = NULL;
- *storage_path = NULL;
- *validity = 0;
- *info_exist = FALSE;
-
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
- *info_exist = FALSE;
-
- return ret;
- }
-
- *storage_name = g_strdup((const char *)sqlite3_column_text(sql_stmt, 1));
- *storage_path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 2));
- *validity = sqlite3_column_int(sql_stmt, 6);
-
- *info_exist = TRUE;
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_check_storage(sqlite3 *handle, const char *storage_id, const char *storage_name, char **storage_path, int *validity, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = NULL;
+ media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
+ media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
+ media_svc_retvm_if(validity == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "validity is NULL");
*storage_path = NULL;
*validity = 0;
- if (storage_name != NULL)
- sql = sqlite3_mprintf("SELECT * FROM '%s' WHERE storage_uuid=%Q AND storage_name=%Q", MEDIA_SVC_DB_TABLE_STORAGE, storage_id, storage_name);
- else
- sql = sqlite3_mprintf("SELECT * FROM '%s' WHERE storage_uuid=%Q", MEDIA_SVC_DB_TABLE_STORAGE, storage_id);
-
+ sql = sqlite3_mprintf("SELECT storage_path, validity FROM %q WHERE storage_id=%Q", DB_TABLE_STORAGE, storage_id);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
-
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- *storage_path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 2));
- *validity = sqlite3_column_int(sql_stmt, 6);
+ *storage_path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
+ *validity = sqlite3_column_int(sql_stmt, 1);
SQLITE3_FINALIZE(sql_stmt);
- /*check storage media table*/
- if (STRING_VALID(storage_id)) {
- int table_cnt = 0;
-
- /*Select list of storage*/
- sql = sqlite3_mprintf("SELECT COUNT(*) FROM SQLITE_MASTER WHERE type='table' and name='%q'", storage_id);
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- table_cnt = sqlite3_column_int(sql_stmt, 0);
- SQLITE3_FINALIZE(sql_stmt);
-
- if (table_cnt > 0) {
- /*DO NOT THING*/
- } else {
- media_svc_error("media table not exist for storage [%s]", storage_id);
- /*make storage media table*/
- ret = _media_svc_create_media_table_with_id(storage_id, uid);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "create media table failed : %d", ret);
- }
- }
-
return MS_MEDIA_ERR_NONE;
}
-int _media_svc_append_storage(const char *storage_id, const char *storage_name, const char *storage_path, media_svc_storage_type_e storage_type, uid_t uid)
+int _media_svc_append_storage(const char *storage_id, const char *storage_path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- char *sql = sqlite3_mprintf("INSERT INTO %s (storage_uuid, storage_name, storage_path, storage_type) values (%Q, %Q, %Q, %d); ",
- MEDIA_SVC_DB_TABLE_STORAGE, storage_id, storage_name, storage_path, storage_type);
+ char *sql = sqlite3_mprintf("INSERT INTO %q (storage_id, storage_path) values (%Q, %Q);",
+ DB_TABLE_STORAGE, storage_id, storage_path);
- ret = _media_svc_sql_query(sql, uid);
+ ret = _media_svc_sql_query_direct(sql, uid);
SQLITE3_SAFE_FREE(sql);
return ret;
char *old_storage_path = NULL;
int validity = 0;
+ media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
+ media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+
/*Get old path*/
- ret = _media_svc_check_storage(handle, storage_id, NULL, &old_storage_path, &validity, uid);
+ ret = _media_svc_check_storage(handle, storage_id, &old_storage_path, &validity);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
/*Storage table update*/
- sql = sqlite3_mprintf("UPDATE '%s' SET storage_path=%Q WHERE storage_uuid=%Q;", MEDIA_SVC_DB_TABLE_STORAGE, path, storage_id);
- ret = _media_svc_sql_query(sql, uid);
+ sql = sqlite3_mprintf("UPDATE %q SET storage_path=%Q WHERE storage_id=%Q", DB_TABLE_STORAGE, path, storage_id);
+ ret = _media_svc_sql_query_direct(sql, uid);
SQLITE3_SAFE_FREE(sql);
if (ret != MS_MEDIA_ERR_NONE) {
- G_SAFE_FREE(old_storage_path);
+ g_free(old_storage_path);
return ret;
}
/*Folder table update*/
- sql = sqlite3_mprintf("UPDATE '%s' SET path=REPLACE(path, %Q, %Q) WHERE storage_uuid=%Q;", MEDIA_SVC_DB_TABLE_FOLDER, old_storage_path, path, storage_id);
- ret = _media_svc_sql_query(sql, uid);
+ sql = sqlite3_mprintf("UPDATE %q SET folder_path=REPLACE(folder_path, %Q, %Q) WHERE storage_uuid=%Q", DB_TABLE_FOLDER, old_storage_path, path, storage_id);
+ ret = _media_svc_sql_query_direct(sql, uid);
SQLITE3_SAFE_FREE(sql);
if (ret != MS_MEDIA_ERR_NONE) {
- G_SAFE_FREE(old_storage_path);
+ g_free(old_storage_path);
return ret;
}
/*Media table update*/
- sql = sqlite3_mprintf("UPDATE '%s' SET path=REPLACE(path, %Q, %Q);", storage_id, old_storage_path, path);
- ret = _media_svc_sql_query(sql, uid);
+ sql = sqlite3_mprintf("UPDATE %q SET media_path=REPLACE(media_path, %Q, %Q) WHERE storage_uuid=%Q", DB_TABLE_MEDIA, old_storage_path, path, storage_id);
+ ret = _media_svc_sql_query_direct(sql, uid);
SQLITE3_SAFE_FREE(sql);
- G_SAFE_FREE(old_storage_path);
+ g_free(old_storage_path);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
return ret;
}
-int _media_svc_delete_storage(const char *storage_id, const char *storage_name, uid_t uid)
+static int __media_svc_delete_thumbnail(sqlite3 *handle)
{
int ret = MS_MEDIA_ERR_NONE;
char *sql = NULL;
-
- if (storage_name != NULL)
- sql = sqlite3_mprintf("DELETE FROM '%s' WHERE storage_uuid=%Q AND storage_name=%Q;", MEDIA_SVC_DB_TABLE_STORAGE, storage_id, storage_name);
- else if (storage_id != NULL)
- sql = sqlite3_mprintf("DELETE FROM '%s' WHERE storage_uuid=%Q;", MEDIA_SVC_DB_TABLE_STORAGE, storage_id);
-
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
-
- return ret;
-}
-
-int _media_svc_update_storage_validity(const char *storage_id, int validity, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *sql = NULL;
-
- if (storage_id == NULL)
- sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE storage_uuid != 'media';", MEDIA_SVC_DB_TABLE_STORAGE, validity);
- else
- sql = sqlite3_mprintf("UPDATE '%s' SET validity=%d WHERE storage_uuid=%Q;", MEDIA_SVC_DB_TABLE_STORAGE, validity, storage_id);
-
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
-
- return ret;
-}
-
-int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage_id, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
- char *sql = NULL;
- char *storage_path = NULL;
- char *remain_path = NULL;
- int remain_len = 0;
- char *internal_path = NULL;
- ret = ms_user_get_internal_root_path(uid, &internal_path);
- media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get root path");
-
- if (STRING_VALID(internal_path) && strncmp(path, internal_path, strlen(internal_path)) == 0) {
- SAFE_STRLCPY(storage_id, MEDIA_SVC_DB_TABLE_MEDIA, MEDIA_SVC_UUID_SIZE+1);
- SAFE_FREE(internal_path);
- return MS_MEDIA_ERR_NONE;
- }
-
- SAFE_FREE(internal_path);
-
- remain_path = strstr(path + (STRING_VALID(MEDIA_ROOT_PATH_USB) ? strlen(MEDIA_ROOT_PATH_USB) : 0) + 1, "/");
- if (remain_path != NULL)
- remain_len = strlen(remain_path);
-
- storage_path = strndup(path, strlen(path) - remain_len);
-
- sql = sqlite3_mprintf("SELECT storage_uuid FROM '%s' WHERE validity=1 AND storage_path = '%s'", MEDIA_SVC_DB_TABLE_STORAGE, storage_path);
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- SAFE_FREE(storage_path);
+ sql = sqlite3_mprintf("SELECT media_thumbnail_path FROM %q WHERE validity=0 AND media_thumbnail_path is not null", DB_TABLE_MEDIA);
+ ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0)))
- SAFE_STRLCPY(storage_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE+1);
+ while (sqlite3_step(sql_stmt) == SQLITE_ROW)
+ _media_svc_remove_file((const char *)sqlite3_column_text(sql_stmt, 0));
SQLITE3_FINALIZE(sql_stmt);
- if (!STRING_VALID(storage_id)) {
- media_svc_error("Not found valid storage id [%s]", path);
- ret = MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
return ret;
}
-int _media_svc_get_storage_type(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e *storage_type)
+int _media_svc_delete_invalid_storage(sqlite3 *handle, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
char *sql = NULL;
- if (!STRING_VALID(storage_id)) {
- media_svc_error("Invalid storage_id");
- ret = MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- sql = sqlite3_mprintf("SELECT storage_type FROM '%s' WHERE storage_uuid=%Q", MEDIA_SVC_DB_TABLE_STORAGE, storage_id);
+ ret = __media_svc_delete_thumbnail(handle);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to remove thumbnail");
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
-
- if (ret != MS_MEDIA_ERR_NONE) {
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
- media_svc_debug("there is no storage.");
- else
- media_svc_error("error when _media_svc_get_storage_type. err = [%d]", ret);
+ sql = sqlite3_mprintf("DELETE FROM %q WHERE validity=0;DELETE FROM %q WHERE validity=0;DELETE FROM %q WHERE validity=0;",
+ DB_TABLE_MEDIA, DB_TABLE_STORAGE, DB_TABLE_FOLDER);
- return ret;
- }
-
- *storage_type = sqlite3_column_int(sql_stmt, 0);
-
- SQLITE3_FINALIZE(sql_stmt);
+ ret = _media_svc_sql_query_direct(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
return ret;
}
-int _media_svc_get_storage_path(sqlite3 *handle, const char *storage_id, char **storage_path)
+int _media_svc_update_storage_validity(const char *storage_id, int validity, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
char *sql = NULL;
- if (!STRING_VALID(storage_id)) {
- media_svc_error("Invalid storage_id");
- ret = MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- sql = sqlite3_mprintf("SELECT storage_path FROM '%s' WHERE (storage_uuid=%Q AND validity=1)", MEDIA_SVC_DB_TABLE_STORAGE, storage_id);
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
-
- if (ret != MS_MEDIA_ERR_NONE) {
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
- media_svc_debug("there is no storage.");
- else
- media_svc_error("error when _media_svc_get_storage_type. err = [%d]", ret);
-
- return ret;
+ if (storage_id == NULL) {
+ sql = sqlite3_mprintf("UPDATE %q SET validity=%d;UPDATE %q SET validity=%d WHERE storage_uuid IS NOT 'media';UPDATE %q SET validity=%d WHERE storage_uuid IS NOT 'media';",
+ DB_TABLE_STORAGE, validity, DB_TABLE_FOLDER, validity, DB_TABLE_MEDIA, validity);
+ } else {
+ sql = sqlite3_mprintf("UPDATE %q SET validity=%d WHERE storage_id=%Q;UPDATE %q SET validity=%d WHERE storage_uuid=%Q;UPDATE %q SET validity=%d WHERE storage_uuid=%Q;",
+ DB_TABLE_STORAGE, validity, storage_id, DB_TABLE_FOLDER, validity, storage_id, DB_TABLE_MEDIA, validity, storage_id);
}
-
- *storage_path = g_strdup((char *)sqlite3_column_text(sql_stmt, 0));
-
- SQLITE3_FINALIZE(sql_stmt);
+ ret = _media_svc_sql_query_direct(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
return ret;
}
-int _media_svc_get_storage_scan_status(sqlite3 *handle, const char *storage_id, media_svc_scan_status_type_e *scan_status)
+int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage_id, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
char *sql = NULL;
+ char *internal_path = NULL;
- if (!STRING_VALID(storage_id)) {
- media_svc_error("Invalid storage_id");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- sql = sqlite3_mprintf("SELECT scan_status FROM '%s' WHERE (storage_uuid=%Q AND validity=1)", MEDIA_SVC_DB_TABLE_STORAGE, storage_id);
+ media_svc_retvm_if(path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- if (ret != MS_MEDIA_ERR_NONE) {
- if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
- media_svc_debug("there is no storage.");
- else
- media_svc_error("error when _media_svc_get_storage_scan_status. err = [%d]", ret);
+ ret = ms_user_get_internal_root_path(uid, &internal_path);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get root path");
- return ret;
+ if (STRING_VALID(internal_path) && strncmp(path, internal_path, strlen(internal_path)) == 0) {
+ SAFE_STRLCPY(storage_id, DB_TABLE_MEDIA, MEDIA_SVC_UUID_SIZE + 1);
+ g_free(internal_path);
+ return MS_MEDIA_ERR_NONE;
}
- *scan_status = sqlite3_column_int(sql_stmt, 0);
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return ret;
-}
-
-int _media_svc_set_storage_scan_status(const char *storage_id, media_svc_scan_status_type_e scan_status, uid_t uid)
-{
- int ret = MS_MEDIA_ERR_NONE;
- char *sql = NULL;
-
- if (storage_id == NULL)
- sql = sqlite3_mprintf("UPDATE '%s' SET scan_status=%d WHERE storage_uuid != 'media';", MEDIA_SVC_DB_TABLE_STORAGE, scan_status);
- else
- sql = sqlite3_mprintf("UPDATE '%s' SET scan_status=%d WHERE storage_uuid=%Q;", MEDIA_SVC_DB_TABLE_STORAGE, scan_status, storage_id);
+ g_free(internal_path);
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
-
- return ret;
-}
-
-static int __media_svc_count_all_storage(sqlite3 *handle, int *count)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE validity = 1", MEDIA_SVC_DB_TABLE_STORAGE);
+ sql = sqlite3_mprintf("SELECT storage_id FROM %q WHERE validity=1 AND instr(%Q, storage_path)", DB_TABLE_STORAGE, path);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("error when _media_svc_sql_prepare_to_step. err = [%d]", ret);
- return ret;
- }
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- *count = sqlite3_column_int(sql_stmt, 0);
+ if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0)))
+ SAFE_STRLCPY(storage_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE + 1);
SQLITE3_FINALIZE(sql_stmt);
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_svc_get_all_storage(sqlite3 *handle, char ***storage_list, char ***storage_id_list, int **scan_status_list, int *count)
-{
- int ret = MS_MEDIA_ERR_NONE;
- int idx = 0;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = NULL;
- int cnt = 0;
-
- ret = __media_svc_count_all_storage(handle, &cnt);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("error when __media_svc_count_all_folders. err = [%d]", ret);
- return ret;
- }
-
- if (cnt > 0) {
- sql = sqlite3_mprintf("SELECT storage_path, storage_uuid, scan_status FROM '%s' WHERE validity = 1", MEDIA_SVC_DB_TABLE_STORAGE);
- } else {
- *storage_list = NULL;
- *scan_status_list = NULL;
- return MS_MEDIA_ERR_NONE;
- }
-
- *storage_list = malloc(sizeof(char *) * cnt);
- *storage_id_list = malloc(sizeof(char *) * cnt);
- *scan_status_list = malloc(sizeof(int) * cnt);
- if (*storage_list == NULL || *storage_id_list == NULL || *scan_status_list == NULL) {
- media_svc_error("Allocation failed");
- SAFE_FREE(*storage_list);
- SAFE_FREE(*storage_id_list);
- SAFE_FREE(*scan_status_list);
- SQLITE3_SAFE_FREE(sql);
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("prepare error [%s]", sqlite3_errmsg(handle));
- SAFE_FREE(*storage_list);
- SAFE_FREE(*storage_id_list);
- SAFE_FREE(*scan_status_list);
- return ret;
- }
-
- media_svc_debug("QEURY OK");
-
- while (1) {
- (*storage_list)[idx] = g_strdup((char *)sqlite3_column_text(sql_stmt, 0));
- (*storage_id_list)[idx] = g_strdup((char *)sqlite3_column_text(sql_stmt, 1));
- (*scan_status_list)[idx] = (int)sqlite3_column_int(sql_stmt, 2);
- if (sqlite3_step(sql_stmt) != SQLITE_ROW)
- break;
- idx++;
- }
-
- if (cnt == idx + 1) {
- *count = cnt;
- media_svc_debug("OK");
- } else {
- /* free all data */
- int i = 0;
- for (i = 0; i < idx; i++) {
- SAFE_FREE((*storage_list)[i]);
- SAFE_FREE((*storage_id_list)[i]);
- }
- SAFE_FREE(*storage_list);
- SAFE_FREE(*storage_id_list);
- SAFE_FREE(*scan_status_list);
- *count = 0;
- ret = MS_MEDIA_ERR_INTERNAL;
+ if (!STRING_VALID(storage_id)) {
+ media_svc_error("Not found valid storage id [%s]", path);
+ ret = MS_MEDIA_ERR_INVALID_PARAMETER;
}
- SQLITE3_FINALIZE(sql_stmt);
-
return ret;
}