Monday, October 4, 2010

Best of New in Kamailio 3.1.0 - #7: Pre-processor Directives

Previous major version, 3.0.0, introduced for first time configuration file pre-processor directives that allowed to include files, define IDs and test their definition.

It was one of the most appreciated additions in 3.0.0, allowing to structure better the configuration file, to enable or disable features with one single line change.

Kamailio v3.1.0 added new features to these pre-processor directives:
  • defined IDs can take values, being either strings, integer or even statements
  • defined IDs with values are replaced across configuration file
  • new subst directive that does perl-like substitutions inside string values within configuration file
For example, the default configuration file for v3.1.0 defines DBURL token to be used for db_url parameters:
#!define DBURL "mysql://openser:openserrw@localhost/openser"
...
modparam("auth_db", "db_url", DBURL)
Changing access to database requires now to update a single place, the define of DBURL.

If you have pieces of config that repeat, you can define them and reuse:
#!define MYLOG xlog("[$Tf]: message $rm from $fu to $ru\n")
...
route {
...
MYLOG;
...
MYLOG;
...
}
...
The new subst allow replacement inside string values - example: replace DBPASSWD token with 123qaz in all strings inside configuration file:
#!subst "/DBPASSWD/123qaz/"
modparam("acc", "db_url", "mysql://user:DBPASSWD@localhost/db")
Note that defines and subst apply to all parts of configuration file, not matter are global parameters, module settings or routing blocks.

Another useful features related to config pre-processor directives is the ability to define IDs from command line using -A parameter:
kamailio -A MYVALUE=abc
You can see as well the core cookbook section for pre-processor directives:

No comments:

Post a Comment