TT#109103 prefs: add support for blob type

* final value is fetched from provisioning using pref value as id
* config: list of preferences needed to be loaded by kamailio
  so we wont load unnecessary data into shared memory

Change-Id: I92e4bbfbe7ba55a06e79384aaa0d792556a39e22
mr9.4
Victor Seva 4 years ago
parent 80625d3096
commit 13fede9852

@ -72,6 +72,11 @@ local NGCPConfig_MT = { __index = NGCPConfig }
ext_contract_id = "",
ringtimeout = 180,
}
},
-- blob prefs to be loaded automaticaly
blob_prefs = {
emergency_provider_info = true,
emergency_location_object = true,
}
}
setmetatable( t, NGCPConfig_MT )

@ -1,5 +1,5 @@
--
-- Copyright 2013-2020 SipWise Team <development@sipwise.com>
-- Copyright 2013-2021 SipWise Team <development@sipwise.com>
--
-- 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
@ -25,6 +25,7 @@ local NGCPXAvp = require 'ngcp.xavp'
local NGCPPrefs = utils.inheritsFrom()
NGCPPrefs.__class__ = 'NGCPPrefs'
NGCPPrefs.levels = {"caller", "callee"}
NGCPPrefs.query_blob = "SELECT * FROM provisioning.voip_%s_blob WHERE id = %s"
function NGCPPrefs.__tostring(self)
local output, msg = '', "%s_%s:%s\n"
@ -58,6 +59,37 @@ function NGCPPrefs:_defaults()
return keys, defaults
end
function NGCPPrefs:pref_is_blob(attribute, value_type)
local vtype = value_type
if type(value_type) == "string" then
vtype = tonumber(value_type)
end
if vtype == 2 then
if self.config.blob_prefs[attribute] then return true end
KSR.dbg(string.format("skip load of blob value of attribute:%s\n",
attribute))
end
return false
end
function NGCPPrefs:_get_blob(blob_id)
local result
local con = assert (self.config:getDBConnection())
local query = self.query_blob:format(self.db_table, blob_id)
local cur = assert (con:execute(query))
local row = cur:fetch({}, "a")
if utable.size(row) > 0 then
KSR.dbg(string.format("row content_type:%s\n", row.content_type))
result = row.value
else
KSR.dbg(string.format("no results for query:%s\n", query))
end
cur:close()
return result
end
function NGCPPrefs:_set_xavp(level, cur, query)
local result = {}
local row = cur:fetch({}, "a")
@ -66,8 +98,12 @@ 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\n",
utable.tostring(result), utable.tostring(row)))
if self:pref_is_blob(row.attribute, row.type) then
row.value = self:_get_blob(row.value)
row.type = 0
end
KSR.dbg(string.format("row attribute:%s\n",
tostring(row.attribute)))
table.insert(result, row)
utable.add(keys, row.attribute)
defaults[row.attribute] = nil

@ -1,5 +1,5 @@
--
-- Copyright 2013-2020 SipWise Team <development@sipwise.com>
-- Copyright 2013-2021 SipWise Team <development@sipwise.com>
--
-- 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
@ -28,6 +28,7 @@ KSR = ksrMock.new()
local mc,env,con
local dp_vars = DPFetch:new()
local bp_vars = require 'tests_v.bp_vars'
package.loaded.luasql = nil
package.preload['luasql.mysql'] = function ()
@ -186,5 +187,27 @@ TestNGCPDomainPrefs = {} --class
caller_xavp("otherfoo","foo")
lu.assertEquals(tostring(self.d), 'caller_dom_prefs:{other={1},otherfoo={"foo"},dummy={"caller"}}\ncallee_dom_prefs:{dummy={"callee"},testid={1},foo={"foo"}}\n')
end
function TestNGCPDomainPrefs:test_caller_load_blob()
lu.assertNotNil(self.d.config)
con:execute("SELECT * FROM dom_preferences WHERE domain ='192.168.51.57'") ;mc :returns(self.cur)
self.cur:fetch(mc.ANYARGS) ;mc :returns(dp_vars:val("d_192_168_51_57"))
con:execute("SELECT * FROM provisioning.voip_dom_preferences_blob WHERE id = 2") ;mc :returns(self.cur)
self.cur:fetch(mc.ANYARGS) ;mc :returns(bp_vars[2])
self.cur:close()
self.cur:fetch(mc.ANYARGS) ;mc :returns(nil)
self.cur:close()
mc:replay()
local keys = self.d:caller_load("192.168.51.57")
mc:verify()
lu.assertTrue(utable.contains(keys, "emergency_provider_info"))
lu.assertStrMatches(
KSR.pv.get("$xavp(caller_dom_prefs=>emergency_provider_info)"),
'^<.xml.+'
)
end
-- class TestNGCPDomainPrefs
--EOF

@ -22,6 +22,7 @@ local lemock = require('lemock')
local utils = require 'ngcp.utils'
local utable = utils.table
local UPFetch = require 'tests_v.up_vars'
local bp_vars = require 'tests_v.bp_vars'
local ksrMock = require 'mocks.ksr'
KSR = ksrMock.new()
@ -247,4 +248,39 @@ TestNGCPUserPrefs = {} --class
lu.assertEquals(self.d:__tostring(), expected)
lu.assertEquals(tostring(self.d), expected)
end
function TestNGCPUserPrefs:test_callee_load_blob()
lu.assertNotNil(self.d.config)
con:execute("SELECT * FROM usr_preferences WHERE uuid ='b3431971-79ab-466e-adbb-81d92a9c94fa' ORDER BY id DESC") ;mc :returns(self.cur)
self.cur:fetch(mc.ANYARGS) ;mc :returns(up_vars:val("b3431971_79ab_466e_adbb_81d92a9c94fa"))
self.cur:fetch(mc.ANYARGS) ;mc :returns(up_vars:val("b3431971_79ab_466e_adbb_81d92a9c94fa"))
con:execute("SELECT * FROM provisioning.voip_usr_preferences_blob WHERE id = 1") ;mc :returns(self.cur)
self.cur:fetch(mc.ANYARGS) ;mc :returns(bp_vars[1])
self.cur:close()
self.cur:fetch(mc.ANYARGS) ;mc :returns(nil)
self.cur:close()
mc:replay()
local keys = self.d:callee_load("b3431971-79ab-466e-adbb-81d92a9c94fa")
mc:verify()
local lkeys = {
"ext_subscriber_id",
"ringtimeout",
"account_id",
"ext_contract_id",
"emergency_location_format",
"emergency_location_object"
}
lu.assertItemsEquals(keys, lkeys)
lu.assertEquals(
KSR.pv.get("$xavp(callee_usr_prefs=>emergency_location_format)"),
"PIDF-LO"
)
lu.assertStrMatches(
KSR.pv.get("$xavp(callee_usr_prefs=>emergency_location_object)"),
'^<.xml.+'
)
end
-- class TestNGCPUserPrefs

@ -0,0 +1,100 @@
--
-- Copyright 2021 SipWise Team <development@sipwise.com>
--
-- 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
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This package is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
-- .
-- On Debian systems, the complete text of the GNU General
-- Public License version 3 can be found in "/usr/share/common-licenses/GPL-3".
--
local bp_vars = {
{
id = 1,
preference_id = 14,
content_type = 'application/xml',
value = [[
<?xml version="1.0" encoding="UTF-8"?>
<presence
xmlns="urn:ietf:params:xml:ns:pidf"
xmlns:gp="urn:ietf:params:xml:ns:pidf:geopriv10"
xmlns:gbp="urn:ietf:params:xml:ns:pidf:geopriv10:basicPolicy"
xmlns:dm="urn:ietf:params:xml:ns:pidf:data-model"
xmlns:cl="urn:ietf:params:xml:ns:pidf:geopriv10:civicAddr"
xmlns:gml="http://www.opengis.net/gml"
entity="pres:alice@atlanta.example.com">
<dm:device id="target123-1">
<gp:geopriv>
<gp:location-info>
<gml:location>
<gml:Point srsName="urn:ogc:def:crs:EPSG::4326">
<gml:pos>32.86726 -97.16054</gml:pos>
</gml:Point>
</gml:location>
</gp:location-info>
<gp:usage-rules>
<gbp:retransmission-allowed>false
</gbp:retransmission-allowed>
<gbp:retention-expiry>2010-11-14T20:00:00Z
</gbp:retention-expiry>
</gp:usage-rules>
<gp:method>802.11</gp:method>
</gp:geopriv>
<dm:deviceID>mac:1234567890ab</dm:deviceID>
<dm:timestamp>2010-11-04T20:57:29Z</dm:timestamp>
</dm:device>
<dm:person id="target123">
<gp:geopriv>
<gp:location-info>
<cl:civicAddress>
<cl:country>US</cl:country>
<cl:A1>Texas</cl:A1>
<cl:A3>Colleyville</cl:A3>
<cl:RD>Treemont</cl:RD>
<cl:STS>Circle</cl:STS>
<cl:HNO>3913</cl:HNO>
<cl:FLR>1</cl:FLR>
<cl:NAM>Haley's Place</cl:NAM>
<cl:PC>76034</cl:PC>
</cl:civicAddress>
</gp:location-info>
<gp:usage-rules>
<gbp:retransmission-allowed>false
</gbp:retransmission-allowed>
<gbp:retention-expiry>2010-11-14T20:00:00Z
</gbp:retention-expiry>
</gp:usage-rules>
<gp:method>triangulation</gp:method>
</gp:geopriv>
<dm:timestamp>2010-11-04T12:28:04Z</dm:timestamp>
</dm:person>
</presence>
]]
},
{
id = 2,
preference_id = 2,
content_type = 'application/xml',
value = [[
<?xml version="1.0" encoding="UTF-8"?>
<emergencyCall.ProviderInfo xmlns="urn:ietf:params:xml:ns:emergencyCall.ProviderInfo">
<DataProviderString>Telekom Deutschland</DataProviderString>
<ProviderID>D124</ProviderID>
<contactURI>sip:+492281234567@t-mobile.de;user=phone</contactURI>
<ProviderIDSeries>BNetzA</ProviderIDSeries>
</emergencyCall.ProviderInfo>
]]
}
}
return bp_vars

@ -152,6 +152,18 @@ local dp_vars = {
value = "4",
last_modified = "1900-01-01 00:00:01"
}
},
d_192_168_51_57 = {
{
id = 14,
uuid = "",
username = "0",
domain = "192.168.51.57",
attribute = "emergency_provider_info",
type = 2,
value = 2,
last_modified = "1900-01-01 00:00:01"
},
}
}

@ -133,6 +133,28 @@ local up_vars = {
value = "no",
last_modified = "1900-01-01 00:00:01"
},
},
b3431971_79ab_466e_adbb_81d92a9c94fa = {
{
id = 1,
uuid = "b3431971-79ab-466e-adbb-81d92a9c94fa",
username = "testuser3",
domain = "192.168.51.57",
attribute = "emergency_location_format",
type = 0,
value = "PIDF-LO",
last_modified = "1900-01-01 00:00:01"
},
{
id = 2,
uuid = "b3431971-79ab-466e-adbb-81d92a9c94fa",
username = "testuser3",
domain = "192.168.51.57",
attribute = "emergency_location_object",
type = 2,
value = 1,
last_modified = "1900-01-01 00:00:01"
},
}
}

Loading…
Cancel
Save