Added support of WPA3-SAE security mode.
[platform/upstream/connman.git] / src / counter.c
old mode 100644 (file)
new mode 100755 (executable)
index 6a0a994..8ea6205
@@ -2,7 +2,7 @@
  *
  *  Connection Manager
  *
- *  Copyright (C) 2007-2010  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2007-2012  Intel Corporation. All rights reserved.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License version 2 as
@@ -23,6 +23,8 @@
 #include <config.h>
 #endif
 
+#include <errno.h>
+
 #include <gdbus.h>
 
 #include "connman.h"
@@ -45,9 +47,6 @@ static void remove_counter(gpointer user_data)
 
        DBG("owner %s path %s", counter->owner, counter->path);
 
-       if (counter->watch > 0)
-               g_dbus_remove_watch(connection, counter->watch);
-
        __connman_rtnl_update_interval_remove(counter->interval);
 
        __connman_service_counter_unregister(counter->path);
@@ -57,7 +56,7 @@ static void remove_counter(gpointer user_data)
        g_free(counter);
 }
 
-static void owner_disconnect(DBusConnection *connection, void *user_data)
+static void owner_disconnect(DBusConnection *conn, void *user_data)
 {
        struct connman_counter *counter = user_data;
 
@@ -76,11 +75,11 @@ int __connman_counter_register(const char *owner, const char *path,
        DBG("owner %s path %s interval %u", owner, path, interval);
 
        counter = g_hash_table_lookup(counter_table, path);
-       if (counter != NULL)
+       if (counter)
                return -EEXIST;
 
        counter = g_try_new0(struct connman_counter, 1);
-       if (counter == NULL)
+       if (!counter)
                return -ENOMEM;
 
        counter->owner = g_strdup(owner);
@@ -113,12 +112,15 @@ int __connman_counter_unregister(const char *owner, const char *path)
        DBG("owner %s path %s", owner, path);
 
        counter = g_hash_table_lookup(counter_table, path);
-       if (counter == NULL)
+       if (!counter)
                return -ESRCH;
 
        if (g_strcmp0(owner, counter->owner) != 0)
                return -EACCES;
 
+       if (counter->watch > 0)
+               g_dbus_remove_watch(connection, counter->watch);
+
        g_hash_table_remove(owner_mapping, counter->owner);
        g_hash_table_remove(counter_table, counter->path);
 
@@ -131,8 +133,11 @@ void __connman_counter_send_usage(const char *path,
        struct connman_counter *counter;
 
        counter = g_hash_table_lookup(counter_table, path);
-       if (counter == NULL)
+       if (!counter) {
+               if (message)
+                       dbus_message_unref(message);
                return;
+       }
 
        dbus_message_set_destination(message, counter->owner);
        dbus_message_set_path(message, counter->path);
@@ -150,9 +155,12 @@ static void release_counter(gpointer key, gpointer value, gpointer user_data)
 
        DBG("owner %s path %s", counter->owner, counter->path);
 
+       if (counter->watch > 0)
+               g_dbus_remove_watch(connection, counter->watch);
+
        message = dbus_message_new_method_call(counter->owner, counter->path,
                                        CONNMAN_COUNTER_INTERFACE, "Release");
-       if (message == NULL)
+       if (!message)
                return;
 
        dbus_message_set_no_reply(message, TRUE);
@@ -165,7 +173,7 @@ int __connman_counter_init(void)
        DBG("");
 
        connection = connman_dbus_get_connection();
-       if (connection == NULL)
+       if (!connection)
                return -1;
 
        counter_table = g_hash_table_new_full(g_str_hash, g_str_equal,
@@ -180,7 +188,7 @@ void __connman_counter_cleanup(void)
 {
        DBG("");
 
-       if (connection == NULL)
+       if (!connection)
                return;
 
        g_hash_table_foreach(counter_table, release_counter, NULL);