Fix log_var function.

Add _str_var and __tostring functions to be able to test the results.
squeeze-backports
Victor Seva 13 years ago
parent 86ba1ec8db
commit 1fdf196a30

@ -24,15 +24,18 @@ NGCPAvp_MT = {
function t.all()
return sr.pv.get("$(avp(" .. id .. ")[*])")
end
NGCPAvp_MT.__tostring = function(t)
local value = sr.pv.get(t.id)
return string.format("%s:%s", t.id, tostring(value))
end
return setmetatable( t, NGCPAvp_MT )
end
function NGCPAvp:log(level)
local value = sr.pv.get(self.id)
if not level then
level = "dbg"
end
sr.log(level, string.format("%s:%s\n", self.id, tostring(value)))
sr.log(level, tostring(self))
end
function NGCPAvp:clean()

@ -368,32 +368,43 @@ end
end
end
function NGCP:_log_var(level, vtype, group)
function NGCP:_str_var(vtype, group)
local _, v, var, vars_index, avp
local output = "{"
vars_index = vtype .. "_" .. group .. "_load"
if self.vars[vars_index] then
for _,v in pairs(self.vars[vars_index]) do
for _,var in pairs(v) do
avp = NGCPAvp:new(var[1])
avp:log(level)
output = output .. tostring(avp) .. ","
end
end
end
output = output .. "}\n"
return output
end
function NGCP:log_var(level, vtype, group)
local vtypes, groups
local _,vt,gr
if not level then
level = "dbg"
end
if not vtype then
if group then
self:_log_var(level, "caller", group)
self:_log_var(level, "callee", group)
else
self:_log_var(level, "caller", "peer")
self:_log_var(level, "callee", "peer")
self:_log_var(level, "caller", "usr")
self:_log_var(level, "callee", "usr")
vtypes = {"caller", "callee"}
else
vtypes = { vtype }
end
if not group then
groups = { "peer", "usr"}
else
groups = { group }
end
for _,vt in pairs(vtypes) do
for _,gr in pairs(groups) do
sr.log(level, self:_str_var(vt, gr))
end
end
end

@ -543,5 +543,10 @@ TestNGCP = {} --class
self.ngcp:log_var(nil, nil, "peer")
self.ngcp:log_var("info", "caller")
end
function TestNGCP:test_str_var()
self:test_caller_usr_load()
assertEquals(self.ngcp:_str_var("caller", "usr"), "{$avp(s:allowed_ips_grp):nil,$avp(s:man_allowed_ips_grp):nil,$avp(s:ignore_allowed_ips):nil,$avp(s:caller_account_id):2,$avp(s:caller_cc):43,$avp(s:caller_ac):1,$avp(s:caller_emergency_cli):nil,$avp(s:caller_emergency_prefix):nil,$avp(s:caller_emergency_suffix):nil,$avp(s:caller_lock):nil,$avp(s:caller_block_override):nil,$avp(s:caller_adm_block_override):nil,$avp(s:caller_allowed_clis):nil,$avp(s:caller_user_cli):nil,$avp(s:caller_block_out_mode):nil,$avp(s:caller_block_out_list):nil,$avp(s:caller_adm_block_out_mode):nil,$avp(s:caller_adm_block_out_list):nil,$avp(s:caller_peer_auth_user):nil,$avp(s:caller_peer_auth_pass):nil,$avp(s:caller_peer_auth_realm):nil,$avp(s:caller_ext_subscriber_id):nil,$avp(s:caller_ext_contract_id):nil,$avp(s:caller_prepaid):nil,$avp(s:caller_ring_group_dest):nil,$avp(s:caller_ring_group_policy):nil,$avp(s:caller_no_nat_sipping):nil,$avp(s:caller_reject_emergency):nil,$avp(s:caller_ncos_id):nil,$avp(s:caller_inbound_upn):from_user,$avp(s:caller_extension_in_npn):nil,$avp(s:caller_inbound_uprn):npn,$avp(s:caller_ipv46_for_rtpproxy):nil,$avp(s:caller_force_outbound_calls_to_peer):nil,$avp(s:caller_use_rtpproxy):nil,$avp(s:rewrite_caller_in_dpid):nil,$avp(s:rewrite_callee_in_dpid):nil,$avp(s:caller_ip_header):P-NGCP-Src-Ip,$avp(s:caller_allow_out_foreign_domain):nil,$avp(s:caller_concurrent_max):nil,$avp(s:caller_concurrent_max_out):nil,$avp(s:caller_concurrent_max_per_account):nil,$avp(s:caller_concurrent_max_out_per_account):nil,$avp(s:caller_sst_enable):no,$avp(s:caller_sst_expires):300,$avp(s:caller_sst_min_timer):90,$avp(s:caller_sst_max_timer):7200,$avp(s:caller_sst_refresh_method):UPDATE_FALLBACK_INVITE,$avp(s:caller_cloud_pbx):nil,}\n")
end
-- class TestNGCP
--EOF

@ -57,5 +57,12 @@ TestNGCPAvp = {} --class
function TestNGCPAvp:test_log()
self.avp:log()
end
function TestNGCPAvp:test_tostring()
self.avp(1)
assertEquals(tostring(self.avp), "$avp(s:testid):1")
self.avp("hola")
assertEquals(tostring(self.avp), "$avp(s:testid):hola")
end
-- class TestNGCPAvp
--EOF
Loading…
Cancel
Save