aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Woodhouse <David.Woodhouse@intel.com>2016-08-16 17:01:32 +0100
committerPatrik Flykt <patrik.flykt@linux.intel.com>2016-08-19 10:10:29 +0300
commitb043b6c4e9dcf907e42c1301f137792a4079bef1 (patch)
treec94fd385759d74ee643ab23e743edbe12b5616bf
parentdf057700e5a02309476703392490bedc0ad8fd9f (diff)
downloadpacrunner-b043b6c4e9dcf907e42c1301f137792a4079bef1.tar.gz
plugins: New shared C file for common JavaScript routines
-rw-r--r--Makefile.am10
-rw-r--r--plugins/mozjs.c6
-rw-r--r--plugins/v8.cc3
-rw-r--r--src/js.h3
-rw-r--r--src/js_funcs.c (renamed from src/javascript.h)29
5 files changed, 39 insertions, 12 deletions
diff --git a/Makefile.am b/Makefile.am
index 55b51e7..d637baf 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -27,6 +27,7 @@ builtin_libadd += @CURL_LIBS@
endif
if MOZJS
+js_sources = src/js_funcs.c
builtin_modules += mozjs
builtin_sources += plugins/mozjs.c
builtin_cflags += @MOZJS_CFLAGS@
@@ -34,6 +35,7 @@ builtin_libadd += @MOZJS_LIBS@
endif
if V8
+js_sources = src/js_funcs.c
builtin_modules += v8
builtin_sources += plugins/v8.cc
builtin_libadd += @V8_LIBS@
@@ -41,12 +43,12 @@ endif
sbin_PROGRAMS = src/pacrunner
-src_pacrunner_SOURCES = $(gdbus_sources) $(builtin_sources) \
+src_pacrunner_SOURCES = $(gdbus_sources) $(builtin_sources) $(js_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/manual.c src/js.h src/js.c src/javascript.h
+ src/manual.c src/js.h src/js.c
src_pacrunner_LDADD = $(builtin_libadd) @GLIB_LIBS@ @PTHREAD_LIBS@ \
@DBUS_LIBS@ -ldl
@@ -97,7 +99,7 @@ noinst_PROGRAMS = unit/test-pacrunner
unit_test_pacrunner_SOURCES = unit/test-pacrunner.c src/pacrunner.h \
src/proxy.c src/manual.c src/download.c \
- src/js.c src/log.c src/plugin.c
+ src/js.c src/log.c src/plugin.c $(js_sources)
unit_test_pacrunner_LDADD = @GLIB_LIBS@ -ldl
@@ -118,7 +120,7 @@ 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.c
+ src/js.c plugins/mozjs.c $(js_sources)
unit_test_mozjs_LDADD = @MOZJS_LIBS@ @GLIB_LIBS@ @PTHREAD_LIBS@
endif
diff --git a/plugins/mozjs.c b/plugins/mozjs.c
index feaabd9..0b9a4c9 100644
--- a/plugins/mozjs.c
+++ b/plugins/mozjs.c
@@ -37,8 +37,6 @@
#include <jsapi.h>
#pragma GCC diagnostic error "-Wredundant-decls"
-#include "javascript.h"
-
#include "pacrunner.h"
#include "js.h"
@@ -203,8 +201,8 @@ static int create_object(struct pacrunner_proxy *proxy)
JS_DefineFunction(ctx->jsctx, ctx->jsobj,
"dnsResolve", dnsresolve, 1, 0);
- JS_EvaluateScript(ctx->jsctx, ctx->jsobj, JAVASCRIPT_ROUTINES,
- strlen(JAVASCRIPT_ROUTINES), NULL, 0, &rval);
+ JS_EvaluateScript(ctx->jsctx, ctx->jsobj, __pacrunner_js_routines,
+ strlen(__pacrunner_js_routines), NULL, 0, &rval);
JS_EvaluateScript(ctx->jsctx, ctx->jsobj, script, strlen(script),
"wpad.dat", 0, &rval);
diff --git a/plugins/v8.cc b/plugins/v8.cc
index 93a1ea5..ebb88a6 100644
--- a/plugins/v8.cc
+++ b/plugins/v8.cc
@@ -34,7 +34,6 @@
#include <linux/if_arp.h>
#include <v8.h>
-#include "javascript.h"
extern "C" {
#include "pacrunner.h"
@@ -175,7 +174,7 @@ static void create_object(void)
v8::Handle<v8::Script> script_scr;
v8::Handle<v8::Value> result;
- script_scr = v8::Script::Compile(v8::String::New(JAVASCRIPT_ROUTINES));
+ script_scr = v8::Script::Compile(v8::String::New(__pacrunner_js_routines));
if (script_scr.IsEmpty()) {
v8::String::Utf8Value err(exc.Exception());
DBG("Javascript failed to compile: %s", *err);
diff --git a/src/js.h b/src/js.h
index e5d7abc..f14e796 100644
--- a/src/js.h
+++ b/src/js.h
@@ -34,3 +34,6 @@ struct pacrunner_js_driver {
int pacrunner_js_driver_register(struct pacrunner_js_driver *driver);
void pacrunner_js_driver_unregister(struct pacrunner_js_driver *driver);
+
+/* Common functions for JS plugins */
+extern const char __pacrunner_js_routines[];
diff --git a/src/javascript.h b/src/js_funcs.c
index d48bd0c..6e9cf1e 100644
--- a/src/javascript.h
+++ b/src/js_funcs.c
@@ -1,4 +1,29 @@
-#define JAVASCRIPT_ROUTINES \
+/*
+ *
+ * PACrunner - Proxy configuration daemon
+ *
+ * Copyright © 2010-2016 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
+
+const char __pacrunner_js_routines[] =
"function dnsDomainIs(host, domain) {\n" \
" return (host.length >= domain.length &&\n" \
" host.substring(host.length - domain.length) == domain);\n" \
@@ -196,4 +221,4 @@
" }\n" \
" return ((date1 <= date) && (date <= date2));\n" \
"}\n" \
-""
+"";