719a947cdde3466931e680bfd0bc1d8f4ed05d40
[platform/core/appfw/message-port.git] / src / message-port.c
1
2 // Message Port
3 // Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        message-port.cpp
20  * @brief       This is the implementation file for the MessagePort.
21  */
22
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <glib.h>
26 #include <gio/gio.h>
27 #include <aul/aul.h>
28 #include <openssl/md5.h>
29 #include <bundle.h>
30 #include <bundle_internal.h>
31 #include <pkgmgr-info.h>
32
33 #include "message-port.h"
34 #include "message-port-log.h"
35
36
37 #define MAX_PACKAGE_STR_SIZE 512
38 #define MESSAGEPORT_BUS_NAME_PREFIX "org.tizen.messageport._"
39 #define MESSAGEPORT_OBJECT_PATH "/org/tizen/messageport"
40 #define MESSAGEPORT_INTERFACE "org.tizen.messageport"
41 #define MESSAGEPORT_INTERFACE_PREFIX "org.tizen.messageport._"
42
43
44
45 #define retvm_if(expr, val, fmt, arg...) do { \
46         if (expr) { \
47                 _LOGE(fmt, ##arg); \
48                 _LOGE("(%s) -> %s() return", #expr, __func__); \
49                 return val; \
50         } \
51 } while (0)
52
53 #define retv_if(expr, val) do { \
54         if (expr) { \
55                 _LOGE("(%s) -> %s() return", #expr, __func__); \
56                 return val; \
57         } \
58 } while (0)
59
60 #define FREE_AND_NULL(ptr) do { \
61         if (ptr) { \
62                 free((void *)ptr); \
63                 ptr = NULL; \
64         } \
65 } while (0)
66
67 static bool _initialized = false;
68 static GDBusConnection *__gdbus_conn = NULL;
69 static char *__app_id;
70 static GHashTable *__local_port_info = NULL;
71 static GHashTable *__remote_port_info = NULL;;
72 static GHashTable *__sender_appid_hash = NULL;;
73 static GHashTable *__checked_app_list_hash = NULL;
74 static GHashTable *__trusted_app_list_hash = NULL;
75 static const int MAX_MESSAGE_SIZE = 16 * 1024;
76
77
78
79 enum __certificate_info_type {
80         UNKNOWN = 0,
81         CERTIFICATE_MATCH,
82         CERTIFICATE_NOT_MATCH,
83 };
84
85 typedef struct message_port_local_port_info {
86         messageport_message_cb callback;
87         bool is_trusted;
88         char *port_name;
89         int local_id;
90 } message_port_local_port_info_s;
91
92 typedef struct message_port_remote_port_info {
93         char *encoded_bus_name;
94         char *sender_id;
95         char *remote_app_id;
96         int certificate_info;
97         int watcher_id;
98         GList *port_list;
99 } message_port_remote_app_info_s;
100
101 typedef struct port_list_info {
102         char *port_name;
103         bool is_trusted;
104         bool exist;
105 } port_list_info_s;
106
107 static char *__get_encoded_name(const char *name, const char *prefix, int prefix_len,
108                                 const char *postfix, int postfix_len)
109 {
110         unsigned char c[MD5_DIGEST_LENGTH] = {0};
111         char *md5_interface = NULL;
112         char *temp;
113         int index = 0;
114         MD5_CTX mdContext;
115         int interface_len = prefix_len + postfix_len + (MD5_DIGEST_LENGTH * 2) + 2;
116
117         MD5_Init(&mdContext);
118         MD5_Update(&mdContext, name, strlen(name));
119         MD5_Final(c, &mdContext);
120
121         md5_interface = (char *)calloc(interface_len , sizeof(char));
122         if (md5_interface == NULL) {
123                 _LOGI("Malloc failed!!");
124                 return 0;
125         }
126
127         snprintf(md5_interface, interface_len, "%s", prefix);
128         temp = md5_interface;
129         temp += prefix_len;
130
131         for (index = 0; index < MD5_DIGEST_LENGTH; index++) {
132                 snprintf(temp, 3, "%02x", c[index]);
133                 temp += 2;
134         }
135
136         if (postfix && postfix_len > 0) {
137                 snprintf(temp, interface_len - (temp - md5_interface), "_%s", postfix);
138         }
139
140         return md5_interface;
141 }
142
143 static char *__get_interface_name(const char *port_name, bool is_trusted)
144 {
145         char *interface_name = NULL;
146
147         interface_name = __get_encoded_name(port_name,
148                                         MESSAGEPORT_INTERFACE_PREFIX,
149                                         strlen(MESSAGEPORT_INTERFACE_PREFIX),
150                                         is_trusted ? "1" : "0", 1);
151
152         if (!interface_name) {
153                 _LOGE("failed to get interface name ");
154         }
155
156         return interface_name;
157 }
158
159 static char *__get_bus_name(const char *remote_app_id)
160 {
161         char *bus_name = NULL;
162
163         bus_name = __get_encoded_name(remote_app_id,
164                                         MESSAGEPORT_BUS_NAME_PREFIX,
165                                         strlen(MESSAGEPORT_BUS_NAME_PREFIX),
166                                         NULL, 0);
167         if (!bus_name) {
168                 _LOGE("fail to get bus name");
169         }
170         return bus_name;
171 }
172
173 static int __remote_port_compare_cb(gconstpointer a, gconstpointer b)
174 {
175         port_list_info_s *key1 = (port_list_info_s *)a;
176         port_list_info_s *key2 = (port_list_info_s *)b;
177
178         if (key1->is_trusted == key2->is_trusted) {
179                 return strcmp(key1->port_name, key2->port_name);
180         }
181
182         return 1;
183 }
184
185
186 static bool __is_preloaded(const char *local_appid, const char *remote_appid)
187 {
188         _LOGI("IsPreloaded");
189
190         bool preload_local = false;
191         bool preload_remote = false;
192
193         pkgmgrinfo_appinfo_h handle = NULL;
194         int ret = pkgmgrinfo_appinfo_get_usr_appinfo(local_appid, getuid(), &handle);
195         if (ret != PMINFO_R_OK) {
196                 _LOGE("Failed to get the appinfo. %d", ret);
197                 pkgmgrinfo_appinfo_destroy_appinfo(handle);
198                 return false;
199         }
200         ret = pkgmgrinfo_appinfo_is_preload(handle, &preload_local);
201         if (ret != PMINFO_R_OK) {
202                 _LOGE("Failed to check the preloaded application. %d", ret);
203                 pkgmgrinfo_appinfo_destroy_appinfo(handle);
204                 return false;
205         }
206         ret = pkgmgrinfo_appinfo_get_usr_appinfo(remote_appid, getuid(), &handle);
207         if (ret != PMINFO_R_OK) {
208                 _LOGE("Failed to get the appinfo. %d", ret);
209                 pkgmgrinfo_appinfo_destroy_appinfo(handle);
210                 return false;
211         }
212         ret = pkgmgrinfo_appinfo_is_preload(handle, &preload_remote);
213         if (ret != PMINFO_R_OK) {
214                 _LOGE("Failed to check the preloaded application. %d", ret);
215                 pkgmgrinfo_appinfo_destroy_appinfo(handle);
216                 return false;
217         }
218
219         if (preload_local && preload_remote) {
220                 pkgmgrinfo_appinfo_destroy_appinfo(handle);
221                 return true;
222         }
223         pkgmgrinfo_appinfo_destroy_appinfo(handle);
224         return false;
225 }
226
227 static int __check_certificate(const char *local_appid, const char *remote_appid)
228 {
229         _LOGI("CheckCertificate");
230
231         pkgmgrinfo_cert_compare_result_type_e res;
232         int ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(local_appid, remote_appid, getuid(), &res);
233         if (ret < 0) {
234                 _LOGE(":CheckCertificate() Failed");
235                 return MESSAGEPORT_ERROR_IO_ERROR;
236         }
237         if (res != PMINFO_CERT_COMPARE_MATCH) {
238                 _LOGE("CheckCertificate() Failed : MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH");
239                 return MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH;
240         }
241
242         return MESSAGEPORT_ERROR_NONE;
243 }
244
245 static void on_name_appeared (GDBusConnection *connection,
246                 const gchar     *name,
247                 const gchar     *name_owner,
248                 gpointer         user_data)
249 {
250         _LOGI("name appeared : %s %s", __app_id, name);
251 }
252
253 static void on_name_vanished (GDBusConnection *connection,
254                 const gchar     *name,
255                 gpointer         user_data)
256 {
257         _LOGI("name vanished : %s", name);
258         message_port_remote_app_info_s *remote_app_info = (message_port_remote_app_info_s *)user_data;
259         g_bus_unwatch_name(remote_app_info->watcher_id);
260         g_hash_table_remove(__remote_port_info, remote_app_info->remote_app_id);
261 }
262
263 static void __hash_destory_list_value(gpointer data)
264 {
265         GList *list = (GList *)data;
266         g_list_foreach(list, (GFunc)g_free, NULL);
267         g_list_free(list);
268         list = NULL;
269 }
270
271 static void __set_checked_app_list(message_port_local_port_info_s *mi, char *remote_appid) {
272
273         GList *app_list = (GList *)g_hash_table_lookup(__checked_app_list_hash, mi->port_name);
274         if (app_list == NULL) {
275                 app_list = g_list_append(app_list, strdup(remote_appid));
276                 _LOGI("set checked_app_list appid: %s", remote_appid);
277                 g_hash_table_insert(__checked_app_list_hash, mi->port_name, app_list);
278         } else {
279                 GList *app = g_list_find(app_list, (gpointer)remote_appid);
280                 if (app == NULL) {
281                         app_list = g_list_append(app_list, strdup(remote_appid));
282                         _LOGI("set checked_app_list appid: %s", remote_appid);
283                 }
284         }
285 }
286
287 static int __get_local_port_info(int id, message_port_local_port_info_s **info)
288 {
289         message_port_local_port_info_s *mi = (message_port_local_port_info_s *)g_hash_table_lookup(__local_port_info, GINT_TO_POINTER(id));
290
291         if (mi == NULL) {
292                 return MESSAGEPORT_ERROR_INVALID_PARAMETER;
293         }
294         *info = mi;
295
296         return MESSAGEPORT_ERROR_NONE;
297 }
298
299 static port_list_info_s *__set_remote_port_info(const char *remote_app_id, const char *remote_port, bool is_trusted)
300 {
301         int ret_val = MESSAGEPORT_ERROR_NONE;
302         port_list_info_s *port_info = (port_list_info_s *)calloc(1, sizeof(port_list_info_s));
303
304         if (!port_info) {
305                 ret_val = MESSAGEPORT_ERROR_OUT_OF_MEMORY;
306                 goto out;
307         }
308         port_info->port_name = strdup(remote_port);
309         if (!port_info->port_name) {
310                 ret_val = MESSAGEPORT_ERROR_OUT_OF_MEMORY;
311                 goto out;
312         }
313         port_info->is_trusted = is_trusted;
314
315         out:
316         if (ret_val != MESSAGEPORT_ERROR_NONE) {
317                 if (port_info) {
318                         FREE_AND_NULL(port_info->port_name);
319                         free(port_info);
320                 }
321                 return NULL;
322         }
323         return port_info;
324 }
325
326 static message_port_remote_app_info_s *__set_remote_app_info(const char *remote_app_id, const char *remote_port, bool is_trusted)
327 {
328         port_list_info_s *port_info = NULL;
329         message_port_remote_app_info_s *remote_app_info = NULL;
330         int ret_val = MESSAGEPORT_ERROR_NONE;
331
332         remote_app_info = (message_port_remote_app_info_s *)calloc(1, sizeof(message_port_remote_app_info_s));
333         if (!remote_app_info) {
334                 ret_val = MESSAGEPORT_ERROR_OUT_OF_MEMORY;
335                 goto out;
336         }
337
338         remote_app_info->encoded_bus_name = __get_bus_name(remote_app_id);
339         if (remote_app_info->encoded_bus_name == NULL) {
340                 ret_val = MESSAGEPORT_ERROR_OUT_OF_MEMORY;
341                 goto out;
342         }
343
344         remote_app_info->remote_app_id = strdup(remote_app_id);
345         if (remote_app_info->remote_app_id == NULL) {
346                 ret_val = MESSAGEPORT_ERROR_OUT_OF_MEMORY;;
347                 goto out;
348         }
349
350         remote_app_info->watcher_id = g_bus_watch_name(G_BUS_TYPE_SESSION,
351                 remote_app_info->encoded_bus_name,
352                 G_BUS_NAME_WATCHER_FLAGS_NONE,
353                 on_name_appeared,
354                 on_name_vanished,
355                 remote_app_info,
356                 NULL);
357
358         port_info = __set_remote_port_info(remote_app_id, remote_port, is_trusted);
359         if (port_info == NULL) {
360                 ret_val = MESSAGEPORT_ERROR_OUT_OF_MEMORY;
361                 goto out;
362         }
363
364         remote_app_info->port_list = g_list_append(remote_app_info->port_list, port_info);
365
366         out:
367         if (ret_val != MESSAGEPORT_ERROR_NONE) {
368                 if (remote_app_info) {
369                         FREE_AND_NULL(remote_app_info->encoded_bus_name);
370                         FREE_AND_NULL(remote_app_info->remote_app_id);
371                         FREE_AND_NULL(remote_app_info);
372                 }
373                 return NULL;
374         }
375         return remote_app_info;
376 }
377
378 static int __get_remote_port_info(const char *remote_app_id, const char *remote_port, bool is_trusted,
379                 message_port_remote_app_info_s **mri, port_list_info_s **pli)
380 {
381         message_port_remote_app_info_s *remote_app_info = NULL;
382         port_list_info_s port_info;
383         GList *cb_list = NULL;
384
385         remote_app_info = (message_port_remote_app_info_s *)g_hash_table_lookup(__remote_port_info, remote_app_id);
386
387         if (remote_app_info == NULL) {
388                 remote_app_info = __set_remote_app_info(remote_app_id, remote_port, is_trusted);
389                 retvm_if(!remote_app_info, MESSAGEPORT_ERROR_OUT_OF_MEMORY, "fail to create message_port_remote_app_info_s");
390                 g_hash_table_insert(__remote_port_info, remote_app_info->remote_app_id, remote_app_info);
391
392         }
393         *mri = remote_app_info;
394
395         port_info.port_name = strdup(remote_port);
396         port_info.is_trusted = is_trusted;
397         cb_list = g_list_find_custom(remote_app_info->port_list, &port_info,
398                                         (GCompareFunc)__remote_port_compare_cb);
399         if (port_info.port_name)
400                 free(port_info.port_name);
401         if (cb_list == NULL) {
402                 port_list_info_s *tmp = __set_remote_port_info(remote_app_id, remote_port, is_trusted);
403                 retvm_if(!tmp, MESSAGEPORT_ERROR_OUT_OF_MEMORY, "fail to create port_list_info_s");
404                 remote_app_info->port_list = g_list_append(remote_app_info->port_list, tmp);
405                 *pli = tmp;
406         } else {
407                 *pli = (port_list_info_s *)cb_list->data;
408         }
409         return MESSAGEPORT_ERROR_NONE;
410 }
411
412 static bool __is_local_port_registed(const char *local_port, bool trusted, int *local_id, message_port_local_port_info_s **lpi)
413 {
414         GHashTableIter iter;
415         gpointer key, value;
416
417         g_hash_table_iter_init(&iter, __local_port_info);
418
419         while (g_hash_table_iter_next(&iter, &key, &value)) {
420                 message_port_local_port_info_s *mi = (message_port_local_port_info_s *)value;
421
422                 if ((mi->is_trusted == trusted) && strcmp(mi->port_name, local_port) == 0) {
423                         *local_id = mi->local_id;
424                         if (lpi != NULL) {
425                                 *lpi = mi;
426                         }
427                         return true;
428                 }
429         }
430         return false;
431 }
432
433 static int __get_sender_pid(GDBusConnection *conn, const char *sender_name)
434 {
435         GDBusMessage *msg = NULL;
436         GDBusMessage *reply = NULL;
437         GError *err = NULL;
438         GVariant *body;
439         int pid = 0;
440
441         msg = g_dbus_message_new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus",
442                         "org.freedesktop.DBus", "GetConnectionUnixProcessID");
443         if (!msg) {
444                 _LOGE("Can't allocate new method call");
445                 goto out;
446         }
447
448         g_dbus_message_set_body (msg, g_variant_new ("(s)", sender_name));
449         reply = g_dbus_connection_send_message_with_reply_sync(conn, msg,
450                                                         G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
451
452         if (!reply) {
453                 if (err != NULL) {
454                         _LOGE("Failed to get pid [%s]", err->message);
455                         g_error_free(err);
456                 }
457                 goto out;
458         }
459
460         body = g_dbus_message_get_body(reply);
461         g_variant_get(body, "(u)", &pid);
462
463 out:
464         if (msg)
465                 g_object_unref(msg);
466         if (reply)
467                 g_object_unref(reply);
468
469         return pid;
470 }
471
472
473 static bool send_message(GVariant *parameters)
474 {
475         char *local_port = NULL;
476         char *local_appid = NULL;
477         char *remote_appid = NULL;
478         char *remote_port = NULL;
479         gboolean local_trusted = false;
480         gboolean remote_trusted = false;
481         gboolean bi_dir = false;
482         int len = 0;
483
484         bundle *data = NULL;
485         bundle_raw *raw = NULL;
486         message_port_local_port_info_s *mi;
487         int local_reg_id = 0;
488
489         g_variant_get(parameters, "(ssbbssbus)", &local_appid, &local_port, &local_trusted, &bi_dir,
490                         &remote_appid, &remote_port, &remote_trusted, &len, &raw);
491
492         if (!remote_port) {
493                 _LOGE("Invalid argument : remote_port is NULL");
494                 goto out;
495         }
496         if (!remote_appid) {
497                 _LOGE("Invalid argument : remote_appid is NULL");
498                 goto out;
499         }
500         if (!__is_local_port_registed(remote_port, remote_trusted, &local_reg_id, &mi)) {
501                 _LOGE("Invalid argument : remote_port:(%s) trusted(%d)", remote_port, remote_trusted);
502                 goto out;
503         }
504         if (!local_appid) {
505                 _LOGE("Invalid argument : local_appid");
506                 goto out;
507         }
508         if (!local_port) {
509                 _LOGE("Invalid argument : local_port");
510                 goto out;
511         }
512         if (strcmp(remote_appid, __app_id) != 0) {
513                 _LOGE("Invalid argument : remote_appid (%s)", remote_appid);
514                 goto out;
515         }
516         if (strcmp(remote_port, mi->port_name) != 0) {
517                 _LOGE("Invalid argument : remote_port (%s)", remote_port);
518                 goto out;
519         }
520         if (!len) {
521                 _LOGE("Invalid argument : data_len");
522                 goto out;
523         }
524         if (remote_trusted) {
525                 if (g_hash_table_lookup(__trusted_app_list_hash, (gpointer)local_appid) == NULL) {
526                         if (!__is_preloaded(local_appid, remote_appid)) {
527                                 // Check the certificate
528                                 int ret = __check_certificate(local_appid, remote_appid);
529                                 if (ret == MESSAGEPORT_ERROR_NONE) {
530                                         g_hash_table_insert(__trusted_app_list_hash, local_appid, "TRUE");
531                                 } else {
532                                         _LOGE("The application (%s) is not signed with the same certificate",
533                                                         local_appid);
534                                         goto out;
535                                 }
536                         }
537                 }
538         }
539
540         __set_checked_app_list(mi, local_appid);
541         data = bundle_decode(raw, len);
542         bundle_free_encoded_rawdata(&raw);
543
544         if (!data) {
545                 _LOGE("Invalid argument : message");
546                 goto out;
547         }
548
549         if (bi_dir) {
550                 mi->callback(mi->local_id, local_appid, local_port, local_trusted, data);
551         } else {
552                 mi->callback(mi->local_id, local_appid, NULL, false, data);
553         }
554 out:
555
556         return true;
557 }
558
559 static int unregister_port(GVariant *parameters)
560 {
561         int ret = MESSAGEPORT_ERROR_NONE;
562         char *remote_appid = NULL;
563         char *remote_port = NULL;
564         bool is_trusted;
565         port_list_info_s *port_info = NULL;
566         message_port_remote_app_info_s *remote_app_info = NULL;
567
568         g_variant_get(parameters, "(sbs)", &remote_appid, &is_trusted, &remote_port);
569
570         if (!remote_appid) {
571                 _LOGE("Invalid argument : remote_appid");
572                 ret = MESSAGEPORT_ERROR_INVALID_PARAMETER;
573                 goto out;
574         }
575         if (!remote_port) {
576                 _LOGE("Invalid argument : remote_port");
577                 ret = MESSAGEPORT_ERROR_INVALID_PARAMETER;
578                 goto out;
579         }
580
581         ret = __get_remote_port_info(remote_appid, remote_port, is_trusted, &remote_app_info, &port_info);
582         if (ret != MESSAGEPORT_ERROR_NONE) {
583                 goto out;
584         }
585         port_info->exist = false;
586
587
588         out:
589         if (remote_appid)
590                 g_free(remote_appid);
591         if (remote_port)
592                 g_free(remote_port);
593
594         return ret;
595 }
596
597 static int __check_remote_port(const char *remote_app_id, const char *remote_port, bool is_trusted, bool *exist)
598 {
599         _LOGI("Check a remote port : [%s:%s]", remote_app_id, remote_port);
600
601         GDBusMessage *msg = NULL;
602         GDBusMessage *reply = NULL;
603         GError *err = NULL;
604         GVariant *body;
605         int ret_val = MESSAGEPORT_ERROR_NONE;
606         char *bus_name = NULL;
607         message_port_remote_app_info_s *remote_app_info = NULL;
608         port_list_info_s *port_info = NULL;
609         int local_reg_id = 0;
610         message_port_local_port_info_s *mi = NULL;
611         GDBusNodeInfo *node_info;
612         GDBusInterfaceInfo *interface_info;
613         const gchar *xml_data;
614         char *interface_name = NULL;
615
616         _LOGI("remote_app_id, app_id :[%s : %s] ", remote_app_id, __app_id);
617
618         ret_val = __get_remote_port_info(remote_app_id, remote_port, is_trusted, &remote_app_info, &port_info);
619         if (ret_val != MESSAGEPORT_ERROR_NONE) {
620                 return ret_val;
621         }
622
623         // self check
624         if (strcmp(remote_app_id, __app_id) == 0) {
625
626                 _LOGI("__is_local_port_registed ");
627                 if (!__is_local_port_registed(remote_port, is_trusted, &local_reg_id, &mi)) {
628                         *exist = false;
629                 } else {
630                         *exist = true;
631                 }
632                 _LOGI("__is_local_port_registed : %d ", *exist);
633                 return MESSAGEPORT_ERROR_NONE;
634         }
635
636         port_info->exist = false;
637         bus_name = remote_app_info->encoded_bus_name;
638
639         msg = g_dbus_message_new_method_call(bus_name, MESSAGEPORT_OBJECT_PATH,
640                         "org.freedesktop.DBus.Introspectable",
641                         "Introspect");
642         _LOGI("bus_name, remote app id:[%s : %s] ", bus_name, remote_app_id);
643         if (!msg) {
644                 _LOGI("Can't allocate new method call");
645                 return MESSAGEPORT_ERROR_OUT_OF_MEMORY;
646         }
647
648         g_dbus_message_set_body(msg, NULL);
649         reply = g_dbus_connection_send_message_with_reply_sync(__gdbus_conn, msg,
650                         G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
651
652         if (err || (reply == NULL)) {
653                 if (err) {
654                         _LOGE("No reply. error = %s", err->message);
655                         g_error_free(err);
656                 }
657                 ret_val = MESSAGEPORT_ERROR_RESOURCE_UNAVAILABLE;
658         } else {
659                 body = g_dbus_message_get_body(reply);
660                 g_variant_get(body, "(&s)", &xml_data);
661
662                 node_info = g_dbus_node_info_new_for_xml(xml_data, &err);
663                 if (err) {
664                         LOGE("g_dbus_node_info_new_for_xml [%s]", err->message);
665                         *exist = false;
666                         ret_val = MESSAGEPORT_ERROR_NONE;
667                         goto out;
668                 }
669
670                 interface_name = __get_interface_name(remote_port, is_trusted);
671                 if (interface_name == NULL) {
672                         ret_val = MESSAGEPORT_ERROR_OUT_OF_MEMORY;
673                         goto out;
674                 }
675
676                 LOGI("Lookup interface : %s", interface_name);
677                 interface_info = g_dbus_node_info_lookup_interface(node_info, interface_name);
678                 if (interface_info == NULL) {
679                         LOGE("g_dbus_node_info_lookup_interface NULL %s", interface_name);
680                         *exist = false;
681                         ret_val = MESSAGEPORT_ERROR_NONE;
682                 }
683                 else {
684
685                         if (is_trusted) {
686                                 if (remote_app_info->certificate_info != CERTIFICATE_MATCH) {
687                                         if (!__is_preloaded(__app_id, remote_app_id)) {
688                                                 if (__check_certificate(__app_id, remote_app_id) != MESSAGEPORT_ERROR_NONE) {
689                                                         ret_val = MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH;
690                                                         goto out;
691                                                 }
692                                         }
693                                         remote_app_info->certificate_info = CERTIFICATE_MATCH;
694                                 }
695                         }
696                         port_info->exist = true;
697                         *exist = true;
698                         ret_val = MESSAGEPORT_ERROR_NONE;
699                 }
700
701         }
702 out:
703         if (msg)
704                 g_object_unref(msg);
705         if (reply)
706                 g_object_unref(reply);
707         if (interface_name)
708                 free(interface_name);
709
710         return ret_val;
711 }
712
713 static bool __check_sender_validation(GVariant *parameters, const char *sender, GDBusConnection *conn)
714 {
715         int ret = 0;
716         char buffer[MAX_PACKAGE_STR_SIZE] = {0, };
717         char *local_appid = NULL;
718         int pid = __get_sender_pid(conn, sender);
719
720         ret = aul_app_get_appid_bypid(pid, buffer, sizeof(buffer));
721         retvm_if(ret != AUL_R_OK, false, "Failed to get the sender ID: (%s) (%d)", sender, pid);
722
723         g_variant_get_child(parameters, 0, "s", &local_appid);
724         retvm_if(!local_appid, false, "remote_appid is NULL (%s) (%d)", sender, pid);
725
726         if (strncmp(buffer, local_appid, MAX_PACKAGE_STR_SIZE) == 0) {
727                 g_hash_table_insert(__sender_appid_hash, strdup(sender), GINT_TO_POINTER(pid));
728                 g_free(local_appid);
729         } else {
730                 g_free(local_appid);
731                 return false;
732         }
733         return true;
734 }
735
736 static void __dbus_method_call_handler(GDBusConnection *conn,
737                                 const gchar *sender, const gchar *object_path,
738                                 const gchar *iface_name, const gchar *method_name,
739                                 GVariant *parameters, GDBusMethodInvocation *invocation,
740                                 gpointer user_data)
741 {
742         _LOGI("method_name: %s", method_name);
743          gpointer sender_pid = g_hash_table_lookup(__sender_appid_hash, sender);
744         int ret = MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND;
745         if (sender_pid == NULL) {
746                 if (!__check_sender_validation(parameters, sender, conn))
747                         return;
748         }
749
750         if (g_strcmp0(method_name, "send_message") == 0) {
751                 ret = send_message(parameters);
752         } else if (g_strcmp0(method_name, "unregister_port") == 0) {
753                 ret = unregister_port(parameters);
754                 g_dbus_method_invocation_return_value(invocation,
755                                 g_variant_new("(i)", ret));
756         }
757
758
759 }
760
761 static const GDBusInterfaceVTable interface_vtable = {
762         __dbus_method_call_handler,
763         NULL,
764         NULL
765 };
766
767 static int __dbus_init(void)
768 {
769         int owner_id = 0;
770         char *bus_name = NULL;
771         bool ret = false;
772         GError *error = NULL;
773
774         bus_name = __get_bus_name(__app_id);
775         retvm_if(!bus_name, false, "bus_name is NULL");
776         LOGI("bus name : %s", bus_name);
777
778         __gdbus_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
779         if (__gdbus_conn == NULL) {
780                 if (error != NULL) {
781                         _LOGE("Failed to get dbus [%s]", error->message);
782                         g_error_free(error);
783                 }
784                 goto out;
785         }
786
787         owner_id = g_bus_own_name_on_connection(__gdbus_conn, bus_name,
788                         G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL);
789
790         if (owner_id == 0) {
791                 _LOGE("Acquiring the own name is failed");
792                 goto out;
793         }
794
795         ret = true;
796
797 out:
798         FREE_AND_NULL(bus_name);
799         if (!__gdbus_conn)
800                 g_object_unref(__gdbus_conn);
801
802         return ret;
803
804 }
805
806
807 int __register_dbus_interface(const char *port_name, bool is_trusted) {
808
809         GDBusNodeInfo *introspection_data = NULL;
810         int registration_id = 0;
811
812         static gchar introspection_prefix[] =
813                 "<node>"
814                 "  <interface name='";
815
816         static gchar introspection_postfix[] =
817                 "'>"
818                 "        <method name='send_message'>"
819                 "          <arg type='s' name='local_appid' direction='in'/>"
820                 "          <arg type='s' name='local_port' direction='in'/>"
821                 "          <arg type='b' name='local_trusted' direction='in'/>"
822                 "          <arg type='b' name='bi_dir' direction='in'/>"
823                 "          <arg type='s' name='remote_appid' direction='in'/>"
824                 "          <arg type='s' name='remote_port' direction='in'/>"
825                 "          <arg type='b' name='remote_trusted' direction='in'/>"
826                 "          <arg type='u' name='data_len' direction='in'/>"
827                 "          <arg type='s' name='data' direction='in'/>"
828                 "        </method>"
829                 "        <method name='unregister_port'>"
830                 "          <arg type='s' name='local_appid' direction='in'/>"
831                 "          <arg type='b' name='is_trusted' direction='in'/>"
832                 "          <arg type='s' name='remote_port' direction='in'/>"
833                 "          <arg type='i' name='response' direction='out'/>"
834                 "        </method>"
835                 "  </interface>"
836                 "</node>";
837
838         char *interface_name = NULL;
839         char *introspection_xml = NULL;
840         int introspection_xml_len = 0;
841
842         interface_name = __get_interface_name(port_name, is_trusted);
843         if (interface_name == NULL) {
844                 LOGE("Fail to get interface name %d", introspection_xml_len);
845                 goto out;
846         }
847
848         introspection_xml_len = strlen(introspection_prefix) + strlen(interface_name) +
849                 strlen(introspection_postfix) + 1;
850
851         LOGI("interface_name %s", interface_name);
852
853         introspection_xml = (char *)calloc(introspection_xml_len, sizeof(char));
854
855         snprintf(introspection_xml, introspection_xml_len, "%s%s%s", introspection_prefix, interface_name, introspection_postfix);
856
857         introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, NULL);
858         if (!introspection_data) {
859                 _LOGE("g_dbus_node_info_new_for_xml() is failed.");
860                 goto out;
861         }
862
863         registration_id = g_dbus_connection_register_object(__gdbus_conn,
864                                                 MESSAGEPORT_OBJECT_PATH, introspection_data->interfaces[0],
865                                                 &interface_vtable, NULL, NULL, NULL);
866
867         _LOGE("registration_id %d", registration_id);
868
869         if (registration_id == 0) {
870                 _LOGE("Failed to g_dbus_connection_register_object");
871                 goto out;
872         }
873
874 out:
875         if (introspection_data)
876                 g_dbus_node_info_unref(introspection_data);
877         if (interface_name)
878                 free(interface_name);
879         if (introspection_xml)
880                 free(introspection_xml);
881
882
883         return registration_id;
884 }
885
886
887 void __list_free_port_list(gpointer data)
888 {
889         port_list_info_s *n = (port_list_info_s *)data;
890
891         FREE_AND_NULL(n->port_name);
892         FREE_AND_NULL(n);
893 }
894
895 static void __hash_destory_local_value(gpointer data)
896 {
897         message_port_local_port_info_s *mli = (message_port_local_port_info_s *)data;
898         if (mli->port_name)
899                 free(mli->port_name);
900 }
901 static void __hash_destory_remote_value(gpointer data)
902 {
903         message_port_remote_app_info_s *mri = (message_port_remote_app_info_s *)data;
904
905         if (mri) {
906                 FREE_AND_NULL(mri->encoded_bus_name);
907                 FREE_AND_NULL(mri->sender_id);
908                 FREE_AND_NULL(mri->remote_app_id);
909                 if (mri->port_list) {
910                         g_list_free_full(mri->port_list, __list_free_port_list);
911                 }
912         }
913 }
914
915 static bool __initialize(void)
916 {
917
918         int pid = getpid();
919         int ret = 0;
920         char buffer[MAX_PACKAGE_STR_SIZE] = {0, };
921
922         _LOGI("initialize");
923         ret = aul_app_get_appid_bypid(pid, buffer, sizeof(buffer));
924         retvm_if(ret != AUL_R_OK, false, "Failed to get the application ID: %d", ret);
925
926         __app_id = strdup(buffer);
927         retvm_if(!__app_id, false, "Malloc failed");
928         _LOGI("init : %s", __app_id);
929
930         if (__local_port_info == NULL) {
931                 __local_port_info = g_hash_table_new_full(g_direct_hash,  g_direct_equal, NULL, __hash_destory_local_value);
932                 retvm_if(!__local_port_info, false, "fail to create __local_port_info");
933         }
934
935         if (__remote_port_info == NULL) {
936                 __remote_port_info = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, __hash_destory_remote_value);
937                 retvm_if(!__remote_port_info, false, "fail to create __remote_port_info");
938         }
939
940         if (__sender_appid_hash == NULL) {
941                 __sender_appid_hash = g_hash_table_new(g_str_hash, g_str_equal);
942                 retvm_if(!__sender_appid_hash, false, "fail to create __sender_appid_hash");
943         }
944
945         if (__trusted_app_list_hash == NULL)
946                 __trusted_app_list_hash = g_hash_table_new(g_str_hash, g_str_equal);
947
948         if (__checked_app_list_hash == NULL)
949                 __checked_app_list_hash =
950                         g_hash_table_new_full(g_str_hash, g_str_equal, NULL, __hash_destory_list_value);
951
952
953         if (!__dbus_init()) {
954                 return false;
955         }
956         _initialized = true;
957
958         return true;
959 }
960
961
962 static bool __message_port_register_port(const int local_id, const char *local_port, bool is_trusted, messageport_message_cb callback)
963 {
964         message_port_local_port_info_s *mi = (message_port_local_port_info_s *)calloc(1, sizeof(message_port_local_port_info_s));
965         retvm_if(!mi, false, "Malloc failed");
966
967         mi->callback = callback;
968         mi->is_trusted = is_trusted;
969         mi->port_name = strdup(local_port);
970         if (mi->port_name == NULL) {
971                 _LOGE("Malloc failed (%s)", local_port);
972                 free(mi);
973                 return false;
974         }
975         mi->local_id = local_id;
976
977         g_hash_table_insert(__local_port_info, GINT_TO_POINTER(mi->local_id), mi);
978         return true;
979 }
980
981 static int __register_message_port(const char *local_port, bool is_trusted, messageport_message_cb callback)
982 {
983         _SECURE_LOGI("Register a message port : [%s:%s]", __app_id, local_port);
984
985         int local_id = 0;
986
987         // Check the message port is already registed
988         if (__is_local_port_registed(local_port, is_trusted, &local_id, NULL)) {
989                 return local_id;
990         }
991
992         local_id = __register_dbus_interface(local_port, is_trusted);
993         if (local_id < 1) {
994                 _LOGE("register_dbus_interface fail !!");
995                 return MESSAGEPORT_ERROR_OUT_OF_MEMORY;
996         }
997
998         if (!__message_port_register_port(local_id, local_port, is_trusted, callback)) {
999                 return MESSAGEPORT_ERROR_OUT_OF_MEMORY;
1000         }
1001
1002         return local_id;
1003 }
1004
1005 static int __message_port_send_message(const char *remote_appid, const char *remote_port,
1006                 const char *local_port, bool trusted_message, bool local_trusted, bool bi_dir, bundle *message)
1007 {
1008         int ret = MESSAGEPORT_ERROR_NONE;
1009         int len = 0;
1010         bundle_raw *raw = NULL;
1011         char *bus_name = NULL;
1012         char *interface_name = NULL;
1013
1014         message_port_remote_app_info_s *remote_app_info = NULL;
1015         port_list_info_s *port_info = NULL;
1016         GDBusMessage *msg = NULL;
1017         GError *err = NULL;
1018         GVariant *body = NULL;
1019
1020         ret = __get_remote_port_info(remote_appid, remote_port, trusted_message, &remote_app_info, &port_info);
1021         if (ret != MESSAGEPORT_ERROR_NONE) {
1022                 return ret;
1023         }
1024
1025         if (port_info->exist == false) {
1026                 bool exist = false;
1027                 _LOGI("port exist check !!");
1028                 ret =  __check_remote_port(remote_appid, remote_port, trusted_message, &exist);
1029                 if (ret != MESSAGEPORT_ERROR_NONE) {
1030                         goto out;
1031                 } else if (!exist) {
1032                         ret = MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND;
1033                         goto out;
1034                 }
1035         }
1036
1037         bus_name = remote_app_info->encoded_bus_name;
1038
1039         if (bundle_encode(message, &raw, &len) != BUNDLE_ERROR_NONE) {
1040                 ret = MESSAGEPORT_ERROR_INVALID_PARAMETER;
1041                 goto out;
1042         }
1043
1044         if (MAX_MESSAGE_SIZE < len) {
1045                 _LOGE("The size of message (%d) has exceeded the maximum limit.", len);
1046                 ret = MESSAGEPORT_ERROR_MAX_EXCEEDED;
1047         }
1048
1049         body = g_variant_new("(ssbbssbus)", __app_id, (local_port) ? local_port : "", local_trusted, bi_dir,
1050                           remote_appid, remote_port, trusted_message, len, raw);
1051
1052         interface_name = __get_interface_name(remote_port, trusted_message);
1053         if (!interface_name) {
1054                 _LOGE("Can't get interface_name");
1055                 ret = MESSAGEPORT_ERROR_OUT_OF_MEMORY;
1056                 goto out;
1057         }
1058
1059         msg = g_dbus_message_new_method_call(bus_name, MESSAGEPORT_OBJECT_PATH, interface_name, "send_message");
1060         if (!msg) {
1061                 _LOGE("Can't allocate new method call");
1062                 ret = MESSAGEPORT_ERROR_OUT_OF_MEMORY;
1063                 goto out;
1064         }
1065
1066         g_dbus_message_set_body(msg, body);
1067         g_dbus_message_set_flags(msg, G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED);
1068         g_dbus_connection_send_message(__gdbus_conn, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &err);
1069         if (err != NULL) {
1070                 _LOGE("No reply. error = %s", err->message);
1071                 g_error_free(err);
1072                 ret = MESSAGEPORT_ERROR_IO_ERROR;
1073                 goto out;
1074         }
1075
1076         out:
1077         if (msg)
1078                 g_object_unref(msg);
1079         if (raw)
1080                 bundle_free_encoded_rawdata(&raw);
1081         if (interface_name)
1082                 free(interface_name);
1083
1084         return ret;
1085 }
1086
1087 int __message_send_bidirectional_message(int id, const char *remote_app_id, const char *remote_port,  bool trusted_message, bundle *message)
1088 {
1089         message_port_local_port_info_s *local_info;
1090         int ret = __get_local_port_info(id, &local_info);
1091         if (ret != MESSAGEPORT_ERROR_NONE) {
1092                 return ret;
1093         }
1094
1095         _LOGE("bidirectional_message %s", local_info->port_name);
1096         return __message_port_send_message(remote_app_id, remote_port,
1097                         local_info->port_name, trusted_message, local_info->is_trusted, true, message);
1098 }
1099
1100 int messageport_unregister_local_port(int local_port_id, bool trusted_port)
1101 {
1102
1103         GDBusMessage *msg = NULL;
1104         GDBusMessage *reply = NULL;
1105         GVariant *body;
1106         char *bus_name = NULL;
1107         GList *checked_app_list = NULL;
1108         GList *checked_app = NULL;
1109
1110         _LOGE("unregister : %d", local_port_id);
1111
1112         message_port_local_port_info_s *mi =
1113                 (message_port_local_port_info_s *)
1114                 g_hash_table_lookup(__local_port_info, GINT_TO_POINTER(local_port_id));
1115         if (mi == NULL)
1116                 return MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND;
1117
1118         if (mi->is_trusted != trusted_port)
1119                 return MESSAGEPORT_ERROR_INVALID_PARAMETER;
1120
1121         checked_app_list = (GList *)g_hash_table_lookup(__checked_app_list_hash, mi->port_name);
1122         checked_app = NULL;
1123         for (checked_app = checked_app_list; checked_app != NULL;
1124                         checked_app = checked_app->next) {
1125
1126                 GError *err = NULL;
1127                 char *checked_app_id = (char *)checked_app->data;
1128                 char *interface_name = __get_interface_name(mi->port_name, mi->is_trusted);
1129                 if (interface_name == NULL) {
1130                         _LOGI("Can't get interface_name");
1131                         return MESSAGEPORT_ERROR_OUT_OF_MEMORY;
1132                 }
1133
1134                 _LOGI("unregister appid: %s", checked_app_id);
1135                 bus_name = __get_bus_name(checked_app_id);
1136                 msg = g_dbus_message_new_method_call(bus_name, MESSAGEPORT_OBJECT_PATH,
1137                                 interface_name, "unregister_port");
1138
1139                 if (interface_name)
1140                         free(interface_name);
1141
1142                 if (!msg) {
1143                         _LOGI("Can't allocate new method call");
1144                         return MESSAGEPORT_ERROR_OUT_OF_MEMORY;
1145                 }
1146
1147                 g_dbus_message_set_body(msg,
1148                                 g_variant_new("(sbs)", __app_id, mi->is_trusted, mi->port_name));
1149                 reply = g_dbus_connection_send_message_with_reply_sync(
1150                                 __gdbus_conn,
1151                                 msg,
1152                                 G_DBUS_SEND_MESSAGE_FLAGS_NONE,
1153                                 -1,
1154                                 NULL,
1155                                 NULL,
1156                                 &err);
1157
1158                 if (err || (reply == NULL)) {
1159                         if (err) {
1160                                 _LOGE("No reply. error = %s", err->message);
1161                                 g_error_free(err);
1162                         }
1163                 } else {
1164                         if (g_dbus_message_to_gerror(reply, &err)) {
1165                                 if (err) {
1166                                         _LOGE("error = %s", err->message);
1167                                         g_error_free(err);
1168                                 }
1169                         } else {
1170                                 int ret_val = MESSAGEPORT_ERROR_NONE;
1171
1172                                 body = g_dbus_message_get_body(reply);
1173                                 g_variant_get(body, "(u)", &ret_val);
1174
1175                                 if (ret_val == MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH) {
1176                                         _SECURE_LOGI("The remote application (%s) is not signed with the same certificate"
1177                                                         , checked_app_id);
1178                                 }
1179                         }
1180                 }
1181                 if (msg)
1182                         g_object_unref(msg);
1183                 if (reply)
1184                         g_object_unref(reply);
1185
1186
1187         }
1188         g_hash_table_remove(__checked_app_list_hash, mi->port_name);
1189         g_hash_table_remove(__local_port_info, GINT_TO_POINTER(local_port_id));
1190
1191         g_dbus_connection_unregister_object(__gdbus_conn, local_port_id);
1192
1193         if (msg)
1194                 g_object_unref(msg);
1195         if (reply)
1196                 g_object_unref(reply);
1197
1198         return MESSAGEPORT_ERROR_NONE;
1199 }
1200
1201 int messageport_register_local_port(const char *local_port, messageport_message_cb callback)
1202 {
1203         if (!_initialized) {
1204                 if (!__initialize())
1205                         return MESSAGEPORT_ERROR_IO_ERROR;
1206         }
1207
1208         return __register_message_port(local_port, false, callback);
1209 }
1210
1211 int messageport_register_trusted_local_port(const char *local_port, messageport_message_cb callback)
1212 {
1213         if (!_initialized) {
1214                 if (!__initialize())
1215                         return MESSAGEPORT_ERROR_IO_ERROR;
1216         }
1217
1218         return __register_message_port(local_port, true, callback);
1219
1220 }
1221
1222 int messageport_check_remote_port(const char *remote_app_id, const char *remote_port, bool *exist)
1223 {
1224         if (!_initialized) {
1225                 if (!__initialize())
1226                         return MESSAGEPORT_ERROR_IO_ERROR;
1227         }
1228
1229         int ret = __check_remote_port(remote_app_id, remote_port, false, exist);
1230         if (ret == MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND) {
1231                 *exist = false;
1232                 ret = MESSAGEPORT_ERROR_NONE;
1233         }
1234
1235         return ret;
1236 }
1237
1238 int messageport_check_trusted_remote_port(const char *remote_app_id, const char *remote_port, bool *exist)
1239 {
1240         if (!_initialized) {
1241                 if (!__initialize())
1242                         return MESSAGEPORT_ERROR_IO_ERROR;
1243         }
1244
1245         int ret = __check_remote_port(remote_app_id, remote_port, true, exist);
1246         if (ret == MESSAGEPORT_ERROR_MESSAGEPORT_NOT_FOUND) {
1247                 *exist = false;
1248                 ret = MESSAGEPORT_ERROR_NONE;
1249         }
1250
1251         return ret;
1252 }
1253
1254 int messageport_send_message(const char *remote_app_id, const char *remote_port, bundle *message)
1255 {
1256         if (!_initialized) {
1257                 if (!__initialize())
1258                         return MESSAGEPORT_ERROR_IO_ERROR;
1259         }
1260
1261         return __message_port_send_message(remote_app_id, remote_port, NULL, false, false, false, message);
1262 }
1263
1264 int messageport_send_trusted_message(const char *remote_app_id, const char *remote_port, bundle *message)
1265 {
1266         if (!_initialized) {
1267                 if (!__initialize())
1268                         return MESSAGEPORT_ERROR_IO_ERROR;
1269         }
1270
1271         return __message_port_send_message(remote_app_id, remote_port, NULL, true, false, false, message);
1272 }
1273
1274 int messageport_send_bidirectional_message(int id, const char *remote_app_id, const char *remote_port,
1275                 bundle *message)
1276 {
1277         if (!_initialized) {
1278                 if (!__initialize())
1279                         return MESSAGEPORT_ERROR_IO_ERROR;
1280         }
1281
1282         return __message_send_bidirectional_message(id, remote_app_id, remote_port, false, message);
1283 }
1284
1285 int messageport_send_bidirectional_trusted_message(int id, const char *remote_app_id, const char *remote_port,
1286                 bundle *message)
1287 {
1288         if (!_initialized) {
1289                 if (!__initialize())
1290                         return MESSAGEPORT_ERROR_IO_ERROR;
1291         }
1292         return __message_send_bidirectional_message(id, remote_app_id, remote_port, true, message);
1293 }
1294
1295 int messageport_get_local_port_name(int id, char **name)
1296 {
1297         message_port_local_port_info_s *local_info;
1298         int ret = __get_local_port_info(id, &local_info);
1299
1300         if (ret != MESSAGEPORT_ERROR_NONE) {
1301                 return ret;
1302         }
1303
1304         *name = strdup(local_info->port_name);
1305
1306         if (*name == NULL) {
1307                 return MESSAGEPORT_ERROR_OUT_OF_MEMORY;
1308         }
1309
1310         return MESSAGEPORT_ERROR_NONE;
1311 }
1312
1313 int messageport_check_trusted_local_port(int id, bool *trusted)
1314 {
1315         message_port_local_port_info_s *local_info;
1316         int ret = __get_local_port_info(id, &local_info);
1317
1318         if (ret != MESSAGEPORT_ERROR_NONE) {
1319                 return ret;
1320         }
1321
1322         *trusted = local_info->is_trusted;
1323
1324         return MESSAGEPORT_ERROR_NONE;;
1325 }
1326