Add definitions for IPv4 methods
[connman] / src / iface.c
index a29c901..e5b88fa 100644 (file)
@@ -2,7 +2,7 @@
  *
  *  Connection Manager
  *
- *  Copyright (C) 2007  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2007-2008  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
@@ -863,27 +863,126 @@ static DBusMessage *set_network(DBusConnection *conn,
        return reply;
 }
 
+static DBusMessage *list_networks(DBusConnection *conn,
+                                       DBusMessage *msg, void *data)
+{
+       struct connman_iface *iface = data;
+       DBusMessage *reply;
+       DBusMessageIter array, iter;
+
+       DBG("conn %p", conn);
+
+       reply = dbus_message_new_method_return(msg);
+       if (reply == NULL)
+               return NULL;
+
+       dbus_message_iter_init_append(reply, &array);
+
+       dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
+                               DBUS_TYPE_OBJECT_PATH_AS_STRING, &iter);
+
+       __connman_iface_network_list(iface, &iter);
+
+       dbus_message_iter_close_container(&array, &iter);
+
+       return reply;
+}
+
+static DBusMessage *create_network(DBusConnection *conn,
+                                       DBusMessage *msg, void *data)
+{
+       struct connman_iface *iface = data;
+       DBusMessage *reply;
+       DBusMessageIter array, dict;
+       const char *path, *identifier = NULL, *passphrase = NULL;
+
+       DBG("conn %p", conn);
+
+       dbus_message_iter_init(msg, &array);
+
+       dbus_message_iter_recurse(&array, &dict);
+
+       while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+               DBusMessageIter entry, value;
+               const char *key, *val;
+
+               dbus_message_iter_recurse(&dict, &entry);
+               dbus_message_iter_get_basic(&entry, &key);
+
+               dbus_message_iter_next(&entry);
+
+               dbus_message_iter_recurse(&entry, &value);
+
+               //type = dbus_message_iter_get_arg_type(&value);
+               dbus_message_iter_get_basic(&value, &val);
+
+               if (g_strcasecmp(key, "Identifier") == 0)
+                       identifier = val;
+
+               if (g_strcasecmp(key, "Passphrase") == 0)
+                       passphrase = val;
+
+               dbus_message_iter_next(&dict);
+       }
+
+       DBG("identifier %s passphrase %s", identifier, passphrase);
+
+       path = __connman_iface_add_network(iface, identifier, passphrase);
+
+       reply = dbus_message_new_method_return(msg);
+       if (reply == NULL)
+               return NULL;
+
+       dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path,
+                                                       DBUS_TYPE_INVALID);
+
+       return reply;
+}
+
+static DBusMessage *remove_network(DBusConnection *conn,
+                                       DBusMessage *msg, void *data)
+{
+       struct connman_iface *iface = data;
+       DBusMessage *reply;
+       const char *path;
+
+       DBG("conn %p", conn);
+
+       dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+                                                       DBUS_TYPE_INVALID);
+
+       __connman_iface_remove_network(iface, path);
+
+       reply = dbus_message_new_method_return(msg);
+       if (reply == NULL)
+               return NULL;
+
+       dbus_message_append_args(reply, DBUS_TYPE_INVALID);
+
+       return reply;
+}
+
 static DBusMessage *select_network(DBusConnection *conn,
                                        DBusMessage *msg, void *data)
 {
        struct connman_iface *iface = data;
+       struct connman_network *network;
        DBusMessage *reply;
-       const char *network;
-       gchar *passphrase;
+       const char *path;
 
        DBG("conn %p", conn);
 
-       dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &network,
+       dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
                                                        DBUS_TYPE_INVALID);
 
-       passphrase = __connman_iface_find_passphrase(iface, network);
-       if (passphrase == NULL)
+       network = __connman_iface_find_network(iface, path);
+       if (network == NULL)
                goto done;
 
        g_free(iface->network.identifier);
-       iface->network.identifier = g_strdup(network);
+       iface->network.identifier = g_strdup(network->identifier);
        g_free(iface->network.passphrase);
-       iface->network.passphrase = passphrase;
+       iface->network.passphrase = g_strdup(network->passphrase);
 
        __connman_iface_connect(iface, &iface->network);
 
@@ -1054,7 +1153,10 @@ static GDBusMethodTable iface_methods[] = {
        { "SetPolicy",     "s",     "",      set_policy     },
        { "GetNetwork",    "",      "a{sv}", get_network    },
        { "SetNetwork",    "a{sv}", "",      set_network    },
-       { "SelectNetwork", "s",     "",      select_network },
+       { "ListNetworks",  "",      "ao",    list_networks  },
+       { "CreateNetwork", "a{av}", "o",     create_network },
+       { "RemoveNetwork", "o",     "",      remove_network },
+       { "SelectNetwork", "o",     "",      select_network },
        { "GetIPv4",       "",      "a{sv}", get_ipv4       },
        { "SetIPv4",       "a{sv}", "",      set_ipv4       },
        { },
@@ -1166,7 +1268,6 @@ static int probe_device(LibHalContext *ctx,
                ifname = libhal_device_get_property_string(ctx, udi,
                                                "net.interface", NULL);
                if (ifname != NULL && ifname_filter != NULL &&
-                                               *ifname_filter != '\0' &&
                                g_str_equal(ifname, ifname_filter) == FALSE) {
                        device_free(iface);
                        return -1;
@@ -1200,8 +1301,6 @@ static int probe_device(LibHalContext *ctx,
 
        conn = libhal_ctx_get_dbus_connection(ctx);
 
-       g_dbus_register_object(conn, iface->path, iface, device_free);
-
        interfaces = g_slist_append(interfaces, iface);
 
        if (iface->flags & CONNMAN_IFACE_FLAG_IPV4) {
@@ -1212,7 +1311,8 @@ static int probe_device(LibHalContext *ctx,
 
        g_dbus_register_interface(conn, iface->path,
                                        CONNMAN_IFACE_INTERFACE,
-                                       iface_methods, iface_signals, NULL);
+                                       iface_methods, iface_signals, NULL,
+                                                       iface, device_free);
 
        DBG("iface %p identifier %s", iface, iface->identifier);
 
@@ -1272,7 +1372,6 @@ static void device_removed(LibHalContext *ctx, const char *udi)
                        interfaces = g_slist_remove(interfaces, iface);
                        g_dbus_unregister_interface(conn, iface->path,
                                                CONNMAN_IFACE_INTERFACE);
-                       g_dbus_unregister_object_hierarchy(conn, iface->path);
                        break;
                }
        }
@@ -1375,8 +1474,6 @@ static void hal_cleanup(void *data)
 
                g_dbus_unregister_interface(conn, iface->path,
                                                CONNMAN_IFACE_INTERFACE);
-
-               g_dbus_unregister_object_hierarchy(conn, iface->path);
        }
 
        g_slist_free(interfaces);
@@ -1405,7 +1502,7 @@ int __connman_iface_init(DBusConnection *conn, const char *interface)
 
        hal_init(connection);
 
-       hal_watch = g_dbus_add_watch(connection, "org.freedesktop.Hal",
+       hal_watch = g_dbus_add_service_watch(connection, "org.freedesktop.Hal",
                                hal_init, hal_cleanup, connection, NULL);
 
        return 0;