Module: kamailio Branch: master Commit: 187a29601037820fe79f18069caf5032c9a297c6 URL: https://github.com/kamailio/kamailio/commit/187a29601037820fe79f18069caf5032...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2016-04-14T18:45:44+02:00
app_lua: backup and restore the sip msg structure in lua env
- nested execution of callbacks can happen (e.g., branch route callback executed inside the request_route callback)
---
Modified: modules/app_lua/app_lua_api.c
---
Diff: https://github.com/kamailio/kamailio/commit/187a29601037820fe79f18069caf5032... Patch: https://github.com/kamailio/kamailio/commit/187a29601037820fe79f18069caf5032...
---
diff --git a/modules/app_lua/app_lua_api.c b/modules/app_lua/app_lua_api.c index 5a603df..ca1dee3 100644 --- a/modules/app_lua/app_lua_api.c +++ b/modules/app_lua/app_lua_api.c @@ -549,13 +549,15 @@ int app_lua_return_true(lua_State *L) /** * */ -int app_lua_dostring(struct sip_msg *msg, char *script) +int app_lua_dostring(sip_msg_t *msg, char *script) { int ret; char *txt; + sip_msg_t *bmsg;
LM_DBG("executing Lua string: [[%s]]\n", script); LM_DBG("lua top index is: %d\n", lua_gettop(_sr_L_env.L)); + bmsg = _sr_L_env.msg; _sr_L_env.msg = msg; ret = luaL_dostring(_sr_L_env.L, script); if(ret!=0) @@ -564,20 +566,22 @@ int app_lua_dostring(struct sip_msg *msg, char *script) LM_ERR("error from Lua: %s\n", (txt)?txt:"unknown"); lua_pop (_sr_L_env.L, 1); } - _sr_L_env.msg = 0; + _sr_L_env.msg = bmsg; return (ret==0)?1:-1; }
/** * */ -int app_lua_dofile(struct sip_msg *msg, char *script) +int app_lua_dofile(sip_msg_t *msg, char *script) { int ret; char *txt; + sip_msg_t *bmsg;
LM_DBG("executing Lua file: [[%s]]\n", script); LM_DBG("lua top index is: %d\n", lua_gettop(_sr_L_env.L)); + bmsg = _sr_L_env.msg; _sr_L_env.msg = msg; ret = luaL_dofile(_sr_L_env.L, script); if(ret!=0) @@ -586,17 +590,18 @@ int app_lua_dofile(struct sip_msg *msg, char *script) LM_ERR("error from Lua: %s\n", (txt)?txt:"unknown"); lua_pop(_sr_L_env.L, 1); } - _sr_L_env.msg = 0; + _sr_L_env.msg = bmsg; return (ret==0)?1:-1; }
/** * */ -int app_lua_runstring(struct sip_msg *msg, char *script) +int app_lua_runstring(sip_msg_t *msg, char *script) { int ret; char *txt; + sip_msg_t *bmsg;
if(_sr_L_env.LL==NULL) { @@ -606,6 +611,7 @@ int app_lua_runstring(struct sip_msg *msg, char *script)
LM_DBG("running Lua string: [[%s]]\n", script); LM_DBG("lua top index is: %d\n", lua_gettop(_sr_L_env.LL)); + bmsg = _sr_L_env.msg; _sr_L_env.msg = msg; ret = luaL_dostring(_sr_L_env.LL, script); if(ret!=0) @@ -614,7 +620,7 @@ int app_lua_runstring(struct sip_msg *msg, char *script) LM_ERR("error from Lua: %s\n", (txt)?txt:"unknown"); lua_pop (_sr_L_env.LL, 1); } - _sr_L_env.msg = 0; + _sr_L_env.msg = bmsg; return (ret==0)?1:-1; }
@@ -627,6 +633,7 @@ int app_lua_run_ex(sip_msg_t *msg, char *func, char *p1, char *p2, int n; int ret; char *txt; + sip_msg_t *bmsg;
if(_sr_L_env.LL==NULL) { @@ -676,9 +683,10 @@ int app_lua_run_ex(sip_msg_t *msg, char *func, char *p1, char *p2, } } } + bmsg = _sr_L_env.msg; _sr_L_env.msg = msg; ret = lua_pcall(_sr_L_env.LL, n, 0, 0); - _sr_L_env.msg = 0; + _sr_L_env.msg = bmsg; if(ret!=0) { LM_ERR("error executing: %s (err: %d)\n", func, ret);