Kamailio Advanced Training
Click here for more details!

Learn how to build RTC services with Kamailio!

Sunday, January 17, 2010

Best of New in Kamailio 3.0.0 - #19: htable

This is the last post in this series. It is still a lot to talk about, but now is time for new development. You can check the wiki page with what is new in Kamailio (OpenSER) 3.0.0:

http://www.kamailio.org/dokuwiki/doku.php/features:new-in-3.0.x

I am stopping just a bit to hash table module, the one that provides a shared caching system in config file. You can load at start time values from a database in shared memory and then get/set them at runtime.

The module can cope with many hash tables at same time. The items in tables can have expire time, being automatically deleted if there is no updated done to them.

The 3.0.0 brings couple of enhancements to this module:
  • run a routing block at start time - event_route[htable:mod-init] - is executed just after the module has been initialized, allowing you to set initial values in hash tables. Note that you can us this route block to initialize parameters and script variables for other modules
  • count items in a table by regular expression over the value
  • count items in a table by regular expression over the name

Here is a simple example of how to count active calls done by each user and limit to 3:
...
modparam("htable", "htable", "acalls=>size=8;")
...
route {
...
if(is_method("INVITE") && !has_totag())
{
# a new call
if($shtcv(ht=>^$fU$)>=3)
{
send_reply("403", "limit exceeded");
exit;
}
$sht(acalls=>$ci) = $fU;
t_on_failure("NEW_INVITE");
}

if(is_method("BYE"))
{
$sht(acalls=>$ci) = $null;
}
...
}

failure_route[NEW_INVITE] {
$sht(acalls=>$ci) = $null;
}
For more see module's readme:
http://kamailio.org/docs/modules/3.0.x/modules_k/htable.html

Best of New in Kamailio 3.0.0 - Table of Content.

No comments:

Post a Comment