} message_port_local_port_info_s;
typedef struct message_port_remote_port_info {
- char *sender_id;
char *remote_app_id;
int certificate_info;
GList *port_list;
} message_port_remote_app_info_s;
typedef struct port_list_info {
+ message_port_remote_app_info_s *remote_app_info;
char *port_name;
char *encoded_bus_name;
bool is_trusted;
int send_sock_fd;
- int watcher_id;
bool exist;
GIOChannel *gio_read;
int g_src_id;
return MESSAGEPORT_ERROR_NONE;
}
-static void on_name_appeared(GDBusConnection *connection,
- const gchar *name,
- const gchar *name_owner,
- gpointer user_data)
-{
- _LOGD("name appeared : %s %s", __app_id, name);
-}
-
-static void on_name_vanished(GDBusConnection *connection,
- const gchar *name,
- gpointer user_data)
-{
- _LOGI("name vanished : %s", name);
- port_list_info_s *pli = (port_list_info_s *)user_data;
- if (pli == NULL) {
- LOGE("NULL port info");
- return;
- }
-
- _LOGD("watcher_id :%d", pli->watcher_id);
- if (pli->watcher_id > 0)
- g_bus_unwatch_name(pli->watcher_id);
- else
- _LOGE("Invalid watcher_id %d", pli->watcher_id);
- pli->exist = false;
- pli->watcher_id = 0;
-
-}
-
static int __get_local_port_info(int id, message_port_local_port_info_s **info)
{
message_port_local_port_info_s *mi = (message_port_local_port_info_s *)g_hash_table_lookup(__local_port_info, GINT_TO_POINTER(id));
if (port_info == NULL)
return;
- _LOGI("__clear_disconnect_socket : fd [%d]", port_info->send_sock_fd);
if (port_info->gio_read != NULL) {
g_io_channel_shutdown(port_info->gio_read, TRUE, &error);
port_info->send_sock_fd = 0;
}
-static gboolean __socket_disconnect_handler(GIOChannel *gio,
- GIOCondition cond,
- gpointer data)
+/* LCOV_EXCL_START */
+void __free_port_info(gpointer data)
{
- /* It's sender socket's gio channel so, only EOF can be received */
port_list_info_s *port_info = (port_list_info_s *)data;
- _LOGI("__socket_disconnect_handler %d", cond);
- __clear_disconnect_socket(port_info);
- return FALSE;
-}
+ message_port_remote_app_info_s *remote_app_info;
-static void __watch_remote_port_info(port_list_info_s *port_info)
-{
if (port_info == NULL)
return;
- if (port_info->watcher_id < 1) {
- port_info->watcher_id = g_bus_watch_name_on_connection(
- __gdbus_conn,
- port_info->encoded_bus_name,
- G_BUS_NAME_WATCHER_FLAGS_NONE,
- on_name_appeared,
- on_name_vanished,
- port_info,
- NULL);
- } else {
- LOGD("Already watched port info");
- return;
+ remote_app_info = port_info->remote_app_info;
+
+ _LOGI("__free_port_info : remote_app_id : %s port_name : %s",
+ remote_app_info->remote_app_id,
+ port_info->port_name);
+
+ remote_app_info->port_list = g_list_remove(remote_app_info->port_list,
+ port_info);
+
+ __clear_disconnect_socket(port_info);
+
+ if (port_info->encoded_bus_name)
+ free(port_info->encoded_bus_name);
+ if (port_info->port_name)
+ free(port_info->port_name);
+
+ free(port_info);
+
+ if (g_list_length(remote_app_info->port_list) == 0) {
+ g_hash_table_remove(__remote_app_info,
+ remote_app_info->remote_app_id);
}
}
+/* LCOV_EXCL_STOP */
+
+static gboolean __socket_disconnect_handler(GIOChannel *gio,
+ GIOCondition cond,
+ gpointer data)
+{
+ _LOGI("__socket_disconnect_handler %d", cond);
+ __free_port_info(data);
+
+ return FALSE;
+}
static int __get_remote_port_info(const char *remote_app_id, const char *remote_port, bool is_trusted,
message_port_remote_app_info_s **mri, port_list_info_s **pli)
goto out;
}
remote_app_info->port_list = g_list_append(remote_app_info->port_list, tmp);
+ tmp->remote_app_info = remote_app_info;
*pli = tmp;
} else {
*pli = (port_list_info_s *)cb_list->data;
port_info->exist = true;
*exist = true;
ret_val = MESSAGEPORT_ERROR_NONE;
- __watch_remote_port_info(port_info);
}
}
out:
if (result)
g_variant_unref(result);
+ if (ret_val != MESSAGEPORT_ERROR_NONE || !name_exist)
+ __free_port_info((gpointer)port_info);
+
return ret_val;
}
}
/* LCOV_EXCL_START */
-void __list_free_port_list(gpointer data)
-{
- port_list_info_s *n = (port_list_info_s *)data;
-
- FREE_AND_NULL(n->encoded_bus_name);
- FREE_AND_NULL(n->port_name);
- FREE_AND_NULL(n);
-}
-/* LCOV_EXCL_STOP */
-
-/* LCOV_EXCL_START */
static void __hash_destory_local_value(gpointer data)
{
message_port_local_port_info_s *mli = (message_port_local_port_info_s *)data;
{
message_port_remote_app_info_s *mri = (message_port_remote_app_info_s *)data;
if (mri) {
- FREE_AND_NULL(mri->sender_id);
FREE_AND_NULL(mri->remote_app_id);
if (mri->port_list)
- g_list_free_full(mri->port_list, __list_free_port_list);
+ g_list_free_full(mri->port_list, __free_port_info);
free(mri);
}
pthread_mutex_unlock(&mutex);
return G_SOURCE_CONTINUE;
} else if (ret == MESSAGEPORT_ERROR_IO_ERROR) {
- __clear_disconnect_socket(port_info);
+ __free_port_info((gpointer)port_info);
pthread_mutex_unlock(&mutex);
return G_SOURCE_REMOVE;
}
bool exist = false;
_LOGD("port exist check !!");
ret = __check_remote_port(remote_appid, remote_port, trusted_message, &exist);
- if (ret != MESSAGEPORT_ERROR_NONE) {
- goto out;
- } else if (!exist) {
- ret = MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND;
- goto out;
- }
+ if (ret != MESSAGEPORT_ERROR_NONE)
+ return ret;
+ else if (!exist)
+ return MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND;
}
if (port_info->send_sock_fd > 0) {
goto out;
}
- port_info->g_src_id = g_io_add_watch(port_info->gio_read, G_IO_IN | G_IO_HUP,
- __socket_disconnect_handler, (gpointer)port_info);
+ port_info->g_src_id = g_io_add_watch(
+ port_info->gio_read,
+ G_IO_IN | G_IO_HUP,
+ __socket_disconnect_handler,
+ (gpointer)port_info);
if (port_info->g_src_id == 0) {
_LOGE("fail to add watch on socket");
ret = MESSAGEPORT_ERROR_IO_ERROR;
ret = MESSAGEPORT_ERROR_IO_ERROR;
goto out;
}
- __watch_remote_port_info(port_info);
-
}
out:
g_object_unref(fd_list);
if (ret != MESSAGEPORT_ERROR_NONE) {
- __clear_disconnect_socket(port_info);
+ __free_port_info((gpointer)port_info);
if (sock_pair[SOCK_PAIR_SENDER])
close(sock_pair[SOCK_PAIR_SENDER]);
if (sock_pair[SOCK_PAIR_RECEIVER])