Add basic interfaces for automatic proxy configuration
authorMarcel Holtmann <marcel@holtmann.org>
Mon, 4 Jan 2010 02:47:21 +0000 (18:47 -0800)
committerMarcel Holtmann <marcel@holtmann.org>
Mon, 4 Jan 2010 02:47:21 +0000 (18:47 -0800)
doc/service-api.txt
plugins/dhclient.c
plugins/openconnect.c
scripts/dhclient.conf
src/connman.h
src/dhcp.c
src/ipconfig.c
src/provider.c
src/service.c

index 1fe37ea..0f22f39 100644 (file)
@@ -302,6 +302,28 @@ Properties string State [readonly]
                        the actual system configuration while this allows
                        user configuration.
 
+               dict Proxy [readonly]
+
+                       string Method [readonly]
+
+                               Possible values are "direct", "auto",
+                               "manual" and "auto-config".
+
+                               If the DHCP server provides an automatic
+                               configuration URL, then this value is set
+                               to "auto-config". The PAC file will be
+                               referenced by the URL value.
+
+                               If no automatic configuration is available,
+                               then "direct" is set.
+
+                               The values "auto" and "manual" are not yet
+                               supported.
+
+                       string URL [readonly]
+
+                               Automatic proxy configuration URL.
+
                dict Ethernet [readonly]
 
                        string Method [readonly]
index 1a86fa4..ed170ed 100644 (file)
@@ -87,6 +87,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);
index bbe8bb8..891aa87 100644 (file)
@@ -188,6 +188,9 @@ static void openconnect_task_notify(struct connman_task *task,
                if (!strcmp(key, "INTERNAL_IP4_DNS"))
                        connman_provider_set_string(provider, "DNS", value);
 
+               if (!strcmp(key, "CISCO_PROXY_PAC"))
+                       connman_provider_set_string(provider, "PAC", value);
+
                if (domain == NULL && !strcmp(key, "CISCO_DEF_DOMAIN"))
                        domain = value;
 
index dc116ef..3ed1829 100644 (file)
@@ -1,5 +1,7 @@
 send host-name "<hostname>";
+option proxy-auto-config code 252 = text;
 request subnet-mask, broadcast-address, routers, host-name,
        domain-search, domain-name, domain-name-servers,
-       time-offset, time-servers, ntp-servers, interface-mtu;
+       time-offset, time-servers, ntp-servers, interface-mtu,
+       proxy-auto-config;
 require subnet-mask, domain-name-servers;
index 38b3251..72e3bae 100644 (file)
@@ -134,7 +134,9 @@ void __connman_ipconfig_append_ipv4config(struct connman_ipconfig *ipconfig,
                                                        DBusMessageIter *iter);
 int __connman_ipconfig_set_ipv4config(struct connman_ipconfig *ipconfig,
                                                        DBusMessageIter *value);
-int __connman_ipconfig_append_ethernet(struct connman_ipconfig *ipconfig,
+void __connman_ipconfig_append_proxy(struct connman_ipconfig *ipconfig,
+                                                       DBusMessageIter *iter);
+void __connman_ipconfig_append_ethernet(struct connman_ipconfig *ipconfig,
                                                        DBusMessageIter *iter);
 
 int __connman_ipconfig_load(struct connman_ipconfig *ipconfig,
index 7a301f6..0e890c2 100644 (file)
@@ -122,6 +122,7 @@ void connman_dhcp_set_value(struct connman_dhcp *dhcp,
                g_free(dhcp->element->ipv4.timeserver);
                dhcp->element->ipv4.timeserver = g_strdup(value);
        } else if (g_strcmp0(key, "MTU") == 0) {
+       } else if (g_strcmp0(key, "PAC") == 0) {
        }
 }
 
index a731a9a..07fa770 100644 (file)
@@ -1118,7 +1118,16 @@ int __connman_ipconfig_set_ipv4config(struct connman_ipconfig *ipconfig,
        return 0;
 }
 
-int __connman_ipconfig_append_ethernet(struct connman_ipconfig *ipconfig,
+void __connman_ipconfig_append_proxy(struct connman_ipconfig *ipconfig,
+                                                       DBusMessageIter *iter)
+{
+       const char *method = "direct";
+
+       connman_dbus_dict_append_basic(iter, "Method",
+                                               DBUS_TYPE_STRING, &method);
+}
+
+void __connman_ipconfig_append_ethernet(struct connman_ipconfig *ipconfig,
                                                        DBusMessageIter *iter)
 {
        const char *method = "auto";
@@ -1133,8 +1142,6 @@ int __connman_ipconfig_append_ethernet(struct connman_ipconfig *ipconfig,
        if (ipconfig->mtu > 0)
                connman_dbus_dict_append_basic(iter, "MTU",
                                        DBUS_TYPE_UINT16, &ipconfig->mtu);
-
-       return 0;
 }
 
 int __connman_ipconfig_load(struct connman_ipconfig *ipconfig,
index 7fb6701..e33f02e 100644 (file)
@@ -43,6 +43,7 @@ struct connman_provider {
        enum connman_provider_error error;
        char *name;
        char *type;
+       char *pac;
        char *dns;
        char *domain;
        DBusMessage *pending;
@@ -538,6 +539,7 @@ static void provider_free(gpointer user_data)
        g_free(provider->domain);
        g_free(provider->identifier);
        g_free(provider->dns);
+       g_free(provider->pac);
 }
 
 static void unregister_provider(gpointer data)
@@ -577,6 +579,7 @@ static void __connman_provider_initialize(struct connman_provider *provider)
 
        provider->name = NULL;
        provider->type = NULL;
+       provider->pac = NULL;
        provider->dns = NULL;
        provider->domain = NULL;
        provider->identifier = NULL;
@@ -793,10 +796,13 @@ int connman_provider_set_string(struct connman_provider *provider,
        } else if (g_str_equal(key, "Netmask") == TRUE) {
                g_free(provider->element.ipv4.netmask);
                provider->element.ipv4.netmask = g_strdup(value);
+       } else if (g_str_equal(key, "PAC") == TRUE) {
+               g_free(provider->pac);
+               provider->pac = g_strdup(value);
        } else if (g_str_equal(key, "DNS") == TRUE) {
                g_free(provider->dns);
                provider->dns = g_strdup(value);
-       } else if (g_str_equal(key, "Domain")) {
+       } else if (g_str_equal(key, "Domain") == TRUE) {
                g_free(provider->domain);
                provider->domain = g_strdup(value);
        }
index ddb9fcb..2970ad0 100644 (file)
@@ -440,6 +440,26 @@ static void append_ipv4config(DBusMessageIter *iter, void *user_data)
                __connman_ipconfig_append_ipv4config(service->ipconfig, iter);
 }
 
+static void append_proxy(DBusMessageIter *iter, void *user_data)
+{
+       struct connman_service *service = user_data;
+
+       switch (service->state) {
+       case CONNMAN_SERVICE_STATE_UNKNOWN:
+       case CONNMAN_SERVICE_STATE_IDLE:
+       case CONNMAN_SERVICE_STATE_FAILURE:
+       case CONNMAN_SERVICE_STATE_DISCONNECT:
+       case CONNMAN_SERVICE_STATE_ASSOCIATION:
+       case CONNMAN_SERVICE_STATE_CONFIGURATION:
+               return;
+       case CONNMAN_SERVICE_STATE_READY:
+               break;
+       }
+
+       if (service->ipconfig != NULL)
+               __connman_ipconfig_append_proxy(service->ipconfig, iter);
+}
+
 static void settings_changed(struct connman_service *service)
 {
        connman_dbus_property_changed_dict(service->path,
@@ -597,6 +617,8 @@ static DBusMessage *get_properties(DBusConnection *conn,
        connman_dbus_dict_append_dict(&dict, "IPv4.Configuration",
                                                append_ipv4config, service);
 
+       connman_dbus_dict_append_dict(&dict, "Proxy", append_proxy, service);
+
        connman_dbus_dict_close(&array, &dict);
 
        return reply;