[SR-Users] Kamailio E164 Normalisation

Daniel Tryba d.tryba at pocos.nl
Mon Nov 2 18:52:50 CET 2015


On Monday 02 November 2015 17:28:29 Daniel Bryars wrote:
> So I'm investigating if it's possible to fix up the number and add the + in
> Kamailio. Clearly I could detect if the number starts with 44 and change
> this to +44, but this seems very brittle (what about other international
> numbers) - it there a proper way to do this, or a standard module?

I do it with a couple of regexps for $fU/$tU$rU. You just have to make some 
assumtions. It pretty stupid straight forward code, transforming to "e164 
plus" format and than back to the endpoint specific settings:

        $avp(ntU)=$tU;

        if($tU=~"^00[1-9][0-9]+$")
        {
                $avp(ntU)="+"+$(tU{s.substr,2,0});
        }
        else if($tU=~"^0[1-9][0-9]+$")
        {
                $avp(ntU)="+31"+$(tU{s.substr,1,0});
        }
        else if($tU~="^[2-8][0-9]{5,6}$")
        {
                $avp(ntU)="+31"+$avp(areacode)+$tU;
        }
        else 
        {
                $avp(ntU)="+"+$tU;
        }



and use $avp(ntU) with uac_replace_to (after modifiying $ntU to the format 
desired by endpoint (yet more regexps like above)).

Repeat for $fU and $rU. You might want to to this in an external script 
instead of kamailio config script though. 

If there is a better way, I'd like to know myself.





More information about the sr-users mailing list