[SR-Users] extract part of string / INVITE

Alex Balashov abalashov at evaristesys.com
Wed Nov 13 12:22:42 CET 2013


Hi Oli,

On 11/13/2013 06:13 AM, Oliver Roth wrote:

> Hi all
>
> I need to extract a part of the INVITE msg:
>
> INVITE sip:+41796159999 at 82.197.185.185;user=CSC10824 SIP/2.0
>
> I need
>
> 10824
>
> in a avp variable.

Hi Oli,

The string you are operating on is called the Request URI, which is 
exposed by the $ru pseudovariable.  The best way to extract it is to use 
the transformations[1] specifically for extracting URI parameters, which 
is what 'phone' is:

   $avp(user_id) = $(ru{uri.param,user});

If you want '10824' rather than CSC, you can extract a substring:

   $avp(user_id) = $(ru{uri.param,user}{s.substr,3,0});

-- Alex

[1] Operations on strings and message parts:

     http://www.kamailio.org/wiki/cookbooks/4.0.x/transformations


-- 
Alex Balashov - Principal
Evariste Systems LLC
235 E Ponce de Leon Ave
Suite 106
Decatur, GA 30030
United States
Tel: +1-678-954-0670
Web: http://www.evaristesys.com/, http://www.alexbalashov.com/



More information about the sr-users mailing list