Thursday, January 15, 2009

Send SIP Messages From Config File

You can initiate SIP messages from Kamailio (OpenSER) configuration file ...

uac module provides a new function that allow sending sip requests from configuration file:

- uac_send_req()

http://kamailio.org/docs/modules/devel/uac.html#id2467912


It opens the door for a new bunch of things you can do now. I can think of now:

1) send IM alerts on special events

route { 
$uac_req(method)="MESSAGE";
$uac_req(ruri)= "sip:alert[at]kamailio.org";
$uac_req(furi)="sip:server[at]kamailio.org";
$uac_req(hdrs)="Content-Type: text/plain\r\n";
$uac_req(body)="SIP request from:" + $si + ":" + $sp;
uac_send_req();
}


2) turn lamps on for some sip phones on some events - e.g., snom:

http://wiki.snom.com/Features/LED_Remote_Control


3) talk server-to-server - here one example can be building a platform with a central server for accounting. Accounting is done at 200ok. So each routing server will build a csv list (time,callid, from tag, to tag, invite from uri, invite r-uri):

onreply_route[1] {
  if(status!="200")
    return;
  $uac_req(method)="ACCOUNTING";
  $uac_req(ruri)="sip:store[at]accounting.kamailio.org";
  $uac_req(furi)="sip:server[at]server1.kamailio.org";
  $uac_req(hdrs)="Content-Type: text/accounting-csv\r\n";
  pv_printf($uac_req(body), "$TS,$ci,$ft,$tt,$T_req($fu),$T_req($ru)");
  uac_send_req();
}


note that $T_req() is given by tm module, also with Kamailio trunk:

http://www.kamailio.org/dokuwiki/doku.php/pseudovariables:devel#tm_module_pseudo-variables


The accounting server:

route{
  # you should check the source IP also
  if(method=="ACCOUNTING" && $rU="store")
  {
       sql_query("ca",
             "insert into accounting(timeval,callid,ftag,ttag,src,dst) values ('$(rb{s.select,0,,})','$(rb{s.select,1,,})', ...)",
             "ra");
      send_reply("200", "Stored");   
  }
}


... and you can put your imagination work ... there are plenty of new and cute features you can add on your service with this functionality ...

No comments:

Post a Comment