Merge "[net-config] Pointer is passed to g_free() after the memory was deallocated...
authortaesub kim <taesub.kim@samsung.com>
Fri, 22 Jan 2016 01:06:17 +0000 (17:06 -0800)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Fri, 22 Jan 2016 01:06:17 +0000 (17:06 -0800)
include/wifi.h
src/dbus/netdbus.c
src/signal-handler.c
src/wifi-agent.c
src/wifi-eap-config.c
src/wifi.c

index 9163ab7..f72d12e 100755 (executable)
@@ -34,6 +34,9 @@ extern "C" {
 #define WIFI_CERT_STORAGEDIR   "/var/lib/wifi/cert"
 #define CONNMAN_STORAGEDIR             "/var/lib/connman"
 
+void __netconfig_wifi_connect_reply(GObject *source_object, GAsyncResult *res,
+               gpointer user_data);
+
 void wifi_object_create_and_init(void);
 void wifi_object_deinit(void);
 
index d998fb7..33fa8cf 100755 (executable)
@@ -192,6 +192,8 @@ gboolean netconfig_invoke_dbus_method_nonblock(const char *dest, const char *pat
                        netdbus_get_cancellable(),
                        (GAsyncReadyCallback) notify_func,
                        NULL);
+       if (notify_func)
+               netconfig_gdbus_pending_call_ref();
 
        return TRUE;
 }
index b0d7c1b..fee6d0a 100755 (executable)
@@ -58,7 +58,7 @@
 #define CONNMAN_SIGNAL_NAME_CHANGED            "NameOwnerChanged"
 
 #define MAX_SIG_LEN 64
-#define TOTAL_CONN_SIGNALS 3
+#define TOTAL_CONN_SIGNALS 4
 
 typedef enum {
        SIG_INTERFACE_REMOVED = 0,
@@ -330,6 +330,77 @@ static void _dbus_name_changed_cb(GDBusConnection *conn,
        return;
 }
 
+static void _services_changed_cb(GDBusConnection *conn, const gchar *name,
+               const gchar *path, const gchar *interface, const gchar *sig,
+               GVariant *param, gpointer user_data)
+{
+       gchar *property, *value;
+       gchar *service_path;
+       GVariant *variant = NULL;
+       GVariantIter *added = NULL, *removed = NULL, *next = NULL;
+
+       if (path == NULL || param == NULL)
+               return;
+
+       if (g_strcmp0(sig, CONNMAN_SIGNAL_SERVICES_CHANGED) != 0)
+               return;
+
+       if (netconfig_get_default_profile() != NULL)
+               return;
+
+       g_variant_get(param, "(a(oa{sv})ao)", &added, &removed);
+
+       while (g_variant_iter_loop(added, "(oa{sv})", &service_path, &next)) {
+               gboolean is_wifi_prof, is_cell_prof, is_cell_internet_prof;
+               is_wifi_prof = netconfig_is_wifi_profile(service_path);
+               is_cell_prof = netconfig_is_cellular_profile(service_path);
+               is_cell_internet_prof = netconfig_is_cellular_internet_profile(
+                               service_path);
+               if (service_path != NULL) {
+                       while (g_variant_iter_loop(next, "{sv}", &property,
+                                               &variant)) {
+                               if (g_strcmp0(property, "State") == 0) {
+                                       g_variant_get(variant, "s", &value);
+                                       DBG("Profile %s State %s", service_path,
+                                                       value);
+                                       if (g_strcmp0(value, "ready") != 0 &&
+                                                       g_strcmp0(value,
+                                                               "online") != 0) {
+                                               g_free(property);
+                                               g_variant_unref(variant);
+                                               break;
+                                       }
+
+                                       if(!is_cell_prof)
+                                               netconfig_update_default_profile(
+                                                               service_path);
+                                       else if (is_cell_internet_prof) {
+                                               netconfig_update_default_profile(
+                                                               service_path);
+                                       }
+                                       if (is_wifi_prof)
+                                               wifi_state_set_service_state(
+                                                       NETCONFIG_WIFI_CONNECTED);
+                                       else if (is_cell_prof &&
+                                                       is_cell_internet_prof)
+                                               cellular_state_set_service_state(
+                                                       NETCONFIG_CELLULAR_ONLINE);
+                                       g_free(property);
+                                       g_variant_unref(variant);
+                                       break;
+                               }
+                       }
+               }
+       }
+       if (next)
+               g_variant_iter_free(next);
+       if (added)
+               g_variant_iter_free(added);
+       if (removed)
+               g_variant_iter_free(removed);
+       return;
+}
+
 static void _supplicant_interface_removed(GDBusConnection *conn,
                const gchar *name, const gchar *path, const gchar *interface,
                const gchar *sig, GVariant *param, gpointer user_data)
@@ -551,6 +622,18 @@ void register_gdbus_signal(void)
                        NULL,
                        NULL);
 
+       conn_subscription_ids[3] = g_dbus_connection_signal_subscribe(
+                       connection,
+                       CONNMAN_SERVICE,
+                       CONNMAN_MANAGER_INTERFACE,
+                       CONNMAN_SIGNAL_SERVICES_CHANGED,
+                       NULL,
+                       NULL,
+                       G_DBUS_SIGNAL_FLAGS_NONE,
+                       _services_changed_cb,
+                       NULL,
+                       NULL);
+
        INFO("Successfully register connman DBus signal filters");
 
        for (sig = SIG_INTERFACE_REMOVED; sig < SIG_MAX; sig++) {
index b8b02a6..bb6facc 100755 (executable)
@@ -268,7 +268,8 @@ gboolean handle_set_field(NetConnmanAgent *connman_agent,
 
        if (updated == TRUE) {
                reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
-                               service, CONNMAN_SERVICE_INTERFACE, "Connect", NULL, NULL);
+                               service, CONNMAN_SERVICE_INTERFACE, "Connect",
+                               NULL, __netconfig_wifi_connect_reply);
                if (reply == TRUE) {
                        g_dbus_method_invocation_return_value (context, NULL);
                } else {
index 72b0636..adaa63d 100755 (executable)
@@ -515,7 +515,8 @@ gboolean handle_create_eap_config(Wifi *wifi, GDBusMethodInvocation *context,
                }
 
                result = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE,
-                               service, CONNMAN_SERVICE_INTERFACE, "Connect", NULL, NULL);
+                               service, CONNMAN_SERVICE_INTERFACE, "Connect",
+                               NULL, __netconfig_wifi_connect_reply);
 
                if (netconfig_eap_notifier.user_data != NULL) {
                        g_free(netconfig_eap_notifier.user_data);
index 796849c..ea1b2d7 100755 (executable)
@@ -69,6 +69,32 @@ static void _set_wifi_mac_address(void)
        }
 }
 
+void __netconfig_wifi_connect_reply(GObject *source_object, GAsyncResult *res,
+               gpointer user_data)
+{
+       GDBusConnection *conn = NULL;
+       GError *error = NULL;
+
+       DBG("WiFi Connection Reply");
+
+       conn = G_DBUS_CONNECTION(source_object);
+       g_dbus_connection_call_finish(conn, res, &error);
+       if (error != NULL) {
+               ERR("WiFi Connection Error [%s]", error->message);
+               g_error_free(error);
+               if (netconfig_dbus_emit_signal(NULL, NETCONFIG_WIFI_PATH,
+                               NETCONFIG_WIFI_INTERFACE, "WiFiConnectFail",
+                               NULL) == FALSE)
+                       ERR("Failed to emit WiFiConnectFail signal");
+               else
+                       DBG("Successfully sent WiFiConnectFail signal");
+       } else
+               DBG("WiFi Connection has been initiated successfully");
+
+       netconfig_gdbus_pending_call_unref();
+       return;
+}
+
 void wifi_object_create_and_init(void)
 {
        DBG("Create wifi object.");