[SR-Users] Can following scenario be implemented using Kamilio

Alex Balashov abalashov at evaristesys.com
Tue Mar 3 18:31:13 CET 2015


On 03/03/2015 12:21 PM, Daniel Tryba wrote:

>                  $var(contact) = $T_rpl($ct);
>                  $var(contact) = $(var(contact){re.subst,/^<(sip:\+?
> [0-9]+ at .*)>$/\1/});

I would recommend, from a best-practical perspective, not doing this 
substitution, but instead using transformations[1] to extract the URI. 
The Contact header is a "name-address pair", so you can extract the URI 
component this way:

    $var(contact) = $(T_rpl($ct){nameaddr.uri});

There are many reasons for doing this, but the most significant is that 
the formal properties of a grammatically correct SIP URI are actually 
quite complex and certainly go beyond <(sip:\+?>[0-9]+ at .*)>:

1. The URI scheme doesn't have to be sip:, but can also be sips:.

2. The user part of the RURI doesn't have to be numeric, but can be 
alphanumeric and also contain quite a lot of symbols (e.g. '+').

3. The @domain portion is optional.

    sip:1.2.3.4:5060 is a valid URI.

4. In a name-address header like Contact, the URI is not required to be 
encapsulated in <>s, although practically, it most often is.

This is a valid Contact header:

    Contact: sip:user at 1.2.3.4:5060

-- Alex

[1] http://www.kamailio.org/wiki/cookbooks/4.2.x/transformations, 
specifically:

http://www.kamailio.org/wiki/cookbooks/4.2.x/transformations#nameaddruri


-- 
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