Skip to content

Commit

Permalink
some fixes & optimizations
Browse files Browse the repository at this point in the history
* handle caller-id
* fix token-reg registration
* use reg_fetch_contacts
* set tm failure_exec_mode
* use IC_SIL
  • Loading branch information
lazedo committed Jul 5, 2018
1 parent a670864 commit cef7614
Showing 1 changed file with 34 additions and 9 deletions.
43 changes: 34 additions & 9 deletions kamailio/pusher-role.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
######## Generic Hash Table container in shared memory ########
modparam("htable", "htable", "push_cache=>autoexpire=60;")

modparam("tm", "failure_exec_mode", 1)

route[PUSHER_ROUTE]
{
if ( (!is_method("INVITE")) || (!isflagset(FLAG_INTERNALLY_SOURCED)) || $hdr(X-KAZOO-PUSHER-Token-ID) == $null)
return;

xlog("L_INFO", "$ci|pusher|start deliver call to $hdr(X-KAZOO-PUSHER-Token-ID)\n");
if(route(PUSHER_PREPARE_PUSH)) {
if(lookup("location", "$hdr(X-KAZOO-AOR)") > 0) {
if(reg_fetch_contacts("location", "$hdr(X-KAZOO-AOR)", "callee")) {
$du = $(ulc(callee=>received));
$fs = $(ulc(callee=>socket));
xlog("L_INFO", "$ci|pusher|routing $hdr(X-KAZOO-AOR) to contact $du\n");
send_reply(100, "calling a push device");
route(PUSHER_TO_EXTERNAL_RELAY);
} else {
Expand Down Expand Up @@ -72,14 +77,25 @@ route[PUSHER_PREPARE_PUSH_PAYLOAD]
$sht(push_cache=>$var(TokenReg)) = 1;

### caller-id ###
$var(rp) = $hdr(Remote-Party-ID);
$var(from_user) = $(var(rp){tobody.user});
$var(from_name) = $(var(rp){tobody.display}{re.subst,/"//g});
if($hdr(Remote-Party-ID) != $null) {
$var(from_user) = $(hdr(Remote-Party-ID){tobody.user});
$var(from_name) = $(hdr(Remote-Party-ID){tobody.display}{re.subst,/"//g});
} else if($hdr(P-Asserted-Identity) != $null) {
$var(from_user) = $(hdr(P-Asserted-Identity){tobody.user});
$var(from_name) = $(hdr(P-Asserted-Identity){tobody.display}{re.subst,/"//g});
} else if($hdr(P-Preferred-Identity) != $null) {
$var(from_user) = $(hdr(P-Preferred-Identity){tobody.user});
$var(from_name) = $(hdr(P-Preferred-Identity){tobody.display}{re.subst,/"//g});
} else {
$var(from_user) = $(hdr(From){tobody.user});
$var(from_name) = $(hdr(From){tobody.display}{re.subst,/"//g});
}

$var(from) = $_s($var(from_user) - $var(from_name));


$var(PushPayload) = $_s({"call-id" : "$ci", "proxy" : "$var(TokenProxy)", "caller-id-number" : "$var(from_user)", "caller-id-name" : "$var(from_name)", "registration-token" : "$var(TokenReg)"});
$var(Payload) = $_s({ "Event-Category" : "notification", "Event-Name" : "push_req", "Call-ID" : "$ci", "Token-ID" : "$var(TokenID)", "Token-Type" : "$var(TokenType)", "Token-App" : "$var(TokenApp)", "Alert-Key" : "IC_MSG", "Alert-Params" : ["$var(from)"], "Sound" : "ring.caf", "Payload" : $var(PushPayload) });
$var(Payload) = $_s({ "Event-Category" : "notification", "Event-Name" : "push_req", "Call-ID" : "$ci", "Token-ID" : "$var(TokenID)", "Token-Type" : "$var(TokenType)", "Token-App" : "$var(TokenApp)", "Alert-Key" : "IC_SIL", "Alert-Params" : ["$var(from)"], "Sound" : "ring.caf", "Payload" : $var(PushPayload) });

$avp(push_routing_key) = "notification.push." + $var(TokenType) + "." + $var(TokenID);
$avp(push_payload) = $var(Payload);
Expand All @@ -106,7 +122,9 @@ route[PUSHER_ATTEMPT_REGISTRATION]
if($sht(push_cache=>$hdr(X-Token-Reg)) != $null) {
$var(password) = $null;
$sht(push_cache=>$hdr(X-Token-Reg)) = $null;
xlog("L_INFO", "$ci|pusher|registration with x-token-reg\n");
xlog("L_INFO", "$ci|pusher|registration with x-token-reg $hdr(X-Token-Reg)\n");
$xavp(ulattrs=>custom_channel_vars) = "{}";
$xavp(ulattrs[0]=>x_token_reg) = $hdr(X-Token-Reg);
route(SAVE_LOCATION);
} else {
xlog("L_INFO", "$ci|pusher|registration x-token-reg '$hdr(X-Token-Reg)' from header was not found\n");
Expand All @@ -118,6 +136,8 @@ route[PUSHER_ATTEMPT_REGISTRATION]
$var(password) = $null;
$sht(push_cache=>$(sel(contact.uri){uri.param,x-token-reg})) = $null;
xlog("L_INFO", "$ci|pusher|registration with x-token-reg $(sel(contact.uri){uri.param,x-token-reg})\n");
$xavp(ulattrs=>custom_channel_vars) = "{}";
$xavp(ulattrs[0]=>x_token_reg) = $(sel(contact.uri){uri.param,x-token-reg});
route(SAVE_LOCATION);
} else {
xlog("L_INFO", "$ci|pusher|registration x-token-reg from contact uri param '$(sel(contact.uri){uri.param,x-token-reg})' was not found\n");
Expand All @@ -129,17 +149,20 @@ route[PUSHER_ATTEMPT_REGISTRATION]
$var(password) = $null;
$sht(push_cache=>$(sel(contact){tobody.params}{param.value,x-token-reg})) = $null;
xlog("L_INFO", "$ci|pusher|registration with x-token-reg $(sel(contact){tobody.params}{param.value,x-token-reg})\n");
$xavp(ulattrs=>custom_channel_vars) = "{}";
$xavp(ulattrs[0]=>x_token_reg) = $(sel(contact){tobody.params}{param.value,x-token-reg});
route(SAVE_LOCATION);
} else {
xlog("L_INFO", "$ci|pusher|registration x-token-reg from contact param '$(sel(contact){tobody.params}{param.value,x-token-reg})' was not found\n");
}
}
}

route[PUSHER_ON_REGISTRATION]
{
if($(xavp(ulattrs=>custom_channel_vars){kz.json,Pusher-Application}{s.len}) > 0 && $var(Status) == "Registered") {
if( ( $(xavp(ulattrs=>x_token_reg){s.len}) > 0 ||
$(xavp(ulattrs=>custom_channel_vars){kz.json,Pusher-Application}{s.len}) > 0) &&
$var(Status) == "Registered") {
if($sht(push_cache=>$(tu{s.tolower})) != $null) {
xlog("L_INFO", "$ci|pusher|device registered, delivering the call\n");
$var(ref) = $sht(push_cache=>$(tu{s.tolower}));
Expand All @@ -153,7 +176,9 @@ route[PUSHER_ON_REGISTRATION]

route[PUSHER_DELIVER_CALL]
{
if(lookup("location", "$hdr(X-KAZOO-AOR)") > 0) {
if(reg_fetch_contacts("location", "$hdr(X-KAZOO-AOR)", "callee")) {
$du = $(ulc(callee=>received));
$fs = $(ulc(callee=>socket));
route(PUSHER_TO_EXTERNAL_RELAY);
} else {
t_reply(486, "Failed to lookup after resume");
Expand Down

0 comments on commit cef7614

Please sign in to comment.