Update WISPr command line client to use GWeb
[framework/connectivity/connman.git] / plugins / dhclient.c
index fc42024..e63e1dc 100644 (file)
@@ -2,7 +2,7 @@
  *
  *  Connection Manager
  *
- *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2007-2010  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
 
 #define CONNMAN_API_SUBJECT_TO_CHANGE
 #include <connman/plugin.h>
+#include <connman/utsname.h>
 #include <connman/dhcp.h>
 #include <connman/task.h>
 #include <connman/log.h>
 
-#if 0
-static unsigned char netmask2prefixlen(const char *netmask)
-{
-       unsigned char bits = 0;
-       in_addr_t mask = inet_network(netmask);
-       in_addr_t host = ~mask;
-
-       /* a valid netmask must be 2^n - 1 */
-       if ((host & (host + 1)) != 0)
-               return -1;
-
-       for (; mask; mask <<= 1)
-               ++bits;
-
-       return bits;
-}
-#endif
-
 static void dhclient_notify(struct connman_task *task,
                                        DBusMessage *msg, void *user_data)
 {
@@ -105,6 +88,8 @@ static void dhclient_notify(struct connman_task *task,
                        connman_dhcp_set_value(dhcp, "Timeserver", value);
                } else if (g_ascii_strcasecmp(key, "new_interface_mtu") == 0) {
                        connman_dhcp_set_value(dhcp, "MTU", value);
+               } else if (g_ascii_strcasecmp(key, "new_proxy_auto_config") == 0) {
+                       connman_dhcp_set_value(dhcp, "PAC", value);
                }
 
                dbus_message_iter_next(&dict);
@@ -129,15 +114,34 @@ struct dhclient_data {
        char *ifname;
 };
 
+static void dhclient_unlink(const char *ifname)
+{
+       char *pathname;
+
+       pathname = g_strdup_printf("%s/dhclient.%s.pid",
+                                               STATEDIR, ifname);
+       unlink(pathname);
+       g_free(pathname);
+
+       pathname = g_strdup_printf("%s/dhclient.%s.leases",
+                                               STATEDIR, ifname);
+       unlink(pathname);
+       g_free(pathname);
+}
+
 static void dhclient_died(struct connman_task *task, void *user_data)
 {
        struct dhclient_data *dhclient = user_data;
 
+       connman_dhcp_set_data(dhclient->dhcp, NULL);
+
        connman_dhcp_unref(dhclient->dhcp);
 
        connman_task_destroy(dhclient->task);
        dhclient->task = NULL;
 
+       dhclient_unlink(dhclient->ifname);
+
        g_free(dhclient->ifname);
        g_free(dhclient);
 }
@@ -163,21 +167,6 @@ static void dhclient_setup(struct connman_task *task, const char *ifname)
        connman_task_add_argument(task, "-n", NULL);
 }
 
-static void dhclient_unlink(const char *ifname)
-{
-       char *pathname;
-
-       pathname = g_strdup_printf("%s/dhclient.%s.pid",
-                                               STATEDIR, ifname);
-       unlink(pathname);
-       g_free(pathname);
-
-       pathname = g_strdup_printf("%s/dhclient.%s.leases",
-                                               STATEDIR, ifname);
-       unlink(pathname);
-       g_free(pathname);
-}
-
 static int dhclient_request(struct connman_dhcp *dhcp)
 {
        struct dhclient_data *dhclient;
@@ -207,7 +196,8 @@ static int dhclient_request(struct connman_dhcp *dhcp)
        connman_task_set_notify(dhclient->task, "Notify",
                                                dhclient_notify, dhcp);
 
-       connman_task_run(dhclient->task, dhclient_died, dhclient);
+       connman_task_run(dhclient->task, dhclient_died, dhclient,
+                                               NULL, NULL, NULL);
 
        return 0;
 }
@@ -218,16 +208,17 @@ static int dhclient_release(struct connman_dhcp *dhcp)
 
        DBG("dhcp %p", dhcp);
 
-       if (dhclient->task != NULL)
-               connman_task_stop(dhclient->task);
+       if (dhclient == NULL)
+               return -ESRCH;
 
-       dhclient_unlink(dhclient->ifname);
+       connman_task_stop(dhclient->task);
 
        return 0;
 }
 
 static struct connman_dhcp_driver dhclient_driver = {
        .name           = "dhclient",
+       .priority       = CONNMAN_DHCP_PRIORITY_LOW,
        .request        = dhclient_request,
        .release        = dhclient_release,
 };