[SR-Users] Inconsistent string interpolation

Daniel-Constantin Mierla miconda at gmail.com
Thu Oct 1 12:53:24 CEST 2015


Hello,

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.

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 :-)

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.

Instead of concatenation expression, you can use few other options:


- $_s(...) -- iirc, like:

$var(x) = $_s("sip:+$var(abc)-$var(def)-$si@$Ri:$Rp");

- pv_printf($var(x), ...)

Cheers,
Daniel
On 01/10/15 11:56, Sven Neuhaus wrote:
> Hello,
>
> I'm occasionally running into issues with inconsistent string
> interpolation in the kamailio.cfg.
>
> Here's the latest example. Take this line:
>
> $var(x) = "sip:+$var(abc)-$var(def)-$si@$Ri:$Rp";
>
> Here, the values of the variables will NOT be interpolated into the
> string. Instead, I have to use this:
>
> $var(x) = "sip:+" + $var(abc) + "-" + $var(def) + "-" + $si + "@" + $Ri
> + ":" + $Rp;
>
>
> However, when I have an instruction such as:
>
> append_hf("P-Asserted-Identity: $var(x)\r\n");
>
> Then string interpolation takes place (i.e. the value of $var(x) is put
> into the string.
>
> This is very confusing and error prone. Is it something that can be
> fixed? The behaviour should be consistent.
>
> -Sven
>
>
>
> _______________________________________________
> 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

-- 
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, Sep 28-30, 2015, in Berlin - http://asipto.com/u/kat

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20151001/91e23f6c/attachment.html>


More information about the sr-users mailing list