# Forward REGISTER to Asterisk
route[REGFWD] {
if(!is_method("REGISTER"))
{
return;
}
if($hdr(Expires)==$null)
{
reg_fetch_contacts("location", "$sel(contact.uri)", "caller");
$var(i) = 0;
$var(j) = 0;
while($var(i) < $(ulc(caller=>count)))
{
if($(ulc(caller=>expires)[$var(i)])!=10)
{
$var(j) = $var(j) + 1;
}
$var(i) = $var(i) + 1;
}
if($var(j)>=1)
{
return;
}
}
$var(rip) = $sel(cfg_get.asterisk.bindip);
$uac_req(method)="REGISTER";
$uac_req(ruri)="sip:" + $var(rip) + ":" + $sel(cfg_get.asterisk.bindport);
$uac_req(furi)="sip:" + $au + "@" + $var(rip);
$uac_req(turi)="sip:" + $au + "@" + $var(rip);
$uac_req(hdrs)="Contact: <sip:" + $au + "@"
+ $sel(cfg_get.kamailio.bindip)
+ ":" + $sel(cfg_get.kamailio.bindport) + ">\r\n";
if($sel(contact.expires) != $null)
$uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $sel(contact.expires) + "\r\n";
else
$uac_req(hdrs)= $uac_req(hdrs) + "Expires: " + $hdr(Expires) + "\r\n";
uac_req_send();
}