summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorminje.ahn <minje.ahn@samsung.com>2024-03-06 14:20:01 +0900
committerminje.ahn <minje.ahn@samsung.com>2024-03-06 14:44:55 +0900
commit2bc1d2a82f85e1c9560fa2466d0c24cc9c0f0045 (patch)
tree4a74712ba8e275ac2039e42c87d2d54c49ed171c
parent283db828471c773510a3b0dd4377e59beb032452 (diff)
downloadlibmedia-service-2bc1d2a82f85e1c9560fa2466d0c24cc9c0f0045.tar.gz
libmedia-service-2bc1d2a82f85e1c9560fa2466d0c24cc9c0f0045.tar.bz2
libmedia-service-2bc1d2a82f85e1c9560fa2466d0c24cc9c0f0045.zip
Add string vaild function
Change-Id: Id4221d315dee719a85154a4aaca3192a2915243e Signed-off-by: minje.ahn <minje.ahn@samsung.com>
-rwxr-xr-xsrc/common/media-svc-db-utils.c20
-rwxr-xr-xsrc/common/media-svc-media-folder.c2
-rwxr-xr-xsrc/common/media-svc-media.c12
-rwxr-xr-xsrc/common/media-svc-noti.c4
-rwxr-xr-xsrc/common/media-svc-storage.c6
-rw-r--r--src/common/media-svc-util.c10
-rwxr-xr-xsrc/common/media-svc.c28
-rwxr-xr-xsrc/include/common/media-svc-util.h2
8 files changed, 43 insertions, 41 deletions
diff --git a/src/common/media-svc-db-utils.c b/src/common/media-svc-db-utils.c
index ba528ab..68b73b1 100755
--- a/src/common/media-svc-db-utils.c
+++ b/src/common/media-svc-db-utils.c
@@ -55,23 +55,23 @@ static void __add_table_info(const char *name,
{
table_info_s *tbl = NULL;
- if (!MS_STRING_VALID(name))
+ if (!name)
return;
- if (MS_STRING_VALID(trigger_name)) {
- if(!MS_STRING_VALID(event_table) || !MS_STRING_VALID(action_table))
+ if (trigger_name) {
+ if(!event_table || !action_table)
return;
}
tbl = g_new0(table_info_s, 1);
- if (MS_STRING_VALID(trigger_name)) {
+ if (trigger_name) {
tbl->trigger_name = g_strdup(trigger_name);
tbl->event_table = g_strdup(event_table);
tbl->action_table = g_strdup(action_table);
}
- if (MS_STRING_VALID(view_name))
+ if (view_name)
tbl->view_name = g_strdup(view_name);
g_hash_table_insert(table, (gpointer)name, (gpointer)tbl);
@@ -264,7 +264,7 @@ int _media_svc_make_table_query(const char *table_name, media_svc_table_slist_e
/*create trigger */
if (col_ptr->is_trigger) {
- if (MS_STRING_VALID(tb->trigger_name)) {
+ if (tb->trigger_name) {
if (strncmp(table_name, DB_TABLE_ALBUM, strlen(DB_TABLE_ALBUM)) == 0) {
g_string_append_printf(trigger_query, DB_QUERY_TRIGGER_WITH_COUNT,
tb->trigger_name, tb->event_table, tb->action_table, tb->event_table,
@@ -599,7 +599,7 @@ int _media_svc_sql_prepare_to_step_simple(sqlite3 *handle, const char *sql_str,
media_svc_sec_debug("Query[%s]", sql_str);
- if (!MS_STRING_VALID(sql_str)) {
+ if (!STRING_VALID(sql_str)) {
media_svc_error("invalid query");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
@@ -634,7 +634,7 @@ int _media_svc_sql_query_list(GList **query_list, uid_t uid)
for (idx = 0; idx < length; idx++) {
sql = (char *)g_list_nth_data(*query_list, idx);
- if (MS_STRING_VALID(sql)) {
+ if (STRING_VALID(sql)) {
query_len = strlen(sql);
if (query_len >= (sizeof(query_bundle) - 1)) {
@@ -658,7 +658,7 @@ int _media_svc_sql_query_list(GList **query_list, uid_t uid)
/* column limit = 2000 */
}
- SAFE_STRLCAT(query_bundle, sql, sizeof(query_bundle));
+ g_strlcat(query_bundle, sql, sizeof(query_bundle));
total_len += query_len;
SQLITE3_SAFE_FREE(sql);
@@ -705,7 +705,7 @@ int _media_svc_sql_query_list_direct(GList **query_list, uid_t uid)
for (idx = 0; idx < length; idx++) {
sql = (char *)g_list_nth_data(*query_list, idx);
- if (MS_STRING_VALID(sql)) {
+ if (STRING_VALID(sql)) {
ret = __media_svc_query_direct(handle, sql, uid);
if (ret != MS_MEDIA_ERR_NONE)
media_svc_debug("_media_svc_query_direct failed[%s]", sql);
diff --git a/src/common/media-svc-media-folder.c b/src/common/media-svc-media-folder.c
index ae09390..f1f3825 100755
--- a/src/common/media-svc-media-folder.c
+++ b/src/common/media-svc-media-folder.c
@@ -190,7 +190,7 @@ int _media_svc_check_folder_by_path(sqlite3 *handle, const char *path)
sqlite3_stmt *sql_stmt = NULL;
char *sql = NULL;
- media_svc_retvm_if(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
sql = sqlite3_mprintf("SELECT 1 FROM %q WHERE folder_path=%Q", DB_TABLE_FOLDER, path);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
diff --git a/src/common/media-svc-media.c b/src/common/media-svc-media.c
index facd740..9a68030 100755
--- a/src/common/media-svc-media.c
+++ b/src/common/media-svc-media.c
@@ -39,7 +39,7 @@ int _media_svc_check_data_by_path(sqlite3 *handle, const char *path)
sqlite3_stmt *sql_stmt = NULL;
char *sql = NULL;
- media_svc_retvm_if(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
sql = sqlite3_mprintf("SELECT 1 FROM %q WHERE media_path=%Q", DB_TABLE_MEDIA, path);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
@@ -55,7 +55,7 @@ int _media_svc_get_modified_time(sqlite3 *handle, const char *path, int *modifie
sqlite3_stmt *sql_stmt = NULL;
char *sql = NULL;
- media_svc_retvm_if(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Path is NULL");
sql = sqlite3_mprintf("SELECT media_modified_time FROM %q WHERE media_path=%Q", DB_TABLE_MEDIA, path);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
@@ -184,7 +184,7 @@ int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *path, cha
sqlite3_stmt *sql_stmt = NULL;
char *sql = NULL;
- media_svc_retvm_if(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
sql = sqlite3_mprintf("SELECT media_thumbnail_path FROM %q WHERE media_path='%q'", DB_TABLE_MEDIA, path);
@@ -211,7 +211,7 @@ int _media_svc_delete_item_by_path(const char *path, uid_t uid)
int ret = MS_MEDIA_ERR_NONE;
char *sql = NULL;
- media_svc_retvm_if(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
sql = sqlite3_mprintf("DELETE FROM %q WHERE media_path=%Q;", DB_TABLE_MEDIA, path);
@@ -227,7 +227,7 @@ int _media_svc_update_item_validity(const char *path, int validity, bool stack_q
int ret = MS_MEDIA_ERR_NONE;
char *sql = NULL;
- media_svc_retvm_if(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
media_svc_debug("path=[%s], validity=[%d]", path, validity);
@@ -333,7 +333,7 @@ int _media_svc_get_noti_info(sqlite3 *handle, const char *path, media_svc_noti_i
char *sql = NULL;
media_svc_retvm_if(item == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "item is NULL");
- media_svc_retvm_if(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
sql = sqlite3_mprintf("SELECT media_id, media_type, media_mime_type FROM %q WHERE media_path=%Q", DB_TABLE_MEDIA, path);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
diff --git a/src/common/media-svc-noti.c b/src/common/media-svc-noti.c
index a13f61d..69f0916 100755
--- a/src/common/media-svc-noti.c
+++ b/src/common/media-svc-noti.c
@@ -55,7 +55,7 @@ static void __media_svc_destroy_noti_item(gpointer data)
int _media_svc_publish_noti(media_item_update_type_e update_type, const char *path, media_type_e media_type, const char *uuid, const char *mime_type)
{
int ret = MS_MEDIA_ERR_NONE;
- media_svc_retvm_if(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
ret = media_db_update_send(getpid(), MS_MEDIA_ITEM_FILE, update_type, path, uuid, media_type, mime_type);
media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Send noti failed[%d][%s]", ret, path);
@@ -68,7 +68,7 @@ int _media_svc_publish_noti(media_item_update_type_e update_type, const char *pa
int _media_svc_publish_dir_noti(media_item_update_type_e update_type, const char *path, const char *uuid, int pid)
{
int ret = MS_MEDIA_ERR_NONE;
- media_svc_retvm_if(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
ret = media_db_update_send(pid, MS_MEDIA_ITEM_DIRECTORY, update_type, path, uuid, MS_MEDIA_UNKNOWN, NULL);
media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Send dir noti failed[%d][%s]", ret, path);
diff --git a/src/common/media-svc-storage.c b/src/common/media-svc-storage.c
index 730912a..a076418 100755
--- a/src/common/media-svc-storage.c
+++ b/src/common/media-svc-storage.c
@@ -168,7 +168,7 @@ int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage
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 (MS_STRING_VALID(internal_path) && strncmp(path, internal_path, strlen(internal_path)) == 0) {
+ if (STRING_VALID(internal_path) && strncmp(path, internal_path, strlen(internal_path)) == 0) {
g_strlcpy(storage_id, DB_TABLE_MEDIA, MEDIA_SVC_UUID_SIZE + 1);
g_free(internal_path);
return MS_MEDIA_ERR_NONE;
@@ -181,12 +181,12 @@ int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- if (MS_STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0)))
+ if (STRING_VALID((const char *)sqlite3_column_text(sql_stmt, 0)))
g_strlcpy(storage_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE + 1);
SQLITE3_FINALIZE(sql_stmt);
- if (!MS_STRING_VALID(storage_id)) {
+ if (!STRING_VALID(storage_id)) {
media_svc_error("Not found valid storage id [%s]", path);
ret = MS_MEDIA_ERR_INVALID_PARAMETER;
}
diff --git a/src/common/media-svc-util.c b/src/common/media-svc-util.c
index a6096a3..2e7930a 100644
--- a/src/common/media-svc-util.c
+++ b/src/common/media-svc-util.c
@@ -318,7 +318,7 @@ static char *__media_svc_get_title_from_filename(const char *filename)
char *title = NULL;
char *last_dot = NULL;
- media_svc_retvm_if(!MS_STRING_VALID(filename), g_strdup(MEDIA_SVC_TAG_UNKNOWN), "Invalid path");
+ media_svc_retvm_if(!STRING_VALID(filename), g_strdup(MEDIA_SVC_TAG_UNKNOWN), "Invalid path");
last_dot = strrchr(filename, '.');
if (last_dot) {
@@ -334,7 +334,7 @@ static char *__media_svc_get_title_from_filename(const char *filename)
void _media_svc_remove_file(const char *path)
{
- if (!MS_STRING_VALID(path))
+ if (!STRING_VALID(path))
return;
if (remove(path) != 0)
@@ -349,7 +349,7 @@ static int __media_svc_get_thumbnail_path(char *thumb_path, const char *pathname
g_autofree gchar *thumb_dir = NULL;
ret = ms_user_get_root_thumb_store_path(uid, &thumb_dir);
- media_svc_retvm_if(!MS_STRING_VALID(thumb_dir), ret, "ms_user_get_root_thumb_store_path failed");
+ media_svc_retvm_if(!STRING_VALID(thumb_dir), ret, "ms_user_get_root_thumb_store_path failed");
media_svc_retvm_if(!g_file_test(thumb_dir, G_FILE_TEST_IS_DIR), MS_MEDIA_ERR_INTERNAL, "Not a directory");
memset(file_ext, 0, sizeof(file_ext));
@@ -395,7 +395,7 @@ int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char
char mime_type[256] = {0, };
media_svc_media_type_e media_type;
- media_svc_retvm_if(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
content_info->path = g_strdup(path);
media_svc_retv_del_if(content_info->path == NULL, MS_MEDIA_ERR_INTERNAL, content_info);
@@ -483,7 +483,7 @@ int _media_svc_extract_image_metadata(media_svc_content_info_s *content_info)
media_svc_retvm_if(!content_info, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid content_info");
media_svc_retvm_if(content_info->media_type != MEDIA_SVC_MEDIA_TYPE_IMAGE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid media_type [%d]", content_info->media_type);
- media_svc_retvm_if(!MS_STRING_VALID(content_info->path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
+ media_svc_retvm_if(!STRING_VALID(content_info->path), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid path");
path = content_info->path;
content_info->media_meta.title = __media_svc_get_title_from_filename(content_info->file_name);
diff --git a/src/common/media-svc.c b/src/common/media-svc.c
index e13331f..01a6e3a 100755
--- a/src/common/media-svc.c
+++ b/src/common/media-svc.c
@@ -190,8 +190,8 @@ int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, const ch
long long int folder_id = 0;
media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
- media_svc_retvm_if(!MS_STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
- media_svc_retvm_if(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+ media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
media_svc_content_info_s content_info;
memset(&content_info, 0, sizeof(media_svc_content_info_s));
@@ -263,8 +263,8 @@ int media_svc_insert_item_immediately(sqlite3 *handle, const char *storage_id, c
long long int folder_id = 0;
media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
- media_svc_retvm_if(!MS_STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
- media_svc_retvm_if(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+ media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
media_svc_content_info_s content_info;
memset(&content_info, 0, sizeof(media_svc_content_info_s));
@@ -351,10 +351,10 @@ int media_svc_move_item(sqlite3 *handle,
media_svc_debug_fenter();
media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
- media_svc_retvm_if(!MS_STRING_VALID(src_path), MS_MEDIA_ERR_INVALID_PARAMETER, "src_path is NULL");
- media_svc_retvm_if(!MS_STRING_VALID(dest_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dest_path is NULL");
- media_svc_retvm_if(!MS_STRING_VALID(media_id), MS_MEDIA_ERR_INVALID_PARAMETER, "media_id is NULL");
- media_svc_retvm_if(!MS_STRING_VALID(mime_type), MS_MEDIA_ERR_INVALID_PARAMETER, "mime_type is NULL");
+ media_svc_retvm_if(!STRING_VALID(src_path), MS_MEDIA_ERR_INVALID_PARAMETER, "src_path is NULL");
+ media_svc_retvm_if(!STRING_VALID(dest_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dest_path is NULL");
+ media_svc_retvm_if(!STRING_VALID(media_id), MS_MEDIA_ERR_INVALID_PARAMETER, "media_id is NULL");
+ media_svc_retvm_if(!STRING_VALID(mime_type), MS_MEDIA_ERR_INVALID_PARAMETER, "mime_type is NULL");
/* Get storage_id */
ret = _media_svc_get_storage_uuid(handle, dest_path, dst_stg_id, uid);
@@ -459,8 +459,8 @@ int media_svc_refresh_item(sqlite3 *handle, bool is_direct, const char *storage_
media_svc_noti_item *noti_item = NULL;
media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
- media_svc_retvm_if(!MS_STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
- media_svc_retvm_if(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+ media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
/*Set media info*/
ret = _media_svc_set_media_info(&content_info, storage_id, path, true);
@@ -471,7 +471,7 @@ int media_svc_refresh_item(sqlite3 *handle, bool is_direct, const char *storage_
if (ret != MS_MEDIA_ERR_NONE && ret != MS_MEDIA_ERR_DB_NO_RECORD)
goto REFRESH_FINALIZE;
- if (MS_STRING_VALID(thumb_path)) {
+ if (strlen(thumb_path) > 0) {
_media_svc_remove_file(thumb_path);
ret = _media_svc_update_thumbnail_path(path, NULL, uid);
@@ -556,7 +556,7 @@ REFRESH_FINALIZE:
int media_svc_send_dir_update_noti(const char *dir_path, const char *folder_id, media_item_update_type_e update_type, int pid)
{
- media_svc_retvm_if(!MS_STRING_VALID(dir_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dir_path is NULL");
+ media_svc_retvm_if(!STRING_VALID(dir_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dir_path is NULL");
return _media_svc_publish_dir_noti(update_type, dir_path, folder_id, pid);
}
@@ -607,8 +607,8 @@ int media_svc_insert_storage(sqlite3 *handle, const char *storage_id, const char
int media_svc_insert_folder(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
{
media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
- media_svc_retvm_if(!MS_STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
- media_svc_retvm_if(!MS_STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
+ media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
+ media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
return _media_svc_append_by_folder_path(handle, storage_id, path, uid);
}
diff --git a/src/include/common/media-svc-util.h b/src/include/common/media-svc-util.h
index cbfbaf9..83a6c90 100755
--- a/src/include/common/media-svc-util.h
+++ b/src/include/common/media-svc-util.h
@@ -32,6 +32,8 @@
extern "C" {
#endif
+#define STRING_VALID(str) (str && strlen(str) > 0)
+
/**
* Media meta data information
*/