Module: kamailio
Branch: master
Commit: f7509533685129a87f411e395eb87c07935b969d
URL:
https://github.com/kamailio/kamailio/commit/f7509533685129a87f411e395eb87c0…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-02-25T09:29:09+01:00
app_jsdt: added parameter mode to control initialization of js module api
---
Modified: src/modules/app_jsdt/app_jsdt_api.c
Modified: src/modules/app_jsdt/app_jsdt_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/f7509533685129a87f411e395eb87c0…
Patch:
https://github.com/kamailio/kamailio/commit/f7509533685129a87f411e395eb87c0…
---
diff --git a/src/modules/app_jsdt/app_jsdt_api.c b/src/modules/app_jsdt/app_jsdt_api.c
index a3c1026a3a..b1ded049fc 100644
--- a/src/modules/app_jsdt/app_jsdt_api.c
+++ b/src/modules/app_jsdt/app_jsdt_api.c
@@ -54,6 +54,7 @@ typedef struct _sr_jsdt_env
static sr_jsdt_env_t _sr_J_env = {0};
str _sr_jsdt_load_file = STR_NULL;
+int _sr_jsdt_mode = 1;
static int *_sr_jsdt_reload_version = NULL;
static int _sr_jsdt_local_version = 0;
@@ -471,12 +472,14 @@ int jsdt_sr_init_child(int rank)
LM_ERR("cannot create load JS context (load)\n");
return -1;
}
- duk_push_object(_sr_J_env.JJ);
- duk_push_c_function(_sr_J_env.JJ, cb_resolve_module, DUK_VARARGS);
- duk_put_prop_string(_sr_J_env.JJ, -2, "resolve");
- duk_push_c_function(_sr_J_env.JJ, cb_load_module, DUK_VARARGS);
- duk_put_prop_string(_sr_J_env.JJ, -2, "load");
- duk_module_node_init(_sr_J_env.JJ);
+ if(_sr_jsdt_mode == 1) {
+ duk_push_object(_sr_J_env.JJ);
+ duk_push_c_function(_sr_J_env.JJ, cb_resolve_module, DUK_VARARGS);
+ duk_put_prop_string(_sr_J_env.JJ, -2, "resolve");
+ duk_push_c_function(_sr_J_env.JJ, cb_load_module, DUK_VARARGS);
+ duk_put_prop_string(_sr_J_env.JJ, -2, "load");
+ duk_module_node_init(_sr_J_env.JJ);
+ }
jsdt_sr_kemi_register_libs(_sr_J_env.JJ);
LM_DBG("loading js script file: %.*s\n",
_sr_jsdt_load_file.len, _sr_jsdt_load_file.s);
diff --git a/src/modules/app_jsdt/app_jsdt_mod.c b/src/modules/app_jsdt/app_jsdt_mod.c
index 526376a1d5..1328c3069b 100644
--- a/src/modules/app_jsdt/app_jsdt_mod.c
+++ b/src/modules/app_jsdt/app_jsdt_mod.c
@@ -56,6 +56,7 @@ static int w_app_jsdt_run3(sip_msg_t *msg, char *func, char *p1, char
*p2,
static int fixup_jsdt_run(void** param, int param_no);
extern str _sr_jsdt_load_file;
+extern int _sr_jsdt_mode;
/* clang-format off */
static cmd_export_t cmds[]={
@@ -79,6 +80,7 @@ static cmd_export_t cmds[]={
static param_export_t params[]={
{"load", PARAM_STR, &_sr_jsdt_load_file},
+ {"mode", PARAM_INT, &_sr_jsdt_mode},
{0, 0, 0}
};