certifiacte validation code added
[profile/ivi/message-port.git] / lib / message-port.c
1 #include "message-port.h"
2 #include "msgport-manager.h"
3 #include "msgport-utils.h"
4 #include "common/log.h"
5
6 static int
7 _messageport_register_port (const char *name, gboolean is_trusted, messageport_message_cb cb)
8 {
9     int port_id = 0; /* id of the port created */
10     messageport_error_e res;
11     MsgPortManager *manager = msgport_get_manager ();
12
13     g_assert (manager);
14     g_assert (MSGPORT_IS_MANAGER (manager));
15
16     res = msgport_manager_register_service (manager, name, is_trusted, cb, &port_id);
17
18     return port_id > 0 ? port_id : (int)res;
19 }
20
21 static messageport_error_e
22 _messageport_check_remote_port (const char *app_id, const char *port, gboolean is_trusted, gboolean *exists)
23 {
24     messageport_error_e res;
25     MsgPortManager *manager = msgport_get_manager ();
26
27     res = msgport_manager_check_remote_service (manager, app_id, port, is_trusted, NULL);
28
29     if (exists) *exists = (res == MESSAGEPORT_ERROR_NONE);
30
31     return res;
32 }
33
34 static messageport_error_e
35 _messageport_send_message (const char *app_id, const char *port, gboolean is_trusted, bundle *message)
36 {
37     MsgPortManager *manager = msgport_get_manager ();
38
39     GVariant *v_data = bundle_to_variant_map (message);
40
41     return msgport_manager_send_message (manager, app_id, port, is_trusted, v_data);
42 }
43
44 messageport_error_e
45 _messageport_send_bidirectional_message (int id, const gchar *remote_app_id, const gchar *remote_port, gboolean is_trusted, bundle *message)
46 {
47     MsgPortManager *manager = msgport_get_manager ();
48
49     GVariant *v_data = bundle_to_variant_map (message);
50
51     return msgport_manager_send_bidirectional_message (manager, id, remote_app_id, remote_port, is_trusted, v_data);
52 }
53
54 /*
55  * API
56  */
57
58 int
59 messageport_register_local_port(const char* local_port, messageport_message_cb callback)
60 {
61     return _messageport_register_port (local_port, FALSE, callback);
62 }
63
64 messageport_error_e
65 messageport_register_trusted_local_port (const char *local_port, messageport_message_cb callback)
66 {
67     return _messageport_register_port (local_port, TRUE, callback);
68 }
69
70 messageport_error_e
71 messageport_check_remote_port (const char *remote_app_id, const char *port_name, gboolean *exists)
72 {
73     return _messageport_check_remote_port (remote_app_id, port_name, FALSE, exists);
74 }
75
76 messageport_error_e
77 messageport_check_trusted_remote_port (const char *remote_app_id, const char *port_name, gboolean *exists)
78 {
79     return _messageport_check_remote_port (remote_app_id, port_name, TRUE, exists);
80 }
81
82 messageport_error_e
83 messageport_send_message (const char* remote_app_id, const char* remote_port, bundle* message)
84 {
85     return _messageport_send_message (remote_app_id, remote_port, FALSE, message);
86 }
87
88 messageport_error_e
89 messageport_send_trusted_message(const char* remote_app_id, const char* remote_port, bundle* message)
90 {
91     return _messageport_send_message (remote_app_id, remote_port, TRUE, message);
92 }
93
94 messageport_error_e
95 messageport_send_bidirectional_message(int id, const char* remote_app_id, const char* remote_port, bundle* data)
96 {
97     return _messageport_send_bidirectional_message (id, remote_app_id, remote_port, FALSE, data);
98 }
99
100 messageport_error_e
101 messageport_send_bidirectional_trusted_message (int id, const char *remote_app_id, const char *remote_port, bundle *data)
102 {
103     return _messageport_send_bidirectional_message (id, remote_app_id, remote_port, TRUE, data);
104 }
105
106 messageport_error_e
107 messageport_get_local_port_name(int port_id, char **name_out)
108 {
109     MsgPortManager *manager = msgport_get_manager ();
110
111     return msgport_manager_get_service_name (manager, port_id, name_out);
112 }
113
114 messageport_error_e
115 messageport_check_trusted_local_port (int id, gboolean *trusted)
116 {
117     (void) id;
118
119     if (trusted) *trusted = FALSE;
120
121     return MESSAGEPORT_ERROR_NONE;
122 }
123