Apply the secure logs
[platform/core/appfw/message-port.git] / src / message-port.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 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
25 #include "message-port.h"
26 #include "message-port-log.h"
27
28 #include "MessagePortProxy.h"
29
30 int
31 messageport_register_local_port(const char* local_port, messageport_message_cb callback)
32 {
33         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
34         if (pProxy != NULL)
35         {
36                 return pProxy->RegisterMessagePort(local_port, false, callback);
37         }
38
39         return MESSAGEPORT_ERROR_IO_ERROR;
40 }
41
42 int
43 messageport_register_trusted_local_port(const char* local_port, messageport_message_cb callback)
44 {
45         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
46         if (pProxy != NULL)
47         {
48                 return pProxy->RegisterMessagePort(local_port, true, callback);
49         }
50
51         return MESSAGEPORT_ERROR_IO_ERROR;
52 }
53
54 int
55 messageport_check_remote_port(const char* remote_app_id, const char *remote_port, bool* exist)
56 {
57         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
58         if (pProxy != NULL)
59         {
60                 return pProxy->CheckRemotePort(remote_app_id, remote_port, false, exist);
61         }
62
63         return MESSAGEPORT_ERROR_IO_ERROR;
64 }
65
66 int
67 messageport_check_trusted_remote_port(const char* remote_app_id, const char *remote_port, bool* exist)
68 {
69         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
70         if (pProxy != NULL)
71         {
72                 return pProxy->CheckRemotePort(remote_app_id, remote_port, true, exist);
73         }
74
75         return MESSAGEPORT_ERROR_IO_ERROR;
76 }
77
78 int
79 messageport_send_message(const char* remote_app_id, const char* remote_port, bundle* message)
80 {
81         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
82         if (pProxy != NULL)
83         {
84                 return pProxy->SendMessage(remote_app_id, remote_port, false, message);
85         }
86
87         return MESSAGEPORT_ERROR_IO_ERROR;
88 }
89
90 int
91 messageport_send_trusted_message(const char* remote_app_id, const char* remote_port, bundle* message)
92 {
93         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
94         if (pProxy != NULL)
95         {
96                 return pProxy->SendMessage(remote_app_id, remote_port, true, message);
97         }
98
99         return MESSAGEPORT_ERROR_IO_ERROR;
100 }
101
102 int
103 messageport_send_bidirectional_message(int id, const char* remote_app_id, const char* remote_port, bundle* message)
104 {
105         int ret = 0;
106         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
107         if (pProxy != NULL)
108         {
109                 char* pName = pProxy->GetLocalPortNameN(id);
110                 bool trusted = false;
111                 ret = pProxy->CheckTrustedLocalPort(id, &trusted);
112                 if (ret < 0)
113                 {
114                         free(pName);
115                         return MESSAGEPORT_ERROR_INVALID_PARAMETER;
116                 }
117
118                 ret = pProxy->SendMessage(pName, trusted, remote_app_id, remote_port, false, message);
119
120                 free(pName);
121
122                 return ret;
123         }
124
125         return MESSAGEPORT_ERROR_IO_ERROR;
126 }
127
128 int
129 messageport_send_bidirectional_trusted_message(int id, const char* remote_app_id, const char* remote_port, bundle* message)
130 {
131         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
132         if (pProxy != NULL)
133         {
134                 bool trusted = false;
135                 int ret = pProxy->CheckTrustedLocalPort(id, &trusted);
136                 if (ret < 0)
137                 {
138                         return ret;
139                 }
140
141                 char* pName = pProxy->GetLocalPortNameN(id);
142                 if (pName == NULL)
143                 {
144                         return MESSAGEPORT_ERROR_INVALID_PARAMETER;
145                 }
146
147                 ret = pProxy->SendMessage(pName, trusted, remote_app_id, remote_port, true, message);
148
149                 free(pName);
150
151                 return ret;
152         }
153
154         return MESSAGEPORT_ERROR_IO_ERROR;
155 }
156
157 int
158 messageport_get_local_port_name(int id, char **name)
159 {
160         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
161         if (pProxy != NULL)
162         {
163                 char* pName = pProxy->GetLocalPortNameN(id);
164                 if (pName == NULL)
165                 {
166                         return MESSAGEPORT_ERROR_INVALID_PARAMETER;
167                 }
168                 else
169                 {
170                         *name = pName;
171                         return 0;
172                 }
173         }
174
175         return MESSAGEPORT_ERROR_IO_ERROR;
176 }
177
178 int
179 messageport_check_trusted_local_port(int id, bool *trusted)
180 {
181         MessagePortProxy* pProxy = MessagePortProxy::GetProxy();
182         if (pProxy != NULL)
183         {
184                 return pProxy->CheckTrustedLocalPort(id, trusted);
185         }
186
187         return MESSAGEPORT_ERROR_IO_ERROR;
188 }
189