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

Fernando Frota M Morais frota at cecom.ufmg.br
Tue Feb 16 02:21:27 CET 2010


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

-- 
     Fernando Frota Machado de Morais
        Divisao de Redes de Comunicacao
        Centro de Computacao
        Universidade Federal de Minas Gerais
        Brasil
        Tel. +55(31)3409.4007  Fax. +55(31)3409.4004






More information about the sr-users mailing list