diff --git a/src/modules/app_lua/app_lua_sr.c b/src/modules/app_lua/app_lua_sr.c index f6155dc7415..6edba5d7a79 100644 --- a/src/modules/app_lua/app_lua_sr.c +++ b/src/modules/app_lua/app_lua_sr.c @@ -884,7 +884,7 @@ static const luaL_Reg _sr_hdr_Map [] = { /** * */ -static int lua_sr_pv_get (lua_State *L) +static int lua_sr_pv_get_val (lua_State *L, int rmode) { str pvn; pv_spec_t *pvs; @@ -895,35 +895,56 @@ static int lua_sr_pv_get (lua_State *L) env_L = sr_lua_env_get(); pvn.s = (char*)lua_tostring(L, -1); - if(pvn.s==NULL || env_L->msg==NULL) - return 0; + if(pvn.s==NULL || env_L->msg==NULL) { + if(rmode) { + lua_pushlstring(L, "<>", 8); + return 1; + } else { + return 0; + } + } pvn.len = strlen(pvn.s); LM_DBG("pv get: %s\n", pvn.s); pl = pv_locate_name(&pvn); - if(pl != pvn.len) - { + if(pl != pvn.len) { LM_ERR("invalid pv [%s] (%d/%d)\n", pvn.s, pl, pvn.len); - return 0; + if(rmode) { + lua_pushlstring(L, "<>", 8); + return 1; + } else { + return 0; + } } pvs = pv_cache_get(&pvn); - if(pvs==NULL) - { + if(pvs==NULL) { LM_ERR("cannot get pv spec for [%s]\n", pvn.s); - return 0; + if(rmode) { + lua_pushlstring(L, "<>", 8); + return 1; + } else { + return 0; + } } memset(&val, 0, sizeof(pv_value_t)); - if(pv_get_spec_value(env_L->msg, pvs, &val) != 0) - { + if(pv_get_spec_value(env_L->msg, pvs, &val) != 0) { LM_ERR("unable to get pv value for [%s]\n", pvn.s); - return 0; + if(rmode) { + lua_pushlstring(L, "<>", 8); + return 1; + } else { + return 0; + } } - if(val.flags&PV_VAL_NULL) - { - return 0; + if(val.flags&PV_VAL_NULL) { + if(rmode) { + lua_pushlstring(L, "<>", 8); + return 1; + } else { + return 0; + } } - if(val.flags&PV_TYPE_INT) - { + if(val.flags&PV_TYPE_INT) { lua_pushinteger(L, val.ri); return 1; } @@ -931,6 +952,22 @@ static int lua_sr_pv_get (lua_State *L) return 1; } +/** + * + */ +static int lua_sr_pv_get (lua_State *L) +{ + return lua_sr_pv_get_val(L, 0); +} + +/** + * + */ +static int lua_sr_pv_getw (lua_State *L) +{ + return lua_sr_pv_get_val(L, 1); +} + /** * */ @@ -1137,6 +1174,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}, {"seti", lua_sr_pv_seti}, {"sets", lua_sr_pv_sets}, {"unset", lua_sr_pv_unset},