4 * Copyright (c) 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Ja-young Gu <jygu@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
25 #include <glib-2.0/glib.h>
29 #include <security-server.h>
31 #include <TelDefines.h>
32 #include <TapiCommon.h>
34 #include "tapi-lib-proxy.h"
35 #include "TapiUtility.h"
36 #include "tapi_proxy_internal.h"
38 /* This global stores the proxy connection to dbus */
39 DBusGProxy* tapi_cs_proxy_internal;
41 static char g_priv_cookie_name[255] = { 0, };
42 static int g_priv_cookie_size = 0;
46 * This function is used to initialise a connnection with telephony server through DBUS.
48 * @return True / False
54 static int tapi_init_cs_internal()
56 DBusGConnection* tapi_cs_connection = NULL;
60 tapi_cs_connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &err);
61 TAPI_LIB_DEBUG(LEVEL_ERR, "tapi_cs_connection = 0x%x");
63 /* No need to assert but, need to return FALSE */
64 if (tapi_cs_connection == NULL) {
66 fprintf(stderr, "[FAILED]connection to dbus failed: %s\n", err->message);
67 TAPI_LIB_DEBUG(LEVEL_ERR, "failed to get CS connection with error cause");
71 TAPI_LIB_DEBUG(LEVEL_ERR, "failed to get CS connection with NULL error cause");
76 tapi_cs_proxy_internal = dbus_g_proxy_new_for_name(tapi_cs_connection, "org.projectx.telephony",
77 "/org/projectx/app", "org.projectx.telephony");
79 /* No need to assert but, need to return FALSE */
80 TAPI_RETURN_VAL_IF_FAIL(tapi_cs_proxy_internal, FALSE);
87 * This function is used to check the connnection status with telephony server through DBUS.
89 * @return True / False
95 int tapi_check_dbus_status_internal(void)
97 TS_BOOL result = TRUE;
99 TAPI_LIB_DEBUG(LEVEL_DEBUG, "DBUS-CS tapi_check_dbus_status");
101 if (tapi_cs_proxy_internal != NULL && dbus_g_proxy_get_interface(tapi_cs_proxy_internal)) {
102 TAPI_LIB_DEBUG(LEVEL_DEBUG, "DBUS-CS Ready to use");
106 TAPI_LIB_DEBUG(LEVEL_DEBUG, "DBUS-CS Initializing...");
107 if (tapi_init_cs_internal()) {
108 TAPI_LIB_DEBUG(LEVEL_DEBUG, "DBUS-CS INIT completed");
112 TAPI_LIB_DEBUG(LEVEL_ERR, "FAIL TO DBUS-CS INIT");
119 static void _dump_cookie(char *data, int size)
121 char buf[255] = { 0, };
122 char tmp[3] = { 0, };
125 for (i = 0; i < size; i++) {
126 snprintf(tmp, 3, "%02X", data[i]);
127 strncat(buf, tmp, 3);
128 if ((i + 1) % 8 == 0)
129 strncat(buf, " ", 2);
132 TAPI_LIB_DEBUG(LEVEL_DEBUG, "cookie=[%s]", buf);
135 static int _cookie_init(void)
139 ret = security_server_get_cookie_size();
141 TAPI_LIB_DEBUG(LEVEL_DEBUG, "get_cookie_size() failed. ret=%d", ret);
144 g_priv_cookie_size = ret;
146 ret = security_server_request_cookie(g_priv_cookie_name, g_priv_cookie_size);
148 memset(g_priv_cookie_name, 0, 255);
149 g_priv_cookie_size = 0;
150 TAPI_LIB_DEBUG(LEVEL_DEBUG, "request_cookie() failed. ret=%d", ret);
154 _dump_cookie(g_priv_cookie_name, g_priv_cookie_size);
160 * This function is used to send the service request to telephony server through DBUS.
162 * @return True / False
163 * @param[in] tapi_service,tapi_service_function,in_param1,in_param2,in_param3,in_param4
164 * @param[out] out_param1,out_param2,out_param3,out_param4
169 TS_BOOL tapi_send_request_internal(int tapi_service, int tapi_service_function, GArray* in_param1, GArray* in_param2,
170 GArray* in_param3, GArray* in_param4, GArray** out_param1, GArray** out_param2, GArray** out_param3,
175 GError* error = NULL;
176 TS_BOOL api_ret = TRUE;
178 GArray* in_param5 = ((void *) 0);
181 * Add d-bus connection name to ALL REQUEST
182 * - If already appended conn_name to in_param4[0] before tapi_send_request(),
183 * then append conn_name to in_param4[1] and ignore by telephony-server.
185 tapi_dbus_connection_name app_name;
186 tel_get_app_name(&app_name);
187 if (app_name.length_of_name == 0) {
188 TAPI_LIB_DEBUG(LEVEL_DEBUG, "No dbus connection name (pid=%d)", getpid());
191 TAPI_LIB_DEBUG(LEVEL_DEBUG, "conn_name=[%s]", app_name.name);
193 g_array_append_vals(in_param4, &app_name, sizeof(tapi_dbus_connection_name));
196 * Add security cookie to ALL REQUEST
198 if (g_priv_cookie_size == 0) {
199 if (_cookie_init() != TRUE) {
200 TAPI_LIB_DEBUG(LEVEL_DEBUG, "no cookie name. pid=%d", getpid());
205 in_param5 = g_array_new(FALSE, FALSE, sizeof(gchar));
206 g_array_append_vals(in_param5, g_priv_cookie_name, g_priv_cookie_size + 1);
211 api_ret = org_projectx_telephony_service_request_sec(tapi_cs_proxy_internal, tapi_service, tapi_service_function,
212 in_param1, in_param2, in_param3, in_param4, in_param5, out_param1, out_param2, out_param3, out_param4,
213 &error_occurred, &error);
215 if (api_ret != TRUE) {
216 // dBUS-RPC is failed
219 // We can not say only TS is killed. This is dBUS-RPC failure including TS crash case
220 TAPI_LIB_DEBUG(LEVEL_ALERT, "dBUS-RPC is failed %d", api_ret);
223 // dBUS gives error cause
224 TAPI_LIB_DEBUG(LEVEL_ALERT,
225 " D-Bus API failure: errCode[0x%x], message:[%s], service type=%d, service function=0x%x",
226 error_occurred, error->message, tapi_service, tapi_service_function);
231 // dBUS does not give error cause even though dBUS-RPC is failed
232 TAPI_LIB_DEBUG(LEVEL_ALERT, "dBUS RPC is failed but error returned was NULL ");
236 // dBUS-RPC is successfully done
239 TAPI_LIB_DEBUG(LEVEL_INFO, "dBUS RPC is successfully done. service type=%d, service function=0x%x",
240 tapi_service, tapi_service_function);
243 g_array_free(in_param5, TRUE);