2 * event system low-level API
9 #include <bundle_internal.h>
12 #include <eventsystem.h>
16 #define LOG_TAG "eventsystem"
18 #define SYS_EVENT_NAME_PREFIX "tizen.system.event"
19 #define EVENT_SYSTEM_PREFIX "eventsystem.id_"
20 #define EVENT_SYSTEM_PREFIX_LEN 15
21 #define EVENT_SYSTEM_MEMBER "eventsystem"
22 #define VALID_COUNT_OF_EVENTNAME_TOKEN 3
23 #define VALID_LAST_COUNT_FOR_EVENTNAME (VALID_COUNT_OF_EVENTNAME_TOKEN + 1)
24 #define MAX_COUNT_FOR_EVENTNAME_CHECK (VALID_LAST_COUNT_FOR_EVENTNAME + 1)
26 #define FREE_AND_NULL(ptr) do { \
33 #define _E(fmt, arg...) LOGE(fmt, ##arg)
34 #define _D(fmt, arg...) LOGD(fmt, ##arg)
35 #define _W(fmt, arg...) LOGW(fmt, ##arg)
36 #define _I(fmt, arg...) LOGI(fmt, ##arg)
38 #define retvm_if(expr, val, fmt, arg...) do { \
41 _E("(%s) -> %s() return", #expr, __func__); \
46 #define retv_if(expr, val) do { \
48 _E("(%s) -> %s() return", #expr, __func__); \
53 #define tryvm_if(expr, val, fmt, arg...) do { \
55 _E("(%s) "fmt, #expr, ##arg); \
61 pthread_mutex_t send_sync_lock = PTHREAD_MUTEX_INITIALIZER;
63 static GList *system_event_list;
64 static int _initialized;
65 static GHashTable *check_tbl;
66 static GHashTable *filter_tbl;
67 static GHashTable *last_data_tbl;
69 struct last_data_item {
72 GVariant *trusted_param;
75 typedef struct eventmap {
84 eventsystem_handler ep_cb;
88 typedef struct eventinfo {
90 char *destination_name;
99 typedef struct sysevent_info {
101 guint owner_id_session;
102 char *own_name_system_bus;
103 char *own_name_session_bus;
105 static sysevent_info_s s_info;
107 static int __eventsystem_check_user_send_validation(const char *event_name);
108 static int __eventsystem_requet_destination_list(const char *event_name, GList **dest_list);
109 static int __eventsystem_check_sender_validation(int sender_pid,
110 const char *event_name, char **sender);
112 static int __event_compare_name_cb(gconstpointer a, gconstpointer b)
114 eventmap_s *key1 = (eventmap_s *)a;
115 eventmap_s *key2 = (eventmap_s *)b;
116 return strcmp(key1->interface_name, key2->interface_name) |
117 strcmp(key1->member_name, key2->member_name);
120 static int __event_compare_reg_id_cb(gconstpointer a, gconstpointer b)
122 eventmap_s *key1 = (eventmap_s *)a;
123 eventmap_s *key2 = (eventmap_s *)b;
124 return !(key1->reg_id == key2->reg_id);
127 static void __initialize(void)
129 #if (GLIB_MAJOR_VERSION <= 2 && GLIB_MINOR_VERSION < 36)
136 static int __eventsystem_get_sender_pid(GDBusConnection *conn, const char *sender_name)
138 GDBusMessage *msg = NULL;
139 GDBusMessage *reply = NULL;
144 msg = g_dbus_message_new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus",
145 "org.freedesktop.DBus", "GetConnectionUnixProcessID");
147 _E("Can't allocate new method call");
151 g_dbus_message_set_body(msg, g_variant_new("(s)", sender_name));
152 reply = g_dbus_connection_send_message_with_reply_sync(conn, msg,
153 G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
157 _E("Failed to get pid [%s]", err->message);
163 body = g_dbus_message_get_body(reply);
164 g_variant_get(body, "(u)", &pid);
170 g_object_unref(reply);
175 static char *__get_object_path(char *interface_name)
178 char *object_path = (char *)calloc(strlen(interface_name), sizeof(char) + 2);
180 if (object_path == NULL) {
181 _E("failed to allocate memory");
185 object_path[0] = '/';
187 for (i = 0; interface_name[i]; i++) {
188 if (interface_name[i] == '.')
189 object_path[i + 1] = '/';
191 object_path[i + 1] = interface_name[i];
197 static char *__get_encoded_interface_name(char *interface_name)
201 gchar *encoded_value;
203 encoded_value = g_compute_checksum_for_string(G_CHECKSUM_MD5,
204 interface_name, strlen(interface_name));
206 evtid_len = EVENT_SYSTEM_PREFIX_LEN + strlen(encoded_value) + 1;
208 evtid = (char *)calloc(evtid_len, sizeof(char));
210 _D("memory alloc failed");
211 g_free(encoded_value);
215 snprintf(evtid, evtid_len, "%s%s", EVENT_SYSTEM_PREFIX, (char *)encoded_value);
217 g_free(encoded_value);
222 static char *__get_member_name_from_eventname(char *event_name)
225 char *ptr_last = NULL;
226 char *temp_name = NULL;
227 char *member_name = NULL;
228 char *save_ptr = NULL;
231 temp_name = strdup(event_name);
232 if (temp_name == NULL) {
237 ptr = strtok_r(temp_name, ".", &save_ptr);
239 _E("invalid event_name(%s), count(%d)", event_name, count);
240 FREE_AND_NULL(temp_name);
245 while (count < MAX_COUNT_FOR_EVENTNAME_CHECK) {
246 ptr = strtok_r(NULL, ".", &save_ptr);
249 /* _D("(%d)ptr(%s)(%d)", count, ptr, strlen(ptr)); */
254 if (count != VALID_LAST_COUNT_FOR_EVENTNAME) {
255 _E("invalid event_name(%s), count(%d)", event_name, count);
256 FREE_AND_NULL(temp_name);
261 /* _D("new member_name(%s)(%d)", ptr_last, strlen(ptr_last)); */
262 member_name = strdup(ptr_last);
265 FREE_AND_NULL(temp_name);
269 _E("ptr_last is NULL");
270 FREE_AND_NULL(temp_name);
274 _D("member_name(%s)", member_name);
276 FREE_AND_NULL(temp_name);
280 static int __check_validation_usrevent_sender(int sender_pid,
281 const char *interface_name, const char *event_name)
283 char *sender_id = NULL;
287 if (__eventsystem_check_sender_validation(sender_pid,
288 event_name, &sender_id) < 0) {
289 _E("invalid user-event sender");
293 if (sender_id == NULL) {
294 _E("sender_id is null");
298 key = strdup(interface_name);
305 val = strdup(sender_id);
313 g_hash_table_insert(filter_tbl, key, val);
319 static int __check_validation_user_defined_name(const char *event_name)
321 char *event_id = NULL;
325 if (check_tbl == NULL)
326 check_tbl = g_hash_table_new(g_str_hash, g_str_equal);
328 event_id = (char *)g_hash_table_lookup(check_tbl, event_name);
329 if (event_id == NULL) {
330 if (__eventsystem_check_user_send_validation(event_name) < 0) {
331 _E("invalid user-event name");
334 key = strdup(event_name);
339 g_hash_table_insert(check_tbl, key, key);
347 static int __check_interface_validation_user(char *interface_name)
349 int len = strlen(EVENT_SYSTEM_PREFIX);
351 if (strncmp(interface_name, EVENT_SYSTEM_PREFIX, len) != 0)
357 static int __check_eventname_validation_user(char *event_name)
359 int len = strlen(USER_EVENT_NAME_PREFIX);
361 if (strncmp(event_name, USER_EVENT_NAME_PREFIX, len) != 0)
367 static int __check_eventname_validation_system(char *event_name)
369 int len = strlen(SYS_EVENT_NAME_PREFIX);
371 if (strncmp(event_name, SYS_EVENT_NAME_PREFIX, len) != 0)
377 static int __get_gdbus_shared_connection(GDBusConnection **connection, GBusType bus_type,
378 eventsystem_event_type event_type)
380 GError *error = NULL;
383 char own_name[128] = {0, };
384 GDBusConnection *conn_system = NULL;
389 *connection = g_bus_get_sync(bus_type, NULL, &error);
390 if (*connection == NULL) {
392 _E("Failed to get dbus [%s], bus_type [%d]",
393 error->message, bus_type);
399 if (((bus_type == G_BUS_TYPE_SYSTEM && !s_info.owner_id) ||
400 (bus_type == G_BUS_TYPE_SESSION && !s_info.owner_id_session))) {
401 guid = g_dbus_generate_guid();
403 _E("failed to get guid");
406 snprintf(own_name, 128, "%s.%s.id%s_%d_%d", "event.busname",
407 (bus_type == G_BUS_TYPE_SESSION ? "session" : "system"),
408 guid, getuid(), getpid());
411 _D("bus_name is [%s]", own_name);
412 owner_id = g_bus_own_name_on_connection(*connection, own_name,
413 G_BUS_NAME_OWNER_FLAGS_NONE,
414 NULL, NULL, NULL, NULL);
416 _E("g_bus_own_name_on_connection, error");
420 if (bus_type == G_BUS_TYPE_SESSION && event_type == ES_TYPE_USER) {
421 /* set same name on system-bus */
423 conn_system = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
424 if (conn_system == NULL) {
425 _E("failed to get system connection");
427 _E("error(%s)", error->message);
432 owner_id = g_bus_own_name_on_connection(conn_system,
433 own_name, G_BUS_NAME_OWNER_FLAGS_NONE,
434 NULL, NULL, NULL, NULL);
436 _E("g_bus_own_name_on_connection(for system), error");
437 g_object_unref(conn_system);
441 g_object_unref(conn_system);
445 if (bus_type == G_BUS_TYPE_SESSION) {
446 s_info.owner_id_session = owner_id;
447 s_info.own_name_session_bus = strdup(own_name);
448 if (s_info.own_name_session_bus == NULL) {
453 s_info.owner_id = owner_id;
454 s_info.own_name_system_bus = strdup(own_name);
455 if (s_info.own_name_system_bus == NULL) {
465 static void __eventsystem_event_handler(GDBusConnection *connection,
466 const gchar *sender_name, const gchar *object_path,
467 const gchar *interface_name, const gchar *signal_name,
468 GVariant *parameters, gpointer user_data)
472 GList *cb_list = NULL;
474 bundle_raw *raw = NULL;
476 em.interface_name = (char *)interface_name;
477 em.member_name = (char *)signal_name;
479 _D("sender_name(%s), interface_name(%s), signal_name(%s)",
480 sender_name, interface_name, signal_name);
482 cb_list = g_list_find_custom(system_event_list, &em,
483 (GCompareFunc)__event_compare_name_cb);
487 g_variant_get(parameters, "(us)", &len, &raw);
489 buf = bundle_decode((bundle_raw *)raw, len);
491 em.event_name = ((eventmap_s *)cb_list->data)->event_name;
492 em.ep_cb = ((eventmap_s *)cb_list->data)->ep_cb;
494 em.ep_cb(em.event_name, buf, user_data);
496 bundle_free_encoded_rawdata(&raw);
500 static void __eventsystem_application_event_handler(int sender_pid,
501 const gchar *interface_name, const gchar *signal_name,
502 GVariant *parameters, gpointer user_data)
504 GList *cb_list = NULL;
506 bundle_raw *raw = NULL;
509 em.interface_name = (char *)interface_name;
510 em.member_name = (char *)signal_name;
512 cb_list = g_list_find_custom(system_event_list, &em,
513 (GCompareFunc)__event_compare_name_cb);
515 if (cb_list == NULL) {
516 _E("not interested event");
520 em.event_name = ((eventmap_s *)cb_list->data)->event_name;
522 if (sender_pid > 0 && __check_interface_validation_user((char *)interface_name)) {
523 if (__check_validation_usrevent_sender(sender_pid,
524 (const char *)interface_name, em.event_name) < 0) {
525 _E("invalid sender");
530 g_variant_get(parameters, "(us)", &len, &raw);
531 em.es_cb = ((eventmap_s *)cb_list->data)->es_cb;
533 em.es_cb(em.event_name, raw, len, user_data);
535 bundle_free_encoded_rawdata(&raw);
539 * application-use filter for user-event
541 static void __eventsystem_filter_userevent_for_application(GDBusConnection *connection,
542 const gchar *sender_name, const gchar *object_path,
543 const gchar *interface_name, const gchar *signal_name,
544 GVariant *parameters, gpointer user_data)
546 char *sender_id = NULL;
549 _D("sender_name(%s), interface_name(%s)", sender_name, interface_name);
551 if (filter_tbl == NULL)
552 filter_tbl = g_hash_table_new(g_str_hash, g_str_equal);
554 sender_id = (char *)g_hash_table_lookup(filter_tbl, interface_name);
555 if (sender_id == NULL) {
556 sender_pid = __eventsystem_get_sender_pid(connection, sender_name);
557 if (sender_pid <= 0) {
558 _E("failed to get pid of sender(%s)", sender_name);
561 _D("sender_pid(%d)", sender_pid);
564 __eventsystem_application_event_handler(sender_pid, interface_name,
565 signal_name, parameters, user_data);
569 * application-use filter for system-event
571 static void __eventsystem_filter_sysevent_for_application(GDBusConnection *connection,
572 const gchar *sender_name, const gchar *object_path,
573 const gchar *interface_name, const gchar *signal_name,
574 GVariant *parameters, gpointer user_data)
576 _D("sender_name(%s), interface_name(%s)", sender_name, interface_name);
578 __eventsystem_application_event_handler(-1, interface_name,
579 signal_name, parameters, user_data);
583 * internal-use filter for user-event
585 static void __eventsystem_filter_userevent_for_internal(GDBusConnection *connection,
586 const gchar *sender_name, const gchar *object_path,
587 const gchar *interface_name, const gchar *signal_name,
588 GVariant *parameters, gpointer user_data)
590 _D("sender_name(%s), interface_name(%s), signal_name(%s)",
591 sender_name, interface_name, signal_name);
593 __eventsystem_event_handler(connection, sender_name,
594 object_path, interface_name, signal_name, parameters, user_data);
598 * internal-use filter for system-event
600 static void __eventsystem_filter_sysevent_for_internal(GDBusConnection *connection,
601 const gchar *sender_name, const gchar *object_path,
602 const gchar *interface_name, const gchar *signal_name,
603 GVariant *parameters, gpointer user_data)
605 _D("sender_name(%s), interface_name(%s), signal_name(%s)",
606 sender_name, interface_name, signal_name);
608 __eventsystem_event_handler(connection, sender_name,
609 object_path, interface_name, signal_name, parameters, user_data);
612 static int __eventsystem_register_event_internal(const char *event_name,
613 eventmap_s **em_s, void *user_data)
615 eventmap_s *em = NULL;
616 char *interface_name = NULL;
617 char *object_path = NULL;
618 char *member_name = NULL;
619 char *sender_name = NULL;
620 GDBusSignalCallback filter;
622 guint subscription_id = 0;
624 int evt_type = ES_TYPE_UNKNOWN;
625 GDBusConnection *conn = NULL;
627 if (__check_eventname_validation_system((char *)event_name)) {
628 evt_type = ES_TYPE_SYSTEM;
629 } else if (__check_eventname_validation_user((char *)event_name)) {
630 evt_type = ES_TYPE_USER;
632 evt_type = ES_TYPE_UNKNOWN;
633 _E("unknown type event(%s)", event_name);
637 if (evt_type == ES_TYPE_SYSTEM) {
638 interface_name = strdup(SYS_EVENT_NAME_PREFIX);
639 if (interface_name == NULL) {
645 member_name = __get_member_name_from_eventname((char *)event_name);
646 if (member_name == NULL) {
647 _E("invalid member_name");
652 if (!g_dbus_is_member_name(member_name)) {
653 _E("invalid member name");
657 filter = __eventsystem_filter_sysevent_for_internal;
659 interface_name = __get_encoded_interface_name((char *)event_name);
660 if (!interface_name) {
661 _E("interface_name is NULL");
665 if (!g_dbus_is_interface_name(interface_name)) {
666 _E("invalid interface_name(%s)", interface_name);
670 member_name = strdup(EVENT_SYSTEM_MEMBER);
676 filter = __eventsystem_filter_userevent_for_internal;
679 object_path = __get_object_path(interface_name);
681 _E("object_path is NULL");
687 bus_type = G_BUS_TYPE_SYSTEM;
689 if (__get_gdbus_shared_connection(&conn, bus_type, evt_type) < 0) {
690 _E("getting gdbus-connetion error");
694 subscription_id = g_dbus_connection_signal_subscribe(conn,
695 sender_name, /* sender */
697 member_name, /* member */
698 object_path, /* object_path */
700 G_DBUS_SIGNAL_FLAGS_NONE,
703 NULL); /* user_data_free_func */
705 _D("event_name(%s), interface_name(%s)", event_name, interface_name);
706 _D("member_name(%s), subscription_id(%d), bus_type(%d)",
707 member_name, subscription_id, bus_type);
709 if (subscription_id != 0) {
710 em = calloc(1, sizeof(eventmap_s));
712 _E("memory alloc failed");
715 em->interface_name = strdup(interface_name);
716 em->member_name = strdup(member_name);
717 em->event_name = strdup(event_name);
718 em->bus_type = bus_type;
719 em->reg_id = subscription_id;
720 em->event_type = evt_type;
722 if (!em->interface_name || !em->member_name || !em->event_name) {
724 FREE_AND_NULL(em->interface_name);
725 FREE_AND_NULL(em->member_name);
726 FREE_AND_NULL(em->event_name);
736 _D("dbus subscribe: error(%d), event(%s)", subscription_id, event_name);
741 FREE_AND_NULL(object_path);
743 FREE_AND_NULL(member_name);
745 FREE_AND_NULL(interface_name);
748 g_object_unref(conn);
754 * function : register the event
756 int eventsystem_register_event(const char *event_name, unsigned int *reg_id,
757 eventsystem_handler callback, void *user_data)
759 eventmap_s *em = NULL;
760 int ret = ES_R_ERROR;
762 retvm_if(!g_dbus_is_interface_name(event_name), ES_R_EINVAL,
763 "Invalid argument : event_name(%s)", event_name);
764 retvm_if(!reg_id, ES_R_EINVAL, "Invalid argument : reg_id");
765 retvm_if(!callback, ES_R_EINVAL, "Invalid argument : callback");
770 ret = __eventsystem_register_event_internal(event_name, &em, user_data);
771 if (ret == ES_R_OK && em) {
772 em->ep_cb = callback;
773 system_event_list = g_list_append(system_event_list, em);
774 *reg_id = em->reg_id;
777 _E("error, ret(%d), em(%s)", ret, em);
784 * function : unregister the event
786 int eventsystem_unregister_event(unsigned int reg_id)
789 eventmap_s *em_data = NULL;
791 GList *cb_list = NULL;
792 GDBusConnection *conn = NULL;
793 eventsystem_event_type evt_type;
795 retvm_if(reg_id == 0, ES_R_EINVAL, "Invalid argument : reg_id");
801 cb_list = g_list_find_custom(system_event_list, &em,
802 (GCompareFunc)__event_compare_reg_id_cb);
804 em_data = (eventmap_s *)cb_list->data;
806 bus_type = em_data->bus_type;
807 evt_type = em_data->event_type;
809 _D("unsubscribe: reg_id(%d), bus_type(%d)", reg_id, bus_type);
811 if (__get_gdbus_shared_connection(&conn, bus_type, evt_type) < 0) {
812 _E("getting gdbus-connetion error");
815 g_dbus_connection_signal_unsubscribe(conn, reg_id);
817 system_event_list = g_list_remove(system_event_list, cb_list->data);
819 FREE_AND_NULL(em_data->interface_name);
820 FREE_AND_NULL(em_data->member_name);
821 FREE_AND_NULL(em_data->event_name);
822 FREE_AND_NULL(em_data);
823 g_object_unref(conn);
829 static int __eventsystem_send_event(GDBusConnection *conn, eventinfo_s *evti, bundle *data)
831 GError *error = NULL;
832 GVariant *param = NULL;
835 bundle_raw *raw = NULL;
839 bundle_encode(buf, &raw, &len);
841 param = g_variant_new("(us)", len, raw);
842 ret = g_dbus_connection_emit_signal(conn,
843 evti->destination_name,
845 evti->interface_name,
850 _D("interface_name(%s)", evti->interface_name);
851 _D("object_path(%s)", evti->object_path);
852 _D("member_name(%s)", evti->member_name);
855 _E("Unable to connect to dbus: %s", error->message);
860 bundle_free_encoded_rawdata(&raw);
865 static void __eventsystem_free_trusted_list(gpointer data)
867 char *name = (char *)data;
872 static int __eventsystem_send_trusted_event(GDBusConnection *conn, eventinfo_s *evti,
873 bundle *data, GList *dest_list)
875 GList *tmp_list = NULL;
880 tmp_list = g_list_first(dest_list);
882 while (tmp_list != NULL) {
883 dest_name = (char *)tmp_list->data;
884 if (dest_name && dest_name[0] != '\0') {
885 _D("dest_name(%s)", dest_name);
886 evti->destination_name = dest_name;
887 ret = __eventsystem_send_event(conn, evti, data);
888 if (ret != ES_R_OK) {
894 tmp_list = g_list_next(tmp_list);
896 g_list_free_full(dest_list, __eventsystem_free_trusted_list);
898 _E("dest_list is null");
905 * function : send the user-event
907 int eventsystem_send_user_event(const char *event_name, bundle *data, bool is_trusted)
910 eventinfo_s *evti = NULL;
911 struct last_data_item *item;
912 bundle_raw *raw = NULL;
915 /* check validation */
916 retvm_if(!event_name, ES_R_EINVAL, "Invalid argument : event_name is NULL");
917 retvm_if(!data, ES_R_EINVAL, "Invalid argument : data is NULL");
918 retvm_if(!__check_eventname_validation_user((char *)event_name), ES_R_EINVAL,
919 "Invalid argument : event_name(%s)", event_name);
921 if (!__check_validation_user_defined_name(event_name)) {
922 _E("Invalid event name(%s)", event_name);
926 evti = calloc(1, sizeof(eventinfo_s));
928 _E("memory alloc failed");
931 evti->event_name = strdup(event_name);
932 if (!evti->event_name) {
933 _E("memory alloc failed");
938 evti->interface_name = __get_encoded_interface_name(evti->event_name);
939 if (!evti->interface_name) {
940 _E("interface_name is NULL");
944 evti->member_name = strdup(EVENT_SYSTEM_MEMBER);
945 if (!evti->member_name) {
946 _E("memory alloc failed");
951 evti->object_path = __get_object_path(evti->interface_name);
952 if (!evti->object_path) {
953 _E("object_path is NULL");
958 evti->destination_name = NULL;
959 evti->is_user_event = true;
960 evti->is_trusted = is_trusted;
962 GDBusConnection *conn = NULL;
963 if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SESSION, ES_TYPE_USER) == ES_R_OK) {
965 GList *dest_list = NULL;
966 ret = __eventsystem_requet_destination_list(evti->event_name, &dest_list);
968 _E("failed to get dest list");
971 ret = __eventsystem_send_trusted_event(conn, evti,
975 ret = __eventsystem_send_event(conn, evti, data);
978 if (bundle_encode(data, &raw, &len)) {
979 _E("Unable to encode bundle");
984 item = (struct last_data_item *)g_hash_table_lookup(last_data_tbl,
987 if (!evti->is_trusted) {
989 g_variant_unref(item->param);
990 item->param = g_variant_new("(us)", len, raw);
992 if (item->trusted_param)
993 g_variant_unref(item->trusted_param);
994 item->trusted_param = g_variant_new("(us)", len, raw);
997 bundle_free_encoded_rawdata(&raw);
999 _E("getting gdbus-connetion error");
1004 g_object_unref(conn);
1007 FREE_AND_NULL(evti->object_path);
1009 FREE_AND_NULL(evti->member_name);
1011 FREE_AND_NULL(evti->interface_name);
1013 FREE_AND_NULL(evti->event_name);
1015 FREE_AND_NULL(evti);
1021 * function : send the system-event
1023 int eventsystem_send_system_event(const char *event_name, bundle *data)
1026 eventinfo_s *evti = NULL;
1027 GDBusConnection *conn = NULL;
1029 pthread_mutex_lock(&send_sync_lock);
1031 /* check validation */
1032 tryvm_if(!event_name, ret = ES_R_EINVAL, "Invalid argument : event_name is NULL");
1033 tryvm_if(!data, ret = ES_R_EINVAL, "Invalid argument : data is NULL");
1034 tryvm_if(!__check_eventname_validation_system((char *)event_name), ret = ES_R_EINVAL,
1035 "Invalid argument : event_name(%s)", event_name);
1036 tryvm_if(!g_dbus_is_interface_name(event_name), ret = ES_R_EINVAL,
1037 "Invalid argument : event_name(%s)", event_name);
1039 _D("event_name(%s)", event_name);
1041 evti = calloc(1, sizeof(eventinfo_s));
1043 _E("memory alloc failed");
1044 pthread_mutex_unlock(&send_sync_lock);
1047 evti->event_name = strdup(event_name);
1048 if (!evti->event_name) {
1049 _E("out_of_memory");
1053 evti->interface_name = strdup(SYS_EVENT_NAME_PREFIX);
1054 if (!evti->interface_name) {
1055 _E("out of memory");
1059 evti->member_name = __get_member_name_from_eventname(evti->event_name);
1060 if (!evti->member_name) {
1061 _E("member_name is NULL");
1065 if (!g_dbus_is_member_name(evti->member_name)) {
1066 _E("Invalid member_name(%s)", evti->member_name);
1070 evti->object_path = __get_object_path(evti->interface_name);
1071 if (!evti->object_path) {
1072 _E("object_path is NULL");
1076 evti->destination_name = NULL;
1077 evti->is_user_event = false;
1079 if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) == ES_R_OK) {
1080 ret = __eventsystem_send_event(conn, evti, data);
1082 _E("getting gdbus-connection error");
1087 g_object_unref(conn);
1089 FREE_AND_NULL(evti->object_path);
1091 FREE_AND_NULL(evti->member_name);
1093 FREE_AND_NULL(evti->interface_name);
1095 FREE_AND_NULL(evti->event_name);
1097 FREE_AND_NULL(evti);
1100 pthread_mutex_unlock(&send_sync_lock);
1106 * function : request sending the event
1108 int eventsystem_request_sending_system_event(const char *event_name, bundle *data)
1111 GDBusConnection *conn = NULL;
1112 GError *error = NULL;
1113 GDBusProxy *proxy = NULL;
1114 GVariant *param = NULL;
1115 GVariant *value = NULL;
1117 bundle_raw *raw = NULL;
1120 _D("event_name(%s)", event_name);
1125 if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) < 0) {
1126 _E("getting gdbus-connetion error");
1131 proxy = g_dbus_proxy_new_sync(conn,
1132 G_DBUS_PROXY_FLAGS_NONE, NULL,
1133 ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME,
1135 if (proxy == NULL) {
1136 _E("failed to create new proxy, error(%s)", error->message);
1137 g_error_free(error);
1142 bundle_encode(data, &raw, &len);
1144 param = g_variant_new("(ssi)", event_name, raw, len);
1145 value = g_dbus_proxy_call_sync(proxy, "RequestSendingEvent", param,
1146 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1147 if (error != NULL) {
1148 _E("proxy call sync error(%s)", error->message);
1149 g_error_free(error);
1154 g_variant_get(value, "(i)", &result);
1156 _D("result(%d)", result);
1161 g_object_unref(proxy);
1162 g_variant_unref(value);
1165 g_object_unref(conn);
1170 static int __eventsystem_check_sender_validation(int sender_pid, const char *event_name,
1173 int ret = ES_R_EINVAL;
1174 GDBusConnection *conn = NULL;
1175 GError *error = NULL;
1176 GDBusProxy *proxy = NULL;
1177 GVariant *param = NULL;
1178 GVariant *value = NULL;
1184 if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) < 0) {
1185 _E("getting gdbus-connetion error");
1190 proxy = g_dbus_proxy_new_sync(conn,
1191 G_DBUS_PROXY_FLAGS_NONE, NULL,
1192 ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME,
1194 if (proxy == NULL) {
1195 _E("failed to create new proxy, error(%s)", error->message);
1196 g_error_free(error);
1201 param = g_variant_new("(is)", sender_pid, event_name);
1202 value = g_dbus_proxy_call_sync(proxy, "CheckSenderValidation", param,
1203 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1204 if (error != NULL) {
1205 _E("proxy call sync error(%s)", error->message);
1206 g_error_free(error);
1211 g_variant_get(value, "(is)", &result, sender_id);
1213 _D("result(%d)", result);
1218 g_object_unref(proxy);
1219 g_variant_unref(value);
1222 g_object_unref(conn);
1227 static int __eventsystem_check_user_send_validation(const char *event_name)
1229 int ret = ES_R_EINVAL;
1230 GDBusConnection *conn = NULL;
1231 GError *error = NULL;
1232 GDBusProxy *proxy = NULL;
1233 GVariant *param = NULL;
1234 GVariant *value = NULL;
1240 if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) < 0) {
1241 _E("getting gdbus-connetion error");
1246 proxy = g_dbus_proxy_new_sync(conn,
1247 G_DBUS_PROXY_FLAGS_NONE, NULL,
1248 ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME,
1250 if (proxy == NULL) {
1251 _E("failed to create new proxy, error(%s)", error->message);
1252 g_error_free(error);
1257 param = g_variant_new("(s)", event_name);
1258 value = g_dbus_proxy_call_sync(proxy, "CheckUserSendValidation", param,
1259 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1260 if (error != NULL) {
1261 _E("proxy call sync error(%s)", error->message);
1262 g_error_free(error);
1267 g_variant_get(value, "(i)", &result);
1269 _D("result(%d)", result);
1274 g_object_unref(proxy);
1275 g_variant_unref(value);
1278 g_object_unref(conn);
1283 static int __eventsystem_check_privilege_validation(const char *event_name)
1285 int ret = ES_R_ENOTPERMITTED;
1286 GDBusConnection *conn = NULL;
1287 GError *error = NULL;
1288 GDBusProxy *proxy = NULL;
1289 GVariant *param = NULL;
1290 GVariant *value = NULL;
1296 if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) < 0) {
1297 _E("getting gdbus-connetion error");
1302 proxy = g_dbus_proxy_new_sync(conn,
1303 G_DBUS_PROXY_FLAGS_NONE, NULL,
1304 ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME,
1306 if (proxy == NULL) {
1307 _E("failed to create new proxy, error(%s)", error->message);
1308 g_error_free(error);
1313 param = g_variant_new("(s)", event_name);
1314 value = g_dbus_proxy_call_sync(proxy, "CheckPrivilegeValidation", param,
1315 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1316 if (error != NULL) {
1317 _E("proxy call sync error(%s)", error->message);
1318 g_error_free(error);
1323 g_variant_get(value, "(i)", &result);
1325 _D("result(%d)", result);
1330 g_object_unref(proxy);
1331 g_variant_unref(value);
1334 g_object_unref(conn);
1339 static int __eventsystem_setup_trusted_peer(const char *event_name, const char *dest_bus_name)
1341 int ret = ES_R_ERROR;
1342 GDBusConnection *conn = NULL;
1343 GError *error = NULL;
1344 GDBusProxy *proxy = NULL;
1345 GVariant *param = NULL;
1346 GVariant *value = NULL;
1352 if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) < 0) {
1353 _E("getting gdbus-connetion error");
1358 proxy = g_dbus_proxy_new_sync(conn,
1359 G_DBUS_PROXY_FLAGS_NONE, NULL,
1360 ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME,
1362 if (proxy == NULL) {
1363 _E("failed to create new proxy, error(%s)", error->message);
1364 g_error_free(error);
1369 param = g_variant_new("(ss)", event_name, dest_bus_name);
1370 value = g_dbus_proxy_call_sync(proxy, "SetupTrustedPeer", param,
1371 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1372 if (error != NULL) {
1373 _E("proxy call sync error(%s)", error->message);
1374 g_error_free(error);
1379 g_variant_get(value, "(i)", &result);
1381 _D("result(%d)", result);
1386 g_object_unref(proxy);
1387 g_variant_unref(value);
1390 g_object_unref(conn);
1395 static int __eventsystem_requet_destination_list(const char *event_name, GList **dest_list)
1397 int ret = ES_R_ERROR;
1398 GDBusConnection *conn = NULL;
1399 GError *error = NULL;
1400 GDBusProxy *proxy = NULL;
1401 GVariant *param = NULL;
1402 GVariant *value = NULL;
1405 char *dest_name = NULL;
1411 if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) < 0) {
1412 _E("getting gdbus-connetion error");
1417 proxy = g_dbus_proxy_new_sync(conn,
1418 G_DBUS_PROXY_FLAGS_NONE, NULL,
1419 ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME,
1421 if (proxy == NULL) {
1422 _E("failed to create new proxy, error(%s)", error->message);
1423 g_error_free(error);
1428 param = g_variant_new("(s)", event_name);
1429 value = g_dbus_proxy_call_sync(proxy, "GetTrustedPeerList", param,
1430 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1431 if (error != NULL) {
1432 _E("proxy call sync error(%s)", error->message);
1433 g_error_free(error);
1438 g_variant_get(value, "(ias)", &result, &iter);
1440 _D("result(%d)", result);
1444 while (g_variant_iter_loop(iter, "s", &str)) {
1445 dest_name = strdup((char *)str);
1447 _D("dest name(%s)", str);
1448 *dest_list = g_list_append(*dest_list, dest_name);
1450 _E("out of memory");
1456 g_variant_iter_free(iter);
1459 g_object_unref(proxy);
1460 g_variant_unref(value);
1463 g_object_unref(conn);
1468 #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE
1469 static int __eventsystem_request_earlier_data(const char *event_name,
1470 eventsystem_cb callback, void *user_data)
1473 GDBusConnection *conn = NULL;
1474 GError *error = NULL;
1475 GDBusProxy *proxy = NULL;
1476 GVariant *param = NULL;
1477 GVariant *value = NULL;
1479 bundle_raw *raw = NULL;
1485 if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM, ES_TYPE_SYSTEM) < 0) {
1486 _E("getting gdbus-connetion error");
1491 proxy = g_dbus_proxy_new_sync(conn,
1492 G_DBUS_PROXY_FLAGS_NONE, NULL,
1493 ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME,
1496 if (proxy == NULL) {
1497 _E("failed to create new proxy, error(%s)", error->message);
1498 g_error_free(error);
1503 param = g_variant_new("(s)", event_name);
1504 value = g_dbus_proxy_call_sync(proxy, "GetEarlierData", param,
1505 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1506 if (error != NULL) {
1507 _E("proxy call sync error(%s)", error->message);
1508 g_error_free(error);
1513 g_variant_get(value, "(iis)", &result, &len, &raw);
1514 g_variant_unref(value);
1516 _D("result(%d), len(%d)", result, len);
1518 if (!result && raw && len > 0) {
1519 callback(event_name, raw, len, user_data);
1520 bundle_free_encoded_rawdata(&raw);
1526 g_object_unref(proxy);
1527 g_variant_unref(value);
1530 g_object_unref(conn);
1536 static int __request_esd_for_last_data(const char *event_name, bool check)
1539 GDBusConnection *conn = NULL;
1540 GError *error = NULL;
1541 GDBusProxy *proxy = NULL;
1542 GVariant *param = NULL;
1543 GVariant *value = NULL;
1549 if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SYSTEM,
1550 ES_TYPE_SYSTEM) < 0) {
1551 _E("getting gdbus-connetion error");
1556 proxy = g_dbus_proxy_new_sync(conn,
1557 G_DBUS_PROXY_FLAGS_NONE, NULL,
1558 ESD_BUS_NAME, ESD_OBJECT_PATH, ESD_INTERFACE_NAME,
1561 if (proxy == NULL) {
1562 _E("failed to create new proxy, error(%s)", error->message);
1563 g_error_free(error);
1568 param = g_variant_new("(ss)", event_name,
1569 check ? s_info.own_name_session_bus :
1570 s_info.own_name_system_bus);
1571 value = g_dbus_proxy_call_sync(proxy,
1572 check ? "CheckLastData" : "KeepLastData", param,
1573 G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
1575 if (error != NULL) {
1576 _E("proxy call sync error(%s)", error->message);
1577 g_error_free(error);
1582 g_variant_get(value, "(i)", &result);
1584 _D("result(%d)", result);
1589 g_object_unref(proxy);
1590 g_variant_unref(value);
1593 g_object_unref(conn);
1598 static void _send_last_user_event(const char *event_name,
1599 bundle *data, void *user_data)
1601 GDBusConnection *conn = NULL;
1602 GError *error = NULL;
1603 eventinfo_s *evti = NULL;
1605 struct last_data_item *item;
1606 const char *is_trusted;
1608 _D("send last data");
1610 if (g_strcmp0(event_name, SYS_EVENT_REQUEST_LAST_DATA) != 0)
1613 evti = calloc(1, sizeof(eventinfo_s));
1615 _E("memory alloc failed");
1619 evti->event_name = (char *)bundle_get_val(data,
1620 EVT_KEY_KEPT_EVENT_NAME);
1621 if (!evti->event_name) {
1622 _E("memory alloc failed");
1626 item = (struct last_data_item *)g_hash_table_lookup(last_data_tbl,
1631 evti->interface_name = __get_encoded_interface_name(evti->event_name);
1632 if (!evti->interface_name) {
1633 _E("interface_name is NULL");
1637 evti->member_name = strdup(EVENT_SYSTEM_MEMBER);
1638 if (!evti->member_name) {
1639 _E("memory alloc failed");
1643 evti->object_path = __get_object_path(evti->interface_name);
1644 if (!evti->object_path) {
1645 _E("object_path is NULL");
1649 evti->destination_name = (char *)bundle_get_val(data,
1650 EVT_KEY_KEPT_OWN_NAME);
1651 if (!evti->destination_name) {
1652 _E("object_path is NULL");
1656 is_trusted = bundle_get_val(data, EVT_KEY_KEPT_IS_TRUSTED);
1658 _E("object_path is NULL");
1662 if (strncmp("true", is_trusted, sizeof("true")) != 0) {
1663 if (!item->trusted_param)
1665 evti->is_trusted = true;
1669 evti->is_trusted = false;
1672 if (__get_gdbus_shared_connection(&conn, G_BUS_TYPE_SESSION,
1673 ES_TYPE_USER) == ES_R_OK) {
1674 ret = g_dbus_connection_emit_signal(conn,
1675 evti->destination_name,
1677 evti->interface_name,
1679 evti->is_trusted ? item->trusted_param : item->param,
1682 _E("Unable to connect to dbus: %s", error->message);
1683 g_error_free(error);
1688 g_object_unref(conn);
1691 FREE_AND_NULL(evti->object_path);
1693 FREE_AND_NULL(evti->member_name);
1695 FREE_AND_NULL(evti->interface_name);
1697 FREE_AND_NULL(evti);
1700 int eventsystem_keep_last_event_data(const char *event_name)
1703 unsigned int reg_id;
1704 struct last_data_item *item;
1706 if (last_data_tbl == NULL)
1707 last_data_tbl = g_hash_table_new(g_str_hash, g_str_equal);
1709 ret = __request_esd_for_last_data(event_name, false);
1713 item = calloc(1, sizeof(*item));
1717 item->event_name = strdup(event_name);
1719 item->trusted_param = NULL;
1721 g_hash_table_insert(last_data_tbl, (char *)event_name, item);
1723 ret = eventsystem_register_event(SYS_EVENT_REQUEST_LAST_DATA,
1724 ®_id, _send_last_user_event, NULL);
1729 int eventsystem_register_application_event(const char *event_name, unsigned int *reg_id,
1730 int *event_type, eventsystem_cb callback, void *user_data)
1733 char *interface_name = NULL;
1734 char *object_path = NULL;
1735 char *member_name = NULL;
1736 char *sender_name = NULL;
1737 GDBusSignalCallback filter;
1739 guint subscription_id = 0;
1741 GDBusConnection *conn = NULL;
1746 if (__check_eventname_validation_system((char *)event_name)) {
1747 if (__eventsystem_check_privilege_validation(event_name) != ES_R_OK) {
1748 _E("invalid privilege(%s)", event_name);
1749 return ES_R_ENOTPERMITTED;
1751 *event_type = ES_TYPE_SYSTEM;
1752 } else if (__check_eventname_validation_user((char *)event_name)) {
1753 *event_type = ES_TYPE_USER;
1755 *event_type = ES_TYPE_UNKNOWN;
1756 _E("unknown type event(%s)", event_name);
1760 if (*event_type == ES_TYPE_SYSTEM) {
1761 interface_name = strdup(SYS_EVENT_NAME_PREFIX);
1762 if (interface_name == NULL) {
1763 _E("out of memory");
1766 if (!g_dbus_is_interface_name(interface_name)) {
1767 _E("invalid interface_name(%s)", interface_name);
1768 FREE_AND_NULL(interface_name);
1771 member_name = __get_member_name_from_eventname((char *)event_name);
1772 if (member_name == NULL) {
1773 _E("member_name is NULL(%s)", event_name);
1774 FREE_AND_NULL(interface_name);
1777 if (!g_dbus_is_member_name(member_name)) {
1778 _E("Invalid member_name(%s)", member_name);
1779 FREE_AND_NULL(interface_name);
1780 FREE_AND_NULL(member_name);
1783 filter = __eventsystem_filter_sysevent_for_application;
1784 bus_type = G_BUS_TYPE_SYSTEM;
1786 interface_name = __get_encoded_interface_name((char *)event_name);
1787 if (!interface_name) {
1788 _E("interface_name is NULL");
1791 if (!g_dbus_is_interface_name(interface_name)) {
1792 _E("invalid interface_name(%s)", interface_name);
1793 FREE_AND_NULL(interface_name);
1796 member_name = strdup(EVENT_SYSTEM_MEMBER);
1798 _E("out_of_memory");
1799 FREE_AND_NULL(interface_name);
1802 filter = __eventsystem_filter_userevent_for_application;
1803 bus_type = G_BUS_TYPE_SESSION;
1806 object_path = __get_object_path(interface_name);
1808 _E("failed get object_path");
1809 FREE_AND_NULL(interface_name);
1810 FREE_AND_NULL(member_name);
1815 _D("interface_name(%s), object_path(%s)", interface_name, object_path);
1816 _D(" member_name(%s), sender_name(%s), type(%d), bus_type(%d)",
1817 member_name, sender_name, *event_type, bus_type);
1819 if (__get_gdbus_shared_connection(&conn, bus_type, *event_type) < 0) {
1820 _E("getting gdbus-connetion error");
1821 FREE_AND_NULL(interface_name);
1822 FREE_AND_NULL(object_path);
1823 FREE_AND_NULL(member_name);
1827 #ifdef APPFW_EVENT_SYSTEM_EARLIER_FEATURE
1828 __eventsystem_request_earlier_data(event_name, callback, user_data);
1831 subscription_id = g_dbus_connection_signal_subscribe(conn,
1832 sender_name, /* sender */
1834 member_name, /* member */
1835 object_path, /* object_path */
1837 G_DBUS_SIGNAL_FLAGS_NONE,
1840 NULL); /* user_data_free_func */
1842 _D("event_name(%s), subscription_id(%d)", event_name, subscription_id);
1844 if (subscription_id != 0) {
1845 em = calloc(1, sizeof(eventmap_s));
1847 _E("memory alloc failed");
1850 em->interface_name = strdup(interface_name);
1851 em->member_name = strdup(member_name);
1852 em->event_name = strdup(event_name);
1853 em->es_cb = callback;
1854 em->bus_type = bus_type;
1855 em->reg_id = subscription_id;
1856 em->event_type = *event_type;
1858 if (!em->interface_name || !em->member_name ||
1860 _E("out_of_memory");
1861 FREE_AND_NULL(em->interface_name);
1862 FREE_AND_NULL(em->member_name);
1863 FREE_AND_NULL(em->event_name);
1868 g_list_append(system_event_list, em);
1869 *reg_id = subscription_id;
1873 if (em->bus_type == G_BUS_TYPE_SESSION &&
1874 em->event_type == ES_TYPE_USER) {
1875 if (s_info.own_name_session_bus == NULL) {
1876 _E("session bus is not ready");
1879 if (__eventsystem_setup_trusted_peer(event_name,
1880 s_info.own_name_session_bus) < 0) {
1881 _E("failed to setup trusted peer");
1889 _E("dbus subscribe: error(%d)", subscription_id);
1893 FREE_AND_NULL(interface_name);
1894 FREE_AND_NULL(object_path);
1895 FREE_AND_NULL(member_name);
1897 g_object_unref(conn);
1899 __request_esd_for_last_data(event_name, true);
1904 int eventsystem_unregister_application_event(unsigned int reg_id)
1907 eventmap_s *em_data = NULL;
1909 GList *cb_list = NULL;
1910 GDBusConnection *conn = NULL;
1911 eventsystem_event_type evt_type;
1913 retvm_if(reg_id == 0, ES_R_EINVAL, "Invalid argument : reg_id");
1919 cb_list = g_list_find_custom(system_event_list, &em,
1920 (GCompareFunc)__event_compare_reg_id_cb);
1922 em_data = (eventmap_s *)cb_list->data;
1924 bus_type = em_data->bus_type;
1925 evt_type = em_data->event_type;
1927 _D("unsubscribe: reg_id(%d), bus_type(%d)", reg_id, bus_type);
1929 if (__get_gdbus_shared_connection(&conn, bus_type, evt_type) < 0) {
1930 _E("getting gdbus-connetion error");
1933 g_dbus_connection_signal_unsubscribe(conn, reg_id);
1935 system_event_list = g_list_remove(system_event_list, cb_list->data);
1937 FREE_AND_NULL(em_data->interface_name);
1938 FREE_AND_NULL(em_data->member_name);
1939 FREE_AND_NULL(em_data->event_name);
1940 FREE_AND_NULL(em_data);
1941 g_object_unref(conn);
1943 _E("not found matched item");
1950 int eventsystem_application_finalize(void)
1954 GHashTableIter iter;
1958 _D("release all resouces");
1960 if (system_event_list)
1961 g_list_free(system_event_list);
1964 g_hash_table_iter_init(&iter, check_tbl);
1966 while (g_hash_table_iter_next(&iter, &key, &value)) {
1967 val_item = (char *)value;
1971 _E("check_tbl, val_item is NULL");
1972 g_hash_table_iter_remove(&iter);
1974 g_hash_table_unref(check_tbl);
1978 g_hash_table_iter_init(&iter, filter_tbl);
1980 while (g_hash_table_iter_next(&iter, &key, &value)) {
1981 key_item = (char *)key;
1985 _E("filter_tbl, key_item is NULL");
1987 val_item = (char *)value;
1991 _E("filter_tbl, val_item is NULL");
1993 g_hash_table_iter_remove(&iter);
1995 g_hash_table_unref(filter_tbl);
1998 if (last_data_tbl) {
1999 g_hash_table_iter_init(&iter, last_data_tbl);
2001 while (g_hash_table_iter_next(&iter, &key, &value)) {
2002 key_item = (char *)key;
2006 _E("last_data_tbl, val_item is NULL");
2008 val_item = (char *)value;
2012 _E("last_data_tbl, val_item is NULL");
2013 g_hash_table_iter_remove(&iter);
2015 g_hash_table_unref(check_tbl);
2018 FREE_AND_NULL(s_info.own_name_system_bus);
2019 FREE_AND_NULL(s_info.own_name_session_bus);