1136
* creates and push a table to the lua stack with
1137
* the elements of the list
1139
static int lua_sr_push_str_list_table(lua_State *L, struct str_list *list) {
1141
struct str_list *k = list;
1145
lua_pushnumber(L, i);
1146
lua_pushlstring(L, k->s.s, k->s.len);
1147
lua_settable(L, -3);
1154
static int lua_sr_push_xavp_table(lua_State *L, sr_xavp_t *xavp);
1157
* creates and push a table for the key name in xavp
1159
static void lua_sr_push_xavp_name_table(lua_State *L, sr_xavp_t *xavp, str name) {
1161
lua_Number elem = 1;
1162
sr_xavp_t *avp = xavp;
1164
while(avp!=NULL&&!STR_EQ(avp->name,name))
1171
lua_pushnumber(L, elem);
1172
switch(avp->val.type) {
1178
lua_pushnumber(L, i);
1181
lua_pushlstring(L, avp->val.v.s.s, avp->val.v.s.len);
1185
case SR_XTYPE_LLONG:
1188
LM_WARN("XAVP type:%d value not supported\n", avp->val.type);
1191
if(!lua_sr_push_xavp_table(L,avp->val.v.xavp)){
1192
LM_ERR("xavp:%.*s subtable error. Nil value added\n", avp->name.len, avp->name.s);
1197
LM_ERR("xavp:%.*s unknown type: %d. Nil value added\n",
1198
avp->name.len, avp->name.s, avp->val.type);
1204
avp = xavp_get_next(avp);
1206
lua_setfield(L, -2, name.s);
1210
* creates and push a table to the lua stack with
1211
* the elements of the xavp
1213
static int lua_sr_push_xavp_table(lua_State *L, sr_xavp_t *xavp) {
1214
sr_xavp_t *avp = NULL;
1215
struct str_list *keys;
1218
if(xavp->val.type!=SR_XTYPE_XAVP){
1219
LM_ERR("%s not xavp?\n", xavp->name.s);
1222
avp = xavp->val.v.xavp;
1223
keys = xavp_get_list_key_names(xavp);
1230
lua_sr_push_xavp_name_table(L, avp, keys->s);
1241
* creates and push a table to the lua stack with
1242
* only the firsts elements of the xavp
1244
static int lua_sr_push_xavp_table_simple(lua_State *L, sr_xavp_t *xavp) {
1246
sr_xavp_t *avp = NULL;
1248
if(xavp->val.type!=SR_XTYPE_XAVP){
1249
LM_ERR("%s not xavp?\n", xavp->name.s);
1252
avp = xavp->val.v.xavp;
1256
switch(avp->val.type) {
1259
lua_setfield(L, -2, avp->name.s);
1263
lua_pushnumber(L, i);
1264
lua_setfield(L, -2, avp->name.s);
1267
lua_pushlstring(L, avp->val.v.s.s, avp->val.v.s.len);
1268
lua_setfield(L, -2, avp->name.s);
1272
case SR_XTYPE_LLONG:
1275
lua_setfield(L, -2, avp->name.s);
1276
LM_WARN("XAVP type:%d value not supported\n", avp->val.type);
1279
if(!lua_sr_push_xavp_table(L,avp->val.v.xavp)){
1280
LM_ERR("xavp:%.*s subtable error. Nil value added\n", avp->name.len, avp->name.s);
1283
lua_setfield(L, -2, avp->name.s);
1292
* puts a table with content of a xavp
1294
static int lua_sr_xavp_get(lua_State *L)
1298
sr_lua_env_t *env_L;
1302
int simple_flag = 0;
1304
env_L = sr_lua_env_get();
1305
num_param = lua_gettop(L);
1306
if(num_param<2 && num_param>3)
1308
LM_ERR("wrong number of parameters [%d]\n", num_param);
1314
if(!lua_isnumber(L, param))
1316
LM_ERR("invalid int parameter\n");
1319
simple_flag = lua_tointeger(L, param);
1323
if(!lua_isnumber(L, param))
1325
LM_ERR("invalid int parameter\n");
1328
indx = lua_tointeger(L, param);
1331
xavp_name.s = (char*)lua_tostring(L, param);
1332
if(xavp_name.s==NULL || env_L->msg==NULL)
1334
xavp_name.len = strlen(xavp_name.s);
1336
avp = xavp_get_by_index(&xavp_name, indx, NULL);
1338
LM_ERR("can't get xavp:%.*s index:%d\n", xavp_name.len, xavp_name.s, indx);
1343
if (simple_flag != 0)
1345
lua_sr_push_xavp_table_simple(L, avp);
1349
lua_sr_push_xavp_table(L, avp);
1355
* puts a table with the list of keys of the xavp
1357
static int lua_sr_xavp_get_keys (lua_State *L)
1361
sr_lua_env_t *env_L;
1363
struct str_list *keys, *k;
1365
env_L = sr_lua_env_get();
1369
LM_ERR("to few parameters [%d]\n",lua_gettop(L));
1373
if(!lua_isnumber(L, -1))
1375
LM_ERR("invalid int parameter\n");
1378
indx = lua_tointeger(L, -1);
1380
xavp_name.s = (char*)lua_tostring(L, -2);
1381
if(xavp_name.s==NULL || env_L->msg==NULL)
1383
xavp_name.len = strlen(xavp_name.s);
1385
avp = xavp_get_by_index(&xavp_name, indx, NULL);
1387
LM_ERR("can't get xavp:%.*s index:%d\n", xavp_name.len, xavp_name.s, indx);
1391
keys = xavp_get_list_key_names(avp);
1392
lua_sr_push_str_list_table(L, keys);
1405
static const luaL_reg _sr_xavp_Map [] = {
1406
{"get", lua_sr_xavp_get},
1407
{"get_keys", lua_sr_xavp_get_keys},