We need to make 2 transformations in URI and To field
1. Convert telephone number to to format E.164
2. To correct a domain part of the address if it is set incorrectly by
stupid UA
All this is done through set of if operators because every of
transformations can be absent or can be done on own algorithm. Let's
consider a special case. We have on an input 799111(a)62.33.22.14 and on
an output should receive 78142799111(a)voapp.ru
URI will be transformed by these commands
subst_uri("/^sip:([0-9]+)@(.*)/sip:78142\1@\2/i");
subst_uri("/^sip:([0-9]+)@(.*)/sip:\1@voapp.ru/i");
To field will be transformed by these commands
subst("/^To:(.*)sip:([0-9]+)@(.*)/To:\1sip:78142\2@\3/i");
subst("/^To:(.*)sip:([0-9]+)@([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)(.*)/
To:\1sip:\2@voapp.ru\7/i");
We test and get dump of messages using tcpdump
We receive from UA
INVITE sip:705353@62.33.22.14 SIP/2.0
Via: SIP/2.0/UDP 192.168.13.15
From: ......._1 <sip:gan@192.168.13.15>;tag=22683200-29298-10909
To: <sip:705353@62.33.22.14>
............
We make transformation and sent following:
INVITE sip:78142705353@voapp.ru SIP/2.0
Max-Forwards: 10
Record-Route: <sip:62.33.22.14;ftag=22683200-29298-10909;lr>
Via: SIP/2.0/UDP voapp.ru:5060;branch=z9hG4bKa4db.e5fa9a02.0
Via: SIP/2.0/UDP 192.168.13.15;rport=53809;received=217.107.59.194
From: ......._1 <sip:gan@192.168.13.15>;tag=22683200-29298-10909
To: <sip:78142705353@62.33.22.14>
To: <sip:705353@voapp.ru>
...............
As you can see URI was transformed correctly
And instead of To field we have 2 To fields everyone corresponding to
one of transformations.
It is a bug? Or it is feature OpenSER? Whether it is possible to bypass
this restriction?
I understand that it is possible to make one subst call instead of two
calls.
subst("/^To:(.*)sip:([0-9]+)@([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)(.*)/
To:\1sip:78142\2@voapp.ru\7/i");
But in a reality the algorithm is much more complex. And that instead of
several consecutive transformations to leave one it is required to use a
many of if operators. It is very inconvenient, conducts to mistakes and
reduces readability of a code.
Dmitry