Module: kamailio Branch: master Commit: 037632161767262c3c562d20985ae8c66637f0d8 URL: https://github.com/kamailio/kamailio/commit/037632161767262c3c562d20985ae8c66637f0d8
Author: Daniel-Constantin Mierla <mico...@gmail.com> Committer: Daniel-Constantin Mierla <mico...@gmail.com> Date: 2017-04-20T20:07:55+02:00 app_sqlang: implemented KSR.x.exit() using context field --- Modified: src/modules/app_sqlang/app_sqlang_api.c --- Diff: https://github.com/kamailio/kamailio/commit/037632161767262c3c562d20985ae8c66637f0d8.diff Patch: https://github.com/kamailio/kamailio/commit/037632161767262c3c562d20985ae8c66637f0d8.patch --- diff --git a/src/modules/app_sqlang/app_sqlang_api.c b/src/modules/app_sqlang/app_sqlang_api.c index d5e3f86..e654cdc 100644 --- a/src/modules/app_sqlang/app_sqlang_api.c +++ b/src/modules/app_sqlang/app_sqlang_api.c @@ -52,7 +52,9 @@ void sqlang_sr_kemi_register_libs(HSQUIRRELVM J); typedef struct _sr_sqlang_env { HSQUIRRELVM J; + int J_exit; HSQUIRRELVM JJ; + int JJ_exit; sip_msg_t *msg; unsigned int flags; unsigned int nload; /* number of scripts loaded */ @@ -248,7 +250,15 @@ static int sqlang_isfunction(HSQUIRRELVM J, int idx) static char* sqlang_safe_tostring(HSQUIRRELVM J, int idx) { - return "Error on sqlang"; + const SQChar *s = NULL; + + if(idx>=0) { + idx += 2; + } + if(sqlang_isstring(J, idx)) { + sq_getstring(J, idx, &s); + } + return (s)?(char*)s:"Error on sqlang"; } static int sqlang_gettype(HSQUIRRELVM J, int idx) @@ -508,6 +518,11 @@ const SQRegFunction _sr_kemi_pv_J_Map[] = { */ static SQInteger sqlang_sr_exit (HSQUIRRELVM J) { + if(_sr_J_env.JJ==J) { + _sr_J_env.JJ_exit = 1; + } else { + _sr_J_env.J_exit = 1; + } return sq_throwerror(J, _SC("~~ksr~exit~~")); } @@ -516,6 +531,11 @@ static SQInteger sqlang_sr_exit (HSQUIRRELVM J) */ static SQInteger sqlang_sr_drop (HSQUIRRELVM J) { + if(_sr_J_env.JJ==J) { + _sr_J_env.JJ_exit = 1; + } else { + _sr_J_env.J_exit = 1; + } sr_kemi_core_drop(NULL); return sq_throwerror(J, _SC("~~ksr~exit~~")); } @@ -693,11 +713,23 @@ const SQRegFunction _sr_kemi_x_J_Map[] = { /** * */ -void sqlang_errorfunc(HSQUIRRELVM SQ_UNUSED_ARG(J), const SQChar *fmt,...) +void sqlang_errorfunc(HSQUIRRELVM J, const SQChar *fmt, ...) { char ebuf[4096]; va_list ap; + if(_sr_J_env.JJ==J) { + if(_sr_J_env.JJ_exit == 1) { + LM_DBG("exception on ksr exit (JJ)\n"); + return; + } + } else { + if(_sr_J_env.J_exit == 1) { + LM_DBG("exception on ksr exit (J)\n"); + return; + } + } + ebuf[0] = '\0'; va_start(ap, fmt); vsnprintf(ebuf, 4094, fmt, ap); @@ -965,16 +997,23 @@ int app_sqlang_run_ex(sip_msg_t *msg, char *func, char *p1, char *p2, LM_DBG("executing sqlang function: [[%s]] (n: %d)\n", func, n); bmsg = _sr_J_env.msg; _sr_J_env.msg = msg; + _sr_J_env.JJ_exit = 0; /* call the function */ rv = sq_call(_sr_J_env.JJ, n, SQFalse, SQTrue); if(SQ_SUCCEEDED(rv)) { ret = 1; } else { - LM_ERR("failed to execute the func: %s (%d)\n", func, (int)rv); - sqstd_printcallstack(_sr_J_env.JJ); - ret = -1; + if(_sr_J_env.JJ_exit==0) { + LM_ERR("failed to execute the func: %s (%d)\n", func, (int)rv); + sqstd_printcallstack(_sr_J_env.JJ); + ret = -1; + } else { + LM_DBG("script execution exit\n"); + ret = 1; + } } _sr_J_env.msg = bmsg; + _sr_J_env.JJ_exit = 0; sq_settop(_sr_J_env.JJ, (top<=0)?1:top); /* restores the original stack size */ return ret; _______________________________________________ Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev