[SR-Users] Inconsistent string interpolation

Daniel-Constantin Mierla miconda at gmail.com
Fri Oct 2 08:38:33 CEST 2015

On 01/10/15 14:34, Sven Neuhaus wrote:
> Am 01.10.2015 um 12:53 schrieb Daniel-Constantin Mierla:
>> there are different actions, one is assignment of an expression and the
>> other is a function call. Functions can evaluate they parameters as they
>> need/want by having the appropriate C code inside.
> After I noticed the problem and tried to understand what was going on,
> that's what I came up with. That doesn't make it less error prone, however.
>> For assignments, that is the general interpreter which considers strings
>> as being the tokens in between quotes. Trying to interpret variables
>> inside the strings automatically won't work, because that will mean to
>> do it for cases when it should not happen (e.g., modparams or function
>> parameters that specify just name of variables). Of course, with some
>> extra coding to keep states of where that string is used might be
>> possible, but I think will make the interpreter too complex. I might be
>> wrong, so a patch is welcome to prove the otherwise :-)
> Ideally, all variables in double quoted strings should be interpolated
> and single quoted strings should not (the same way it is done in bash,
> Perl, PHP, Groove, Ruby and elsewhere).

In C is not :-) .

>> Some functions can evaluate the parameter content, some don't. And in
>> some cases, even there is a variable inside a parameter for a function,
>> it is not evaluated, but it is set. That's again based on the purpose of
>> the function.
> That's frightening!

Why? Do you know the purpose of parameters for C libc functions without
fist looking at the manual? One needs to retrieve values, so instead of
evaluating the value, is about setting the value.

>> Instead of concatenation expression, you can use few other options:
>> - $_s(...) -- iirc, like:
> That $_() is a useful thing to know.
>> $var(x) = $_s("sip:+$var(abc)-$var(def)-$si@$Ri:$Rp");
>> - pv_printf($var(x), ...)
> I looked up the documentation for pv_printf() in the KEx module and was
> baffled to see the variable name being passed as a string in the example
> ... "pv_printf("$ru", "sip:$rU@$fd");"   :-*

That's pretty much from day 0 of sip express router back in 2001 -- the
parameters of functions from modules had to be enclosed in double
quotes, not matter what they are. There was no support for expressions
as parameters for functions. Later there were some changes and some
parameters can be without double quotes, but that is not the general
rule -- if in double quotes, it should work always (for module functions).


Daniel-Constantin Mierla
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Book: SIP Routing With Kamailio - http://www.asipto.com
Kamailio Advanced Training - http://asipto.com/u/kat

More information about the sr-users mailing list