diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2010-11-13 19:03:51 +0900 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2010-11-13 19:03:51 +0900 |
commit | bb5cbf3af77f5a8e1d64e30252320d4512d1499d (patch) | |
tree | aaa0275d1ae0850d03f9a815376b2f594a1b3604 | |
parent | 57591ad18c52280d52ffb566e1d5a581d2d108f7 (diff) | |
download | pacrunner-bb5cbf3af77f5a8e1d64e30252320d4512d1499d.tar.gz |
Move manual proxy configuration into separate file
-rw-r--r-- | Makefile.am | 6 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/manual.c | 58 | ||||
-rw-r--r-- | src/pacrunner.h | 5 | ||||
-rw-r--r-- | src/proxy.c | 17 |
5 files changed, 71 insertions, 17 deletions
diff --git a/Makefile.am b/Makefile.am index 5a9aa7e..452cb45 100644 --- a/Makefile.am +++ b/Makefile.am @@ -32,8 +32,8 @@ src_pacrunner_SOURCES = $(gdbus_sources) $(builtin_sources) \ src/main.c src/pacrunner.h \ src/log.h src/log.c src/plugin.h src/plugin.c \ src/download.h src/download.c \ - src/client.c src/manager.c \ - src/proxy.c src/mozjs.c src/javascript.h + src/client.c src/manager.c src/proxy.c \ + src/manual.c src/mozjs.c src/javascript.h src_pacrunner_LDADD = $(builtin_libadd) @MOZJS_LIBS@ \ @GLIB_LIBS@ @DBUS_LIBS@ @CAPNG_LIBS@ -ldl @@ -76,7 +76,7 @@ endif noinst_PROGRAMS = unit/test-mozjs unit_test_mozjs_SOURCES = unit/test-mozjs.c src/pacrunner.h \ - src/proxy.c src/download.c src/mozjs.c + src/proxy.c src/manual.c src/download.c src/mozjs.c unit_test_mozjs_LDADD = @MOZJS_LIBS@ @GLIB_LIBS@ @@ -161,6 +161,7 @@ int main(int argc, char *argv[]) __pacrunner_download_init(); __pacrunner_manager_init(conn); __pacrunner_client_init(conn); + __pacrunner_manual_init(); __pacrunner_mozjs_init(); __pacrunner_plugin_init(); @@ -173,6 +174,7 @@ int main(int argc, char *argv[]) __pacrunner_plugin_cleanup(); __pacrunner_mozjs_cleanup(); + __pacrunner_manual_cleanup(); __pacrunner_client_cleanup(); __pacrunner_manager_cleanup(); __pacrunner_download_cleanup(); diff --git a/src/manual.c b/src/manual.c new file mode 100644 index 0000000..dc5efd4 --- /dev/null +++ b/src/manual.c @@ -0,0 +1,58 @@ +/* + * + * PACrunner - Proxy configuration daemon + * + * Copyright (C) 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 + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "pacrunner.h" + +static char *last_result; + +const char *__pacrunner_manual_execute(const char *url, const char *host, + char **servers, char **exludes) +{ + DBG("url %s host %s", url, host); + + if (servers == NULL || servers[0] == NULL) + return "DIRECT"; + + g_free(last_result); + last_result = g_strdup_printf("PROXY %s", servers[0]); + + return last_result; +} + +int __pacrunner_manual_init(void) +{ + DBG(""); + + last_result = NULL; + + return 0; +} + +void __pacrunner_manual_cleanup(void) +{ + DBG(""); + + g_free(last_result); +} diff --git a/src/pacrunner.h b/src/pacrunner.h index 1a51cbe..a3a8104 100644 --- a/src/pacrunner.h +++ b/src/pacrunner.h @@ -89,6 +89,11 @@ void __pacrunner_manager_cleanup(); int __pacrunner_client_init(DBusConnection *conn); void __pacrunner_client_cleanup(); +int __pacrunner_manual_init(void); +void __pacrunner_manual_cleanup(void); +const char *__pacrunner_manual_execute(const char *url, const char *host, + char **servers, char **exludes); + int __pacrunner_mozjs_init(void); void __pacrunner_mozjs_cleanup(void); int __pacrunner_mozjs_set_proxy(struct pacrunner_proxy *proxy); diff --git a/src/proxy.c b/src/proxy.c index bc1b5ac..8570c9c 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -36,7 +36,6 @@ struct pacrunner_proxy { char *script; char **servers; char **excludes; - char *result; }; struct pacrunner_proxy *pacrunner_proxy_create(const char *interface) @@ -86,9 +85,6 @@ static void reset_proxy(struct pacrunner_proxy *proxy) g_strfreev(proxy->excludes); proxy->excludes = NULL; - - g_free(proxy->result); - proxy->result = NULL; } void pacrunner_proxy_unref(struct pacrunner_proxy *proxy) @@ -178,13 +174,6 @@ int pacrunner_proxy_set_manual(struct pacrunner_proxy *proxy, g_strfreev(proxy->excludes); proxy->excludes = excludes; - g_free(proxy->result); - - if (proxy->servers[0] == NULL) - proxy->result = g_strdup("DIRECT"); - else - proxy->result = g_strdup_printf("PROXY %s", proxy->servers[0]); - pacrunner_proxy_enable(proxy); return 0; @@ -338,9 +327,9 @@ const char *pacrunner_proxy_lookup(const char *url, const char *host) case PACRUNNER_PROXY_METHOD_DIRECT: break; case PACRUNNER_PROXY_METHOD_MANUAL: - if (selected_proxy->result == NULL) - break; - return selected_proxy->result; + return __pacrunner_manual_execute(url, host, + selected_proxy->servers, + selected_proxy->excludes); case PACRUNNER_PROXY_METHOD_AUTO: return __pacrunner_mozjs_execute(url, host); } |