--- src/manager.c | 77 ++++++++++++++++++++++++++++++++++++++++++------------- src/mozjs.c | 2 + src/pacrunner.h | 9 +++++- src/proxy.c | 46 +++++++++++++++++++++++++------- 4 files changed, 104 insertions(+), 30 deletions(-)
diff --git a/src/manager.c b/src/manager.c index 64e41d2..f1dbd06 100644 --- a/src/manager.c +++ b/src/manager.c @@ -80,7 +80,8 @@ static struct proxy_config *create_config(DBusConnection *conn, const char *method, const char *url, const char *script, - const char *server, + GString *servers, + GString *excludes, const char *interface, const char *domainname, const char *nameserver) @@ -111,8 +112,9 @@ static struct proxy_config *create_config(DBusConnection *conn, disconnect_callback, config, NULL); if (g_strcmp0(method, "manual") == 0) { - if (pacrunner_proxy_set_server(config->proxy, server) < 0) - pacrunner_error("Failed to set proxy server"); + if (pacrunner_proxy_set_manual(config->proxy, servers, + excludes) < 0) + pacrunner_error("Failed to set proxy servers"); return config; } else if (g_strcmp0(method, "auto") != 0) { @@ -133,6 +135,37 @@ static struct proxy_config *create_config(DBusConnection *conn, return config; } +static GString *get_string_list(DBusMessageIter *array) +{ + GString *list; + + DBG(" "); + + list = g_string_new(NULL); + if (list == NULL) + return NULL; + + while (dbus_message_iter_get_arg_type(array) == DBUS_TYPE_STRING) { + char *value = NULL; + + dbus_message_iter_get_basic(array, &value); + + if (list->len > 0) + g_string_append_printf(list, " %s", value); + else + g_string_append(list, value); + + dbus_message_iter_next(array); + } + + if (list->len == 0) { + g_string_free(list, TRUE); + list = NULL; + } + + return list; +} + static DBusMessage *create_proxy_config(DBusConnection *conn, DBusMessage *msg, void *user_data) { @@ -140,7 +173,7 @@ static DBusMessage *create_proxy_config(DBusConnection *conn, struct proxy_config *config; const char *sender, *method = NULL; const char *url = NULL, *script = NULL; - const char *server = NULL, *exclude = NULL; + GString *servers = NULL, *excludes = NULL; const char *interface = NULL, *domainname = NULL, *nameserver = NULL; sender = dbus_message_get_sender(msg); @@ -185,15 +218,11 @@ static DBusMessage *create_proxy_config(DBusConnection *conn, DBUS_TYPE_INVALID) break; - if (g_str_equal(key, "Servers") == TRUE) { - dbus_message_iter_get_basic(&list, &server); - if (strlen(server) == 0) - server = NULL; - } else if (g_str_equal(key, "Excludes") == TRUE) { - dbus_message_iter_get_basic(&list, &exclude); - if (strlen(exclude) == 0) - exclude = NULL; - } else if (g_str_equal(key, "Domains") == TRUE) { + if (g_str_equal(key, "Servers") == TRUE) + servers = get_string_list(&list); + else if (g_str_equal(key, "Excludes") == TRUE) + excludes = get_string_list(&list); + else if (g_str_equal(key, "Domains") == TRUE) { dbus_message_iter_get_basic(&list, &domainname); if (strlen(domainname) == 0) domainname = NULL; @@ -209,18 +238,30 @@ static DBusMessage *create_proxy_config(DBusConnection *conn, } DBG("sender %s method %s", sender, method); - DBG("url %s script %p server %s exclude %s", - url, script, server, exclude); + DBG("url %s script %p servers %p excludes %p", + url, script, servers, excludes); DBG("interface %s domainname %s nameserver %s", interface, domainname, nameserver); - if (method == NULL) + if (method == NULL) { + if (servers != NULL) + g_string_free(servers, TRUE); + if (excludes != NULL) + g_string_free(excludes, TRUE); + return g_dbus_create_error(msg, PACRUNNER_ERROR_INTERFACE ".Failed", "No proxy method specified"); + } + + config = create_config(conn, sender, method, url, script, servers, + excludes, interface, domainname, nameserver); + + if (servers != NULL) + g_string_free(servers, TRUE); + if (excludes != NULL) + g_string_free(excludes, TRUE); - config = create_config(conn, sender, method, url, script, server, - interface, domainname, nameserver); if (config == NULL) return g_dbus_create_error(msg, PACRUNNER_ERROR_INTERFACE ".Failed", diff --git a/src/mozjs.c b/src/mozjs.c index de40c3f..f930590 100644 --- a/src/mozjs.c +++ b/src/mozjs.c @@ -162,6 +162,8 @@ static void create_object(void) return; script = pacrunner_proxy_get_script(current_proxy); + if (script == NULL) + return; jsctx = JS_NewContext(jsrun, 8 * 1024); diff --git a/src/pacrunner.h b/src/pacrunner.h index 0dce86d..ee97b73 100644 --- a/src/pacrunner.h +++ b/src/pacrunner.h @@ -72,6 +72,11 @@ enum pacrunner_proxy_method { PACRUNNER_PROXY_METHOD_AUTO = 3, }; +enum pacrunner_proxy_manual_context { + PACRUNNER_PROXY_MANUAL_CONTEXT_GENERIC = 0, + PACRUNNER_PROXY_MANUAL_CONTEXT_PROTOCOL_BASED = 1, +}; + struct pacrunner_proxy; struct pacrunner_proxy *pacrunner_proxy_create(const char *interface); @@ -87,8 +92,8 @@ int pacrunner_proxy_set_direct(struct pacrunner_proxy *proxy); int pacrunner_proxy_set_auto(struct pacrunner_proxy *proxy, const char *url); int pacrunner_proxy_set_script(struct pacrunner_proxy *proxy, const char *script); -int pacrunner_proxy_set_server(struct pacrunner_proxy *proxy, - const char *server); +int pacrunner_proxy_set_manual(struct pacrunner_proxy *proxy, + GString *servers, GString *excludes); int __pacrunner_proxy_init(void); void __pacrunner_proxy_cleanup(void); diff --git a/src/proxy.c b/src/proxy.c index 1838eba..ca74d91 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -24,6 +24,7 @@ #endif #include <errno.h> +#include <string.h> #include "pacrunner.h" @@ -34,7 +35,9 @@ struct pacrunner_proxy { enum pacrunner_proxy_method method; char *url; char *script; - char *server; + enum pacrunner_proxy_manual_context manual_context; + char **servers; + char **excludes; }; struct pacrunner_proxy *pacrunner_proxy_create(const char *interface) @@ -79,8 +82,11 @@ static void reset_proxy(struct pacrunner_proxy *proxy) g_free(proxy->script); proxy->script = NULL; - g_free(proxy->server); - proxy->server = NULL; + g_strfreev(proxy->servers); + proxy->servers = NULL; + + g_strfreev(proxy->excludes); + proxy->excludes = NULL; } void pacrunner_proxy_unref(struct pacrunner_proxy *proxy) @@ -228,25 +234,45 @@ int pacrunner_proxy_set_script(struct pacrunner_proxy *proxy, return 0; } -int pacrunner_proxy_set_server(struct pacrunner_proxy *proxy, - const char *server) +int pacrunner_proxy_set_manual(struct pacrunner_proxy *proxy, + GString *servers, GString *excludes) { int err; - - DBG("proxy %p server %s", proxy, server); + char **server; if (proxy == NULL) return -EINVAL; - if (server == NULL) + if (servers == NULL) return -EINVAL; + DBG("proxy %p servers %s", proxy, servers->str); + err = pacrunner_proxy_set_method(proxy, PACRUNNER_PROXY_METHOD_MANUAL); if (err < 0) return err; - g_free(proxy->server); - proxy->server = g_strdup(server); + g_strfreev(proxy->servers); + proxy->servers = g_strsplit_set(servers->str, " ", 0); + + proxy->manual_context = PACRUNNER_PROXY_MANUAL_CONTEXT_GENERIC; + + for (server = proxy->servers; *server != NULL; server++) { + if (strstr(*server, "://") != NULL) { + proxy->manual_context = + PACRUNNER_PROXY_MANUAL_CONTEXT_PROTOCOL_BASED; + } + } + + DBG("manual context %d", proxy->manual_context); + + g_strfreev(proxy->excludes); + + if (excludes != NULL) { + DBG("proxy %p excludes %s", proxy, excludes->str); + + proxy->excludes = g_strsplit_set(excludes->str, " ", 0); + } __pacrunner_mozjs_set_proxy(proxy); -- 1.7.1 _______________________________________________ connman mailing list connman@connman.net http://lists.connman.net/listinfo/connman