diff --git a/ngcp/ngcp.lua b/ngcp/ngcp.lua index aed70f5..9f06014 100644 --- a/ngcp/ngcp.lua +++ b/ngcp/ngcp.lua @@ -326,6 +326,36 @@ NGCP_MT = { __index = NGCP } return unique_keys end + function NGCP:log_pref(level, vtype) + local _,pref,xavp,xavp_log + + if not level then + level = "dbg" + end + + if not vtype then + for _,pref in pairs(self.prefs) do + xavp = pref:xavp("caller") + xavp_log = tostring(xavp) + sr.log(level, string.format("%s:%s\n", xavp.name, xavp_log)) + xavp = pref:xavp("callee") + xavp_log = tostring(xavp) + sr.log(level, string.format("%s:%s\n", xavp.name, xavp_log)) + end + else + if self.prefs[vtype] then + xavp = self.prefs[vtype]:xavp("caller") + xavp_log = tostring(xavp) + sr.log(level, string.format("%s:%s\n", xavp.name, xavp_log)) + xavp = self.prefs[vtype]:xavp("callee") + xavp_log = tostring(xavp) + sr.log(level, string.format("%s:%s\n", xavp.name, xavp_log)) + else + error(string.format("there is no prefs for %s", vtype)) + end + end + end + function NGCP:clean_vars(vtype, group) local _, v, var, vars_index, avp vars_index = vtype .. "_" .. group .. "_load" diff --git a/tests/ngcp.lua b/tests/ngcp.lua index 4dd1321..94f0149 100644 --- a/tests/ngcp.lua +++ b/tests/ngcp.lua @@ -75,6 +75,19 @@ TestNGCP = {} --class assertEquals(sr.pv.get("$xavp(callee_real_prefs=>dummy)"),"callee") end + function TestNGCP:test_log_pref() + self.ngcp:log_pref() + assertError(self.ngcp.log_pref, self.ngcp, "dbg", "foo_var") + end + + function TestNGCP:test_log_pref_info() + self.ngcp:log_pref("info") + end + + function TestNGCP:test_log_pref_peer() + self.ngcp:log_pref("dbg", "peer") + end + function TestNGCP:test_caller_usr_load_empty() assertEquals(self.ngcp:caller_usr_load(), {}) end