From 80d234fc23f3cb0011788a4af2ba4e8ebf13eb65 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Mon, 20 Jun 2016 14:25:27 +0100 Subject: proxy: Add pacrunner_js_clear_proxy() We'll want this for a sane per-proxy-config cleanup of the JS context. --- plugins/v8.cc | 1 + src/js.c | 16 ++++++++++++++++ src/js.h | 1 + src/pacrunner.h | 1 + src/proxy.c | 2 ++ 5 files changed, 21 insertions(+) diff --git a/plugins/v8.cc b/plugins/v8.cc index e947bed..93a1ea5 100644 --- a/plugins/v8.cc +++ b/plugins/v8.cc @@ -302,6 +302,7 @@ static struct pacrunner_js_driver v8_driver = { "v8", PACRUNNER_JS_PRIORITY_HIGH, v8_set_proxy, + NULL, v8_execute, }; diff --git a/src/js.c b/src/js.c index ff08cee..3a9274e 100644 --- a/src/js.c +++ b/src/js.c @@ -69,6 +69,22 @@ int __pacrunner_js_set_proxy(struct pacrunner_proxy *proxy) return -ENXIO; } +int __pacrunner_js_clear_proxy(struct pacrunner_proxy *proxy) +{ + GSList *list; + + for (list = js_driver_list; list; list = list->next) { + struct pacrunner_js_driver *driver = list->data; + + if (driver->clear_proxy) + return driver->clear_proxy(proxy); + else + return 0; + } + + return -ENXIO; +} + char *__pacrunner_js_execute(struct pacrunner_proxy *proxy, const char *url, const char *host) { diff --git a/src/js.h b/src/js.h index ea76849..e5d7abc 100644 --- a/src/js.h +++ b/src/js.h @@ -27,6 +27,7 @@ struct pacrunner_js_driver { const char *name; int priority; int (*set_proxy) (struct pacrunner_proxy *proxy); + int (*clear_proxy) (struct pacrunner_proxy *proxy); char *(*execute)(struct pacrunner_proxy *proxy, const char *url, const char *host); }; diff --git a/src/pacrunner.h b/src/pacrunner.h index 7b7ad15..87c51da 100644 --- a/src/pacrunner.h +++ b/src/pacrunner.h @@ -113,5 +113,6 @@ char *__pacrunner_mozjs_execute(const char *url, const char *host); int __pacrunner_js_init(void); void __pacrunner_js_cleanup(void); int __pacrunner_js_set_proxy(struct pacrunner_proxy *proxy); +int __pacrunner_js_clear_proxy(struct pacrunner_proxy *proxy); char *__pacrunner_js_execute(struct pacrunner_proxy *proxy, const char *url, const char *host); diff --git a/src/proxy.c b/src/proxy.c index 47be08a..08ae3dd 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -128,6 +128,8 @@ void pacrunner_proxy_unref(struct pacrunner_proxy *proxy) if (!g_atomic_int_dec_and_test(&proxy->refcount)) return; + __pacrunner_js_clear_proxy(proxy); + reset_proxy(proxy); g_list_free_full(proxy->domains, proxy_domain_destroy); -- cgit 1.2.3-korg