From ab0c46b6b1cf8c36a1c38f072a52080fa993324b Mon Sep 17 00:00:00 2001 From: Jiwoong Im Date: Mon, 27 Mar 2017 18:31:36 +0900 Subject: [PATCH 01/16] Release version 0.1.1 Changes: - Set license using %license macro Change-Id: I8d29f1f56eedda36b8e146039774fcb8fb8f9a06 Signed-off-by: Jiwoong Im --- packaging/eventsystem.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/eventsystem.spec b/packaging/eventsystem.spec index 76d5262..f395496 100644 --- a/packaging/eventsystem.spec +++ b/packaging/eventsystem.spec @@ -1,6 +1,6 @@ Name: eventsystem Summary: Event system library -Version: 0.1.0 +Version: 0.1.1 Release: 1 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From b150ed52f6e1bf3c921ac42fe83092f6de339b90 Mon Sep 17 00:00:00 2001 From: jusung son Date: Tue, 10 Oct 2017 18:01:05 +0900 Subject: [PATCH 02/16] Fix memory leak Change-Id: Ib81bbeabfcd374de1e505b05d93d876686863b2c Signed-off-by: jusung son --- src/eventsystem.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) mode change 100644 => 100755 src/eventsystem.c diff --git a/src/eventsystem.c b/src/eventsystem.c old mode 100644 new mode 100755 index e51db0b..56d210c --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -851,14 +851,14 @@ static int __eventsystem_send_event(GDBusConnection *conn, eventinfo_s *evti, bu _D("object_path(%s)", evti->object_path); _D("member_name(%s)", evti->member_name); + bundle_free_encoded_rawdata(&raw); + if (ret == FALSE) { _E("Unable to connect to dbus: %s", error->message); g_error_free(error); return ES_R_ERROR; } - bundle_free_encoded_rawdata(&raw); - return ES_R_OK; } @@ -1717,7 +1717,7 @@ int eventsystem_keep_last_event_data(const char *event_name) item->param = NULL; item->trusted_param = NULL; - g_hash_table_insert(last_data_tbl, (char *)event_name, item); + g_hash_table_insert(last_data_tbl, item->event_name, item); ret = eventsystem_register_event(SYS_EVENT_REQUEST_LAST_DATA, ®_id, _send_last_user_event, NULL); @@ -1953,6 +1953,7 @@ int eventsystem_application_finalize(void) GHashTableIter iter; char *key_item; char *val_item; + struct last_data_item *last_item; _D("release all resouces"); @@ -1998,20 +1999,21 @@ int eventsystem_application_finalize(void) g_hash_table_iter_init(&iter, last_data_tbl); while (g_hash_table_iter_next(&iter, &key, &value)) { - key_item = (char *)key; - if (key_item) - free(key_item); - else - _E("last_data_tbl, val_item is NULL"); - - val_item = (char *)value; - if (val_item) - free(val_item); - else + last_item = (struct last_data_item *)value; + if (last_item) { + if (last_item->event_name) + free(last_item->event_name); + if (last_item->param) + g_variant_unref(last_item->param); + if (last_item->trusted_param) + g_variant_unref(last_item->trusted_param); + free(last_item); + } else { _E("last_data_tbl, val_item is NULL"); + } g_hash_table_iter_remove(&iter); } - g_hash_table_unref(check_tbl); + g_hash_table_unref(last_data_tbl); } FREE_AND_NULL(s_info.own_name_system_bus); -- 2.7.4 From 2bf6227565a37a7384466b00aaf2bfe72509204a Mon Sep 17 00:00:00 2001 From: jusung son Date: Wed, 11 Oct 2017 15:22:22 +0900 Subject: [PATCH 03/16] Fix wrong log format Change-Id: I95e8894d894c1b0a1e99054388c43eeafaeaa373 Signed-off-by: jusung son --- src/eventsystem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/eventsystem.c b/src/eventsystem.c index 56d210c..29480c1 100755 --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -774,7 +774,7 @@ int eventsystem_register_event(const char *event_name, unsigned int *reg_id, *reg_id = em->reg_id; ret = ES_R_OK; } else { - _E("error, ret(%d), em(%s)", ret, em); + _E("error, ret(%d), event_name(%s)", ret, event_name); } return ret; -- 2.7.4 From 276f27c11fa8a8f16b0d30b3c3ba3bd457905d3f Mon Sep 17 00:00:00 2001 From: jusung son Date: Thu, 12 Oct 2017 13:46:54 +0900 Subject: [PATCH 04/16] Release version 0.1.2 Changes: - Fix wrong log format - Fix memory leak Change-Id: I63b3168b34d619c9241fe8cb3a43cc8407ca9126 Signed-off-by: jusung son --- packaging/eventsystem.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 packaging/eventsystem.spec diff --git a/packaging/eventsystem.spec b/packaging/eventsystem.spec old mode 100644 new mode 100755 index f395496..c046442 --- a/packaging/eventsystem.spec +++ b/packaging/eventsystem.spec @@ -1,6 +1,6 @@ Name: eventsystem Summary: Event system library -Version: 0.1.1 +Version: 0.1.2 Release: 1 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 772bbc5699de4d39f18bc32f92f1c0c149b02a6b Mon Sep 17 00:00:00 2001 From: jusung son Date: Fri, 6 Jul 2018 16:39:49 +0900 Subject: [PATCH 05/16] Fix dbus proxy creation code Add G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES flag. esd does not provide object which has properties. Without this flag, g_dbus_proxy_new_sync() will try to load properties using GetAll method, and this call will be denied by default dbus policy. Change-Id: I82fa44b201ba948e348be107e1b0e14b36a38e25 Signed-off-by: jusung son --- src/eventsystem.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/eventsystem.c b/src/eventsystem.c index 29480c1..90e7e91 100755 --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -1129,7 +1129,7 @@ int eventsystem_request_sending_system_event(const char *event_name, bundle *dat } proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, NULL, &error); if (proxy == NULL) { @@ -1188,7 +1188,7 @@ static int __eventsystem_check_sender_validation(int sender_pid, const char *eve } proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, NULL, &error); if (proxy == NULL) { @@ -1244,7 +1244,7 @@ static int __eventsystem_check_user_send_validation(const char *event_name) } proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, NULL, &error); if (proxy == NULL) { @@ -1300,7 +1300,7 @@ static int __eventsystem_check_privilege_validation(const char *event_name) } proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, NULL, &error); if (proxy == NULL) { @@ -1356,7 +1356,7 @@ static int __eventsystem_setup_trusted_peer(const char *event_name, const char * } proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, NULL, &error); if (proxy == NULL) { @@ -1415,7 +1415,7 @@ static int __eventsystem_requet_destination_list(const char *event_name, GList * } proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, NULL, &error); if (proxy == NULL) { @@ -1489,7 +1489,7 @@ static int __eventsystem_request_earlier_data(const char *event_name, } proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, NULL, &error); @@ -1553,7 +1553,7 @@ static int __request_esd_for_last_data(const char *event_name, bool check) } proxy = g_dbus_proxy_new_sync(conn, - G_DBUS_PROXY_FLAGS_NONE, NULL, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, NULL, &error); -- 2.7.4 From bcf5fa318b8be128e33bac916d3ef21feedb7d91 Mon Sep 17 00:00:00 2001 From: jusung son Date: Fri, 6 Jul 2018 16:48:37 +0900 Subject: [PATCH 06/16] Release version 0.1.3 Changes: - Fix dbus proxy creation code Change-Id: Ifa796dd1b6e43726e7a6987caa4c919cf55b3ffd Signed-off-by: jusung son --- packaging/eventsystem.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/eventsystem.spec b/packaging/eventsystem.spec index c046442..349e4a0 100755 --- a/packaging/eventsystem.spec +++ b/packaging/eventsystem.spec @@ -1,6 +1,6 @@ Name: eventsystem Summary: Event system library -Version: 0.1.2 +Version: 0.1.3 Release: 1 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 79150acb1e20f0d13d7fbb16e8f6e8b04d1c4ea8 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 17 Oct 2018 13:20:36 +0900 Subject: [PATCH 07/16] Fixed a bug about finding callback function Change-Id: If81fb645267dd181e56bf2cf3a4d40f0bfcf4cf3 Signed-off-by: Hwankyu Jhun --- src/eventsystem.c | 288 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 151 insertions(+), 137 deletions(-) diff --git a/src/eventsystem.c b/src/eventsystem.c index 90e7e91..aea30f5 100755 --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -83,6 +83,7 @@ typedef struct eventmap { eventsystem_cb es_cb; eventsystem_handler ep_cb; }; + void *user_data; } eventmap_s; typedef struct eventinfo { @@ -108,14 +109,10 @@ static int __eventsystem_check_user_send_validation(const char *event_name); static int __eventsystem_requet_destination_list(const char *event_name, GList **dest_list); static int __eventsystem_check_sender_validation(int sender_pid, const char *event_name, char **sender); - -static int __event_compare_name_cb(gconstpointer a, gconstpointer b) -{ - eventmap_s *key1 = (eventmap_s *)a; - eventmap_s *key2 = (eventmap_s *)b; - return strcmp(key1->interface_name, key2->interface_name) | - strcmp(key1->member_name, key2->member_name); -} +static eventmap_s *__create_eventmap(const char *interface_name, + const char *member_name, const char *event_name, + int event_type, eventsystem_cb callback, void *user_data); +static void __destroy_eventmap(gpointer data); static int __event_compare_reg_id_cb(gconstpointer a, gconstpointer b) { @@ -468,19 +465,20 @@ static void __eventsystem_event_handler(GDBusConnection *connection, GVariant *parameters, gpointer user_data) { int len; - eventmap_s em; + eventmap_s *em = (eventmap_s *)user_data; GList *cb_list = NULL; bundle *buf = NULL; bundle_raw *raw = NULL; - em.interface_name = (char *)interface_name; - em.member_name = (char *)signal_name; + if (!em) { + _E("Critical error!"); + return; + } _D("sender_name(%s), interface_name(%s), signal_name(%s)", sender_name, interface_name, signal_name); - cb_list = g_list_find_custom(system_event_list, &em, - (GCompareFunc)__event_compare_name_cb); + cb_list = g_list_find(system_event_list, em); if (cb_list == NULL) return; @@ -488,10 +486,8 @@ static void __eventsystem_event_handler(GDBusConnection *connection, buf = bundle_decode((bundle_raw *)raw, len); - em.event_name = ((eventmap_s *)cb_list->data)->event_name; - em.ep_cb = ((eventmap_s *)cb_list->data)->ep_cb; - if (em.ep_cb) - em.ep_cb(em.event_name, buf, user_data); + if (em->ep_cb) + em->ep_cb(em->event_name, buf, em->user_data); bundle_free_encoded_rawdata(&raw); bundle_free(buf); @@ -501,36 +497,33 @@ static void __eventsystem_application_event_handler(int sender_pid, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data) { - GList *cb_list = NULL; - eventmap_s em; + GList *cb_list; + eventmap_s *em = (eventmap_s *)user_data; bundle_raw *raw = NULL; int len; - em.interface_name = (char *)interface_name; - em.member_name = (char *)signal_name; - - cb_list = g_list_find_custom(system_event_list, &em, - (GCompareFunc)__event_compare_name_cb); + if (!em) { + _E("Critical error!"); + return; + } + cb_list = g_list_find(system_event_list, em); if (cb_list == NULL) { _E("not interested event"); return; } - em.event_name = ((eventmap_s *)cb_list->data)->event_name; - if (sender_pid > 0 && __check_interface_validation_user((char *)interface_name)) { if (__check_validation_usrevent_sender(sender_pid, - (const char *)interface_name, em.event_name) < 0) { + (const char *)interface_name, em->event_name) < 0) { _E("invalid sender"); return; } } g_variant_get(parameters, "(us)", &len, &raw); - em.es_cb = ((eventmap_s *)cb_list->data)->es_cb; - if (em.es_cb) - em.es_cb(em.event_name, raw, len, user_data); + if (em->es_cb) + em->es_cb(em->event_name, raw, len, em->user_data); bundle_free_encoded_rawdata(&raw); } @@ -612,10 +605,10 @@ static void __eventsystem_filter_sysevent_for_internal(GDBusConnection *connecti static int __eventsystem_register_event_internal(const char *event_name, eventmap_s **em_s, void *user_data) { - eventmap_s *em = NULL; - char *interface_name = NULL; - char *object_path = NULL; - char *member_name = NULL; + eventmap_s *em; + char *interface_name; + char *object_path; + char *member_name; char *sender_name = NULL; GDBusSignalCallback filter; GBusType bus_type; @@ -691,6 +684,13 @@ static int __eventsystem_register_event_internal(const char *event_name, goto out_4; } + em = __create_eventmap(interface_name, member_name, event_name, + evt_type, NULL, user_data); + if (!em) { + ret = ES_R_ENOMEM; + goto out_4; + } + subscription_id = g_dbus_connection_signal_subscribe(conn, sender_name, /* sender */ interface_name, @@ -699,7 +699,7 @@ static int __eventsystem_register_event_internal(const char *event_name, NULL, /* arg0 */ G_DBUS_SIGNAL_FLAGS_NONE, filter, - user_data, + em, NULL); /* user_data_free_func */ _D("event_name(%s), interface_name(%s)", event_name, interface_name); @@ -707,33 +707,14 @@ static int __eventsystem_register_event_internal(const char *event_name, member_name, subscription_id, bus_type); if (subscription_id != 0) { - em = calloc(1, sizeof(eventmap_s)); - if (!em) { - _E("memory alloc failed"); - ret = ES_R_ENOMEM; - } else { - em->interface_name = strdup(interface_name); - em->member_name = strdup(member_name); - em->event_name = strdup(event_name); - em->bus_type = bus_type; - em->reg_id = subscription_id; - em->event_type = evt_type; - - if (!em->interface_name || !em->member_name || !em->event_name) { - _E("out_of_memory"); - FREE_AND_NULL(em->interface_name); - FREE_AND_NULL(em->member_name); - FREE_AND_NULL(em->event_name); - FREE_AND_NULL(em); - ret = ES_R_ENOMEM; - goto out_4; - } + em->bus_type = bus_type; + em->reg_id = subscription_id; - *em_s = em; - ret = ES_R_OK; - } + *em_s = em; + ret = ES_R_OK; } else { _D("dbus subscribe: error(%d), event(%s)", subscription_id, event_name); + __destroy_eventmap(em); ret = ES_R_ERROR; } @@ -816,10 +797,7 @@ int eventsystem_unregister_event(unsigned int reg_id) system_event_list = g_list_remove(system_event_list, cb_list->data); - FREE_AND_NULL(em_data->interface_name); - FREE_AND_NULL(em_data->member_name); - FREE_AND_NULL(em_data->event_name); - FREE_AND_NULL(em_data); + __destroy_eventmap(em_data); g_object_unref(conn); } @@ -1725,17 +1703,73 @@ int eventsystem_keep_last_event_data(const char *event_name) return ret; } +static void __destroy_eventmap(gpointer data) +{ + eventmap_s *em = (eventmap_s *)data; + + if (!em) + return; + + if (em->interface_name) + free(em->interface_name); + if (em->member_name) + free(em->member_name); + if (em->event_name) + free(em->event_name); + free(em); +} + +static eventmap_s *__create_eventmap(const char *interface_name, + const char *member_name, const char *event_name, + int event_type, eventsystem_cb callback, void *user_data) +{ + eventmap_s *em; + + em = calloc(1, sizeof(eventmap_s)); + if (!em) { + _E("Out of memory"); + return NULL; + } + + em->interface_name = strdup(interface_name); + if (!em->interface_name) { + _E("Failed to duplicate interface name"); + __destroy_eventmap(em); + return NULL; + } + + em->member_name = strdup(member_name); + if (!em->member_name) { + _E("Failed to duplicate member name"); + __destroy_eventmap(em); + return NULL; + } + + em->event_name = strdup(event_name); + if (!em->event_name) { + _E("Failed to duplicate event name"); + __destroy_eventmap(em); + return NULL; + } + + em->event_type = event_type; + em->es_cb = callback; + em->user_data = user_data; + + return em; +} + int eventsystem_register_application_event(const char *event_name, unsigned int *reg_id, int *event_type, eventsystem_cb callback, void *user_data) { eventmap_s *em; - char *interface_name = NULL; - char *object_path = NULL; - char *member_name = NULL; + char *interface_name; + char *object_path; + char *member_name; char *sender_name = NULL; GDBusSignalCallback filter; GBusType bus_type; - guint subscription_id = 0; + guint subscription_id = 0; int ret = 0; GDBusConnection *conn = NULL; @@ -1805,9 +1839,8 @@ int eventsystem_register_application_event(const char *event_name, unsigned int object_path = __get_object_path(interface_name); if (!object_path) { _E("failed get object_path"); - FREE_AND_NULL(interface_name); - FREE_AND_NULL(member_name); - return ES_R_ERROR; + ret = ES_R_ERROR; + goto end; } sender_name = NULL; @@ -1817,16 +1850,21 @@ int eventsystem_register_application_event(const char *event_name, unsigned int if (__get_gdbus_shared_connection(&conn, bus_type, *event_type) < 0) { _E("getting gdbus-connetion error"); - FREE_AND_NULL(interface_name); - FREE_AND_NULL(object_path); - FREE_AND_NULL(member_name); - return ES_R_ERROR; + ret = ES_R_ERROR; + goto end; } #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE __eventsystem_request_earlier_data(event_name, callback, user_data); #endif + em = __create_eventmap(interface_name, member_name, event_name, + *event_type, callback, user_data); + if (!em) { + ret = ES_R_ENOMEM; + goto end; + } + subscription_id = g_dbus_connection_signal_subscribe(conn, sender_name, /* sender */ interface_name, @@ -1835,77 +1873,56 @@ int eventsystem_register_application_event(const char *event_name, unsigned int NULL, /* arg0 */ G_DBUS_SIGNAL_FLAGS_NONE, filter, - user_data, + em, NULL); /* user_data_free_func */ _D("event_name(%s), subscription_id(%d)", event_name, subscription_id); if (subscription_id != 0) { - em = calloc(1, sizeof(eventmap_s)); - if (!em) { - _E("memory alloc failed"); - ret = ES_R_ENOMEM; - } else { - em->interface_name = strdup(interface_name); - em->member_name = strdup(member_name); - em->event_name = strdup(event_name); - em->es_cb = callback; - em->bus_type = bus_type; - em->reg_id = subscription_id; - em->event_type = *event_type; - - if (!em->interface_name || !em->member_name || - !em->event_name) { - _E("out_of_memory"); - FREE_AND_NULL(em->interface_name); - FREE_AND_NULL(em->member_name); - FREE_AND_NULL(em->event_name); - FREE_AND_NULL(em); - ret = ES_R_ENOMEM; + em->bus_type = bus_type; + em->reg_id = subscription_id; + + system_event_list = g_list_append(system_event_list, em); + *reg_id = subscription_id; + + ret = ES_R_OK; + + if (em->bus_type == G_BUS_TYPE_SESSION && + em->event_type == ES_TYPE_USER) { + if (s_info.own_name_session_bus == NULL) { + _E("session bus is not ready"); + ret = ES_R_ERROR; } else { - system_event_list = - g_list_append(system_event_list, em); - *reg_id = subscription_id; - - ret = ES_R_OK; - - if (em->bus_type == G_BUS_TYPE_SESSION && - em->event_type == ES_TYPE_USER) { - if (s_info.own_name_session_bus == NULL) { - _E("session bus is not ready"); - ret = ES_R_ERROR; - } else { - if (__eventsystem_setup_trusted_peer(event_name, + if (__eventsystem_setup_trusted_peer(event_name, s_info.own_name_session_bus) < 0) { - _E("failed to setup trusted peer"); - ret = ES_R_ERROR; - } - } + _E("failed to setup trusted peer"); + ret = ES_R_ERROR; } } } } else { _E("dbus subscribe: error(%d)", subscription_id); + __destroy_eventmap(em); ret = ES_R_ERROR; } + __request_esd_for_last_data(event_name, true); +end: FREE_AND_NULL(interface_name); FREE_AND_NULL(object_path); FREE_AND_NULL(member_name); if (conn) g_object_unref(conn); - __request_esd_for_last_data(event_name, true); - return ret; } int eventsystem_unregister_application_event(unsigned int reg_id) { eventmap_s em; - eventmap_s *em_data = NULL; + eventmap_s *em_data; GBusType bus_type; - GList *cb_list = NULL; + GList *cb_list; GDBusConnection *conn = NULL; eventsystem_event_type evt_type; @@ -1916,32 +1933,29 @@ int eventsystem_unregister_application_event(unsigned int reg_id) em.reg_id = reg_id; cb_list = g_list_find_custom(system_event_list, &em, - (GCompareFunc)__event_compare_reg_id_cb); - if (cb_list) { - em_data = (eventmap_s *)cb_list->data; + (GCompareFunc)__event_compare_reg_id_cb); + if (!cb_list) { + _E("not found matched item"); + return ES_R_ERROR; + } - bus_type = em_data->bus_type; - evt_type = em_data->event_type; + em_data = (eventmap_s *)cb_list->data; - _D("unsubscribe: reg_id(%d), bus_type(%d)", reg_id, bus_type); + bus_type = em_data->bus_type; + evt_type = em_data->event_type; - if (__get_gdbus_shared_connection(&conn, bus_type, evt_type) < 0) { - _E("getting gdbus-connetion error"); - return ES_R_ERROR; - } - g_dbus_connection_signal_unsubscribe(conn, reg_id); + _D("unsubscribe: reg_id(%d), bus_type(%d)", reg_id, bus_type); - system_event_list = g_list_remove(system_event_list, cb_list->data); - - FREE_AND_NULL(em_data->interface_name); - FREE_AND_NULL(em_data->member_name); - FREE_AND_NULL(em_data->event_name); - FREE_AND_NULL(em_data); - g_object_unref(conn); - } else { - _E("not found matched item"); + if (__get_gdbus_shared_connection(&conn, bus_type, evt_type) < 0) { + _E("getting gdbus-connetion error"); return ES_R_ERROR; } + g_dbus_connection_signal_unsubscribe(conn, reg_id); + + system_event_list = g_list_remove(system_event_list, cb_list->data); + + __destroy_eventmap(em_data); + g_object_unref(conn); return ES_R_OK; } -- 2.7.4 From 2aae648148a6c32300d9709deb24e5ca26544dd1 Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 17 Oct 2018 15:46:57 +0900 Subject: [PATCH 08/16] Release version 0.1.4 Changes: - Fixed a bug about finding callback function Change-Id: Idae3e93d4a170c6fa2266ca8809b8359831fa04f Signed-off-by: Hwankyu Jhun --- packaging/eventsystem.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/eventsystem.spec b/packaging/eventsystem.spec index 349e4a0..96962d0 100755 --- a/packaging/eventsystem.spec +++ b/packaging/eventsystem.spec @@ -1,6 +1,6 @@ Name: eventsystem Summary: Event system library -Version: 0.1.3 +Version: 0.1.4 Release: 1 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From fc572e111cef665bb39a9c335033ed486792b666 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Thu, 24 Jan 2019 09:10:22 +0900 Subject: [PATCH 09/16] Support launch_on_event with user event Change-Id: I586a79c2389ddace9d2c0ffaf80f4fcadd1313bc Signed-off-by: Inkyun Kil Signed-off-by: jusung son --- include/eventsystem_internal.h | 1 + src/eventsystem.c | 134 ++++++++++++++++++++++++++++++++--------- 2 files changed, 105 insertions(+), 30 deletions(-) mode change 100755 => 100644 src/eventsystem.c diff --git a/include/eventsystem_internal.h b/include/eventsystem_internal.h index ccbc2de..044f06d 100644 --- a/include/eventsystem_internal.h +++ b/include/eventsystem_internal.h @@ -26,6 +26,7 @@ extern "C" { #define ESD_INTERFACE_NAME "tizen.system.event.app2esd" #define USER_EVENT_NAME_PREFIX "event." +#define SYSTEM_EVENT_NAME_PREFIX "event://" /** * system-event definitions diff --git a/src/eventsystem.c b/src/eventsystem.c old mode 100755 new mode 100644 index aea30f5..587ef35 --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -106,13 +106,15 @@ typedef struct sysevent_info { static sysevent_info_s s_info; static int __eventsystem_check_user_send_validation(const char *event_name); -static int __eventsystem_requet_destination_list(const char *event_name, GList **dest_list); +static int __eventsystem_request_destination_list(const char *event_name, GList **dest_list); static int __eventsystem_check_sender_validation(int sender_pid, const char *event_name, char **sender); static eventmap_s *__create_eventmap(const char *interface_name, const char *member_name, const char *event_name, int event_type, eventsystem_cb callback, void *user_data); static void __destroy_eventmap(gpointer data); +static int __eventsystem_launch_on_event_for_userevent(const char *event_name, + bundle *data, const bool trusted); static int __event_compare_reg_id_cb(gconstpointer a, gconstpointer b) { @@ -871,7 +873,6 @@ static int __eventsystem_send_trusted_event(GDBusConnection *conn, eventinfo_s * } tmp_list = g_list_next(tmp_list); } - g_list_free_full(dest_list, __eventsystem_free_trusted_list); } else { _E("dest_list is null"); } @@ -884,11 +885,13 @@ static int __eventsystem_send_trusted_event(GDBusConnection *conn, eventinfo_s * */ int eventsystem_send_user_event(const char *event_name, bundle *data, bool is_trusted) { - int ret = 0; + int ret = ES_R_OK; eventinfo_s *evti = NULL; struct last_data_item *item; bundle_raw *raw = NULL; int len; + GDBusConnection *conn = NULL; + GList *trusted_dest_list = NULL; /* check validation */ retvm_if(!event_name, ES_R_EINVAL, "Invalid argument : event_name is NULL"); @@ -910,53 +913,38 @@ int eventsystem_send_user_event(const char *event_name, bundle *data, bool is_tr if (!evti->event_name) { _E("memory alloc failed"); ret = ES_R_ENOMEM; - goto out_1; + goto out; } evti->interface_name = __get_encoded_interface_name(evti->event_name); if (!evti->interface_name) { _E("interface_name is NULL"); ret = ES_R_ERROR; - goto out_2; + goto out; } evti->member_name = strdup(EVENT_SYSTEM_MEMBER); if (!evti->member_name) { _E("memory alloc failed"); ret = ES_R_ENOMEM; - goto out_3; + goto out; } evti->object_path = __get_object_path(evti->interface_name); if (!evti->object_path) { _E("object_path is NULL"); ret = ES_R_ERROR; - goto out_4; + goto out; } evti->destination_name = NULL; evti->is_user_event = true; evti->is_trusted = is_trusted; - GDBusConnection *conn = NULL; if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SESSION, ES_TYPE_USER) == ES_R_OK) { - if (is_trusted) { - GList *dest_list = NULL; - ret = __eventsystem_requet_destination_list(evti->event_name, &dest_list); - if (ret < 0) { - _E("failed to get dest list"); - ret = ES_R_ERROR; - } else { - ret = __eventsystem_send_trusted_event(conn, evti, - data, dest_list); - } - } else { - ret = __eventsystem_send_event(conn, evti, data); - } - if (bundle_encode(data, &raw, &len)) { _E("Unable to encode bundle"); ret = ES_R_ERROR; - goto out_5; + goto out; } item = (struct last_data_item *)g_hash_table_lookup(last_data_tbl, @@ -973,23 +961,45 @@ int eventsystem_send_user_event(const char *event_name, bundle *data, bool is_tr } bundle_free_encoded_rawdata(&raw); + + if (is_trusted) { + if (__eventsystem_request_destination_list(evti->event_name, &trusted_dest_list) < 0) { + _E("failed to get dest list"); + ret = ES_R_ERROR; + goto out; + } + if (__eventsystem_send_trusted_event(conn, evti, data, trusted_dest_list) < 0) { + _E("failed to send trusted event"); + ret = ES_R_ERROR; + goto out; + } + + if (__eventsystem_launch_on_event_for_userevent(evti->event_name, data, true) < 0) + _E("Failed to launch on event for userevent"); + } else { + if (__eventsystem_send_event(conn, evti, data) < 0) { + _E("failed to send event"); + ret = ES_R_ERROR; + goto out; + } + + if (__eventsystem_launch_on_event_for_userevent(evti->event_name, data, false) < 0) + _E("Failed to launch on event for userevent"); + } } else { _E("getting gdbus-connetion error"); ret = ES_R_ERROR; } +out: if (conn) g_object_unref(conn); - -out_5: + if (trusted_dest_list) + g_list_free_full(trusted_dest_list, __eventsystem_free_trusted_list); FREE_AND_NULL(evti->object_path); -out_4: FREE_AND_NULL(evti->member_name); -out_3: FREE_AND_NULL(evti->interface_name); -out_2: FREE_AND_NULL(evti->event_name); -out_1: FREE_AND_NULL(evti); return ret; @@ -1370,7 +1380,7 @@ out_1: return ret; } -static int __eventsystem_requet_destination_list(const char *event_name, GList **dest_list) +static int __eventsystem_request_destination_list(const char *event_name, GList **dest_list) { int ret = ES_R_ERROR; GDBusConnection *conn = NULL; @@ -1572,6 +1582,70 @@ out_1: return ret; } +static int __eventsystem_launch_on_event_for_userevent(const char *event_name, + bundle *data, const bool trusted) +{ + int ret = ES_R_EINVAL; + GDBusConnection *conn = NULL; + GError *error = NULL; + GDBusProxy *proxy = NULL; + GVariant *param = NULL; + GVariant *value = NULL; + gint result = 0; + bundle_raw *raw = NULL; + bundle *buf = data; + int len; + + if (!_initialized) + __initialize(); + + if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) < 0) { + _E("getting gdbus-connetion error"); + ret = ES_R_ERROR; + goto out_1; + } + + proxy = g_dbus_proxy_new_sync(conn, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, + ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME, + NULL, &error); + if (proxy == NULL) { + _E("failed to create new proxy, error(%s)", error->message); + g_error_free(error); + ret = ES_R_ERROR; + goto out_1; + } + + bundle_encode(buf, &raw, &len); + + param = g_variant_new("(ssib)", event_name, raw, len, trusted); + value = g_dbus_proxy_call_sync(proxy, "LaunchOnEventFromUserEvent", param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error != NULL) { + _E("proxy call sync error(%s)", error->message); + g_error_free(error); + ret = ES_R_ERROR; + goto out_2; + } + + _D("Launch on event from user event (%s)", event_name); + + g_variant_get(value, "(i)", &result); + + _D("result(%d)", result); + + ret = result; + +out_2: + bundle_free_encoded_rawdata(&raw); + g_object_unref(proxy); + g_variant_unref(value); +out_1: + if (conn) + g_object_unref(conn); +} + + static void _send_last_user_event(const char *event_name, bundle *data, void *user_data) { -- 2.7.4 From 9832dc3864d4e15894b070696517b59a6e8820b3 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Wed, 15 May 2019 18:25:36 +0200 Subject: [PATCH 10/16] Remove unnecessary openssl dependency Change-Id: Idcc32c23266e33831bb1d61623af81ea0a0abca0 --- CMakeLists.txt | 2 +- eventsystem.pc.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a43a4b..da3d498 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src) ### Required packages INCLUDE(FindPkgConfig) -pkg_check_modules(libpkgs REQUIRED dlog bundle openssl glib-2.0 capi-base-common) +pkg_check_modules(libpkgs REQUIRED dlog bundle glib-2.0 capi-base-common) #FIND_LIBRARY(LIB_DL dl) diff --git a/eventsystem.pc.in b/eventsystem.pc.in index 85881d4..5cc84bc 100644 --- a/eventsystem.pc.in +++ b/eventsystem.pc.in @@ -8,6 +8,6 @@ includedir=${prefix}/include Name: libeventsystem Description: event system library Version: @VERSION@ -Requires: bundle openssl glib-2.0 gio-2.0 +Requires: bundle glib-2.0 gio-2.0 Libs: -L${libdir} -leventsystem Cflags: -I${includedir} -- 2.7.4 From 65f10ab32c35be8ddcbcc9022e657f0a2996b86a Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Fri, 5 Jul 2019 08:54:25 +0900 Subject: [PATCH 11/16] Release version 0.1.5 Changes: - Remove unnecessary openssl dependency - Support launch_on_event with user event Change-Id: I97bcabb572060003a60c7a09d9f7407bbe6258b5 Signed-off-by: Inkyun Kil --- packaging/eventsystem.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/eventsystem.spec b/packaging/eventsystem.spec index 96962d0..f9c4360 100755 --- a/packaging/eventsystem.spec +++ b/packaging/eventsystem.spec @@ -1,6 +1,6 @@ Name: eventsystem Summary: Event system library -Version: 0.1.4 +Version: 0.1.5 Release: 1 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 775c7918b4974410e3cf82d0c59399931b728a34 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Thu, 11 Jul 2019 11:13:01 +0900 Subject: [PATCH 12/16] Unsubscribing signal when registration fails Change-Id: Ifdbb9d641d634e4517c1fcaa5d059eada86ae6be Signed-off-by: Inkyun Kil --- src/eventsystem.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/eventsystem.c b/src/eventsystem.c index 587ef35..3f80264 100644 --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -1966,11 +1966,15 @@ int eventsystem_register_application_event(const char *event_name, unsigned int if (s_info.own_name_session_bus == NULL) { _E("session bus is not ready"); ret = ES_R_ERROR; + g_dbus_connection_signal_unsubscribe(conn, subscription_id); + __destroy_eventmap(em); } else { if (__eventsystem_setup_trusted_peer(event_name, s_info.own_name_session_bus) < 0) { _E("failed to setup trusted peer"); ret = ES_R_ERROR; + g_dbus_connection_signal_unsubscribe(conn, subscription_id); + __destroy_eventmap(em); } } } -- 2.7.4 From d4bf4b3257261aa68cd5d1f30d3f724f67c0ada1 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Tue, 16 Jul 2019 09:05:42 +0900 Subject: [PATCH 13/16] Release version 0.1.6 Changes: - Unsubscribing signal when registration fails Change-Id: Ifddd088a5feabc4305288e49c281cc32c7d43e69 Signed-off-by: Inkyun Kil --- packaging/eventsystem.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/eventsystem.spec b/packaging/eventsystem.spec index f9c4360..8dd7ab5 100755 --- a/packaging/eventsystem.spec +++ b/packaging/eventsystem.spec @@ -1,6 +1,6 @@ Name: eventsystem Summary: Event system library -Version: 0.1.5 +Version: 0.1.6 Release: 1 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 7120c0e282cd9e1ce9b976caa1a2c195cbe6e377 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Thu, 8 Aug 2019 09:11:00 +0900 Subject: [PATCH 14/16] Fix stack overflow gboolean is different from bool Change-Id: I352572d00b1ea68fa86f775b0b471ae6c23ad828 Signed-off-by: Inkyun Kil --- src/eventsystem.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/eventsystem.c b/src/eventsystem.c index 3f80264..b678c79 100644 --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -114,7 +114,7 @@ static eventmap_s *__create_eventmap(const char *interface_name, int event_type, eventsystem_cb callback, void *user_data); static void __destroy_eventmap(gpointer data); static int __eventsystem_launch_on_event_for_userevent(const char *event_name, - bundle *data, const bool trusted); + bundle *data, gboolean trusted); static int __event_compare_reg_id_cb(gconstpointer a, gconstpointer b) { @@ -974,7 +974,7 @@ int eventsystem_send_user_event(const char *event_name, bundle *data, bool is_tr goto out; } - if (__eventsystem_launch_on_event_for_userevent(evti->event_name, data, true) < 0) + if (__eventsystem_launch_on_event_for_userevent(evti->event_name, data, TRUE) < 0) _E("Failed to launch on event for userevent"); } else { if (__eventsystem_send_event(conn, evti, data) < 0) { @@ -983,7 +983,7 @@ int eventsystem_send_user_event(const char *event_name, bundle *data, bool is_tr goto out; } - if (__eventsystem_launch_on_event_for_userevent(evti->event_name, data, false) < 0) + if (__eventsystem_launch_on_event_for_userevent(evti->event_name, data, FALSE) < 0) _E("Failed to launch on event for userevent"); } } else { @@ -1583,7 +1583,7 @@ out_1: } static int __eventsystem_launch_on_event_for_userevent(const char *event_name, - bundle *data, const bool trusted) + bundle *data, gboolean trusted) { int ret = ES_R_EINVAL; GDBusConnection *conn = NULL; -- 2.7.4 From dca96ac699140b262f7b5149c87efffc18f591e3 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Thu, 8 Aug 2019 09:48:04 +0900 Subject: [PATCH 15/16] Release version 0.1.7 Changes: - Fix stack overflow Change-Id: I62fb573b3daa4f1417d45807723283c0d66a1adf Signed-off-by: Inkyun Kil --- packaging/eventsystem.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/eventsystem.spec b/packaging/eventsystem.spec index 8dd7ab5..84ec09d 100755 --- a/packaging/eventsystem.spec +++ b/packaging/eventsystem.spec @@ -1,6 +1,6 @@ Name: eventsystem Summary: Event system library -Version: 0.1.6 +Version: 0.1.7 Release: 1 Group: Application Framework/Libraries License: Apache-2.0 -- 2.7.4 From 839cdcbef9e5aaa54c54a76cfdfc89c241f650b7 Mon Sep 17 00:00:00 2001 From: Jusung Son Date: Fri, 30 Aug 2019 11:16:55 +0900 Subject: [PATCH 16/16] Add missing return Change-Id: I2bd5612f38a4be7348c2455e1b61307ef85452e1 Signed-off-by: Jusung Son --- src/eventsystem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/eventsystem.c b/src/eventsystem.c index b678c79..c9239af 100644 --- a/src/eventsystem.c +++ b/src/eventsystem.c @@ -1643,6 +1643,8 @@ out_2: out_1: if (conn) g_object_unref(conn); + + return ret; } -- 2.7.4