Module: kamailio Branch: master Commit: b98cb43b1ea33706fe133f6585c0705892663ae6 URL: https://github.com/kamailio/kamailio/commit/b98cb43b1ea33706fe133f6585c0705892663ae6
Author: Daniel-Constantin Mierla <mico...@gmail.com> Committer: Daniel-Constantin Mierla <mico...@gmail.com> Date: 2018-08-24T08:20:17+02:00 app_lua: kemi - exported KSR.pv.getw("$...") - get the value of the pseudo-variable if it is not $null and the empty string ("") if it is $null --- Modified: src/modules/app_lua/app_lua_sr.c --- Diff: https://github.com/kamailio/kamailio/commit/b98cb43b1ea33706fe133f6585c0705892663ae6.diff Patch: https://github.com/kamailio/kamailio/commit/b98cb43b1ea33706fe133f6585c0705892663ae6.patch --- diff --git a/src/modules/app_lua/app_lua_sr.c b/src/modules/app_lua/app_lua_sr.c index 4414bd83a2..dc2aa8644f 100644 --- a/src/modules/app_lua/app_lua_sr.c +++ b/src/modules/app_lua/app_lua_sr.c @@ -900,9 +900,12 @@ static int lua_sr_pv_get_val (lua_State *L, int rmode) pvn.s = (char*)lua_tostring(L, -1); if(pvn.s==NULL || env_L->msg==NULL) { - if(rmode) { + if(rmode==1) { lua_pushlstring(L, "<<null>>", 8); return 1; + } else if(rmode==2) { + lua_pushlstring(L, "", 0); + return 1; } else { return 0; } @@ -913,9 +916,12 @@ static int lua_sr_pv_get_val (lua_State *L, int rmode) pl = pv_locate_name(&pvn); if(pl != pvn.len) { LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len); - if(rmode) { + if(rmode==1) { lua_pushlstring(L, "<<null>>", 8); return 1; + } else if(rmode==2) { + lua_pushlstring(L, "", 0); + return 1; } else { return 0; } @@ -923,9 +929,12 @@ static int lua_sr_pv_get_val (lua_State *L, int rmode) pvs = pv_cache_get(&pvn); if(pvs==NULL) { LM_ERR("cannot get pv spec for [%s]\n", pvn.s); - if(rmode) { + if(rmode==1) { lua_pushlstring(L, "<<null>>", 8); return 1; + } else if(rmode==2) { + lua_pushlstring(L, "", 0); + return 1; } else { return 0; } @@ -933,17 +942,23 @@ static int lua_sr_pv_get_val (lua_State *L, int rmode) memset(&val, 0, sizeof(pv_value_t)); if(pv_get_spec_value(env_L->msg, pvs, &val) != 0) { LM_ERR("unable to get pv value for [%s]\n", pvn.s); - if(rmode) { + if(rmode==1) { lua_pushlstring(L, "<<null>>", 8); return 1; + } else if(rmode==2) { + lua_pushlstring(L, "", 0); + return 1; } else { return 0; } } if(val.flags&PV_VAL_NULL) { - if(rmode) { + if(rmode==1) { lua_pushlstring(L, "<<null>>", 8); return 1; + } else if(rmode==2) { + lua_pushlstring(L, "", 0); + return 1; } else { return 0; } @@ -972,6 +987,14 @@ static int lua_sr_pv_getw (lua_State *L) return lua_sr_pv_get_val(L, 1); } +/** + * + */ +static int lua_sr_pv_gete (lua_State *L) +{ + return lua_sr_pv_get_val(L, 2); +} + /** * */ @@ -1179,6 +1202,7 @@ static int lua_sr_pv_is_null (lua_State *L) static const luaL_Reg _sr_pv_Map [] = { {"get", lua_sr_pv_get}, {"getw", lua_sr_pv_getw}, + {"gete", lua_sr_pv_gete}, {"seti", lua_sr_pv_seti}, {"sets", lua_sr_pv_sets}, {"unset", lua_sr_pv_unset}, _______________________________________________ Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev