From b75e0136b1f2663672253d376be5aee35c481140 Mon Sep 17 00:00:00 2001 From: lazedo Date: Thu, 13 Apr 2017 19:25:14 +0100 Subject: [PATCH] Fastpickup (#160) * presence-sync deprecated * rework bindings/custom * add ipops * rework registrar bindings * rework presence bindings * rework fastpickup * split reset specifics to new configuration file * better and less intrusive logs * ensure pickup doesn't change with state * less noise in logs --- kamailio/default.cfg | 18 +--- kamailio/fast-pickup-role.cfg | 123 +++++++++++++++-------- kamailio/kazoo-bindings.cfg | 13 +-- kamailio/kazoo-custom-bindings.cfg | 5 - kamailio/local.cfg | 1 - kamailio/presence-reset.cfg | 80 +++++++++++++++ kamailio/presence-role.cfg | 151 +++++++++-------------------- kamailio/presence_sync-role.cfg | 42 -------- kamailio/registrar-role.cfg | 14 +++ 9 files changed, 229 insertions(+), 218 deletions(-) delete mode 100644 kamailio/kazoo-custom-bindings.cfg create mode 100644 kamailio/presence-reset.cfg delete mode 100644 kamailio/presence_sync-role.cfg diff --git a/kamailio/default.cfg b/kamailio/default.cfg index a7aa8c2..0c3e3be 100644 --- a/kamailio/default.cfg +++ b/kamailio/default.cfg @@ -99,6 +99,9 @@ loadmodule "stun.so" ######## Kamailio path module ######## loadmodule "path.so" +######## Kamailio ipops module ######## +loadmodule "ipops.so" + ######## Kamailio control connector module ######## loadmodule "ctl.so" modparam("ctl", "binrpc_buffer_size", 4096) @@ -239,21 +242,6 @@ include_file "responder-role.cfg" #!ifdef NODES_ROLE include_file "nodes-role.cfg" #!endif -#!ifdef REGISTRAR_SYNC_ROLE -include_file "registrar-sync-role.cfg" -#!endif -#!ifdef FAST_PICKUP_ROLE -include_file "fast-pickup-role.cfg" -#!endif -#!ifdef PRESENCE_SYNC_ROLE -include_file "presence_sync-role.cfg" -#!endif -#!ifdef PRESENCE_QUERY_ROLE -include_file "presence_query-role.cfg" -#!endif -#!ifdef PRESENCE_NOTIFY_SYNC_ROLE -include_file "presence_notify_sync-role.cfg" -#!endif ####### Permissions module ########## diff --git a/kamailio/fast-pickup-role.cfg b/kamailio/fast-pickup-role.cfg index 50a14d0..560c5eb 100644 --- a/kamailio/fast-pickup-role.cfg +++ b/kamailio/fast-pickup-role.cfg @@ -1,6 +1,37 @@ ######## FAST PICKUP ROLE ######## modparam("htable", "htable", "park=>size=16;autoexpire=600") -modparam("htable", "htable", "fp=>size=32;autoexpire=3600;"); +modparam("htable", "htable", "fp=>size=8"); + +route[FAST_PICKUP_START] +{ + $sht(fp=>count) = 0; +} + +route[FAST_PICKUP_LOAD] +{ + sht_reset("fp"); +#!ifndef KZ_USE_DISPATCHER_LIST + xlog("L_INFO", "$ci|log|fast|initializing fastpick hash table from dispatcher\n"); + if (sql_xquery("exec", "select destination from dispatcher", "ra") == 1) { + while($xavp(ra) != $null) { + $var(host) = $(xavp(ra=>destination){uri.host}); + $var(port) = $(xavp(ra=>destination){uri.port}); + $var(destination) = $xavp(ra=>destination); + $var(i) = 0; + if(!is_ip("$var(host)")) { + if(dns_query("$var(host)", "xyz")) { + $var(destination) = $_s(sip:$dns(xyz=>addr[$var(i)]):$var(port)); + } + } + xlog("L_INFO", "$ci|log|fast|adding key $(var(destination){s.md5}) for $var(destination)\n"); + $sht(fp=>$(var(destination){s.md5})) = $var(destination); + pv_unset("$xavp(ra)"); + } + } +#!else + xlog("L_INFO", "$ci|log|fast|cannot initialize hash table from dispatcher. check KZ_USE_DISPATCHER_LIST option in local.cfg\n"); +#!endif +} route[FAST_PICKUP_ATTEMPT] { @@ -10,31 +41,31 @@ route[FAST_PICKUP_ATTEMPT] $var(replaced_call_id) = "none"; - if($ru =~ "sip:kfp+") { - $var(Cookie) = $(rU{s.rm,kfp+}); - if($sht(fp=>$var(Cookie)::Call-ID) != $null) { - $var(replaced_call_id) = $sht(fp=>$var(Cookie)::Call-ID); - if($hdr(Replaces)!= $null) { - remove_hf_re("^Replaces"); - } - append_hf("Replaces: $var(replaced_call_id)\r\n"); - $ru = $sht(fp=>$var(Cookie)::URI); - $tu = $sht(fp=>$var(Cookie)::URI); - $du = $sht(fp=>$var(Cookie)::Switch-URI); - xlog("L_INFO", "$ci|log|call-id fast pickup call $var(replaced_call_id), redirecting to $du\n"); + if($hdr(Replaces)!= $null) { + $var(replaced_call_id) = $(hdr(Replaces){s.select,0,;}); + } + + if($var(replaced_call_id) =~ "kfp+") { + if($shtinc(fp=>count) == 1) { + route(FAST_PICKUP_LOAD); + } + remove_hf_re("^Replaces"); + $var(PickupOptions) = $(var(replaced_call_id){re.subst,/^kfp\+(.{2})([^@]*)@(.*)/\1/}{s.decode.hexa}); + $var(md5) = $(var(replaced_call_id){re.subst,/^kfp\+(.{2})([^@]*)@(.*)/\2/}); + $var(replaced_call_id) = $(var(replaced_call_id){re.subst,/^kfp\+(.{2})([^@]*)@(.*)/\3/}); + if( $sht(fp=>$var(md5)) != $null) { + route(FAST_PICKUP_OPTION); + $du = $sht(fp=>$var(md5)); + append_hf("Replaces: $var(replaced_call_id)$var(Pickup)\r\n"); + xlog("L_INFO", "$ci|log|fast|found shortcut for call-id $var(replaced_call_id) , redirecting ($(ru{uri.user})) to $du\n"); route(EXTERNAL_TO_INTERNAL_RELAY); exit(); } else { - xlog("L_INFO", "$ci|log|call-id fast pickup call not found $ru\n"); - send_reply("404", "Not Found"); - exit(); + $var(replaced_call_id) = "none"; + xlog("L_INFO", "$ci|log|fast|shortcut $var(md5) invalid in this server, using standard routing\n"); } } - if($hdr(Replaces)!= $null) { - $var(replaced_call_id) = $(hdr(Replaces){s.select,0,;}); - } - if($var(replaced_call_id) != "none") { xlog("L_INFO", "$ci|log|request has replaces call-id $var(replaced_call_id)\n"); $var(amqp_payload_request) = '{"Event-Category" : "call_event" , "Event-Name" : "channel_status_req", "Call-ID" : "' + $var(replaced_call_id) + '", "Active-Only" : true }'; @@ -45,13 +76,12 @@ route[FAST_PICKUP_ATTEMPT] $du = $(kzR{kz.json,Switch-URL}); if($du != $null) { if($(ru{uri.user}) =~ "\*") { - xlog("L_INFO", "$ci|log|adding a-leg to replaces header\n"); remove_hf_re("^Replaces"); append_hf("Replaces: $var(replaced_call_id);a-leg=true\r\n"); - } - xlog("L_INFO", "$ci|log|call-id $var(replaced_call_id) found redirecting call ($(ru{uri.user})) to $du\n"); - route(EXTERNAL_TO_INTERNAL_RELAY); - exit(); + } + xlog("L_INFO", "$ci|log|call-id $var(replaced_call_id) found redirecting call ($(ru{uri.user})) to $du\n"); + route(EXTERNAL_TO_INTERNAL_RELAY); + exit(); } else { xlog("L_WARN", "$ci|log|call-id $var(replaced_call_id) not found in cluster, proceeding with normal dispatch\n"); remove_hf_re("^Replaces"); @@ -62,7 +92,7 @@ route[FAST_PICKUP_ATTEMPT] } ##### CALL-PARK #### - if($(ru{uri.user}) =~ "\*3" && $sht(park=>$(ru{uri.user})@$(ru{uri.domain})) != $null) { + if($(ru{uri.user}) =~ "\*" && $sht(park=>$(ru{uri.user})@$(ru{uri.domain})) != $null) { $du = $sht(park=>$(ru{uri.user})@$(ruri{uri.domain})); xlog("L_INFO", "$ci|log|redirecting park request to $du\n"); if ($hdr(Proxy-Authorization) != $null) { @@ -96,21 +126,36 @@ route[FAST_PICKUP_REPLY] { $sht(park=>$(avp(refer_to_uri){uri.user})@$(avp(refer_to_uri){uri.domain})) = $var(contact); } +route[FAST_PICKUP_OPTION] +{ + $var(Pickup) = ""; + switch($var(PickupOptions)) + { + case 1: + $var(Pickup) = ";a-leg=true"; + break; + case 2: + $var(Pickup) = ";early-only=true"; + break; + default: + break; + } +} + route[FAST_PICKUP_INIT] { - $var(AppName) = $(kzE{kz.json,App-Name}); - if($var(AppName) == "park") { - $var(Pickup) = ";a-leg=true"; - } else { - if($(kzE{kz.json,State}) == "confirmed"){ - $var(Pickup) = ";early-only=true"; - } else { - $var(Pickup) = ""; - } - } - $sht(fp=>$(kzE{kz.json,Call-Cookie})::Switch-URI) = $(kzE{kz.json,Switch-URI}); - $sht(fp=>$(kzE{kz.json,Call-Cookie})::Call-ID) = $(kzE{kz.json,Target-Call-ID}) + $var(Pickup); - $sht(fp=>$(kzE{kz.json,Call-Cookie})::URI) = "sip:" + $(kzE{kz.json,From-User}) + "@" + $(kzE{kz.json,To-Realm}) ; + $var(AppName) = $(kzE{kz.json,App-Name}); + if($var(AppName) == "park") { + $var(Pickup) = 1; #";a-leg=true"; + } else { + $var(Pickup) = 2; #";early-only=true"; + } + $var(Option) = $(var(Pickup){s.encode.hexa}); + $var(Cookie) = $(kzE{kz.json,Switch-URI}{s.md5}); + $var(call_id) = $(kzE{kz.json,Call-ID}); + $var(JObj) = $(kzE{re.subst,/"Call-ID"\s*\:\s*"([^\s"]*)"/"Call-ID" : "kfp+$var(Option)$var(Cookie)@\1"/}); + xlog("L_DEBUG", "$ci|init|fast|created shortcut kfp+$var(Option)$var(Cookie)@ for call-id $var(call_id)\n"); } # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab + diff --git a/kamailio/kazoo-bindings.cfg b/kamailio/kazoo-bindings.cfg index 42fc044..304ef47 100644 --- a/kamailio/kazoo-bindings.cfg +++ b/kamailio/kazoo-bindings.cfg @@ -16,8 +16,6 @@ ### ### -include_file "kazoo-custom-bindings.cfg" - event_route[kazoo:mod-init] { @@ -25,11 +23,6 @@ event_route[kazoo:mod-init] route(PRESENCE_BINDINGS); #!endif - #!ifdef PRESENCE_QUERY_ROLE - route(PRESENCE_QUERY_BINDINGS); - #!endif - - #!ifdef MESSAGE_ROLE route(MESSAGE_BINDINGS); #!endif @@ -38,10 +31,6 @@ event_route[kazoo:mod-init] route(REGISTRAR_BINDINGS); #!endif - #!ifdef REGISTRAR_SYNC_ROLE - route(REGISTRAR_SYNC_BINDINGS); - #!endif - #!ifdef NODES_ROLE route(NODES_BINDINGS); #!endif @@ -51,6 +40,8 @@ event_route[kazoo:mod-init] kazoo_subscribe("$var(payload)"); #!endif + #!import_file "kazoo-custom-bindings.cfg" + } event_route[kazoo:consumer-event] diff --git a/kamailio/kazoo-custom-bindings.cfg b/kamailio/kazoo-custom-bindings.cfg deleted file mode 100644 index 711b78d..0000000 --- a/kamailio/kazoo-custom-bindings.cfg +++ /dev/null @@ -1,5 +0,0 @@ -######## kazoo custom bindings ######## - - - -# vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/local.cfg b/kamailio/local.cfg index afb55f4..6dc3113 100644 --- a/kamailio/local.cfg +++ b/kamailio/local.cfg @@ -21,7 +21,6 @@ # # #!trydef MESSAGE_ROLE # # #!trydef PUSHER_ROLE # # #!trydef REGISTRAR_SYNC_ROLE -# # #!trydef PRESENCE_SYNC_ROLE # # #!trydef PRESENCE_NOTIFY_SYNC_ROLE ################################################################################ diff --git a/kamailio/presence-reset.cfg b/kamailio/presence-reset.cfg new file mode 100644 index 0000000..f3e0ec3 --- /dev/null +++ b/kamailio/presence-reset.cfg @@ -0,0 +1,80 @@ +##### PRESENCE RESET ROUTINES + +route[PRESENCE_RESET_BINDINGS] +{ + #!import_file "presence-reset-custom-bindings.cfg" + + #!ifndef PRESENCE_RESET_CUSTOM_BINDINGS + $var(payload) = "{ 'exchange' : 'presence' , 'queue' : 'presence-reset-MY_HOSTNAME', 'exclusive' : 0 ,'type' : 'topic', 'routing' : 'presence.reset.*.*', 'federate' : 1 }"; + kazoo_subscribe("$var(payload)"); + #!endif + +} + + +route[RESET_ZONE] +{ + xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|received presence reset for this zone\n"); + sql_query("exec", "delete from presentity"); + $var(presentities) = $sqlrows(exec); + xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|removed $var(presentities) presentities\n"); +} + +route[RESET_ACCOUNT] +{ + xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|received presence reset for realm $(kzE{kz.json,Realm})\n"); + sql_query("exec", 'delete from presentity where domain="$(kzE{kz.json,Realm})" '); + $var(presentities) = $sqlrows(exec); + sql_query("exec", 'update active_watchers set expires = $TS where watcher_domain="$(kzE{kz.json,Realm})" '); + $var(watchers) = $sqlrows(exec); + xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|removed $var(presentities) presentities and expired $var(watchers) subscribers for realm $(kzE{kz.json,Realm})\n"); +} + +route[RESET_WILDCARD] +{ + if($(kzE{kz.json,Realm}) == "*") { + if($(kzE{kz.json,Username}) == "MY_AMQP_ZONE") { + route(RESET_ZONE); + } else { + xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|received presence reset for zone $(kzE{kz.json,Username}). 'MY_AMQP_ZONE' doesn't care\n"); + } + exit(); + } else { + route(RESET_ACCOUNT); + } + +} + + +event_route[kazoo:consumer-event-presence-reset] +{ + if($(kzE{kz.json,Username}) == "*" || $(kzE{kz.json,Realm}) == "*") { + route(RESET_WILDCARD); + exit(); + } + + xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|received presence reset for $(kzE{kz.json,Username})@$(kzE{kz.json,Realm})\n"); + $var(presentity) = "sip:" + $(kzE{kz.json,Username}) + "@" + $(kzE{kz.json,Realm}); + sql_query("exec", 'delete from presentity where domain="$(kzE{kz.json,Realm})" and username = "$(kzE{kz.json,Username})"'); + if(pres_has_subscribers("$var(presentity)", "message-summary")) { + xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|notifying message-summary subscribers of $var(presentity)\n"); + pres_refresh_watchers("$var(presentity)", "message-summary", 1); + } else { + xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|skip message-summary subscriber notification for $var(presentity))\n"); + } + + if(pres_has_subscribers("$var(presentity)", "presence")) { + xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|notifying presence subscribers of $var(presentity)\n"); + pres_refresh_watchers("$var(presentity)", "presence", 1); + } else { + xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|skip presence subscriber notification for $var(presentity))\n"); + } + + if(pres_has_subscribers("$var(presentity)", "dialog")) { + xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|notifying dialog subscribers of $var(presentity)\n"); + pres_refresh_watchers("$var(presentity)", "dialog", 1); + } else { + xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|skip dialog subscriber notification for $var(presentity))\n"); + } + +} diff --git a/kamailio/presence-role.cfg b/kamailio/presence-role.cfg index 3d4493d..2b5d3bb 100644 --- a/kamailio/presence-role.cfg +++ b/kamailio/presence-role.cfg @@ -61,6 +61,24 @@ loadmodule "sqlops.so" #!endif modparam("sqlops","sqlcon", "exec=>KAZOO_DB_URL") + + +#!ifdef FAST_PICKUP_ROLE +#!include_file "fast-pickup-role.cfg" +#!endif +#!ifdef PRESENCE_QUERY_ROLE +#!include_file "presence_query-role.cfg" +#!endif +#!ifdef PRESENCE_NOTIFY_SYNC_ROLE +#!include_file "presence_notify_sync-role.cfg" +#!endif + +#!include_file "presence-reset.cfg" + + +####### Presence Logic ######## + +#!ifdef NAT_TRAVERSAL_ROLE route[PRESENCE_NAT] { if (client_nat_test("3")) { @@ -71,8 +89,8 @@ route[PRESENCE_NAT] force_rport(); } +#!endif -####### Presence Logic ######## route[HANDLE_SUBSCRIBE] { if (!is_method("SUBSCRIBE")) { @@ -175,10 +193,16 @@ route[HANDLE_PUBLISH] event_route[kazoo:consumer-event-presence-dialog-update] { - xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|received $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State})\n"); + + xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|received $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) from $(kzE{kz.json,Switch-URI})\n"); + $var(JObj) = $kzE; + #!ifdef FAST_PICKUP_ROLE + route(FAST_PICKUP_INIT); + #!endif + if(pres_has_subscribers("$(kzE{kz.json,From})", "dialog")) { xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|publishing dialog update for $(kzE{kz.json,From})\n"); - kazoo_pua_publish_dialoginfo($kzE); + kazoo_pua_publish_dialoginfo($var(JObj)); pres_refresh_watchers("$(kzE{kz.json,From})", "dialog", 1); } else { xlog("L_INFO", "$(kzE{kz.json,Call-ID})|log|skip dialog update for $(kzE{kz.json,From})\n"); @@ -220,116 +244,33 @@ event_route[kazoo:consumer-event-presence-update] } -route[RESET_ZONE] -{ - xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|received presence reset for this zone\n"); - sql_query("exec", "delete from presentity"); - $var(presentities) = $sqlrows(exec); - xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|removed $var(presentities) presentities\n"); -} -route[RESET_ACCOUNT] +route[PRESENCE_BINDINGS] { - xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|received presence reset for realm $(kzE{kz.json,Realm})\n"); - sql_query("exec", 'delete from presentity where domain="$(kzE{kz.json,Realm})" '); - $var(presentities) = $sqlrows(exec); - sql_query("exec", 'update active_watchers set expires = $TS where watcher_domain="$(kzE{kz.json,Realm})" '); - $var(watchers) = $sqlrows(exec); - xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|removed $var(presentities) presentities and expired $var(watchers) subscribers for realm $(kzE{kz.json,Realm})\n"); -} + #!import_file "presence-custom-bindings.cfg" + + #!ifndef PRESENCE_CUSTOM_BINDINGS + $var(payload) = "{ 'exchange' : 'presence' , 'queue' : 'presence-dialog-MY_HOSTNAME', 'exclusive' : 0 ,'type' : 'topic', 'routing' : 'dialog.*.*', 'federate' : 1 }"; + kazoo_subscribe("$var(payload)"); -route[RESET_WILDCARD] -{ - if($(kzE{kz.json,Realm}) == "*") { - if($(kzE{kz.json,Username}) == "MY_AMQP_ZONE") { - route(RESET_ZONE); - } else { - xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|received presence reset for zone $(kzE{kz.json,Username}). 'MY_AMQP_ZONE' doesn't care\n"); - } - exit(); - } else { - route(RESET_ACCOUNT); - } - -} + $var(payload) = "{ 'exchange' : 'presence' , 'queue' : 'presence-presence-MY_HOSTNAME', 'exclusive' : 0 ,'type' : 'topic', 'routing' : 'update.*.*', 'federate' : 1 }"; + kazoo_subscribe("$var(payload)"); + $var(payload) = "{ 'exchange' : 'presence' , 'queue' : 'presence-mwi-MY_HOSTNAME', 'exclusive' : 0 ,'type' : 'topic', 'routing' : 'mwi_updates.*', 'federate' : 1 }"; + kazoo_subscribe("$var(payload)"); + #!endif -event_route[kazoo:consumer-event-presence-reset] -{ - if($(kzE{kz.json,Username}) == "*" || $(kzE{kz.json,Realm}) == "*") { - route(RESET_WILDCARD); - exit(); - } - - xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|received presence reset for $(kzE{kz.json,Username})@$(kzE{kz.json,Realm})\n"); - $var(presentity) = "sip:" + $(kzE{kz.json,Username}) + "@" + $(kzE{kz.json,Realm}); - sql_query("exec", 'delete from presentity where domain="$(kzE{kz.json,Realm})" and username = "$(kzE{kz.json,Username})"'); - if(pres_has_subscribers("$var(presentity)", "message-summary")) { - xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|notifying message-summary subscribers of $var(presentity)\n"); - pres_refresh_watchers("$var(presentity)", "message-summary", 1); - } else { - xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|skip message-summary subscriber notification for $var(presentity))\n"); - } - - if(pres_has_subscribers("$var(presentity)", "presence")) { - xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|notifying presence subscribers of $var(presentity)\n"); - pres_refresh_watchers("$var(presentity)", "presence", 1); - } else { - xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|skip presence subscriber notification for $var(presentity))\n"); - } - - if(pres_has_subscribers("$var(presentity)", "dialog")) { - xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|notifying dialog subscribers of $var(presentity)\n"); - pres_refresh_watchers("$var(presentity)", "dialog", 1); - } else { - xlog("L_INFO", "$(kzE{kz.json,Msg-ID})|reset|skip dialog subscriber notification for $var(presentity))\n"); - } + route(PRESENCE_RESET_BINDINGS); + + #!ifdef PRESENCE_QUERY_ROLE + route(PRESENCE_QUERY_BINDINGS); + #!endif -} + #!ifdef FAST_PICKUP_ROLE + route(FAST_PICKUP_START); + #!endif -route[HANDLE_PRESENCE_UPDATE] -{ - $var(call-id) = $(kzE{kz.json,Call-ID}); - if( $(kzE{kz.json,Event-Package}) == "dialog") { - if($sht(p=>$var(call-id)) != $(kzE{kz.json,State}) || $(kzE{kz.json,Flush-Level}) != $null) { - xlog("L_INFO", "$(kzE{kz.json,Target-Call-ID})|log|received $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) $kzE\n"); - $sht(p=>$(kzE{kz.json,Call-ID})) = $(kzE{kz.json,State}); - #!ifdef FAST_PICKUP_ROLE - route(FAST_PICKUP_INIT); - #!endif - kazoo_pua_publish($kzE); - pres_refresh_watchers("$(kzE{kz.json,From})", "$(kzE{kz.json,Event-Package})", 1); - $var(Presence) = $(kzE{re.subst,/"Event-Package": "dialog"/"Event-Package": "presence"/g}); - xlog("L_INFO", "PRESENCE $var(Presence)"); - kazoo_pua_publish($var(Presence)); - pres_refresh_watchers("$(var(Presence){kz.json,From})", "$(var(Presence){kz.json,Event-Package})", 1); - } else { - xlog("L_INFO", "$var(call-id)|log|received duplicate $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) state $(kzE{kz.json,State}) $kzE\n"); - xlog("L_INFO", "$var(call-id)|log|payload $kzE\n"); - } - } else { - xlog("L_INFO", "$var(call-id)|log|received $(kzE{kz.json,Event-Package}) update for $(kzE{kz.json,From}) $kzE\n"); - kazoo_pua_publish($kzE); - pres_refresh_watchers("$(kzE{kz.json,From})", "$(kzE{kz.json,Event-Package})", 1); - } } -#!ifndef PRESENCE_CUSTOM_BINDINGS -route[PRESENCE_BINDINGS] -{ - $var(payload) = "{ 'exchange' : 'presence' , 'queue' : 'presence-dialog-MY_HOSTNAME', 'exclusive' : 0 ,'type' : 'topic', 'routing' : 'dialog.*.*', 'federate' : 1 }"; - kazoo_subscribe("$var(payload)"); - - $var(payload) = "{ 'exchange' : 'presence' , 'queue' : 'presence-presence-MY_HOSTNAME', 'exclusive' : 0 ,'type' : 'topic', 'routing' : 'update.*.*', 'federate' : 1 }"; - kazoo_subscribe("$var(payload)"); - - $var(payload) = "{ 'exchange' : 'presence' , 'queue' : 'presence-mwi-MY_HOSTNAME', 'exclusive' : 0 ,'type' : 'topic', 'routing' : 'mwi_updates.*', 'federate' : 1 }"; - kazoo_subscribe("$var(payload)"); - - $var(payload) = "{ 'exchange' : 'presence' , 'queue' : 'presence-reset-MY_HOSTNAME', 'exclusive' : 0 ,'type' : 'topic', 'routing' : 'presence.reset.*.*', 'federate' : 1 }"; - kazoo_subscribe("$var(payload)"); - -} -#!endif # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab diff --git a/kamailio/presence_sync-role.cfg b/kamailio/presence_sync-role.cfg deleted file mode 100644 index d3d987d..0000000 --- a/kamailio/presence_sync-role.cfg +++ /dev/null @@ -1,42 +0,0 @@ -######## 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-presence-sync] -{ - xlog("L_INFO", "received SYNC $kzE\n"); - $var(Queue) = $(kzE{kz.json,Server-ID}); - $var(Now) = $TS; - ######## SEND BACK START ######## - $var(amqp_payload_request) = '{"Event-Category" : "presence", "Event-Name" : "sync", "Action" : "Start" }'; - kazoo_publish("targeted", "$var(Queue)", $var(amqp_payload_request)); - - if (sql_xquery("cb", "select * from active_watchers where expires > $var(Now)", "ra") == 1) - { - while($xavp(ra) != $null) - { - $var(runloop) = 1; - while($xavp(ra) != $null && $var(runloop) < MAX_WHILE_LOOPS ) { - xlog("L_INFO", "[id, presentity, watcher] = [$xavp(ra=>id), $xavp(ra=>presentity_uri), $xavp(ra=>watcher_username)]\n"); - $var(Expires) = $xavp(ra=>expires) - $var(Now); - xlog("L_INFO", "EXPIRES $var(Expires) , $xavp(ra=>expires) , $var(Now)\n"); - $var(amqp_payload_request) = '{"Event-Category" : "presence", "Event-Name" : "subscription", "Event-Package" : "$xavp(ra=>event)", "Expires" : $var(Expires), "Server-ID" : "BLF-MY_HOSTNAME" , "Contact" : "$xavp(ra=>contact)", "Call-ID" : "$xavp(ra=>callid)", "From" : "sip:$xavp(ra=>watcher_username)@$xavp(ra=>watcher_domain)", "User" : "$xavp(ra=>presentity_uri)" }"'; - kazoo_publish("targeted", "$var(Queue)", $var(amqp_payload_request)); - pv_unset("$xavp(ra)"); - $var(runloop) = $var(runloop) + 1; - } - } - } - - ######## SEND BACK END ######## - $var(amqp_payload_request) = '{"Event-Category" : "presence", "Event-Name" : "sync", "Action" : "End" }'; - kazoo_publish("targeted", "$var(Queue)", $var(amqp_payload_request)); - -} - -# vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab \ No newline at end of file diff --git a/kamailio/registrar-role.cfg b/kamailio/registrar-role.cfg index 1272029..95b53ae 100644 --- a/kamailio/registrar-role.cfg +++ b/kamailio/registrar-role.cfg @@ -310,9 +310,23 @@ event_route[kazoo:consumer-event-directory-reg-flush] route[REGISTRAR_BINDINGS] { + #!import_file "registrar-custom-bindings.cfg" + + #!ifndef REGISTRAR_CUSTOM_BINDINGS + $var(payload) = "{ 'exchange' : 'registrar' , 'type' : 'topic', 'queue' : 'registrar-flush-MY_HOSTNAME', 'routing' : 'registration.flush.*', 'no_ack' : 1, 'wait_for_consumer_ack' : 0 }"; kazoo_subscribe("$var(payload)"); + #!endif + + #!ifdef REGISTRAR_SYNC_ROLE + route(REGISTRAR_SYNC_BINDINGS); + #!endif + } +#!ifdef REGISTRAR_SYNC_ROLE +#!include_file "registrar-sync-role.cfg" +#!endif + # vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab