2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 #include <bundle_internal.h>
23 #include <sys/socket.h>
29 #include <gio/gunixfdlist.h>
30 #include <glib-unix.h>
32 #include "message_port_log.h"
33 #include "message_port_common.h"
34 #include "message_port_remote.h"
37 #define MAX_PACKAGE_STR_SIZE 512
39 #define DBUS_RELEASE_NAME_REPLY_RELEASED 1 /* *< Service was released from the given name */
40 #define DBUS_RELEASE_NAME_REPLY_NON_EXISTENT 2 /* *< The given name does not exist on the bus */
41 #define DBUS_RELEASE_NAME_REPLY_NOT_OWNER 3 /* *< Service is not an owner of the given name */
43 #define MAX_RETRY_CNT 10
44 #define SOCK_PAIR_SENDER 0
45 #define SOCK_PAIR_RECEIVER 1
47 static bool _initialized = false;
48 static GHashTable *__local_port_info;
49 static GHashTable *__trusted_app_list_hash;
50 static GList *__callback_info_list;
51 static GHashTable *__sender_appid_hash;
53 typedef struct message_port_pkt {
54 int remote_port_name_len;
55 char *remote_port_name;
62 typedef struct message_port_callback_info {
63 message_port_local_port_info_s *local_info;
68 } message_port_callback_info_s;
70 static void __callback_info_free(gpointer data)
72 message_port_callback_info_s *callback_info = (message_port_callback_info_s *)data;
74 if (callback_info == NULL)
77 if (callback_info->remote_app_id)
78 FREE_AND_NULL(callback_info->remote_app_id);
80 if (callback_info->local_info) {
81 if (callback_info->local_info->port_name)
82 FREE_AND_NULL(callback_info->local_info->port_name);
84 FREE_AND_NULL(callback_info->local_info);
87 if (callback_info->gio_read != NULL) {
88 g_io_channel_shutdown(callback_info->gio_read, TRUE, &error);
90 _LOGE("g_io_channel_shutdown error : %s", error->message);
93 g_io_channel_unref(callback_info->gio_read);
94 callback_info->gio_read = NULL;
97 if (callback_info->g_src_id != 0) {
98 g_source_remove(callback_info->g_src_id);
99 callback_info->g_src_id = 0;
102 FREE_AND_NULL(callback_info);
105 /* LCOV_EXCL_START */
106 static void __callback_info_free_by_info(message_port_callback_info_s *callback_info)
110 find_list = g_list_find(__callback_info_list, callback_info);
111 if (find_list == NULL)
114 __callback_info_list = g_list_remove_link(__callback_info_list, find_list);
115 __callback_info_free(callback_info);
116 g_list_free(find_list);
119 static void __callback_info_free_by_local_id(int local_id)
122 GList *callback_info;
124 for (iter = __callback_info_list; iter != NULL; ) {
125 if (((message_port_callback_info_s *)iter->data)->local_id == local_id) {
126 callback_info = iter;
128 __callback_info_list =
129 g_list_remove_link(__callback_info_list, callback_info);
130 __callback_info_free(callback_info->data);
131 g_list_free(callback_info);
138 /* LCOV_EXCL_START */
139 static void __hash_destory_local_value(gpointer data)
141 message_port_local_port_info_s *mli = (message_port_local_port_info_s *)data;
144 free(mli->port_name);
150 static bool __initialize(void)
152 if (!initialized_common) {
153 if (!initialize_common())
157 if (__local_port_info == NULL) {
158 __local_port_info = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, __hash_destory_local_value);
159 retvm_if(!__local_port_info, false, "fail to create __local_port_info");
162 if (__sender_appid_hash == NULL) {
163 __sender_appid_hash = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
164 retvm_if(!__sender_appid_hash, false, "fail to create __sender_appid_hash");
167 if (__trusted_app_list_hash == NULL) {
168 __trusted_app_list_hash = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
169 retvm_if(!__trusted_app_list_hash, false, "fail to create __trusted_app_list_hash");
177 bool is_local_port_registed(const char *local_port, bool trusted, int *local_id, message_port_local_port_info_s **lpi)
182 if (__local_port_info == NULL) {
183 _LOGI("There is no registed local port");
187 g_hash_table_iter_init(&iter, __local_port_info);
188 while (g_hash_table_iter_next(&iter, &key, &value)) {
189 message_port_local_port_info_s *mi = (message_port_local_port_info_s *)value;
191 if ((mi->is_trusted == trusted) && strcmp(mi->port_name, local_port) == 0) {
192 *local_id = mi->local_id;
201 static int __get_sender_pid(GDBusConnection *conn, const char *sender_name)
203 GDBusMessage *msg = NULL;
204 GDBusMessage *reply = NULL;
209 msg = g_dbus_message_new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus",
210 "org.freedesktop.DBus", "GetConnectionUnixProcessID");
212 _LOGE("Can't allocate new method call");
216 g_dbus_message_set_body(msg, g_variant_new("(s)", sender_name));
217 reply = g_dbus_connection_send_message_with_reply_sync(conn, msg,
218 G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
222 _LOGE("Failed to get pid [%s]", err->message);
225 _LOGE("Failed to get pid");
230 body = g_dbus_message_get_body(reply);
231 g_variant_get(body, "(u)", &pid);
237 g_object_unref(reply);
242 static message_port_pkt_s *__message_port_recv_raw(int fd)
244 message_port_pkt_s *pkt = NULL;
247 pkt = (message_port_pkt_s *)calloc(sizeof(message_port_pkt_s), 1);
249 /* LCOV_EXCL_START */
255 if (read_string_from_socket(fd, (char **)&pkt->remote_port_name, &pkt->remote_port_name_len) != MESSAGE_PORT_ERROR_NONE) {
256 /* LCOV_EXCL_START */
257 LOGE("read socket fail: port_name");
258 free(pkt->remote_port_name);
264 if (read_socket(fd, (char *)&pkt->is_bidirection, sizeof(pkt->is_bidirection), &nb) != MESSAGE_PORT_ERROR_NONE) {
265 /* LCOV_EXCL_START */
266 LOGE("read socket fail: is_bidirection");
267 free(pkt->remote_port_name);
273 if (read_socket(fd, (char *)&pkt->is_trusted, sizeof(pkt->is_trusted), &nb) != MESSAGE_PORT_ERROR_NONE) {
274 /* LCOV_EXCL_START */
275 LOGE("read socket fail: is_trusted");
276 free(pkt->remote_port_name);
282 if (read_string_from_socket(fd, (char **)&pkt->data, &pkt->data_len) != MESSAGE_PORT_ERROR_NONE) {
283 /* LCOV_EXCL_START */
284 LOGE("read socket fail: data");
287 free(pkt->remote_port_name);
296 static bool __validate_callback_info(message_port_callback_info_s *callback_info)
300 cb_list = g_list_find(__callback_info_list, callback_info);
301 if (cb_list == NULL) {
302 _LOGI("local_info : %p is already released from list", callback_info);
309 static bool __validate_local_info(int local_id)
313 cb_list = g_hash_table_lookup(__local_port_info, GUINT_TO_POINTER(local_id));
314 if (cb_list == NULL) {
315 _LOGI("local_info : %d is already released", local_id);
322 static gboolean __socket_request_handler(GIOChannel *gio,
327 message_port_callback_info_s *callback_info;
328 message_port_pkt_s *pkt = NULL;
329 message_port_local_port_info_s *local_port_info;
334 callback_info = (message_port_callback_info_s *)data;
335 if (callback_info == NULL)
338 message_port_lock_mutex();
339 if (__validate_callback_info(callback_info) == false) {
345 if (__validate_local_info(callback_info->local_id) == false) {
350 local_port_info = callback_info->local_info;
351 if (local_port_info == NULL || local_port_info->callback == NULL) {
352 _LOGE("Failed to get callback info");
357 if (cond == G_IO_HUP) {
358 _LOGI("socket G_IO_HUP");
363 fd = g_io_channel_unix_get_fd(gio);
365 _LOGE("fail to get fd from io channel");
370 pkt = __message_port_recv_raw(fd);
372 _LOGE("recv error on SOCKET");
377 kb = bundle_decode(pkt->data, pkt->data_len);
379 _LOGE("Invalid argument : message");
384 if (pkt->is_bidirection)
385 local_port_info->callback(callback_info->local_id,
386 callback_info->remote_app_id, pkt->remote_port_name,
387 pkt->is_trusted, kb, local_port_info->user_data);
389 local_port_info->callback(callback_info->local_id,
390 callback_info->remote_app_id, NULL,
391 pkt->is_trusted, kb, local_port_info->user_data);
397 if (pkt->remote_port_name)
398 free(pkt->remote_port_name);
404 if (ret == FALSE && existed == TRUE)
405 __callback_info_free_by_info(callback_info);
407 message_port_unlock_mutex();
412 static message_port_callback_info_s *__create_callback_info(message_port_local_port_info_s *mi, char *local_appid)
414 message_port_local_port_info_s *local_info = NULL;
415 message_port_callback_info_s *callback_info = NULL;
418 callback_info = (message_port_callback_info_s *)calloc(1, sizeof(message_port_callback_info_s));
419 if (callback_info == NULL) {
420 /* LCOV_EXCL_START */
421 _LOGE("out of memory");
426 local_info = (message_port_local_port_info_s *)calloc(1, sizeof(message_port_local_port_info_s));
427 if (local_info == NULL) {
428 /* LCOV_EXCL_START */
430 _LOGE("out of memory");
435 callback_info->local_id = mi->local_id;
436 callback_info->local_info = local_info;
437 callback_info->remote_app_id = strdup(local_appid);
438 if (callback_info->remote_app_id == NULL) {
439 /* LCOV_EXCL_START */
441 _LOGE("out of memory");
446 local_info->port_name = strdup(mi->port_name);
447 if (local_info->port_name == NULL) {
448 /* LCOV_EXCL_START */
450 _LOGE("out of memory");
455 local_info->callback = mi->callback;
456 local_info->is_trusted = mi->is_trusted;
457 local_info->local_id = mi->local_id;
458 local_info->user_data = mi->user_data;
462 __callback_info_free(callback_info);
466 return callback_info;
469 static void __callback_info_append(message_port_callback_info_s *callback_info)
471 __callback_info_list = g_list_append(__callback_info_list, callback_info);
474 static void __callback_info_update_user_data(int local_id, message_port_message_cb callback, void *user_data)
477 message_port_callback_info_s *callback_info;
479 /* LCOV_EXCL_START */
480 for (iter = __callback_info_list; iter != NULL; iter = iter->next) {
481 callback_info = (message_port_callback_info_s *)iter->data;
482 if (callback_info->local_id == local_id
483 && callback_info->local_info != NULL) {
484 callback_info->local_info->callback = callback;
485 callback_info->local_info->user_data = user_data;
491 static bool __receive_message(GVariant *parameters, GDBusMethodInvocation *invocation)
493 char *local_port = NULL;
494 char *local_appid = NULL;
495 char *remote_appid = NULL;
496 char *remote_port = NULL;
497 gboolean local_trusted = false;
498 gboolean remote_trusted = false;
499 gboolean bi_dir = false;
503 bundle_raw *raw = NULL;
504 message_port_local_port_info_s *mi;
505 int local_reg_id = 0;
506 message_port_callback_info_s *callback_info = NULL;
510 GUnixFDList *fd_list;
512 int *returned_fds = NULL;
517 message_port_lock_mutex();
518 g_variant_get(parameters, "(&s&sbb&s&sbu&s)", &local_appid, &local_port, &local_trusted, &bi_dir,
519 &remote_appid, &remote_port, &remote_trusted, &len, &raw);
522 _LOGE("Invalid argument : remote_port is NULL");
526 _LOGE("Invalid argument : remote_appid is NULL");
531 _LOGE("Invalid argument : local_appid");
535 if (!is_local_port_registed(remote_port, remote_trusted, &local_reg_id, &mi)) {
536 _LOGE("Invalid argument : remote_port:(%s) trusted(%d)", remote_port, remote_trusted);
540 callback_info = __create_callback_info(mi, local_appid);
541 if (callback_info == NULL) {
546 _LOGE("Invalid argument : local_port");
549 if (strcmp(remote_appid, app_id) != 0) {
550 _LOGE("Invalid argument : remote_appid (%s)", remote_appid);
553 if (strcmp(remote_port, callback_info->local_info->port_name) != 0) {
554 _LOGE("Invalid argument : remote_port (%s)", remote_port);
558 _LOGE("Invalid argument : data_len");
561 if (remote_trusted) {
562 /* LCOV_EXCL_START */
563 if (g_hash_table_lookup(__trusted_app_list_hash, (gpointer)local_appid) == NULL) {
564 if (!is_preloaded(local_appid, remote_appid)) {
565 int ret = check_certificate(local_appid, remote_appid);
566 if (ret == MESSAGE_PORT_ERROR_NONE) {
567 key_appid = strdup(local_appid);
569 g_hash_table_insert(__trusted_app_list_hash, key_appid, "TRUE");
571 _LOGE("The application (%s) is not signed with the same certificate",
580 data = bundle_decode(raw, len);
582 _LOGE("Invalid argument : message");
586 LOGD("call calback %s", local_appid);
588 callback_info->local_info->callback(callback_info->local_info->local_id,
589 local_appid, local_port, local_trusted, data, callback_info->local_info->user_data);
591 callback_info->local_info->callback(callback_info->local_info->local_id,
592 local_appid, NULL, false, data, callback_info->local_info->user_data);
597 msg = g_dbus_method_invocation_get_message(invocation);
598 fd_list = g_dbus_message_get_unix_fd_list(msg);
600 /* When application send message to self fd_list is NULL */
601 if (fd_list != NULL) {
602 returned_fds = g_unix_fd_list_steal_fds(fd_list, &fd_len);
603 if (returned_fds == NULL) {
604 _LOGE("fail to get fds");
608 fd = returned_fds[0];
610 LOGI("g_unix_fd_list_get %d fd: [%d]", fd_len, fd);
612 callback_info->gio_read = g_io_channel_unix_new(fd);
613 if (!callback_info->gio_read) {
614 _LOGE("Error is %s\n", strerror_r(errno, buf, sizeof(buf)));
619 callback_info->g_src_id = g_io_add_watch_full(
620 callback_info->gio_read,
623 __socket_request_handler, callback_info,
625 if (callback_info->g_src_id == 0) {
626 _LOGE("fail to add watch on socket");
630 __callback_info_append(callback_info);
635 message_port_unlock_mutex();
637 __callback_info_free(callback_info);
640 g_free(returned_fds);
645 static void __on_sender_name_appeared(GDBusConnection *connection,
647 const gchar *name_owner,
650 _LOGI("sender name appeared : %s", name);
653 static void __on_sender_name_vanished(GDBusConnection *connection,
657 int *watcher_id = (int *)user_data;
660 local_appid = (char *)g_hash_table_lookup(__sender_appid_hash, name);
662 g_hash_table_remove(__trusted_app_list_hash, (gpointer)local_appid);
663 g_hash_table_remove(__sender_appid_hash, (gpointer)name);
668 g_bus_unwatch_name(*watcher_id);
670 LOGE("Invalid watcher_id %d", *watcher_id);
673 LOGE("watcher_id is NULL");
677 static bool __check_sender_validation(GVariant *parameters, const char *sender, GDBusConnection *conn)
680 char buffer[MAX_PACKAGE_STR_SIZE] = {0, };
681 char *local_appid = NULL;
682 int pid = __get_sender_pid(conn, sender);
683 int *watcher_id = (int *)calloc(1, sizeof(int));
686 retvm_if(!watcher_id, false, "Malloc failed");
688 ret = aul_app_get_appid_bypid(pid, buffer, sizeof(buffer));
689 if (ret != AUL_R_OK) {
690 _LOGE("Failed to get the sender ID: (%s) (%d)", sender, pid);
695 g_variant_get_child(parameters, 0, "&s", &local_appid);
696 if (local_appid == NULL) {
697 _LOGE("appid is NULL : (%s) (%d)", sender, pid);
702 if (strncmp(buffer, local_appid, MAX_PACKAGE_STR_SIZE) == 0) {
703 _LOGD("insert sender !!!!! %s", sender);
704 _sender = strdup(sender);
705 if (_sender == NULL) {
706 /* LCOV_EXCL_START */
707 _LOGE("out of memory");
713 _appid = strdup(local_appid);
714 if (_appid == NULL) {
715 /* LCOV_EXCL_START */
716 _LOGE("out of memory");
723 g_hash_table_insert(__sender_appid_hash, (gpointer)_sender, (gpointer)_appid);
724 *watcher_id = g_bus_watch_name_on_connection(
727 G_BUS_NAME_WATCHER_FLAGS_NONE,
728 __on_sender_name_appeared,
729 __on_sender_name_vanished,
738 /* LCOV_EXCL_START */
739 static void __close_socket(GDBusMethodInvocation *invocation)
742 GUnixFDList *fd_list;
744 int *returned_fds = NULL;
746 msg = g_dbus_method_invocation_get_message(invocation);
747 fd_list = g_dbus_message_get_unix_fd_list(msg);
748 if (fd_list != NULL) {
749 returned_fds = g_unix_fd_list_steal_fds(fd_list, &fd_len);
750 if (returned_fds != NULL) {
751 close(returned_fds[0]);
752 g_free(returned_fds);
757 static void __dbus_method_call_handler(GDBusConnection *conn,
758 const gchar *sender, const gchar *object_path,
759 const gchar *iface_name, const gchar *method_name,
760 GVariant *parameters, GDBusMethodInvocation *invocation,
763 _LOGI("method_name: %s, sender: %s", method_name, sender);
764 gpointer sender_appid = g_hash_table_lookup(__sender_appid_hash, sender);
765 if (sender_appid == NULL) {
766 if (!__check_sender_validation(parameters, sender, conn)) {
767 _LOGE("Failed to validate");
768 __close_socket(invocation);
773 if (g_strcmp0(method_name, "send_message") == 0)
774 __receive_message(parameters, invocation);
776 g_dbus_method_invocation_return_value(invocation, NULL);
779 static const GDBusInterfaceVTable interface_vtable = {
780 __dbus_method_call_handler,
785 static bool __message_port_register_port(const int local_id, const char *local_port, bool is_trusted, message_port_message_cb callback, void *user_data)
787 message_port_local_port_info_s *mi = (message_port_local_port_info_s *)calloc(1, sizeof(message_port_local_port_info_s));
788 retvm_if(!mi, false, "Malloc failed");
790 mi->callback = callback;
791 mi->is_trusted = is_trusted;
792 mi->port_name = strdup(local_port);
793 if (mi->port_name == NULL) {
794 /* LCOV_EXCL_START */
795 _LOGE("Malloc failed (%s)", local_port);
800 mi->local_id = local_id;
801 mi->user_data = user_data;
803 g_hash_table_insert(__local_port_info, GINT_TO_POINTER(mi->local_id), mi);
807 static int __register_dbus_interface(const char *port_name,
808 bool is_trusted, message_port_message_cb callback, void *user_data)
810 GDBusNodeInfo *introspection_data = NULL;
811 int registration_id = 0;
812 int ret = MESSAGE_PORT_ERROR_NONE;
814 static gchar introspection_prefix[] =
816 " <interface name='";
818 static gchar introspection_postfix[] =
820 " <method name='send_message'>"
821 " <arg type='s' name='local_appid' direction='in'/>"
822 " <arg type='s' name='local_port' direction='in'/>"
823 " <arg type='b' name='local_trusted' direction='in'/>"
824 " <arg type='b' name='bi_dir' direction='in'/>"
825 " <arg type='s' name='remote_appid' direction='in'/>"
826 " <arg type='s' name='remote_port' direction='in'/>"
827 " <arg type='b' name='remote_trusted' direction='in'/>"
828 " <arg type='u' name='data_len' direction='in'/>"
829 " <arg type='s' name='data' direction='in'/>"
834 char *introspection_xml = NULL;
835 int introspection_xml_len = 0;
838 GError *error = NULL;
839 char *bus_name = NULL;
840 char *interface_name = NULL;
841 GVariant *result = NULL;
843 bus_name = get_encoded_name(app_id, port_name, is_trusted);
845 _LOGE("Fail to get bus name");
848 interface_name = bus_name;
850 introspection_xml_len = strlen(introspection_prefix) + strlen(interface_name) +
851 strlen(introspection_postfix) + 1;
853 introspection_xml = (char *)calloc(introspection_xml_len, sizeof(char));
854 if (!introspection_xml) {
855 /* LCOV_EXCL_START */
856 _LOGE("out of memory");
861 snprintf(introspection_xml, introspection_xml_len, "%s%s%s", introspection_prefix, interface_name, introspection_postfix);
863 introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
864 if (!introspection_data) {
865 ret = MESSAGE_PORT_ERROR_IO_ERROR;
866 _LOGE("g_dbus_node_info_new_for_xml() is failed.");
870 registration_id = g_dbus_connection_register_object(gdbus_conn,
871 MESSAGEPORT_OBJECT_PATH, introspection_data->interfaces[0],
872 &interface_vtable, NULL, NULL, NULL);
874 _LOGD("registration_id %d", registration_id);
876 if (registration_id == 0) {
877 ret = MESSAGE_PORT_ERROR_IO_ERROR;
878 _LOGE("Failed to g_dbus_connection_register_object");
882 if (!__message_port_register_port(registration_id, port_name, is_trusted,
883 callback, user_data)) {
884 ret = MESSAGE_PORT_ERROR_OUT_OF_MEMORY;
888 result = g_dbus_connection_call_sync(
894 g_variant_new("(su)", bus_name, G_BUS_NAME_OWNER_FLAGS_NONE),
895 G_VARIANT_TYPE("(u)"),
896 G_DBUS_CALL_FLAGS_NONE,
901 _LOGE("RequestName fail : %s", error->message);
902 ret = MESSAGE_PORT_ERROR_IO_ERROR;
906 if (result == NULL) {
907 ret = MESSAGE_PORT_ERROR_IO_ERROR;
908 _LOGE("fail to get name NULL");
911 g_variant_get(result, "(u)", &owner_id);
913 ret = MESSAGE_PORT_ERROR_IO_ERROR;
914 _LOGE("Acquiring the own name is failed");
918 _LOGI("Acquiring the own name : %d", owner_id);
921 if (introspection_data)
922 g_dbus_node_info_unref(introspection_data);
923 if (introspection_xml)
924 free(introspection_xml);
928 g_variant_unref(result);
930 if (ret != MESSAGE_PORT_ERROR_NONE) {
931 if (registration_id != 0)
932 g_hash_table_remove(__local_port_info, GINT_TO_POINTER(registration_id));
933 registration_id = ret;
936 return registration_id;
939 int get_local_port_info(int id, message_port_local_port_info_s **info)
941 message_port_local_port_info_s *mi = (message_port_local_port_info_s *)g_hash_table_lookup(__local_port_info, GINT_TO_POINTER(id));
944 return MESSAGE_PORT_ERROR_PORT_NOT_FOUND;
947 return MESSAGE_PORT_ERROR_NONE;
950 int register_message_port(const char *local_port, bool is_trusted, message_port_message_cb callback, void *user_data)
952 _SECURE_LOGI("local_port : [%s:%s]", local_port, is_trusted ? "trusted" : "non-trusted");
955 message_port_local_port_info_s *port_info;
958 return MESSAGE_PORT_ERROR_IO_ERROR;
961 /* Check the message port is already registed */
962 if (is_local_port_registed(local_port, is_trusted, &local_id, &port_info)) {
963 port_info->callback = callback;
964 port_info->user_data = user_data;
965 __callback_info_update_user_data(local_id, callback, user_data);
969 local_id = __register_dbus_interface(local_port, is_trusted, callback, user_data);
971 _LOGE("register_dbus_interface fail !!");
976 int unregister_local_port(int local_port_id, bool trusted_port)
980 char *bus_name = NULL;
983 message_port_local_port_info_s *mi;
985 _LOGI("unregister : %d", local_port_id);
989 return MESSAGE_PORT_ERROR_IO_ERROR;
992 mi = (message_port_local_port_info_s *)
993 g_hash_table_lookup(__local_port_info, GINT_TO_POINTER(local_port_id));
995 return MESSAGE_PORT_ERROR_PORT_NOT_FOUND;
997 if (mi->is_trusted != trusted_port)
998 return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
1000 __callback_info_free_by_local_id(local_port_id);
1002 bus_name = get_encoded_name(app_id, mi->port_name, mi->is_trusted);
1003 if (bus_name == NULL)
1004 return MESSAGE_PORT_ERROR_OUT_OF_MEMORY;
1006 g_dbus_connection_unregister_object(gdbus_conn, local_port_id);
1008 result = g_dbus_connection_call_sync(
1012 DBUS_INTERFACE_DBUS,
1014 g_variant_new("(s)", bus_name),
1015 G_VARIANT_TYPE("(u)"),
1016 G_DBUS_CALL_FLAGS_NONE,
1025 _LOGE("RequestName fail : %s", err->message);
1027 return MESSAGE_PORT_ERROR_PORT_NOT_FOUND;
1029 g_variant_get(result, "(u)", &ret);
1032 g_variant_unref(result);
1033 /* LCOV_EXCL_START */
1034 if (ret != DBUS_RELEASE_NAME_REPLY_RELEASED) {
1035 if (ret == DBUS_RELEASE_NAME_REPLY_NON_EXISTENT) {
1036 _LOGE("Port Not exist");
1037 return MESSAGE_PORT_ERROR_PORT_NOT_FOUND;
1038 } else if (ret == DBUS_RELEASE_NAME_REPLY_NOT_OWNER) {
1039 _LOGE("Try to release not owned name. MESSAGE_PORT_ERROR_INVALID_PARAMETER");
1040 return MESSAGE_PORT_ERROR_INVALID_PARAMETER;
1043 /* LCOV_EXCL_STOP */
1044 g_hash_table_remove(__local_port_info, GINT_TO_POINTER(local_port_id));
1046 return MESSAGE_PORT_ERROR_NONE;