From db2d4a6aad77b8c141232d689842eeecf9f570f7 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Sun, 31 Mar 2013 11:40:42 +0200 Subject: [PATCH] Added keys field to insert the keys used --- ngcp/xavp.lua | 12 ++++++++---- tests/ngcp_xavp.lua | 21 +++++++++++++++------ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/ngcp/xavp.lua b/ngcp/xavp.lua index 2ddf605..f642597 100644 --- a/ngcp/xavp.lua +++ b/ngcp/xavp.lua @@ -16,14 +16,15 @@ NGCPXAvp_MT = { end local t = { - group = group + group = group, + keys = {} } if level == 'callee' then t.level = 1 else t.level = 0 end - NGCPXAvp._create(t.level,group,l) + NGCPXAvp._create(t, t.level,group,l) NGCPXAvp_MT.__call = function(t, key, value) if not key then error("key is empty") @@ -33,8 +34,10 @@ NGCPXAvp_MT = { if not value then return sr.pv.get(id) elseif type(value) == "number" then + table.add(t.keys, key) sr.pv.seti(id, value) elseif type(value) == "string" then + table.add(t.keys, key) sr.pv.sets(id, value) else error("value is not a number or string") @@ -56,7 +59,7 @@ NGCPXAvp_MT = { elseif vtype == 1 then if type(value) == "string" then value = tonumber(value) - end + end sr.pv.seti(id, value) else sr.log("err",string.format("can't set value:%s of type:%d", value, vtype)) @@ -74,7 +77,7 @@ NGCPXAvp_MT = { end end - function NGCPXAvp._create(level, group, l) + function NGCPXAvp:_create(level, group, l) local i, name -- create dummy vars name = string.format("$xavp(%s=>dummy)", group) @@ -83,6 +86,7 @@ NGCPXAvp_MT = { NGCPXAvp._setvalue(name, 0, "caller") -- caller -> [0] for i=1,#l do name = string.format("$xavp(%s[%d]=>%s)", group, level, l[i].attribute) + table.add(self.keys, l[i].attribute) NGCPXAvp._setvalue(name, l[i].type, l[i].value) end end diff --git a/tests/ngcp_xavp.lua b/tests/ngcp_xavp.lua index 811436c..7d8f6c5 100644 --- a/tests/ngcp_xavp.lua +++ b/tests/ngcp_xavp.lua @@ -17,20 +17,20 @@ vals = { }, { id = 2, - uuid = "94023caf-dfba-4f33-8bdb-b613ce627613", - username = "testuser2", + uuid = "ae736f72-21d1-4ea6-a3ea-4d7f56b3887c", + username = "testuser1", domain = "192.168.51.56", - attribute = "account_id", + attribute = "whatever", type = 1, value = 2, last_modified = "1900-01-01 00:00:01" }, { id = 3, - uuid = "94023caf-dfba-4f33-8bdb-b613ce627613", - username = "testuser2", + uuid = "ae736f72-21d1-4ea6-a3ea-4d7f56b3887c", + username = "testuser1", domain = "192.168.51.56", - attribute = "account_id", + attribute = "elsewhere", type = 0, value = "2", last_modified = "1900-01-01 00:00:01" @@ -73,6 +73,15 @@ TestNGCPXAvp = {} --class assertFalse(self.xavp("testid")) assertFalse(sr.pv.get("$xavp(peer[0]=>testid)")) end + + function TestNGCPXAvp:test_keys() + assertItemsEquals(self.xavp.keys, {"account_id","whatever","elsewhere"}) + self.xavp("testid", 1) + assertItemsEquals(self.xavp.keys, {"account_id","whatever","elsewhere","testid"}) + self.xavp:clean() + assertItemsEquals(self.xavp.keys, {"account_id","whatever","elsewhere","testid"}) + end + -- class TestNGCPXAvp ---- Control test output: