Monday, December 28, 2009

Best of New in Kamailio 3.0.0 - #9: event_route

The event_route is offering a framework for developers to give script writers more control when special events happen. Unlike the other routing blocks which were designed to process SIP messages, the event_route can be triggered by a non-SIP-related event as well.

An example is event_route[htable:mod-init] which is executed by htable module when it is initialized. Practically, the event_route is executed once, when Kamailio (OpenSER) starts. The main goal for event_route[htable:mod-init] is to allow initializations at startup -- can be variables from htable or other modules.
...  
event_route[htable:mod-init] {
$sht(a=>x) = 1;
$shv(counter) = 0;
sql_query("insert into restarts (start_time) values ('$Tf')");
}
...

Another event_route is exported by tm module: event_route[tm:local-request] - which is executed when tm generates internally and sends a SIP request. Such cases are:
  • SIP messages sent by msilo module
  • SIP messages sent by presence server
  • SIP messages sent by dialog module
  • SIP messages sent via MI or CTL interfaces
Examples of usage:
  • log details about local request
  • account the local request
  • apply filters to local generated requests
...  
event_route[tm:local-request] {
xlog("request [$rm] from [$fu] to [$ru]\n");
}
...
Among the benefits of event_route:
  • new events can be exported and fired by any module
  • no need to extend the config grammar when adding a new event
  • various variables can be made available when the event is fired to be used inside the event_route
  • no need to have SIP message to be processed
For the future I expect several events to be added, for example:
  • when a location contact expires
  • timer-based events (rtimer module to migrate from using route to using event_route blocks)
  • when dialog module sends BYE on timeout
Next episode to be about: topology hiding module.

No comments:

Post a Comment