|
|
######## Presence sync server module ########
|
|
|
|
|
|
####### SQL OPS module ##########
|
|
|
#!ifndef SQLOPS_LOADED
|
|
|
loadmodule "sqlops.so"
|
|
|
modparam("sqlops","sqlcon", "cb=>KAZOO_DB_URL")
|
|
|
#!trydef SQLOPS_LOADED
|
|
|
#!endif
|
|
|
|
|
|
event_route[kazoo:consumer-event-directory-reg-sync]
|
|
|
{
|
|
|
$var(Server) = $(kzE{kz.json,Server-ID});
|
|
|
xlog("L_INFO", "received registrar sync from $var(Server) : $kzE\n");
|
|
|
|
|
|
if (sql_xquery("cb", "select * from location", "ra") == 1)
|
|
|
{
|
|
|
while($xavp(ra) != $null) {
|
|
|
$var(runloop) = 1;
|
|
|
while($xavp(ra) != $null && $var(runloop) < MAX_WHILE_LOOPS ) {
|
|
|
if(registered("location", "sip:$xavp(ra=>username)@$xavp(ra=>domain)", 0, 1)) {
|
|
|
xlog("L_INFO", "[id, username, domain] = [$xavp(ra=>id), $xavp(ra=>username), $xavp(ra=>domain)]\n");
|
|
|
$var(Expires) = $xavp(ra=>expires) - $TS;
|
|
|
$var(amqp_payload_request) = '{"Event-Category" : "directory", "Event-Name" : "reg_success", "Status" : "Success", "Event-Timestamp" : $TS, "Expires" : $(var(Expires){s.int}), "First-Registration" : false, "Contact" : "$(xavp(ra=>contact){s.escape.common})", "Call-ID" : "$xavp(ra=>callid)", "Realm" : "$xavp(ra=>domain)", "Username" : "$xavp(ra=>username)", "From-User" : "$xavp(ra=>username)", "From-Host" : "$xavp(ra=>domain)", "To-User" : "$xavp(ra=>username)", "To-Host" : "$xavp(ra=>domain)", "User-Agent" : "$(xavp(ra=>user_agent){s.escape.common})" , "Custom-Channel-Vars" : $xavp(ulattrs=>custom_channel_vars), "Proxy-Path" : "sip:$(xavp(ra=>socket){s.substr,4,0})" }';
|
|
|
kazoo_publish("targeted", "$var(Server)", $var(amqp_payload_request));
|
|
|
}
|
|
|
pv_unset("$xavp(ra)");
|
|
|
$var(runloop) = $var(runloop) + 1;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|