Fix : Invalid GVariant format
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-network.c
index 9d74d66..5752a53 100644 (file)
@@ -1,11 +1,5 @@
 /*
- * Bluetooth-frwk
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
- *              Girishashok Joshi <girish.joshi@samsung.com>
- *              Chanyeol Park <chanyeol.park@samsung.com>
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -26,9 +20,7 @@
 #include <dlog.h>
 #include <string.h>
 #include <stdio.h>
-#if !defined(LIBNOTIFY_SUPPORT) && !defined(LIBNOTIFICATION_SUPPORT)
 #include <syspopup_caller.h>
-#endif
 #include <net_connection.h>
 
 #include "bluetooth-api.h"
@@ -108,7 +100,10 @@ static connection_profile_h __bt_get_net_profile(void *connection,
                        if (g_strv_length(split_string) < 3)
                                continue;
 
-                       if (g_ascii_strcasecmp(split_string[2], net_address) == 0) {
+                       if (split_string[2] == NULL) {
+                               BT_ERR("__bt_get_net_profile Error Parameter are NULL..\n");
+                               continue;
+                       } else if (g_ascii_strcasecmp(split_string[2], net_address) == 0) {
                                BT_DBG("matched profile");
                                g_strfreev(split_string);
                                return profile_h;
@@ -127,7 +122,7 @@ int _bt_is_network_connected(void *connection, unsigned char *address,
        handle = __bt_get_net_profile(connection,
                                CONNECTION_ITERATOR_TYPE_CONNECTED,
                                address);
-       if(handle)
+       if (handle)
                *is_connected = TRUE;
        else
                *is_connected = FALSE;
@@ -156,8 +151,9 @@ static void __bt_network_connect_cb(GDBusProxy *proxy, GAsyncResult *res,
                        g_clear_error(&g_error);
                }
                result = BLUETOOTH_ERROR_INTERNAL;
+       } else {
+               g_variant_unref(reply);
        }
-       g_variant_unref(reply);
 
        func_data = user_data;
        if (func_data == NULL) {
@@ -183,7 +179,7 @@ static void __bt_network_connect_cb(GDBusProxy *proxy, GAsyncResult *res,
                                                        &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
 
        g_dbus_method_invocation_return_value(req_info->context,
-                       g_variant_new("iv", result, out_param1));
+                       g_variant_new("(iv)", result, out_param1));
 
        _bt_delete_request_list(req_info->req_id);
 
@@ -215,8 +211,9 @@ static void __bt_network_disconnect_cb(GDBusProxy *proxy, GAsyncResult *res,
                        g_clear_error(&g_error);
                }
                result = BLUETOOTH_ERROR_INTERNAL;
+       } else {
+               g_variant_unref(reply);
        }
-       g_variant_unref(reply);
 
        func_data = user_data;
        if (func_data == NULL) {
@@ -243,7 +240,7 @@ static void __bt_network_disconnect_cb(GDBusProxy *proxy, GAsyncResult *res,
                                                        &device_addr, sizeof(bluetooth_device_address_t), TRUE, NULL, NULL);
 
        g_dbus_method_invocation_return_value(req_info->context,
-                       g_variant_new("iv", result, out_param1));
+                       g_variant_new("(iv)", result, out_param1));
 
        _bt_delete_request_list(req_info->req_id);
 
@@ -258,11 +255,12 @@ int _bt_network_activate(void)
 {
        int ret = BLUETOOTH_ERROR_NONE;
        char *adapter_path;
+       GVariant *result = NULL;
        GError *err = NULL;
        GDBusConnection *conn;
        GDBusProxy *server_proxy;
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        adapter_path = _bt_get_adapter_path();
@@ -278,22 +276,27 @@ int _bt_network_activate(void)
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       g_dbus_proxy_call_sync(server_proxy, "Register",
+       result = g_dbus_proxy_call_sync(server_proxy, "Register",
                                 g_variant_new("(ss)", NAP_UUID_NAME, NET_BRIDGE_INTERFACE),
                                 G_DBUS_CALL_FLAGS_NONE,
                                 -1,
                                 NULL,
                                 &err);
-       if (err != NULL) {
-               g_dbus_error_strip_remote_error(err);
-               BT_ERR("Network server register Error: %s\n", err->message);
-               if (g_strcmp0(err->message, "Already Exists") == 0) {
-                       ret = BLUETOOTH_ERROR_ALREADY_INITIALIZED;
-               } else {
-                       ret = BLUETOOTH_ERROR_INTERNAL;
+       if (result == NULL) {
+               if (err != NULL) {
+                       g_dbus_error_strip_remote_error(err);
+                       BT_ERR("Network server register Error: %s\n", err->message);
+                       if (g_strcmp0(err->message, "Already Exists") == 0)
+                               ret = BLUETOOTH_ERROR_ALREADY_INITIALIZED;
+                       else
+                               ret = BLUETOOTH_ERROR_INTERNAL;
+
+                       g_error_free(err);
                }
-               g_error_free(err);
+       } else {
+               g_variant_unref(result);
        }
+
        g_object_unref(server_proxy);
 
        return ret;
@@ -302,12 +305,13 @@ int _bt_network_activate(void)
 int _bt_network_deactivate(void)
 {
        char *adapter_path;
+       GVariant *result = NULL;
        GError *err = NULL;
        GDBusConnection *conn;
        GDBusProxy *server_proxy;
        int ret = BLUETOOTH_ERROR_NONE;
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        adapter_path = _bt_get_adapter_path();
@@ -323,23 +327,28 @@ int _bt_network_deactivate(void)
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
-       g_dbus_proxy_call_sync(server_proxy, "Unregister",
+       result = g_dbus_proxy_call_sync(server_proxy, "Unregister",
                                 g_variant_new("(s)", NAP_UUID_NAME),
                                 G_DBUS_CALL_FLAGS_NONE,
                                 -1,
                                 NULL,
                                 &err);
-       if (err != NULL) {
-               g_dbus_error_strip_remote_error(err);
-               BT_ERR("Network server unregister Error: %s\n", err->message);
-               if (g_strcmp0(err->message,
-                               "Operation currently not available") == 0) {
-                       ret = BLUETOOTH_ERROR_ALREADY_DEACTIVATED;
-               } else {
-                       ret = BLUETOOTH_ERROR_INTERNAL;
+       if (result == NULL) {
+               if (err != NULL) {
+                       g_dbus_error_strip_remote_error(err);
+                       BT_ERR("Network server unregister Error: %s\n", err->message);
+                       if (g_strcmp0(err->message,
+                                       "Operation currently not available") == 0) {
+                               ret = BLUETOOTH_ERROR_ALREADY_DEACTIVATED;
+                       } else {
+                               ret = BLUETOOTH_ERROR_INTERNAL;
+                       }
+                       g_error_free(err);
                }
-               g_error_free(err);
+       } else {
+               g_variant_unref(result);
        }
+
        g_object_unref(server_proxy);
 
        return ret;
@@ -348,15 +357,13 @@ int _bt_network_deactivate(void)
 int _bt_network_connect(int request_id, int role,
                bluetooth_device_address_t *device_address)
 {
-       const gchar *device_path = NULL;
+       gchar *device_path = NULL;
        char address[BT_ADDRESS_STRING_SIZE] = { 0 };
        char remote_role[BLUETOOTH_UUID_STRING_MAX] = { 0 };
        bt_function_data_t *func_data;
        GDBusProxy *adapter_proxy;
        GDBusProxy *profile_proxy;
        GDBusConnection *conn;
-       GVariant *result = NULL;
-       GError*err = NULL;
 
        BT_CHECK_PARAMETER(device_address, return);
 
@@ -380,28 +387,14 @@ int _bt_network_connect(int request_id, int role,
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
 
-       result = g_dbus_proxy_call_sync(adapter_proxy, "FindDevice",
-                       g_variant_new("(s)", address),
-                       G_DBUS_CALL_FLAGS_NONE,
-                       -1, NULL, &err);
-       if (result == NULL) {
-               BT_ERR("Error occurred in call to FindDevice");
-               if (err) {
-                       BT_ERR("Error: %s", err->message);
-                       g_clear_error(&err);
-               }
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       device_path =  g_variant_get_string(result, NULL);
+       device_path = _bt_get_device_object_path(address);
        if (device_path == NULL) {
                BT_ERR("No paired device");
-               g_variant_unref(result);
                return BLUETOOTH_ERROR_NOT_PAIRED;
        }
 
@@ -409,10 +402,9 @@ int _bt_network_connect(int request_id, int role,
                        NULL, BT_BLUEZ_NAME,
                        device_path, BT_NETWORK_CLIENT_INTERFACE,  NULL, NULL);
 
-       g_variant_unref(result);
+       g_free(device_path);
        retv_if(profile_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
        func_data = g_malloc0(sizeof(bt_function_data_t));
-
        func_data->address = g_strdup(address);
        func_data->req_id = request_id;
 
@@ -430,39 +422,24 @@ int _bt_network_connect(int request_id, int role,
 int _bt_network_disconnect(int request_id,
                bluetooth_device_address_t *device_address)
 {
-       const gchar *device_path = NULL;
+       gchar *device_path = NULL;
        char address[BT_ADDRESS_STRING_SIZE] = { 0 };
        bt_function_data_t *func_data;
        GDBusProxy *adapter_proxy;
        GDBusProxy *profile_proxy;
        GDBusConnection *conn;
-       GVariant *result = NULL;
-       GError*err = NULL;
 
        BT_CHECK_PARAMETER(device_address, return);
 
        adapter_proxy = _bt_get_adapter_proxy();
        retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        _bt_convert_addr_type_to_string(address, device_address->addr);
 
-       result = g_dbus_proxy_call_sync(adapter_proxy, "FindDevice",
-                                g_variant_new("(s)", address),
-                                G_DBUS_CALL_FLAGS_NONE,
-                                -1, NULL, &err);
-       if (result == NULL) {
-               BT_ERR("Error occurred in call to FindDevice");
-               if (err) {
-                       BT_ERR("Error: %s", err->message);
-                       g_clear_error(&err);
-               }
-               return BLUETOOTH_ERROR_INTERNAL;
-       }
-
-       device_path =  g_variant_get_string(result, NULL);
+       device_path = _bt_get_device_object_path(address);
        if (device_path == NULL) {
                BT_ERR("No paired device");
                return BLUETOOTH_ERROR_NOT_PAIRED;
@@ -472,10 +449,9 @@ int _bt_network_disconnect(int request_id,
                        NULL, BT_BLUEZ_NAME,
                        device_path, BT_NETWORK_CLIENT_INTERFACE,  NULL, NULL);
 
-       g_variant_unref(result);
+       g_free(device_path);
        retv_if(profile_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
        func_data = g_malloc0(sizeof(bt_function_data_t));
-
        func_data->address = g_strdup(address);
        func_data->req_id = request_id;
 
@@ -501,7 +477,7 @@ int _bt_network_server_disconnect(int request_id,
 
        BT_CHECK_PARAMETER(device_address, return);
 
-       conn = _bt_get_system_gconn();
+       conn = _bt_gdbus_get_system_gconn();
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
 
        adapter_path = _bt_get_adapter_path();