Kamailio - get first occurrence value of a param in a string

337 Views Asked by At

I need to get the value of first tgrp param in this string using Kamailio :

$var(x) = <sip:xxxxxxxxx;tgrp=0001000;[email protected]:5060;transport=UDP;user=phone;tgrp=237>

I’m trying $var(y) = $(var(x){param.value,tgrp}); but it’s getting the last value of tgrp which is 237>.

Noting that first tgrp is not always in the second index , some other parameters can be added to the string.

How to get the value of first occurrence of tgrp param ?

2

There are 2 best solutions below

0
arheops On

param.value string operations designed to work with unique params names.

You can loop over all params using for loop and checking {param.name,index}

0
miconda On

Try a solution based on xavp_params_explode():

Something like:

xavp_params_explode("$(var(x){s.unbracket})", "x");
xdbg("$xavp(x=>tgrp[0])"); # <- print the value of first parameter tgrp

The index [0] can be omitted, without it first value being returned, but if you want the second param value, then use [1] as index.