Browse Source

Merge pull request #27 from 2600hz/KAZOO-3265

KAZOO-3265 MESSAGE-ROLE
3.20
bitbashing 11 years ago
parent
commit
dff7a8afa4
3 changed files with 95 additions and 11 deletions
  1. +39
    -11
      kamailio/default.cfg
  2. +1
    -0
      kamailio/local.cfg
  3. +55
    -0
      kamailio/message-role.cfg

+ 39
- 11
kamailio/default.cfg View File

@ -174,6 +174,9 @@ include_file "registrar-role.cfg"
#!ifdef PRESENCE-ROLE
include_file "presence-role.cfg"
#!endif
#!ifdef MESSAGE-ROLE
include_file "message-role.cfg"
#!endif
#!ifdef NAT-TRAVERSAL-ROLE
include_file "nat-traversal-role.cfg"
#!endif
@ -322,6 +325,30 @@ route[HANDLE_NOTIFY]
route[HANDLE_MESSAGE]
{
#!ifdef MESSAGE-ROLE
if (is_method("MESSAGE")) {
xlog("L_INFO", "$ci|MESSAGE from $fu to $tu");
if (isflagset(FLAG_INTERNALLY_SOURCED) || src_ip == myself) {
xlog("L_INFO", "$ci| routing MESSAGE to external from $fu to $tu");
route(INTERNAL_TO_EXTERNAL_RELAY);
#!ifdef TRAFFIC-FILTER-ROLE
} else if (!isflagset(FLAG_TRUSTED_SOURCE)
&& $rd =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}") {
xlog("L_WARN", "$ci|end|dropping MESSAGE request with IP domain");
#!endif
} else {
xlog("L_WARN", "$ci|end|MESSAGE $(hdr(Content-Type))");
if( $hdr(Content-Type) == "application/im-iscomposing+xml" ) {
xlog("L_WARN", "$ci|end|dropping MESSAGE application/im-iscomposing+xml");
sl_send_reply("200", "OK");
} else {
route(DISPATCHER_FIND_ROUTES);
route(EXTERNAL_TO_INTERNAL_RELAY);
}
}
exit();
}
#!else
if (is_method("MESSAGE")) {
if (isflagset(FLAG_INTERNALLY_SOURCED)) {
route(INTERNAL_TO_EXTERNAL_RELAY);
@ -330,6 +357,7 @@ route[HANDLE_MESSAGE]
exit;
}
}
#!endif
}
route[HANDLE_IN_DIALOG_REQUESTS]
@ -509,9 +537,9 @@ onreply_route[INTERNAL_REPLY]
#!endif
if (is_method("INVITE") &&
!isflagset(FLAG_SESSION_PROGRESS) &&
t_check_status("(180)|(183)|(200)")
) {
!isflagset(FLAG_SESSION_PROGRESS) &&
t_check_status("(180)|(183)|(200)")
) {
if ($avp(AVP_REDIRECT_KEY) != $null &&
$sht(redirects=>$avp(AVP_REDIRECT_KEY)) != $null
) {
@ -543,8 +571,8 @@ failure_route[INTERNAL_FAULT]
# Handle redirects
if (t_check_status("302")) {
$var(redirect) = @from.uri.user + "@" + @from.uri.host + "->"
+ $T_rpl($(ct{tobody.user})) + "@" + $T_rpl($(ct{tobody.host}));
$var(redirect) = @from.uri.user + "@" + @from.uri.host + "->"
+ $T_rpl($(ct{tobody.user})) + "@" + $T_rpl($(ct{tobody.host}));
if($T_rpl($hdr(X-Redirect-Server)) != $null) {
$sht(redirects=>$var(redirect)) = $T_rpl($hdr(X-Redirect-Server));
xlog("L_INFO", "$ci|log|stored redirect mapping $var(redirect) to $T_rpl($hdr(X-Redirect-Server))");
@ -563,7 +591,7 @@ failure_route[INTERNAL_FAULT]
if (t_check_status("6[0-9][0-9]") && !t_check_status("600|603|604|606")) {
$var(new_code) = "4" + $(T_reply_code{s.substr,1,0});
xlog("L_INFO", "$ci|log|sending 6XX reply as $var(new_code) $var(reply_reason)");
t_reply("$(var(new_code){s.int})", "$var(reply_reason)");
t_reply("$(var(new_code){s.int})", "$var(reply_reason)");
# if the failure case was something that we should recover
# from then try to find a new media server
@ -604,13 +632,13 @@ event_route[kazoo:mod-init]
{
#!ifdef PRESENCE-ROLE
### use this simple form of binding a listener
### use this simple form of binding a listener
### kazoo_subscribe("dialoginfo", "direct", "BLF-QUEUE-MY_HOSTNAME", "BLF-MY_HOSTNAME");
###
### or unleash the power of rabbit to kazoo-blf
###
### 'no_ack' : 1 => needs ack,
### 'wait_for_consumer_ack'
### 'no_ack' : 1 => needs ack,
### 'wait_for_consumer_ack'
### : 1 => when it receives, it processses on the AMQP Worker ad after that it confirms
### : 0 => when it receives, it acks then processes in the AMQP Worker
### only works if no_ack : 0
@ -619,13 +647,13 @@ event_route[kazoo:mod-init]
### pattern : ^BLF
### definition : ha-mode: all
###
###
###
$var(payload) = "{ 'exchange' : 'dialoginfo' , 'type' : 'direct', 'queue' : 'BLF-QUEUE-MY_HOSTNAME', 'routing' : 'BLF-MY_HOSTNAME', 'auto_delete' : 0, 'durable' : 1, 'no_ack' : 0, 'wait_for_consumer_ack' : 1 }";
xlog("L_INFO","SUBSCRIBE $var(payload)");
kazoo_subscribe("$var(payload)");
#!endif
}
event_route[kazoo:consumer-event]


+ 1
- 0
kamailio/local.cfg View File

@ -17,6 +17,7 @@ debug = L_INFO
# # #!trydef WEBSOCKETS-ROLE
# # #!trydef TLS-ROLE
# # #!trydef ANTIFLOOD-ROLE
# # #!trydef MESSAGE-ROLE
################################################################################
## SERVER INFORMATION


+ 55
- 0
kamailio/message-role.cfg View File

@ -0,0 +1,55 @@
modparam("htable", "htable", "msg=>size=32;autoexpire=60;")
event_route[kazoo:consumer-event-message-route]
{
$var(uri_username) = "";
kazoo_json($kzE, "Endpoints[0].To-Username", "$var(uri_username)");
$var(x) = $(kzE{kz.json,Endpoints[0].To-Username});
xlog("L_INFO", "received message route for $(kzE{kz.json,Endpoints[0].To-DID})");
if( $var(uri_username) != "" ) {
$var(from_uri) = "sip:" + $(kzE{kz.json,Caller-ID-Number}) + "@" + $(kzE{kz.json,Endpoints[0].To-Realm});
$var(to_uri) = "sip:" + $(kzE{kz.json,Endpoints[0].To-Username}) + "@" + $(kzE{kz.json,Endpoints[0].To-Realm});
} else {
$var(from_uri) = "sip:" + $(kzE{kz.json,Caller-ID-Number}) + $(kzE{kz.json,Endpoints[0].To-Realm});
$var(to_uri) = $(kzE{kz.json,Endpoints[0].Route});
}
$sht(msg=>$(kzE{kz.json,Call-ID})) = $kzE;
$uac_req(method)="MESSAGE";
$uac_req(body)= $(kzE{kz.json,Body});
$uac_req(hdrs)="Content-Type: text/plain\r\n";
$uac_req(turi) = $var(to_uri);
$uac_req(ruri) = $var(to_uri);
$uac_req(furi) = $var(from_uri);
$uac_req(ouri) = "sip:MY_IP_ADDRESS:5060";
$uac_req(callid) = $(kzE{kz.json,Call-ID});
xlog("L_INFO", "sending message from $var(from_uri) to $var(to_uri) ");
uac_req_send();
}
route[MESSAGE_REPLY]
{
if( $(sht(msg=>$ci)) == $null) {
exit();
}
if($T_reply_code != 200 && $T_reply_code != 202) {
$var(Result) = "Failure";
} else {
$var(Result) = "Success";
}
$var(Payload) = '{ "Event-Category" : "message", "Event-Name" : "delivery", "Call-ID" : "' + $(sht(msg=>$ci){kz.json,Call-ID}) + '", "Message-ID" : "' + $(sht(msg=>$ci){kz.json,Message-ID}) +'" , "Delivery-Result-Code" : "sip:" + $T_reply_code + '" , "Msg-ID" : "' + $(sht(msg=>$ci){kz.json,Msg-ID}) + '" , "Status" : "' + $var(Result) + '"}';
$var(RoutingKey) = $(sht(msg=>$ci){kz.json,Server-ID});
$var(exchange) = "targeted";
if($var(RoutingKey) == "") {
$var(exchange) = "sms";
$var(RoutingKey) = "message.delivery." + $(sht(msg=>$ci){kz.json,Call-ID}{kz.encode});
}
xlog("L_INFO", "sending delivery message for $ci");
kazoo_publish($var(exchange), $var(RoutingKey), $var(Payload));
}
# vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab

Loading…
Cancel
Save