0

Please help me to get the a value from SIP INVITE header reached to kamailio like INVITE sip:+341930203454@sub.domain.com;myid=+34@sub.domain.com SIP/2.0 and i want to save the myid value +34 into a variable, without the domain name.

     $var(uri) = $sel(ruri);
     xavp_params_explode("$(var(uri){s.unbracket})", "uri");
     xlog("L_INFO", "$var(uri) Received converted to $xavp(uri=>myid[0])\n");

I tried above and it prints +34@sub.domain.com But i want to just save +34 into a variable to further check the prefix based routing from the database.

Could you please help how to get it or If there is any alternate/single line approach to get this value, please help.

thanks in advance.

Sheldon
  • 169
  • 1
  • 2
  • 16

2 Answers2

2

An one line statement variant can be:

$var(result) = $(ru{uri.param,myid}{s.select,0,@});

Where:

  • $ru - is the request URI (sip address in the first line of request)
  • {uri.param,myid} - is a transformation returning the value of a parameter (myid in this case) in a URI
  • {s.select,0,@} - is a transformation returning first token from a string by splitting it using the delimiter @
miconda
  • 1,754
  • 11
  • 14
0

I think something like this will work:

$var(uri) = $sel(ruri);
$var(myid-param) = $(var(uri){param.value,myid}); # this should return +34@sub.domain.com
$var(sip-myid-param) = "sip:" + $var(myid-param); # this should return sip:+34@sub.domain.com
$var(user-part) = $(var(sip-myid-param){uri.user}); # this should return +34

All above string operation is possible to put in one line, I used several lines just to show it in simple way.

In one line it should be something like below, but please do not quote me on this, but I hope you can get an idea

$var(user-part) = $(var("sip:" + $var($(var(uri){param.value,myid}))){uri.user});
os11k
  • 1,210
  • 2
  • 13
  • 26
  • 1
    The one line is not going to work, the name of a $var(name) cannot be build with an expression like "sip" + ... It has to be a static string. – miconda Dec 06 '20 at 16:54