[Kamailio-Users] What is the best (and secure) way to change FROM_URI using regexp?

Daniel-Constantin Mierla miconda at gmail.com
Tue Feb 16 23:11:27 CET 2010


Hello,

On 02/16/2010 02:21 AM, Fernando Frota M Morais wrote:
> Before sending this message I looked for an answer and found some options, two
> of them are followed:
>
> 1) SUBST function, sample listed here:
>
> if (is_present_hf("User-Agent"))
>    {
>        remove_hf("User-Agent");
>        remove_hf("P-Asserted-Identity");
>        subst("/^From: \".+\" (<sip: *[a-zA-Z0-9_\.-]+<at>  .*>)/From: \1/ig");
>        subst("/^To: \".+\" (<sip: *[a-zA-Z0-9_\.-]+<at>  .*>)/To: \1/ig");
>     }
>
> 2-a) uac_replace:
>
> if (from_uri=~"^sip:10804007\@voip.mydomain") {
>                xlog("L_ALERT", "TESTANDO - Original From is ($fu-$fn)\n");
>   #              uac_replace_from("sip:031" . $fU . "\@voip.mydomain");
>                 uac_replace_from("Frota10804007","sip:03110804007 at voip.mydomain");
> 	       xlog("L_ALERT", "TESTANDO - From changed to ($fu-$fn)\n");
> };
>
> OR :
>
> 2-b) uac _replace #2:
>
> if (from_uri=~"^sip:10804007\@.*") {
>                  xlog("L_ALERT", "Route 21 - Original from is ($fu-$fn)\n");
>                  $avp(from)=$fu;
> #               $avp(to)=$ru;
> #               avp_pushto("$ru", "$avp(from)");
>                  avp_subst("$avp(from)", "/(sip:)/sip:031/");
>                  uac_replace_from("$avp(from)");
> #               xlog("L_ALERT", "Route 21 - From changed to ($fu-$fn)\n");
> #               avp_pushto("$ru", "$avp(to)");
>          };
> }
> OR
>
>
> Looks like uac_replace is safer then "subst" function, because it can be
> reverted, but I did not found a way to use concatenation or any other kind of
> string operation as a parameter for it.

the parameters can be pseudo-variables, so you can build value there.

Cheers,
Daniel

>   I don't want to start a discussion, I
> need only a few lines showing me how to change from_uri_from  from
> "sip:108xxxx" to "sip:031108xxxx".
>
> Thanks in advance,
>
>    

-- 
Daniel-Constantin Mierla
SIP Server Professional Solutions
* http://www.asipto.com/





More information about the sr-users mailing list