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@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@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users