Send connman mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
https://lists.01.org/mailman/listinfo/connman
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."
Today's Topics:
1. [PATCH 4/7] js: add __pacrunner_js_getipaddr() function
([email protected])
2. [PATCH 7/7] Add duktape support ([email protected])
3. [PATCH 6/7] Import duktape v1.5.0 (David Woodhouse)
----------------------------------------------------------------------
Message: 1
Date: Tue, 16 Aug 2016 17:01:34 +0100
From: [email protected]
To: [email protected]
Subject: [PATCH 4/7] js: add __pacrunner_js_getipaddr() function
Message-ID: <[email protected]>
From: David Woodhouse <[email protected]>
Remove the duplicate definitions from mozjs and v8 plugins
---
plugins/mozjs.c | 36 +-----------------------------------
plugins/v8.cc | 35 +----------------------------------
src/js.h | 2 ++
src/js_funcs.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 48 insertions(+), 69 deletions(-)
diff --git a/plugins/mozjs.c b/plugins/mozjs.c
index b980d9d..2720cac 100644
--- a/plugins/mozjs.c
+++ b/plugins/mozjs.c
@@ -26,12 +26,9 @@
#include <errno.h>
#include <unistd.h>
#include <string.h>
-#include <sys/ioctl.h>
#include <pthread.h>
#include <netdb.h>
-#include <arpa/inet.h>
-#include <linux/if_arp.h>
#pragma GCC diagnostic ignored "-Wredundant-decls"
#include <jsapi.h>
@@ -48,32 +45,6 @@ struct pacrunner_mozjs {
JSObject *jsobj;
};
-static int getaddr(const char *node, char *host, size_t hostlen)
-{
- struct sockaddr_in addr;
- struct ifreq ifr;
- int sk, err;
-
- sk = socket(PF_INET, SOCK_DGRAM, 0);
- if (sk < 0)
- return -EIO;
-
- memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, node, sizeof(ifr.ifr_name));
-
- err = ioctl(sk, SIOCGIFADDR, &ifr);
-
- close(sk);
-
- if (err < 0)
- return -EIO;
-
- memcpy(&addr, &ifr.ifr_addr, sizeof(addr));
- snprintf(host, hostlen, "%s", inet_ntoa(addr.sin_addr));
-
- return 0;
-}
-
static int resolve(const char *node, char *host, size_t hostlen)
{
struct addrinfo *info;
@@ -96,7 +67,6 @@ static int resolve(const char *node, char *host, size_t
hostlen)
static JSBool myipaddress(JSContext *jsctx, uintN argc, jsval *vp)
{
struct pacrunner_mozjs *ctx = JS_GetContextPrivate(jsctx);
- const char *interface;
char address[NI_MAXHOST];
DBG("");
@@ -106,11 +76,7 @@ static JSBool myipaddress(JSContext *jsctx, uintN argc,
jsval *vp)
if (!ctx)
return JS_TRUE;
- interface = pacrunner_proxy_get_interface(ctx->proxy);
- if (!interface)
- return JS_TRUE;
-
- if (getaddr(interface, address, sizeof(address)) < 0)
+ if (__pacrunner_js_getipaddr(ctx->proxy, address, sizeof(address)) < 0)
return JS_TRUE;
DBG("address %s", address);
diff --git a/plugins/v8.cc b/plugins/v8.cc
index ebb88a6..954239d 100644
--- a/plugins/v8.cc
+++ b/plugins/v8.cc
@@ -27,11 +27,8 @@
#include <errno.h>
#include <unistd.h>
#include <string.h>
-#include <sys/ioctl.h>
#include <netdb.h>
-#include <arpa/inet.h>
-#include <linux/if_arp.h>
#include <v8.h>
@@ -51,32 +48,6 @@ static gboolean v8_gc(gpointer user_data)
return !v8::V8::IdleNotification();
}
-static int getaddr(const char *node, char *host, size_t hostlen)
-{
- struct sockaddr_in addr;
- struct ifreq ifr;
- int sk, err;
-
- sk = socket(PF_INET, SOCK_DGRAM, 0);
- if (sk < 0)
- return -EIO;
-
- memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, node, sizeof(ifr.ifr_name));
-
- err = ioctl(sk, SIOCGIFADDR, &ifr);
-
- close(sk);
-
- if (err < 0)
- return -EIO;
-
- memcpy(&addr, &ifr.ifr_addr, sizeof(addr));
- snprintf(host, hostlen, "%s", inet_ntoa(addr.sin_addr));
-
- return 0;
-}
-
static int resolve(const char *node, char *host, size_t hostlen)
{
struct addrinfo *info;
@@ -106,11 +77,7 @@ static v8::Handle<v8::Value> myipaddress(const
v8::Arguments& args)
if (current_proxy == NULL)
return v8::ThrowException(v8::String::New("No current proxy"));
- interface = pacrunner_proxy_get_interface(current_proxy);
- if (interface == NULL)
- return v8::ThrowException(v8::String::New("Error fetching
interface"));
-
- if (getaddr(interface, address, sizeof(address)) < 0)
+ if (__pacrunner_js_getipaddr(current_proxy, address, sizeof(address)) <
0)
return v8::ThrowException(v8::String::New("Error fetching IP
address"));
DBG("address %s", address);
diff --git a/src/js.h b/src/js.h
index f45efbf..b924cdb 100644
--- a/src/js.h
+++ b/src/js.h
@@ -36,5 +36,7 @@ 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 */
+int __pacrunner_js_getipaddr(struct pacrunner_proxy *proxy, char *host,
+ size_t hostlen);
extern const char __pacrunner_js_routines[];
diff --git a/src/js_funcs.c b/src/js_funcs.c
index 6e9cf1e..d8204e5 100644
--- a/src/js_funcs.c
+++ b/src/js_funcs.c
@@ -23,6 +23,50 @@
#include <config.h>
#endif
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <stdio.h>
+
+#include <arpa/inet.h>
+#include <linux/if_arp.h>
+
+#include "pacrunner.h"
+#include "js.h"
+
+int __pacrunner_js_getipaddr(struct pacrunner_proxy *proxy, char *host,
+ size_t hostlen)
+{
+ const char *interface;
+ struct sockaddr_in addr;
+ struct ifreq ifr;
+ int sk, err;
+
+ interface = pacrunner_proxy_get_interface(proxy);
+ if (!interface)
+ return -EINVAL;
+
+ sk = socket(PF_INET, SOCK_DGRAM, 0);
+ if (sk < 0)
+ return -EIO;
+
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
+
+ err = ioctl(sk, SIOCGIFADDR, &ifr);
+
+ close(sk);
+
+ if (err < 0)
+ return -EIO;
+
+ memcpy(&addr, &ifr.ifr_addr, sizeof(addr));
+ snprintf(host, hostlen, "%s", inet_ntoa(addr.sin_addr));
+
+ return 0;
+}
+
const char __pacrunner_js_routines[] =
"function dnsDomainIs(host, domain) {\n" \
" return (host.length >= domain.length &&\n" \
--
2.7.4
------------------------------
Message: 2
Date: Tue, 16 Aug 2016 17:01:37 +0100
From: [email protected]
To: [email protected]
Subject: [PATCH 7/7] Add duktape support
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8
From: David Woodhouse <[email protected]>
---
Makefile.am | 10 ++-
configure.ac | 5 ++
plugins/duktape.c | 231 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 245 insertions(+), 1 deletion(-)
create mode 100644 plugins/duktape.c
diff --git a/Makefile.am b/Makefile.am
index d637baf..8f1f9fc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -41,6 +41,12 @@ builtin_sources += plugins/v8.cc
builtin_libadd += @V8_LIBS@
endif
+if DUKTAPE
+js_sources = src/js_funcs.c
+builtin_modules += duktape
+builtin_sources += plugins/duktape.c duktape/duktape.c
+endif
+
sbin_PROGRAMS = src/pacrunner
src_pacrunner_SOURCES = $(gdbus_sources) $(builtin_sources) $(js_sources) \
@@ -126,11 +132,13 @@ unit_test_mozjs_LDADD = @MOZJS_LIBS@ @GLIB_LIBS@
@PTHREAD_LIBS@
endif
if V8
-
unit_test_pacrunner_SOURCES += plugins/v8.cc
unit_test_pacrunner_LDADD += @V8_LIBS@
+endif
+if DUKTAPE
+unit_test_pacrunner_SOURCES += plugins/duktape.c duktape/duktape.c
endif
endif #UNIT
diff --git a/configure.ac b/configure.ac
index c788c7f..d31cdcc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -69,6 +69,11 @@ AC_ARG_ENABLE(pie, AC_HELP_STRING([--enable-pie],
fi
])
+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
diff --git a/plugins/duktape.c b/plugins/duktape.c
new file mode 100644
index 0000000..a8a93bc
--- /dev/null
+++ b/plugins/duktape.c
@@ -0,0 +1,231 @@
+/*
+ * PACrunner - Proxy configuration daemon
+ *
+ * Copyright ? 2013-2016 Intel Corporation. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or modify
+ * it under the terms and conditions of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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 <sys/ioctl.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include <ctype.h>
+
+#include <netdb.h>
+
+#include "pacrunner.h"
+#include "js.h"
+
+#include "duktape/duktape.h"
+
+struct pacrunner_duktape {
+ struct pacrunner_proxy *proxy;
+ pthread_mutex_t lock;
+ duk_context *dctx;
+};
+
+static duk_ret_t myipaddress(duk_context *dkctx)
+{
+ struct pacrunner_duktape *ctx;
+ duk_memory_functions fns;
+ char address[NI_MAXHOST];
+
+ duk_get_memory_functions(dkctx, &fns);
+ ctx = fns.udata;
+
+ if (__pacrunner_js_getipaddr(ctx->proxy, address, sizeof(address)) < 0)
+ duk_push_string(dkctx, NULL);
+ else
+ duk_push_string(dkctx, address);
+
+ DBG("address %s", address);
+
+ return 1;
+}
+
+static duk_ret_t dnsresolve(duk_context *dkctx)
+{
+ struct pacrunner_duktape *ctx;
+ const char *host = duk_require_string(dkctx, 0);
+ duk_memory_functions fns;
+ char address[NI_MAXHOST];
+
+ DBG("host %s", host);
+
+ duk_get_memory_functions(dkctx, &fns);
+ ctx = fns.udata;
+
+ address[0] = 0;
+ if (__pacrunner_js_resolve(ctx->proxy, host, address,
+ sizeof(address)) < 0)
+ duk_push_string(dkctx, NULL);
+ else
+ duk_push_string(dkctx, address);
+
+ DBG("address %s", address);
+
+ return 1;
+}
+
+static int create_object(struct pacrunner_proxy *proxy)
+{
+ struct pacrunner_duktape *ctx;
+ const char *script;
+
+ script = (char *) pacrunner_proxy_get_script(proxy);
+ if (!script) {
+ pacrunner_error("no script\n");
+ return 0;
+ }
+
+ ctx = g_malloc0(sizeof(struct pacrunner_duktape));
+
+ ctx->proxy = proxy;
+ ctx->dctx = duk_create_heap(NULL, NULL, NULL, ctx, NULL);
+ if (!ctx->dctx) {
+ pacrunner_error("no headp\n");
+ g_free(ctx);
+ return -ENOMEM;
+ }
+ duk_push_global_object(ctx->dctx);
+
+ /* Register the C functions so the script can use them */
+ duk_push_c_function(ctx->dctx, myipaddress, 0);
+ duk_put_prop_string(ctx->dctx, -2, "myIpAddress");
+
+ duk_push_c_function(ctx->dctx, dnsresolve, 1);
+ duk_put_prop_string(ctx->dctx, -2, "dnsResolve");
+
+ if (duk_peval_string_noresult(ctx->dctx,
+ __pacrunner_js_routines) != 0 ||
+ duk_peval_string_noresult(ctx->dctx, script) != 0) {
+ pacrunner_error("Error: %s\n",
+ duk_safe_to_string(ctx->dctx, -1));
+ duk_destroy_heap(ctx->dctx);
+ g_free(ctx);
+ return -EINVAL;
+ }
+
+ if (pthread_mutex_init(&ctx->lock, NULL) != 0) {
+ pacrunner_error("Failed to init mutex lock\n");
+ duk_destroy_heap(ctx->dctx);
+ g_free(ctx);
+ return -EIO;
+ }
+
+ __pacrunner_proxy_set_jsctx(proxy, ctx);
+ pacrunner_error("done %p\n", ctx);
+ return 0;
+}
+
+static int duktape_clear_proxy(struct pacrunner_proxy *proxy)
+{
+ struct pacrunner_duktape *ctx = __pacrunner_proxy_get_jsctx(proxy);
+
+ DBG("proxy %p ctx %p", proxy, ctx);
+
+ if (!ctx)
+ return -EINVAL;
+
+ duk_destroy_heap(ctx->dctx);
+ pthread_mutex_destroy(&ctx->lock);
+
+ __pacrunner_proxy_set_jsctx(proxy, NULL);
+ return 0;
+}
+
+static int duktape_set_proxy(struct pacrunner_proxy *proxy)
+{
+ DBG("proxy %p", proxy);
+
+ if (!proxy)
+ return 0;
+
+ duktape_clear_proxy(proxy);
+
+ return create_object(proxy);
+}
+
+static char *duktape_execute(struct pacrunner_proxy *proxy,
+ const char *url, const char *host)
+{
+ struct pacrunner_duktape *ctx = __pacrunner_proxy_get_jsctx(proxy);
+ char *result;
+
+ DBG("proxy %p ctx %p url %s host %s", proxy, ctx, url, host);
+
+ if (!ctx)
+ return NULL;
+
+ pthread_mutex_lock(&ctx->lock);
+
+ duk_get_prop_string(ctx->dctx, -1 /*index*/, "FindProxyForURL");
+
+ duk_push_string(ctx->dctx, url);
+ duk_push_string(ctx->dctx, host);
+ if (duk_pcall(ctx->dctx, 2 /*nargs*/) != 0) {
+ pacrunner_error("Error: %s\n",
+ duk_safe_to_string(ctx->dctx, -1));
+ result = NULL;
+ } else {
+ result = strdup(duk_safe_to_string(ctx->dctx, -1));
+ }
+ duk_pop(ctx->dctx); /* pop result/error */
+
+ if (result) {
+ DBG("the return string is: %s\n", result);
+ }
+
+ pthread_mutex_unlock(&ctx->lock);
+
+ return result;
+}
+
+
+static struct pacrunner_js_driver duktape_driver = {
+ .name = "duktape",
+ .priority = PACRUNNER_JS_PRIORITY_HIGH,
+ .set_proxy = duktape_set_proxy,
+ .clear_proxy = duktape_clear_proxy,
+ .execute = duktape_execute,
+};
+
+static int duktape_init(void)
+{
+ DBG("");
+
+ return pacrunner_js_driver_register(&duktape_driver);
+}
+
+
+static void duktape_exit(void)
+{
+ DBG("");
+
+ pacrunner_js_driver_unregister(&duktape_driver);
+
+ duktape_set_proxy(NULL);
+}
+
+PACRUNNER_PLUGIN_DEFINE(duktape, duktape_init, duktape_exit)
--
2.7.4
------------------------------
Message: 3
Date: Tue, 16 Aug 2016 17:27:42 +0100
From: David Woodhouse <[email protected]>
To: [email protected]
Subject: [PATCH 6/7] Import duktape v1.5.0
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
---
This patch is huge, so it got eaten by the mailing list. I've split it
out so it's doing *nothing* but dropping the duktape release files into
a duktape/ directory. It can be seen in its full glory at
http://git.infradead.org/users/dwmw2/pacrunner.git/commitdiff/7ae270a8e
?duktape/duk_config.h |??3753 +++
?duktape/duktape.c????| 86379 +++++++++++++++++++++++++++++++++++++++++++++++++
?duktape/duktape.h????|??1567 +
?3 files changed, 91699 insertions(+)
?create mode 100644 duktape/duk_config.h
?create mode 100644 duktape/duktape.c
?create mode 100644 duktape/duktape.h
...
--
David Woodhouse Open Source Technology Centre
[email protected] Intel Corporation
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5760 bytes
Desc: not available
URL:
<http://lists.01.org/pipermail/connman/attachments/20160816/e69975df/attachment-0001.bin>
------------------------------
Subject: Digest Footer
_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman
------------------------------
End of connman Digest, Vol 10, Issue 16
***************************************