diff --git a/ngcp/config.lua b/ngcp/config.lua index e0b0220..3dae668 100644 --- a/ngcp/config.lua +++ b/ngcp/config.lua @@ -1,5 +1,5 @@ -- --- Copyright 2015 SipWise Team +-- Copyright 2015-2020 SipWise Team -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -29,7 +29,7 @@ local NGCPConfig = { __class__ = 'NGCPConfig' } local NGCPConfig_MT = { __index = NGCPConfig } - +-- luacheck: globals KSR function NGCPConfig:new() local t = { db_host = "127.0.0.1", @@ -97,11 +97,11 @@ local NGCPConfig_MT = { __index = NGCPConfig } local ok,_ = pcall(check_connection, self.con) if not ok then self.con = nil - KSR.log("dbg", "lost database connection. Reconnecting") + KSR.dbg("lost database connection. Reconnecting\n") end end if not self.con then - KSR.log("dbg","connecting to mysql") + KSR.dbg("connecting to mysql\n") self.con = self.env:connect( self.db_database, self.db_username, self.db_pass, self.db_host, self.db_port) end diff --git a/ngcp/dlgcnt.lua b/ngcp/dlgcnt.lua index f0e1be0..f0c0148 100644 --- a/ngcp/dlgcnt.lua +++ b/ngcp/dlgcnt.lua @@ -1,5 +1,5 @@ -- --- Copyright 2014 SipWise Team +-- Copyright 2014-2020 SipWise Team -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -34,7 +34,7 @@ NGCPDlgCounters_MT.__tostring = function (t) utable.tostring(t.config), utable.tostring(t.central), utable.tostring(t.pair)); end - +-- luacheck: globals KSR function NGCPDlgCounters.new() local t = NGCPDlgCounters.init(); setmetatable( t, NGCPDlgCounters_MT ); @@ -72,7 +72,7 @@ end function NGCPDlgCounters._connect(config) local client = redis.connect(config.host,config.port); client:select(config.db); - KSR.log("dbg", string.format("connected to redis server %s:%d at %s\n", + KSR.dbg(string.format("connected to redis server %s:%d at %s\n", config.host, config.port, config.db)); return client; end @@ -81,12 +81,14 @@ end local res = self.central:decr(key); if res == 0 then self.central:del(key); - KSR.log("dbg", string.format("central:del[%s] counter is 0\n", key)); + KSR.dbg(string.format("central:del[%s] counter is 0\n", key)); elseif res < 0 and not self.config.allow_negative then self.central:del(key); - KSR.log("warn", string.format("central:del[%s] counter was %s\n", key, tostring(res))); + KSR.warn(string.format("central:del[%s] counter was %s\n", + key, tostring(res))); else - KSR.log("dbg", string.format("central:decr[%s]=>[%s]\n", key, tostring(res))); + KSR.dbg(string.format("central:decr[%s]=>[%s]\n", + key, tostring(res))); end return res; end @@ -116,15 +118,17 @@ end self.central = self._connect(self.config.central); end local res = self.central:incr(key); - KSR.log("dbg", string.format("central:incr[%s]=>%s\n", key, tostring(res))); + KSR.dbg(string.format("central:incr[%s]=>%s\n", key, tostring(res))); if not self._test_connection(self.pair) then self.pair = self._connect(self.config.pair); end if self.config.check_pair_dup and self:is_in_set(callid, key) then - KSR.log("warn", string.format("pair:check_pair_dup[%s]=>[%s] already there!\n", callid, key)); + local msg = "pair:check_pair_dup[%s]=>[%s] already there!\n"; + KSR.warn(msg:format(callid, key)); end local pos = self.pair:lpush(callid, key); - KSR.log("dbg", string.format("pair:lpush[%s]=>[%s] %s\n", callid, key, tostring(pos))); + KSR.dbg(string.format("pair:lpush[%s]=>[%s] %s\n", + callid, key, tostring(pos))); end function NGCPDlgCounters:del_key(callid, key) @@ -133,11 +137,12 @@ end end local num = self.pair:lrem(callid, 1, key); if num == 0 then - KSR.log("dbg", string.format("pair:lrem[%s]=>[%s] no such key found in list, skipping decrement", - callid, key)); + local msg = "pair:lrem[%s]=>[%s] no such key found in list, " .. + "skipping decrement\n"; + KSR.dbg(msg:format(callid, key)); return false; end - KSR.log("dbg", string.format("pair:lrem[%s]=>[%s] %d\n", callid, key, num)); + KSR.dbg(string.format("pair:lrem[%s]=>[%s] %d\n", callid, key, num)); if not self._test_connection(self.central) then self.central = self._connect(self.config.central); end @@ -157,7 +162,7 @@ end end while key do self:_decr(key); - KSR.log("dbg", string.format("pair:lpop[%s]=>[%s]\n", callid, key)); + KSR.dbg(string.format("pair:lpop[%s]=>[%s]\n", callid, key)); key = self.pair:lpop(callid); end end @@ -167,7 +172,7 @@ end self.central = self._connect(self.config.central); end local res = self.central:get(key); - KSR.log("dbg", string.format("central:get[%s]=>%s\n", key, tostring(res))); + KSR.dbg(string.format("central:get[%s]=>%s\n", key, tostring(res))); return res; end -- class diff --git a/ngcp/dlglist.lua b/ngcp/dlglist.lua index a4c800b..9b1ed55 100644 --- a/ngcp/dlglist.lua +++ b/ngcp/dlglist.lua @@ -1,5 +1,5 @@ -- --- Copyright 2015 SipWise Team +-- Copyright 2015-2020 SipWise Team -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -34,7 +34,7 @@ NGCPDlgList_MT.__tostring = function (t) utable.tostring(t.config), utable.tostring(t.central), utable.tostring(t.pair)); end - +-- luacheck: globals KSR function NGCPDlgList.new() local t = NGCPDlgList.init(); setmetatable( t, NGCPDlgList_MT ); @@ -71,7 +71,7 @@ end local function _connect(config) local client = redis.connect(config.host,config.port); client:select(config.db); - KSR.log("dbg", string.format("connected to redis server %s:%d at %s\n", + KSR.dbg(string.format("connected to redis server %s:%d at %s\n", config.host, config.port, config.db)); return client; end @@ -81,9 +81,9 @@ end local num = self.central:llen(key); if num == 0 then self.central:del(key); - KSR.log("dbg", string.format("central[%s] is empty. Removed\n", key)); + KSR.dbg(string.format("central[%s] is empty. Removed\n", key)); else - KSR.log("dbg", string.format("central:lrem[%s]=>[%s]\n", key, tostring(num))); + KSR.dbg(string.format("central:lrem[%s]=>[%s]\n", key, tostring(num))); end return num; end @@ -113,15 +113,15 @@ end self.central = _connect(self.config.central); end local pos = self.central:rpush(key, callid); - KSR.log("dbg", string.format("central:rpush[%s]=>[%s] %s\n", key, callid, tostring(pos))); + KSR.dbg(string.format("central:rpush[%s]=>[%s] %s\n", key, callid, tostring(pos))); if not _test_connection(self.pair) then self.pair = _connect(self.config.pair); end if self.config.check_pair_dup and self:is_in_set(callid, key) then - KSR.log("warn", string.format("pair:check_pair_dup[%s]=>[%s] already there!\n", callid, key)); + KSR.warn(string.format("pair:check_pair_dup[%s]=>[%s] already there!\n", callid, key)); end pos = self.pair:lpush("list:"..callid, key); - KSR.log("dbg", string.format("pair:lpush[list:%s]=>[%s] %s\n", callid, key, tostring(pos))); + KSR.dbg(string.format("pair:lpush[list:%s]=>[%s] %s\n", callid, key, tostring(pos))); end function NGCPDlgList:del(callid, key) @@ -130,10 +130,10 @@ end end local num = self.pair:lrem("list:"..callid, 0, key); if num == 0 then - KSR.log("dbg", string.format("pair:lrem[list:%s] no such key %s found in list", callid, key)); + KSR.dbg(string.format("pair:lrem[list:%s] no such key %s found in list\n", callid, key)); return false; end - KSR.log("dbg", string.format("pair:lrem[%s]=>[%s] %d\n", callid, key, num)); + KSR.dbg(string.format("pair:lrem[%s]=>[%s] %d\n", callid, key, num)); if not _test_connection(self.central) then self.central = _connect(self.config.central); end @@ -154,7 +154,7 @@ end end while key do self:_del(key, callid); - KSR.log("dbg", string.format("pair:lpop[%s]=>[%s]\n", callid, key)); + KSR.dbg(string.format("pair:lpop[%s]=>[%s]\n", callid, key)); key = self.pair:lpop("list:"..callid); end end diff --git a/ngcp/loop.lua b/ngcp/loop.lua index e7a73b9..94f93e4 100644 --- a/ngcp/loop.lua +++ b/ngcp/loop.lua @@ -1,5 +1,5 @@ -- --- Copyright 2016 SipWise Team +-- Copyright 2016-2020 SipWise Team -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -33,7 +33,7 @@ NGCPLoop_MT.__tostring = function (t) return string.format("config:%s", utable.tostring(t.config)); end - +-- luacheck: globals KSR function NGCPLoop.new() local t = NGCPLoop.init(); setmetatable( t, NGCPLoop_MT ); @@ -63,7 +63,7 @@ end local function _connect(config) local client = redis.connect(config.host,config.port); client:select(config.db); - KSR.log("dbg", string.format("connected to redis server %s:%d at %s\n", + KSR.dbg(string.format("connected to redis server %s:%d at %s\n", config.host, config.port, config.db)); return client; end @@ -72,12 +72,14 @@ end if not _test_connection(self.client) then self.client = _connect(self.config); end - local key = string.format("%s;%s;%s", tostring(fu), tostring(tu), tostring(ru)); + local key = string.format("%s;%s;%s", + tostring(fu), tostring(tu), tostring(ru)); local res = self.client:incr(key); if res == 1 then self.client:expire(key, self.config.expire); end - KSR.log("dbg", string.format("[%s]=>[%s] expires:%s\n", key, tostring(res), tostring(self.config.expires))); + KSR.dbg(string.format("[%s]=>[%s] expires:%s\n", + key, tostring(res), tostring(self.config.expires))); return res; end diff --git a/ngcp/pref.lua b/ngcp/pref.lua index d6fd27c..5075cbe 100644 --- a/ngcp/pref.lua +++ b/ngcp/pref.lua @@ -34,7 +34,7 @@ function NGCPPrefs.__tostring(self) end return output end - +-- luacheck: globals KSR function NGCPPrefs:init() for _,v in pairs(self.levels) do NGCPXAvp.init(v, self.group) @@ -49,8 +49,8 @@ function NGCPPrefs:_defaults() local group = self.group:gsub('_prefs','') local defaults = self.config:get_defaults(group) local keys = {} - - KSR.dbg(string.format("defaults[%s]:%s", group, utable.tostring(defaults))) + local msg = "defaults[%s]:%s\n" + KSR.dbg(msg:format(group, utable.tostring(defaults))) for k,_ in pairs(defaults) do table.insert(keys, k) @@ -66,7 +66,7 @@ function NGCPPrefs:_set_xavp(level, cur, query) if utable.size(row) > 0 then while utable.size(row) > 0 do - KSR.dbg(string.format("result:%s row:%s", + KSR.dbg(string.format("result:%s row:%s\n", utable.tostring(result), utable.tostring(row))) table.insert(result, row) utable.add(keys, row.attribute) @@ -74,13 +74,13 @@ function NGCPPrefs:_set_xavp(level, cur, query) row = cur:fetch({}, "a") end else - KSR.dbg(string.format("no results for query:%s", query)) + KSR.dbg(string.format("no results for query:%s\n", query)) end cur:close() local xavp = self:xavp(level, result) for k,v in pairs(defaults) do - KSR.dbg(string.format("setting default[%s]:%s", k, tostring(v))) + KSR.dbg(string.format("setting default[%s]:%s\n", k, tostring(v))) xavp(k, v) end return keys diff --git a/ngcp/recentcalls.lua b/ngcp/recentcalls.lua index 3c74bfc..b9aa3c5 100644 --- a/ngcp/recentcalls.lua +++ b/ngcp/recentcalls.lua @@ -1,5 +1,5 @@ -- --- Copyright 2015 SipWise Team +-- Copyright 2015-2020 SipWise Team -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -32,7 +32,7 @@ NGCPRecentCalls_MT.__tostring = function (t) return string.format("config:%s central:%s", utable.tostring(t.config), utable.tostring(t.central)) end - +-- luacheck: globals KSR function NGCPRecentCalls.new() local t = NGCPRecentCalls.init(); setmetatable( t, NGCPRecentCalls_MT ) @@ -64,7 +64,7 @@ end function NGCPRecentCalls._connect(config) local client = redis.connect(config.host,config.port) client:select(config.db) - KSR.log("info", string.format("connected to redis server %s:%d at %s\n", + KSR.info(string.format("connected to redis server %s:%d at %s\n", config.host, config.port, config.db)) return client end @@ -87,14 +87,14 @@ end if res then self.central:expire(key, self.config.expire) end - KSR.log("info", string.format("central:hset[%s]=>[%s] callid: %s uuid: %s " .. - "start_time: %s duration: %d caller: %s callee: %s source: %s expire: %d\n", - key, tostring(res), - callid, uuid, - start_time, duration, - caller, callee, - source, - self.config.expire)) + local msg = "central:hset[%s]=>[%s] callid: %s uuid: %s " .. + "start_time: %s duration: %d caller: %s callee: %s source: %s expire: %d\n" + KSR.info(msg:format(key, tostring(res), + callid, uuid, + start_time, duration, + caller, callee, + source, + self.config.expire)) return res end @@ -107,10 +107,10 @@ end if res then self.central:expire(key, self.config.out_expire) end - KSR.log("info", string.format("central:hset[%s]=>[%s] %s: %s expire: %d\n", - key, tostring(res), - element, tostring(value), - self.config.out_expire)) + KSR.info(string.format("central:hset[%s]=>[%s] %s: %s expire: %d\n", + key, tostring(res), + element, tostring(value), + self.config.out_expire)) return res end @@ -121,7 +121,7 @@ end local res = self.central:hgetall(key) if res then - KSR.log("info", string.format("central:hget[%s]=>[%s]\n", + KSR.info(string.format("central:hget[%s]=>[%s]\n", key, tostring(res[element]))) return res[element] @@ -136,7 +136,7 @@ end end self.central:del(key) - KSR.log("info", string.format("central:del[%s] removed\n", key)); + KSR.info(string.format("central:del[%s] removed\n", key)); return 0 end diff --git a/ngcp/rp.lua b/ngcp/rp.lua index 11da668..07780ce 100644 --- a/ngcp/rp.lua +++ b/ngcp/rp.lua @@ -123,7 +123,7 @@ function NGCPRealPrefs:_usr_load(level, keys) if value then real_values[v] = value else - KSR.err(string.format("key:%s not in user, profile or domain", v)) + KSR.err(string.format("key:%s not in user, profile or domain\n", v)) end end local real_keys = {} diff --git a/ngcp/xavp.lua b/ngcp/xavp.lua index 8e5fcb9..d2c4234 100644 --- a/ngcp/xavp.lua +++ b/ngcp/xavp.lua @@ -1,5 +1,5 @@ -- --- Copyright 2013-2015 SipWise Team +-- Copyright 2013-2020 SipWise Team -- -- This program is free software: you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -27,6 +27,7 @@ local NGCPXAvp = { local NGCPXAvp_MT = { __index = NGCPXAvp } +-- luacheck: globals KSR function NGCPXAvp:new(level,group,l) local t = NGCPXAvp.init(level,group,l) NGCPXAvp_MT.__call = function(s, key, value) @@ -34,16 +35,15 @@ local NGCPXAvp_MT = { error("key is empty") end local id = string.format("$xavp(%s[0]=>%s)", s.name, key) - --print(string.format("id:%s", id)) if not value then return KSR.pv.get(id) elseif type(value) == "number" then utable.add(s.keys, key) - --sr.log("dbg", string.format("seti: [%s]:%d", id, value)) + --KSR.dbg(string.format("seti: [%s]:%d\n", id, value)) KSR.pv.seti(id, value) elseif type(value) == "string" then utable.add(s.keys, key) - --sr.log("dbg", string.format("sets: [%s]:%s", id, value)) + --KSR.dbg(string.format("sets: [%s]:%s\n", id, value)) KSR.pv.sets(id, value) elseif type(value) == "table" then utable.add(s.keys, key) @@ -68,7 +68,7 @@ local NGCPXAvp_MT = { if ll then output = utable.tostring(ll) end - KSR.log("dbg", string.format("output:%s", output)) + KSR.dbg(string.format("output:%s\n", output)) return output end setmetatable( t, NGCPXAvp_MT ) @@ -100,7 +100,7 @@ local NGCPXAvp_MT = { vtype = tonumber(vtype) end if vtype == 0 then - KSR.log("dbg",string.format("sr.pv.sets->%s:%s", id, value)) + KSR.dbg(string.format("KSR.pv.sets->%s:%s\n", id, value)) if type(value) == 'number' then value = tostring(value) end @@ -111,7 +111,7 @@ local NGCPXAvp_MT = { end KSR.pv.seti(id, value) else - KSR.log("err",string.format("can't set value:%s of type:%s", + KSR.err(string.format("can't set value:%s of type:%s\n", tostring(value), tostring(vtype))) end if value and id then @@ -120,9 +120,9 @@ local NGCPXAvp_MT = { if type(check) == 'table' then utable.tostring(check) end - else + else --error(string.format("%s:nil", id)) - KSR.log("err", string.format("%s:nil", id)) + KSR.err(string.format("%s:nil\n", id)) end end end @@ -131,7 +131,8 @@ local NGCPXAvp_MT = { local name = string.format("$xavp(%s=>dummy)", self.name) if not KSR.pv.get(name) then NGCPXAvp._setvalue(name, 0, self.level) - KSR.log("dbg",string.format("%s created with dummy value:%s", name, self.level)) + KSR.dbg(string.format("%s created with dummy value:%s\n", + name, self.level)) end for i=1,#l do name = string.format("$xavp(%s[0]=>%s)", tostring(self.name), tostring(l[i].attribute))