[PATCH 0/5] Avoid to keep service in list if AP is not found during scan
by blanquicet@gmail.com
From: Jose Blanquicet <jose.blanquicet-melendez(a)magnetimarelli.com>
This patch set does not remove any auto-connect/roaming functionality,
it aims to avoit keeping service in the list after AP deauthenticate
us and it is not found in the scan.
The first three patches revert the patches that add the connectable
flag because such implementation prevents ConnMan to remove the service
from the services list when it is no longer in range, resulting in a
confusion for users because they will continue seeing a service in their
list when it is not actually available.
Doing so, ConnMan will remove the service as other services and then,
once it comes back, wpa_s will notify ConnMan about it through a
"BSSAdded" signal which will start auto-connect procedure and state
machines would continue correctly. In case wpa_s does not send such
signal before notifying we got connected, which should not happen, the
last two patches of this set introduce a notification named
"network_associated" which should handle this border case. I tested it
by simulating ConnMan do not process "BSSAdded" signals and it worked,
it means that state machines moved correctly and connection trigger
from wpa_s completed successfully.
I do not think I could trigger all use cases thus I would appreciate if
people could test auto-connect and roaming use cases. Mainly
auto-connect when AP is who deauthenticate STA. For instance, Saurav
Babu in the scenario he recently mentioned when AP blocks STA's MAC
address.
Jose Blanquicet (5):
Revert "device: Use network's connectable flag"
Revert "plugins/wifi: Marking network's Connectable flag as true."
Revert "network: connectable flag in network structure"
gsupplicant: Add callback to notify the associated network
wifi: Set current network in case of reconnection
gsupplicant/gsupplicant.h | 1 +
gsupplicant/supplicant.c | 25 +++++++++++++++
include/network.h | 5 ---
plugins/wifi.c | 82 +++++++++++++++++++++++++++++------------------
src/device.c | 6 +---
src/network.c | 13 --------
6 files changed, 78 insertions(+), 54 deletions(-)
--
1.9.1
3 years, 9 months
Why I have no Scope:Global IPV6 address ?
by Pierre Couderc
I use connman but get no Scope:Global IPV6 address.
What so I miss ?
Thanks
PC
sudo ifconfig :
wlan0 Link encap:Ethernet HWaddr 40:f0:2f:c6:9a:d2
inet addr:192.168.163.11 Bcast:192.168.163.255
Mask:255.255.255.0
inet6 addr: fe80::42f0:2fff:fec6:9ad2/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
....
3 years, 10 months
Best Practices to reestablish DHCP Ethernet
by Bill
I have a number of Debian Jessie Beaglebones running DHCP using Connman 1.33
in the field at various customer sites with multiple Network providers and
routers. All work well except two which seem to lose ethernet IP's at random
intervals but always come back after a physical box reboot.
What is the appropriate action to take in code when connectivity is lost for
say 5 mins due to an unknown problem:
Service connman restart ?
Something else?
Do I need to renew dhclient or is it not used by Connman?
Further, would you expect Connman to ALWAYS just work & pull a non 169 IP
after recovery from a router outage because it keeps trying to get a real
address - suggesting something more serious has happened that may require me
to reboot my HW?
I realize that the best approach is to solve the problem but with no control
over the customer's equipment I want to have a reasonable 'get me back'
system.
Any ideas?
Thanks
Bill
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
3 years, 11 months
[PATCH v2 5/5] session: Interface to query session->mark value
by sutar.mounesh@gmail.com
From: Bjoern Thorwirth <external.bjoern.thorwirth(a)de.bosch.com>
Will return the session mark
(without needing to expose the complete struct connman_session)
diff --git a/include/session.h b/include/session.h
index 0d66f48..68be6a9 100644
--- a/include/session.h
+++ b/include/session.h
@@ -22,8 +22,10 @@
#ifndef __CONNMAN_SESSION_H
#define __CONNMAN_SESSION_H
+#include <stdint.h>
#include <connman/service.h>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -97,6 +99,7 @@ struct connman_session_policy {
GSList* services);
};
+uint32_t connman_session_firewall_get_fwmark(struct connman_session *session);
int connman_session_policy_register(struct connman_session_policy *config);
void connman_session_policy_unregister(struct connman_session_policy *config);
diff --git a/src/session.c b/src/session.c
index b408037..d66ba3f 100644
--- a/src/session.c
+++ b/src/session.c
@@ -436,6 +436,11 @@ static void add_nat_rules(struct connman_session *session)
g_free(ifname);
}
+uint32_t connman_session_firewall_get_fwmark(struct connman_session *session)
+{
+ return session->mark;
+}
+
static void cleanup_routing_table(struct connman_session *session)
{
DBG("");
--
2.7.4
3 years, 11 months
[PATCH v2 4/5] session: Callback hook for policy plugin to return service of session
by sutar.mounesh@gmail.com
From: Bjoern Thorwirth <external.bjoern.thorwirth(a)de.bosch.com>
Returns the allowed service for a session based on a provided list of available services.
diff --git a/include/session.h b/include/session.h
index 25a5e58..0d66f48 100644
--- a/include/session.h
+++ b/include/session.h
@@ -93,6 +93,8 @@ struct connman_session_policy {
struct connman_service *service);
void (*update_session_state)(struct connman_session* session,
enum connman_session_state state);
+ struct connman_service* (*get_service_for_session)(struct connman_session* session,
+ GSList* services);
};
int connman_session_policy_register(struct connman_session_policy *config);
diff --git a/src/session.c b/src/session.c
index 0c8c0bb..b408037 100644
--- a/src/session.c
+++ b/src/session.c
@@ -1757,6 +1757,41 @@ static void session_activate(struct connman_session *session)
if (!service_hash)
return;
+ if (policy && policy->get_service_for_session)
+ {
+ struct connman_service *service;
+ struct connman_service_info *info;
+ GSList *service_list = NULL;
+ enum connman_service_state state = CONNMAN_SESSION_STATE_DISCONNECTED;
+
+ g_hash_table_iter_init(&iter, service_hash);
+
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ struct connman_service_info *info = value;
+ state = __connman_service_get_state(info->service);
+
+ if (is_session_connected(session, state))
+ service_list = g_slist_prepend(service_list,
+ info->service);
+ }
+
+ service_list = g_slist_reverse(service_list);
+ service = policy->get_service_for_session(session,service_list);
+
+ if (service) {
+ info = g_hash_table_lookup(service_hash,service);
+ DBG("session %p add service %p", session, info->service);
+
+ info->sessions = g_slist_prepend(info->sessions,
+ session);
+ session->service = info->service;
+ update_session_state(session);
+ }
+
+ g_slist_free(service_list);
+ return;
+ }
+
g_hash_table_iter_init(&iter, service_hash);
while (g_hash_table_iter_next(&iter, &key, &value)) {
struct connman_service_info *info = value;
--
2.7.4
3 years, 11 months
[PATCH v2 3/5] service: Query function to retrieve service handle
by sutar.mounesh@gmail.com
From: Bjoern Thorwirth <external.bjoern.thorwirth(a)de.bosch.com>
Query function to retrieve service handle for service identifier string
diff --git a/include/service.h b/include/service.h
index 185f008..958e7fd 100644
--- a/include/service.h
+++ b/include/service.h
@@ -130,6 +130,7 @@ bool connman_service_get_favorite(struct connman_service *service);
bool connman_service_get_autoconnect(struct connman_service *service);
struct connman_service *connman_service_lookup_from_network(struct connman_network *network);
+struct connman_service *connman_service_lookup_from_identifier(const char* identifier);
void connman_service_create_ip4config(struct connman_service *service,
int index);
diff --git a/src/service.c b/src/service.c
index 2289d54..d9c1907 100644
--- a/src/service.c
+++ b/src/service.c
@@ -6404,6 +6404,11 @@ static struct connman_service *lookup_by_identifier(const char *identifier)
return g_hash_table_lookup(service_hash, identifier);
}
+struct connman_service *connman_service_lookup_from_identifier(const char* identifier)
+{
+ return lookup_by_identifier(identifier);
+}
+
struct provision_user_data {
const char *ident;
int ret;
--
2.7.4
3 years, 11 months
[PATCH v2 2/5] session: Callback hook for policy plugins to update session state
by sutar.mounesh@gmail.com
From: Bjoern Thorwirth <external.bjoern.thorwirth(a)de.bosch.com>
Called when state of session changes.
diff --git a/include/session.h b/include/session.h
index 48f1510..25a5e58 100644
--- a/include/session.h
+++ b/include/session.h
@@ -55,6 +55,12 @@ enum connman_session_id_type {
CONNMAN_SESSION_ID_TYPE_LSM = 3,
};
+enum connman_session_state {
+ CONNMAN_SESSION_STATE_DISCONNECTED = 0,
+ CONNMAN_SESSION_STATE_CONNECTED = 1,
+ CONNMAN_SESSION_STATE_ONLINE = 2,
+};
+
struct connman_session;
struct connman_session_config {
@@ -85,6 +91,8 @@ struct connman_session_policy {
GSList *bearers);
bool (*allowed)(struct connman_session *session,
struct connman_service *service);
+ void (*update_session_state)(struct connman_session* session,
+ enum connman_session_state state);
};
int connman_session_policy_register(struct connman_session_policy *config);
diff --git a/src/session.c b/src/session.c
index b77d9dc..0c8c0bb 100644
--- a/src/session.c
+++ b/src/session.c
@@ -38,12 +38,6 @@ static GHashTable *service_hash;
static struct connman_session *ecall_session;
static uint32_t session_mark = 256;
-enum connman_session_state {
- CONNMAN_SESSION_STATE_DISCONNECTED = 0,
- CONNMAN_SESSION_STATE_CONNECTED = 1,
- CONNMAN_SESSION_STATE_ONLINE = 2,
-};
-
struct session_info {
struct connman_session_config config;
enum connman_session_state state;
@@ -1691,6 +1685,10 @@ static void update_session_state(struct connman_session *session)
del_nat_rules(session);
update_routing_table(session);
add_nat_rules(session);
+
+ if (policy && policy->update_session_state)
+ policy->update_session_state(session, state);
+
session_notify(session);
}
diff --git a/tools/session-test.h b/tools/session-test.h
index 5e6d196..8512933 100644
--- a/tools/session-test.h
+++ b/tools/session-test.h
@@ -68,12 +68,6 @@ void util_session_cleanup(struct test_session *session);
typedef void (* notify_func_t) (struct test_session *session);
-enum connman_session_state {
- CONNMAN_SESSION_STATE_DISCONNECTED = 0,
- CONNMAN_SESSION_STATE_CONNECTED = 1,
- CONNMAN_SESSION_STATE_ONLINE = 2,
-};
-
struct test_session_info {
enum connman_session_state state;
char *name;
--
2.7.4
3 years, 11 months
[PATCH v2 1/5] session: add parameter Service into createsession call of ConnMan session API
by sutar.mounesh@gmail.com
From: Bjoern Thorwirth <external.bjoern.thorwirth(a)de.bosch.com>
It is extension to the session API interface. It enables a service differentiation
for processes run by the same user. It allows ConnMan to differentiate between bearer
usage permissions and the respective priorities based on the requested service type.
Usually calling process that implements the session API is identified by the user ID
as it is runs. All processes of the same user share the same list of allowed bearers,
and the same priority for choosing between available bearers is applied.
With the proposed changes, extension allows processes to select a service context
for which the routing decision is made.
diff --git a/src/session.c b/src/session.c
index 1f80b14..b77d9dc 100644
--- a/src/session.c
+++ b/src/session.c
@@ -549,6 +549,7 @@ struct creation_data {
GSList *allowed_bearers;
char *allowed_interface;
bool source_ip_rule;
+ char *service;
};
static void cleanup_creation_data(struct creation_data *creation_data)
@@ -558,6 +559,8 @@ static void cleanup_creation_data(struct creation_data *creation_data)
if (creation_data->pending)
dbus_message_unref(creation_data->pending);
+ if (creation_data->service)
+ g_free(creation_data->service);
g_slist_free(creation_data->allowed_bearers);
g_free(creation_data->allowed_interface);
@@ -1475,6 +1478,9 @@ int __connman_session_create(DBusMessage *msg)
connman_session_parse_connection_type(val);
user_connection_type = true;
+ } else if (g_str_equal(key, "Service")) {
+ dbus_message_iter_get_basic(&value, &val);
+ creation_data->service = g_strdup(val);
} else if (g_str_equal(key, "AllowedInterface")) {
dbus_message_iter_get_basic(&value, &val);
creation_data->allowed_interface = g_strdup(val);
--
2.7.4
3 years, 11 months
[PATCH v3] build: Pull pacrunner forward to mozjs38
by Jeremy Linton
Mozjs185 is getting really old and unsupported. Newer versions
of the mozjs JSAPI are C++ based. So we convert the plugin to
C++ and then apply necessarily API changes so that it can be built
with the more recent mozjs38. For example we now need to "root"
values being passed into the API in order to satisfy the JSAPI
garbage collection rules. Further, a number of the APIs have been
tweaked and moved into the JS namespace, so we namespace them
appropriately and adjust their parameters.
---
Makefile.am | 15 +++---
configure.ac | 4 +-
plugins/{mozjs.c => mozjs.cc} | 109 ++++++++++++++++++++++--------------------
3 files changed, 68 insertions(+), 60 deletions(-)
rename plugins/{mozjs.c => mozjs.cc} (59%)
diff --git a/Makefile.am b/Makefile.am
index ee84b75..65cc8c9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -31,9 +31,10 @@ endif
if MOZJS
js_sources = src/js_funcs.c
builtin_modules += mozjs
-builtin_sources += plugins/mozjs.c
-builtin_cflags += @MOZJS_CFLAGS@
-builtin_libadd += @MOZJS_LIBS@
+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 V8
@@ -137,16 +138,16 @@ unit_test_pacrunner_LDADD += @CURL_LIBS@
endif
if MOZJS
-unit_test_pacrunner_SOURCES += plugins/mozjs.c
-
+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.c $(js_sources)
-
+ 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
diff --git a/configure.ac b/configure.ac
index 888c873..bf76fbb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -76,8 +76,8 @@ 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, mozjs185, dummy=yes,
- AC_MSG_ERROR(Mozilla Javascript >= 1.8 is required))
+ 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
diff --git a/plugins/mozjs.c b/plugins/mozjs.cc
similarity index 59%
rename from plugins/mozjs.c
rename to plugins/mozjs.cc
index a923203..e10b297 100644
--- a/plugins/mozjs.c
+++ b/plugins/mozjs.cc
@@ -31,11 +31,15 @@
#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;
@@ -43,42 +47,42 @@ struct pacrunner_mozjs {
struct pacrunner_proxy *proxy;
JSContext *jsctx;
JSObject *jsobj;
+ JSAutoCompartment *jsac;
};
-static JSBool myipaddress(JSContext *jsctx, uintN argc, jsval *vp)
+static bool myipaddress(JSContext *jsctx, unsigned argc, jsval *vp)
{
- struct pacrunner_mozjs *ctx = JS_GetContextPrivate(jsctx);
+ struct pacrunner_mozjs *ctx = (pacrunner_mozjs *)JS_GetContextPrivate(jsctx);
char address[NI_MAXHOST];
DBG("");
- JS_SET_RVAL(jsctx, vp, JSVAL_NULL);
+ JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
+
+ args.rval().setNull();
if (!ctx)
- return JS_TRUE;
+ return true;
if (__pacrunner_js_getipaddr(ctx->proxy, address, sizeof(address)) < 0)
- return JS_TRUE;
+ return true;
DBG("address %s", address);
- JS_SET_RVAL(jsctx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(jsctx,
- address)));
+ args.rval().setString(JS_NewStringCopyZ(jsctx,address));
- return JS_TRUE;
+ return true;
}
-static JSBool dnsresolve(JSContext *jsctx, uintN argc, jsval *vp)
+static bool dnsresolve(JSContext *jsctx, unsigned argc, jsval *vp)
{
- struct pacrunner_mozjs *ctx = JS_GetContextPrivate(jsctx);
+ struct pacrunner_mozjs *ctx = (pacrunner_mozjs *)JS_GetContextPrivate(jsctx);
char address[NI_MAXHOST];
- jsval *argv = JS_ARGV(jsctx, vp);
- char *host = JS_EncodeString(jsctx, JS_ValueToString(jsctx, argv[0]));
+ JS::CallArgs args = JS::CallArgsFromVp(argc,vp);
+ char * host = JS_EncodeString(jsctx, args[0].toString());
DBG("host %s", host);
- JS_SET_RVAL(jsctx, vp, JSVAL_NULL);
-
if (!ctx)
goto out;
@@ -87,20 +91,16 @@ static JSBool dnsresolve(JSContext *jsctx, uintN argc, jsval *vp)
DBG("address %s", address);
- JS_SET_RVAL(jsctx, vp, STRING_TO_JSVAL(JS_NewStringCopyZ(jsctx, address)));
+ args.rval().setString(JS_NewStringCopyZ(jsctx,address));
out:
JS_free(jsctx, host);
- return JS_TRUE;
+ return true;
}
static JSClass jscls = {
"global", JSCLASS_GLOBAL_FLAGS,
- JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};
static JSRuntime *jsrun;
@@ -109,13 +109,12 @@ static int create_object(struct pacrunner_proxy *proxy)
{
struct pacrunner_mozjs *ctx;
const char *script;
- jsval rval;
script = pacrunner_proxy_get_script(proxy);
if (!script)
return 0;
- ctx = g_malloc0(sizeof(struct pacrunner_mozjs));
+ ctx = (pacrunner_mozjs *)g_malloc0(sizeof(struct pacrunner_mozjs));
ctx->proxy = proxy;
ctx->jsctx = JS_NewContext(jsrun, 8 * 1024);
@@ -126,41 +125,48 @@ static int create_object(struct pacrunner_proxy *proxy)
JS_SetContextPrivate(ctx->jsctx, ctx);
__pacrunner_proxy_set_jsctx(proxy, ctx);
-#if JS_VERSION >= 185
- ctx->jsobj = JS_NewCompartmentAndGlobalObject(ctx->jsctx, &jscls,
- NULL);
-#else
- ctx->jsobj = JS_NewObject(ctx->jsctx, &jscls, NULL, NULL);
-#endif
+ 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, ctx->jsobj))
+ if (!JS_InitStandardClasses(ctx->jsctx, jsobj))
pacrunner_error("Failed to init JS standard classes");
- JS_DefineFunction(ctx->jsctx, ctx->jsobj, "myIpAddress",
- myipaddress, 0, 0);
- JS_DefineFunction(ctx->jsctx, ctx->jsobj,
- "dnsResolve", dnsresolve, 1, 0);
+ 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_EvaluateScript(ctx->jsctx, ctx->jsobj, __pacrunner_js_routines,
- strlen(__pacrunner_js_routines), NULL, 0, &rval);
+ JS::Evaluate(ctx->jsctx, JS::HandleObject(jsobj), opts,
+ __pacrunner_js_routines, strlen(__pacrunner_js_routines)
+ , &rval);
- JS_EvaluateScript(ctx->jsctx, ctx->jsobj, script, strlen(script),
- "wpad.dat", 0, &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_proxy_get_jsctx(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;
}
@@ -168,7 +174,6 @@ static int mozjs_clear_proxy(struct pacrunner_proxy *proxy)
static int mozjs_set_proxy(struct pacrunner_proxy *proxy)
{
DBG("proxy %p", proxy);
-
if (!proxy)
return 0;
@@ -180,11 +185,9 @@ static int mozjs_set_proxy(struct pacrunner_proxy *proxy)
static char * mozjs_execute(struct pacrunner_proxy *proxy, const char *url,
const char *host)
{
- struct pacrunner_mozjs *ctx = __pacrunner_proxy_get_jsctx(proxy);
- JSBool result;
- jsval rval, args[2];
+ 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)
@@ -193,12 +196,16 @@ static char * mozjs_execute(struct pacrunner_proxy *proxy, const char *url,
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));
- args[0] = STRING_TO_JSVAL(JS_NewStringCopyZ(ctx->jsctx, url));
- args[1] = STRING_TO_JSVAL(JS_NewStringCopyZ(ctx->jsctx, host));
- result = JS_CallFunctionName(ctx->jsctx, ctx->jsobj,
- "FindProxyForURL", 2, args, &rval);
+ JS::RootedObject jsobj(ctx->jsctx,ctx->jsobj);
+
+ result = JS_CallFunctionName(ctx->jsctx, jsobj, "FindProxyForURL", args , &rval);
JS_EndRequest(ctx->jsctx);
@@ -207,8 +214,7 @@ static char * mozjs_execute(struct pacrunner_proxy *proxy, const char *url,
pthread_mutex_unlock(&mozjs_mutex);
if (result) {
- answer = JS_EncodeString(ctx->jsctx,
- JS_ValueToString(ctx->jsctx, rval));
+ answer = JS_EncodeString(ctx->jsctx, rval.toString());
g_answer = g_strdup(answer);
JS_free(ctx->jsctx, answer);
return g_answer;
@@ -228,8 +234,8 @@ static struct pacrunner_js_driver mozjs_driver = {
static int mozjs_init(void)
{
DBG("");
-
- jsrun = JS_NewRuntime(8 * 1024 * 1024);
+ JS_Init();
+ jsrun = JS_NewRuntime(JS::DefaultHeapMaxBytes, 8 * 1024 * 1024 );
return pacrunner_js_driver_register(&mozjs_driver);
}
@@ -241,6 +247,7 @@ static void mozjs_exit(void)
pacrunner_js_driver_unregister(&mozjs_driver);
JS_DestroyRuntime(jsrun);
+ JS_ShutDown();
}
PACRUNNER_PLUGIN_DEFINE(mozjs, mozjs_init, mozjs_exit)
--
2.11.0
3 years, 11 months