[SR-Users] new features: extended cfg preprocessor directives

Daniel-Constantin Mierla miconda at gmail.com
Wed May 5 20:55:16 CEST 2010


Hello,

just to let you know about some new features related to config 
preprocessing. 3.0 added config preprocessor directives such as 
'include_file' and 'define'. But the define could be used only to 
control which parts of config file are active.

Several days ago I committed the code to allow you 'define' values for 
IDs, like:

#!define MYINT 123
#!define MYSTR "xyz"

The defined IDs are replaced at startup, during config parsing, e.g.,:

$var(x) = 100 + MYINT;

- is read as:

$var(x) = 100 + 123;

Moreover, you can have multi-line defined IDs:

#!define IDLOOP     $var(i) = 0; \
                 while($var(i)<5) { \
                     xlog("++++ $var(i)\n"); \
                     $var(i) = $var(i) + 1; \
                 }

- then in routing block

route {
     ...
     IDLOOP
     ...
}

A completely new thing is the substitution preprocessor directive:

#!subst "/regexp/subst/"

Defined IDs are not replaced within string values (because a cfg IDs is 
a standalone alphanumeric token, not enclosed in single or double 
quotes), so if you need to change something inside a string within 
config file, then use substitution. For example, if you want to replace 
the password in all db_url module parameters:

#!subst "/DBPASSWD/xyz/"

modparam("acc", "db_url", "mysql://user:DBPASSWD@localhost/db")
modparam("auth_db", "db_url", "mysql://user:DBPASSWD@localhost/db")

The value of a 'subst' directive can be any valid perl-like substitution 
expression, you can use wildcards, group tokens, backreferences, ....

Hope this will make your cfg scripting easier. Testing and feedback is 
appreciated.

Cheers,
Daniel

-- 
Daniel-Constantin Mierla
* http://www.asipto.com/
* http://twitter.com/miconda
* http://www.linkedin.com/in/danielconstantinmierla

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20100505/b42380b6/attachment.htm>


More information about the sr-users mailing list