Hello,

On 5/5/10 9:03 PM, Alex Balashov wrote:
Daniel,

Can values of a preprocessor ID be tested in the preprocessor itself, like #if?

by now there is no #!if, only #!ifdef/#!ifndef which return true/false if the ID was defined.

Cheers,
Daniel


Thanks,

-- Alex

On 05/05/2010 02:55 PM, Daniel-Constantin Mierla wrote:

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:dbpas...@localhost/db")
modparam("auth_db", "db_url", "mysql://user:dbpas...@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



_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users



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


_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
sr-users@lists.sip-router.org
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

Reply via email to