aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2019-08-02 14:05:42 +0200
committerMarcel Holtmann <marcel@holtmann.org>2019-08-02 14:05:42 +0200
commita2703ec7cf6a2774bd0597202ba25a74fdeea3f8 (patch)
tree7f0a7c3d140baf4e6824f80142b1ac64d680b922
parent0e28c73fd7b3e2ac0b7d80a18dbe7d9d39e75503 (diff)
downloadpacrunner-a2703ec7cf6a2774bd0597202ba25a74fdeea3f8.tar.gz
plugins: Remove support for MozJS engine
-rw-r--r--.gitignore1
-rw-r--r--Makefile.am23
-rwxr-xr-xbootstrap-configure3
-rw-r--r--configure.ac10
-rw-r--r--plugins/mozjs.cc253
-rw-r--r--src/pacrunner.h5
-rw-r--r--unit/test-mozjs.c225
7 files changed, 1 insertions, 519 deletions
diff --git a/.gitignore b/.gitignore
index 0c77974..29b8741 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,6 +31,5 @@ src/org.pacrunner.service
libproxy/libproxy-1.0.pc
tools/proxy
tools/manual-proxy-test
-unit/test-mozjs
unit/test-pacrunner
unit/suite/*.xml
diff --git a/Makefile.am b/Makefile.am
index 6b2bc6d..819abab 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -28,15 +28,6 @@ builtin_cflags += @CURL_CFLAGS@
builtin_libadd += @CURL_LIBS@
endif
-if MOZJS
-js_sources = src/js_funcs.c
-builtin_modules += mozjs
-builtin_libadd += plugins/libmozjsplugin.a @MOZJS_LIBS@ -lstdc++
-noinst_LIBRARIES += plugins/libmozjsplugin.a
-plugins_libmozjsplugin_a_SOURCES = plugins/mozjs.cc
-plugins_libmozjsplugin_a_CXXFLAGS = $(AM_CFLAGS) @MOZJS_CFLAGS@ @DBUS_CFLAGS@ @GLIB_CFLAGS@
-endif
-
if DUKTAPE
js_sources = src/js_funcs.c
builtin_modules += duktape
@@ -122,20 +113,6 @@ unit_test_pacrunner_LDADD += @CURL_LIBS@
endif
-if MOZJS
-unit_test_pacrunner_SOURCES += plugins/mozjs.cc
-unit_test_pacrunner_CXXFLAGS = $(AM_CFLAGS) @MOZJS_CFLAGS@
-unit_test_pacrunner_LDADD += @MOZJS_LIBS@ @PTHREAD_LIBS@
-
-noinst_PROGRAMS += unit/test-mozjs
-
-unit_test_mozjs_SOURCES = unit/test-mozjs.c src/pacrunner.h \
- src/proxy.c src/manual.c src/download.c \
- src/js.c plugins/mozjs.cc $(js_sources)
-unit_test_mozjs_CXXFLAGS = $(AM_CFLAGS) @MOZJS_CFLAGS@
-unit_test_mozjs_LDADD = @MOZJS_LIBS@ @GLIB_LIBS@ @PTHREAD_LIBS@
-endif
-
if DUKTAPE
unit_test_pacrunner_SOURCES += plugins/duktape.c
diff --git a/bootstrap-configure b/bootstrap-configure
index 661675c..cb8613d 100755
--- a/bootstrap-configure
+++ b/bootstrap-configure
@@ -11,7 +11,6 @@ fi
--mandir=/usr/share/man \
--disable-datafiles \
--enable-libproxy \
- --enable-curl \
- --enable-mozjs \
--enable-duktape \
+ --enable-curl \
--enable-unit $*
diff --git a/configure.ac b/configure.ac
index e979e58..aa3da42 100644
--- a/configure.ac
+++ b/configure.ac
@@ -73,16 +73,6 @@ AC_ARG_ENABLE(duktape, AC_HELP_STRING([--enable-duktape],
[enable Duktape Javascript plugin support]))
AM_CONDITIONAL(DUKTAPE, test "${enable_duktape}" = "yes")
-AC_ARG_ENABLE(mozjs, AC_HELP_STRING([--enable-mozjs],
- [enable Mozilla Javascript plugin support]))
-if (test "${enable_mozjs}" = "yes"); then
- PKG_CHECK_MODULES(MOZJS, mozjs-38, dummy=yes,
- AC_MSG_ERROR(Mozilla Javascript version 38 is required))
- AC_SUBST(MOZJS_CFLAGS)
- AC_SUBST(MOZJS_LIBS)
-fi
-AM_CONDITIONAL(MOZJS, test "${enable_mozjs}" = "yes")
-
PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.16, dummy=yes,
AC_MSG_ERROR(GLib >= 2.16 is required))
AC_SUBST(GLIB_CFLAGS)
diff --git a/plugins/mozjs.cc b/plugins/mozjs.cc
deleted file mode 100644
index e10b297..0000000
--- a/plugins/mozjs.cc
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- *
- * PACrunner - Proxy configuration daemon
- *
- * Copyright (C) 2010-2011 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 <errno.h>
-#include <unistd.h>
-#include <string.h>
-#include <pthread.h>
-
-#include <netdb.h>
-
-#pragma GCC diagnostic ignored "-Wredundant-decls"
-#pragma GCC diagnostic ignored "-Winvalid-offsetof"
-#include <jsapi.h>
-#pragma GCC diagnostic error "-Wredundant-decls"
-#pragma GCC diagnostic error "-Winvalid-offsetof"
-
-extern "C" {
-#include "pacrunner.h"
-#include "js.h"
-}
-
-static pthread_mutex_t mozjs_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-struct pacrunner_mozjs {
- struct pacrunner_proxy *proxy;
- JSContext *jsctx;
- JSObject *jsobj;
- JSAutoCompartment *jsac;
-};
-
-static bool myipaddress(JSContext *jsctx, unsigned argc, jsval *vp)
-{
- struct pacrunner_mozjs *ctx = (pacrunner_mozjs *)JS_GetContextPrivate(jsctx);
- char address[NI_MAXHOST];
-
- DBG("");
-
- JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
-
- args.rval().setNull();
-
- if (!ctx)
- return true;
-
- if (__pacrunner_js_getipaddr(ctx->proxy, address, sizeof(address)) < 0)
- return true;
-
- DBG("address %s", address);
-
- args.rval().setString(JS_NewStringCopyZ(jsctx,address));
-
- return true;
-}
-
-static bool dnsresolve(JSContext *jsctx, unsigned argc, jsval *vp)
-{
- struct pacrunner_mozjs *ctx = (pacrunner_mozjs *)JS_GetContextPrivate(jsctx);
- char address[NI_MAXHOST];
- JS::CallArgs args = JS::CallArgsFromVp(argc,vp);
- char * host = JS_EncodeString(jsctx, args[0].toString());
-
- DBG("host %s", host);
-
- if (!ctx)
- goto out;
-
- if (__pacrunner_js_resolve(ctx->proxy, host, address, sizeof(address)) < 0)
- goto out;
-
- DBG("address %s", address);
-
- args.rval().setString(JS_NewStringCopyZ(jsctx,address));
-
- out:
- JS_free(jsctx, host);
- return true;
-
-}
-
-static JSClass jscls = {
- "global", JSCLASS_GLOBAL_FLAGS,
-};
-
-static JSRuntime *jsrun;
-
-static int create_object(struct pacrunner_proxy *proxy)
-{
- struct pacrunner_mozjs *ctx;
- const char *script;
-
- script = pacrunner_proxy_get_script(proxy);
- if (!script)
- return 0;
-
- ctx = (pacrunner_mozjs *)g_malloc0(sizeof(struct pacrunner_mozjs));
-
- ctx->proxy = proxy;
- ctx->jsctx = JS_NewContext(jsrun, 8 * 1024);
- if (!ctx->jsctx) {
- g_free(ctx);
- return -ENOMEM;
- }
- JS_SetContextPrivate(ctx->jsctx, ctx);
- __pacrunner_proxy_set_jsctx(proxy, ctx);
-
- JS::CompartmentOptions compart_opts;
- compart_opts.setVersion(JSVERSION_LATEST);
- ctx->jsobj = JS_NewGlobalObject(ctx->jsctx, &jscls, nullptr,
- JS::DontFireOnNewGlobalHook, compart_opts);
- JS::RootedObject jsobj(ctx->jsctx,ctx->jsobj);
-
- ctx->jsac = new JSAutoCompartment(ctx->jsctx, jsobj);
-
- if (!JS_InitStandardClasses(ctx->jsctx, jsobj))
- pacrunner_error("Failed to init JS standard classes");
-
- JS_DefineFunction(ctx->jsctx, jsobj, "myIpAddress", myipaddress, 0, 0);
- JS_DefineFunction(ctx->jsctx, jsobj, "dnsResolve", dnsresolve, 1, 0);
-
- JS::RootedValue rval(ctx->jsctx);
- JS::CompileOptions opts(ctx->jsctx);
- opts.setIntroductionType("pacrunner")
- .setUTF8(true)
- .setCompileAndGo(true);
-
- JS::Evaluate(ctx->jsctx, JS::HandleObject(jsobj), opts,
- __pacrunner_js_routines, strlen(__pacrunner_js_routines)
- , &rval);
-
- JS::Evaluate(ctx->jsctx, jsobj, opts, script, strlen(script), &rval);
-
- return 0;
-}
-
-static int mozjs_clear_proxy(struct pacrunner_proxy *proxy)
-{
- struct pacrunner_mozjs *ctx = (pacrunner_mozjs *)__pacrunner_proxy_get_jsctx(proxy);
-
- DBG("proxy %p ctx %p", proxy, ctx);
-
- if (!ctx)
- return -EINVAL;
-
- delete ctx->jsac;
- JS_DestroyContext(ctx->jsctx);
- __pacrunner_proxy_set_jsctx(proxy, NULL);
- g_free(ctx);
-
- return 0;
-}
-
-static int mozjs_set_proxy(struct pacrunner_proxy *proxy)
-{
- DBG("proxy %p", proxy);
- if (!proxy)
- return 0;
-
- mozjs_clear_proxy(proxy);
-
- return create_object(proxy);
-}
-
-static char * mozjs_execute(struct pacrunner_proxy *proxy, const char *url,
- const char *host)
-{
- struct pacrunner_mozjs *ctx = (pacrunner_mozjs *)__pacrunner_proxy_get_jsctx(proxy);
- bool result;
- char *answer, *g_answer;
- DBG("proxy %p ctx %p url %s host %s", proxy, ctx, url, host);
-
- if (!ctx)
- return NULL;
-
- pthread_mutex_lock(&mozjs_mutex);
-
- JS_BeginRequest(ctx->jsctx);
- JS::RootedValue rval(ctx->jsctx);
- JS::AutoValueArray<2> args(ctx->jsctx);
-
- args[0].setString(JS_NewStringCopyZ(ctx->jsctx, url));
- args[1].setString(JS_NewStringCopyZ(ctx->jsctx, host));
-
-
- JS::RootedObject jsobj(ctx->jsctx,ctx->jsobj);
-
- result = JS_CallFunctionName(ctx->jsctx, jsobj, "FindProxyForURL", args , &rval);
-
- JS_EndRequest(ctx->jsctx);
-
- JS_MaybeGC(ctx->jsctx);
-
- pthread_mutex_unlock(&mozjs_mutex);
-
- if (result) {
- answer = JS_EncodeString(ctx->jsctx, rval.toString());
- g_answer = g_strdup(answer);
- JS_free(ctx->jsctx, answer);
- return g_answer;
- }
-
- return NULL;
-}
-
-static struct pacrunner_js_driver mozjs_driver = {
- .name = "mozjs",
- .priority = PACRUNNER_JS_PRIORITY_DEFAULT,
- .set_proxy = mozjs_set_proxy,
- .clear_proxy = mozjs_clear_proxy,
- .execute = mozjs_execute,
-};
-
-static int mozjs_init(void)
-{
- DBG("");
- JS_Init();
- jsrun = JS_NewRuntime(JS::DefaultHeapMaxBytes, 8 * 1024 * 1024 );
-
- return pacrunner_js_driver_register(&mozjs_driver);
-}
-
-static void mozjs_exit(void)
-{
- DBG("");
-
- pacrunner_js_driver_unregister(&mozjs_driver);
-
- JS_DestroyRuntime(jsrun);
- JS_ShutDown();
-}
-
-PACRUNNER_PLUGIN_DEFINE(mozjs, mozjs_init, mozjs_exit)
diff --git a/src/pacrunner.h b/src/pacrunner.h
index e31d7ef..a112271 100644
--- a/src/pacrunner.h
+++ b/src/pacrunner.h
@@ -105,11 +105,6 @@ void __pacrunner_manual_destroy_excludes(GList **excludes);
char *__pacrunner_manual_execute(const char *url, const char *host,
GList **servers, GList **excludes);
-int __pacrunner_mozjs_init(void);
-void __pacrunner_mozjs_cleanup(void);
-int __pacrunner_mozjs_set_proxy(struct pacrunner_proxy *proxy);
-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);
diff --git a/unit/test-mozjs.c b/unit/test-mozjs.c
deleted file mode 100644
index 25c8634..0000000
--- a/unit/test-mozjs.c
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- *
- * PACrunner - Proxy configuration daemon
- *
- * Copyright (C) 2010-2011 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 <stdlib.h>
-
-#include <glib.h>
-
-#include "pacrunner.h"
-
-extern struct pacrunner_plugin_desc __pacrunner_builtin_mozjs;
-
-static int mozjs_init(void) {
- return __pacrunner_builtin_mozjs.init();
-}
-
-static void mozjs_exit(void) {
- __pacrunner_builtin_mozjs.exit();
-}
-
-
-void pacrunner_error(const char *format, ...)
-{
-}
-
-void pacrunner_debug(const char *format, ...)
-{
-}
-
-#define MULTIPLE_COUNT 500
-#define MASSIVE_COUNT MULTIPLE_COUNT * 100
-
-#define EXAMPLE_URL "http://www.example.com/site/test.html"
-#define EXAMPLE_HOST "www.example.com"
-
-#define DIRECT_PAC "function FindProxyForURL(url, host)\n" \
- "{\n" \
- " return \"DIRECT\";" \
- "}\n"
-
-#define EXAMPLE_PAC \
- "function FindProxyForURL(url, host)\n" \
- "{\n" \
- " var me = myIpAddress();\n" \
- " var resolved_ip = dnsResolve(host);\n" \
- " if (me == \"127.0.0.1\") { return \"DIRECT\"; }\n" \
- " if (host == \"127.0.0.1\") { return \"DIRECT\"; }\n" \
- " if (host == \"localhost\") { return \"DIRECT\"; }\n" \
- " if (isPlainHostName(host)) { return \"DIRECT\"; }\n" \
- " return \"PROXY proxy.example.com\";\n" \
- "}\n"
-
-static struct pacrunner_proxy *proxy;
-
-static void test_single_init(void)
-{
- g_assert(mozjs_init() == 0);
-
- mozjs_exit();
-}
-
-static void test_multiple_init(void)
-{
- int i;
-
- for (i = 0; i < MULTIPLE_COUNT; i++) {
- g_assert(mozjs_init() == 0);
-
- mozjs_exit();
- }
-}
-
-static void test_single_execute_without_pac(void)
-{
- char *result;
-
- g_assert(mozjs_init() == 0);
-
- result = __pacrunner_js_execute(proxy, EXAMPLE_URL, EXAMPLE_HOST);
- g_test_message("result: %s", result);
- g_free(result);
- mozjs_exit();
-}
-
-static void test_multiple_execute_without_pac(void)
-{
- char *result;
- int i;
-
- g_assert(mozjs_init() == 0);
-
- for (i = 0; i < MULTIPLE_COUNT; i++) {
- result = __pacrunner_js_execute(proxy, EXAMPLE_URL,
- EXAMPLE_HOST);
- g_test_message("result %d: %s", i, result);
- g_free(result);
- }
-
- mozjs_exit();
-}
-
-static void test_single_execute_with_direct_pac(void)
-{
- char *result;
-
- g_assert(mozjs_init() == 0);
-
- g_assert(pacrunner_proxy_set_auto(proxy, NULL, DIRECT_PAC) == 0);
-
- result = __pacrunner_js_execute(proxy, EXAMPLE_URL, EXAMPLE_HOST);
- g_test_message("result: %s", result);
- g_free(result);
-
- pacrunner_proxy_disable(proxy);
-
- mozjs_exit();
-}
-
-static void test_multiple_execute_with_direct_pac(void)
-{
- char *result;
- int i;
-
- mozjs_init();
-
- g_assert(pacrunner_proxy_set_auto(proxy, NULL, DIRECT_PAC) == 0);
-
- for (i = 0; i < MULTIPLE_COUNT; i++) {
- result = __pacrunner_js_execute(proxy, EXAMPLE_URL,
- EXAMPLE_HOST);
- g_test_message("result %d: %s", i, result);
- g_free(result);
- }
-
- pacrunner_proxy_disable(proxy);
-
- mozjs_exit();
-}
-
-static void test_massive_execute_with_direct_pac(void)
-{
- char *result;
- int i;
-
- mozjs_init();
-
- g_assert(pacrunner_proxy_set_auto(proxy, NULL, DIRECT_PAC) == 0);
-
- for (i = 0; i < MASSIVE_COUNT; i++) {
- result = __pacrunner_js_execute(proxy, EXAMPLE_URL,
- EXAMPLE_HOST);
- g_test_message("result %d: %s", i, result);
- g_free(result);
- }
-
- pacrunner_proxy_disable(proxy);
-
- mozjs_exit();
-}
-
-static void test_multiple_execute_with_example_pac(void)
-{
- char *result;
- int i;
-
- mozjs_init();
-
- g_assert(pacrunner_proxy_set_auto(proxy, NULL, EXAMPLE_PAC) == 0);
-
- for (i = 0; i < MULTIPLE_COUNT; i++) {
- result = __pacrunner_js_execute(proxy, EXAMPLE_URL,
- EXAMPLE_HOST);
- g_test_message("result %d: %s", i, result);
- g_free(result);
- }
-
- pacrunner_proxy_disable(proxy);
-
- mozjs_exit();
-}
-
-int main(int argc, char **argv)
-{
- g_test_init(&argc, &argv, NULL);
-
- proxy = pacrunner_proxy_create("eth0");
-
- g_test_add_func("/mozjs/single-init", test_single_init);
- g_test_add_func("/mozjs/multiple-init", test_multiple_init);
- g_test_add_func("/mozjs/single-execute-without-pac",
- test_single_execute_without_pac);
- g_test_add_func("/mozjs/multiple-execute-without-pac",
- test_multiple_execute_without_pac);
- g_test_add_func("/mozjs/single-execute-with-direct-pac",
- test_single_execute_with_direct_pac);
- g_test_add_func("/mozjs/multiple-execute-with-direct-pac",
- test_multiple_execute_with_direct_pac);
- g_test_add_func("/mozjs/massive-execute-with-direct-pac",
- test_massive_execute_with_direct_pac);
- g_test_add_func("/mozjs/multiple-execute-with-example-pac",
- test_multiple_execute_with_example_pac);
-
- return g_test_run();
-}