void *event_cb_user_data;
};
+typedef struct sticker_group_image_s
+{
+ sticker_data_uri_type_e uri_type;
+ char *uri;
+ char *group;
+} sticker_group_image_s;
+
#ifdef __cplusplus
}
#endif
consumer_handle->event_cb_user_data = NULL;
return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_consumer_group_image_list_foreach_all(sticker_consumer_h consumer_handle, sticker_consumer_group_image_list_foreach_cb callback, void *user_data)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret = 0;
+ GList *list = NULL;
+
+ if (!consumer_handle || !callback)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ ret = sticker_dbus_get_group_image_list(consumer_handle->gdbus_connection, consumer_handle->app_id, &list);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to get group image list : %d", ret);
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+
+ for(GList *tmp = g_list_first(list); tmp != NULL; tmp=tmp->next) {
+ sticker_group_image_s *group_image = NULL;
+ group_image = (sticker_group_image_s *)tmp->data;
+ callback(group_image->group, group_image->uri_type, group_image->uri, user_data);
+ }
+
+cleanup:
+ if (list)
+ g_list_free_full(list, free);
+
+ return ret;
}
\ No newline at end of file
return ret;
}
+
+int sticker_dbus_check_group_exists(GDBusConnection *gdbus_connection, const char *app_id, const char *group, int *result)
+{
+ int ret;
+ GDBusMessage *reply = NULL;
+ GVariant *reply_body = NULL;
+
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(ss)", app_id, group), &reply, "check_group_exists");
+ if (ret == STICKER_CLIENT_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(i)", result);
+ }
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+int sticker_dbus_set_group_image(GDBusConnection *gdbus_connection, const char *app_id, const char *group, sticker_data_uri_type_e type, const char *uri)
+{
+ int ret;
+ GDBusMessage *reply = NULL;
+
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(ssis)", app_id, group, (int)type, uri), &reply, "set_group_image");
+ if (ret != STICKER_CLIENT_ERROR_NONE)
+ LOGE("failed to set group image");
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+int sticker_dbus_get_group_image_list(GDBusConnection *gdbus_connection, const char *app_id, GList **group_image_list)
+{
+ int ret;
+ GDBusMessage *reply = NULL;
+ GVariantIter *iter = NULL;
+ GVariant *reply_body = NULL;
+ int type;
+ char *group = NULL;
+ char *uri = NULL;
+
+ if (group_image_list == NULL) {
+ LOGE("group_image_list is invalid");
+ return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_group_image_list");
+ if (ret == STICKER_CLIENT_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(a(sis))", &iter);
+
+ if (!iter) {
+ LOGD("failed to get iter");
+ return STICKER_CLIENT_ERROR_OPERATION_FAILED;
+ }
+
+ while (g_variant_iter_loop (iter, "(sis)", &group, &type, &uri)) {
+ sticker_group_image_s *group_image = NULL;
+ group_image = g_try_new0(sticker_group_image_s, 1);
+ if (group_image) {
+ if (group) {
+ group_image->group = strdup(group);
+ free(group);
+ group = NULL;
+ }
+ group_image->uri_type = (sticker_data_uri_type_e)type;
+ if (uri) {
+ group_image->uri = strdup(uri);
+ free(uri);
+ uri = NULL;
+ }
+
+ *group_image_list = g_list_append(*group_image_list, group_image);
+ }
+ }
+
+ g_variant_iter_free(iter);
+ }
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
\ No newline at end of file
int sticker_dbus_insert_recent_sticker_info(GDBusConnection *gdbus_connection, int record_id);
int sticker_dbus_get_recent_sticker_list(GDBusConnection *gdbus_connection, int count, GVariantIter **id_iter);
int sticker_dbus_get_sticker_info_by_uri(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, const char *uri);
+int sticker_dbus_check_group_exists(GDBusConnection *gdbus_connection, const char *app_id, const char *group, int *result);
+int sticker_dbus_set_group_image(GDBusConnection *gdbus_connection, const char *app_id, const char *group, sticker_data_uri_type_e type, const char *uri);
+int sticker_dbus_get_group_image_list(GDBusConnection *gdbus_connection, const char *app_id, GList **group_image_list);
#ifdef __cplusplus
}
return STICKER_ERROR_NONE;
}
+
+EXPORT_API int sticker_provider_set_group_image(sticker_provider_h provider_handle, const char *group, sticker_data_uri_type_e type, const char *uri)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ int is_exist = 0;
+ char *app_id = NULL;
+ package_info_h package_info = NULL;
+ char *app_path = NULL;
+ char *file_path = NULL;
+
+ if (!provider_handle || !group || !uri)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ ret = app_get_id(&app_id);
+ if (ret != APP_ERROR_NONE) {
+ LOGE("Failed to get app_id : %d", ret); //LCOV_EXCL_LINE
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+
+ ret = sticker_dbus_check_group_exists(provider_handle->gdbus_connection, app_id, group, &is_exist);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to check group exists : %d", ret);
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+
+ if (!is_exist) {
+ LOGE("Group name does not exist");
+ ret = STICKER_ERROR_INVALID_PARAMETER;
+ goto cleanup;
+ }
+
+ if (type == STICKER_DATA_URI_LOCAL_PATH) {
+ ret = package_info_create(app_id, &package_info);
+ if (ret != PACKAGE_MANAGER_ERROR_NONE || package_info == NULL) {
+ LOGE("failed to create package_info. ret: %d", ret); //LCOV_EXCL_LINE
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+
+ ret = package_info_get_root_path(package_info, &app_path);
+ if (ret != PACKAGE_MANAGER_ERROR_NONE || app_path == NULL) {
+ LOGE("failed to create package_info. ret: %d", ret); //LCOV_EXCL_LINE
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+
+ int path_len = strlen(app_path) + strlen(uri) + 2;
+ file_path = (char *)calloc(path_len, sizeof(char));
+ if (!file_path) {
+ LOGE("failed to alloc memory"); //LCOV_EXCL_LINE
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+
+ if(uri[0] == '/')
+ snprintf(file_path, path_len, "%s%s",app_path, uri);
+ else
+ snprintf(file_path, path_len, "%s%s%s",app_path, "/", uri); //LCOV_EXCL_LINE
+
+ if (access(file_path, F_OK) != 0) {
+ LOGE("%s does not exist", file_path);
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+ }
+
+ ret = sticker_dbus_set_group_image(provider_handle->gdbus_connection, app_id, group, type, file_path ? file_path : uri);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to set group image : %d", ret);
+ if (ret == STICKER_CLIENT_ERROR_NO_SUCH_FILE)
+ ret = STICKER_ERROR_NO_SUCH_FILE;
+ else
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ }
+
+cleanup:
+ if (app_id) {
+ free(app_id);
+ app_id = NULL;
+ }
+
+ if (package_info)
+ package_info_destroy(package_info);
+
+ if (app_path) {
+ free(app_path);
+ app_path = NULL;
+ }
+
+ if (file_path) {
+ free(file_path);
+ file_path = NULL;
+ }
+
+ return ret;
+}
\ No newline at end of file
typedef void (*sticker_consumer_event_cb)(sticker_consumer_event_type_e event_type, sticker_data_h data_handle, void *user_data);
/**
+ * @brief Called to retrieve group images in the sticker database.
+ * @details The sticker_consumer_group_image_list_foreach_all() must be called to invoke this callback function, synchronously.
+ * @since_tizen 6.5
+ * @remarks @a group and @a uri should not be freed and can be used only in the callback.
+ * @param[in] group The group name of the stickers
+ * @param[in] type The URI type of the sticker group image URI
+ * @param[in] uri The URI of the sticker group image
+ * @param[in] user_data The user data passed from the foreach function
+ * @pre sticker_consumer_group_image_list_foreach_all() will invoke this callback.
+ * @see sticker_consumer_group_image_list_foreach_all()
+ */
+typedef void (*sticker_consumer_group_image_list_foreach_cb)(const char *group, sticker_data_uri_type_e type, const char *uri, void *user_data);
+
+/**
* @brief Creates a sticker consumer handle.
* @since_tizen 5.5
* @privlevel public
int sticker_consumer_unset_event_cb(sticker_consumer_h consumer_handle);
/**
+ * @brief Retrieves images of all sticker groups in the database.
+ * @since_tizen 6.5
+ * @param[in] consumer_handle The sticker consumer handle
+ * @param[in] callback The callback function to invoke
+ * @param[in] user_data The user data to be passed to the callback function
+ * @return 0 on success, otherwise a negative error value
+ * @retval #STICKER_ERROR_NONE Successful
+ * @retval #STICKER_ERROR_NOT_SUPPORTED Not supported
+ * @retval #STICKER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #STICKER_ERROR_OPERATION_FAILED Operation failed
+ * @post This function invokes sticker_consumer_group_image_list_foreach_cb() repeatedly for getting data.
+ * @see sticker_consumer_group_image_list_foreach_cb()
+ */
+int sticker_consumer_group_image_list_foreach_all(sticker_consumer_h consumer_handle, sticker_consumer_group_image_list_foreach_cb callback, void *user_data);
+
+/**
* @}
*/
int sticker_provider_data_foreach_all(sticker_provider_h provider_handle, int offset, int count, int *result, sticker_provider_data_foreach_cb callback, void *user_data);
/**
+ * @brief Sets the image of the sticker group.
+ * @details @a uri must be a relative path like '/res/smile.png' when @a type is #STICKER_DATA_URI_LOCAL_PATH.
+ * @since_tizen 6.5
+ * @param[in] provider_handle The sticker provider handle
+ * @param[in] group The group name for setting group image
+ * @param[in] type The URI type of the image file
+ * @param[in] uri The URI of the image file
+ * @return 0 on success, otherwise a negative error value
+ * @retval #STICKER_ERROR_NONE Successful
+ * @retval #STICKER_ERROR_NOT_SUPPORTED Not supported
+ * @retval #STICKER_ERROR_INVALID_PARAMETER Invalid parameter, e.g. @a group is @c NULL or the group name does not exist in the database
+ * @retval #STICKER_ERROR_OPERATION_FAILED Operation failed
+ * @retval #STICKER_ERROR_NO_SUCH_FILE No such file, e.g. @a uri is @c NULL or the specified file does not exist
+ * @see sticker_provider_insert_data()
+ */
+int sticker_provider_set_group_image(sticker_provider_h provider_handle, const char *group, sticker_data_uri_type_e type, const char *uri);
+
+/**
* @}
*/
#define MAX_ERROR_BUFFER 256
+enum {
+ STICKER_URI_TYPE_NONE,
+ STICKER_URI_TYPE_LOCAL_PATH,
+ STICKER_URI_TYPE_WEB_RESOURCE,
+};
+
static GHashTable *_monitoring_hash = NULL;
static char error_buffer[MAX_ERROR_BUFFER];
static GList *consumer_list = NULL;
ret = stickerd_send_update_event(parameters, &reply_body);
} else if (g_strcmp0(method_name, "get_sticker_info_by_uri") == 0) {
ret = stickerd_get_sticker_info_by_uri(parameters, &reply_body);
+ } else if (g_strcmp0(method_name, "check_group_exists") == 0) {
+ ret = stickerd_check_group_exists(parameters, &reply_body);
+ } else if (g_strcmp0(method_name, "set_group_image") == 0) {
+ ret = stickerd_set_group_image(parameters, &reply_body);
+ } else if (g_strcmp0(method_name, "get_group_image_list") == 0) {
+ ret = stickerd_get_group_image_list(parameters, &reply_body);
}
if (ret == STICKERD_SERVER_ERROR_NONE) {
" <arg type='a{iv}' name='sticker_info' direction='out'/>"
" <arg type='a(s)' name='keyword_list' direction='out'/>"
" </method>"
+
+ " <method name='check_group_exists'>"
+ " <arg type='s' name='app_id' direction='in'/>"
+ " <arg type='s' name='group' direction='in'/>"
+ " <arg type='i' name='result' direction='out'/>"
+ " </method>"
+
+ " <method name='set_group_image'>"
+ " <arg type='s' name='app_id' direction='in'/>"
+ " <arg type='s' name='group' direction='in'/>"
+ " <arg type='i' name='type' direction='in'/>"
+ " <arg type='s' name='uri' direction='in'/>"
+ " </method>"
+
+ " <method name='get_group_image_list'>"
+ " <arg type='s' name='app_id' direction='in'/>"
+ " <arg type='a(sis)' name='group_image_list' direction='out'/>"
+ " </method>"
" </interface>"
" </node>";
sticker_info->keyword = g_list_append(sticker_info->keyword, strdup((const char *)keyword));
}
- if (sticker_info->type == 1) {
+ if (sticker_info->type == STICKER_URI_TYPE_LOCAL_PATH) {
if (_check_file_exist(sticker_info->app_id, sticker_info->uri) == 0) {
sticker_info->uri = _convert_sticker_uri(sticker_info->uri, sticker_info->app_id);
if (!sticker_info->uri) {
if (!sticker_info->uri || sticker_info->uri[0] == '\0')
goto free_memory;
- if (sticker_info->type == 1) {
+ if (sticker_info->type == STICKER_URI_TYPE_LOCAL_PATH) {
if (_check_file_exist(sticker_info->app_id, sticker_info->uri) == 0) {
sticker_info->uri = _convert_sticker_uri(sticker_info->uri, sticker_info->app_id);
if (!sticker_info->uri)
g_variant_get(parameters, "(i&si&s)", &record_id, &app_id, &type, &uri);
- if (type == 1) {
+ if (type == STICKER_URI_TYPE_LOCAL_PATH) {
if (_check_file_exist(app_id, uri) == 0) {
uri = _convert_sticker_uri(uri, app_id);
if (!uri) {
return ret;
}
+
+int stickerd_check_group_exists(GVariant *parameters, GVariant **reply_body)
+{
+ int ret;
+ int result;
+ char *app_id = NULL;
+ char *group = NULL;
+
+ g_variant_get(parameters, "(&s&s)", &app_id, &group);
+
+ ret = stickerd_db_check_group_exists(&result, app_id, group);
+ if (ret != STICKERD_SERVER_ERROR_NONE) {
+ LOGE("Failed to check group exists");
+ return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ }
+
+ *reply_body = g_variant_new("(i)", result);
+ if (*reply_body == NULL) {
+ LOGE("Failed to create reply_body");
+ return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ }
+
+ return ret;
+}
+
+int stickerd_set_group_image(GVariant *parameters, GVariant **reply_body)
+{
+ int ret;
+ int type;
+ char *app_id = NULL;
+ char *group = NULL;
+ char *uri = NULL;
+
+ *reply_body = g_variant_new("()");
+ if (*reply_body == NULL) {
+ LOGE("Failed to create reply_body");
+ return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ }
+
+ g_variant_get(parameters, "(&s&si&s)", &app_id, &group, &type, &uri);
+
+ if (type == STICKER_URI_TYPE_LOCAL_PATH) {
+ if (_check_file_exist(app_id, uri) == 0) {
+ uri = _convert_sticker_uri(uri, app_id);
+ if(!uri) {
+ LOGE("failed to copy sticker file");
+ return STICKERD_SERVER_ERROR_FILE_EXISTS;
+ }
+ } else {
+ LOGE("sticker file does not exist");
+ return STICKERD_SERVER_ERROR_NO_SUCH_FILE;
+ }
+ }
+
+ ret = stickerd_db_set_group_image(app_id, group, type, uri);
+ if (ret != STICKERD_SERVER_ERROR_NONE) {
+ LOGE("Failed to set group image");
+ return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ }
+
+ return ret;
+}
+
+int stickerd_get_group_image_list(GVariant *parameters, GVariant **reply_body)
+{
+ int ret;
+ GVariantBuilder *builder = NULL;
+ char *app_id = NULL;
+
+ g_variant_get(parameters, "(&s)", &app_id);
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a(sis)"));
+ ret = stickerd_db_get_group_image_list(builder, app_id);
+ if (ret != STICKERD_SERVER_ERROR_NONE) {
+ LOGE("Failed to get sticker group image list");
+ g_variant_builder_unref(builder);
+ return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ }
+
+ *reply_body = g_variant_new("(a(sis))", builder);
+ g_variant_builder_unref(builder);
+
+ if (*reply_body == NULL) {
+ LOGE("Failed to create reply_body");
+ return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ }
+
+ return ret;
+}
\ No newline at end of file
int stickerd_get_recent_sticker_info(GVariant *parameters, GVariant **reply_body);
int stickerd_send_update_event(GVariant *parameters, GVariant **reply_body);
int stickerd_get_sticker_info_by_uri(GVariant *parameters, GVariant **reply_body);
+int stickerd_check_group_exists(GVariant *parameters, GVariant **reply_body);
+int stickerd_set_group_image(GVariant *parameters, GVariant **reply_body);
+int stickerd_get_group_image_list(GVariant *parameters, GVariant **reply_body);
#ifdef __cplusplus
}
* | history_id | sticker_info_id | count | timestamp |
* +------------+-----------------+-------+-----------+
*
+ * * sticker_group_info
+ * +----------+--------+------------+------+------+
+ * | INT | TEXT | TEXT | INT | TEXT |
+ * +----------+--------+------------+------+------+
+ * | group_id | app_id | group_name | type | uri |
+ * +----------+--------+------------+------+------+
+ *
*/
#define STICKER_DB_PATH tzplatform_mkpath(TZ_SYS_DB, ".sticker_info.db")
#define STICKER_KEYWORD_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_keyword_info(keyword_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, keyword TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)"
#define STICKER_WHITELIST_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_whitelist_info(whitelist_id INTEGER PRIMARY KEY AUTOINCREMENT, provider_id TEXT NOT NULL, consumer_id TEXT NOT NULL)"
#define STICKER_RECENT_HISTORY_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_recent_history_info(history_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, count INTEGER NOT NULL, timestamp TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)"
+#define STICKER_GROUP_INFO_CREATRE_TABLE "CREATE TABLE IF NOT EXISTS sticker_group_info(group_id INTEGER PRIMARY KEY AUTOINCREMENT, app_id TEXT NOT NULL, group_name TEXT NOT NULL, type INTEGER NOT NULL, uri TEXT NOT NULL)"
#define STICKER_DB_INSERT_STICKER_INFO "INSERT INTO sticker_info (app_id, type, uri, thumbnail, description, group_name, date, display_type) VALUES (?, ?, ?, ?, ?, ?, DateTime('now','localtime'), ?)"
#define STICKER_DB_INSERT_STICKER_KEYWORD_INFO "INSERT INTO sticker_keyword_info (sticker_info_id, keyword) VALUES (?, ?)"
#define STICKER_DB_INSERT_RECENT_HISTORY "INSERT INTO sticker_recent_history_info (sticker_info_id, count, timestamp) VALUES (?, 1, DateTime('now','localtime'))"
+#define STICKER_DB_INSERT_GROUP_IMAGE "INSERT INTO sticker_group_info (app_id, group_name, type, uri) VALUES (?, ?, ?, ?)"
#define STICKER_DB_DELETE_STICKER_INFO "DELETE FROM sticker_info WHERE sticker_info_id = ?"
#define STICKER_DB_DELETE_STICKER_KEYWORD_INFO "DELETE FROM sticker_keyword_info WHERE sticker_info_id = ?"
#define STICKER_DB_UPDATE_STICKER_GROUP "UPDATE sticker_info SET group_name = ?, date = DateTime('now','localtime') WHERE sticker_info_id = ?"
#define STICKER_DB_UPDATE_STICKER_DISP_TYPE "UPDATE sticker_info SET display_type = ?, date = DateTime('now','localtime') WHERE sticker_info_id = ?"
#define STICKER_DB_UPDATE_RECENT_HISTORY "UPDATE sticker_recent_history_info SET count = count + 1, timestamp = DateTime('now','localtime') WHERE sticker_info_id = ?"
+#define STICKER_DB_UPDATE_GROUP_IMAGE "UPDATE sticker_group_info SET type = ?, uri = ? WHERE app_id = ? AND group_name = ?"
#define STICKER_DB_GET_LATEST_RECORD_ID "SELECT sticker_info_id FROM sticker_info ORDER BY sticker_info_id DESC LIMIT 1"
#define STICKER_DB_GET_STICKER_INFO_BY_RECORD_ID "SELECT * FROM sticker_info WHERE sticker_info_id = ?"
#define STICKER_DB_CHECK_RECENT_HISTORY_EXISTS "SELECT EXISTS(SELECT 1 FROM sticker_recent_history_info WHERE sticker_info_id = ? LIMIT 1)"
#define STICKER_DB_GET_RECENT_HISTORY "SELECT sticker_info_id FROM sticker_recent_history_info ORDER BY datetime(timestamp) DESC LIMIT ?"
#define STICKER_DB_GET_STICKER_INFO_BY_URI "SELECT * FROM sticker_info WHERE uri = ?"
+#define STICKER_DB_CHECK_GROUP_EXISTS_IN_STICKER_INFO "SELECT EXISTS(SELECT 1 FROM sticker_info WHERE group_name = ? AND app_id = ? LIMIT 1)"
+#define STICKER_DB_CHECK_GROUP_EXISTS_IN_GROUP_INFO "SELECT EXISTS(SELECT 1 FROM sticker_group_info WHERE group_name = ? AND app_id = ? LIMIT 1)"
+#define STICKER_DB_GET_ALL_GROUP_IMAGE_LIST "SELECT group_name, type, uri FROM sticker_group_info WHERE app_id NOT IN (SELECT DISTINCT provider_id FROM sticker_whitelist_info WHERE provider_id NOT IN (SELECT provider_id FROM sticker_whitelist_info WHERE consumer_id = ?))"
typedef enum
{
goto cleanup;
}
+ ret = sqlite3_exec(db, STICKER_GROUP_INFO_CREATRE_TABLE, NULL, NULL, &err);
+ if (ret != SQLITE_OK) {
+ LOGE("Failed to create sticker_group_info table : %s", err);
+ ret = STICKERD_SERVER_ERROR_DB_FAILED;
+ goto cleanup;
+ }
+
is_corrupted = FALSE;
cleanup:
goto cleanup;
}
+ ret = sqlite3_exec(db, STICKER_GROUP_INFO_CREATRE_TABLE, NULL, NULL, &err);
+ if (ret != SQLITE_OK) {
+ LOGE("Failed to create sticker_group_info table : %s", err);
+ ret = STICKERD_SERVER_ERROR_DB_FAILED;
+ goto cleanup;
+ }
+
ret = sqlite3_exec(db, "PRAGMA journal_mode = WAL", NULL, NULL, &err);
if (ret != SQLITE_OK) {
LOGE("Failed to set journal_mode : %s", err);
return db;
}
+static gboolean _check_group_exists(char *app_id, char *group)
+{
+ int ret;
+ gboolean result = FALSE;
+ sqlite3 *db = NULL;
+ sqlite3_stmt *stmt = NULL;
+
+ db = _db_open();
+ if (!db)
+ return FALSE;
+
+ ret = sqlite3_prepare_v2(db, STICKER_DB_CHECK_GROUP_EXISTS_IN_GROUP_INFO, -1, &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("fail to check group exists : %s", sqlite3_errmsg(db));
+ goto cleanup;
+ }
+
+ sqlite3_bind_text(stmt, 1, group, -1, SQLITE_TRANSIENT);
+ sqlite3_bind_text(stmt, 2, app_id, -1, SQLITE_TRANSIENT);
+
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_ERROR) {
+ LOGE("sqlite3_step() failed : ret(%d)", ret);
+ goto cleanup;
+ }
+
+ result = sqlite3_column_int(stmt, 0);
+
+ sqlite3_finalize(stmt);
+ sqlite3_close(db);
+
+ return result;
+
+cleanup:
+ sqlite3_finalize(stmt);
+ sqlite3_close(db);
+
+ return FALSE;
+}
+
int stickerd_db_insert_sticker_info(int *record_id, sticker_info_db *sticker_info)
{
int ret;
sqlite3_close(db);
return STICKERD_SERVER_ERROR_DB_FAILED;
+}
+
+int stickerd_db_check_group_exists(int *result, char *app_id, char *group)
+{
+ int ret;
+ sqlite3 *db = NULL;
+ sqlite3_stmt *stmt = NULL;
+
+ db = _db_open();
+ if (!db)
+ return STICKERD_SERVER_ERROR_DB_FAILED;
+
+ ret = sqlite3_prepare_v2(db, STICKER_DB_CHECK_GROUP_EXISTS_IN_STICKER_INFO, -1, &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("fail to check group exists : %s", sqlite3_errmsg(db));
+ goto cleanup;
+ }
+
+ sqlite3_bind_text(stmt, 1, group, -1, SQLITE_TRANSIENT);
+ sqlite3_bind_text(stmt, 2, app_id, -1, SQLITE_TRANSIENT);
+
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_ERROR) {
+ LOGE("sqlite3_step() failed : ret(%d)", ret);
+ goto cleanup;
+ }
+
+ *result = sqlite3_column_int(stmt, 0);
+
+ sqlite3_finalize(stmt);
+ sqlite3_close(db);
+
+ return STICKERD_SERVER_ERROR_NONE;
+
+cleanup:
+ sqlite3_finalize(stmt);
+ sqlite3_close(db);
+
+ return STICKERD_SERVER_ERROR_DB_FAILED;
+}
+
+int stickerd_db_set_group_image(char *app_id, char *group, int type, char *uri)
+{
+ int ret;
+ gboolean is_exist = FALSE;
+ sqlite3 *db = NULL;
+ sqlite3_stmt *stmt = NULL;
+
+ db = _db_open();
+ if (!db)
+ return STICKERD_SERVER_ERROR_DB_FAILED;
+
+ is_exist = _check_group_exists(app_id, group);
+ const char* query = is_exist ? STICKER_DB_UPDATE_GROUP_IMAGE : STICKER_DB_INSERT_GROUP_IMAGE;
+ ret = sqlite3_prepare_v2(db, query, -1, &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("fail to set group image : %s", sqlite3_errmsg(db));
+ goto cleanup;
+ }
+
+ if (is_exist) {
+ sqlite3_bind_int(stmt, 1, type);
+ sqlite3_bind_text(stmt, 2, uri, -1, SQLITE_TRANSIENT);
+ sqlite3_bind_text(stmt, 3, app_id, -1, SQLITE_TRANSIENT);
+ sqlite3_bind_text(stmt, 4, group, -1, SQLITE_TRANSIENT);
+ } else {
+ sqlite3_bind_text(stmt, 1, app_id, -1, SQLITE_TRANSIENT);
+ sqlite3_bind_text(stmt, 2, group, -1, SQLITE_TRANSIENT);
+ sqlite3_bind_int(stmt, 3, type);
+ sqlite3_bind_text(stmt, 4, uri, -1, SQLITE_TRANSIENT);
+ }
+
+ ret = sqlite3_step(stmt);
+ if (ret == SQLITE_ERROR) {
+ LOGE("sqlite3_step() failed : ret(%d)", ret);
+ goto cleanup;
+ }
+
+ sqlite3_finalize(stmt);
+ sqlite3_close(db);
+
+ return STICKERD_SERVER_ERROR_NONE;
+
+cleanup:
+ sqlite3_finalize(stmt);
+ sqlite3_close(db);
+
+ return STICKERD_SERVER_ERROR_DB_FAILED;
+}
+
+int stickerd_db_get_group_image_list(GVariantBuilder *builder, char *app_id)
+{
+ int ret;
+ sqlite3 *db = NULL;
+ sqlite3_stmt *stmt = NULL;
+
+ db = _db_open();
+ if (!db)
+ return STICKERD_SERVER_ERROR_DB_FAILED;
+
+ ret = sqlite3_prepare_v2(db, STICKER_DB_GET_ALL_GROUP_IMAGE_LIST, -1, &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("fail to get group image list : %s", sqlite3_errmsg(db));
+ goto cleanup;
+ }
+
+ sqlite3_bind_text(stmt, 1, app_id, -1, SQLITE_TRANSIENT);
+
+ while (sqlite3_step(stmt) == SQLITE_ROW) {
+ const unsigned char *group = sqlite3_column_text(stmt, 0);
+ int uri_type = sqlite3_column_int(stmt, 1);
+ const unsigned char *uri = sqlite3_column_text(stmt, 2);
+ if (group && uri)
+ g_variant_builder_add(builder, "(sis)", strdup((const char *)group), uri_type, strdup((const char *)uri));
+ }
+
+ sqlite3_finalize(stmt);
+ sqlite3_close(db);
+
+ return STICKERD_SERVER_ERROR_NONE;
+
+cleanup:
+ sqlite3_finalize(stmt);
+ sqlite3_close(db);
+
+ return STICKERD_SERVER_ERROR_DB_FAILED;
}
\ No newline at end of file
int stickerd_db_check_file_exists(int *result, char *uri);
int stickerd_db_insert_recent_sticker_info(int record_id);
int stickerd_db_get_sticker_info_by_uri(char *uri, sticker_info_db *sticker_info);
+int stickerd_db_check_group_exists(int *result, char *app_id, char *group);
+int stickerd_db_set_group_image(char *app_id, char *group, int type, char *uri);
+int stickerd_db_get_group_image_list(GVariantBuilder *builder, char *app_id);
#ifdef __cplusplus
}
#define STICKER_KEYWORD_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_keyword_info(keyword_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, keyword TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)"
#define STICKER_WHITELIST_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_whitelist_info(whitelist_id INTEGER PRIMARY KEY AUTOINCREMENT, provider_id TEXT NOT NULL, consumer_id TEXT NOT NULL)"
#define STICKER_RECENT_HISTORY_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_recent_history_info(history_id INTEGER PRIMARY KEY AUTOINCREMENT, sticker_info_id INTEGER, count INTEGER NOT NULL, timestamp TEXT NOT NULL, FOREIGN KEY (sticker_info_id) REFERENCES sticker_info(sticker_info_id) ON DELETE CASCADE)"
+#define STICKER_GROUP_INFO_CREATRE_TABLE "CREATE TABLE IF NOT EXISTS sticker_group_info(group_id INTEGER PRIMARY KEY AUTOINCREMENT, app_id TEXT NOT NULL, group_name TEXT NOT NULL, type INTEGER NOT NULL, uri TEXT NOT NULL)"
#define UIFW_ID 502
#define APPFW_ID 301
#define MAX_ERROR_BUFFER 256
goto cleanup;
}
+ ret = sqlite3_exec(db, STICKER_GROUP_INFO_CREATRE_TABLE, NULL, NULL, &err);
+ if (ret != SQLITE_OK) {
+ LOGE("Failed to create sticker_recent_history_info table : %s", err);
+ goto cleanup;
+ }
+
is_corrupted = FALSE;
cleanup:
goto cleanup;
}
+ ret = sqlite3_exec(db, STICKER_GROUP_INFO_CREATRE_TABLE, NULL, NULL, &err);
+ if (ret != SQLITE_OK) {
+ LOGE("Failed to create sticker_recent_history_info table : %s", err);
+ goto cleanup;
+ }
+
ret = sqlite3_exec(db, "PRAGMA journal_mode = WAL", NULL, NULL, &err);
if (ret != SQLITE_OK) {
LOGE("Failed to set journal_mode : %s", err);
return;
}
+static void __delete_group_info(const char *db_path, const char *app_id)
+{
+ int ret;
+ sqlite3 *db = NULL;
+ sqlite3_stmt *stmt = NULL;
+
+ db = __db_open(db_path);
+ if (!db)
+ return;
+
+ ret = sqlite3_prepare_v2(db, "DELETE FROM sticker_group_info WHERE app_id = ?", -1, &stmt, NULL);
+ if (ret != SQLITE_OK) {
+ LOGE("failed to delete group information : %s", sqlite3_errmsg(db));
+ sqlite3_finalize(stmt);
+ sqlite3_close(db);
+ goto cleanup;
+ }
+
+ sqlite3_bind_text(stmt, 1, app_id, -1, SQLITE_TRANSIENT);
+
+ ret = sqlite3_step(stmt);
+ if (ret != SQLITE_OK && ret != SQLITE_DONE) {
+ LOGE("sqlite3_step() failed : ret(%d)", ret);
+ goto cleanup;
+ }
+
+ if (sqlite3_changes(db) == 0) {
+ LOGE("No changes to DB");
+ goto cleanup;
+ }
+
+ sqlite3_finalize(stmt);
+ sqlite3_close(db);
+ return;
+
+cleanup:
+ sqlite3_finalize(stmt);
+ sqlite3_close(db);
+ return;
+}
+
static int __remove_directory(const char *path, int is_error_stop)
{
DIR *dir_ptr = NULL;
}
__delete_sticker_allowlist(db_path, appid);
+ __delete_group_info(db_path, appid);
return 0;
}