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 6/6] Add duktape support (David Woodhouse)
   2. Re: [PATCH 4/6] js: add __pacrunner_js_getipaddr() function
      (Tomasz Bursztyka)
   3. Re: [PATCH 5/6] js: add __pacrunner_js_resolve() function
      (Tomasz Bursztyka)
   4. Re: [PATCH 6/6] Add duktape support (Tomasz Bursztyka)
   5. Re: [PATCH 4/6] js: add __pacrunner_js_getipaddr() function
      (David Woodhouse)
   6. Re: [PATCH 6/6] Add duktape support (David Woodhouse)


----------------------------------------------------------------------

Message: 1
Date: Fri, 12 Aug 2016 15:43:28 +0200
From: David Woodhouse <[email protected]>
To: [email protected]
Subject: [PATCH 6/6] Add duktape support
Message-ID: <[email protected]>
Content-Type: text/plain; charset="UTF-8"

---
?Makefile.am??????????|????10 +-
?configure.ac?????????|?????5 +
?duktape/duk_config.h |??3753 +++
?duktape/duktape.c????| 86379 +++++++++++++++++++++++++++++++++++++++++++++++++
?duktape/duktape.h????|??1567 +
?plugins/duktape.c????|???229 +
?6 files changed, 91942 insertions(+), 1 deletion(-)
?create mode 100644 duktape/duk_config.h
?create mode 100644 duktape/duktape.c
?create mode 100644 duktape/duktape.h
?create mode 100644 plugins/duktape.c

(duktape/*.[ch] omitted from this message)

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..6343023
--- /dev/null
+++ b/plugins/duktape.c
@@ -0,0 +1,229 @@
+/*
+ *??PACrunner JavaScript Engine
+ *
+ *??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.5.5

-- 
dwmw2




------------------------------

Message: 2
Date: Fri, 12 Aug 2016 15:58:58 +0200
From: Tomasz Bursztyka <[email protected]>
To: [email protected]
Subject: Re: [PATCH 4/6] js: add __pacrunner_js_getipaddr() function
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed

Hi David,

>   /* Common functions for JS plugins */
> -int __pacrunner_js_resolve(struct pacrunner_proxy *proxy, const char *node, 
> char *host, size_t hostlen);


A rebase issue here? this line should only be added by patch 5 as it seems.

Tomasz



------------------------------

Message: 3
Date: Fri, 12 Aug 2016 15:59:02 +0200
From: Tomasz Bursztyka <[email protected]>
To: [email protected]
Subject: Re: [PATCH 5/6] js: add __pacrunner_js_resolve() function
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed

Hi David,

>   
> +int __pacrunner_js_resolve(struct pacrunner_proxy *proxy, const char *node, 
> char *host, size_t hostlen)

A quick checkpatch could avoid these easy to spot +80 chars limit issues. ;)

Tomasz


------------------------------

Message: 4
Date: Fri, 12 Aug 2016 16:00:53 +0200
From: Tomasz Bursztyka <[email protected]>
To: [email protected]
Subject: Re: [PATCH 6/6] Add duktape support
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed

Hi David,
> +/*
> + *  PACrunner JavaScript Engine
> + *
> + *  Copyright ? 2013-2016  Intel Corporation. All rights reserved.

Remove 2013, and change the title. That's some old legacy thing that 
never came into pacrunner anyway.

Tomasz



------------------------------

Message: 5
Date: Fri, 12 Aug 2016 16:02:10 +0200
From: David Woodhouse <[email protected]>
To: Tomasz Bursztyka <[email protected]>,
        [email protected]
Subject: Re: [PATCH 4/6] js: add __pacrunner_js_getipaddr() function
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

On Fri, 2016-08-12 at 15:58 +0200, Tomasz Bursztyka wrote:
> Hi David,
> 
> > 
> > ? /* Common functions for JS plugins */
> > -int __pacrunner_js_resolve(struct pacrunner_proxy *proxy, const
> > char *node, char *host, size_t hostlen);
> 
> A rebase issue here? this line should only be added by patch 5 as it
> seems.

Indeed, thanks. I've fixed it up along with some >80-char lines, and
pushed it back out to http://,
git://git.infradead.org/users/dwmw2/pacrunner.git

I've also split the commit which adds the duktape v1.5.0 files to
duktape/, from the one which actually *uses* it.

-- 
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/20160812/31a30d83/attachment-0001.bin>

------------------------------

Message: 6
Date: Fri, 12 Aug 2016 16:04:19 +0200
From: David Woodhouse <[email protected]>
To: Tomasz Bursztyka <[email protected]>,
        [email protected]
Subject: Re: [PATCH 6/6] Add duktape support
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

On Fri, 2016-08-12 at 16:00 +0200, Tomasz Bursztyka wrote:
> Hi David,
> > +/*
> > + *? PACrunner JavaScript Engine
> > + *
> > + *? Copyright ? 2013-2016? Intel Corporation. All rights reserved.
> 
> Remove 2013, and change the title. That's some old legacy thing that?
> never came into pacrunner anyway.

Fixed the title to match other files. I think of this code *does* date
from 2013 though, so I've left that. Although there's probably not a
*lot* left... :)

-- 
dwmw2


-------------- 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/20160812/214f63b7/attachment.bin>

------------------------------

Subject: Digest Footer

_______________________________________________
connman mailing list
[email protected]
https://lists.01.org/mailman/listinfo/connman


------------------------------

End of connman Digest, Vol 10, Issue 9
**************************************

Reply via email to