[SR-Users] Kamailio config file String Concatenation

George Diamantopoulos georgediam at gmail.com
Wed May 2 19:52:03 CEST 2018


Thank you both, this has been quite informative. I wasn't also aware of the
$_s() PV, it's handy indeed. Three more clarifications:

- Will $_s() work before the routing part of the config file, and
specifically with pre-processor definitions? For example in the following:

modparam("nathelper", "sipping_from", $_s(sip:keepalive at SIP_REALM_DEFINITION
))?

- Will providing PVs in a dynamic string work with all functions, even for
those currently not supporting string concatenation? E.g.:

append_hf_value("P-Asserted-Identity", "<$var(new_pai)>");

If yes, I assume this will only work for PVs, as preprocessor defined
strings won't be substituted if the parser finds their labels enclosed in
quotes. In other words, the following won't work:
append_hf_value("P-Asserted-Identity", "<$var(new_pai);SOME_DEF>");

- I assumed this would work in the first example, but maybe I should ask
explicitly. Will pre-processor defines work with the $_s() PV? Is this
valid at all?

$_s($ru;SOME_PREPROC_DEF=$var(value))

BR,
George

On 2 May 2018 at 20:07, Daniel-Constantin Mierla <miconda at gmail.com> wrote:

> Hello,
>
> indeed, there is some inconsistency here brought in after the merge with
> SIP Express Router back in 2008.
>
> Traditionally, Kamailio (or openser before 2008) didn't support
> concatenation expressions as function parameters. That came via SER
> branch and it is not available everywhere in a consistent and coherent
> way (even for the code of modules imported from SER).
>
> If you want to be in the safe side from Kamailio behaviour point of
> view, as I never got into using SER style, here are some hints based on
> what I typically do:
>
>   - use concatenation expressions with '+' only in assignments, like:
>
> $var(x) = "string1" + "string2";
>
>   - use dynamic strings with variables as function parameters, like:
>
> xlog("L_ERR", "string $var(x) more-string $var(y)\n");
>
>   - use and assignment to a private variable first or $_s(...) variable
> on positions that expect a string or a var, such as transformation
> parameters, like:
>
> $var(r) = "repl1" + "repl2";
> $var(x) = $(var(y){s.replace,match,$var(r)});
>
> Cheers,
> Daniel
>
> On 02.05.18 17:05, Alex Balashov wrote:
> > You are correct that concatenation vs interpolation works and doesn't
> work in slightly inconsistent ways, for instance function string arguments
> vs assignment.
> >
> > The $_s() transformation may help make life easier.
> >
> > On May 2, 2018 10:50:53 AM EDT, George Diamantopoulos <
> georgediam at gmail.com> wrote:
> >> Hello,
> >>
> >> I'm a a bit confused as to when string concatenation will work in
> >> kamailio
> >> config file. So far I have identified the following cases:
> >>
> >> Working:
> >>
> >> As part of the right hand side of an assignment:
> >> $var(x) = "string1" + "string2";
> >>
> >> String argument of some functions:
> >> xlog("L_ERR", "string1" + "string2" + DEFINED_STRING + '\n');
> >>
> >> Conditional Statements:
> >> if ( ru =~ "$" + "sip:" + $var(user) ) {
> >>
> >> Not Working:
> >>
> >> In string transformations (the fact that quotes is not part of the
> >> argument
> >> should give a hint though:
> >> $var(x) = $(var(y){s.replace,match,"repl1" + "repl2"});
> >>
> >> String argument of some other functions:
> >> append_hf_value("P-Asserted-Identity", "<" + "$var(new_pai)" + ">");
> >> lookup("location", "sip:$var(username)@" + SIP_REALM_DEFINITION));
> >>
> >> In module parameter definitions:
> >> modparam("nathelper", "sipping_from", "sip:keepalive@" +
> >> SIP_REALM_DEFINITION)
> >>
> >> So far, I have found this to be fairly consistent, except for use
> >> within
> >> functions. For example, string concatenation works for the second
> >> argument
> >> of xlog, but not for the string arguments of append_hf_value() or
> >> lookup().
> >>
> >> Is there anyway to know this for each function beforehand, or is my
> >> only
> >> choice to go through trial and error here? Thanks!
> >>
> >> BR,
> >> George
> >
> > -- Alex
> >
> > --
> > Sent via mobile, please forgive typos and brevity.
> >
> > _______________________________________________
> > Kamailio (SER) - Users Mailing List
> > sr-users at lists.kamailio.org
> > https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>
> --
> Daniel-Constantin Mierla
> www.twitter.com/miconda -- www.linkedin.com/in/miconda
> Kamailio World Conference - May 14-16, 2018 - www.kamailioworld.com
>
>
> _______________________________________________
> Kamailio (SER) - Users Mailing List
> sr-users at lists.kamailio.org
> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20180502/53faccdf/attachment.html>


More information about the sr-users mailing list