|
|
kazoo.presence_notify = 1 descr "enable/disable sending notify callback to omnipresence"
|
|
|
kazoo.presence_notify_timeout = 3000 descr "timeout in ms waiting for notify reply"
|
|
|
kazoo.presence_notify_log_body = 0 descr "logs the body sent in the notification"
|
|
|
kazoo.presence_notify_log_resp_body = 0 descr "logs the body received from notification"
|
|
|
kazoo.presence_notify_log_to_table = 1 descr "logs notify/reply to active_watchers_log table"
|
|
|
kazoo.presence_notify_log_to_amqp = 0 descr "logs notify/reply to amqp"
|
|
|
kazoo.presence_notify_record_route = 0 descr "add record route header to notify msg sent"
|
|
|
kazoo.presence_notify_log_init_body = 0 descr "logs the body before its sent"
|
|
|
kazoo.presence_notify_force_send_socket = 0 descr "forces the send socket to the contact"
|
|
|
|
|
|
######## Generic Hash Table container in shared memory ########
|
|
|
modparam("htable", "htable", "notify=>size=16;autoexpire=3600;updateexpire=1;initval=0")
|
|
|
|
|
|
#!trydef PRESENCE_NOTIFY_INIT
|
|
|
#!trydef MAX_NOTIFY_ERROR 5
|
|
|
|
|
|
route[PRESENCE_LOCAL_NOTIFY]
|
|
|
{
|
|
|
if($rm != "NOTIFY") {
|
|
|
return;
|
|
|
}
|
|
|
t_set_fr(@cfg_get.kazoo.presence_notify_timeout, @cfg_get.kazoo.presence_notify_timeout);
|
|
|
xlog("L_INFO", "$ci|log|init preparing $subs(event) notify to $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri) : $du\n");
|
|
|
if(@cfg_get.kazoo.presence_notify_log_init_body == 1) {
|
|
|
xlog("L_INFO", "$ci|log|init|body $(mb{s.escape.common}{s.replace,\','}{s.replace,$$,})\n");
|
|
|
}
|
|
|
if(@cfg_get.kazoo.presence_notify_force_send_socket == 1) {
|
|
|
$fs = $_s($(pr{s.tolower}):$(hdr(Contact){nameaddr.uri}{uri.host}):$(hdr(Contact){nameaddr.uri}{uri.port}));
|
|
|
xlog("L_INFO", "$ci|log|init|forcing socket to $fs, $(pr{s.tolower}):$(hdr(Contact){nameaddr.uri}{uri.host}):$(hdr(Contact){nameaddr.uri}{uri.port}) , $ct\n");
|
|
|
}
|
|
|
if(@cfg_get.kazoo.presence_notify_record_route == 1) {
|
|
|
record_route();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
####### MQUEUE module ##########
|
|
|
#!ifndef MQUEUE_LOADED
|
|
|
loadmodule "mqueue.so"
|
|
|
#!trydef MQUEUE_LOADED
|
|
|
#!endif
|
|
|
modparam("mqueue","mqueue", "name=presence_last_notity")
|
|
|
|
|
|
#!ifndef TIMER_LOADED
|
|
|
loadmodule "timer.so"
|
|
|
#!trydef TIMER_LOADED
|
|
|
#!endif
|
|
|
modparam("timer", "declare_timer", "PRESENCE_LOG_TIMER=PRESENCE_LOG_TIMER_ROUTE,500,fast,enable");
|
|
|
|
|
|
|
|
|
event_route[presence:notify-reply]
|
|
|
{
|
|
|
if(@cfg_get.kazoo.presence_notify != 1)
|
|
|
return;
|
|
|
|
|
|
$xavp(pres=>delete_subscription) = 0;
|
|
|
|
|
|
if($notify_reply($rs) == 200) {
|
|
|
$sht(notify=>$ci) = $null;
|
|
|
xlog("L_INFO", "$ci|end|notified $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri)\n");
|
|
|
} else if($notify_reply($rs) == 481 && $subs(reason) == "timeout") {
|
|
|
xlog("L_INFO","$ci|end|sent subscription $hdr(Subscription-State)\n");
|
|
|
} else {
|
|
|
xlog("L_ERROR", "$ci|error|received $notify_reply($rs) when notifying $subs(watcher_username)@$subs(watcher_domain) on behalf of $subs(pres_uri)\n");
|
|
|
if($rP != "UDP") {
|
|
|
$xavp(pres=>delete_subscription) = 1;
|
|
|
xlog("L_ERROR", "$ci|error|removing $rP watcher $subs(watcher_username)@$subs(watcher_domain) for $subs(pres_uri)\n");
|
|
|
} else {
|
|
|
$var(shtinc) = $shtinc(notify=>$ci::count);
|
|
|
if($var(shtinc) > MAX_NOTIFY_ERROR) {
|
|
|
$xavp(pres=>delete_subscription) = 1;
|
|
|
xlog("L_ERROR", "$ci|error|removing $rP watcher $subs(watcher_username)@$subs(watcher_domain) for $subs(pres_uri)\n");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if(@cfg_get.kazoo.presence_notify_log_body == 1)
|
|
|
xlog("L_INFO", "$ci|log|sent|body $(mb{s.escape.common}{s.replace,\','}{s.replace,$$,})\n");
|
|
|
if(@cfg_get.kazoo.presence_notify_log_resp_body == 1)
|
|
|
xlog("L_INFO", "$ci|log|resp|body $(notify_reply($mb){s.escape.common}{s.replace,\','}{s.replace,$$,})\n");
|
|
|
|
|
|
if(@cfg_get.kazoo.presence_notify_log_to_amqp == 1) {
|
|
|
route(PRESENCE_NOTIFY_AMQP);
|
|
|
}
|
|
|
|
|
|
if(@cfg_get.kazoo.presence_notify_log_to_table == 1) {
|
|
|
$var(Query) = $_s(REPLACE INTO active_watchers_log (presentity_uri, watcher_username, watcher_domain, event, callid, to_user, to_domain, user_agent, time, result, sent_msg, received_msg) VALUES ("$subs(uri)", "$subs(watcher_username)", "$subs(watcher_domain)", "$subs(event)","$subs(callid)","$subs(to_user)","$subs(to_domain)", '$(subs(user_agent){s.escape.common}{s.replace,\',''}{s.replace,$$,})', $TS, $notify_reply($rs), '$(mb{s.escape.common}{s.replace,\',''}{s.replace,$$,})', '$(notify_reply($mb){s.escape.common}{s.replace,\',''}{s.replace,$$,})'));
|
|
|
mq_add("presence_last_notity", "$subs(callid)", "$var(Query)");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
route[PRESENCE_LOG_TIMER_ROUTE]
|
|
|
{
|
|
|
$var(runloop) = 1;
|
|
|
while(mq_fetch("presence_last_notity") == 1 && $var(runloop) < MAX_WHILE_LOOPS) {
|
|
|
$var(ci) = $mqk(presence_last_notity);
|
|
|
xlog("L_DEBUG", "Query : $mqv(presence_last_notity)");
|
|
|
$var(sqlres) = sql_query("cb", "$mqv(presence_last_notity)");
|
|
|
xlog("L_DEBUG", "Query result : $var(sqlres)");
|
|
|
if($var(sqlres) < 0) {
|
|
|
xlog("L_ERROR", "$var(ci)|log|error updating active_watchers_log\n");
|
|
|
} else {
|
|
|
$var(nrows) = $sqlrows(cb);
|
|
|
xlog("L_DEBUG", "$var(ci)|log|end UPDATED $var(nrows)\n");
|
|
|
if($var(nrows) == 0) {
|
|
|
xlog("L_ERROR", "$var(ci)|log|error no rows affected when updating active_watchers_log\n");
|
|
|
}
|
|
|
}
|
|
|
$var(runloop) = $var(runloop) + 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
route[PRESENCE_NOTIFY_AMQP]
|
|
|
{
|
|
|
$var(amqp_payload_request) = $_s({"Event-Category" : "presence", "Event-Name" : "notify", "Event-Package" : "$subs(event)", "Timestamp" : $TS, "Call-ID" : "$subs(callid)", "From" : "$fu", "To" : "$subs(to_user)@$subs(to_domain)", "Sent" : "$(TS{s.ftime,%Y-%m-%d %H:%M:%S})", "Body" : "Hostname : MY_HOSTNAME\r\nTimestamp : $(TS{s.ftime,%Y-%m-%d %H:%M:%S})\r\n$(mb{s.escape.common}{s.replace,\','}{s.replace,$$,})\r\nResponse\r\n$(notify_reply($mb){s.escape.common}{s.replace,\','}{s.replace,$$,})","Remote-CSeq" : $subs(remote_cseq), "Local-CSeq" : $subs(local_cseq), "Sequence" : $cs, "Version" : $subs(version), "Reply" : $notify_reply($rs) });
|
|
|
$var(rk) = "notify." + $(subs(to_domain){kz.encode}) + "." + $(subs(to_user){kz.encode});
|
|
|
kazoo_publish("omnipresence", "$var(rk)", $var(amqp_payload_request));
|
|
|
xlog("L_INFO", "$ci|log|sent notify callback for event $subs(event) : $tu\n");
|
|
|
}
|