[SR-Users] new features: extended cfg preprocessor directives
Alex Balashov
abalashov at evaristesys.com
Wed May 5 21:03:24 CEST 2010
Daniel,
Can values of a preprocessor ID be tested in the preprocessor itself,
like #if?
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: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
>
>
>
> _______________________________________________
> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
> sr-users at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
--
Alex Balashov - Principal
Evariste Systems LLC
1170 Peachtree Street
12th Floor, Suite 1200
Atlanta, GA 30309
Tel: +1-678-954-0670
Fax: +1-404-961-1892
Web: http://www.evaristesys.com/
More information about the sr-users
mailing list