diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2010-10-10 15:39:55 +0200 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2010-10-10 15:39:55 +0200 |
commit | e88bb56e6fb2a4df3048922d6cf8e96ba9651417 (patch) | |
tree | a8dee5c8f2fc55bd733e267fe37e5bce361da140 /src | |
parent | 50f2b1f8bafd18588f5664f2c7573ca838d2e4b8 (diff) | |
download | pacrunner-e88bb56e6fb2a4df3048922d6cf8e96ba9651417.tar.gz |
Add support for manual proxy server configuration
Diffstat (limited to 'src')
-rw-r--r-- | src/manager.c | 28 | ||||
-rw-r--r-- | src/mozjs.c | 56 | ||||
-rw-r--r-- | src/pacrunner.h | 1 |
3 files changed, 67 insertions, 18 deletions
diff --git a/src/manager.c b/src/manager.c index f04250d..ac30075 100644 --- a/src/manager.c +++ b/src/manager.c @@ -37,6 +37,7 @@ struct proxy_config { char *url; char *script; + char *server; char *interface; char *domainname; char *nameserver; @@ -60,6 +61,7 @@ static void destroy_config(gpointer data) g_free(config->nameserver); g_free(config->domainname); g_free(config->interface); + g_free(config->server); g_free(config->script); g_free(config->url); @@ -84,6 +86,7 @@ static struct proxy_config *create_config(DBusConnection *conn, const char *method, const char *url, const char *script, + const char *server, const char *interface, const char *domainname, const char *nameserver) @@ -100,6 +103,7 @@ static struct proxy_config *create_config(DBusConnection *conn, config->url = g_strdup(url); config->script = g_strdup(script); + config->server = g_strdup(server); config->interface = g_strdup(interface); config->domainname = g_strdup(domainname); config->nameserver = g_strdup(nameserver); @@ -110,6 +114,13 @@ static struct proxy_config *create_config(DBusConnection *conn, config->watch = g_dbus_add_disconnect_watch(conn, sender, disconnect_callback, config, NULL); + if (g_strcmp0(method, "manual") == 0) { + if (__pacrunner_mozjs_set_server(config->interface, + config->server) < 0) + pacrunner_error("Failed to set proxy server"); + return config; + } + if (g_strcmp0(method, "auto") != 0) return config; @@ -130,7 +141,8 @@ static DBusMessage *create_proxy_config(DBusConnection *conn, { DBusMessageIter iter, array; struct proxy_config *config; - const char *sender, *method = NULL, *url = NULL, *script = NULL; + const char *sender, *method = NULL; + const char *url = NULL, *script = NULL, *server = NULL; const char *interface = NULL, *domainname = NULL, *nameserver = NULL; sender = dbus_message_get_sender(msg); @@ -175,7 +187,11 @@ static DBusMessage *create_proxy_config(DBusConnection *conn, DBUS_TYPE_INVALID) break; - if (g_str_equal(key, "Domains") == TRUE) { + 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, "Domains") == TRUE) { dbus_message_iter_get_basic(&list, &domainname); if (strlen(domainname) == 0) domainname = NULL; @@ -190,8 +206,8 @@ static DBusMessage *create_proxy_config(DBusConnection *conn, dbus_message_iter_next(&array); } - DBG("sender %s method %s url %s script %p", - sender, method, url, script); + DBG("sender %s method %s", sender, method); + DBG("url %s script %p server %s", url, script, server); DBG("interface %s domainname %s nameserver %s", interface, domainname, nameserver); @@ -200,8 +216,8 @@ static DBusMessage *create_proxy_config(DBusConnection *conn, PACRUNNER_ERROR_INTERFACE ".Failed", "No proxy method specified"); - config = create_config(conn, sender, method, url, script, - interface, domainname, nameserver); + 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 6c681b5..3e6e5eb 100644 --- a/src/mozjs.c +++ b/src/mozjs.c @@ -43,6 +43,7 @@ static char *current_interface = NULL; static char *current_pacfile = NULL; +static char *current_server = NULL; static int getaddr(const char *node, char *host, size_t hostlen) { @@ -152,22 +153,10 @@ static JSRuntime *jsrun; static JSContext *jsctx = NULL; static JSObject *jsobj = NULL; -static void destory_object(void) -{ - if (jsctx == NULL) - return; - - JS_DestroyContext(jsctx); - jsctx = NULL; -} - static void create_object(void) { jsval rval; - if (jsctx != NULL) - destory_object(); - jsctx = JS_NewContext(jsrun, 8 * 1024); jsobj = JS_NewObject(jsctx, &jscls, NULL, NULL); @@ -186,6 +175,36 @@ static void create_object(void) "wpad.dat", 0, &rval); } +static void destory_object(void) +{ + if (jsctx == NULL) + return; + + JS_DestroyContext(jsctx); + jsctx = NULL; +} + +int __pacrunner_mozjs_set_server(const char *interface, const char *server) +{ + if (server == NULL) + return -EINVAL; + + DBG("interface %s server %s", interface, server); + + destory_object(); + + g_free(current_interface); + current_interface = g_strdup(interface); + + g_free(current_pacfile); + current_pacfile = NULL; + + g_free(current_server); + current_server = g_strdup_printf("PROXY %s", server); + + return 0; +} + int __pacrunner_mozjs_set(const char *interface, const char *script) { if (script == NULL) @@ -193,12 +212,17 @@ int __pacrunner_mozjs_set(const char *interface, const char *script) DBG("interface %s script %p", interface, script); + destory_object(); + g_free(current_interface); current_interface = g_strdup(interface); g_free(current_pacfile); current_pacfile = g_strdup(script); + g_free(current_server); + current_server = NULL; + create_object(); return 0; @@ -215,12 +239,17 @@ int __pacrunner_mozjs_load(const char *interface, const char *url) DBG("interface %s url %s", interface, url); + destory_object(); + g_free(current_interface); current_interface = g_strdup(interface); g_free(current_pacfile); current_pacfile = NULL; + g_free(current_server); + current_server = NULL; + if (g_str_has_prefix(url, "file://") == FALSE) return -EINVAL; @@ -278,6 +307,9 @@ const char *__pacrunner_mozjs_execute(const char *url, const char *host) DBG("url %s host %s", url, host); + if (current_server != NULL) + return current_server; + if (current_pacfile == NULL) return "DIRECT"; diff --git a/src/pacrunner.h b/src/pacrunner.h index 88ae256..ae5612f 100644 --- a/src/pacrunner.h +++ b/src/pacrunner.h @@ -73,6 +73,7 @@ void __pacrunner_client_cleanup(); int __pacrunner_mozjs_init(void); void __pacrunner_mozjs_cleanup(void); +int __pacrunner_mozjs_set_server(const char *interface, const char *server); int __pacrunner_mozjs_set(const char *interface, const char *script); int __pacrunner_mozjs_load(const char *interface, const char *url); void __pacrunner_mozjs_clear(void); |