From c1df278dc2aa54a1411028583c37125eb0f5ab0b Mon Sep 17 00:00:00 2001 From: InHong Han Date: Fri, 27 Mar 2020 18:53:03 +0900 Subject: [PATCH] Support to copy thumbnail to RW directory Change-Id: I0a590cbccbca31453898c762baf27309b9980f7c --- client/sticker_dbus.c | 2 +- server/stickerd_data_manager.c | 40 +++++++++++++++++++++++++++++++++++++--- sticker-parser/sticker-parser.c | 3 +++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/client/sticker_dbus.c b/client/sticker_dbus.c index 13eef77..633089c 100644 --- a/client/sticker_dbus.c +++ b/client/sticker_dbus.c @@ -718,7 +718,7 @@ int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_ if (sticker_data->thumbnail && strcmp(sticker_data->thumbnail, origin_data->thumbnail) != 0) { LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, sticker_data->thumbnail); - ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->thumbnail), &reply, "update_sticker_thumbnail"); + ret = _send_sync_message(gdbus_connection, g_variant_new("(iss)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->thumbnail), &reply, "update_sticker_thumbnail"); if (ret != STICKER_CLIENT_ERROR_NONE) { LOGE("failed to update sticker thumbnail"); goto cleanup; diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index 4f0b5b2..fc5492b 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -214,6 +214,7 @@ int stickerd_register_dbus_interface(void) " " " " + " " " " " " @@ -595,6 +596,21 @@ int stickerd_insert_sticker_info(GVariant *parameters, GVariant **reply_body) } } + 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; + } + } + ret = stickerd_db_insert_sticker_info(&record_id, sticker_info); if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to insert sticker info"); @@ -738,8 +754,15 @@ int stickerd_insert_sticker_info_by_json(GVariant *parameters, GVariant **reply_ goto free_memory; sticker_info->thumbnail = _get_string_from_object(info_object, "thumbnail"); - if (!sticker_info->thumbnail) - goto free_memory; + 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) + goto free_memory; + } else { + goto free_memory; + } + } sticker_info->description = _get_string_from_object(info_object, "description"); @@ -892,6 +915,7 @@ int stickerd_update_sticker_thumbnail(GVariant *parameters, GVariant **reply_bod { int ret; int record_id; + char *app_id; char *thumbnail; *reply_body = g_variant_new("()"); @@ -900,7 +924,17 @@ int stickerd_update_sticker_thumbnail(GVariant *parameters, GVariant **reply_bod 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) { diff --git a/sticker-parser/sticker-parser.c b/sticker-parser/sticker-parser.c index 6910d6b..d5a3bd4 100644 --- a/sticker-parser/sticker-parser.c +++ b/sticker-parser/sticker-parser.c @@ -599,6 +599,9 @@ static int __get_sticker_info_from_json(const char *appid, const char *file_path goto free_memory; thumbnail = __get_string_from_object(info_object, "thumbnail"); + if (thumbnail) + thumbnail = __convert_sticker_uri(thumbnail, appid, app_path); + description = __get_string_from_object(info_object, "description"); int disp_type = __get_int_from_object(info_object, "display_type"); -- 2.7.4