From 9f0e658cd2f4a1c6123f17ae15bc1ed06e2f64ae Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 7 Feb 2020 16:04:58 +0900 Subject: [PATCH 01/16] Rename from companion to receiver Change-Id: I16e037853f89dd05363e49b56da7d017685357d7 Signed-off-by: Jihoon Kim --- CMakeLists.txt | 2 +- packaging/capi-ui-sticker.spec | 4 ++-- {companion => receiver}/CMakeLists.txt | 8 ++++---- {companion => receiver}/inc/ft.h | 2 +- {companion => receiver}/inc/log.h | 0 {companion => receiver}/inc/main.h | 4 ++-- {companion => receiver}/inc/sticker_info.h | 4 ++-- {companion => receiver}/org.tizen.sticker-consumer.manifest | 0 receiver/org.tizen.sticker-receiver.manifest | 5 +++++ {companion => receiver}/res/xml/accessoryservices.xml | 4 ++-- {companion => receiver}/src/ft.cpp | 0 {companion => receiver}/src/main.cpp | 0 {companion => receiver}/src/sticker_info.cpp | 0 {companion => receiver}/tizen-manifest.xml | 6 +++--- 14 files changed, 22 insertions(+), 17 deletions(-) rename {companion => receiver}/CMakeLists.txt (74%) rename {companion => receiver}/inc/ft.h (95%) rename {companion => receiver}/inc/log.h (100%) rename {companion => receiver}/inc/main.h (67%) rename {companion => receiver}/inc/sticker_info.h (80%) rename {companion => receiver}/org.tizen.sticker-consumer.manifest (100%) create mode 100644 receiver/org.tizen.sticker-receiver.manifest rename {companion => receiver}/res/xml/accessoryservices.xml (81%) rename {companion => receiver}/src/ft.cpp (100%) rename {companion => receiver}/src/main.cpp (100%) rename {companion => receiver}/src/sticker_info.cpp (100%) rename {companion => receiver}/tizen-manifest.xml (79%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b03a770..e2f43a7 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,7 @@ ADD_SUBDIRECTORY(sticker-parser) IF(DEFINED COMPANION_MODE) ## Sticker companion service ## -ADD_SUBDIRECTORY(companion) +ADD_SUBDIRECTORY(receiver) ENDIF() ## config ## diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 3db2912..d14e2c0 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -47,7 +47,7 @@ Group: Graphics & UI Framework/Input Requires: %{name} = %{version}-%{release} %if 0%{?sec_product_feature_profile_wearable} -%define _companion_app_name org.tizen.sticker-consumer +%define _companion_app_name org.tizen.sticker-receiver %package -n %{_companion_app_name} Summary: Sticker companion service @@ -167,7 +167,7 @@ chsmack -a "System::Shared" %{TZ_SYS_SHARE}/sticker-data %if 0%{?sec_product_feature_profile_wearable} %files -n %{_companion_app_name} -%manifest companion/%{_companion_app_name}.manifest +%manifest receiver/%{_companion_app_name}.manifest %{TZ_SYS_RO_PACKAGES}/%{_companion_app_name}.xml %{TZ_SYS_RO_APP}/%{_companion_app_name}/* %endif diff --git a/companion/CMakeLists.txt b/receiver/CMakeLists.txt similarity index 74% rename from companion/CMakeLists.txt rename to receiver/CMakeLists.txt index e326999..3d1e6a9 100644 --- a/companion/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -1,5 +1,5 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -PROJECT(sticker-consumer CXX) +PROJECT(sticker-receiver CXX) SET(SRCS src/main.cpp @@ -15,7 +15,7 @@ pkg_check_modules(pkgs_test REQUIRED sap-client-stub-api ) -INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/companion/inc) +INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/receiver/inc) FOREACH(flag ${pkgs_test_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") @@ -39,5 +39,5 @@ ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_test_LDFLAGS} capi-ui-sticker-provider) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${TZ_SYS_RO_APP}/org.tizen.${PROJECT_NAME}/bin) -INSTALL(FILES ${CMAKE_BINARY_DIR}/companion/tizen-manifest.xml DESTINATION ${TZ_SYS_RO_PACKAGES} RENAME org.tizen.${PROJECT_NAME}.xml) -INSTALL(FILES ${CMAKE_BINARY_DIR}/companion/res/xml/accessoryservices.xml DESTINATION ${TZ_SYS_RO_APP}/org.tizen.${PROJECT_NAME}/res/xml) +INSTALL(FILES ${CMAKE_BINARY_DIR}/receiver/tizen-manifest.xml DESTINATION ${TZ_SYS_RO_PACKAGES} RENAME org.tizen.${PROJECT_NAME}.xml) +INSTALL(FILES ${CMAKE_BINARY_DIR}/receiver/res/xml/accessoryservices.xml DESTINATION ${TZ_SYS_RO_APP}/org.tizen.${PROJECT_NAME}/res/xml) diff --git a/companion/inc/ft.h b/receiver/inc/ft.h similarity index 95% rename from companion/inc/ft.h rename to receiver/inc/ft.h index 9aa4b9b..b64fa8d 100644 --- a/companion/inc/ft.h +++ b/receiver/inc/ft.h @@ -19,7 +19,7 @@ #define __FT_H__ #if !defined(PACKAGE) -#define PACKAGE "org.tizen.sticker-consumer" +#define PACKAGE "org.tizen.sticker-receiver" #endif #define GRP_MAIN "main" diff --git a/companion/inc/log.h b/receiver/inc/log.h similarity index 100% rename from companion/inc/log.h rename to receiver/inc/log.h diff --git a/companion/inc/main.h b/receiver/inc/main.h similarity index 67% rename from companion/inc/main.h rename to receiver/inc/main.h index 361bdd5..473ac68 100644 --- a/companion/inc/main.h +++ b/receiver/inc/main.h @@ -5,10 +5,10 @@ #ifndef __MAIN_H__ #define __MAIN_H__ -#define TAG "STICKER_CONSUMER" +#define TAG "STICKER_RECEIVER" #if !defined(PACKAGE) -#define PACKAGE "org.tizen.sticker-consumer" +#define PACKAGE "org.tizen.sticker-receiver" #endif #endif /* __MAIN_H__ */ diff --git a/companion/inc/sticker_info.h b/receiver/inc/sticker_info.h similarity index 80% rename from companion/inc/sticker_info.h rename to receiver/inc/sticker_info.h index b06c885..e65c244 100644 --- a/companion/inc/sticker_info.h +++ b/receiver/inc/sticker_info.h @@ -1,10 +1,10 @@ #ifndef __STICKER_INFO_H__ #define __STICKER_INFO_H__ -#define TAG "STICKER_CONSUMER" +#define TAG "STICKER_RECEIVER" void insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc); void create_sticker_provider_handle(void); void destroy_sticker_provider_handle(void); -#endif /* __STICKER_INF_H__ */ \ No newline at end of file +#endif /* __STICKER_INF_H__ */ diff --git a/companion/org.tizen.sticker-consumer.manifest b/receiver/org.tizen.sticker-consumer.manifest similarity index 100% rename from companion/org.tizen.sticker-consumer.manifest rename to receiver/org.tizen.sticker-consumer.manifest diff --git a/receiver/org.tizen.sticker-receiver.manifest b/receiver/org.tizen.sticker-receiver.manifest new file mode 100644 index 0000000..017d22d --- /dev/null +++ b/receiver/org.tizen.sticker-receiver.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/companion/res/xml/accessoryservices.xml b/receiver/res/xml/accessoryservices.xml similarity index 81% rename from companion/res/xml/accessoryservices.xml rename to receiver/res/xml/accessoryservices.xml index 6419f03..fee8e4c 100644 --- a/companion/res/xml/accessoryservices.xml +++ b/receiver/res/xml/accessoryservices.xml @@ -1,8 +1,8 @@ - + - + - - + + -- 2.7.4 From ebbae0c2ac0fc22b07add78a9c3cdb1f9a9d6bf0 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 7 Feb 2020 16:12:18 +0900 Subject: [PATCH 02/16] Update package version to 0.1.9 Change-Id: Ic81ac37352d1c82aad49de963bfb84829e44070b Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index d14e2c0..dac6ebc 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.8 +Version: 0.1.9 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 -- 2.7.4 From 910064062f9d7dbbb089cb3ead7e7ded803f7112 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 7 Feb 2020 17:38:25 +0900 Subject: [PATCH 03/16] Remove unused file Change-Id: I3eb51edddd4e23f7e7ea25b06c50e4009150e2f0 Signed-off-by: Jihoon Kim --- receiver/org.tizen.sticker-consumer.manifest | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 receiver/org.tizen.sticker-consumer.manifest diff --git a/receiver/org.tizen.sticker-consumer.manifest b/receiver/org.tizen.sticker-consumer.manifest deleted file mode 100644 index 017d22d..0000000 --- a/receiver/org.tizen.sticker-consumer.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - -- 2.7.4 From fa85fe110a1966440bebb2e3fd5284f2809ed60a Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 10 Feb 2020 11:24:35 +0900 Subject: [PATCH 04/16] Support whitelist to limit access to the sticker DB Change-Id: Ifc768961d6f4ab59251bd14a30b827a610c79bf6 --- client/sticker_dbus.c | 24 +++--- client/sticker_dbus.h | 12 +-- consumer/sticker_consumer.c | 25 ++++-- consumer/sticker_consumer_main.h | 1 + server/stickerd_data_manager.c | 39 ++++++--- server/stickerd_db_manager.c | 64 ++++++++++----- server/stickerd_db_manager.h | 6 +- sticker-parser/sticker-parser.c | 171 ++++++++++++++++++++++++++++++--------- 8 files changed, 248 insertions(+), 94 deletions(-) diff --git a/client/sticker_dbus.c b/client/sticker_dbus.c index 7984351..debfc5f 100644 --- a/client/sticker_dbus.c +++ b/client/sticker_dbus.c @@ -741,7 +741,7 @@ int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection return ret; } -int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, GList **group_list) +int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, const char *app_id, GList **group_list) { int ret; GDBusMessage *reply = NULL; @@ -754,7 +754,7 @@ int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, GList **group return STICKER_CLIENT_ERROR_INVALID_PARAMETER; } - ret = _send_sync_message(gdbus_connection, g_variant_new("()"), &reply, "get_group_list"); + ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_group_list"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); g_variant_get(reply_body, "(a(s))", &iter); @@ -780,7 +780,7 @@ int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, GList **group return ret; } -int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, GList **keyword_list) +int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, const char *app_id, GList **keyword_list) { int ret; GDBusMessage *reply = NULL; @@ -793,7 +793,7 @@ int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, GList **key return STICKER_CLIENT_ERROR_INVALID_PARAMETER; } - ret = _send_sync_message(gdbus_connection, g_variant_new("()"), &reply, "get_keyword_list"); + ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_keyword_list"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); g_variant_get(reply_body, "(a(s))", &iter); @@ -840,13 +840,13 @@ int sticker_dbus_get_sticker_count(GDBusConnection *gdbus_connection, const char return ret; } -int sticker_dbus_get_all_sticker_info(GDBusConnection *gdbus_connection, int offset, int count, GVariantIter **id_iter) +int sticker_dbus_get_all_sticker_info(GDBusConnection *gdbus_connection, const char *app_id, int offset, int count, GVariantIter **id_iter) { int ret; GDBusMessage *reply = NULL; GVariant *reply_body = NULL; - ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", offset, count), &reply, "get_all_sticker_info"); + ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", app_id, offset, count), &reply, "get_all_sticker_info"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); g_variant_get(reply_body, "(a(i))", &(*id_iter)); @@ -882,13 +882,13 @@ int sticker_dbus_get_sticker_info_by_appid(GDBusConnection *gdbus_connection, co return ret; } -int sticker_dbus_get_sticker_info_by_type(GDBusConnection *gdbus_connection, sticker_data_uri_type_e type, int offset, int count, GVariantIter **id_iter) +int sticker_dbus_get_sticker_info_by_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_uri_type_e type, int offset, int count, GVariantIter **id_iter) { int ret; GDBusMessage *reply = NULL; GVariant *reply_body = NULL; - ret = _send_sync_message(gdbus_connection, g_variant_new("(iii)", (int)type, offset, count), &reply, "get_sticker_info_by_type"); + ret = _send_sync_message(gdbus_connection, g_variant_new("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_type"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); g_variant_get(reply_body, "(a(i))", &(*id_iter)); @@ -903,13 +903,13 @@ int sticker_dbus_get_sticker_info_by_type(GDBusConnection *gdbus_connection, sti return ret; } -int sticker_dbus_get_sticker_info_by_group(GDBusConnection *gdbus_connection, const char *group, int offset, int count, GVariantIter **id_iter) +int sticker_dbus_get_sticker_info_by_group(GDBusConnection *gdbus_connection, const char *app_id, const char *group, int offset, int count, GVariantIter **id_iter) { int ret; GDBusMessage *reply = NULL; GVariant *reply_body = NULL; - ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", group, offset, count), &reply, "get_sticker_info_by_group"); + ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, group, offset, count), &reply, "get_sticker_info_by_group"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); g_variant_get(reply_body, "(a(i))", &(*id_iter)); @@ -924,13 +924,13 @@ int sticker_dbus_get_sticker_info_by_group(GDBusConnection *gdbus_connection, co return ret; } -int sticker_dbus_get_sticker_info_by_keyword(GDBusConnection *gdbus_connection, const char *keyword, int offset, int count, GVariantIter **id_iter) +int sticker_dbus_get_sticker_info_by_keyword(GDBusConnection *gdbus_connection, const char *app_id, const char *keyword, int offset, int count, GVariantIter **id_iter) { int ret; GDBusMessage *reply = NULL; GVariant *reply_body = NULL; - ret = _send_sync_message(gdbus_connection, g_variant_new("(sii)", keyword, offset, count), &reply, "get_sticker_info_by_keyword"); + ret = _send_sync_message(gdbus_connection, g_variant_new("(ssii)", app_id, keyword, offset, count), &reply, "get_sticker_info_by_keyword"); if (ret == STICKER_CLIENT_ERROR_NONE) { reply_body = g_dbus_message_get_body(reply); g_variant_get(reply_body, "(a(i))", &(*id_iter)); diff --git a/client/sticker_dbus.h b/client/sticker_dbus.h index 44d2309..52dcd02 100644 --- a/client/sticker_dbus.h +++ b/client/sticker_dbus.h @@ -50,14 +50,14 @@ int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int record_id); int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data); int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, int record_id); -int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, GList **group_list); -int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, GList **keyword_list); +int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, const char *app_id, GList **group_list); +int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, const char *app_id, GList **keyword_list); int sticker_dbus_get_sticker_count(GDBusConnection *gdbus_connection, const char *app_id, int *count); -int sticker_dbus_get_all_sticker_info(GDBusConnection *gdbus_connection, int offset, int count, GVariantIter **id_iter); +int sticker_dbus_get_all_sticker_info(GDBusConnection *gdbus_connection, const char *app_id, int offset, int count, GVariantIter **id_iter); int sticker_dbus_get_sticker_info_by_appid(GDBusConnection *gdbus_connection, const char *app_id, int offset, int count, GVariantIter **id_iter); -int sticker_dbus_get_sticker_info_by_type(GDBusConnection *gdbus_connection, sticker_data_uri_type_e type, int offset, int count, GVariantIter **id_iter); -int sticker_dbus_get_sticker_info_by_group(GDBusConnection *gdbus_connection, const char *group, int offset, int count, GVariantIter **id_iter); -int sticker_dbus_get_sticker_info_by_keyword(GDBusConnection *gdbus_connection, const char *keyword, int offset, int count, GVariantIter **id_iter); +int sticker_dbus_get_sticker_info_by_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_uri_type_e type, int offset, int count, GVariantIter **id_iter); +int sticker_dbus_get_sticker_info_by_group(GDBusConnection *gdbus_connection, const char *app_id, const char *group, int offset, int count, GVariantIter **id_iter); +int sticker_dbus_get_sticker_info_by_keyword(GDBusConnection *gdbus_connection, const char *app_id, const char *keyword, int offset, int count, GVariantIter **id_iter); #ifdef __cplusplus } diff --git a/consumer/sticker_consumer.c b/consumer/sticker_consumer.c index 8602652..aa760de 100644 --- a/consumer/sticker_consumer.c +++ b/consumer/sticker_consumer.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -158,6 +159,13 @@ EXPORT_API int sticker_consumer_create(sticker_consumer_h *consumer_handle) if (!consumer_struct) return STICKER_ERROR_OUT_OF_MEMORY; + ret = app_get_id(&consumer_struct->app_id); + if (ret != APP_ERROR_NONE) { + LOGE("Failed to get app_id : %d", ret); + free(consumer_struct); + return STICKER_ERROR_OPERATION_FAILED; + } + ret = sticker_dbus_init(&consumer_struct->gdbus_connection, &consumer_struct->server_watcher_id, &consumer_struct->monitor_id, &consumer_struct->server_monitor_id, STICKER_CLIENT_LIB_CONSUMER, (void *)consumer_struct); if (ret != STICKER_ERROR_NONE) { @@ -191,6 +199,11 @@ EXPORT_API int sticker_consumer_destroy(sticker_consumer_h consumer_handle) if (consumer_handle->gdbus_connection) g_object_unref(consumer_handle->gdbus_connection); + if (consumer_handle->app_id) { + free(consumer_handle->app_id); + consumer_handle->app_id = NULL; + } + free(consumer_handle); return STICKER_ERROR_NONE; @@ -208,7 +221,7 @@ EXPORT_API int sticker_consumer_data_foreach_all(sticker_consumer_h consumer_han if (!consumer_handle || (offset < 0) || (count <= 0) || !result || !callback) return STICKER_ERROR_INVALID_PARAMETER; - ret = sticker_dbus_get_all_sticker_info(consumer_handle->gdbus_connection, offset, count, &id_iter); + ret = sticker_dbus_get_all_sticker_info(consumer_handle->gdbus_connection, consumer_handle->app_id, offset, count, &id_iter); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to get all sticker information : %d", ret); ret = STICKER_ERROR_OPERATION_FAILED; @@ -256,7 +269,7 @@ EXPORT_API int sticker_consumer_data_foreach_by_keyword(sticker_consumer_h consu if (!consumer_handle || (offset < 0) || (count <= 0) || !result || !keyword || !callback) return STICKER_ERROR_INVALID_PARAMETER; - ret = sticker_dbus_get_sticker_info_by_keyword(consumer_handle->gdbus_connection, keyword, offset, count, &id_iter); + ret = sticker_dbus_get_sticker_info_by_keyword(consumer_handle->gdbus_connection, consumer_handle->app_id, keyword, offset, count, &id_iter); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to get sticker information by keyword : %d", ret); ret = STICKER_ERROR_OPERATION_FAILED; @@ -304,7 +317,7 @@ EXPORT_API int sticker_consumer_data_foreach_by_group(sticker_consumer_h consume if (!consumer_handle || (offset < 0) || (count <= 0) || !result || !group || !callback) return STICKER_ERROR_INVALID_PARAMETER; - ret = sticker_dbus_get_sticker_info_by_group(consumer_handle->gdbus_connection, group, offset, count, &id_iter); + ret = sticker_dbus_get_sticker_info_by_group(consumer_handle->gdbus_connection, consumer_handle->app_id, group, offset, count, &id_iter); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to get sticker information by group : %d", ret); ret = STICKER_ERROR_OPERATION_FAILED; @@ -352,7 +365,7 @@ EXPORT_API int sticker_consumer_data_foreach_by_type(sticker_consumer_h consumer if (!consumer_handle || (offset < 0) || (count <= 0) || !result || (type < 1) || !callback) return STICKER_ERROR_INVALID_PARAMETER; - ret = sticker_dbus_get_sticker_info_by_type(consumer_handle->gdbus_connection, type, offset, count, &id_iter); + ret = sticker_dbus_get_sticker_info_by_type(consumer_handle->gdbus_connection, consumer_handle->app_id, type, offset, count, &id_iter); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to get sticker information by group : %d", ret); ret = STICKER_ERROR_OPERATION_FAILED; @@ -398,7 +411,7 @@ EXPORT_API int sticker_consumer_group_list_foreach_all(sticker_consumer_h consum if (!consumer_handle || !callback) return STICKER_ERROR_INVALID_PARAMETER; - ret = sticker_dbus_get_group_list(consumer_handle->gdbus_connection, &list); + ret = sticker_dbus_get_group_list(consumer_handle->gdbus_connection, consumer_handle->app_id, &list); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to get group list : %d", ret); ret = STICKER_ERROR_OPERATION_FAILED; @@ -426,7 +439,7 @@ EXPORT_API int sticker_consumer_keyword_list_foreach_all(sticker_consumer_h cons if (!consumer_handle || !callback) return STICKER_ERROR_INVALID_PARAMETER; - ret = sticker_dbus_get_keyword_list(consumer_handle->gdbus_connection, &list); + ret = sticker_dbus_get_keyword_list(consumer_handle->gdbus_connection, consumer_handle->app_id, &list); if (ret != STICKER_ERROR_NONE) { LOGE("Failed to get keyword list : %d", ret); ret = STICKER_ERROR_OPERATION_FAILED; diff --git a/consumer/sticker_consumer_main.h b/consumer/sticker_consumer_main.h index 7a08ad2..5f72eaf 100644 --- a/consumer/sticker_consumer_main.h +++ b/consumer/sticker_consumer_main.h @@ -31,6 +31,7 @@ struct sticker_consumer_s { int server_watcher_id; int monitor_id; int server_monitor_id; + char *app_id; }; #ifdef __cplusplus diff --git a/server/stickerd_data_manager.c b/server/stickerd_data_manager.c index 6581922..f0dc8d2 100644 --- a/server/stickerd_data_manager.c +++ b/server/stickerd_data_manager.c @@ -225,10 +225,12 @@ int stickerd_register_dbus_interface(void) " " " " + " " " " " " " " + " " " " " " @@ -238,6 +240,7 @@ int stickerd_register_dbus_interface(void) " " " " + " " " " " " " " @@ -251,6 +254,7 @@ int stickerd_register_dbus_interface(void) " " " " + " " " " " " " " @@ -258,6 +262,7 @@ int stickerd_register_dbus_interface(void) " " " " + " " " " " " " " @@ -265,6 +270,7 @@ int stickerd_register_dbus_interface(void) " " " " + " " " " " " " " @@ -1004,10 +1010,12 @@ int stickerd_get_group_list(GVariant *parameters, GVariant **reply_body) { int ret; GVariantBuilder *builder = NULL; + char *app_id = NULL; - builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)")); - ret = stickerd_db_get_group_list(builder); + g_variant_get(parameters, "(&s)", &app_id); + builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)")); + ret = stickerd_db_get_group_list(builder, app_id); if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to get sticker group list"); g_variant_builder_unref(builder); @@ -1029,9 +1037,12 @@ int stickerd_get_keyword_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(s)")); - ret = stickerd_db_get_keyword_list(builder); + ret = stickerd_db_get_keyword_list(builder, app_id); if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to get sticker keyword list"); g_variant_builder_unref(builder); @@ -1158,12 +1169,13 @@ int stickerd_get_all_sticker_info(GVariant *parameters, GVariant **reply_body) { int ret; int offset, count; + char *app_id = NULL; GList *id_list = NULL; GVariantBuilder *id_builder = NULL; - g_variant_get(parameters, "(ii)", &offset, &count); + g_variant_get(parameters, "(&sii)", &app_id, &offset, &count); - ret = stickerd_db_get_record_id(STICKER_DB_STICKER_ALL, &id_list, NULL, offset, count); + ret = stickerd_db_get_record_id(STICKER_DB_STICKER_ALL, &id_list, NULL, app_id, offset, count); if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to get all sticker id"); if(id_list) @@ -1199,7 +1211,7 @@ int stickerd_get_sticker_info_by_app_id(GVariant *parameters, GVariant **reply_b g_variant_get(parameters, "(&sii)", &app_id, &offset, &count); - ret = stickerd_db_get_record_id(STICKER_DB_STICKER_APPID, &id_list, (void *)app_id, offset, count); + ret = stickerd_db_get_record_id(STICKER_DB_STICKER_APPID, &id_list, NULL, app_id, offset, count); if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to get all sticker id"); if(id_list) @@ -1229,12 +1241,13 @@ int stickerd_get_sticker_info_by_type(GVariant *parameters, GVariant **reply_bod { int ret; GList *id_list = NULL; + char *app_id = NULL; int type, offset, count; GVariantBuilder *id_builder = NULL; - g_variant_get(parameters, "(iii)", &type, &offset, &count); + g_variant_get(parameters, "(&siii)", &app_id, &type, &offset, &count); - ret = stickerd_db_get_record_id(STICKER_DB_STICKER_TYPE, &id_list, &type, offset, count); + ret = stickerd_db_get_record_id(STICKER_DB_STICKER_TYPE, &id_list, &type, app_id, offset, count); if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to get all sticker id"); if(id_list) @@ -1264,13 +1277,14 @@ int stickerd_get_sticker_info_by_group(GVariant *parameters, GVariant **reply_bo { int ret; GList *id_list = NULL; + char *app_id = NULL; char *group = NULL; int offset, count; GVariantBuilder *id_builder = NULL; - g_variant_get(parameters, "(&sii)", &group, &offset, &count); + g_variant_get(parameters, "(&s&sii)", &app_id, &group, &offset, &count); - ret = stickerd_db_get_record_id(STICKER_DB_STICKER_GROUP, &id_list, (void *)group, offset, count); + ret = stickerd_db_get_record_id(STICKER_DB_STICKER_GROUP, &id_list, (void *)group, app_id, offset, count); if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to get all sticker id"); if(id_list) @@ -1300,13 +1314,14 @@ int stickerd_get_sticker_info_by_keyword(GVariant *parameters, GVariant **reply_ { int ret; GList *id_list = NULL; + char *app_id = NULL; char *keyword = NULL; int offset, count; GVariantBuilder *id_builder = NULL; - g_variant_get(parameters, "(&sii)", &keyword, &offset, &count); + g_variant_get(parameters, "(&s&sii)", &app_id, &keyword, &offset, &count); - ret = stickerd_db_get_record_id(STICKER_DB_STICKER_KEYWORD, &id_list, (void *)keyword, offset, count); + ret = stickerd_db_get_record_id(STICKER_DB_STICKER_KEYWORD, &id_list, (void *)keyword, app_id, offset, count); if (ret != STICKERD_SERVER_ERROR_NONE) { LOGE("Failed to get all sticker id"); if(id_list) diff --git a/server/stickerd_db_manager.c b/server/stickerd_db_manager.c index 8f62916..02c4691 100644 --- a/server/stickerd_db_manager.c +++ b/server/stickerd_db_manager.c @@ -44,11 +44,19 @@ * | keyword_id | sticker_info_id | keyword | * +------------+-----------------+---------+ * + * sticker_whitelist_info + * +--------------+-------------+-------------+ + * | INT | TEXT | TEXT | + * +--------------+-------------+-------------+ + * | whitelist_id | provider_id | consumer_id | + * +------------+---------------+-------------+ + * */ #define STICKER_DB_PATH tzplatform_mkpath(TZ_SYS_DB, ".sticker_info.db") -#define STICKER_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_info(sticker_info_id INTEGER PRIMARY KEY AUTOINCREMENT, app_id TEXT NOT NULL, type INTEGER NOT NULL, uri TEXT NOT NULL, thumbnail TEXT, description TEXT, group_name TEXT NOT NULL, date TEXT NOT NULL);" +#define STICKER_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_info(sticker_info_id INTEGER PRIMARY KEY AUTOINCREMENT, app_id TEXT NOT NULL, type INTEGER NOT NULL, uri TEXT NOT NULL, thumbnail TEXT, description TEXT, group_name TEXT NOT NULL, date TEXT NOT NULL)" #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_DB_INSERT_STICKER_INFO "INSERT INTO sticker_info (app_id, type, uri, thumbnail, description, group_name, date) VALUES (?, ?, ?, ?, ?, ?, DateTime('now','localtime'))" #define STICKER_DB_INSERT_STICKER_KEYWORD_INFO "INSERT INTO sticker_keyword_info (sticker_info_id, keyword) VALUES (?, ?)" @@ -65,14 +73,14 @@ #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_GET_KEYWORD_INFO_BY_RECORD_ID "SELECT keyword FROM sticker_keyword_info WHERE sticker_info_id = ?" -#define STICKER_DB_GET_ALL_GROUP_LIST "SELECT group_name from (SELECT DISTINCT group_name from sticker_info)" -#define STICKER_DB_GET_ALL_KEYWORD_LIST "SELECT keyword from (SELECT DISTINCT keyword from sticker_keyword_info)" +#define STICKER_DB_GET_ALL_GROUP_LIST "SELECT DISTINCT group_name FROM sticker_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 = ?))" +#define STICKER_DB_GET_ALL_KEYWORD_LIST "SELECT DISTINCT keyword FROM sticker_keyword_info WHERE sticker_info_id IN (SELECT sticker_info_id from sticker_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 = ?)))" #define STICKER_DB_GET_STICKER_COUNT "SELECT count(*) FROM sticker_info WHERE app_id = ?" -#define STICKER_DB_GET_ALL_RECORD_ID "SELECT sticker_info_id from sticker_info LIMIT ?, ?" +#define STICKER_DB_GET_ALL_RECORD_ID "SELECT sticker_info_id FROM sticker_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 = ?)) LIMIT ?, ?" #define STICKER_DB_GET_RECORD_ID_BY_APP_ID "SELECT sticker_info_id from sticker_info WHERE app_id = ? LIMIT ?, ?" -#define STICKER_DB_GET_RECORD_ID_BY_TYPE "SELECT sticker_info_id from sticker_info WHERE type = ? LIMIT ?, ?" -#define STICKER_DB_GET_RECORD_ID_BY_GROUP "SELECT sticker_info_id from sticker_info WHERE group_name = ? LIMIT ?, ?" -#define STICKER_DB_GET_RECORD_ID_BY_KEYWORD "SELECT sticker_info_id from sticker_keyword_info WHERE keyword = ? LIMIT ?, ?" +#define STICKER_DB_GET_RECORD_ID_BY_TYPE "SELECT sticker_info_id FROM sticker_info WHERE type = ? AND 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 = ?)) LIMIT ?, ?" +#define STICKER_DB_GET_RECORD_ID_BY_GROUP "SELECT sticker_info_id from sticker_info WHERE group_name = ? AND 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 = ?)) LIMIT ?, ?" +#define STICKER_DB_GET_RECORD_ID_BY_KEYWORD "SELECT sticker_info_id FROM sticker_keyword_info WHERE keyword = ? INTERSECT SELECT sticker_info_id from sticker_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 = ?)) LIMIT ?, ?" typedef enum { @@ -169,6 +177,12 @@ static int _recover_db(void) ret = STICKERD_SERVER_ERROR_DB_FAILED; } + ret = sqlite3_exec(db, STICKER_WHITELIST_INFO_CREATE_TABLE, NULL, NULL, &err); + if (ret != SQLITE_OK) { + LOGE("Failed to create sticker_whitelist_info table : %s", err); + ret = STICKERD_SERVER_ERROR_DB_FAILED; + } + is_corrupted = FALSE; cleanup: @@ -220,6 +234,12 @@ int stickerd_db_init(void) goto cleanup; } + ret = sqlite3_exec(db, STICKER_WHITELIST_INFO_CREATE_TABLE, NULL, NULL, &err); + if (ret != SQLITE_OK) { + LOGE("Failed to create sticker_whitelist_info table : %s", err); + ret = STICKERD_SERVER_ERROR_DB_FAILED; + } + ret = sqlite3_exec(db, "PRAGMA journal_mode = WAL", NULL, NULL, &err); if (ret != SQLITE_OK) { LOGE("Failed to set journal_mode : %s", err); @@ -550,7 +570,7 @@ cleanup: return STICKERD_SERVER_ERROR_DB_FAILED; } -int stickerd_db_get_group_list(GVariantBuilder *builder) +int stickerd_db_get_group_list(GVariantBuilder *builder, char *app_id) { int ret; sqlite3 *db = NULL; @@ -566,6 +586,8 @@ int stickerd_db_get_group_list(GVariantBuilder *builder) 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); if (group) @@ -584,7 +606,7 @@ cleanup: return STICKERD_SERVER_ERROR_DB_FAILED; } -int stickerd_db_get_keyword_list(GVariantBuilder *builder) +int stickerd_db_get_keyword_list(GVariantBuilder *builder, char *app_id) { int ret; sqlite3 *db = NULL; @@ -594,6 +616,8 @@ int stickerd_db_get_keyword_list(GVariantBuilder *builder) if (!db) return STICKERD_SERVER_ERROR_DB_FAILED; + sqlite3_bind_text(stmt, 1, app_id, -1, SQLITE_TRANSIENT); + ret = sqlite3_prepare_v2(db, STICKER_DB_GET_ALL_KEYWORD_LIST, -1, &stmt, NULL); if (ret != SQLITE_OK) { LOGE("fail to get keyword list : %s", sqlite3_errmsg(db)); @@ -656,7 +680,7 @@ cleanup: return STICKERD_SERVER_ERROR_DB_FAILED; } -int stickerd_db_get_record_id(sticker_info_db_type type, GList **id_list, void *data, int offset, int count) +int stickerd_db_get_record_id(sticker_info_db_type type, GList **id_list, void *data, char *app_id, int offset, int count) { int ret; sqlite3 *db = NULL; @@ -673,17 +697,19 @@ int stickerd_db_get_record_id(sticker_info_db_type type, GList **id_list, void * goto cleanup; } - if (type == STICKER_DB_STICKER_TYPE) - sqlite3_bind_int(stmt, 1, *(int *)data); - else if (type != STICKER_DB_STICKER_ALL) - sqlite3_bind_text(stmt, 1, (char *)data, -1, SQLITE_TRANSIENT); - - if (type == STICKER_DB_STICKER_ALL) { - sqlite3_bind_int(stmt, 1, offset); - sqlite3_bind_int(stmt, 2, count); - } else { + if (type == STICKER_DB_STICKER_ALL || type == STICKER_DB_STICKER_APPID) { + sqlite3_bind_text(stmt, 1, app_id, -1, SQLITE_TRANSIENT); sqlite3_bind_int(stmt, 2, offset); sqlite3_bind_int(stmt, 3, count); + } else { + if (type == STICKER_DB_STICKER_TYPE) + sqlite3_bind_int(stmt, 1, *(int *)data); + else + sqlite3_bind_text(stmt, 1, (char *)data, -1, SQLITE_TRANSIENT); + + sqlite3_bind_text(stmt, 2, app_id, -1, SQLITE_TRANSIENT); + sqlite3_bind_int(stmt, 3, offset); + sqlite3_bind_int(stmt, 4, count); } while (sqlite3_step(stmt) == SQLITE_ROW) { diff --git a/server/stickerd_db_manager.h b/server/stickerd_db_manager.h index 6e6ebb5..b2ff9bb 100644 --- a/server/stickerd_db_manager.h +++ b/server/stickerd_db_manager.h @@ -51,10 +51,10 @@ int stickerd_db_insert_sticker_info(int *record_id, sticker_info_db *sticker_inf int stickerd_db_delete_sticker_info(int record_id); int stickerd_db_update_sticker_info(int record_id, sticker_info_db_type type, void *data); int stickerd_db_get_sticker_info_by_record_id(int record_id, sticker_info_db *sticker_info); -int stickerd_db_get_group_list(GVariantBuilder *builder); -int stickerd_db_get_keyword_list(GVariantBuilder *builder); +int stickerd_db_get_group_list(GVariantBuilder *builder, char *app_id); +int stickerd_db_get_keyword_list(GVariantBuilder *builder, char *app_id); int stickerd_db_get_sticker_count(int *count, char *app_id); -int stickerd_db_get_record_id(sticker_info_db_type type, GList **id_list, void *data, int offset, int count); +int stickerd_db_get_record_id(sticker_info_db_type type, GList **id_list, void *data, char *app_id, int offset, int count); #ifdef __cplusplus } diff --git a/sticker-parser/sticker-parser.c b/sticker-parser/sticker-parser.c index f8fba16..11e7e91 100644 --- a/sticker-parser/sticker-parser.c +++ b/sticker-parser/sticker-parser.c @@ -41,8 +41,9 @@ #define LOG_TAG "STICKER_PARSER" #define STICKER_DIRECTORY tzplatform_mkpath(TZ_SYS_SHARE, "sticker-data") -#define STICKER_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_info(sticker_info_id INTEGER PRIMARY KEY AUTOINCREMENT, app_id TEXT NOT NULL, type INTEGER NOT NULL, uri TEXT NOT NULL, thumbnail TEXT, description TEXT, group_name TEXT NOT NULL, date TEXT NOT NULL);" +#define STICKER_INFO_CREATE_TABLE "CREATE TABLE IF NOT EXISTS sticker_info(sticker_info_id INTEGER PRIMARY KEY AUTOINCREMENT, app_id TEXT NOT NULL, type INTEGER NOT NULL, uri TEXT NOT NULL, thumbnail TEXT, description TEXT, group_name TEXT NOT NULL, date TEXT NOT NULL)" #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 UIFW_ID 502 #define APPFW_ID 301 #define MAX_ERROR_BUFFER 256 @@ -77,6 +78,21 @@ static int __get_int_from_object(JsonObject *object, const char *key) return type; } +static int __change_ownership(const char *path, int user, int group) +{ + int ret; + uid_t uid = (uid_t)user; + gid_t gid = (gid_t)group; + + ret = chown(path, uid, gid); + if (ret != 0) { + strerror_r(errno, error_buffer, MAX_ERROR_BUFFER); + LOGE("chown() failed : %s", error_buffer); + } + + return ret; +} + static void __recover_db() { int ret; @@ -108,6 +124,12 @@ static void __recover_db() goto cleanup; } + ret = sqlite3_exec(db, STICKER_WHITELIST_INFO_CREATE_TABLE, NULL, NULL, &err); + if (ret != SQLITE_OK) { + LOGE("Failed to create sticker_whitelist_info table : %s", err); + goto cleanup; + } + is_corrupted = FALSE; cleanup: @@ -143,6 +165,9 @@ static void __db_init() goto cleanup; } + if (__change_ownership(db_path, UIFW_ID, UIFW_ID) != 0) + LOGE("failed to change ownership"); + ret = sqlite3_exec(db, STICKER_INFO_CREATE_TABLE, NULL, NULL, &err); if (ret != SQLITE_OK) { LOGE("Failed to create sticker_info table : %s" , err); @@ -155,6 +180,12 @@ static void __db_init() goto cleanup; } + ret = sqlite3_exec(db, STICKER_WHITELIST_INFO_CREATE_TABLE, NULL, NULL, &err); + if (ret != SQLITE_OK) { + LOGE("Failed to create sticker_whitelist_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); @@ -199,21 +230,6 @@ static sqlite3 *__db_open(const char *path) return db; } -static int __change_ownership(const char *path, int user, int group) -{ - int ret; - uid_t uid = (uid_t)user; - gid_t gid = (gid_t)group; - - ret = chown(path, uid, gid); - if (ret != 0) { - strerror_r(errno, error_buffer, MAX_ERROR_BUFFER); - LOGE("chown() failed : %s", error_buffer); - } - - return ret; -} - static int __remove_app_path(char *uri, const char *app_path) { int n = 0; @@ -483,9 +499,44 @@ static void __insert_sticker_keyword_info(const char *keyword) return; } +static void __insert_sticker_whitelist_info(const char *provider, const char *consumer) { + int ret; + sqlite3 *db = NULL; + sqlite3_stmt *stmt = NULL; + const char *db_path; + + db_path = tzplatform_mkpath(TZ_SYS_DB, ".sticker_info.db"); + db = __db_open(db_path); + if (!db) + return; + + ret = sqlite3_prepare_v2(db, "INSERT INTO sticker_whitelist_info (provider_id, consumer_id) VALUES (?, ?)", -1, &stmt, NULL); + if (ret == SQLITE_OK) { + sqlite3_bind_text(stmt, 1, provider, -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 2, consumer, -1, SQLITE_TRANSIENT); + + ret = sqlite3_step(stmt); + if (ret != SQLITE_OK && ret != SQLITE_DONE) + LOGE("sqlite3_step() failed : ret(%d)", ret); + + if (sqlite3_changes(db) == 0) + LOGE("No changes to DB"); + + sqlite3_finalize(stmt); + sqlite3_close(db); + } else { + LOGE("fail to insert sticker whiltelist : %s", sqlite3_errmsg(db)); + sqlite3_finalize(stmt); + sqlite3_close(db); + } + + return; +} + static int __get_sticker_info_from_json(const char *appid, const char *file_path, const char *app_path) { int ret = 1; + int arr_len = 0; JsonParser* parser = NULL; GError* err_msg = NULL; char *uri = NULL; @@ -516,6 +567,13 @@ static int __get_sticker_info_from_json(const char *appid, const char *file_path goto cleanup; } + JsonArray *whitelist_arr = json_object_get_array_member(root_obj, "whitelist"); + if (whitelist_arr != NULL) { + for (int i = 0; i < json_array_get_length(whitelist_arr); i++) { + __insert_sticker_whitelist_info(appid, json_array_get_string_element(whitelist_arr, i)); + } + } + JsonArray *sticker_arr = json_object_get_array_member(root_obj, "sticker"); if (sticker_arr == NULL) { LOGE("failed to get array member"); @@ -523,7 +581,7 @@ static int __get_sticker_info_from_json(const char *appid, const char *file_path goto cleanup; } - int arr_len = json_array_get_length(sticker_arr); + arr_len = json_array_get_length(sticker_arr); for (int i = 0; i < arr_len; i++) { JsonObject *info_object = json_array_get_object_element(sticker_arr, i); if (info_object != NULL) { @@ -633,6 +691,47 @@ cleanup: return ret; } +static void __delete_sticker_whitelist(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_whitelist_info WHERE provider_id = ?", -1, &stmt, NULL); + if (ret != SQLITE_OK) { + LOGE("failed to delete sticker whitelist : %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 void __delete_sticker_info(const char *db_path, int record_id) { int ret; @@ -722,8 +821,7 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList * LOGD("METADATA INSTALL"); LOGD("pkgid: %s, appid: %s", pkgid, appid); - metadata *md = NULL; - GList *md_list = NULL; + metadata *md = (metadata *)list->data; package_info_h package_info = NULL; char *app_path = NULL; char *file_path = NULL; @@ -743,27 +841,21 @@ int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgid, const char *appid, GList * goto cleanup; } - for(md_list = g_list_first(list); md_list != NULL; md_list = md_list->next) { - md = (metadata *)md_list->data; - int path_len = strlen(app_path) + strlen((char *)md->value) + 2; - file_path = (char *)calloc(path_len, sizeof(char)); - if (!file_path) { - LOGE("failed to alloc memory"); - continue; - } + int path_len = strlen(app_path) + strlen((char *)md->value) + 2; + file_path = (char *)calloc(path_len, sizeof(char)); + if (!file_path) { + LOGE("failed to alloc memory"); + goto cleanup; + } - if ((char)md->value[0] == '/') - snprintf(file_path, path_len, "%s%s",app_path, (char *)md->value); - else - snprintf(file_path, path_len, "%s%s%s",app_path, "/", (char *)md->value); + if ((char)md->value[0] == '/') + snprintf(file_path, path_len, "%s%s",app_path, (char *)md->value); + else + snprintf(file_path, path_len, "%s%s%s",app_path, "/", (char *)md->value); - if (__get_sticker_info_from_json(appid, file_path, app_path) == 0) + if (__get_sticker_info_from_json(appid, file_path, app_path) == 0) LOGE("failed to get sticker information [path : %s]", file_path); - free(file_path); - file_path = NULL; - } - cleanup: if (package_info) package_info_destroy(package_info); @@ -773,6 +865,11 @@ cleanup: app_path = NULL; } + if (file_path) { + free(file_path); + file_path = NULL; + } + return 0; } @@ -819,6 +916,8 @@ int PKGMGR_MDPARSER_PLUGIN_UNINSTALL(const char *pkgid, const char *appid, GList sqlite3_close(db); } + __delete_sticker_whitelist(db_path, appid); + return 0; } -- 2.7.4 From 1a4fb7b0af728a71a584364792743403b2bbaba6 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Wed, 12 Feb 2020 10:56:49 +0900 Subject: [PATCH 05/16] Update package version to 0.1.10 Change-Id: I2d8ce47df44d9fb68bb629c90559f5f78aad9280 --- packaging/capi-ui-sticker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index dac6ebc..4565037 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.9 +Version: 0.1.10 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 -- 2.7.4 From 00ae77878b4c6ba82e687e8f2406af6e86f0d7c0 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 13 Feb 2020 10:53:14 +0900 Subject: [PATCH 06/16] Change accessory service profile ID Change-Id: I0b16d85be9c28b9970fd9a4a9ed2bfad874cec4d Signed-off-by: Jihoon Kim --- receiver/res/xml/accessoryservices.xml | 6 +++--- receiver/src/ft.cpp | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/receiver/res/xml/accessoryservices.xml b/receiver/res/xml/accessoryservices.xml index fee8e4c..9f501e5 100644 --- a/receiver/res/xml/accessoryservices.xml +++ b/receiver/res/xml/accessoryservices.xml @@ -3,10 +3,10 @@ + role="consumer" + version="1.0"> diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 1cc0c38..c9af50d 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -28,6 +28,8 @@ #include #include +#define ACCESSORY_SERVICE_PROFILE_ID "/sample/filetransfersender" + #include "sticker_info.h" using namespace std; @@ -325,7 +327,7 @@ gboolean agent_initialize() int result = 0; do { - result = sap_agent_initialize(priv_data.agent, "/sample/filetransfer", SAP_AGENT_ROLE_PROVIDER, + result = sap_agent_initialize(priv_data.agent, ACCESSORY_SERVICE_PROFILE_ID, SAP_AGENT_ROLE_CONSUMER, on_agent_initialized, NULL); dlog_print(DLOG_DEBUG, TAG, "SAP >>> getRegisteredServiceAgent() >>> %d", result); -- 2.7.4 From 68765f49c9221045f17f1154301dbec47bb6e871 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 13 Feb 2020 11:01:08 +0900 Subject: [PATCH 07/16] Update package version to 0.1.11 Change-Id: I1502e32bc3e98810cb315f99980ee546577dc81f Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 4565037..ed33df1 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.10 +Version: 0.1.11 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 -- 2.7.4 From 1db6fb682e7bd06b6ec10d60ed783aa618f4235a Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 20 Feb 2020 11:03:35 +0900 Subject: [PATCH 08/16] Fixed the crash issue when the file is received Change-Id: I1bd033d3cda4b16e537842929b6eccd035678b9d --- receiver/src/ft.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index c9af50d..b073de7 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -143,7 +144,7 @@ static void __set_file_transfer_cb(sap_file_transaction_h file_socket) void accept_file() { int ret; - char file_path[100]; + char file_path[PATH_MAX]; char *data_path = NULL; data_path = app_get_shared_data_path(); -- 2.7.4 From 2ba70694d120c01468e22eb2fdf70aa946a78ecf Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 20 Feb 2020 13:59:18 +0900 Subject: [PATCH 09/16] Remove sticker file after inserting DB Change-Id: I9dccbca14e1a90ee4d188456c65945e8c90f766e --- receiver/inc/sticker_info.h | 2 +- receiver/src/ft.cpp | 10 +++++++--- receiver/src/sticker_info.cpp | 4 +++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/receiver/inc/sticker_info.h b/receiver/inc/sticker_info.h index e65c244..27f2206 100644 --- a/receiver/inc/sticker_info.h +++ b/receiver/inc/sticker_info.h @@ -4,7 +4,7 @@ #define TAG "STICKER_RECEIVER" void insert_sticker_data(const char *filepath, const char *keyword, const char *group, const char *desc); -void create_sticker_provider_handle(void); +int create_sticker_provider_handle(void); void destroy_sticker_provider_handle(void); #endif /* __STICKER_INF_H__ */ diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index b073de7..c5ccfbf 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -69,9 +69,13 @@ static void _on_send_completed(sap_file_transaction_h file_transaction, } else { dlog_print(DLOG_INFO, TAG, "Succeed to change permission : %s", recv_filepath.c_str()); - create_sticker_provider_handle(); - insert_sticker_data(recv_filepath.c_str(), "keyword", "group", "test icon"); - destroy_sticker_provider_handle(); + if (create_sticker_provider_handle() == STICKER_ERROR_NONE) { + insert_sticker_data(recv_filepath.c_str(), "keyword", "group", "test icon"); + destroy_sticker_provider_handle(); + + if (unlink(recv_filepath.c_str()) == -1) + dlog_print(DLOG_ERROR, TAG, "Failed to remove sticker file"); + } } } else { switch (result) { diff --git a/receiver/src/sticker_info.cpp b/receiver/src/sticker_info.cpp index 280b357..0282163 100644 --- a/receiver/src/sticker_info.cpp +++ b/receiver/src/sticker_info.cpp @@ -89,7 +89,7 @@ insert_sticker_data(const char *filepath, const char *keyword, const char *group } } -void create_sticker_provider_handle(void) +int create_sticker_provider_handle(void) { int ret; ret = sticker_provider_create(&sticker_provider); @@ -97,6 +97,8 @@ void create_sticker_provider_handle(void) /* Error handling */ dlog_print(DLOG_ERROR, TAG, "Failed to create sticker provider"); } + + return ret; } void destroy_sticker_provider_handle(void) -- 2.7.4 From 439452ff5e88014255b816fe7338c8faffd5dc93 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 20 Feb 2020 14:07:51 +0900 Subject: [PATCH 10/16] Add org.tizen.sticker-receiver as dependency Change-Id: I1e6f86460f9f26b2e275a03fe2819fff7abf81ac Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 1 + 1 file changed, 1 insertion(+) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index ed33df1..2e744c0 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -31,6 +31,7 @@ BuildRequires: pkgconfig(sap-client-stub-api) BuildRequires: hash-signer Requires(post): signing-client +Requires: org.tizen.sticker-receiver %endif Requires: security-config -- 2.7.4 From 7901b7e447bf2f404750ed731dbf9053d2e45748 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Thu, 20 Feb 2020 14:01:39 +0900 Subject: [PATCH 11/16] Update package version to 0.1.12 Change-Id: I1c3894a7952856a8f09e5a33a9804b1795ae6778 --- packaging/capi-ui-sticker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 2e744c0..b14c2c2 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.11 +Version: 0.1.12 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 -- 2.7.4 From 1882bd6caaadf9728f81b9e03d2cc603cfe938df Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 20 Feb 2020 15:54:11 +0900 Subject: [PATCH 12/16] Fix issue failed to install due to no base directory Change-Id: I73177635916e4f980f357d8b33cfccf65119006c Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index b14c2c2..5cae043 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -167,8 +167,12 @@ chsmack -a "System::Shared" %{TZ_SYS_SHARE}/sticker-data %{_includedir}/sticker_provider.h %if 0%{?sec_product_feature_profile_wearable} +%post -n %{_companion_app_name} +mkdir -p %{TZ_SYS_RO_APP}/%{_companion_app_name} + %files -n %{_companion_app_name} %manifest receiver/%{_companion_app_name}.manifest +%license LICENSE %{TZ_SYS_RO_PACKAGES}/%{_companion_app_name}.xml %{TZ_SYS_RO_APP}/%{_companion_app_name}/* %endif -- 2.7.4 From 23422a723afe9fb8df3c92b88428351cd6aaa3e4 Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 20 Feb 2020 15:59:38 +0900 Subject: [PATCH 13/16] Update package version to 0.1.13 Change-Id: I1c3c03ef79ad85459d970fd17a58114799c45db1 Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 5cae043..75149e5 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.12 +Version: 0.1.13 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 -- 2.7.4 From 532005322b3bfd3ed780b97e39f2605a9cc42b5b Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 20 Feb 2020 19:47:57 +0900 Subject: [PATCH 14/16] Fix signing issue on wearable device Change-Id: If67e682df5da525ed44a883855706829c72f283d Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 75149e5..87df788 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -137,10 +137,6 @@ chown -R ui_fw:ui_fw %{TZ_SYS_SHARE}/sticker-data chsmack -t %{TZ_SYS_SHARE}/sticker-data chsmack -a "System::Shared" %{TZ_SYS_SHARE}/sticker-data -%if 0%{?sec_product_feature_profile_wearable} -/usr/bin/signing-client/hash-signer-client.sh -a -d -p platform %{TZ_SYS_RO_APP}/%{_companion_app_name} -%endif - %postun -p /sbin/ldconfig %files @@ -168,7 +164,7 @@ chsmack -a "System::Shared" %{TZ_SYS_SHARE}/sticker-data %if 0%{?sec_product_feature_profile_wearable} %post -n %{_companion_app_name} -mkdir -p %{TZ_SYS_RO_APP}/%{_companion_app_name} +/usr/bin/signing-client/hash-signer-client.sh -a -d -p platform %{TZ_SYS_RO_APP}/%{_companion_app_name} %files -n %{_companion_app_name} %manifest receiver/%{_companion_app_name}.manifest -- 2.7.4 From b45853c2b013cfc651a9b024a325b01423edde4d Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Thu, 20 Feb 2020 19:48:20 +0900 Subject: [PATCH 15/16] Update package version to 0.1.14 Change-Id: I0189865c1d58bcb461a0db2101b3cc96c2308db6 Signed-off-by: Jihoon Kim --- packaging/capi-ui-sticker.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 87df788..7e4cb25 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -1,6 +1,6 @@ Name: capi-ui-sticker Summary: Sticker client library and daemon -Version: 0.1.13 +Version: 0.1.14 Release: 1 Group: Graphics & UI Framework/Input License: Apache-2.0 -- 2.7.4 From 119054284ae25a733a8d54fcac54800a146767ff Mon Sep 17 00:00:00 2001 From: Jihoon Kim Date: Fri, 21 Feb 2020 20:04:14 +0900 Subject: [PATCH 16/16] Remove unused function Change-Id: I288a400ea7ef143a3337b12ee9596f7065682b2b Signed-off-by: Jihoon Kim --- receiver/src/ft.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index c5ccfbf..133f673 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -215,16 +215,6 @@ void conn_terminated(sap_peer_agent_h peer_agent, } void -on_message_received(sap_peer_agent_h peer_agent, unsigned int payload_length, void *buffer, - void *user_data) /* message exchange on_receive callback (sap_agent_data_received_cb) */ -{ - char *peer_app; - sap_peer_agent_get_app_name(peer_agent, &peer_app); - dlog_print(DLOG_INFO, TAG, "received data: %s, len:%d from %s", (char *)buffer, payload_length, peer_app); - g_free(peer_app); -} - -void on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned int payload_length, void *buffer, void *user_data) /* message exchange on_receive callback (sap_agent_data_received_cb) */ { -- 2.7.4