#endif
#define LOG_TAG "STICKERD_DATA_MANAGER"
-#define STICKER_DIRECTORY tzplatform_mkpath(TZ_SYS_SHARE, "sticker-data")
#define MAX_ERROR_BUFFER 256
static GHashTable *_monitoring_hash = NULL;
static char error_buffer[MAX_ERROR_BUFFER];
+static GList *consumer_list = NULL;
extern GMainLoop *main_loop;
static void _check_watcher_exist()
LOGD("Terminate sticker daemon");
g_hash_table_destroy(_monitoring_hash);
_monitoring_hash = NULL;
+ g_list_free_full(consumer_list, free);
+ consumer_list = NULL;
g_main_loop_quit(main_loop);
}
}
delete_monitoring_list(&_monitoring_hash, info->bus_name, info->watcher_id);
}
+ if (g_list_find(consumer_list, info->bus_name))
+ consumer_list = g_list_remove(consumer_list, info->bus_name);
+
if (info->bus_name)
free(info->bus_name);
free(info);
if (_monitoring_hash == NULL)
_monitoring_hash = g_hash_table_new(g_direct_hash, g_direct_equal);
+ if (consumer_list == NULL)
+ consumer_list = g_list_alloc();
+
GVariant *reply_body = NULL;
int ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
if (g_strcmp0(method_name, "sticker_service_register") == 0) {
ret = stickerd_server_register(parameters, &reply_body, sender,
- _on_name_appeared, _on_name_vanished, &_monitoring_hash);
+ _on_name_appeared, _on_name_vanished, &_monitoring_hash, &consumer_list);
} else if (g_strcmp0(method_name, "sticker_service_unregister") == 0) {
- ret = stickerd_server_unregister(parameters, &reply_body, sender, &_monitoring_hash);
+ ret = stickerd_server_unregister(parameters, &reply_body, sender, &_monitoring_hash, &consumer_list);
} else if (g_strcmp0(method_name, "insert_sticker_info") == 0) {
ret = stickerd_insert_sticker_info(parameters, &reply_body);
} else if (g_strcmp0(method_name, "update_sticker_info_by_json") == 0) {
ret = stickerd_insert_sticker_info_by_json(parameters, &reply_body, sender);
} else if (g_strcmp0(method_name, "delete_sticker_info") == 0) {
ret = stickerd_del_sticker_info(parameters, &reply_body);
+ } else if (g_strcmp0(method_name, "delete_sticker_info_by_uri") == 0) {
+ ret = stickerd_del_sticker_info_by_uri(parameters, &reply_body);
} else if (g_strcmp0(method_name, "update_sticker_type") == 0) {
ret = stickerd_update_sticker_type(parameters, &reply_body);
} else if (g_strcmp0(method_name, "update_sticker_uri") == 0) {
ret = stickerd_get_sticker_info_by_keyword(parameters, &reply_body);
} else if (g_strcmp0(method_name, "get_sticker_info_by_disp_type") == 0) {
ret = stickerd_get_sticker_info_by_display_type(parameters, &reply_body);
+ } else if (g_strcmp0(method_name, "get_group_list_by_disp_type") == 0) {
+ ret = stickerd_get_group_list_by_disp_type(parameters, &reply_body);
+ } else if (g_strcmp0(method_name, "update_sticker_disp_type") == 0) {
+ ret = stickerd_update_sticker_disp_type(parameters, &reply_body);
+ } else if (g_strcmp0(method_name, "check_file_exists") == 0) {
+ ret = stickerd_check_file_exists(parameters, &reply_body);
+ } else if (g_strcmp0(method_name, "insert_recent_sticker_info") == 0) {
+ ret = stickerd_insert_recent_sticker_info(parameters, &reply_body);
+ } else if (g_strcmp0(method_name, "get_recent_sticker_info") == 0) {
+ ret = stickerd_get_recent_sticker_info(parameters, &reply_body);
+ } else if (g_strcmp0(method_name, "send_update_event") == 0) {
+ 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);
}
if (ret == STICKERD_SERVER_ERROR_NONE) {
" <node>"
" <interface name='org.tizen.sticker_service'>"
" <method name='sticker_service_register'>"
+ " <arg type='i' name='lib_type' direction='in'/>"
" <arg type='i' name='watcher_id' direction='out'/>"
" </method>"
" <method name='sticker_service_unregister'>"
+ " <arg type='i' name='lib_type' direction='in'/>"
" <arg type='i' name='watcher_id' direction='in'/>"
" </method>"
" <arg type='i' name='record_id' direction='in'/>"
" </method>"
+ " <method name='delete_sticker_info_by_uri'>"
+ " <arg type='s' name='uri' direction='in'/>"
+ " </method>"
+
" <method name='update_sticker_type'>"
" <arg type='i' name='record_id' direction='in'/>"
" <arg type='i' name='type' direction='in'/>"
" <method name='update_sticker_thumbnail'>"
" <arg type='i' name='record_id' direction='in'/>"
+ " <arg type='s' name='app_id' direction='in'/>"
" <arg type='s' name='thumbnail' direction='in'/>"
" </method>"
" <arg type='i' name='count' direction='in'/>"
" <arg type='a(i)' name='id_list' direction='out'/>"
" </method>"
+
+ " <method name='get_group_list_by_disp_type'>"
+ " <arg type='s' name='app_id' direction='in'/>"
+ " <arg type='i' name='disp_type' direction='in'/>"
+ " <arg type='a(s)' name='group_list' direction='out'/>"
+ " </method>"
+
+ " <method name='update_sticker_disp_type'>"
+ " <arg type='i' name='record_id' direction='in'/>"
+ " <arg type='i' name='disp_type' direction='in'/>"
+ " </method>"
+
+ " <method name='check_file_exists'>"
+ " <arg type='s' name='uri' direction='in'/>"
+ " <arg type='i' name='result' direction='out'/>"
+ " </method>"
+
+ " <method name='insert_recent_sticker_info'>"
+ " <arg type='i' name='record_id' direction='in'/>"
+ " </method>"
+
+ " <method name='get_recent_sticker_info'>"
+ " <arg type='i' name='count' direction='in'/>"
+ " <arg type='a(i)' name='id_list' direction='out'/>"
+ " </method>"
+
+ " <method name='send_update_event'>"
+ " <arg type='i' name='record_id' direction='in'/>"
+ " </method>"
+
+ " <method name='get_sticker_info_by_uri'>"
+ " <arg type='s' name='uri' direction='in'/>"
+ " <arg type='a{iv}' name='sticker_info' direction='out'/>"
+ " <arg type='a(s)' name='keyword_list' direction='out'/>"
+ " </method>"
" </interface>"
" </node>";
snprintf(new_path, len, "%s/%s/%s",STICKER_DIRECTORY, appid, uri);
if (access(new_path, F_OK) == 0) {
- LOGE("sticker file already exists");
+ LOGE("sticker file already exists : %s", new_path);
ret = -1;
goto cleanup;
}
}
}
+static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder)
+{
+ if (!keyword) {
+ LOGE("keyword doesn't exist");
+ return;
+ }
+
+ g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword);
+}
+
+static GVariant* _get_sticker_g_variant(STICKER_EVENT_TYPE type, sticker_info_db *sticker_info)
+{
+ GVariantBuilder *info_builder;
+ GVariantBuilder *keyword_builder;
+
+ info_builder = g_variant_builder_new(G_VARIANT_TYPE("a{iv}"));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_APP_ID, g_variant_new_string((const gchar *)sticker_info->app_id));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI_TYPE, g_variant_new_int32(sticker_info->type));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI, g_variant_new_string((const gchar *)sticker_info->uri));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_THUMBNAIL, g_variant_new_string((const gchar *)sticker_info->thumbnail));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DESCRIPTION, g_variant_new_string((const gchar *)sticker_info->description));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_GROUP, g_variant_new_string((const gchar *)sticker_info->group));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DATE, g_variant_new_string((const gchar *)sticker_info->date));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DISP_TYPE, g_variant_new_int32(sticker_info->display_type));
+
+ keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
+ g_list_foreach(sticker_info->keyword, (GFunc) _set_keyword_builder, keyword_builder);
+
+ GVariant *body = g_variant_new("(ia{iv}a(s))", (int)type, info_builder, keyword_builder);
+ g_variant_builder_unref(info_builder);
+ g_variant_builder_unref(keyword_builder);
+
+ if (body)
+ return body;
+ else
+ return NULL;
+}
+
+void _get_consumer_busname(gpointer data, gpointer user_data)
+{
+ if (data == NULL)
+ return;
+
+ int ret;
+ char *cmd = "send_sticker_changed_event";
+ char *sender = (char *)data;
+ GVariant *body = (GVariant *)user_data;
+
+ ret = stickerd_send_dbus_message(body, sender, cmd, STICKER_CLIENT_LIB_CONSUMER);
+ if (ret != STICKERD_SERVER_ERROR_NONE)
+ LOGE("Failed to send sticker changed event");
+}
+
+static void _send_sticker_changed_event(STICKER_EVENT_TYPE type, sticker_info_db *sticker_info)
+{
+ GVariant *body = _get_sticker_g_variant(type, sticker_info);
+
+ if (body)
+ g_list_foreach(consumer_list, _get_consumer_busname, body);
+
+ if (body)
+ g_variant_unref(body);
+}
+
+static void _free_sticker_data(sticker_info_db *sticker_data)
+{
+ if (!sticker_data)
+ return;
+
+ if (sticker_data->app_id) {
+ free(sticker_data->app_id);
+ sticker_data->app_id = NULL;
+ }
+
+ if (sticker_data->uri) {
+ free(sticker_data->uri);
+ sticker_data->uri = NULL;
+ }
+
+ if (sticker_data->thumbnail) {
+ free(sticker_data->thumbnail);
+ sticker_data->thumbnail = NULL;
+ }
+
+ if (sticker_data->keyword) {
+ g_list_free_full(sticker_data->keyword, free);
+ sticker_data->keyword = NULL;
+ }
+
+ if (sticker_data->group) {
+ free(sticker_data->group);
+ sticker_data->group = NULL;
+ }
+
+ if (sticker_data->description) {
+ free(sticker_data->description);
+ sticker_data->description = NULL;
+ }
+
+ if (sticker_data->date) {
+ free(sticker_data->date);
+ sticker_data->date = NULL;
+ }
+
+ free(sticker_data);
+}
+
int stickerd_insert_sticker_info(GVariant *parameters, GVariant **reply_body)
{
int ret;
sticker_info->uri = _convert_sticker_uri(sticker_info->uri, sticker_info->app_id);
if (!sticker_info->uri) {
LOGE("failed to copy sticker file");
- ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ ret = STICKERD_SERVER_ERROR_FILE_EXISTS;
goto cleanup;
}
} else {
LOGE("sticker file does not exist");
- ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ ret = STICKERD_SERVER_ERROR_NO_SUCH_FILE;
+ goto cleanup;
+ }
+ }
+
+ if (sticker_info->thumbnail) {
+ if (_check_file_exist(sticker_info->app_id, sticker_info->thumbnail) == 0) {
+ sticker_info->thumbnail = _convert_sticker_uri(sticker_info->thumbnail, sticker_info->app_id);
+ if (!sticker_info->thumbnail) {
+ LOGE("failed to copy sticker thumbnail");
+ ret = STICKERD_SERVER_ERROR_FILE_EXISTS;
+ goto cleanup;
+ }
+ } else {
+ LOGE("sticker thumbnail does not exist");
+ ret = STICKERD_SERVER_ERROR_NO_SUCH_FILE;
goto cleanup;
}
}
if (*reply_body == NULL) {
LOGE("Failed to create reply_body");
ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
- }
+ } else
+ _send_sticker_changed_event(STICKER_EVENT_TYPE_INSERT, sticker_info);
cleanup:
if (value)
continue;
}
- sticker_info->app_id = app_id;
+ sticker_info->app_id = strdup(app_id);
+ if (!sticker_info->app_id)
+ goto free_memory;
+
sticker_info->type = _get_int_from_object(info_object, "type");
if (sticker_info->type < 1)
goto free_memory;
sticker_info->uri = _get_string_from_object(info_object, "uri");
- if (!sticker_info->uri)
+ if (!sticker_info->uri || sticker_info->uri[0] == '\0')
goto free_memory;
if (sticker_info->type == 1) {
sticker_info->uri = _convert_sticker_uri(sticker_info->uri, sticker_info->app_id);
if (!sticker_info->uri)
goto free_memory;
+ } else {
+ goto free_memory;
}
}
goto free_memory;
sticker_info->thumbnail = _get_string_from_object(info_object, "thumbnail");
- if (!sticker_info->thumbnail)
- goto free_memory;
+ if (sticker_info->thumbnail && sticker_info->thumbnail[0] != '\0') {
+ if (_check_file_exist(sticker_info->app_id, sticker_info->thumbnail) == 0) {
+ sticker_info->thumbnail = _convert_sticker_uri(sticker_info->thumbnail, sticker_info->app_id);
+ if (!sticker_info->thumbnail)
+ goto free_memory;
+ } else {
+ goto free_memory;
+ }
+ }
sticker_info->description = _get_string_from_object(info_object, "description");
if (ret != STICKERD_SERVER_ERROR_NONE) {
LOGE("Failed to insert sticker info");
ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
- }
+ } else
+ _send_sticker_changed_event(STICKER_EVENT_TYPE_INSERT, sticker_info);
free_memory:
- free(sticker_info);
+ _free_sticker_data(sticker_info);
sticker_info = NULL;
}
}
g_variant_get(parameters, "(i)", &record_id);
+ sticker_info_db *sticker_info = (sticker_info_db *)calloc(1, sizeof(sticker_info_db));
+ if (sticker_info)
+ stickerd_db_get_sticker_info_by_record_id(record_id, sticker_info);
+
ret = stickerd_db_delete_sticker_info(record_id);
if (ret != STICKERD_SERVER_ERROR_NONE) {
LOGE("Failed to delete sticker info");
+ ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ } else {
+ if (sticker_info && sticker_info->uri)
+ _send_sticker_changed_event(STICKER_EVENT_TYPE_DELETE, sticker_info);
+ }
+
+ if (sticker_info) {
+ _free_sticker_data(sticker_info);
+ sticker_info = NULL;
+ }
+
+ return ret;
+}
+
+int stickerd_del_sticker_info_by_uri(GVariant *parameters, GVariant **reply_body)
+{
+ int ret;
+ 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)", &uri);
+
+ sticker_info_db *sticker_info = (sticker_info_db *)calloc(1, sizeof(sticker_info_db));
+ if (sticker_info)
+ stickerd_db_get_sticker_info_by_uri(uri, sticker_info);
+
+ ret = stickerd_db_delete_sticker_info_by_uri(uri);
+ if (ret != STICKERD_SERVER_ERROR_NONE) {
+ LOGE("Failed to delete sticker info");
+ ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ } else {
+ if (sticker_info && sticker_info->uri)
+ _send_sticker_changed_event(STICKER_EVENT_TYPE_DELETE, sticker_info);
+ }
+
+ if (sticker_info) {
+ _free_sticker_data(sticker_info);
+ sticker_info = NULL;
+ }
+
return ret;
}
uri = _convert_sticker_uri(uri, app_id);
if (!uri) {
LOGE("failed to copy sticker file");
- return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ return STICKERD_SERVER_ERROR_FILE_EXISTS;
}
+ } else {
+ return STICKERD_SERVER_ERROR_NO_SUCH_FILE;
}
}
{
int ret;
int record_id;
+ char *app_id;
char *thumbnail;
*reply_body = g_variant_new("()");
return STICKERD_SERVER_ERROR_OPERATION_FAILED;
}
- g_variant_get(parameters, "(i&s)", &record_id, &thumbnail);
+ g_variant_get(parameters, "(i&s&s)", &record_id, &app_id, &thumbnail);
+
+ if (_check_file_exist(app_id, thumbnail) == 0) {
+ thumbnail = _convert_sticker_uri(thumbnail, app_id);
+ if (!thumbnail) {
+ LOGE("failed to copy sticker thumbnail");
+ return STICKERD_SERVER_ERROR_FILE_EXISTS;
+ }
+ } else {
+ return STICKERD_SERVER_ERROR_NO_SUCH_FILE;
+ }
ret = stickerd_db_update_sticker_info(record_id, STICKER_DB_STICKER_THUMBNAIL, (void *)thumbnail);
if (ret != STICKERD_SERVER_ERROR_NONE) {
return ret;
}
-static void _set_keyword_builder(char *keyword, GVariantBuilder *keyword_builder)
-{
- if (!keyword) {
- LOGE("keyword doesn't exist");
- return;
- }
-
- g_variant_builder_add(keyword_builder, "(s)", (const char *)keyword);
-}
-
int stickerd_get_sticker_info(GVariant *parameters, GVariant **reply_body)
{
int ret;
ret = stickerd_db_get_sticker_info_by_record_id(record_id, sticker_info);
if (ret != STICKERD_SERVER_ERROR_NONE) {
LOGE("Failed to get sticker info");
-
- if (sticker_info->app_id)
- free(sticker_info->app_id);
-
- if (sticker_info->uri)
- free(sticker_info->uri);
-
- if (sticker_info->thumbnail)
- free(sticker_info->thumbnail);
-
- if (sticker_info->keyword)
- free(sticker_info->keyword);
-
- if (sticker_info->group)
- free(sticker_info->group);
-
- if (sticker_info->description)
- free(sticker_info->description);
-
- if (sticker_info->date)
- free(sticker_info->date);
-
- free(sticker_info);
+ _free_sticker_data(sticker_info);
sticker_info = NULL;
return STICKERD_SERVER_ERROR_OPERATION_FAILED;
}
if (*reply_body == NULL) {
LOGE("Failed to create reply_body");
- free(sticker_info);
+ _free_sticker_data(sticker_info);
sticker_info = NULL;
return STICKERD_SERVER_ERROR_OPERATION_FAILED;
}
- free(sticker_info);
+ _free_sticker_data(sticker_info);
sticker_info = NULL;
+
return ret;
}
g_variant_builder_unref(id_builder);
return ret;
+}
+
+int stickerd_get_group_list_by_disp_type(GVariant *parameters, GVariant **reply_body)
+{
+ int ret;
+ GVariantBuilder *builder = NULL;
+ char *app_id = NULL;
+ int disp_type;
+
+ g_variant_get(parameters, "(&si)", &app_id, &disp_type);
+
+ builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
+ ret = stickerd_db_get_group_list_by_display_type(builder, app_id, disp_type);
+ if (ret != STICKERD_SERVER_ERROR_NONE) {
+ LOGE("Failed to get sticker group list");
+ g_variant_builder_unref(builder);
+ return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ }
+
+ *reply_body = g_variant_new("(a(s))", builder);
+ g_variant_builder_unref(builder);
+
+ if (*reply_body == NULL) {
+ LOGE("Failed to create reply_body");
+ return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ }
+
+ return ret;
+}
+
+int stickerd_update_sticker_disp_type(GVariant *parameters, GVariant **reply_body)
+{
+ int ret;
+ int record_id;
+ int disp_type;
+
+ *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, "(ii)", &record_id, &disp_type);
+
+ ret = stickerd_db_update_sticker_info(record_id, STICKER_DB_STICKER_DISP_TYPE, &disp_type);
+ if (ret != STICKERD_SERVER_ERROR_NONE) {
+ LOGE("Failed to update sticker disp_type");
+ return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ }
+
+ return ret;
+}
+
+int stickerd_check_file_exists(GVariant *parameters, GVariant **reply_body)
+{
+ int ret;
+ int result;
+ char *uri = NULL;
+
+ g_variant_get(parameters, "(&s)", &uri);
+
+ ret = stickerd_db_check_file_exists(&result, uri);
+ if (ret != STICKERD_SERVER_ERROR_NONE) {
+ LOGE("Failed to get sticker count");
+ 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_insert_recent_sticker_info(GVariant *parameters, GVariant **reply_body)
+{
+ int ret;
+ int record_id;
+
+ *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, "(i)", &record_id);
+
+ ret = stickerd_db_insert_recent_sticker_info(record_id);
+ if (ret != STICKERD_SERVER_ERROR_NONE) {
+ LOGE("Failed to insert recent sticker info");
+ return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ }
+
+ return ret;
+}
+
+int stickerd_get_recent_sticker_info(GVariant *parameters, GVariant **reply_body)
+{
+ int ret;
+ int count;
+ GList *id_list = NULL;
+ GVariantBuilder *id_builder = NULL;
+
+ g_variant_get(parameters, "(i)", &count);
+
+ ret = stickerd_db_get_record_id(STICKER_DB_STICKER_RECENT_HISTORY, &id_list, NULL, NULL, 0, count);
+ if (ret != STICKERD_SERVER_ERROR_NONE) {
+ LOGE("Failed to get recent sticker id");
+ if(id_list)
+ g_list_free_full(id_list, free);
+ return STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ }
+
+ id_builder = g_variant_builder_new(G_VARIANT_TYPE("a(i)"));
+ g_list_foreach(id_list, (GFunc) _set_id_builder, id_builder);
+
+ *reply_body = g_variant_new("(a(i))", id_builder);
+ if (*reply_body == NULL) {
+ LOGE("Failed to create reply_body");
+ ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ }
+
+ if (id_list)
+ g_list_free_full(id_list, free);
+
+ if (id_builder)
+ g_variant_builder_unref(id_builder);
+
+ return ret;
+}
+
+int stickerd_send_update_event(GVariant *parameters, GVariant **reply_body)
+{
+ int ret = STICKERD_SERVER_ERROR_NONE;
+ int record_id;
+
+ *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, "(i)", &record_id);
+
+ sticker_info_db *sticker_info = (sticker_info_db *)calloc(1, sizeof(sticker_info_db));
+ if (sticker_info) {
+ ret = stickerd_db_get_sticker_info_by_record_id(record_id, sticker_info);
+ if (ret == STICKERD_SERVER_ERROR_NONE)
+ _send_sticker_changed_event(STICKER_EVENT_TYPE_UPDATE, sticker_info);
+
+ _free_sticker_data(sticker_info);
+ sticker_info = NULL;
+ }
+
+ return ret;
+}
+
+int stickerd_get_sticker_info_by_uri(GVariant *parameters, GVariant **reply_body)
+{
+ int ret;
+ char *uri = NULL;
+ GVariantBuilder *info_builder;
+ GVariantBuilder *keyword_builder;
+
+ g_variant_get(parameters, "(&s)", &uri);
+
+ sticker_info_db *sticker_info = (sticker_info_db *)calloc(1, sizeof(sticker_info_db));
+
+ if (!sticker_info)
+ return STICKERD_SERVER_ERROR_OUT_OF_MEMORY;
+
+ ret = stickerd_db_get_sticker_info_by_uri(uri, sticker_info);
+ if (ret != STICKERD_SERVER_ERROR_NONE) {
+ LOGE("Failed to get sticker info");
+ ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+
+ info_builder = g_variant_builder_new(G_VARIANT_TYPE("a{iv}"));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_INFO_ID, g_variant_new_int32(sticker_info->record_id));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_APP_ID, g_variant_new_string((const gchar *)sticker_info->app_id));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI_TYPE, g_variant_new_int32(sticker_info->type));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI, g_variant_new_string((const gchar *)sticker_info->uri));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_THUMBNAIL, g_variant_new_string((const gchar *)sticker_info->thumbnail));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DESCRIPTION, g_variant_new_string((const gchar *)sticker_info->description));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_GROUP, g_variant_new_string((const gchar *)sticker_info->group));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DATE, g_variant_new_string((const gchar *)sticker_info->date));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DISP_TYPE, g_variant_new_int32(sticker_info->display_type));
+
+ keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
+ g_list_foreach(sticker_info->keyword, (GFunc) _set_keyword_builder, keyword_builder);
+
+ *reply_body = g_variant_new("(a{iv}a(s))", info_builder, keyword_builder);
+ g_variant_builder_unref(info_builder);
+ g_variant_builder_unref(keyword_builder);
+
+ if (*reply_body == NULL) {
+ LOGE("Failed to create reply_body");
+ ret = STICKERD_SERVER_ERROR_OPERATION_FAILED;
+ }
+
+cleanup:
+ if (sticker_info) {
+ _free_sticker_data(sticker_info);
+ sticker_info = NULL;
+ }
+
+ return ret;
}
\ No newline at end of file