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
#!define DBURL "mysql://openser:openserrw@localhost/openser"Changing access to database requires now to update a single place, the define of DBURL.
modparam("auth_db", "db_url", 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")The new subst allow replacement inside string values - example: replace DBPASSWD token with 123qaz in all strings inside configuration file:
#!subst "/DBPASSWD/123qaz/"Note that defines and subst apply to all parts of configuration file, not matter are global parameters, module settings or routing blocks.
modparam("acc", "db_url", "mysql://user:DBPASSWD@localhost/db")
Another useful features related to config pre-processor directives is the ability to define IDs from command line using -A parameter:
kamailio -A MYVALUE=abcYou can see as well the core cookbook section for pre-processor directives:
Post a Comment