DA: Fix build warnings
[platform/upstream/connman.git] / gsupplicant / dbus.c
old mode 100644 (file)
new mode 100755 (executable)
index 5b15bcd..73c9ace
@@ -30,6 +30,7 @@
 #include <glib.h>
 
 #include "dbus.h"
+#include <connman/log.h>
 
 #define TIMEOUT 30000
 
@@ -59,10 +60,35 @@ static int find_method_call_by_caller(gconstpointer a, gconstpointer b)
        return method_call->caller != caller;
 }
 
+static GSList *property_calls;
+
+struct property_call_data {
+       gpointer caller;
+       DBusPendingCall *pending_call;
+       supplicant_dbus_property_function function;
+       void *user_data;
+};
+
+static void property_call_free(void *pointer)
+{
+       struct property_call_data *property_call = pointer;
+       property_calls = g_slist_remove(property_calls, property_call);
+       g_free(property_call);
+}
+
+static int find_property_call_by_caller(gconstpointer a, gconstpointer b)
+{
+       const struct property_call_data *property_call = a;
+       gconstpointer caller = b;
+
+       return property_call->caller != caller;
+}
+
 void supplicant_dbus_setup(DBusConnection *conn)
 {
        connection = conn;
        method_calls = NULL;
+       property_calls = NULL;
 }
 
 void supplicant_dbus_array_foreach(DBusMessageIter *iter,
@@ -124,14 +150,27 @@ void supplicant_dbus_property_foreach(DBusMessageIter *iter,
        }
 }
 
-struct property_get_data {
-       supplicant_dbus_property_function function;
-       void *user_data;
-};
+void supplicant_dbus_property_call_cancel_all(gpointer caller)
+{
+       while (property_calls) {
+               struct property_call_data *property_call;
+               GSList *elem = g_slist_find_custom(property_calls, caller,
+                                               find_property_call_by_caller);
+               if (!elem)
+                       break;
+
+               property_call = elem->data;
+               property_calls = g_slist_delete_link(property_calls, elem);
+
+               dbus_pending_call_cancel(property_call->pending_call);
+
+               dbus_pending_call_unref(property_call->pending_call);
+       }
+}
 
 static void property_get_all_reply(DBusPendingCall *call, void *user_data)
 {
-       struct property_get_data *data = user_data;
+       struct property_call_data *property_call = user_data;
        DBusMessage *reply;
        DBusMessageIter iter;
 
@@ -143,11 +182,11 @@ static void property_get_all_reply(DBusPendingCall *call, void *user_data)
        if (!dbus_message_iter_init(reply, &iter))
                goto done;
 
-       supplicant_dbus_property_foreach(&iter, data->function,
-                                                       data->user_data);
+       supplicant_dbus_property_foreach(&iter, property_call->function,
+                                               property_call->user_data);
 
-       if (data->function)
-               data->function(NULL, NULL, data->user_data);
+       if (property_call->function)
+               property_call->function(NULL, NULL, property_call->user_data);
 
 done:
        dbus_message_unref(reply);
@@ -157,9 +196,9 @@ done:
 
 int supplicant_dbus_property_get_all(const char *path, const char *interface,
                                supplicant_dbus_property_function function,
-                                                       void *user_data)
+                               void *user_data, gpointer caller)
 {
-       struct property_get_data *data;
+       struct property_call_data *property_call = NULL;
        DBusMessage *message;
        DBusPendingCall *call;
 
@@ -169,14 +208,14 @@ int supplicant_dbus_property_get_all(const char *path, const char *interface,
        if (!path || !interface)
                return -EINVAL;
 
-       data = dbus_malloc0(sizeof(*data));
-       if (!data)
+       property_call = g_try_new0(struct property_call_data, 1);
+       if (!property_call)
                return -ENOMEM;
 
        message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path,
                                        DBUS_INTERFACE_PROPERTIES, "GetAll");
        if (!message) {
-               dbus_free(data);
+               g_free(property_call);
                return -ENOMEM;
        }
 
@@ -187,21 +226,25 @@ int supplicant_dbus_property_get_all(const char *path, const char *interface,
        if (!dbus_connection_send_with_reply(connection, message,
                                                &call, TIMEOUT)) {
                dbus_message_unref(message);
-               dbus_free(data);
+               g_free(property_call);
                return -EIO;
        }
 
        if (!call) {
                dbus_message_unref(message);
-               dbus_free(data);
+               g_free(property_call);
                return -EIO;
        }
 
-       data->function = function;
-       data->user_data = user_data;
+       property_call->caller = caller;
+       property_call->pending_call = call;
+       property_call->function = function;
+       property_call->user_data = user_data;
+
+       property_calls = g_slist_prepend(property_calls, property_call);
 
        dbus_pending_call_set_notify(call, property_get_all_reply,
-                                                       data, dbus_free);
+                               property_call, property_call_free);
 
        dbus_message_unref(message);
 
@@ -210,7 +253,7 @@ int supplicant_dbus_property_get_all(const char *path, const char *interface,
 
 static void property_get_reply(DBusPendingCall *call, void *user_data)
 {
-       struct property_get_data *data = user_data;
+       struct property_call_data *property_call = user_data;
        DBusMessage *reply;
        DBusMessageIter iter;
 
@@ -227,8 +270,9 @@ static void property_get_reply(DBusPendingCall *call, void *user_data)
 
                dbus_message_iter_recurse(&iter, &variant);
 
-               if (data->function)
-                       data->function(NULL, &variant, data->user_data);
+               if (property_call->function)
+                       property_call->function(NULL, &variant,
+                                               property_call->user_data);
        }
 done:
        dbus_message_unref(reply);
@@ -239,9 +283,9 @@ done:
 int supplicant_dbus_property_get(const char *path, const char *interface,
                                const char *method,
                                supplicant_dbus_property_function function,
-                                                       void *user_data)
+                               void *user_data, gpointer caller)
 {
-       struct property_get_data *data;
+       struct property_call_data *property_call = NULL;
        DBusMessage *message;
        DBusPendingCall *call;
 
@@ -251,15 +295,15 @@ int supplicant_dbus_property_get(const char *path, const char *interface,
        if (!path || !interface || !method)
                return -EINVAL;
 
-       data = dbus_malloc0(sizeof(*data));
-       if (!data)
+       property_call = g_try_new0(struct property_call_data, 1);
+       if (!property_call)
                return -ENOMEM;
 
        message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path,
                                        DBUS_INTERFACE_PROPERTIES, "Get");
 
        if (!message) {
-               dbus_free(data);
+               g_free(property_call);
                return -ENOMEM;
        }
 
@@ -271,35 +315,34 @@ int supplicant_dbus_property_get(const char *path, const char *interface,
        if (!dbus_connection_send_with_reply(connection, message,
                                                &call, TIMEOUT)) {
                dbus_message_unref(message);
-               dbus_free(data);
+               g_free(property_call);
                return -EIO;
        }
 
        if (!call) {
                dbus_message_unref(message);
-               dbus_free(data);
+               g_free(property_call);
                return -EIO;
        }
 
-       data->function = function;
-       data->user_data = user_data;
+       property_call->caller = caller;
+       property_call->pending_call = call;
+       property_call->function = function;
+       property_call->user_data = user_data;
+
+       property_calls = g_slist_prepend(property_calls, property_call);
 
        dbus_pending_call_set_notify(call, property_get_reply,
-                                                       data, dbus_free);
+                                       property_call, property_call_free);
 
        dbus_message_unref(message);
 
        return 0;
 }
 
-struct property_set_data {
-       supplicant_dbus_result_function function;
-       void *user_data;
-};
-
 static void property_set_reply(DBusPendingCall *call, void *user_data)
 {
-       struct property_set_data *data = user_data;
+       struct property_call_data *property_call = user_data;
        DBusMessage *reply;
        DBusMessageIter iter;
        const char *error;
@@ -313,8 +356,8 @@ static void property_set_reply(DBusPendingCall *call, void *user_data)
 
        dbus_message_iter_init(reply, &iter);
 
-       if (data->function)
-               data->function(error, &iter, data->user_data);
+       if (property_call->function)
+               property_call->function(error, &iter, property_call->user_data);
 
        dbus_message_unref(reply);
 
@@ -325,9 +368,9 @@ int supplicant_dbus_property_set(const char *path, const char *interface,
                                const char *key, const char *signature,
                                supplicant_dbus_setup_function setup,
                                supplicant_dbus_result_function function,
-                                                       void *user_data)
+                               void *user_data, gpointer caller)
 {
-       struct property_set_data *data;
+       struct property_call_data *property_call = NULL;
        DBusMessage *message;
        DBusMessageIter iter, value;
        DBusPendingCall *call;
@@ -341,14 +384,14 @@ int supplicant_dbus_property_set(const char *path, const char *interface,
        if (!key || !signature || !setup)
                return -EINVAL;
 
-       data = dbus_malloc0(sizeof(*data));
-       if (!data)
+       property_call = g_try_new0(struct property_call_data, 1);
+       if (!property_call)
                return -ENOMEM;
 
        message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path,
                                        DBUS_INTERFACE_PROPERTIES, "Set");
        if (!message) {
-               dbus_free(data);
+               g_free(property_call);
                return -ENOMEM;
        }
 
@@ -366,21 +409,25 @@ int supplicant_dbus_property_set(const char *path, const char *interface,
        if (!dbus_connection_send_with_reply(connection, message,
                                                &call, TIMEOUT)) {
                dbus_message_unref(message);
-               dbus_free(data);
+               g_free(property_call);
                return -EIO;
        }
 
        if (!call) {
                dbus_message_unref(message);
-               dbus_free(data);
+               g_free(property_call);
                return -EIO;
        }
 
-       data->function = function;
-       data->user_data = user_data;
+       property_call->caller = caller;
+       property_call->pending_call = call;
+       property_call->function = function;
+       property_call->user_data = user_data;
+
+       property_calls = g_slist_prepend(property_calls, property_call);
 
        dbus_pending_call_set_notify(call, property_set_reply,
-                                                       data, dbus_free);
+                                       property_call, property_call_free);
 
        dbus_message_unref(message);
 
@@ -450,7 +497,10 @@ int supplicant_dbus_method_call(const char *path,
 
        if (!path || !interface || !method)
                return -EINVAL;
-
+#if defined TIZEN_EXT
+       if (strlen(path) == 0)
+               return -EINVAL;
+#endif
        method_call = g_try_new0(struct method_call_data, 1);
        if (!method_call)
                return -ENOMEM;
@@ -578,6 +628,7 @@ void supplicant_dbus_property_append_array(DBusMessageIter *iter,
 
        switch (type) {
        case DBUS_TYPE_STRING:
+       case DBUS_TYPE_BYTE:
                variant_sig = DBUS_TYPE_ARRAY_AS_STRING
                                DBUS_TYPE_ARRAY_AS_STRING
                                DBUS_TYPE_BYTE_AS_STRING;