@ -9,7 +9,7 @@ module:depends("sipwise_vcard_cusax");
module : depends ( " sipwise_pushd_blocking " ) ;
local datamanager = require " util.datamanager " ;
local mod_sql = module : require ( " sql " ) ;
local sql = require " util.sql " ;
local format = string.format ;
local jid_split = require " util.jid " . split ;
local jid_bare = require " util.jid " . bare ;
@ -36,13 +36,6 @@ local pushd_config = {
msg_sound = ' incoming_message.caf ' ,
muc_config = muc_config
} ;
local sql_config = {
driver = " MySQL " ,
database = " provisioning " ,
username = " prosody " ,
password = " PW_PROSODY " ,
host = " localhost "
} ;
local push_usr_query = [ [
SELECT vp.attribute , vup.value FROM provisioning.voip_preferences vp
@ -73,8 +66,17 @@ WHERE vp.attribute = 'mobile_push_silent_list'
AND vup.value = ? ;
] ] ;
local default_params = module : get_option ( " sql " ) ;
local engine ;
-- Reconnect to DB if necessary
local function reconect_check ( )
if not engine.conn : ping ( ) then
engine.conn = nil ;
engine : connect ( ) ;
end
end
-- luacheck: ignore request
local function process_response ( response , code , request )
if code >= 200 and code < 299 then
@ -87,11 +89,7 @@ local function process_response(response, code, request)
end
local function push_silent ( username , domain , other )
-- Reconnect to DB if necessary
if not engine.conn : ping ( ) then
engine.conn = nil ;
engine : connect ( ) ;
end
reconect_check ( ) ;
for row in engine : select ( push_silent_query , username , domain , other ) do
if row [ 1 ] == " 1 " then
module : log ( " debug " , " silent push preference mobile_push_silent_list matches " ) ;
@ -102,11 +100,7 @@ local function push_silent(username, domain, other)
end
local function push_enable ( username , domain )
-- Reconnect to DB if necessary
if not engine.conn : ping ( ) then
engine.conn = nil ;
engine : connect ( ) ;
end
reconect_check ( ) ;
for row in engine : select ( push_dom_query , domain ) do
if row [ 2 ] == " 1 " then
module : log ( " debug " , " domain mobile_push_enable pref set " ) ;
@ -561,13 +555,27 @@ end
module : hook ( " message/bare " , handle_msg , 20 ) ;
module : hook ( " message/offline/handle " , handle_offline , 20 ) ;
local function normalize_params ( params )
assert ( params.driver and params.database ,
" Configuration error: Both the SQL driver and the database need to be specified " ) ;
return params ;
end
function module . load ( )
if prosody.prosodyctl then return ; end
local engines = module : shared ( " /*/sql/connections " ) ;
local params = normalize_params ( module : get_option ( " auth_sql " , default_params ) ) ;
engine = engines [ sql.db2uri ( params ) ] ;
if not engine then
module : log ( " debug " , " Creating new engine " ) ;
engine = sql : create_engine ( params ) ;
engines [ sql.db2uri ( params ) ] = engine ;
end
engine : connect ( ) ;
pushd_config = module : get_option ( " pushd_config " , pushd_config ) ;
if not pushd_config.muc_config then
pushd_config.muc_config = muc_config
end
sql_config = module : get_option ( " auth_sql " , sql_config ) ;
engine = mod_sql : create_engine ( sql_config ) ;
engine : execute ( " SET NAMES 'utf8' COLLATE 'utf8_bin'; " ) ;
module : log ( " debug " , " load OK " ) ;
end