I am trying to have a failover route where if a initial relay fails , i can forward the same request to a second provider.
I am using a certain set of headers that help to authenticate over my providers. I am trying to update those headers. However update and removal both fail. The headers are still present. Please help me understand if i am wrong. Here's the code.
.....
route(GET_CREDENTIALS);
}
remove_hf_re("X-*");
append_hf("X-Src-IP: Trusted\r\n", "Call-ID");
append_hf("X-Identity: $hdr(X-Calling-User)\r\n", "Call-ID");
append_hf("X-Auth-ID: $avp(siptrunk_username)\r\n", "Call-ID");
$avp(realm) = $fd;
$rd = $avp(siptrunk_domain);
$var(duri) = "sip:"+$rU+"@"+$avp(siptrunk_proxy);
$du = $var(duri);
t_on_failure("UAC_AUTH");
if(!t_relay()) {
sl_reply_error();
exit;
}
}
failure_route[UAC_AUTH] {
if(t_check_status("(4|5)[0|8][0|2|3|4|6|8]")){
xlog("L_INFO","failover testing");
revert_uri();
route(FAILOVER);
}
if (t_check_status("40[17]")) {
xlog("got challenged \n");
uac_auth();
xlog("L_INFO", "Return code is $retcode");
$rd = $avp(siptrunk_proxy);
t_on_failure("UAC_AUTH");
t_relay();
}
}
route[FAILOVER]{
xlog("L_INFO","doing failover now.. ");
if($avp(failover_routing_id)!=$null) {
$avp(outbound_routing_id)=$avp(failover_routing_id);
xlog("L_INFO","Failover carrier credentials are..");
route(GET_CREDENTIALS);
#not adding headers now
remove_hf_re("X-*");
append_hf("X-Src-IP: Trusted\r\n", "Call-ID");
append_hf("X-Identity: $hdr(X-Calling-User)\r\n", "Call-ID");
append_hf("X-Auth-ID: $avp(siptrunk_username)\r\n", "Call-ID");
$avp(realm) = $fd;
$rd = $avp(siptrunk_proxy);
$var(duri) = "sip:"+$rU+"@"+$avp(siptrunk_proxy);
$du = $var(duri);
xlog("L_INFO","Destination Uri from failover is : $du");
t_on_failure("UAC_AUTH2");
if(!t_relay()) {
sl_reply_error();
exit;
}
exit;
}
}
failure_route[UAC_AUTH2] {
if(t_check_status("(4|5)[0|8][0|2|3|4|6|8]")){
xlog("L_INFO","Failover failed. cancelled call ");
exit;
}
if (t_check_status("40[17]")) {
xlog("got challenged \n");
uac_auth();
xlog("L_INFO", "Return code is $retcode");
$rd = $avp(siptrunk_proxy);
t_relay();
}
exit;
}