From: Minje Ahn Date: Mon, 10 Jun 2024 06:12:16 +0000 (+0900) Subject: Use sqlite3_str instead of gslist X-Git-Tag: accepted/tizen/unified/20240612.100030~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=65fbf5f172688a9475365e70adfe24e0547e1185;p=platform%2Fcore%2Fapi%2Fmedia-controller.git Use sqlite3_str instead of gslist sqlite3_str makes playlist-related operations simpler. Change-Id: Id46dfd03371b766e34f2b0e086582b89e93d5514 Signed-off-by: Minje Ahn --- diff --git a/packaging/capi-media-controller.spec b/packaging/capi-media-controller.spec index 10fc19c..3927a54 100644 --- a/packaging/capi-media-controller.spec +++ b/packaging/capi-media-controller.spec @@ -1,7 +1,7 @@ Name: capi-media-controller Summary: A media controller library in Tizen Native API -Version: 1.0.1 -Release: 3 +Version: 1.0.2 +Release: 0 Group: Multimedia/API License: Apache-2.0 Source0: %{name}-%{version}.tar.gz diff --git a/svc/media_controller_db_util.c b/svc/media_controller_db_util.c index d3d7136..d5a016c 100644 --- a/svc/media_controller_db_util.c +++ b/svc/media_controller_db_util.c @@ -32,8 +32,7 @@ typedef struct { const char *server_name; const char *playlist_name; - GSList *query_list; - unsigned int query_length; + sqlite3_str *query_list; } playlist_query_s; static GMutex tzplatform_mutex; @@ -604,7 +603,6 @@ static void __make_playlist_query_cb(const char *key, const int type, const bun size_t basic_size = 0; gchar **params = NULL; playlist_query_s *query = (playlist_query_s *)user_data; - char *sql_str = NULL; mc_retm_if_failed(key); mc_retm_if_failed(kv); @@ -617,27 +615,15 @@ static void __make_playlist_query_cb(const char *key, const int type, const bun params = g_strsplit(basic_val, MC_STRING_DELIMITER, 0); mc_retm_if_failed(params); - sql_str = sqlite3_mprintf("INSERT INTO %q(server_name, playlist_name, item_index, %s) VALUES (%Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q);", - MC_DB_TABLE_PLAYLIST, META_LIST, query->server_name, query->playlist_name, __replace_null(params[0]), - __replace_null(params[1]), __replace_null(params[2]), __replace_null(params[3]), __replace_null(params[4]), __replace_null(params[5]), - __replace_null(params[6]), __replace_null(params[7]), __replace_null(params[8]), __replace_null(params[9]), __replace_null(params[10]), - __replace_null(params[11]), __replace_null(params[12]), __replace_null(params[13]), __replace_null(params[14])); + sqlite3_str_appendf( + query->query_list, + "INSERT INTO %q(server_name, playlist_name, item_index, %s) VALUES (%Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q);", + MC_DB_TABLE_PLAYLIST, META_LIST, query->server_name, query->playlist_name, __replace_null(params[0]), + __replace_null(params[1]), __replace_null(params[2]), __replace_null(params[3]), __replace_null(params[4]), __replace_null(params[5]), + __replace_null(params[6]), __replace_null(params[7]), __replace_null(params[8]), __replace_null(params[9]), __replace_null(params[10]), + __replace_null(params[11]), __replace_null(params[12]), __replace_null(params[13]), __replace_null(params[14])); g_strfreev(params); - - if (!sql_str) { - mc_error("sql_str is NULL"); - return; - } - mc_secure_debug("sql_str [%s]", sql_str); - - query->query_list = g_slist_append(query->query_list, sql_str); - query->query_length += strlen(sql_str); -} - -static void __sqlite3_safe_free(gpointer data) -{ - sqlite3_free(data); } int __read_message_from_file(const gchar *path, gchar **data, size_t *size) @@ -745,8 +731,7 @@ static int __parse_db_request(gchar **params, char **sql_str) gchar *message = NULL; size_t message_size = 0; bundle *bundle = NULL; - playlist_query_s playlist_query = { NULL, NULL, NULL, 0 }; - GSList *iter = NULL; + playlist_query_s playlist_query = { 0, }; mc_retvm_if((!params[2] || !params[3]), MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "invalid query"); @@ -762,23 +747,13 @@ static int __parse_db_request(gchar **params, char **sql_str) playlist_query.server_name = params[1]; playlist_query.playlist_name = params[2]; + playlist_query.query_list = sqlite3_str_new(NULL); bundle_foreach(bundle, __make_playlist_query_cb, &playlist_query); bundle_free(bundle); - mc_retvm_if(!playlist_query.query_list, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "invalid query_list"); - - _sql_str = (char *)sqlite3_malloc(playlist_query.query_length + 1); - if (!_sql_str) { - mc_error("invalid _sql_str"); - g_slist_free_full(playlist_query.query_list, __sqlite3_safe_free); - return MEDIA_CONTROLLER_ERROR_OUT_OF_MEMORY; - } - memset(_sql_str, 0, playlist_query.query_length + 1); - for (iter = playlist_query.query_list; (iter && iter->data); iter = g_slist_next(iter)) - g_strlcat(_sql_str, (char *)iter->data, playlist_query.query_length + 1); - - g_slist_free_full(playlist_query.query_list, __sqlite3_safe_free); + _sql_str = sqlite3_str_finish(playlist_query.query_list); playlist_query.query_list = NULL; + mc_retvm_if(!_sql_str, MEDIA_CONTROLLER_ERROR_INVALID_OPERATION, "invalid query"); } else if (strncmp(MC_DB_CMD_UPDATE_ICON, params[0], strlen(MC_DB_CMD_UPDATE_ICON)) == 0) { if (params[2])