## Include common directory ##
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/include")
-INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/client")
-INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/provider")
-INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/consumer")
+INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/client/inc")
## Dependent packages ##
INCLUDE(FindPkgConfig)
## API ##
ADD_SUBDIRECTORY(include)
+## Sticker client ##
+ADD_SUBDIRECTORY(client)
+
## Sticker server ##
ADD_SUBDIRECTORY(server)
-## Sticker provider library ##
-ADD_SUBDIRECTORY(provider)
-
-## Sticker consumer library ##
-ADD_SUBDIRECTORY(consumer)
-
## Sticker parser ##
ADD_SUBDIRECTORY(sticker-parser)
--- /dev/null
+SET(CONSUMER_SRCS
+ src/sticker_consumer.c
+ src/sticker_data.c
+ src/sticker_dbus.c
+)
+
+SET(PROVIDER_SRCS
+ src/sticker_provider.c
+ src/sticker_data.c
+ src/sticker_dbus.c
+)
+
+INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/client/inc)
+
+FOREACH(flag ${pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall")
+
+## Add definitions ##
+ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
+
+## sticker consumer library ##
+ADD_LIBRARY(${PROJECT_NAME}-consumer SHARED ${CONSUMER_SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME}-consumer ${pkgs_LDFLAGS})
+
+## sticker provider library ##
+ADD_LIBRARY(${PROJECT_NAME}-provider SHARED ${PROVIDER_SRCS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME}-provider ${pkgs_LDFLAGS})
+
+## Install library files ##
+INSTALL(TARGETS ${PROJECT_NAME}-consumer DESTINATION ${LIBDIR} COMPONENT RuntimeLibraries)
+INSTALL(TARGETS ${PROJECT_NAME}-provider DESTINATION ${LIBDIR} COMPONENT RuntimeLibraries)
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_UIX_STICKER_CONSUMER_MAIN_H__
+#define __TIZEN_UIX_STICKER_CONSUMER_MAIN_H__
+
+#include <gio/gio.h>
+#include <dbus/dbus.h>
+#include "sticker_consumer.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+struct sticker_consumer_s {
+ GDBusConnection *gdbus_connection;
+ int server_watcher_id;
+ int monitor_id;
+ int server_monitor_id;
+ char *app_id;
+ sticker_consumer_event_cb event_cb;
+ void *event_cb_user_data;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_UIX_STICKER_CONSUMER_MAIN_H__ */
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_UIX_STICKER_DATA_MAIN_H__
+#define __TIZEN_UIX_STICKER_DATA_MAIN_H__
+
+#include <glib.h>
+#include "sticker_data.h"
+
+/**
+ * @file sticker_data_main.h
+ */
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+struct sticker_data_s{
+ int sticker_info_id;
+ char *app_id;
+ sticker_data_uri_type_e type;
+ char *uri;
+ char *thumbnail;
+ GList *keyword;
+ char *group;
+ char *description;
+ char *date;
+ sticker_data_display_type_e disp_type;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+/**
+ * @}
+ */
+
+#endif /* __TIZEN_UIX_STICKER_DATA_MAIN_H__ */
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_UIX_STICKER_DEFS_H__
+#define __TIZEN_UIX_STICKER_DEFS_H__
+
+#include <tzplatform_config.h>
+#include <stdbool.h>
+#include <system_info.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define HAPI __attribute__((visibility("hidden")))
+
+#define DBUS_NAME "org.freedesktop.DBus"
+#define DBUS_OBJECT_PATH "/org/freedesktop/DBus"
+#define DBUS_INTERFACE_NAME "org.freedesktop.DBus"
+
+#define STICKER_DBUS_NAME "org.tizen.sticker.server"
+#define STICKER_OBJECT_PATH "/org/tizen/sticker/server"
+#define STICKER_INTERFACE_NAME "org.tizen.sticker_service"
+#define STICKER_PROVIDER_INTERFACE_NAME "org.tizen.sticker_provider"
+#define STICKER_CONSUMER_INTERFACE_NAME "org.tizen.sticker_consumer"
+
+#define STICKER_PRIVILEGE_MEDIASTORAGE "http://tizen.org/privilege/mediastorage"
+#define STICKER_FEATURE_STICKER "tizen.org/feature/ui_service.sticker"
+#define CHECK_STICKER_FEATURE() \
+ do { \
+ bool is_supported = false; \
+ if (!system_info_get_platform_bool(STICKER_FEATURE_STICKER, &is_supported)) { \
+ if (is_supported == false) { \
+ LOGE("ui_service.sticker feature not supported"); \
+ return STICKER_ERROR_NOT_SUPPORTED; \
+ } \
+ } \
+ } while (0)
+#define STICKER_DIRECTORY "/opt/usr/share/sticker-data"
+
+typedef enum {
+ STICKER_CLIENT_LIB_NONE,
+ STICKER_CLIENT_LIB_CONSUMER,
+ STICKER_CLIENT_LIB_PROVIDER,
+} CLIENT_LIB;
+
+typedef enum {
+ STICKER_DATA_TYPE_INFO_ID = 1,
+ STICKER_DATA_TYPE_APP_ID,
+ STICKER_DATA_TYPE_URI_TYPE,
+ STICKER_DATA_TYPE_URI,
+ STICKER_DATA_TYPE_THUMBNAIL,
+ STICKER_DATA_TYPE_DESCRIPTION,
+ STICKER_DATA_TYPE_GROUP,
+ STICKER_DATA_TYPE_KEYWORD,
+ STICKER_DATA_TYPE_DATE,
+ STICKER_DATA_TYPE_DISP_TYPE,
+} STICKER_DAT_TYPE;
+
+typedef enum {
+ STICKER_EVENT_TYPE_INSERT,
+ STICKER_EVENT_TYPE_DELETE,
+ STICKER_EVENT_TYPE_UPDATE,
+} STICKER_EVENT_TYPE;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_UIX_STICKER_DEFS_H__ */
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_UIX_STICKER_PROVIDER_MAIN_H__
+#define __TIZEN_UIX_STICKER_PROVIDER_MAIN_H__
+
+#include <gio/gio.h>
+#include <dbus/dbus.h>
+#include "sticker_provider.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+struct sticker_provider_s {
+ GDBusConnection *gdbus_connection;
+ int server_watcher_id;
+ int monitor_id;
+ int server_monitor_id;
+ sticker_provider_insert_finished_cb insert_finished_cb;
+ void *insert_finished_cb_user_data;
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_UIX_STICKER_PROVIDER_MAIN_H__ */
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlog.h>
+#include <gio/gio.h>
+#include <dbus/dbus.h>
+#include <app_common.h>
+#include <cynara-client.h>
+#include <cynara-error.h>
+#include <cynara-session.h>
+
+#include "sticker_consumer.h"
+#include "sticker_consumer_main.h"
+#include "sticker_dbus.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "STICKER_CONSUMER"
+
+static cynara *p_cynara = NULL;
+
+static int _cynara_initialize()
+{
+ int ret = cynara_initialize(&p_cynara, NULL);
+ if (ret != CYNARA_API_SUCCESS)
+ LOGE("Failed to cynara initialize"); //LCOV_EXCL_LINE
+
+ return ret;
+}
+
+static int _check_privilege(const char *uid, const char *privilege)
+{
+ int ret;
+ FILE *fp = NULL;
+ char label_path[1024] = "/proc/self/attr/current";
+ char smack_label[1024] = {'\0',};
+
+ if (!p_cynara) {
+ return -1;
+ }
+
+ fp = fopen(label_path, "r");
+ if (fp != NULL) {
+ ret = fread(smack_label, 1, sizeof(smack_label), fp);
+ if (ret <= 0)
+ LOGE("Failed to fread");
+
+ fclose(fp);
+ }
+
+ pid_t pid = getpid();
+ char *session = cynara_session_from_pid(pid);
+ ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
+ if (session)
+ free(session);
+
+ if (ret != CYNARA_API_ACCESS_ALLOWED) {
+ LOGE("Access denied. The result of cynara_check() : %d.", ret); //LCOV_EXCL_LINE
+ return -1;
+ }
+
+ return 0;
+}
+
+static void _cynara_deinitialize()
+{
+ if (p_cynara)
+ cynara_finish(p_cynara);
+
+ p_cynara = NULL;
+}
+
+static int _sticker_check_privilege() {
+ char uid[16];
+ int ret = STICKER_ERROR_NONE;
+
+ if (_cynara_initialize() != CYNARA_API_SUCCESS)
+ return STICKER_ERROR_PERMISSION_DENIED;
+
+ snprintf(uid, 16, "%d", getuid());
+ if (_check_privilege(uid, STICKER_PRIVILEGE_MEDIASTORAGE) < 0) {
+ LOGE("Permission is denied"); //LCOV_EXCL_LINE
+ ret = STICKER_ERROR_PERMISSION_DENIED;
+ }
+
+ _cynara_deinitialize();
+
+ return ret;
+}
+
+static int _call_sticker_data_foreach_cb(sticker_consumer_h consumer_handle, GVariantIter *id_iter, sticker_consumer_data_foreach_cb callback, void *user_data)
+{
+ int ret;
+ int info_id;
+ int count = 0;
+
+ if (!id_iter) return count;
+
+ while (g_variant_iter_loop (id_iter, "(i)", &info_id)) {
+ sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
+ if (!sticker_data)
+ continue;
+
+ ret = sticker_dbus_get_sticker_info_by_record_id(consumer_handle->gdbus_connection, sticker_data, info_id);
+ if (ret == STICKER_ERROR_NONE) {
+ count++;
+ callback(sticker_data, user_data);
+ }
+ sticker_data_destroy(sticker_data);
+ }
+
+ return count;
+}
+
+EXPORT_API int sticker_consumer_create(sticker_consumer_h *consumer_handle)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ if (!consumer_handle)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ if (_sticker_check_privilege() != STICKER_ERROR_NONE)
+ return STICKER_ERROR_PERMISSION_DENIED;
+
+ struct sticker_consumer_s *consumer_struct = (sticker_consumer_h)calloc(1, sizeof(struct sticker_consumer_s));
+
+ if (!consumer_struct)
+ return STICKER_ERROR_OUT_OF_MEMORY;
+
+ ret = app_get_id(&consumer_struct->app_id);
+ if (ret != APP_ERROR_NONE) {
+ //LCOV_EXCL_START
+ LOGE("Failed to get app_id : %d", ret);
+ free(consumer_struct);
+ return STICKER_ERROR_OPERATION_FAILED;
+ //LCOV_EXCL_STOP
+ }
+
+ 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) {
+ //LCOV_EXCL_START
+ LOGE("Failed to initialize dbus : %d", ret);
+ free(consumer_struct);
+ return STICKER_ERROR_OPERATION_FAILED;
+ //LCOV_EXCL_STOP
+ }
+
+ *consumer_handle = consumer_struct;
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_consumer_destroy(sticker_consumer_h consumer_handle)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ if (!consumer_handle)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ LOGD("consumer_handle : %p", consumer_handle);
+ ret = sticker_dbus_shutdown(consumer_handle->gdbus_connection, &consumer_handle->server_watcher_id,
+ &consumer_handle->server_monitor_id, &consumer_handle->monitor_id, STICKER_CLIENT_LIB_CONSUMER);
+ if (ret != STICKER_ERROR_NONE) {
+ //LCOV_EXCL_START
+ LOGE("Failed to finalize dbus : %d", ret);
+ free(consumer_handle);
+ return STICKER_ERROR_OPERATION_FAILED;
+ //LCOV_EXCL_STOP
+ }
+
+ 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;
+}
+
+EXPORT_API int sticker_consumer_data_foreach_all(sticker_consumer_h consumer_handle, int offset, int count, int *result, sticker_consumer_data_foreach_cb callback, void *user_data)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ int sticker_count = 0;
+ GVariantIter *id_iter = NULL;
+
+ 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, 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;
+ goto cleanup;
+ }
+
+ if (id_iter)
+ sticker_count = _call_sticker_data_foreach_cb(consumer_handle, id_iter, callback, user_data);
+
+ *result = sticker_count;
+
+cleanup:
+ if (id_iter)
+ g_variant_iter_free(id_iter);
+
+ return ret;
+}
+
+EXPORT_API int sticker_consumer_data_foreach_by_keyword(sticker_consumer_h consumer_handle, int offset, int count, int *result, const char *keyword, sticker_consumer_data_foreach_cb callback, void *user_data)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ int sticker_count = 0;
+ GVariantIter *id_iter = NULL;
+
+ 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, 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;
+ goto cleanup;
+ }
+
+ if (id_iter)
+ sticker_count = _call_sticker_data_foreach_cb(consumer_handle, id_iter, callback, user_data);
+
+ *result = sticker_count;
+
+cleanup:
+ if (id_iter)
+ g_variant_iter_free(id_iter);
+
+ return ret;
+}
+
+EXPORT_API int sticker_consumer_data_foreach_by_group(sticker_consumer_h consumer_handle, int offset, int count, int *result, const char *group, sticker_consumer_data_foreach_cb callback, void *user_data)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ int sticker_count = 0;
+ GVariantIter *id_iter = NULL;
+
+ 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, 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;
+ goto cleanup;
+ }
+
+ if (id_iter)
+ sticker_count = _call_sticker_data_foreach_cb(consumer_handle, id_iter, callback, user_data);
+
+ *result = sticker_count;
+
+cleanup:
+ if (id_iter)
+ g_variant_iter_free(id_iter);
+
+ return ret;
+}
+
+EXPORT_API int sticker_consumer_data_foreach_by_type(sticker_consumer_h consumer_handle, int offset, int count, int *result, sticker_data_uri_type_e type, sticker_consumer_data_foreach_cb callback, void *user_data)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ int sticker_count = 0;
+ GVariantIter *id_iter = NULL;
+
+ 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, consumer_handle->app_id, type, offset, count, &id_iter);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to get sticker information by uri type : %d", ret);
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+
+ if (id_iter)
+ sticker_count = _call_sticker_data_foreach_cb(consumer_handle, id_iter, callback, user_data);
+
+ *result = sticker_count;
+
+cleanup:
+ if (id_iter)
+ g_variant_iter_free(id_iter);
+
+ return ret;
+}
+
+EXPORT_API int sticker_consumer_group_list_foreach_all(sticker_consumer_h consumer_handle, sticker_consumer_group_list_foreach_cb callback, void *user_data)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ GList *list = NULL;
+
+ if (!consumer_handle || !callback)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ 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;
+ goto cleanup;
+ }
+
+ for(GList *tmp = g_list_first(list); tmp != NULL; tmp=tmp->next) {
+ callback((const char *)tmp->data, user_data);
+ }
+
+cleanup:
+ if (list)
+ g_list_free_full(list, free);
+
+ return ret;
+}
+
+EXPORT_API int sticker_consumer_keyword_list_foreach_all(sticker_consumer_h consumer_handle, sticker_consumer_keyword_list_foreach_cb callback, void *user_data)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ GList *list = NULL;
+
+ if (!consumer_handle || !callback)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ 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;
+ goto cleanup;
+ }
+
+ for(GList *tmp = g_list_first(list); tmp != NULL; tmp=tmp->next) {
+ callback((const char *)tmp->data, user_data);
+ }
+
+cleanup:
+ if (list)
+ g_list_free_full(list, free);
+
+ return ret;
+}
+
+EXPORT_API int sticker_consumer_data_foreach_by_display_type(sticker_consumer_h consumer_handle, int offset, int count, int *result, sticker_data_display_type_e type, sticker_consumer_data_foreach_cb callback, void *user_data)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ int sticker_count = 0;
+ GVariantIter *id_iter = NULL;
+
+ if (!consumer_handle || (offset < 0) || (count <= 0) || !result || (type < 1) || !callback)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ ret = sticker_dbus_get_sticker_info_by_display_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 display type : %d", ret);
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+
+ if (id_iter)
+ sticker_count = _call_sticker_data_foreach_cb(consumer_handle, id_iter, callback, user_data);
+
+ *result = sticker_count;
+
+cleanup:
+ if (id_iter)
+ g_variant_iter_free(id_iter);
+
+ return ret;
+}
+
+EXPORT_API int sticker_consumer_group_list_foreach_by_display_type(sticker_consumer_h consumer_handle, sticker_data_display_type_e type, sticker_consumer_group_list_foreach_cb callback, void *user_data)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ GList *list = NULL;
+
+ if (!consumer_handle || (type < 1) || !callback)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ ret = sticker_dbus_get_group_list_by_display_type(consumer_handle->gdbus_connection, consumer_handle->app_id, type, &list);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to get group list : %d", ret);
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+
+ for(GList *tmp = g_list_first(list); tmp != NULL; tmp=tmp->next) {
+ callback((const char *)tmp->data, user_data);
+ }
+
+cleanup:
+ if (list)
+ g_list_free_full(list, free);
+
+ return ret;
+}
+
+EXPORT_API int sticker_consumer_add_recent_data(sticker_consumer_h consumer_handle, sticker_data_h data_handle)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+
+ if (!consumer_handle || !data_handle || (data_handle->sticker_info_id <= 0) || !data_handle->uri)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ ret = sticker_dbus_insert_recent_sticker_info(consumer_handle->gdbus_connection, data_handle->sticker_info_id);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to add recent sticker information : %d", ret);
+ return STICKER_ERROR_OPERATION_FAILED;
+ }
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_consumer_get_recent_data_list(sticker_consumer_h consumer_handle, int count, int *result, sticker_consumer_data_foreach_cb callback, void *user_data)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ int sticker_count = 0;
+ GVariantIter *id_iter = NULL;
+
+ if (!consumer_handle || (count <= 0) || !result || !callback)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ ret = sticker_dbus_get_recent_sticker_list(consumer_handle->gdbus_connection, count, &id_iter);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to get recent sticker information : %d", ret);
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+
+ if (id_iter)
+ sticker_count = _call_sticker_data_foreach_cb(consumer_handle, id_iter, callback, user_data);
+
+ *result = sticker_count;
+
+cleanup:
+ if (id_iter)
+ g_variant_iter_free(id_iter);
+
+ return ret;
+}
+
+EXPORT_API int sticker_consumer_set_event_cb(sticker_consumer_h consumer_handle, sticker_consumer_event_cb callback, void *user_data)
+{
+ CHECK_STICKER_FEATURE();
+
+ if (!consumer_handle || !callback)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ consumer_handle->event_cb = callback;
+ consumer_handle->event_cb_user_data = user_data;
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_consumer_unset_event_cb(sticker_consumer_h consumer_handle)
+{
+ CHECK_STICKER_FEATURE();
+
+ if (!consumer_handle)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ consumer_handle->event_cb = NULL;
+ consumer_handle->event_cb_user_data = NULL;
+
+ return STICKER_ERROR_NONE;
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <dlog.h>
+#include <app_common.h>
+#include <package_manager.h>
+
+#include "sticker_data.h"
+#include "sticker_dbus.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "STICKER_DATA"
+
+static char* _make_absolute_path(const char *relative_path)
+{
+ int ret = STICKER_ERROR_NONE;
+ char *app_id = NULL;
+ package_info_h package_info = NULL;
+ char *app_path = NULL;
+ char *file_path = NULL;
+
+ 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 = 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(relative_path) + 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(relative_path[0] == '/')
+ snprintf(file_path, path_len, "%s%s",app_path, relative_path);
+ else
+ snprintf(file_path, path_len, "%s%s%s",app_path, "/", relative_path); //LCOV_EXCL_LINE
+
+ if (access(file_path, F_OK) != 0) {
+ LOGE("%s does not exist", file_path);
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ free(file_path);
+ }
+
+cleanup:
+ if (app_id)
+ free(app_id);
+
+ if (package_info)
+ package_info_destroy(package_info);
+
+ if (app_path)
+ free(app_path);
+
+ if (ret == STICKER_ERROR_NONE)
+ return file_path;
+ else
+ return NULL;
+}
+
+EXPORT_API int sticker_data_create(sticker_data_h *data_handle)
+{
+ CHECK_STICKER_FEATURE();
+
+ if (!data_handle)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ sticker_data_h data_struct = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
+
+ if (!data_struct)
+ return STICKER_ERROR_OUT_OF_MEMORY;
+
+ char *app_id = NULL;
+ int ret = app_get_id(&app_id);
+ if (ret != APP_ERROR_NONE) {
+ //LCOV_EXCL_START
+ LOGE("Failed to get app_id : %d", ret);
+ free(data_struct);
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ //LCOV_EXCL_STOP
+ }
+
+ data_struct->app_id = strdup(app_id);
+ *data_handle = data_struct;
+
+cleanup:
+ free(app_id);
+
+ return ret;
+}
+
+EXPORT_API int sticker_data_destroy(sticker_data_h data_handle)
+{
+ CHECK_STICKER_FEATURE();
+
+ if (!data_handle)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ if (data_handle->app_id) {
+ free(data_handle->app_id);
+ data_handle->app_id = NULL;
+ }
+
+ if (data_handle->uri) {
+ free(data_handle->uri);
+ data_handle->uri = NULL;
+ }
+
+ if (data_handle->thumbnail) {
+ free(data_handle->thumbnail);
+ data_handle->thumbnail = NULL;
+ }
+
+ if (data_handle->keyword) {
+ g_list_free_full(data_handle->keyword, free);
+ data_handle->keyword = NULL;
+ }
+
+ if (data_handle->group) {
+ free(data_handle->group);
+ data_handle->group = NULL;
+ }
+
+ if (data_handle->description) {
+ free(data_handle->description);
+ data_handle->description = NULL;
+ }
+
+ if (data_handle->date) {
+ free(data_handle->date);
+ data_handle->date = NULL;
+ }
+
+ free(data_handle);
+ data_handle = NULL;
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_data_clone(sticker_data_h origin_handle, sticker_data_h *target_handle)
+{
+ CHECK_STICKER_FEATURE();
+
+ sticker_data_h handle;
+ if (!origin_handle || !target_handle)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ sticker_data_create(&handle);
+ if (!handle)
+ return STICKER_ERROR_OUT_OF_MEMORY;
+
+ handle->sticker_info_id = origin_handle->sticker_info_id;
+
+ if (origin_handle->app_id)
+ handle->app_id = strdup(origin_handle->app_id);
+
+ handle->type = origin_handle->type;
+
+ if (origin_handle->uri)
+ handle->uri = strdup(origin_handle->uri);
+
+ if (origin_handle->thumbnail)
+ handle->thumbnail = strdup(origin_handle->thumbnail);
+
+ if (origin_handle->keyword)
+ handle->keyword = g_list_copy_deep(origin_handle->keyword, (GCopyFunc) g_strdup, NULL);
+
+ if (origin_handle->group)
+ handle->group = strdup(origin_handle->group);
+
+ if (origin_handle->description)
+ handle->description = strdup(origin_handle->description);
+
+ if (origin_handle->date)
+ handle->date = strdup(origin_handle->date);
+
+ handle->disp_type = origin_handle->disp_type;
+
+ *target_handle = handle;
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_data_get_handle(const char* uri, sticker_data_h *data_handle)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ GDBusConnection *gdbus_connection = NULL;
+ int server_watcher_id = 0;
+ int monitor_id = 0;
+ int server_monitor_id = 0;
+ int is_exist = 0;
+
+ if (!uri || uri[0] == '\0' || !data_handle)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ struct sticker_data_s *handle = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
+ if (!handle)
+ return STICKER_ERROR_OUT_OF_MEMORY;
+
+ ret = sticker_dbus_init(&gdbus_connection, &server_watcher_id, &monitor_id, &server_monitor_id, STICKER_CLIENT_LIB_PROVIDER, NULL);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to initialize dbus : %d", ret);
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+
+ ret = sticker_dbus_check_file_exists(gdbus_connection, uri, &is_exist);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to check file exists : %d", ret);
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+
+ if (!is_exist) {
+ LOGE("Sticker does not exist. URI : %s", uri);
+ ret = STICKER_ERROR_NO_SUCH_FILE;
+ goto cleanup;
+ }
+
+ ret = sticker_dbus_get_sticker_info_by_uri(gdbus_connection, handle, uri);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to get sticker information : %d", ret);
+ goto cleanup;
+ }
+
+ *data_handle = handle;
+
+ ret = sticker_dbus_shutdown(gdbus_connection, &server_watcher_id, &server_monitor_id, &monitor_id, STICKER_CLIENT_LIB_PROVIDER);
+ if (ret != STICKER_ERROR_NONE)
+ LOGE("Failed to finalize dbus : %d", ret);
+
+ g_object_unref(gdbus_connection);
+
+ return STICKER_ERROR_NONE;
+
+cleanup:
+ if (handle)
+ sticker_data_destroy(handle);
+
+ if (gdbus_connection) {
+ int ret_err = sticker_dbus_shutdown(gdbus_connection, &server_watcher_id, &server_monitor_id, &monitor_id, STICKER_CLIENT_LIB_PROVIDER);
+ if (ret_err != STICKER_ERROR_NONE)
+ LOGE("Failed to finalize dbus : %d", ret_err);
+
+ g_object_unref(gdbus_connection);
+ }
+
+ return ret;
+}
+
+EXPORT_API int sticker_data_get_app_id(sticker_data_h data_handle, char **app_id)
+{
+ CHECK_STICKER_FEATURE();
+
+ if (!data_handle || !app_id)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ if (!data_handle->app_id)
+ return STICKER_ERROR_NO_DATA;
+
+ *app_id = strdup(data_handle->app_id);
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_data_set_uri(sticker_data_h data_handle, sticker_data_uri_type_e type, const char *uri)
+{
+ CHECK_STICKER_FEATURE();
+
+ char *file_path = NULL;
+ if (!data_handle || !type || !uri || uri[0] == '\0')
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ if (type == STICKER_DATA_URI_LOCAL_PATH) {
+ if (access(uri, F_OK) != 0) {
+ file_path = _make_absolute_path(uri);
+ if (file_path == NULL) {
+ return STICKER_ERROR_INVALID_PARAMETER;
+ }
+ } else
+ file_path = strdup(uri);
+ }
+
+ if (data_handle->uri)
+ free(data_handle->uri);
+
+ data_handle->type = type;
+ if (type == STICKER_DATA_URI_LOCAL_PATH)
+ data_handle->uri = file_path;
+ else
+ data_handle->uri = strdup(uri);
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_data_get_uri(sticker_data_h data_handle, sticker_data_uri_type_e *type, char **uri)
+{
+ CHECK_STICKER_FEATURE();
+
+ if (!data_handle || !type || !uri)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ if (!data_handle->type || !data_handle->uri)
+ return STICKER_ERROR_NO_DATA;
+
+ *type = data_handle->type;
+ *uri = strdup(data_handle->uri);
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_data_foreach_keyword(sticker_data_h data_handle, sticker_data_keyword_foreach_cb callback, void *user_data)
+{
+ CHECK_STICKER_FEATURE();
+
+ if (!data_handle || !callback)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ if (!data_handle->keyword)
+ return STICKER_ERROR_NO_DATA;
+
+ GList *list = NULL;
+ for(list = g_list_first(data_handle->keyword); list != NULL; list=list->next) {
+ callback(list->data, user_data);
+ }
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_data_add_keyword(sticker_data_h data_handle, const char *keyword)
+{
+ CHECK_STICKER_FEATURE();
+
+ GList *node;
+ if (!data_handle || !keyword)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ node = g_list_find_custom(data_handle->keyword, keyword, (GCompareFunc) strcmp);
+
+ if (node) {
+ LOGE("keyword already exists");
+ return STICKER_ERROR_INVALID_PARAMETER;
+ } else {
+ data_handle->keyword = g_list_append(data_handle->keyword, strdup(keyword));
+ }
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_data_remove_keyword(sticker_data_h data_handle, const char *keyword)
+{
+ CHECK_STICKER_FEATURE();
+
+ GList *node;
+ if (!data_handle || !keyword)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ node = g_list_find_custom(data_handle->keyword, keyword, (GCompareFunc) strcmp);
+
+ if (node) {
+ data_handle->keyword = g_list_delete_link(data_handle->keyword, node);
+ } else {
+ LOGE("keyword does not exist");
+ return STICKER_ERROR_INVALID_PARAMETER;
+ }
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_data_set_group_name(sticker_data_h data_handle, const char *group)
+{
+ CHECK_STICKER_FEATURE();
+
+ if (!data_handle || !group)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ if (data_handle->group)
+ free(data_handle->group);
+
+ data_handle->group = strdup(group);
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_data_get_group_name(sticker_data_h data_handle, char **group)
+{
+ CHECK_STICKER_FEATURE();
+
+ if (!data_handle || !group)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ if (!data_handle->group)
+ return STICKER_ERROR_NO_DATA;
+
+ *group = strdup(data_handle->group);
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_data_set_thumbnail(sticker_data_h data_handle, const char *thumbnail)
+{
+ CHECK_STICKER_FEATURE();
+
+ char *file_path = NULL;
+ if (!data_handle || !thumbnail || thumbnail[0] == '\0')
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ if (access(thumbnail, F_OK) != 0) {
+ file_path = _make_absolute_path(thumbnail);
+ if (file_path == NULL)
+ return STICKER_ERROR_INVALID_PARAMETER;
+ } else
+ file_path = strdup(thumbnail);
+
+ if (data_handle->thumbnail)
+ free(data_handle->thumbnail);
+
+ data_handle->thumbnail = file_path;
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_data_get_thumbnail(sticker_data_h data_handle, char **thumbnail)
+{
+ CHECK_STICKER_FEATURE();
+
+ if (!data_handle || !thumbnail)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ if (!data_handle->thumbnail)
+ *thumbnail = strdup("");
+ else
+ *thumbnail = strdup(data_handle->thumbnail);
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_data_set_description(sticker_data_h data_handle, const char *description)
+{
+ CHECK_STICKER_FEATURE();
+
+ if (!data_handle || !description)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ if (data_handle->description)
+ free(data_handle->description);
+
+ data_handle->description = strdup(description);
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_data_get_description(sticker_data_h data_handle, char **description)
+{
+ CHECK_STICKER_FEATURE();
+
+ if (!data_handle || !description)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ if (!data_handle->description)
+ *description = strdup("");
+ else
+ *description = strdup(data_handle->description);
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_data_get_date(sticker_data_h data_handle, char **date)
+{
+ CHECK_STICKER_FEATURE();
+
+ if (!data_handle || !date)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ if (!data_handle->date)
+ return STICKER_ERROR_NO_DATA;
+
+ *date = strdup(data_handle->date);
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_data_set_display_type(sticker_data_h data_handle, sticker_data_display_type_e type)
+{
+ CHECK_STICKER_FEATURE();
+
+ if (!data_handle || !type || type < STICKER_DATA_DISP_EMOJI || type > STICKER_DATA_DISP_WALLPAPER)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ data_handle->disp_type = type;
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_data_get_display_type(sticker_data_h data_handle, sticker_data_display_type_e *type)
+{
+ CHECK_STICKER_FEATURE();
+
+ if (!data_handle || !type)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ *type = data_handle->disp_type;
+
+ return STICKER_ERROR_NONE;
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlog.h>
+
+#include "sticker_dbus.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "STICKER_DBUS"
+
+#define STICKER_DIRECTORY "/opt/usr/share/sticker-data"
+
+static int is_server_started = 0;
+static CLIENT_LIB last_req_lib = STICKER_CLIENT_LIB_NONE;
+
+static void _server_appeared_cb(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data)
+{
+ LOGD("name : %s, name_owner : %s", name, name_owner);
+}
+
+//LCOV_EXCL_START
+static void _server_vanished_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
+{
+ LOGD("name : %s", name);
+}
+//LCOV_EXCL_STOP
+
+static int _dbus_init(GDBusConnection **gdbus_connection)
+{
+ GError *error = NULL;
+ int watch_id = 0;
+
+ if (*gdbus_connection == NULL) {
+ GDBusConnection *conn = NULL;
+ conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+ if (conn == NULL) {
+ //LCOV_EXCL_START
+ if (error != NULL) {
+ LOGE("g_bus_get_sync error message = %s", error->message);
+ g_error_free(error);
+ }
+ //LCOV_EXCL_STOP
+ return STICKER_CLIENT_ERROR_IO_ERROR;
+ }
+ *gdbus_connection = conn;
+ }
+
+ LOGD("Connected bus name : %s", g_dbus_connection_get_unique_name(*gdbus_connection));
+ watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
+ STICKER_DBUS_NAME,
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ _server_appeared_cb,
+ _server_vanished_cb,
+ NULL, NULL);
+
+ LOGD("watch_id : %d", watch_id);
+ if (watch_id == 0) {
+ LOGE("Failed to get identifier"); //LCOV_EXCL_LINE
+ return STICKER_CLIENT_ERROR_IO_ERROR;
+ }
+
+ return STICKER_CLIENT_ERROR_NONE;
+}
+
+static void _get_sticker_info_from_gvariant(GVariantIter *info_iter, GVariantIter *keyword_iter, sticker_data_h sticker_data)
+{
+ STICKER_DAT_TYPE key;
+ GVariant *value = NULL;
+ char *keyword = NULL;
+
+ if (!info_iter || !keyword_iter) {
+ LOGW("failed to get iter");
+ return;
+ }
+
+ while (g_variant_iter_loop (info_iter, "{iv}", &key, &value)) {
+ switch(key) {
+ case STICKER_DATA_TYPE_INFO_ID:
+ sticker_data->sticker_info_id = g_variant_get_int32(value);
+ break;
+ case STICKER_DATA_TYPE_APP_ID:
+ sticker_data->app_id = g_variant_dup_string(value, NULL);
+ break;
+ case STICKER_DATA_TYPE_URI_TYPE:
+ sticker_data->type = g_variant_get_int32(value);
+ break;
+ case STICKER_DATA_TYPE_URI:
+ sticker_data->uri = g_variant_dup_string(value, NULL);
+ break;
+ case STICKER_DATA_TYPE_THUMBNAIL:
+ sticker_data->thumbnail = g_variant_dup_string(value, NULL);
+ break;
+ case STICKER_DATA_TYPE_DESCRIPTION:
+ sticker_data->description = g_variant_dup_string(value, NULL);
+ break;
+ case STICKER_DATA_TYPE_GROUP:
+ sticker_data->group = g_variant_dup_string(value, NULL);
+ break;
+ case STICKER_DATA_TYPE_DATE:
+ sticker_data->date = g_variant_dup_string(value, NULL);
+ break;
+ case STICKER_DATA_TYPE_DISP_TYPE:
+ sticker_data->disp_type = g_variant_get_int32(value);
+ break;
+ default:
+ break;
+ }
+ }
+
+ while (g_variant_iter_loop (keyword_iter, "(s)", &keyword)) {
+ sticker_data->keyword = g_list_append(sticker_data->keyword, strdup((const char *)keyword));
+ }
+
+ if (value)
+ g_variant_unref(value);
+
+ g_variant_iter_free(info_iter);
+ g_variant_iter_free(keyword_iter);
+}
+
+static void _call_insert_finished_cb(sticker_provider_h provider_handle, GVariant *body)
+{
+ int ret;
+ g_variant_get(body, "(i)", &ret);
+
+ if (ret == 0) {
+ provider_handle->insert_finished_cb(STICKER_ERROR_NONE, provider_handle->insert_finished_cb_user_data);
+ } else {
+ provider_handle->insert_finished_cb(STICKER_ERROR_OPERATION_FAILED, provider_handle->insert_finished_cb_user_data);
+ }
+}
+
+//LCOV_EXCL_START
+static void _handle_sticker_consumer_cb(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
+
+ sticker_consumer_h consumer_handle = (sticker_consumer_h)user_data;
+
+ if (consumer_handle == NULL) {
+ LOGE("consumer handle is not available");
+ return;
+ }
+
+ if (parameters == NULL) {
+ LOGE("failed to get sticker info");
+ return;
+ }
+
+ if (g_strcmp0(signal_name, "send_sticker_changed_event") == 0) {
+ if (consumer_handle->event_cb != NULL) {
+ sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
+ if (sticker_data) {
+ int event_type;
+ GVariantIter *info_iter = NULL;
+ GVariantIter *keyword_iter = NULL;
+
+ g_variant_get(parameters, "(ia{iv}a(s))", &event_type, &info_iter, &keyword_iter);
+ _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
+ consumer_handle->event_cb((sticker_consumer_event_type_e)event_type, sticker_data, consumer_handle->event_cb_user_data);
+
+ if (info_iter)
+ g_variant_iter_free(info_iter);
+
+ if (keyword_iter)
+ g_variant_iter_free(keyword_iter);
+
+ sticker_data_destroy(sticker_data);
+ }
+ }
+ }
+
+ #if 0 // Receive the sticker information by asynchronous communication.
+ if (g_strcmp0(signal_name, "send_group_list") == 0) {
+ if (consumer_handle->group_foreach_cb != NULL)
+ _call_sticker_list_cb(consumer_handle, parameters, signal_name);
+ return;
+ } else if (g_strcmp0(signal_name, "send_keyword_list") == 0) {
+ if (consumer_handle->keyword_foreach_cb != NULL)
+ _call_sticker_list_cb(consumer_handle, parameters, signal_name);
+ return;
+ }
+
+ sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
+
+ if (!sticker_data) {
+ LOGE("failed to allocate memory");
+ return;
+ }
+
+ _get_sticker_info_from_gvariant(parameters, sticker_data);
+
+ if (g_strcmp0(signal_name, "send_all_sticker_info") == 0) {
+ if (consumer_handle->data_foreach_cb != NULL)
+ consumer_handle->data_foreach_cb(sticker_data, consumer_handle->data_foreach_cb_user_data);
+ else
+ LOGW("No registered callback function");
+ } else if (g_strcmp0(signal_name, "send_sticker_info_by_keyword") == 0) {
+ if (consumer_handle->data_foreach_by_keyword_cb != NULL)
+ consumer_handle->data_foreach_by_keyword_cb(sticker_data, consumer_handle->data_foreach_by_keyword_cb_user_data);
+ else
+ LOGW("No registered callback function");
+ } else if (g_strcmp0(signal_name, "send_sticker_info_by_group") == 0) {
+ if (consumer_handle->data_foreach_by_group_cb != NULL)
+ consumer_handle->data_foreach_by_group_cb(sticker_data, consumer_handle->data_foreach_by_group_cb_user_data);
+ else
+ LOGW("No registered callback function");
+ } else if (g_strcmp0(signal_name, "send_sticker_info_by_type") == 0) {
+ if (consumer_handle->data_foreach_by_type_cb != NULL)
+ consumer_handle->data_foreach_by_type_cb(sticker_data, consumer_handle->data_foreach_by_type_cb_user_data);
+ else
+ LOGW("No registered callback function");
+ }
+
+ _free_sticker_data(sticker_data);
+ #endif
+}
+//LCOV_EXCL_STOP
+
+static void _handle_sticker_provider_cb(GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
+ sticker_provider_h provider_handle = (sticker_provider_h)user_data;
+
+ if (provider_handle == NULL) {
+ LOGE("provider handle is not available");
+ return;
+ }
+
+ if (parameters == NULL) {
+ LOGE("failed to get sticker info");
+ return;
+ }
+
+ if (g_strcmp0(signal_name, "send_insert_result") == 0) {
+ if (provider_handle->insert_finished_cb != NULL)
+ _call_insert_finished_cb(provider_handle, parameters);
+ }
+
+ #if 0 // Receive the sticker information by asynchronous communication.
+ sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
+
+ if (!sticker_data) {
+ LOGE("failed to allocate memory");
+ return;
+ }
+
+ _get_sticker_info_from_gvariant(parameters, sticker_data);
+
+ if (g_strcmp0(signal_name, "send_sticker_info_by_appid") == 0) {
+ if (provider_handle->data_foreach_cb != NULL)
+ provider_handle->data_foreach_cb(sticker_data, provider_handle->data_foreach_cb_user_data);
+ else
+ LOGW("No registered callback function");
+ }
+
+ _free_sticker_data(sticker_data);
+ #endif
+}
+
+static int _dbus_signal_init(GDBusConnection *gdbus_connection, int *monitor_id, CLIENT_LIB lib, void *data)
+{
+ int ret = STICKER_CLIENT_ERROR_NONE;
+ if (*monitor_id == 0) {
+ int id = 0;
+ if (lib == STICKER_CLIENT_LIB_CONSUMER)
+ id = g_dbus_connection_signal_subscribe(gdbus_connection,
+ STICKER_DBUS_NAME,
+ STICKER_CONSUMER_INTERFACE_NAME,
+ NULL,
+ STICKER_OBJECT_PATH,
+ NULL,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ _handle_sticker_consumer_cb,
+ data,
+ NULL);
+ else if (lib == STICKER_CLIENT_LIB_PROVIDER)
+ id = g_dbus_connection_signal_subscribe(gdbus_connection,
+ STICKER_DBUS_NAME,
+ STICKER_PROVIDER_INTERFACE_NAME,
+ NULL,
+ STICKER_OBJECT_PATH,
+ NULL,
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ _handle_sticker_provider_cb,
+ data,
+ NULL);
+ LOGD("id : %d", id);
+ if (id == 0) {
+ //LCOV_EXCL_START
+ ret = STICKER_CLIENT_ERROR_IO_ERROR;
+ LOGE("g_dbus_connection_signal_subscribe() failed");
+ //LCOV_EXCL_STOP
+ } else {
+ *monitor_id = id;
+ }
+ }
+
+ return ret;
+}
+
+static GDBusMessage *_get_gdbus_message(GVariant *body, const char *cmd)
+{
+ GDBusMessage *message = NULL;
+ message = g_dbus_message_new_method_call(
+ STICKER_DBUS_NAME,
+ STICKER_OBJECT_PATH,
+ STICKER_INTERFACE_NAME,
+ cmd);
+
+ if (!message) {
+ //LCOV_EXCL_START
+ LOGE("Failed to create a new gdbus message");
+ if (body)
+ g_variant_unref(body);
+ //LCOV_EXCL_STOP
+ return NULL;
+ }
+
+ if (body != NULL)
+ g_dbus_message_set_body(message, body);
+
+ return message;
+}
+
+static int _send_gdbus_sync_message(GDBusConnection *gdbus_connection, GDBusMessage *msg, GDBusMessage **reply, const char *cmd)
+{
+ int ret = STICKER_CLIENT_ERROR_NONE;
+ GError *err = NULL;
+
+ *reply = g_dbus_connection_send_message_with_reply_sync(
+ gdbus_connection,
+ msg,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL,
+ &err);
+
+ if (!*reply) {
+ //LCOV_EXCL_START
+ ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
+ if (err != NULL) {
+ LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
+ if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
+ ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
+ g_error_free(err);
+ }
+ //LCOV_EXCL_STOP
+ return ret;
+ }
+
+ if (g_dbus_message_to_gerror(*reply, &err)) {
+ //LCOV_EXCL_START
+ LOGE("error message = %s, code = %d", err->message, err->code);
+ if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
+ ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
+ else
+ ret = err->code;
+ g_error_free(err);
+ //LCOV_EXCL_STOP
+ return ret;
+ }
+
+ LOGD("Send a message to server(cmd : %s)", cmd);
+ return STICKER_CLIENT_ERROR_NONE;
+}
+
+static int _send_sync_message(GDBusConnection *gdbus_connection, GVariant *body, GDBusMessage **reply, char *cmd)
+{
+ int ret = STICKER_CLIENT_ERROR_NONE;
+ GDBusMessage *msg = NULL;
+
+ msg = _get_gdbus_message(body, cmd);
+ if (msg == NULL)
+ return STICKER_CLIENT_ERROR_IO_ERROR;
+
+ ret = _send_gdbus_sync_message(gdbus_connection, msg, reply, cmd);
+
+ if (msg)
+ g_object_unref(msg);
+
+ return ret;
+}
+
+static int _send_async_message(GDBusConnection *gdbus_connection, GVariant *body, char *cmd)
+{
+ int ret = STICKER_CLIENT_ERROR_NONE;
+ GDBusMessage *msg = NULL;
+ GError *err = NULL;
+
+ msg = _get_gdbus_message(body, cmd);
+ if (msg == NULL)
+ return STICKER_CLIENT_ERROR_IO_ERROR;
+
+ g_dbus_connection_send_message(gdbus_connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &err);
+
+ if (msg)
+ g_object_unref(msg);
+
+ if (err != NULL) {
+ //LCOV_EXCL_START
+ ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
+ LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
+
+ if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
+ ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
+
+ g_error_free(err);
+ return ret;
+ //LCOV_EXCL_STOP
+ }
+
+ return ret;
+}
+
+static int _monitor_register(GDBusConnection *gdbus_connection, int *server_watcher_id, CLIENT_LIB lib)
+{
+ int ret;
+ GDBusMessage *reply = NULL;
+ GVariant *reply_body = NULL;
+
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", (int)lib), &reply, "sticker_service_register");
+ if (ret != STICKER_CLIENT_ERROR_NONE) {
+ LOGE("_send_sync_message() failed : %d", ret);
+ return ret;
+ }
+
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(i)", server_watcher_id);
+
+ if (reply)
+ g_object_unref(reply);
+
+ is_server_started = 1;
+ return ret;
+}
+
+static void _on_name_appeared(GDBusConnection *connection,
+ const gchar *name,
+ const gchar *name_owner,
+ gpointer user_data)
+{
+ if (is_server_started == 0) {
+ int *watcher_id = (int *)user_data;
+ _monitor_register(connection, watcher_id, last_req_lib);
+ }
+}
+
+//LCOV_EXCL_START
+static void _on_name_vanished(GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ is_server_started = 0;
+}
+//LCOV_EXCL_STOP
+
+int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id,
+ int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data)
+{
+ int ret;
+ last_req_lib = lib;
+
+ ret = _dbus_init(gdbus_connection);
+ if (ret != STICKER_CLIENT_ERROR_NONE) {
+ //LCOV_EXCL_START
+ LOGE("_dbus_init() failed : %d", ret);
+ return ret;
+ //LCOV_EXCL_STOP
+ }
+
+ ret = _dbus_signal_init(*gdbus_connection, monitor_id, lib, data);
+ if (ret != STICKER_CLIENT_ERROR_NONE) {
+ //LCOV_EXCL_START
+ LOGE("_dbus_signal_init() failed : %d", ret);
+ return ret;
+ //LCOV_EXCL_STOP
+ }
+
+ ret = _monitor_register(*gdbus_connection, server_watcher_id, lib);
+ if (ret != STICKER_CLIENT_ERROR_NONE) {
+ //LCOV_EXCL_START
+ LOGE("_monitor_register() failed : %d", ret);
+ return ret;
+ //LCOV_EXCL_STOP
+ }
+
+ if (*server_monitor_id == 0) {
+ *server_monitor_id = g_bus_watch_name_on_connection(
+ *gdbus_connection,
+ STICKER_DBUS_NAME,
+ G_BUS_NAME_WATCHER_FLAGS_NONE,
+ _on_name_appeared,
+ _on_name_vanished,
+ server_watcher_id,
+ NULL);
+ if (*server_monitor_id == 0) {
+ //LCOV_EXCL_START
+ g_dbus_connection_signal_unsubscribe(*gdbus_connection, *monitor_id);
+ *monitor_id = 0;
+ LOGE("Failed to get identifier");
+ return STICKER_CLIENT_ERROR_IO_ERROR;
+ //LCOV_EXCL_STOP
+ }
+ }
+
+ return STICKER_CLIENT_ERROR_NONE;
+}
+
+int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id, CLIENT_LIB lib)
+{
+ int ret;
+
+ if (server_watcher_id) {
+ ret = _send_async_message(gdbus_connection, g_variant_new("(ii)", (int)lib, *server_watcher_id), "sticker_service_unregister");
+ if (ret != STICKER_CLIENT_ERROR_NONE) {
+ LOGE("Failed to unregister sticker service");
+ return ret;
+ }
+
+ *server_watcher_id = 0;
+ }
+
+ if (*server_monitor_id) {
+ g_bus_unwatch_name(*server_monitor_id);
+ *server_monitor_id = 0;
+ }
+
+ if (*monitor_id) {
+ g_dbus_connection_signal_unsubscribe(gdbus_connection, *monitor_id);
+ *monitor_id = 0;
+ }
+
+ return STICKER_CLIENT_ERROR_NONE;
+}
+
+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 sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
+{
+ int ret;
+ int ret_id = -1;
+ GDBusMessage *reply = NULL;
+ GVariant *reply_body = NULL;
+ GVariantBuilder *info_builder;
+ GVariantBuilder *keyword_builder;
+
+ if (!sticker_data->app_id || (sticker_data->type < 1) || !sticker_data->uri || !sticker_data->group || !sticker_data->keyword)
+ return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
+
+ 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_data->app_id));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI_TYPE, g_variant_new_int32(sticker_data->type));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI, g_variant_new_string((const gchar *)sticker_data->uri));
+ if (sticker_data->thumbnail)
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_THUMBNAIL, g_variant_new_string((const gchar *)sticker_data->thumbnail));
+ if (sticker_data->description)
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DESCRIPTION, g_variant_new_string((const gchar *)sticker_data->description));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_GROUP, g_variant_new_string((const gchar *)sticker_data->group));
+ g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DISP_TYPE, g_variant_new_int32(sticker_data->disp_type));
+
+ keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
+ g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
+
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(a{iv}a(s))", info_builder, keyword_builder), &reply, "insert_sticker_info");
+ if (ret != STICKER_CLIENT_ERROR_NONE) {
+ LOGW("Failed to save sticker info");
+ return ret;
+ }
+
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(i)", &ret_id);
+ sticker_data->sticker_info_id = ret_id;
+
+ LOGD("ret_id : %d", ret_id);
+
+ g_variant_builder_unref(info_builder);
+ g_variant_builder_unref(keyword_builder);
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, const char *app_id, const char *json_path)
+{
+ int ret;
+
+ ret = _send_async_message(gdbus_connection, g_variant_new("(ss)", app_id, json_path), "update_sticker_info_by_json");
+ if (ret != STICKER_CLIENT_ERROR_NONE)
+ LOGE("failed to send json path");
+
+ return ret;
+}
+
+int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int record_id)
+{
+ int ret;
+ GDBusMessage *reply = NULL;
+
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "delete_sticker_info");
+ if (ret != STICKER_CLIENT_ERROR_NONE)
+ LOGE("failed to delete sticker info");
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+int sticker_dbus_delete_sticker_info_by_uri(GDBusConnection *gdbus_connection, const char *uri)
+{
+ int ret;
+ GDBusMessage *reply = NULL;
+
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "delete_sticker_info_by_uri");
+ if (ret != STICKER_CLIENT_ERROR_NONE)
+ LOGE("failed to delete sticker info");
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
+{
+ int ret;
+ bool is_updated = false;
+ GDBusMessage *reply = NULL;
+ GVariant *reply_body = NULL;
+ sticker_data_h origin_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
+
+ if (!origin_data) {
+ LOGE("failed to allocate memory");
+ return STICKER_CLIENT_ERROR_OUT_OF_MEMORY;
+ }
+
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "get_sticker_info");
+ if (ret == STICKER_CLIENT_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ GVariantIter *info_iter = NULL;
+ GVariantIter *keyword_iter = NULL;
+
+ g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
+ _get_sticker_info_from_gvariant(info_iter, keyword_iter, origin_data);
+
+ if (info_iter)
+ g_variant_iter_free(info_iter);
+
+ if (keyword_iter)
+ g_variant_iter_free(keyword_iter);
+ } else {
+ LOGW("failed to get sticker info");
+ free(origin_data);
+ if (reply)
+ g_object_unref(reply);
+ return ret;
+ }
+
+ if (sticker_data->uri) {
+ int len;
+ char *conv_path = NULL;
+ if (sticker_data->type == STICKER_DATA_URI_LOCAL_PATH) {
+ len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->uri) + 2;
+ conv_path = (char *)calloc(len, sizeof(char));
+ if (conv_path)
+ snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->uri);
+ } else
+ conv_path = strdup(sticker_data->uri);
+
+ if (conv_path && (strcmp(conv_path, origin_data->uri) != 0)) {
+ LOGD("origin_uri : %s, new_uri : %s", origin_data->uri, conv_path);
+ int is_exist = 0;
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", sticker_data->uri), &reply, "check_file_exists");
+ if (ret == STICKER_CLIENT_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(i)", &is_exist);
+
+ if (is_exist) {
+ LOGE("file already exists");
+ ret = STICKER_CLIENT_ERROR_FILE_EXISTS;
+ free(conv_path);
+ goto cleanup;
+ }
+ } else {
+ LOGE("failed to check file exists");
+ free(conv_path);
+ goto cleanup;
+ }
+
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(isis)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->type, sticker_data->uri), &reply, "update_sticker_uri");
+ if (ret != STICKER_CLIENT_ERROR_NONE) {
+ LOGE("failed to update sticker uri");
+ free(conv_path);
+ goto cleanup;
+ }
+ is_updated = true;
+ }
+ free(conv_path);
+ }
+
+ if (sticker_data->type != 0 && sticker_data->type != origin_data->type) {
+ LOGD("origin_type : %d, new_type : %d", origin_data->type, sticker_data->type);
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->type), &reply, "update_sticker_type");
+ if (ret != STICKER_CLIENT_ERROR_NONE) {
+ LOGE("failed to update sticker type");
+ goto cleanup;
+ }
+ is_updated = true;
+ }
+
+ if (sticker_data->thumbnail) {
+ int len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->thumbnail) + 2;
+ char *conv_path = (char *)calloc(len, sizeof(char));
+ if (conv_path) {
+ snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->thumbnail);
+ if (strcmp(conv_path, origin_data->thumbnail) != 0)
+ {
+ LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, conv_path);
+ 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");
+ free(conv_path);
+ goto cleanup;
+ }
+ is_updated = true;
+ }
+ free(conv_path);
+ }
+ }
+
+ if (sticker_data->description && strcmp(sticker_data->description, origin_data->description) != 0) {
+ LOGD("origin_description : %s, new_description : %s", origin_data->description, sticker_data->description);
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->description), &reply, "update_sticker_description");
+ if (ret != STICKER_CLIENT_ERROR_NONE) {
+ LOGE("failed to update sticker description");
+ goto cleanup;
+ }
+ is_updated = true;
+ }
+
+ if (sticker_data->group && strcmp(sticker_data->group, origin_data->group) != 0) {
+ LOGD("origin_group : %s, new_group : %s", origin_data->group, sticker_data->group);
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->group), &reply, "update_sticker_group");
+ if (ret != STICKER_CLIENT_ERROR_NONE) {
+ LOGE("failed to update sticker group");
+ goto cleanup;
+ }
+ is_updated = true;
+ }
+
+ if (sticker_data->disp_type != 0 && sticker_data->disp_type != origin_data->disp_type) {
+ LOGD("origin_disp_type : %d, new_disp_type : %d", origin_data->disp_type, sticker_data->disp_type);
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->disp_type), &reply, "update_sticker_disp_type");
+ if (ret != STICKER_CLIENT_ERROR_NONE) {
+ LOGE("failed to update sticker display type");
+ goto cleanup;
+ }
+ is_updated = true;
+ }
+
+ if (sticker_data->keyword) {
+ GVariantBuilder *keyword_builder;
+ keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
+ g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(ia(s))", sticker_data->sticker_info_id, keyword_builder), &reply, "update_sticker_keyword");
+ if (ret != STICKER_CLIENT_ERROR_NONE)
+ LOGE("failed to update sticker keyword");
+ else
+ is_updated = true;
+ g_variant_builder_unref(keyword_builder);
+ }
+
+ if (is_updated)
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "send_update_event");
+
+cleanup:
+ sticker_data_destroy(origin_data);
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, int record_id)
+{
+ int ret;
+ GDBusMessage *reply = NULL;
+ GVariant *reply_body = NULL;
+ GVariantIter *info_iter = NULL;
+ GVariantIter *keyword_iter = NULL;
+
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "get_sticker_info");
+ if (ret == STICKER_CLIENT_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ sticker_data->sticker_info_id = record_id;
+
+ g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
+ _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (info_iter)
+ g_variant_iter_free(info_iter);
+
+ if (keyword_iter)
+ g_variant_iter_free(keyword_iter);
+ }
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, const char *app_id, GList **group_list)
+{
+ int ret;
+ GDBusMessage *reply = NULL;
+ GVariantIter *iter = NULL;
+ GVariant *reply_body = NULL;
+ char *group = NULL;
+
+ if (group_list == NULL) {
+ LOGE("group_list is invalid");
+ return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
+ }
+
+ 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);
+
+ if (!iter) {
+ LOGD("failed to get iter");
+ return STICKER_CLIENT_ERROR_OPERATION_FAILED;
+ }
+
+ while (g_variant_iter_loop (iter, "(s)", &group)) {
+ *group_list = g_list_append(*group_list, strdup((const char *)group));
+ }
+
+ g_variant_iter_free(iter);
+ }
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, const char *app_id, GList **keyword_list)
+{
+ int ret;
+ GDBusMessage *reply = NULL;
+ GVariantIter *iter = NULL;
+ GVariant *reply_body = NULL;
+ char *keyword = NULL;
+
+ if (keyword_list == NULL) {
+ LOGE("keyword_list is invalid");
+ return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
+ }
+
+ 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);
+
+ if (!iter) {
+ LOGD("failed to get iter");
+ return STICKER_CLIENT_ERROR_OPERATION_FAILED;
+ }
+
+ while (g_variant_iter_loop (iter, "(s)", &keyword)) {
+ *keyword_list = g_list_append(*keyword_list, strdup((const char *)keyword));
+ }
+
+ g_variant_iter_free(iter);
+ }
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+int sticker_dbus_get_sticker_count(GDBusConnection *gdbus_connection, const char *app_id, int *count)
+{
+ int ret;
+ GDBusMessage *reply = NULL;
+ GVariant *reply_body = NULL;
+
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_sticker_count");
+ if (ret == STICKER_CLIENT_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(i)", count);
+ }
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+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("(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);
+ }
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+int sticker_dbus_get_sticker_info_by_appid(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("(sii)", app_id, offset, count), &reply, "get_sticker_info_by_appid");
+ if (ret == STICKER_CLIENT_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(a(i))", id_iter);
+ }
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+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("(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);
+ }
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+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("(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);
+ }
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+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("(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);
+ }
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+int sticker_dbus_get_sticker_info_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_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("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_disp_type");
+ if (ret == STICKER_CLIENT_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(a(i))", id_iter);
+ }
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+int sticker_dbus_get_group_list_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_type_e type, GList **group_list)
+{
+ int ret;
+ GDBusMessage *reply = NULL;
+ GVariantIter *iter = NULL;
+ GVariant *reply_body = NULL;
+ char *group = NULL;
+
+ if (group_list == NULL) {
+ LOGE("group_list is invalid");
+ return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(si)", app_id, (int)type), &reply, "get_group_list_by_disp_type");
+ if (ret == STICKER_CLIENT_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(a(s))", &iter);
+
+ if (!iter) {
+ LOGD("failed to get iter");
+ return STICKER_CLIENT_ERROR_OPERATION_FAILED;
+ }
+
+ while (g_variant_iter_loop (iter, "(s)", &group)) {
+ *group_list = g_list_append(*group_list, strdup((const char *)group));
+ }
+
+ g_variant_iter_free(iter);
+ }
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+int sticker_dbus_check_file_exists(GDBusConnection *gdbus_connection, const char *uri, int *result)
+{
+ int ret;
+ GDBusMessage *reply = NULL;
+ GVariant *reply_body = NULL;
+
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "check_file_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_insert_recent_sticker_info(GDBusConnection *gdbus_connection, int record_id)
+{
+ int ret;
+ GDBusMessage *reply = NULL;
+
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "insert_recent_sticker_info");
+ if (ret != STICKER_CLIENT_ERROR_NONE)
+ LOGE("failed to insert recent sticker info");
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+int sticker_dbus_get_recent_sticker_list(GDBusConnection *gdbus_connection, int count, GVariantIter **id_iter)
+{
+ int ret;
+ GDBusMessage *reply = NULL;
+ GVariant *reply_body = NULL;
+
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", count), &reply, "get_recent_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);
+ }
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
+
+int sticker_dbus_get_sticker_info_by_uri(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, const char *uri)
+{
+ int ret;
+ GDBusMessage *reply = NULL;
+ GVariant *reply_body = NULL;
+ GVariantIter *info_iter = NULL;
+ GVariantIter *keyword_iter = NULL;
+
+ ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "get_sticker_info_by_uri");
+ if (ret == STICKER_CLIENT_ERROR_NONE) {
+ reply_body = g_dbus_message_get_body(reply);
+ g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
+ _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
+
+ if (reply_body)
+ g_variant_unref(reply_body);
+
+ if (info_iter)
+ g_variant_iter_free(info_iter);
+
+ if (keyword_iter)
+ g_variant_iter_free(keyword_iter);
+ }
+
+ if (reply)
+ g_object_unref(reply);
+
+ return ret;
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __TIZEN_UIX_STICKER_DBUS_H__
+#define __TIZEN_UIX_STICKER_DBUS_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <dbus/dbus.h>
+#include "sticker_defs.h"
+#include "sticker_data.h"
+#include "sticker_data_main.h"
+#include "sticker_provider_main.h"
+#include "sticker_consumer_main.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum sticker_client_error {
+ STICKER_CLIENT_ERROR_NONE,
+ STICKER_CLIENT_ERROR_INVALID_PARAMETER,
+ STICKER_CLIENT_ERROR_PERMISSION_DENIED,
+ STICKER_CLIENT_ERROR_OUT_OF_MEMORY,
+ STICKER_CLIENT_ERROR_SERVICE_NOT_READY,
+ STICKER_CLIENT_ERROR_OPERATION_FAILED,
+ STICKER_CLIENT_ERROR_IO_ERROR,
+ STICKER_CLIENT_ERROR_DB_FAILED,
+ STICKER_CLIENT_ERROR_FILE_EXISTS,
+ STICKER_CLIENT_ERROR_NO_SUCH_FILE,
+};
+
+int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id,
+ int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data);
+int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id, CLIENT_LIB lib);
+int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data);
+int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, const char *app_id, const char *json_path);
+int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int record_id);
+int sticker_dbus_delete_sticker_info_by_uri(GDBusConnection *gdbus_connection, const char *uri);
+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, 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, 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, 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);
+int sticker_dbus_get_sticker_info_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_type_e type, int offset, int count, GVariantIter **id_iter);
+int sticker_dbus_get_group_list_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_type_e type, GList **group_list);
+int sticker_dbus_check_file_exists(GDBusConnection *gdbus_connection, const char *uri, int *result);
+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);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_UIX_STICKER_DBUS_H__ */
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <dlog.h>
+#include <app_common.h>
+#include <package_manager.h>
+
+#include "sticker_provider.h"
+#include "sticker_provider_main.h"
+#include "sticker_dbus.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "STICKER_PROVIDER"
+
+EXPORT_API int sticker_provider_create(sticker_provider_h *provider_handle)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ if (!provider_handle)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ struct sticker_provider_s *provider_struct = (sticker_provider_h)calloc(1, sizeof(struct sticker_provider_s));
+
+ if (!provider_struct)
+ return STICKER_ERROR_OUT_OF_MEMORY;
+
+ ret = sticker_dbus_init(&provider_struct->gdbus_connection, &provider_struct->server_watcher_id,
+ &provider_struct->monitor_id, &provider_struct->server_monitor_id, STICKER_CLIENT_LIB_PROVIDER, (void *)provider_struct);
+ if (ret != STICKER_ERROR_NONE) {
+ //LCOV_EXCL_START
+ LOGE("Failed to initialize dbus : %d", ret);
+ free(provider_struct);
+ return STICKER_ERROR_OPERATION_FAILED;
+ //LCOV_EXCL_STOP
+ }
+
+ *provider_handle = provider_struct;
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_provider_destroy(sticker_provider_h provider_handle)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ if (!provider_handle)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ LOGD("provider_handle : %p", provider_handle);
+ ret = sticker_dbus_shutdown(provider_handle->gdbus_connection, &provider_handle->server_watcher_id,
+ &provider_handle->server_monitor_id, &provider_handle->monitor_id, STICKER_CLIENT_LIB_PROVIDER);
+ if (ret != STICKER_ERROR_NONE) {
+ //LCOV_EXCL_START
+ LOGE("Failed to finalize dbus : %d", ret);
+ free(provider_handle);
+ return STICKER_ERROR_OPERATION_FAILED;
+ //LCOV_EXCL_STOP
+ }
+
+ if (provider_handle->gdbus_connection)
+ g_object_unref(provider_handle->gdbus_connection);
+
+ free(provider_handle);
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_provider_insert_data(sticker_provider_h provider_handle, sticker_data_h data_handle)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ int is_exist = 0;
+
+ if (!provider_handle || !data_handle || (data_handle->sticker_info_id > 0) || !data_handle->uri)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ int len = strlen(STICKER_DIRECTORY) + strlen(data_handle->app_id) + strlen(data_handle->uri) + 3;
+ char *new_path = (char *)calloc(len, sizeof(char));
+ if (!new_path) {
+ return STICKER_ERROR_OUT_OF_MEMORY;
+ }
+
+ if (data_handle->uri[0] == '/')
+ snprintf(new_path, len, "%s/%s%s",STICKER_DIRECTORY, data_handle->app_id, data_handle->uri);
+ else
+ snprintf(new_path, len, "%s/%s/%s",STICKER_DIRECTORY, data_handle->app_id, data_handle->uri);
+
+ ret = sticker_dbus_check_file_exists(provider_handle->gdbus_connection, new_path, &is_exist);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to check file exists : %d", ret);
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+
+ if (is_exist) {
+ LOGE("Sticker already exists");
+ ret = STICKER_ERROR_FILE_EXISTS;
+ goto cleanup;
+ }
+
+ ret = sticker_dbus_insert_sticker_info(provider_handle->gdbus_connection, data_handle);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to insert sticker information : %d", ret);
+ if (ret == STICKER_CLIENT_ERROR_NO_SUCH_FILE)
+ ret = STICKER_ERROR_NO_SUCH_FILE;
+ else
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ }
+
+cleanup:
+ if (new_path) {
+ free(new_path);
+ new_path = NULL;
+ }
+
+ return ret;
+}
+
+EXPORT_API int sticker_provider_insert_data_by_json_file(sticker_provider_h provider_handle, const char *json_path, sticker_provider_insert_finished_cb callback, void *user_data)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ char *app_id = NULL;
+ package_info_h package_info = NULL;
+ char *app_path = NULL;
+ char *file_path = NULL;
+
+ if (!provider_handle || !json_path || !callback)
+ 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;
+ }
+
+ if (access(json_path, F_OK) != 0) {
+ 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(json_path) + 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(json_path[0] == '/')
+ snprintf(file_path, path_len, "%s%s",app_path, json_path);
+ else
+ snprintf(file_path, path_len, "%s%s%s",app_path, "/", json_path);
+
+ if (access(file_path, F_OK) != 0) {
+ LOGE("%s does not exist", file_path);
+ ret = STICKER_ERROR_INVALID_PARAMETER;
+ goto cleanup;
+ }
+ } else
+ file_path = strdup(json_path);
+
+ SECURE_LOGD("json path : %s", file_path);
+ ret = sticker_dbus_insert_sticker_info_by_json(provider_handle->gdbus_connection, app_id, file_path);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to load json file : %d", ret);
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+
+ provider_handle->insert_finished_cb = callback;
+ provider_handle->insert_finished_cb_user_data = user_data;
+
+cleanup:
+ if (app_id)
+ free(app_id);
+
+ if (package_info)
+ package_info_destroy(package_info);
+
+ if (app_path)
+ free(app_path);
+
+ if (file_path)
+ free(file_path);
+
+ return ret;
+}
+
+EXPORT_API int sticker_provider_update_data(sticker_provider_h provider_handle, sticker_data_h data_handle)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ if (!provider_handle || !data_handle || (data_handle->sticker_info_id <= 0))
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ ret = sticker_dbus_update_sticker_info(provider_handle->gdbus_connection, data_handle);
+ if (ret != STICKER_ERROR_NONE) {
+ //LCOV_EXCL_START
+ LOGE("Failed to update sticker information : %d", ret);
+ if (ret == STICKER_CLIENT_ERROR_FILE_EXISTS)
+ return STICKER_ERROR_FILE_EXISTS;
+ else if (ret == STICKER_CLIENT_ERROR_NO_SUCH_FILE)
+ return STICKER_ERROR_NO_SUCH_FILE;
+ else
+ return STICKER_ERROR_OPERATION_FAILED;
+ //LCOV_EXCL_STOP
+ }
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_provider_delete_data(sticker_provider_h provider_handle, sticker_data_h data_handle)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ if (!provider_handle || !data_handle || (data_handle->sticker_info_id <= 0))
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ ret = sticker_dbus_delete_sticker_info(provider_handle->gdbus_connection, data_handle->sticker_info_id);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to delete sticker information : %d", ret);
+ return STICKER_ERROR_OPERATION_FAILED;
+ }
+
+ return STICKER_ERROR_NONE;
+}
+
+EXPORT_API int sticker_provider_get_sticker_count(sticker_provider_h provider_handle, int *count)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ char *app_id = NULL;
+
+ if (!provider_handle || !count)
+ 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_get_sticker_count(provider_handle->gdbus_connection, app_id, count);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to get sticker count : %d", ret);
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ }
+
+cleanup:
+ if (app_id)
+ free(app_id);
+
+ return ret;
+}
+
+EXPORT_API 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)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ int info_id;
+ int sticker_count = 0;
+ char *app_id = NULL;
+ GVariantIter *id_iter = NULL;
+
+ if (!provider_handle || (offset < 0) || (count <= 0) || !result || !callback)
+ 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_get_sticker_info_by_appid(provider_handle->gdbus_connection, app_id, offset, count, &id_iter);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to get sticker information : %d", ret);
+ ret = STICKER_ERROR_OPERATION_FAILED;
+ goto cleanup;
+ }
+
+ if (id_iter) {
+ while (g_variant_iter_loop (id_iter, "(i)", &info_id)) {
+ sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
+ if (!sticker_data) {
+ ret = STICKER_ERROR_OUT_OF_MEMORY;
+ goto cleanup;
+ }
+
+ ret = sticker_dbus_get_sticker_info_by_record_id(provider_handle->gdbus_connection, sticker_data, info_id);
+ if (ret == STICKER_ERROR_NONE) {
+ sticker_count++;
+ callback(sticker_data, user_data);
+ sticker_data_destroy(sticker_data);
+ } else {
+ sticker_data_destroy(sticker_data);
+ goto cleanup;
+ }
+ }
+ }
+
+ *result = sticker_count;
+
+cleanup:
+ if (app_id)
+ free(app_id);
+
+ if (id_iter)
+ g_variant_iter_free(id_iter);
+
+ return ret;
+}
+
+EXPORT_API int sticker_provider_delete_data_by_uri(sticker_provider_h provider_handle, const char *uri)
+{
+ CHECK_STICKER_FEATURE();
+
+ int ret;
+ int is_exist = 0;
+
+ if (!provider_handle || !uri)
+ return STICKER_ERROR_INVALID_PARAMETER;
+
+ ret = sticker_dbus_check_file_exists(provider_handle->gdbus_connection, uri, &is_exist);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to check file exists : %d", ret);
+ return STICKER_ERROR_OPERATION_FAILED;
+ }
+
+ if (!is_exist) {
+ LOGE("Sticker does not exist");
+ return STICKER_ERROR_NO_SUCH_FILE;
+ }
+
+ ret = sticker_dbus_delete_sticker_info_by_uri(provider_handle->gdbus_connection, uri);
+ if (ret != STICKER_ERROR_NONE) {
+ LOGE("Failed to delete sticker information : %d", ret);
+ return STICKER_ERROR_OPERATION_FAILED;
+ }
+
+ return STICKER_ERROR_NONE;
+}
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <dlog.h>
-#include <app_common.h>
-#include <package_manager.h>
-
-#include "sticker_data.h"
-#include "sticker_dbus.h"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "STICKER_DATA"
-
-static char* _make_absolute_path(const char *relative_path)
-{
- int ret = STICKER_ERROR_NONE;
- char *app_id = NULL;
- package_info_h package_info = NULL;
- char *app_path = NULL;
- char *file_path = NULL;
-
- 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 = 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(relative_path) + 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(relative_path[0] == '/')
- snprintf(file_path, path_len, "%s%s",app_path, relative_path);
- else
- snprintf(file_path, path_len, "%s%s%s",app_path, "/", relative_path); //LCOV_EXCL_LINE
-
- if (access(file_path, F_OK) != 0) {
- LOGE("%s does not exist", file_path);
- ret = STICKER_ERROR_OPERATION_FAILED;
- free(file_path);
- }
-
-cleanup:
- if (app_id)
- free(app_id);
-
- if (package_info)
- package_info_destroy(package_info);
-
- if (app_path)
- free(app_path);
-
- if (ret == STICKER_ERROR_NONE)
- return file_path;
- else
- return NULL;
-}
-
-static void _free_sticker_data(sticker_data_h 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);
- sticker_data = NULL;
-}
-
-EXPORT_API int sticker_data_create(sticker_data_h *data_handle)
-{
- CHECK_STICKER_FEATURE();
-
- if (!data_handle)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- sticker_data_h data_struct = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
-
- if (!data_struct)
- return STICKER_ERROR_OUT_OF_MEMORY;
-
- char *app_id = NULL;
- int ret = app_get_id(&app_id);
- if (ret != APP_ERROR_NONE) {
- //LCOV_EXCL_START
- LOGE("Failed to get app_id : %d", ret);
- free(data_struct);
- ret = STICKER_ERROR_OPERATION_FAILED;
- goto cleanup;
- //LCOV_EXCL_STOP
- }
-
- data_struct->app_id = strdup(app_id);
- *data_handle = data_struct;
-
-cleanup:
- free(app_id);
-
- return ret;
-}
-
-EXPORT_API int sticker_data_destroy(sticker_data_h data_handle)
-{
- CHECK_STICKER_FEATURE();
-
- if (!data_handle)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- if (data_handle->app_id) {
- free(data_handle->app_id);
- data_handle->app_id = NULL;
- }
-
- if (data_handle->uri) {
- free(data_handle->uri);
- data_handle->uri = NULL;
- }
-
- if (data_handle->thumbnail) {
- free(data_handle->thumbnail);
- data_handle->thumbnail = NULL;
- }
-
- if (data_handle->keyword) {
- g_list_free_full(data_handle->keyword, free);
- data_handle->keyword = NULL;
- }
-
- if (data_handle->group) {
- free(data_handle->group);
- data_handle->group = NULL;
- }
-
- if (data_handle->description) {
- free(data_handle->description);
- data_handle->description = NULL;
- }
-
- if (data_handle->date) {
- free(data_handle->date);
- data_handle->date = NULL;
- }
-
- free(data_handle);
- data_handle = NULL;
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_data_clone(sticker_data_h origin_handle, sticker_data_h *target_handle)
-{
- CHECK_STICKER_FEATURE();
-
- sticker_data_h handle;
- if (!origin_handle || !target_handle)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- sticker_data_create(&handle);
- if (!handle)
- return STICKER_ERROR_OUT_OF_MEMORY;
-
- handle->sticker_info_id = origin_handle->sticker_info_id;
-
- if (origin_handle->app_id)
- handle->app_id = strdup(origin_handle->app_id);
-
- handle->type = origin_handle->type;
-
- if (origin_handle->uri)
- handle->uri = strdup(origin_handle->uri);
-
- if (origin_handle->thumbnail)
- handle->thumbnail = strdup(origin_handle->thumbnail);
-
- if (origin_handle->keyword)
- handle->keyword = g_list_copy_deep(origin_handle->keyword, (GCopyFunc) g_strdup, NULL);
-
- if (origin_handle->group)
- handle->group = strdup(origin_handle->group);
-
- if (origin_handle->description)
- handle->description = strdup(origin_handle->description);
-
- if (origin_handle->date)
- handle->date = strdup(origin_handle->date);
-
- handle->disp_type = origin_handle->disp_type;
-
- *target_handle = handle;
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_data_get_handle(const char* uri, sticker_data_h *data_handle)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- GDBusConnection *gdbus_connection = NULL;
- int server_watcher_id = 0;
- int monitor_id = 0;
- int server_monitor_id = 0;
- int is_exist = 0;
-
- if (!uri || uri[0] == '\0' || !data_handle)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- struct sticker_data_s *handle = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
- if (!handle)
- return STICKER_ERROR_OUT_OF_MEMORY;
-
- ret = sticker_dbus_init(&gdbus_connection, &server_watcher_id, &monitor_id, &server_monitor_id, STICKER_CLIENT_LIB_PROVIDER, NULL);
- if (ret != STICKER_ERROR_NONE) {
- LOGE("Failed to initialize dbus : %d", ret);
- ret = STICKER_ERROR_OPERATION_FAILED;
- goto cleanup;
- }
-
- ret = sticker_dbus_check_file_exists(gdbus_connection, uri, &is_exist);
- if (ret != STICKER_ERROR_NONE) {
- LOGE("Failed to check file exists : %d", ret);
- ret = STICKER_ERROR_OPERATION_FAILED;
- goto cleanup;
- }
-
- if (!is_exist) {
- LOGE("Sticker does not exist. URI : %s", uri);
- ret = STICKER_ERROR_NO_SUCH_FILE;
- goto cleanup;
- }
-
- ret = sticker_dbus_get_sticker_info_by_uri(gdbus_connection, handle, uri);
- if (ret != STICKER_ERROR_NONE) {
- LOGE("Failed to get sticker information : %d", ret);
- goto cleanup;
- }
-
- *data_handle = handle;
-
- ret = sticker_dbus_shutdown(gdbus_connection, &server_watcher_id, &server_monitor_id, &monitor_id, STICKER_CLIENT_LIB_PROVIDER);
- if (ret != STICKER_ERROR_NONE)
- LOGE("Failed to finalize dbus : %d", ret);
-
- g_object_unref(gdbus_connection);
-
- return STICKER_ERROR_NONE;
-
-cleanup:
- if (handle)
- _free_sticker_data(handle);
-
- if (gdbus_connection) {
- int ret_err = sticker_dbus_shutdown(gdbus_connection, &server_watcher_id, &server_monitor_id, &monitor_id, STICKER_CLIENT_LIB_PROVIDER);
- if (ret_err != STICKER_ERROR_NONE)
- LOGE("Failed to finalize dbus : %d", ret_err);
-
- g_object_unref(gdbus_connection);
- }
-
- return ret;
-}
-
-EXPORT_API int sticker_data_get_app_id(sticker_data_h data_handle, char **app_id)
-{
- CHECK_STICKER_FEATURE();
-
- if (!data_handle || !app_id)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- if (!data_handle->app_id)
- return STICKER_ERROR_NO_DATA;
-
- *app_id = strdup(data_handle->app_id);
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_data_set_uri(sticker_data_h data_handle, sticker_data_uri_type_e type, const char *uri)
-{
- CHECK_STICKER_FEATURE();
-
- char *file_path = NULL;
- if (!data_handle || !type || !uri || uri[0] == '\0')
- return STICKER_ERROR_INVALID_PARAMETER;
-
- if (type == STICKER_DATA_URI_LOCAL_PATH) {
- if (access(uri, F_OK) != 0) {
- file_path = _make_absolute_path(uri);
- if (file_path == NULL) {
- return STICKER_ERROR_INVALID_PARAMETER;
- }
- } else
- file_path = strdup(uri);
- }
-
- if (data_handle->uri)
- free(data_handle->uri);
-
- data_handle->type = type;
- if (type == STICKER_DATA_URI_LOCAL_PATH)
- data_handle->uri = file_path;
- else
- data_handle->uri = strdup(uri);
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_data_get_uri(sticker_data_h data_handle, sticker_data_uri_type_e *type, char **uri)
-{
- CHECK_STICKER_FEATURE();
-
- if (!data_handle || !type || !uri)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- if (!data_handle->type || !data_handle->uri)
- return STICKER_ERROR_NO_DATA;
-
- *type = data_handle->type;
- *uri = strdup(data_handle->uri);
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_data_foreach_keyword(sticker_data_h data_handle, sticker_data_keyword_foreach_cb callback, void *user_data)
-{
- CHECK_STICKER_FEATURE();
-
- if (!data_handle || !callback)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- if (!data_handle->keyword)
- return STICKER_ERROR_NO_DATA;
-
- GList *list = NULL;
- for(list = g_list_first(data_handle->keyword); list != NULL; list=list->next) {
- callback(list->data, user_data);
- }
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_data_add_keyword(sticker_data_h data_handle, const char *keyword)
-{
- CHECK_STICKER_FEATURE();
-
- GList *node;
- if (!data_handle || !keyword)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- node = g_list_find_custom(data_handle->keyword, keyword, (GCompareFunc) strcmp);
-
- if (node) {
- LOGE("keyword already exists");
- return STICKER_ERROR_INVALID_PARAMETER;
- } else {
- data_handle->keyword = g_list_append(data_handle->keyword, strdup(keyword));
- }
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_data_remove_keyword(sticker_data_h data_handle, const char *keyword)
-{
- CHECK_STICKER_FEATURE();
-
- GList *node;
- if (!data_handle || !keyword)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- node = g_list_find_custom(data_handle->keyword, keyword, (GCompareFunc) strcmp);
-
- if (node) {
- data_handle->keyword = g_list_delete_link(data_handle->keyword, node);
- } else {
- LOGE("keyword does not exist");
- return STICKER_ERROR_INVALID_PARAMETER;
- }
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_data_set_group_name(sticker_data_h data_handle, const char *group)
-{
- CHECK_STICKER_FEATURE();
-
- if (!data_handle || !group)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- if (data_handle->group)
- free(data_handle->group);
-
- data_handle->group = strdup(group);
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_data_get_group_name(sticker_data_h data_handle, char **group)
-{
- CHECK_STICKER_FEATURE();
-
- if (!data_handle || !group)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- if (!data_handle->group)
- return STICKER_ERROR_NO_DATA;
-
- *group = strdup(data_handle->group);
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_data_set_thumbnail(sticker_data_h data_handle, const char *thumbnail)
-{
- CHECK_STICKER_FEATURE();
-
- char *file_path = NULL;
- if (!data_handle || !thumbnail || thumbnail[0] == '\0')
- return STICKER_ERROR_INVALID_PARAMETER;
-
- if (access(thumbnail, F_OK) != 0) {
- file_path = _make_absolute_path(thumbnail);
- if (file_path == NULL)
- return STICKER_ERROR_INVALID_PARAMETER;
- } else
- file_path = strdup(thumbnail);
-
- if (data_handle->thumbnail)
- free(data_handle->thumbnail);
-
- data_handle->thumbnail = file_path;
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_data_get_thumbnail(sticker_data_h data_handle, char **thumbnail)
-{
- CHECK_STICKER_FEATURE();
-
- if (!data_handle || !thumbnail)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- if (!data_handle->thumbnail)
- *thumbnail = strdup("");
- else
- *thumbnail = strdup(data_handle->thumbnail);
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_data_set_description(sticker_data_h data_handle, const char *description)
-{
- CHECK_STICKER_FEATURE();
-
- if (!data_handle || !description)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- if (data_handle->description)
- free(data_handle->description);
-
- data_handle->description = strdup(description);
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_data_get_description(sticker_data_h data_handle, char **description)
-{
- CHECK_STICKER_FEATURE();
-
- if (!data_handle || !description)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- if (!data_handle->description)
- *description = strdup("");
- else
- *description = strdup(data_handle->description);
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_data_get_date(sticker_data_h data_handle, char **date)
-{
- CHECK_STICKER_FEATURE();
-
- if (!data_handle || !date)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- if (!data_handle->date)
- return STICKER_ERROR_NO_DATA;
-
- *date = strdup(data_handle->date);
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_data_set_display_type(sticker_data_h data_handle, sticker_data_display_type_e type)
-{
- CHECK_STICKER_FEATURE();
-
- if (!data_handle || !type || type < STICKER_DATA_DISP_EMOJI || type > STICKER_DATA_DISP_WALLPAPER)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- data_handle->disp_type = type;
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_data_get_display_type(sticker_data_h data_handle, sticker_data_display_type_e *type)
-{
- CHECK_STICKER_FEATURE();
-
- if (!data_handle || !type)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- *type = data_handle->disp_type;
-
- return STICKER_ERROR_NONE;
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __TIZEN_UIX_STICKER_DATA_MAIN_H__
-#define __TIZEN_UIX_STICKER_DATA_MAIN_H__
-
-#include <glib.h>
-#include "sticker_data.h"
-
-/**
- * @file sticker_data_main.h
- */
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-struct sticker_data_s{
- int sticker_info_id;
- char *app_id;
- sticker_data_uri_type_e type;
- char *uri;
- char *thumbnail;
- GList *keyword;
- char *group;
- char *description;
- char *date;
- sticker_data_display_type_e disp_type;
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-/**
- * @}
- */
-
-#endif /* __TIZEN_UIX_STICKER_DATA_MAIN_H__ */
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <dlog.h>
-
-#include "sticker_dbus.h"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "STICKER_DBUS"
-
-#define STICKER_DIRECTORY "/opt/usr/share/sticker-data"
-
-static int is_server_started = 0;
-static CLIENT_LIB last_req_lib = STICKER_CLIENT_LIB_NONE;
-
-static void _server_appeared_cb(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer user_data)
-{
- LOGD("name : %s, name_owner : %s", name, name_owner);
-}
-
-//LCOV_EXCL_START
-static void _server_vanished_cb(GDBusConnection *connection, const gchar *name, gpointer user_data)
-{
- LOGD("name : %s", name);
-}
-//LCOV_EXCL_STOP
-
-static int _dbus_init(GDBusConnection **gdbus_connection)
-{
- GError *error = NULL;
- int watch_id = 0;
-
- if (*gdbus_connection == NULL) {
- GDBusConnection *conn = NULL;
- conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
- if (conn == NULL) {
- //LCOV_EXCL_START
- if (error != NULL) {
- LOGE("g_bus_get_sync error message = %s", error->message);
- g_error_free(error);
- }
- //LCOV_EXCL_STOP
- return STICKER_CLIENT_ERROR_IO_ERROR;
- }
- *gdbus_connection = conn;
- }
-
- LOGD("Connected bus name : %s", g_dbus_connection_get_unique_name(*gdbus_connection));
- watch_id = g_bus_watch_name(G_BUS_TYPE_SYSTEM,
- STICKER_DBUS_NAME,
- G_BUS_NAME_WATCHER_FLAGS_NONE,
- _server_appeared_cb,
- _server_vanished_cb,
- NULL, NULL);
-
- LOGD("watch_id : %d", watch_id);
- if (watch_id == 0) {
- LOGE("Failed to get identifier"); //LCOV_EXCL_LINE
- return STICKER_CLIENT_ERROR_IO_ERROR;
- }
-
- return STICKER_CLIENT_ERROR_NONE;
-}
-
-static void _get_sticker_info_from_gvariant(GVariantIter *info_iter, GVariantIter *keyword_iter, sticker_data_h sticker_data)
-{
- STICKER_DAT_TYPE key;
- GVariant *value = NULL;
- char *keyword = NULL;
-
- if (!info_iter || !keyword_iter) {
- LOGW("failed to get iter");
- return;
- }
-
- while (g_variant_iter_loop (info_iter, "{iv}", &key, &value)) {
- switch(key) {
- case STICKER_DATA_TYPE_INFO_ID:
- sticker_data->sticker_info_id = g_variant_get_int32(value);
- break;
- case STICKER_DATA_TYPE_APP_ID:
- sticker_data->app_id = g_variant_dup_string(value, NULL);
- break;
- case STICKER_DATA_TYPE_URI_TYPE:
- sticker_data->type = g_variant_get_int32(value);
- break;
- case STICKER_DATA_TYPE_URI:
- sticker_data->uri = g_variant_dup_string(value, NULL);
- break;
- case STICKER_DATA_TYPE_THUMBNAIL:
- sticker_data->thumbnail = g_variant_dup_string(value, NULL);
- break;
- case STICKER_DATA_TYPE_DESCRIPTION:
- sticker_data->description = g_variant_dup_string(value, NULL);
- break;
- case STICKER_DATA_TYPE_GROUP:
- sticker_data->group = g_variant_dup_string(value, NULL);
- break;
- case STICKER_DATA_TYPE_DATE:
- sticker_data->date = g_variant_dup_string(value, NULL);
- break;
- case STICKER_DATA_TYPE_DISP_TYPE:
- sticker_data->disp_type = g_variant_get_int32(value);
- break;
- default:
- break;
- }
- }
-
- while (g_variant_iter_loop (keyword_iter, "(s)", &keyword)) {
- sticker_data->keyword = g_list_append(sticker_data->keyword, strdup((const char *)keyword));
- }
-
- if (value)
- g_variant_unref(value);
-
- g_variant_iter_free(info_iter);
- g_variant_iter_free(keyword_iter);
-}
-
-static void _free_sticker_data(sticker_data_h sticker_data)
-{
- 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);
- sticker_data = NULL;
-}
-
-static void _call_insert_finished_cb(sticker_provider_h provider_handle, GVariant *body)
-{
- int ret;
- g_variant_get(body, "(i)", &ret);
-
- if (ret == 0) {
- provider_handle->insert_finished_cb(STICKER_ERROR_NONE, provider_handle->insert_finished_cb_user_data);
- } else {
- provider_handle->insert_finished_cb(STICKER_ERROR_OPERATION_FAILED, provider_handle->insert_finished_cb_user_data);
- }
-}
-
-//LCOV_EXCL_START
-static void _handle_sticker_consumer_cb(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
- sticker_consumer_h consumer_handle = (sticker_consumer_h)user_data;
-
- if (consumer_handle == NULL) {
- LOGE("consumer handle is not available");
- return;
- }
-
- if (parameters == NULL) {
- LOGE("failed to get sticker info");
- return;
- }
-
- if (g_strcmp0(signal_name, "send_sticker_changed_event") == 0) {
- if (consumer_handle->event_cb != NULL) {
- sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
- if (sticker_data) {
- int event_type;
- GVariantIter *info_iter = NULL;
- GVariantIter *keyword_iter = NULL;
-
- g_variant_get(parameters, "(ia{iv}a(s))", &event_type, &info_iter, &keyword_iter);
- _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
- consumer_handle->event_cb((sticker_consumer_event_type_e)event_type, sticker_data, consumer_handle->event_cb_user_data);
-
- if (info_iter)
- g_variant_iter_free(info_iter);
-
- if (keyword_iter)
- g_variant_iter_free(keyword_iter);
-
- _free_sticker_data(sticker_data);
- }
- }
- }
-
- #if 0 // Receive the sticker information by asynchronous communication.
- if (g_strcmp0(signal_name, "send_group_list") == 0) {
- if (consumer_handle->group_foreach_cb != NULL)
- _call_sticker_list_cb(consumer_handle, parameters, signal_name);
- return;
- } else if (g_strcmp0(signal_name, "send_keyword_list") == 0) {
- if (consumer_handle->keyword_foreach_cb != NULL)
- _call_sticker_list_cb(consumer_handle, parameters, signal_name);
- return;
- }
-
- sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
-
- if (!sticker_data) {
- LOGE("failed to allocate memory");
- return;
- }
-
- _get_sticker_info_from_gvariant(parameters, sticker_data);
-
- if (g_strcmp0(signal_name, "send_all_sticker_info") == 0) {
- if (consumer_handle->data_foreach_cb != NULL)
- consumer_handle->data_foreach_cb(sticker_data, consumer_handle->data_foreach_cb_user_data);
- else
- LOGW("No registered callback function");
- } else if (g_strcmp0(signal_name, "send_sticker_info_by_keyword") == 0) {
- if (consumer_handle->data_foreach_by_keyword_cb != NULL)
- consumer_handle->data_foreach_by_keyword_cb(sticker_data, consumer_handle->data_foreach_by_keyword_cb_user_data);
- else
- LOGW("No registered callback function");
- } else if (g_strcmp0(signal_name, "send_sticker_info_by_group") == 0) {
- if (consumer_handle->data_foreach_by_group_cb != NULL)
- consumer_handle->data_foreach_by_group_cb(sticker_data, consumer_handle->data_foreach_by_group_cb_user_data);
- else
- LOGW("No registered callback function");
- } else if (g_strcmp0(signal_name, "send_sticker_info_by_type") == 0) {
- if (consumer_handle->data_foreach_by_type_cb != NULL)
- consumer_handle->data_foreach_by_type_cb(sticker_data, consumer_handle->data_foreach_by_type_cb_user_data);
- else
- LOGW("No registered callback function");
- }
-
- _free_sticker_data(sticker_data);
- #endif
-}
-//LCOV_EXCL_STOP
-
-static void _handle_sticker_provider_cb(GDBusConnection *connection,
- const gchar *sender_name,
- const gchar *object_path,
- const gchar *interface_name,
- const gchar *signal_name,
- GVariant *parameters,
- gpointer user_data)
-{
- LOGD("own_name : %s, signal_name : %s", g_dbus_connection_get_unique_name(connection), signal_name);
- sticker_provider_h provider_handle = (sticker_provider_h)user_data;
-
- if (provider_handle == NULL) {
- LOGE("provider handle is not available");
- return;
- }
-
- if (parameters == NULL) {
- LOGE("failed to get sticker info");
- return;
- }
-
- if (g_strcmp0(signal_name, "send_insert_result") == 0) {
- if (provider_handle->insert_finished_cb != NULL)
- _call_insert_finished_cb(provider_handle, parameters);
- }
-
- #if 0 // Receive the sticker information by asynchronous communication.
- sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
-
- if (!sticker_data) {
- LOGE("failed to allocate memory");
- return;
- }
-
- _get_sticker_info_from_gvariant(parameters, sticker_data);
-
- if (g_strcmp0(signal_name, "send_sticker_info_by_appid") == 0) {
- if (provider_handle->data_foreach_cb != NULL)
- provider_handle->data_foreach_cb(sticker_data, provider_handle->data_foreach_cb_user_data);
- else
- LOGW("No registered callback function");
- }
-
- _free_sticker_data(sticker_data);
- #endif
-}
-
-static int _dbus_signal_init(GDBusConnection *gdbus_connection, int *monitor_id, CLIENT_LIB lib, void *data)
-{
- int ret = STICKER_CLIENT_ERROR_NONE;
- if (*monitor_id == 0) {
- int id = 0;
- if (lib == STICKER_CLIENT_LIB_CONSUMER)
- id = g_dbus_connection_signal_subscribe(gdbus_connection,
- STICKER_DBUS_NAME,
- STICKER_CONSUMER_INTERFACE_NAME,
- NULL,
- STICKER_OBJECT_PATH,
- NULL,
- G_DBUS_SIGNAL_FLAGS_NONE,
- _handle_sticker_consumer_cb,
- data,
- NULL);
- else if (lib == STICKER_CLIENT_LIB_PROVIDER)
- id = g_dbus_connection_signal_subscribe(gdbus_connection,
- STICKER_DBUS_NAME,
- STICKER_PROVIDER_INTERFACE_NAME,
- NULL,
- STICKER_OBJECT_PATH,
- NULL,
- G_DBUS_SIGNAL_FLAGS_NONE,
- _handle_sticker_provider_cb,
- data,
- NULL);
- LOGD("id : %d", id);
- if (id == 0) {
- //LCOV_EXCL_START
- ret = STICKER_CLIENT_ERROR_IO_ERROR;
- LOGE("g_dbus_connection_signal_subscribe() failed");
- //LCOV_EXCL_STOP
- } else {
- *monitor_id = id;
- }
- }
-
- return ret;
-}
-
-static GDBusMessage *_get_gdbus_message(GVariant *body, const char *cmd)
-{
- GDBusMessage *message = NULL;
- message = g_dbus_message_new_method_call(
- STICKER_DBUS_NAME,
- STICKER_OBJECT_PATH,
- STICKER_INTERFACE_NAME,
- cmd);
-
- if (!message) {
- //LCOV_EXCL_START
- LOGE("Failed to create a new gdbus message");
- if (body)
- g_variant_unref(body);
- //LCOV_EXCL_STOP
- return NULL;
- }
-
- if (body != NULL)
- g_dbus_message_set_body(message, body);
-
- return message;
-}
-
-static int _send_gdbus_sync_message(GDBusConnection *gdbus_connection, GDBusMessage *msg, GDBusMessage **reply, const char *cmd)
-{
- int ret = STICKER_CLIENT_ERROR_NONE;
- GError *err = NULL;
-
- *reply = g_dbus_connection_send_message_with_reply_sync(
- gdbus_connection,
- msg,
- G_DBUS_SEND_MESSAGE_FLAGS_NONE,
- -1,
- NULL,
- NULL,
- &err);
-
- if (!*reply) {
- //LCOV_EXCL_START
- ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
- if (err != NULL) {
- LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
- if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
- ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
- g_error_free(err);
- }
- //LCOV_EXCL_STOP
- return ret;
- }
-
- if (g_dbus_message_to_gerror(*reply, &err)) {
- //LCOV_EXCL_START
- LOGE("error message = %s, code = %d", err->message, err->code);
- if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
- ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
- else
- ret = err->code;
- g_error_free(err);
- //LCOV_EXCL_STOP
- return ret;
- }
-
- LOGD("Send a message to server(cmd : %s)", cmd);
- return STICKER_CLIENT_ERROR_NONE;
-}
-
-static int _send_sync_message(GDBusConnection *gdbus_connection, GVariant *body, GDBusMessage **reply, char *cmd)
-{
- int ret = STICKER_CLIENT_ERROR_NONE;
- GDBusMessage *msg = NULL;
-
- msg = _get_gdbus_message(body, cmd);
- if (msg == NULL)
- return STICKER_CLIENT_ERROR_IO_ERROR;
-
- ret = _send_gdbus_sync_message(gdbus_connection, msg, reply, cmd);
-
- if (msg)
- g_object_unref(msg);
-
- return ret;
-}
-
-static int _send_async_message(GDBusConnection *gdbus_connection, GVariant *body, char *cmd)
-{
- int ret = STICKER_CLIENT_ERROR_NONE;
- GDBusMessage *msg = NULL;
- GError *err = NULL;
-
- msg = _get_gdbus_message(body, cmd);
- if (msg == NULL)
- return STICKER_CLIENT_ERROR_IO_ERROR;
-
- g_dbus_connection_send_message(gdbus_connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &err);
-
- if (msg)
- g_object_unref(msg);
-
- if (err != NULL) {
- //LCOV_EXCL_START
- ret = STICKER_CLIENT_ERROR_SERVICE_NOT_READY;
- LOGE("Error occurred when sending message(%s) : %s", cmd, err->message);
-
- if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
- ret = STICKER_CLIENT_ERROR_PERMISSION_DENIED;
-
- g_error_free(err);
- return ret;
- //LCOV_EXCL_STOP
- }
-
- return ret;
-}
-
-static int _monitor_register(GDBusConnection *gdbus_connection, int *server_watcher_id, CLIENT_LIB lib)
-{
- int ret;
- GDBusMessage *reply = NULL;
- GVariant *reply_body = NULL;
-
- ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", (int)lib), &reply, "sticker_service_register");
- if (ret != STICKER_CLIENT_ERROR_NONE) {
- LOGE("_send_sync_message() failed : %d", ret);
- return ret;
- }
-
- reply_body = g_dbus_message_get_body(reply);
- g_variant_get(reply_body, "(i)", server_watcher_id);
-
- if (reply)
- g_object_unref(reply);
-
- is_server_started = 1;
- return ret;
-}
-
-static void _on_name_appeared(GDBusConnection *connection,
- const gchar *name,
- const gchar *name_owner,
- gpointer user_data)
-{
- if (is_server_started == 0) {
- int *watcher_id = (int *)user_data;
- _monitor_register(connection, watcher_id, last_req_lib);
- }
-}
-
-//LCOV_EXCL_START
-static void _on_name_vanished(GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
-{
- is_server_started = 0;
-}
-//LCOV_EXCL_STOP
-
-int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id,
- int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data)
-{
- int ret;
- last_req_lib = lib;
-
- ret = _dbus_init(gdbus_connection);
- if (ret != STICKER_CLIENT_ERROR_NONE) {
- //LCOV_EXCL_START
- LOGE("_dbus_init() failed : %d", ret);
- return ret;
- //LCOV_EXCL_STOP
- }
-
- ret = _dbus_signal_init(*gdbus_connection, monitor_id, lib, data);
- if (ret != STICKER_CLIENT_ERROR_NONE) {
- //LCOV_EXCL_START
- LOGE("_dbus_signal_init() failed : %d", ret);
- return ret;
- //LCOV_EXCL_STOP
- }
-
- ret = _monitor_register(*gdbus_connection, server_watcher_id, lib);
- if (ret != STICKER_CLIENT_ERROR_NONE) {
- //LCOV_EXCL_START
- LOGE("_monitor_register() failed : %d", ret);
- return ret;
- //LCOV_EXCL_STOP
- }
-
- if (*server_monitor_id == 0) {
- *server_monitor_id = g_bus_watch_name_on_connection(
- *gdbus_connection,
- STICKER_DBUS_NAME,
- G_BUS_NAME_WATCHER_FLAGS_NONE,
- _on_name_appeared,
- _on_name_vanished,
- server_watcher_id,
- NULL);
- if (*server_monitor_id == 0) {
- //LCOV_EXCL_START
- g_dbus_connection_signal_unsubscribe(*gdbus_connection, *monitor_id);
- *monitor_id = 0;
- LOGE("Failed to get identifier");
- return STICKER_CLIENT_ERROR_IO_ERROR;
- //LCOV_EXCL_STOP
- }
- }
-
- return STICKER_CLIENT_ERROR_NONE;
-}
-
-int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id, CLIENT_LIB lib)
-{
- int ret;
-
- if (server_watcher_id) {
- ret = _send_async_message(gdbus_connection, g_variant_new("(ii)", (int)lib, *server_watcher_id), "sticker_service_unregister");
- if (ret != STICKER_CLIENT_ERROR_NONE) {
- LOGE("Failed to unregister sticker service");
- return ret;
- }
-
- *server_watcher_id = 0;
- }
-
- if (*server_monitor_id) {
- g_bus_unwatch_name(*server_monitor_id);
- *server_monitor_id = 0;
- }
-
- if (*monitor_id) {
- g_dbus_connection_signal_unsubscribe(gdbus_connection, *monitor_id);
- *monitor_id = 0;
- }
-
- return STICKER_CLIENT_ERROR_NONE;
-}
-
-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 sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
-{
- int ret;
- int ret_id = -1;
- GDBusMessage *reply = NULL;
- GVariant *reply_body = NULL;
- GVariantBuilder *info_builder;
- GVariantBuilder *keyword_builder;
-
- if (!sticker_data->app_id || (sticker_data->type < 1) || !sticker_data->uri || !sticker_data->group || !sticker_data->keyword)
- return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
-
- 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_data->app_id));
- g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI_TYPE, g_variant_new_int32(sticker_data->type));
- g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_URI, g_variant_new_string((const gchar *)sticker_data->uri));
- if (sticker_data->thumbnail)
- g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_THUMBNAIL, g_variant_new_string((const gchar *)sticker_data->thumbnail));
- if (sticker_data->description)
- g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DESCRIPTION, g_variant_new_string((const gchar *)sticker_data->description));
- g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_GROUP, g_variant_new_string((const gchar *)sticker_data->group));
- g_variant_builder_add(info_builder, "{iv}", STICKER_DATA_TYPE_DISP_TYPE, g_variant_new_int32(sticker_data->disp_type));
-
- keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
- g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
-
- ret = _send_sync_message(gdbus_connection, g_variant_new("(a{iv}a(s))", info_builder, keyword_builder), &reply, "insert_sticker_info");
- if (ret != STICKER_CLIENT_ERROR_NONE) {
- LOGW("Failed to save sticker info");
- return ret;
- }
-
- reply_body = g_dbus_message_get_body(reply);
- g_variant_get(reply_body, "(i)", &ret_id);
- sticker_data->sticker_info_id = ret_id;
-
- LOGD("ret_id : %d", ret_id);
-
- g_variant_builder_unref(info_builder);
- g_variant_builder_unref(keyword_builder);
-
- if (reply_body)
- g_variant_unref(reply_body);
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, const char *app_id, const char *json_path)
-{
- int ret;
-
- ret = _send_async_message(gdbus_connection, g_variant_new("(ss)", app_id, json_path), "update_sticker_info_by_json");
- if (ret != STICKER_CLIENT_ERROR_NONE)
- LOGE("failed to send json path");
-
- return ret;
-}
-
-int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int record_id)
-{
- int ret;
- GDBusMessage *reply = NULL;
-
- ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "delete_sticker_info");
- if (ret != STICKER_CLIENT_ERROR_NONE)
- LOGE("failed to delete sticker info");
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-int sticker_dbus_delete_sticker_info_by_uri(GDBusConnection *gdbus_connection, const char *uri)
-{
- int ret;
- GDBusMessage *reply = NULL;
-
- ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "delete_sticker_info_by_uri");
- if (ret != STICKER_CLIENT_ERROR_NONE)
- LOGE("failed to delete sticker info");
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-int sticker_dbus_update_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data)
-{
- int ret;
- bool is_updated = false;
- GDBusMessage *reply = NULL;
- GVariant *reply_body = NULL;
- sticker_data_h origin_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
-
- if (!origin_data) {
- LOGE("failed to allocate memory");
- return STICKER_CLIENT_ERROR_OUT_OF_MEMORY;
- }
-
- ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "get_sticker_info");
- if (ret == STICKER_CLIENT_ERROR_NONE) {
- reply_body = g_dbus_message_get_body(reply);
- GVariantIter *info_iter = NULL;
- GVariantIter *keyword_iter = NULL;
-
- g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
- _get_sticker_info_from_gvariant(info_iter, keyword_iter, origin_data);
-
- if (info_iter)
- g_variant_iter_free(info_iter);
-
- if (keyword_iter)
- g_variant_iter_free(keyword_iter);
- } else {
- LOGW("failed to get sticker info");
- free(origin_data);
- if (reply)
- g_object_unref(reply);
- return ret;
- }
-
- if (sticker_data->uri) {
- int len;
- char *conv_path = NULL;
- if (sticker_data->type == STICKER_DATA_URI_LOCAL_PATH) {
- len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->uri) + 2;
- conv_path = (char *)calloc(len, sizeof(char));
- if (conv_path)
- snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->uri);
- } else
- conv_path = strdup(sticker_data->uri);
-
- if (conv_path && (strcmp(conv_path, origin_data->uri) != 0)) {
- LOGD("origin_uri : %s, new_uri : %s", origin_data->uri, conv_path);
- int is_exist = 0;
- ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", sticker_data->uri), &reply, "check_file_exists");
- if (ret == STICKER_CLIENT_ERROR_NONE) {
- reply_body = g_dbus_message_get_body(reply);
- g_variant_get(reply_body, "(i)", &is_exist);
-
- if (is_exist) {
- LOGE("file already exists");
- ret = STICKER_CLIENT_ERROR_FILE_EXISTS;
- free(conv_path);
- goto cleanup;
- }
- } else {
- LOGE("failed to check file exists");
- free(conv_path);
- goto cleanup;
- }
-
- ret = _send_sync_message(gdbus_connection, g_variant_new("(isis)", sticker_data->sticker_info_id, sticker_data->app_id, sticker_data->type, sticker_data->uri), &reply, "update_sticker_uri");
- if (ret != STICKER_CLIENT_ERROR_NONE) {
- LOGE("failed to update sticker uri");
- free(conv_path);
- goto cleanup;
- }
- is_updated = true;
- }
- free(conv_path);
- }
-
- if (sticker_data->type != 0 && sticker_data->type != origin_data->type) {
- LOGD("origin_type : %d, new_type : %d", origin_data->type, sticker_data->type);
- ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->type), &reply, "update_sticker_type");
- if (ret != STICKER_CLIENT_ERROR_NONE) {
- LOGE("failed to update sticker type");
- goto cleanup;
- }
- is_updated = true;
- }
-
- if (sticker_data->thumbnail) {
- int len = strlen(STICKER_DIRECTORY) + strlen(sticker_data->app_id) + strlen(sticker_data->thumbnail) + 2;
- char *conv_path = (char *)calloc(len, sizeof(char));
- if (conv_path) {
- snprintf(conv_path, len, "%s/%s%s", STICKER_DIRECTORY, sticker_data->app_id, sticker_data->thumbnail);
- if (strcmp(conv_path, origin_data->thumbnail) != 0)
- {
- LOGD("origin_thumbnail : %s, new_thumbnail : %s", origin_data->thumbnail, conv_path);
- 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");
- free(conv_path);
- goto cleanup;
- }
- is_updated = true;
- }
- free(conv_path);
- }
- }
-
- if (sticker_data->description && strcmp(sticker_data->description, origin_data->description) != 0) {
- LOGD("origin_description : %s, new_description : %s", origin_data->description, sticker_data->description);
- ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->description), &reply, "update_sticker_description");
- if (ret != STICKER_CLIENT_ERROR_NONE) {
- LOGE("failed to update sticker description");
- goto cleanup;
- }
- is_updated = true;
- }
-
- if (sticker_data->group && strcmp(sticker_data->group, origin_data->group) != 0) {
- LOGD("origin_group : %s, new_group : %s", origin_data->group, sticker_data->group);
- ret = _send_sync_message(gdbus_connection, g_variant_new("(is)", sticker_data->sticker_info_id, sticker_data->group), &reply, "update_sticker_group");
- if (ret != STICKER_CLIENT_ERROR_NONE) {
- LOGE("failed to update sticker group");
- goto cleanup;
- }
- is_updated = true;
- }
-
- if (sticker_data->disp_type != 0 && sticker_data->disp_type != origin_data->disp_type) {
- LOGD("origin_disp_type : %d, new_disp_type : %d", origin_data->disp_type, sticker_data->disp_type);
- ret = _send_sync_message(gdbus_connection, g_variant_new("(ii)", sticker_data->sticker_info_id, sticker_data->disp_type), &reply, "update_sticker_disp_type");
- if (ret != STICKER_CLIENT_ERROR_NONE) {
- LOGE("failed to update sticker display type");
- goto cleanup;
- }
- is_updated = true;
- }
-
- if (sticker_data->keyword) {
- GVariantBuilder *keyword_builder;
- keyword_builder = g_variant_builder_new(G_VARIANT_TYPE("a(s)"));
- g_list_foreach(sticker_data->keyword, (GFunc) _set_keyword_builder, keyword_builder);
- ret = _send_sync_message(gdbus_connection, g_variant_new("(ia(s))", sticker_data->sticker_info_id, keyword_builder), &reply, "update_sticker_keyword");
- if (ret != STICKER_CLIENT_ERROR_NONE)
- LOGE("failed to update sticker keyword");
- else
- is_updated = true;
- g_variant_builder_unref(keyword_builder);
- }
-
- if (is_updated)
- ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", sticker_data->sticker_info_id), &reply, "send_update_event");
-
-cleanup:
- _free_sticker_data(origin_data);
-
- if (reply_body)
- g_variant_unref(reply_body);
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-int sticker_dbus_get_sticker_info_by_record_id(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, int record_id)
-{
- int ret;
- GDBusMessage *reply = NULL;
- GVariant *reply_body = NULL;
- GVariantIter *info_iter = NULL;
- GVariantIter *keyword_iter = NULL;
-
- ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "get_sticker_info");
- if (ret == STICKER_CLIENT_ERROR_NONE) {
- reply_body = g_dbus_message_get_body(reply);
- sticker_data->sticker_info_id = record_id;
-
- g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
- _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
-
- if (reply_body)
- g_variant_unref(reply_body);
-
- if (info_iter)
- g_variant_iter_free(info_iter);
-
- if (keyword_iter)
- g_variant_iter_free(keyword_iter);
- }
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-int sticker_dbus_get_group_list(GDBusConnection *gdbus_connection, const char *app_id, GList **group_list)
-{
- int ret;
- GDBusMessage *reply = NULL;
- GVariantIter *iter = NULL;
- GVariant *reply_body = NULL;
- char *group = NULL;
-
- if (group_list == NULL) {
- LOGE("group_list is invalid");
- return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
- }
-
- 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);
-
- if (!iter) {
- LOGD("failed to get iter");
- return STICKER_CLIENT_ERROR_OPERATION_FAILED;
- }
-
- while (g_variant_iter_loop (iter, "(s)", &group)) {
- *group_list = g_list_append(*group_list, strdup((const char *)group));
- }
-
- g_variant_iter_free(iter);
- }
-
- if (reply_body)
- g_variant_unref(reply_body);
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-int sticker_dbus_get_keyword_list(GDBusConnection *gdbus_connection, const char *app_id, GList **keyword_list)
-{
- int ret;
- GDBusMessage *reply = NULL;
- GVariantIter *iter = NULL;
- GVariant *reply_body = NULL;
- char *keyword = NULL;
-
- if (keyword_list == NULL) {
- LOGE("keyword_list is invalid");
- return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
- }
-
- 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);
-
- if (!iter) {
- LOGD("failed to get iter");
- return STICKER_CLIENT_ERROR_OPERATION_FAILED;
- }
-
- while (g_variant_iter_loop (iter, "(s)", &keyword)) {
- *keyword_list = g_list_append(*keyword_list, strdup((const char *)keyword));
- }
-
- g_variant_iter_free(iter);
- }
-
- if (reply_body)
- g_variant_unref(reply_body);
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-int sticker_dbus_get_sticker_count(GDBusConnection *gdbus_connection, const char *app_id, int *count)
-{
- int ret;
- GDBusMessage *reply = NULL;
- GVariant *reply_body = NULL;
-
- ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", app_id), &reply, "get_sticker_count");
- if (ret == STICKER_CLIENT_ERROR_NONE) {
- reply_body = g_dbus_message_get_body(reply);
- g_variant_get(reply_body, "(i)", count);
- }
-
- if (reply_body)
- g_variant_unref(reply_body);
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-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("(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);
- }
-
- if (reply_body)
- g_variant_unref(reply_body);
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-int sticker_dbus_get_sticker_info_by_appid(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("(sii)", app_id, offset, count), &reply, "get_sticker_info_by_appid");
- if (ret == STICKER_CLIENT_ERROR_NONE) {
- reply_body = g_dbus_message_get_body(reply);
- g_variant_get(reply_body, "(a(i))", id_iter);
- }
-
- if (reply_body)
- g_variant_unref(reply_body);
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-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("(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);
- }
-
- if (reply_body)
- g_variant_unref(reply_body);
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-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("(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);
- }
-
- if (reply_body)
- g_variant_unref(reply_body);
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-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("(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);
- }
-
- if (reply_body)
- g_variant_unref(reply_body);
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-int sticker_dbus_get_sticker_info_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_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("(siii)", app_id, (int)type, offset, count), &reply, "get_sticker_info_by_disp_type");
- if (ret == STICKER_CLIENT_ERROR_NONE) {
- reply_body = g_dbus_message_get_body(reply);
- g_variant_get(reply_body, "(a(i))", id_iter);
- }
-
- if (reply_body)
- g_variant_unref(reply_body);
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-int sticker_dbus_get_group_list_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_type_e type, GList **group_list)
-{
- int ret;
- GDBusMessage *reply = NULL;
- GVariantIter *iter = NULL;
- GVariant *reply_body = NULL;
- char *group = NULL;
-
- if (group_list == NULL) {
- LOGE("group_list is invalid");
- return STICKER_CLIENT_ERROR_INVALID_PARAMETER;
- }
-
- ret = _send_sync_message(gdbus_connection, g_variant_new("(si)", app_id, (int)type), &reply, "get_group_list_by_disp_type");
- if (ret == STICKER_CLIENT_ERROR_NONE) {
- reply_body = g_dbus_message_get_body(reply);
- g_variant_get(reply_body, "(a(s))", &iter);
-
- if (!iter) {
- LOGD("failed to get iter");
- return STICKER_CLIENT_ERROR_OPERATION_FAILED;
- }
-
- while (g_variant_iter_loop (iter, "(s)", &group)) {
- *group_list = g_list_append(*group_list, strdup((const char *)group));
- }
-
- g_variant_iter_free(iter);
- }
-
- if (reply_body)
- g_variant_unref(reply_body);
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-int sticker_dbus_check_file_exists(GDBusConnection *gdbus_connection, const char *uri, int *result)
-{
- int ret;
- GDBusMessage *reply = NULL;
- GVariant *reply_body = NULL;
-
- ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "check_file_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_insert_recent_sticker_info(GDBusConnection *gdbus_connection, int record_id)
-{
- int ret;
- GDBusMessage *reply = NULL;
-
- ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", record_id), &reply, "insert_recent_sticker_info");
- if (ret != STICKER_CLIENT_ERROR_NONE)
- LOGE("failed to insert recent sticker info");
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-int sticker_dbus_get_recent_sticker_list(GDBusConnection *gdbus_connection, int count, GVariantIter **id_iter)
-{
- int ret;
- GDBusMessage *reply = NULL;
- GVariant *reply_body = NULL;
-
- ret = _send_sync_message(gdbus_connection, g_variant_new("(i)", count), &reply, "get_recent_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);
- }
-
- if (reply_body)
- g_variant_unref(reply_body);
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
-
-int sticker_dbus_get_sticker_info_by_uri(GDBusConnection *gdbus_connection, sticker_data_h sticker_data, const char *uri)
-{
- int ret;
- GDBusMessage *reply = NULL;
- GVariant *reply_body = NULL;
- GVariantIter *info_iter = NULL;
- GVariantIter *keyword_iter = NULL;
-
- ret = _send_sync_message(gdbus_connection, g_variant_new("(s)", uri), &reply, "get_sticker_info_by_uri");
- if (ret == STICKER_CLIENT_ERROR_NONE) {
- reply_body = g_dbus_message_get_body(reply);
- g_variant_get(reply_body, "(a{iv}a(s))", &info_iter, &keyword_iter);
- _get_sticker_info_from_gvariant(info_iter, keyword_iter, sticker_data);
-
- if (reply_body)
- g_variant_unref(reply_body);
-
- if (info_iter)
- g_variant_iter_free(info_iter);
-
- if (keyword_iter)
- g_variant_iter_free(keyword_iter);
- }
-
- if (reply)
- g_object_unref(reply);
-
- return ret;
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __TIZEN_UIX_STICKER_DBUS_H__
-#define __TIZEN_UIX_STICKER_DBUS_H__
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <glib.h>
-#include <gio/gio.h>
-#include <dbus/dbus.h>
-#include "sticker_defs.h"
-#include "sticker_data.h"
-#include "sticker_data_main.h"
-#include "sticker_provider_main.h"
-#include "sticker_consumer_main.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-enum sticker_client_error {
- STICKER_CLIENT_ERROR_NONE,
- STICKER_CLIENT_ERROR_INVALID_PARAMETER,
- STICKER_CLIENT_ERROR_PERMISSION_DENIED,
- STICKER_CLIENT_ERROR_OUT_OF_MEMORY,
- STICKER_CLIENT_ERROR_SERVICE_NOT_READY,
- STICKER_CLIENT_ERROR_OPERATION_FAILED,
- STICKER_CLIENT_ERROR_IO_ERROR,
- STICKER_CLIENT_ERROR_DB_FAILED,
- STICKER_CLIENT_ERROR_FILE_EXISTS,
- STICKER_CLIENT_ERROR_NO_SUCH_FILE,
-};
-
-int sticker_dbus_init(GDBusConnection **gdbus_connection, int *server_watcher_id,
- int *monitor_id, int *server_monitor_id, CLIENT_LIB lib, void *data);
-int sticker_dbus_shutdown(GDBusConnection *gdbus_connection, int *server_watcher_id, int *server_monitor_id, int *monitor_id, CLIENT_LIB lib);
-int sticker_dbus_insert_sticker_info(GDBusConnection *gdbus_connection, sticker_data_h sticker_data);
-int sticker_dbus_insert_sticker_info_by_json(GDBusConnection *gdbus_connection, const char *app_id, const char *json_path);
-int sticker_dbus_delete_sticker_info(GDBusConnection *gdbus_connection, int record_id);
-int sticker_dbus_delete_sticker_info_by_uri(GDBusConnection *gdbus_connection, const char *uri);
-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, 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, 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, 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);
-int sticker_dbus_get_sticker_info_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_type_e type, int offset, int count, GVariantIter **id_iter);
-int sticker_dbus_get_group_list_by_display_type(GDBusConnection *gdbus_connection, const char *app_id, sticker_data_display_type_e type, GList **group_list);
-int sticker_dbus_check_file_exists(GDBusConnection *gdbus_connection, const char *uri, int *result);
-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);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_UIX_STICKER_DBUS_H__ */
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __TIZEN_UIX_STICKER_DEFS_H__
-#define __TIZEN_UIX_STICKER_DEFS_H__
-
-#include <tzplatform_config.h>
-#include <stdbool.h>
-#include <system_info.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define HAPI __attribute__((visibility("hidden")))
-
-#define DBUS_NAME "org.freedesktop.DBus"
-#define DBUS_OBJECT_PATH "/org/freedesktop/DBus"
-#define DBUS_INTERFACE_NAME "org.freedesktop.DBus"
-
-#define STICKER_DBUS_NAME "org.tizen.sticker.server"
-#define STICKER_OBJECT_PATH "/org/tizen/sticker/server"
-#define STICKER_INTERFACE_NAME "org.tizen.sticker_service"
-#define STICKER_PROVIDER_INTERFACE_NAME "org.tizen.sticker_provider"
-#define STICKER_CONSUMER_INTERFACE_NAME "org.tizen.sticker_consumer"
-
-#define STICKER_PRIVILEGE_MEDIASTORAGE "http://tizen.org/privilege/mediastorage"
-#define STICKER_FEATURE_STICKER "tizen.org/feature/ui_service.sticker"
-#define CHECK_STICKER_FEATURE() \
- do { \
- bool is_supported = false; \
- if (!system_info_get_platform_bool(STICKER_FEATURE_STICKER, &is_supported)) { \
- if (is_supported == false) { \
- LOGE("ui_service.sticker feature not supported"); \
- return STICKER_ERROR_NOT_SUPPORTED; \
- } \
- } \
- } while (0)
-#define STICKER_DIRECTORY "/opt/usr/share/sticker-data"
-
-typedef enum {
- STICKER_CLIENT_LIB_NONE,
- STICKER_CLIENT_LIB_CONSUMER,
- STICKER_CLIENT_LIB_PROVIDER,
-} CLIENT_LIB;
-
-typedef enum {
- STICKER_DATA_TYPE_INFO_ID = 1,
- STICKER_DATA_TYPE_APP_ID,
- STICKER_DATA_TYPE_URI_TYPE,
- STICKER_DATA_TYPE_URI,
- STICKER_DATA_TYPE_THUMBNAIL,
- STICKER_DATA_TYPE_DESCRIPTION,
- STICKER_DATA_TYPE_GROUP,
- STICKER_DATA_TYPE_KEYWORD,
- STICKER_DATA_TYPE_DATE,
- STICKER_DATA_TYPE_DISP_TYPE,
-} STICKER_DAT_TYPE;
-
-typedef enum {
- STICKER_EVENT_TYPE_INSERT,
- STICKER_EVENT_TYPE_DELETE,
- STICKER_EVENT_TYPE_UPDATE,
-} STICKER_EVENT_TYPE;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_UIX_STICKER_DEFS_H__ */
\ No newline at end of file
+++ /dev/null
-SET(SRCS
- sticker_consumer.c
- ../client/sticker_data.c
- ../client/sticker_dbus.c
-)
-
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
-INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/include)
-
-FOREACH(flag ${pkgs_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall")
-
-## Add definitions ##
-ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
-
-## sticker consumer library ##
-ADD_LIBRARY(${PROJECT_NAME}-consumer SHARED ${SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME}-consumer ${pkgs_LDFLAGS})
-
-## Install library files ##
-INSTALL(TARGETS ${PROJECT_NAME}-consumer DESTINATION ${LIBDIR} COMPONENT RuntimeLibraries)
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <dlog.h>
-#include <gio/gio.h>
-#include <dbus/dbus.h>
-#include <app_common.h>
-#include <cynara-client.h>
-#include <cynara-error.h>
-#include <cynara-session.h>
-
-#include "sticker_consumer.h"
-#include "sticker_consumer_main.h"
-#include "sticker_dbus.h"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "STICKER_CONSUMER"
-
-static cynara *p_cynara = NULL;
-
-static void _free_sticker_data(sticker_data_h sticker_data)
-{
- 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);
- sticker_data = NULL;
-}
-
-static int _cynara_initialize()
-{
- int ret = cynara_initialize(&p_cynara, NULL);
- if (ret != CYNARA_API_SUCCESS)
- LOGE("Failed to cynara initialize"); //LCOV_EXCL_LINE
-
- return ret;
-}
-
-static int _check_privilege(const char *uid, const char *privilege)
-{
- int ret;
- FILE *fp = NULL;
- char label_path[1024] = "/proc/self/attr/current";
- char smack_label[1024] = {'\0',};
-
- if (!p_cynara) {
- return -1;
- }
-
- fp = fopen(label_path, "r");
- if (fp != NULL) {
- ret = fread(smack_label, 1, sizeof(smack_label), fp);
- if (ret <= 0)
- LOGE("Failed to fread");
-
- fclose(fp);
- }
-
- pid_t pid = getpid();
- char *session = cynara_session_from_pid(pid);
- ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
- if (session)
- free(session);
-
- if (ret != CYNARA_API_ACCESS_ALLOWED) {
- LOGE("Access denied. The result of cynara_check() : %d.", ret); //LCOV_EXCL_LINE
- return -1;
- }
-
- return 0;
-}
-
-static void _cynara_deinitialize()
-{
- if (p_cynara)
- cynara_finish(p_cynara);
-
- p_cynara = NULL;
-}
-
-static int _sticker_check_privilege() {
- char uid[16];
- int ret = STICKER_ERROR_NONE;
-
- if (_cynara_initialize() != CYNARA_API_SUCCESS)
- return STICKER_ERROR_PERMISSION_DENIED;
-
- snprintf(uid, 16, "%d", getuid());
- if (_check_privilege(uid, STICKER_PRIVILEGE_MEDIASTORAGE) < 0) {
- LOGE("Permission is denied"); //LCOV_EXCL_LINE
- ret = STICKER_ERROR_PERMISSION_DENIED;
- }
-
- _cynara_deinitialize();
-
- return ret;
-}
-
-EXPORT_API int sticker_consumer_create(sticker_consumer_h *consumer_handle)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- if (!consumer_handle)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- if (_sticker_check_privilege() != STICKER_ERROR_NONE)
- return STICKER_ERROR_PERMISSION_DENIED;
-
- struct sticker_consumer_s *consumer_struct = (sticker_consumer_h)calloc(1, sizeof(struct sticker_consumer_s));
-
- if (!consumer_struct)
- return STICKER_ERROR_OUT_OF_MEMORY;
-
- ret = app_get_id(&consumer_struct->app_id);
- if (ret != APP_ERROR_NONE) {
- //LCOV_EXCL_START
- LOGE("Failed to get app_id : %d", ret);
- free(consumer_struct);
- return STICKER_ERROR_OPERATION_FAILED;
- //LCOV_EXCL_STOP
- }
-
- 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) {
- //LCOV_EXCL_START
- LOGE("Failed to initialize dbus : %d", ret);
- free(consumer_struct);
- return STICKER_ERROR_OPERATION_FAILED;
- //LCOV_EXCL_STOP
- }
-
- *consumer_handle = consumer_struct;
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_consumer_destroy(sticker_consumer_h consumer_handle)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- if (!consumer_handle)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- LOGD("consumer_handle : %p", consumer_handle);
- ret = sticker_dbus_shutdown(consumer_handle->gdbus_connection, &consumer_handle->server_watcher_id,
- &consumer_handle->server_monitor_id, &consumer_handle->monitor_id, STICKER_CLIENT_LIB_CONSUMER);
- if (ret != STICKER_ERROR_NONE) {
- //LCOV_EXCL_START
- LOGE("Failed to finalize dbus : %d", ret);
- free(consumer_handle);
- return STICKER_ERROR_OPERATION_FAILED;
- //LCOV_EXCL_STOP
- }
-
- 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;
-}
-
-EXPORT_API int sticker_consumer_data_foreach_all(sticker_consumer_h consumer_handle, int offset, int count, int *result, sticker_consumer_data_foreach_cb callback, void *user_data)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- int info_id;
- int sticker_count = 0;
- GVariantIter *id_iter = NULL;
-
- 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, 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;
- goto cleanup;
- }
-
- if (id_iter) {
- while (g_variant_iter_loop (id_iter, "(i)", &info_id)) {
- sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
- if (!sticker_data) {
- ret = STICKER_ERROR_OUT_OF_MEMORY;
- goto cleanup;
- }
-
- ret = sticker_dbus_get_sticker_info_by_record_id(consumer_handle->gdbus_connection, sticker_data, info_id);
- if (ret == STICKER_ERROR_NONE) {
- sticker_count++;
- callback(sticker_data, user_data);
- _free_sticker_data(sticker_data);
- } else {
- _free_sticker_data(sticker_data);
- goto cleanup;
- }
- }
- }
-
- *result = sticker_count;
-
-cleanup:
- if (id_iter)
- g_variant_iter_free(id_iter);
-
- return ret;
-}
-
-EXPORT_API int sticker_consumer_data_foreach_by_keyword(sticker_consumer_h consumer_handle, int offset, int count, int *result, const char *keyword, sticker_consumer_data_foreach_cb callback, void *user_data)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- int info_id;
- int sticker_count = 0;
- GVariantIter *id_iter = NULL;
-
- 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, 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;
- goto cleanup;
- }
-
- if (id_iter) {
- while (g_variant_iter_loop (id_iter, "(i)", &info_id)) {
- sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
- if (!sticker_data) {
- ret = STICKER_ERROR_OUT_OF_MEMORY;
- goto cleanup;
- }
-
- ret = sticker_dbus_get_sticker_info_by_record_id(consumer_handle->gdbus_connection, sticker_data, info_id);
- if (ret == STICKER_ERROR_NONE) {
- sticker_count++;
- callback(sticker_data, user_data);
- _free_sticker_data(sticker_data);
- } else {
- _free_sticker_data(sticker_data);
- goto cleanup;
- }
- }
- }
-
- *result = sticker_count;
-
-cleanup:
- if (id_iter)
- g_variant_iter_free(id_iter);
-
- return ret;
-}
-
-EXPORT_API int sticker_consumer_data_foreach_by_group(sticker_consumer_h consumer_handle, int offset, int count, int *result, const char *group, sticker_consumer_data_foreach_cb callback, void *user_data)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- int info_id;
- int sticker_count = 0;
- GVariantIter *id_iter = NULL;
-
- 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, 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;
- goto cleanup;
- }
-
- if (id_iter) {
- while (g_variant_iter_loop (id_iter, "(i)", &info_id)) {
- sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
- if (!sticker_data) {
- ret = STICKER_ERROR_OUT_OF_MEMORY;
- goto cleanup;
- }
-
- ret = sticker_dbus_get_sticker_info_by_record_id(consumer_handle->gdbus_connection, sticker_data, info_id);
- if (ret == STICKER_ERROR_NONE) {
- sticker_count++;
- callback(sticker_data, user_data);
- _free_sticker_data(sticker_data);
- } else {
- _free_sticker_data(sticker_data);
- goto cleanup;
- }
- }
- }
-
- *result = sticker_count;
-
-cleanup:
- if (id_iter)
- g_variant_iter_free(id_iter);
-
- return ret;
-}
-
-EXPORT_API int sticker_consumer_data_foreach_by_type(sticker_consumer_h consumer_handle, int offset, int count, int *result, sticker_data_uri_type_e type, sticker_consumer_data_foreach_cb callback, void *user_data)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- int info_id;
- int sticker_count = 0;
- GVariantIter *id_iter = NULL;
-
- 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, consumer_handle->app_id, type, offset, count, &id_iter);
- if (ret != STICKER_ERROR_NONE) {
- LOGE("Failed to get sticker information by uri type : %d", ret);
- ret = STICKER_ERROR_OPERATION_FAILED;
- goto cleanup;
- }
-
- if (id_iter) {
- while (g_variant_iter_loop (id_iter, "(i)", &info_id)) {
- sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
- if (!sticker_data) {
- ret = STICKER_ERROR_OUT_OF_MEMORY;
- goto cleanup;
- }
-
- ret = sticker_dbus_get_sticker_info_by_record_id(consumer_handle->gdbus_connection, sticker_data, info_id);
- if (ret == STICKER_ERROR_NONE) {
- sticker_count++;
- callback(sticker_data, user_data);
- _free_sticker_data(sticker_data);
- } else {
- _free_sticker_data(sticker_data);
- goto cleanup;
- }
- }
- }
-
- *result = sticker_count;
-
-cleanup:
- if (id_iter)
- g_variant_iter_free(id_iter);
-
- return ret;
-}
-
-EXPORT_API int sticker_consumer_group_list_foreach_all(sticker_consumer_h consumer_handle, sticker_consumer_group_list_foreach_cb callback, void *user_data)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- GList *list = NULL;
-
- if (!consumer_handle || !callback)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- 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;
- goto cleanup;
- }
-
- for(GList *tmp = g_list_first(list); tmp != NULL; tmp=tmp->next) {
- callback((const char *)tmp->data, user_data);
- }
-
-cleanup:
- if (list)
- g_list_free_full(list, free);
-
- return ret;
-}
-
-EXPORT_API int sticker_consumer_keyword_list_foreach_all(sticker_consumer_h consumer_handle, sticker_consumer_keyword_list_foreach_cb callback, void *user_data)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- GList *list = NULL;
-
- if (!consumer_handle || !callback)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- 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;
- goto cleanup;
- }
-
- for(GList *tmp = g_list_first(list); tmp != NULL; tmp=tmp->next) {
- callback((const char *)tmp->data, user_data);
- }
-
-cleanup:
- if (list)
- g_list_free_full(list, free);
-
- return ret;
-}
-
-EXPORT_API int sticker_consumer_data_foreach_by_display_type(sticker_consumer_h consumer_handle, int offset, int count, int *result, sticker_data_display_type_e type, sticker_consumer_data_foreach_cb callback, void *user_data)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- int info_id;
- int sticker_count = 0;
- GVariantIter *id_iter = NULL;
-
- if (!consumer_handle || (offset < 0) || (count <= 0) || !result || (type < 1) || !callback)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- ret = sticker_dbus_get_sticker_info_by_display_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 display type : %d", ret);
- ret = STICKER_ERROR_OPERATION_FAILED;
- goto cleanup;
- }
-
- if (id_iter) {
- while (g_variant_iter_loop (id_iter, "(i)", &info_id)) {
- sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
- if (!sticker_data) {
- ret = STICKER_ERROR_OUT_OF_MEMORY;
- goto cleanup;
- }
-
- ret = sticker_dbus_get_sticker_info_by_record_id(consumer_handle->gdbus_connection, sticker_data, info_id);
- if (ret == STICKER_ERROR_NONE) {
- sticker_count++;
- callback(sticker_data, user_data);
- _free_sticker_data(sticker_data);
- } else {
- _free_sticker_data(sticker_data);
- goto cleanup;
- }
- }
- }
-
- *result = sticker_count;
-
-cleanup:
- if (id_iter)
- g_variant_iter_free(id_iter);
-
- return ret;
-}
-
-EXPORT_API int sticker_consumer_group_list_foreach_by_display_type(sticker_consumer_h consumer_handle, sticker_data_display_type_e type, sticker_consumer_group_list_foreach_cb callback, void *user_data)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- GList *list = NULL;
-
- if (!consumer_handle || (type < 1) || !callback)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- ret = sticker_dbus_get_group_list_by_display_type(consumer_handle->gdbus_connection, consumer_handle->app_id, type, &list);
- if (ret != STICKER_ERROR_NONE) {
- LOGE("Failed to get group list : %d", ret);
- ret = STICKER_ERROR_OPERATION_FAILED;
- goto cleanup;
- }
-
- for(GList *tmp = g_list_first(list); tmp != NULL; tmp=tmp->next) {
- callback((const char *)tmp->data, user_data);
- }
-
-cleanup:
- if (list)
- g_list_free_full(list, free);
-
- return ret;
-}
-
-EXPORT_API int sticker_consumer_add_recent_data(sticker_consumer_h consumer_handle, sticker_data_h data_handle)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
-
- if (!consumer_handle || !data_handle || (data_handle->sticker_info_id <= 0) || !data_handle->uri)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- ret = sticker_dbus_insert_recent_sticker_info(consumer_handle->gdbus_connection, data_handle->sticker_info_id);
- if (ret != STICKER_ERROR_NONE) {
- LOGE("Failed to add recent sticker information : %d", ret);
- return STICKER_ERROR_OPERATION_FAILED;
- }
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_consumer_get_recent_data_list(sticker_consumer_h consumer_handle, int count, int *result, sticker_consumer_data_foreach_cb callback, void *user_data)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- int info_id;
- int sticker_count = 0;
- GVariantIter *id_iter = NULL;
-
- if (!consumer_handle || (count <= 0) || !result || !callback)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- ret = sticker_dbus_get_recent_sticker_list(consumer_handle->gdbus_connection, count, &id_iter);
- if (ret != STICKER_ERROR_NONE) {
- LOGE("Failed to get recent sticker information : %d", ret);
- ret = STICKER_ERROR_OPERATION_FAILED;
- goto cleanup;
- }
-
- if (id_iter) {
- while (g_variant_iter_loop (id_iter, "(i)", &info_id)) {
- sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
- if (!sticker_data) {
- ret = STICKER_ERROR_OUT_OF_MEMORY;
- goto cleanup;
- }
-
- ret = sticker_dbus_get_sticker_info_by_record_id(consumer_handle->gdbus_connection, sticker_data, info_id);
- if (ret == STICKER_ERROR_NONE) {
- sticker_count++;
- callback(sticker_data, user_data);
- _free_sticker_data(sticker_data);
- } else {
- _free_sticker_data(sticker_data);
- goto cleanup;
- }
- }
- }
-
- *result = sticker_count;
-
-cleanup:
- if (id_iter)
- g_variant_iter_free(id_iter);
-
- return ret;
-}
-
-EXPORT_API int sticker_consumer_set_event_cb(sticker_consumer_h consumer_handle, sticker_consumer_event_cb callback, void *user_data)
-{
- CHECK_STICKER_FEATURE();
-
- if (!consumer_handle || !callback)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- consumer_handle->event_cb = callback;
- consumer_handle->event_cb_user_data = user_data;
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_consumer_unset_event_cb(sticker_consumer_h consumer_handle)
-{
- CHECK_STICKER_FEATURE();
-
- if (!consumer_handle)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- consumer_handle->event_cb = NULL;
- consumer_handle->event_cb_user_data = NULL;
-
- return STICKER_ERROR_NONE;
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __TIZEN_UIX_STICKER_CONSUMER_MAIN_H__
-#define __TIZEN_UIX_STICKER_CONSUMER_MAIN_H__
-
-#include <gio/gio.h>
-#include <dbus/dbus.h>
-#include "sticker_consumer.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-struct sticker_consumer_s {
- GDBusConnection *gdbus_connection;
- int server_watcher_id;
- int monitor_id;
- int server_monitor_id;
- char *app_id;
- sticker_consumer_event_cb event_cb;
- void *event_cb_user_data;
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_UIX_STICKER_CONSUMER_MAIN_H__ */
\ No newline at end of file
+++ /dev/null
-SET(SRCS
- sticker_provider.c
- ../client/sticker_data.c
- ../client/sticker_dbus.c
-)
-
-INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
-INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/include)
-
-FOREACH(flag ${pkgs_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall")
-
-## Add definitions ##
-ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
-
-## sticker provider library ##
-ADD_LIBRARY(${PROJECT_NAME}-provider SHARED ${SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME}-provider ${pkgs_LDFLAGS})
-
-## Install library files ##
-INSTALL(TARGETS ${PROJECT_NAME}-provider DESTINATION ${LIBDIR} COMPONENT RuntimeLibraries)
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <dlog.h>
-#include <app_common.h>
-#include <package_manager.h>
-
-#include "sticker_provider.h"
-#include "sticker_provider_main.h"
-#include "sticker_dbus.h"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "STICKER_PROVIDER"
-
-static void _free_sticker_data(sticker_data_h sticker_data)
-{
- 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);
- sticker_data = NULL;
-}
-
-EXPORT_API int sticker_provider_create(sticker_provider_h *provider_handle)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- if (!provider_handle)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- struct sticker_provider_s *provider_struct = (sticker_provider_h)calloc(1, sizeof(struct sticker_provider_s));
-
- if (!provider_struct)
- return STICKER_ERROR_OUT_OF_MEMORY;
-
- ret = sticker_dbus_init(&provider_struct->gdbus_connection, &provider_struct->server_watcher_id,
- &provider_struct->monitor_id, &provider_struct->server_monitor_id, STICKER_CLIENT_LIB_PROVIDER, (void *)provider_struct);
- if (ret != STICKER_ERROR_NONE) {
- //LCOV_EXCL_START
- LOGE("Failed to initialize dbus : %d", ret);
- free(provider_struct);
- return STICKER_ERROR_OPERATION_FAILED;
- //LCOV_EXCL_STOP
- }
-
- *provider_handle = provider_struct;
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_provider_destroy(sticker_provider_h provider_handle)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- if (!provider_handle)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- LOGD("provider_handle : %p", provider_handle);
- ret = sticker_dbus_shutdown(provider_handle->gdbus_connection, &provider_handle->server_watcher_id,
- &provider_handle->server_monitor_id, &provider_handle->monitor_id, STICKER_CLIENT_LIB_PROVIDER);
- if (ret != STICKER_ERROR_NONE) {
- //LCOV_EXCL_START
- LOGE("Failed to finalize dbus : %d", ret);
- free(provider_handle);
- return STICKER_ERROR_OPERATION_FAILED;
- //LCOV_EXCL_STOP
- }
-
- if (provider_handle->gdbus_connection)
- g_object_unref(provider_handle->gdbus_connection);
-
- free(provider_handle);
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_provider_insert_data(sticker_provider_h provider_handle, sticker_data_h data_handle)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- int is_exist = 0;
-
- if (!provider_handle || !data_handle || (data_handle->sticker_info_id > 0) || !data_handle->uri)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- int len = strlen(STICKER_DIRECTORY) + strlen(data_handle->app_id) + strlen(data_handle->uri) + 3;
- char *new_path = (char *)calloc(len, sizeof(char));
- if (!new_path) {
- return STICKER_ERROR_OUT_OF_MEMORY;
- }
-
- if (data_handle->uri[0] == '/')
- snprintf(new_path, len, "%s/%s%s",STICKER_DIRECTORY, data_handle->app_id, data_handle->uri);
- else
- snprintf(new_path, len, "%s/%s/%s",STICKER_DIRECTORY, data_handle->app_id, data_handle->uri);
-
- ret = sticker_dbus_check_file_exists(provider_handle->gdbus_connection, new_path, &is_exist);
- if (ret != STICKER_ERROR_NONE) {
- LOGE("Failed to check file exists : %d", ret);
- ret = STICKER_ERROR_OPERATION_FAILED;
- goto cleanup;
- }
-
- if (is_exist) {
- LOGE("Sticker already exists");
- ret = STICKER_ERROR_FILE_EXISTS;
- goto cleanup;
- }
-
- ret = sticker_dbus_insert_sticker_info(provider_handle->gdbus_connection, data_handle);
- if (ret != STICKER_ERROR_NONE) {
- LOGE("Failed to insert sticker information : %d", ret);
- if (ret == STICKER_CLIENT_ERROR_NO_SUCH_FILE)
- ret = STICKER_ERROR_NO_SUCH_FILE;
- else
- ret = STICKER_ERROR_OPERATION_FAILED;
- }
-
-cleanup:
- if (new_path) {
- free(new_path);
- new_path = NULL;
- }
-
- return ret;
-}
-
-EXPORT_API int sticker_provider_insert_data_by_json_file(sticker_provider_h provider_handle, const char *json_path, sticker_provider_insert_finished_cb callback, void *user_data)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- char *app_id = NULL;
- package_info_h package_info = NULL;
- char *app_path = NULL;
- char *file_path = NULL;
-
- if (!provider_handle || !json_path || !callback)
- 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;
- }
-
- if (access(json_path, F_OK) != 0) {
- 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(json_path) + 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(json_path[0] == '/')
- snprintf(file_path, path_len, "%s%s",app_path, json_path);
- else
- snprintf(file_path, path_len, "%s%s%s",app_path, "/", json_path);
-
- if (access(file_path, F_OK) != 0) {
- LOGE("%s does not exist", file_path);
- ret = STICKER_ERROR_INVALID_PARAMETER;
- goto cleanup;
- }
- } else
- file_path = strdup(json_path);
-
- SECURE_LOGD("json path : %s", file_path);
- ret = sticker_dbus_insert_sticker_info_by_json(provider_handle->gdbus_connection, app_id, file_path);
- if (ret != STICKER_ERROR_NONE) {
- LOGE("Failed to load json file : %d", ret);
- ret = STICKER_ERROR_OPERATION_FAILED;
- goto cleanup;
- }
-
- provider_handle->insert_finished_cb = callback;
- provider_handle->insert_finished_cb_user_data = user_data;
-
-cleanup:
- if (app_id)
- free(app_id);
-
- if (package_info)
- package_info_destroy(package_info);
-
- if (app_path)
- free(app_path);
-
- if (file_path)
- free(file_path);
-
- return ret;
-}
-
-EXPORT_API int sticker_provider_update_data(sticker_provider_h provider_handle, sticker_data_h data_handle)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- if (!provider_handle || !data_handle || (data_handle->sticker_info_id <= 0))
- return STICKER_ERROR_INVALID_PARAMETER;
-
- ret = sticker_dbus_update_sticker_info(provider_handle->gdbus_connection, data_handle);
- if (ret != STICKER_ERROR_NONE) {
- //LCOV_EXCL_START
- LOGE("Failed to update sticker information : %d", ret);
- if (ret == STICKER_CLIENT_ERROR_FILE_EXISTS)
- return STICKER_ERROR_FILE_EXISTS;
- else if (ret == STICKER_CLIENT_ERROR_NO_SUCH_FILE)
- return STICKER_ERROR_NO_SUCH_FILE;
- else
- return STICKER_ERROR_OPERATION_FAILED;
- //LCOV_EXCL_STOP
- }
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_provider_delete_data(sticker_provider_h provider_handle, sticker_data_h data_handle)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- if (!provider_handle || !data_handle || (data_handle->sticker_info_id <= 0))
- return STICKER_ERROR_INVALID_PARAMETER;
-
- ret = sticker_dbus_delete_sticker_info(provider_handle->gdbus_connection, data_handle->sticker_info_id);
- if (ret != STICKER_ERROR_NONE) {
- LOGE("Failed to delete sticker information : %d", ret);
- return STICKER_ERROR_OPERATION_FAILED;
- }
-
- return STICKER_ERROR_NONE;
-}
-
-EXPORT_API int sticker_provider_get_sticker_count(sticker_provider_h provider_handle, int *count)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- char *app_id = NULL;
-
- if (!provider_handle || !count)
- 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_get_sticker_count(provider_handle->gdbus_connection, app_id, count);
- if (ret != STICKER_ERROR_NONE) {
- LOGE("Failed to get sticker count : %d", ret);
- ret = STICKER_ERROR_OPERATION_FAILED;
- }
-
-cleanup:
- if (app_id)
- free(app_id);
-
- return ret;
-}
-
-EXPORT_API 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)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- int info_id;
- int sticker_count = 0;
- char *app_id = NULL;
- GVariantIter *id_iter = NULL;
-
- if (!provider_handle || (offset < 0) || (count <= 0) || !result || !callback)
- 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_get_sticker_info_by_appid(provider_handle->gdbus_connection, app_id, offset, count, &id_iter);
- if (ret != STICKER_ERROR_NONE) {
- LOGE("Failed to get sticker information : %d", ret);
- ret = STICKER_ERROR_OPERATION_FAILED;
- goto cleanup;
- }
-
- if (id_iter) {
- while (g_variant_iter_loop (id_iter, "(i)", &info_id)) {
- sticker_data_h sticker_data = (sticker_data_h)calloc(1, sizeof(struct sticker_data_s));
- if (!sticker_data) {
- ret = STICKER_ERROR_OUT_OF_MEMORY;
- goto cleanup;
- }
-
- ret = sticker_dbus_get_sticker_info_by_record_id(provider_handle->gdbus_connection, sticker_data, info_id);
- if (ret == STICKER_ERROR_NONE) {
- sticker_count++;
- callback(sticker_data, user_data);
- _free_sticker_data(sticker_data);
- } else {
- _free_sticker_data(sticker_data);
- goto cleanup;
- }
- }
- }
-
- *result = sticker_count;
-
-cleanup:
- if (app_id)
- free(app_id);
-
- if (id_iter)
- g_variant_iter_free(id_iter);
-
- return ret;
-}
-
-EXPORT_API int sticker_provider_delete_data_by_uri(sticker_provider_h provider_handle, const char *uri)
-{
- CHECK_STICKER_FEATURE();
-
- int ret;
- int is_exist = 0;
-
- if (!provider_handle || !uri)
- return STICKER_ERROR_INVALID_PARAMETER;
-
- ret = sticker_dbus_check_file_exists(provider_handle->gdbus_connection, uri, &is_exist);
- if (ret != STICKER_ERROR_NONE) {
- LOGE("Failed to check file exists : %d", ret);
- return STICKER_ERROR_OPERATION_FAILED;
- }
-
- if (!is_exist) {
- LOGE("Sticker does not exist");
- return STICKER_ERROR_NO_SUCH_FILE;
- }
-
- ret = sticker_dbus_delete_sticker_info_by_uri(provider_handle->gdbus_connection, uri);
- if (ret != STICKER_ERROR_NONE) {
- LOGE("Failed to delete sticker information : %d", ret);
- return STICKER_ERROR_OPERATION_FAILED;
- }
-
- return STICKER_ERROR_NONE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __TIZEN_UIX_STICKER_PROVIDER_MAIN_H__
-#define __TIZEN_UIX_STICKER_PROVIDER_MAIN_H__
-
-#include <gio/gio.h>
-#include <dbus/dbus.h>
-#include "sticker_provider.h"
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-struct sticker_provider_s {
- GDBusConnection *gdbus_connection;
- int server_watcher_id;
- int monitor_id;
- int server_monitor_id;
- sticker_provider_insert_finished_cb insert_finished_cb;
- void *insert_finished_cb_user_data;
-};
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __TIZEN_UIX_STICKER_PROVIDER_MAIN_H__ */
\ No newline at end of file
AUX_SOURCE_DIRECTORY(src SOURCES)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../common STICKER_COMMON_SOURCES)
-AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../client STICKER_CLIENT_SOURCES)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../client/src STICKER_CLIENT_SOURCES)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../consumer STICKER_CONSUMER_SOURCES)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../provider STICKER_PROVIDER_SOURCES)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/mock MOCK_SRCS)