New property "Script" on the net.connman.Service D-Bus interface. The caller can provide a PAC script instead of an URL. The pacrunner plugin can give the PAC script to pacrunner when calling the D-Bus method org.pacrunner.Manager.CreateProxyConfiguration().
https://bugs.meego.com/show_bug.cgi?id=10025 --- doc/service-api.txt | 32 +++++++++++++++++++++------- include/service.h | 1 + plugins/pacrunner.c | 17 +++++++++----- src/service.c | 58 +++++++++++++++++++++++++++++++++++++++++++++----- 4 files changed, 88 insertions(+), 20 deletions(-) diff --git a/doc/service-api.txt b/doc/service-api.txt index 2123e91..f817145 100644 --- a/doc/service-api.txt +++ b/doc/service-api.txt @@ -394,11 +394,11 @@ Properties string State [readonly] Possible values are "direct", "auto" and "manual". - In case of "auto" method, the URL file can be - provided unless you want to let DHCP/WPAD - auto-discover to be tried. In such case if DHCP - and WPAD auto-discover methods fails then - method will be "direct". + In case of "auto" method, either the URL file + or a PAC script can be provided unless you want + to let DHCP/WPAD auto-discover to be tried. In + such case if DHCP and WPAD auto-discover + methods fails then method will be "direct". In case of "direct" no additional information are provided. For the "manual" method the @@ -409,6 +409,22 @@ Properties string State [readonly] Automatic proxy configuration URL. Used by "auto" method. + string Script [optional] + + PAC script as text string. The script must + be valid Javascript with FindProxyForURL() + function. + + Example: + + function FindProxyForURL(url, host) + { + return "DIRECT"; + } + + Used when "auto" method is set. URL and Script + cannot be used both. + array{string} Servers [readonly] Used when "manual" method is set. @@ -433,9 +449,9 @@ Properties string State [readonly] the actual system configuration while this allows user configuration. - If "auto" method is set with an empty URL, then - DHCP/WPAD auto-discover will be tried. Otherwise the - specified URL will be used. + If "auto" method is set with an empty URL and an empty + script, then DHCP/WPAD auto-discover will be tried. + Otherwise the specified URL or script will be used. dict Provider [readonly] diff --git a/include/service.h b/include/service.h index 36c8658..b2b1186 100644 --- a/include/service.h +++ b/include/service.h @@ -102,6 +102,7 @@ enum connman_service_proxy_method connman_service_get_proxy_method(struct connma char **connman_service_get_proxy_servers(struct connman_service *service); char **connman_service_get_proxy_excludes(struct connman_service *service); const char *connman_service_get_proxy_url(struct connman_service *service); +const char *connman_service_get_proxy_script(struct connman_service *service); const char *connman_service_get_proxy_autoconfig(struct connman_service *service); #ifdef __cplusplus diff --git a/plugins/pacrunner.c b/plugins/pacrunner.c index 84c22ab..71c41ef 100644 --- a/plugins/pacrunner.c +++ b/plugins/pacrunner.c @@ -150,16 +150,21 @@ static void create_proxy_configuration(void) case CONNMAN_SERVICE_PROXY_METHOD_AUTO: method = "auto"; - str = connman_service_get_proxy_url(default_service); + str = connman_service_get_proxy_script(default_service); if (str == NULL) { - str = connman_service_get_proxy_autoconfig( - default_service); + str = connman_service_get_proxy_url(default_service); + if (str == NULL) { + str = connman_service_get_proxy_autoconfig( + default_service); + } if (str == NULL) goto done; + connman_dbus_dict_append_basic(&dict, "URL", + DBUS_TYPE_STRING, &str); + } else { + connman_dbus_dict_append_basic(&dict, "Script", + DBUS_TYPE_STRING, &str); } - - connman_dbus_dict_append_basic(&dict, "URL", - DBUS_TYPE_STRING, &str); break; } diff --git a/src/service.c b/src/service.c index ec54a94..3a6fe44 100644 --- a/src/service.c +++ b/src/service.c @@ -109,6 +109,7 @@ struct connman_service { char **proxies; char **excludes; char *pac; + char *pac_script; connman_bool_t wps; }; @@ -1178,14 +1179,19 @@ static void append_proxy(DBusMessageIter *iter, void *user_data) pac = __connman_ipconfig_get_proxy_autoconfig( service->ipconfig_ipv6); - if (service->pac == NULL && pac == NULL) + if (service->pac == NULL && pac == NULL && + service->pac_script == NULL) goto done; if (service->pac != NULL) pac = service->pac; - connman_dbus_dict_append_basic(iter, "URL", - DBUS_TYPE_STRING, &pac); + if (pac) + connman_dbus_dict_append_basic(iter, "URL", + DBUS_TYPE_STRING, &pac); + else + connman_dbus_dict_append_basic(iter, "Script", + DBUS_TYPE_STRING, &service->pac_script); break; } @@ -1224,6 +1230,9 @@ static void append_proxyconfig(DBusMessageIter *iter, void *user_data) if (service->pac != NULL) connman_dbus_dict_append_basic(iter, "URL", DBUS_TYPE_STRING, &service->pac); + else if (service->pac_script != NULL) + connman_dbus_dict_append_basic(iter, "Script", + DBUS_TYPE_STRING, &service->pac_script); break; } @@ -1873,7 +1882,8 @@ enum connman_service_proxy_method connman_service_get_proxy_method( if (service->proxy_config != CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN) { if (service->proxy_config == CONNMAN_SERVICE_PROXY_METHOD_AUTO && - service->pac == NULL) + service->pac == NULL && + service->pac_script == NULL) return service->proxy; return service->proxy_config; @@ -1900,6 +1910,14 @@ const char *connman_service_get_proxy_url(struct connman_service *service) return service->pac; } +const char *connman_service_get_proxy_script(struct connman_service *service) +{ + if (service == NULL) + return NULL; + + return service->pac_script; +} + void __connman_service_set_proxy_autoconfig(struct connman_service *service, const char *url) { @@ -2143,6 +2161,7 @@ static int update_proxy_configuration(struct connman_service *service, GString *servers_str = NULL; GString *excludes_str = NULL; const char *url = NULL; + const char *script = NULL; method = CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN; @@ -2181,6 +2200,11 @@ static int update_proxy_configuration(struct connman_service *service, goto error; dbus_message_iter_get_basic(&variant, &url); + } else if (g_str_equal(key, "Script") == TRUE) { + if (type != DBUS_TYPE_STRING) + goto error; + + dbus_message_iter_get_basic(&variant, &script); } else if (g_str_equal(key, "Servers") == TRUE) { DBusMessageIter str_array; @@ -2271,11 +2295,18 @@ static int update_proxy_configuration(struct connman_service *service, break; case CONNMAN_SERVICE_PROXY_METHOD_AUTO: g_free(service->pac); + g_free(service->pac_script); - if (url != NULL && strlen(url) > 0) + if (url != NULL && strlen(url) > 0) { service->pac = g_strdup(url); - else + service->pac_script = NULL; + } else if (script != NULL && strlen(script) > 0) { service->pac = NULL; + service->pac_script = g_strdup(script); + } else { + service->pac = NULL; + service->pac_script = NULL; + } /* if we are connected: - if service->pac == NULL @@ -3066,6 +3097,7 @@ static void service_free(gpointer user_data) g_free(service->private_key_file); g_free(service->private_key_passphrase); g_free(service->phase2); + g_free(service->pac_script); if (service->stats.timer != NULL) g_timer_destroy(service->stats.timer); @@ -5266,6 +5298,13 @@ static int service_load(struct connman_service *service) service->pac = str; } + str = g_key_file_get_string(keyfile, + service->identifier, "Proxy.Script", NULL); + if (str != NULL) { + g_free(service->pac_script); + service->pac_script = str; + } + done: g_key_file_free(keyfile); @@ -5446,6 +5485,13 @@ update: g_key_file_remove_key(keyfile, service->identifier, "Proxy.URL", NULL); + if (service->pac_script != NULL && strlen(service->pac_script) > 0) + g_key_file_set_string(keyfile, service->identifier, + "Proxy.Script", service->pac_script); + else + g_key_file_remove_key(keyfile, service->identifier, + "Proxy.Script", NULL); + data = g_key_file_to_data(keyfile, &length, NULL); if (g_file_set_contents(pathname, data, length, NULL) == FALSE) -- 1.7.5.4 _______________________________________________ connman mailing list [email protected] http://lists.connman.net/listinfo/connman
