07-31-2018 05:01 PM - edited 03-18-2019 12:28 PM
Hello,
I'm trying to write sip profile that truncates the 10-digit Diversion number dow to the last 4-digits and re-writes that number back into the Diversion header, but I'm not very succesful. I've written may copy and writes to different headers, but never had a need to first truncate a part of the header and re-write. For example (IP addresses changed for privacy):
I need the original Diversion header of
Diversion: <sip:1234563333@192.168.0.1:5060;user=phone>
To be changed to:
Diversion: <sip:3333@192.168.0.1:5060;user=phone>
Can someone help with the profile rule to make this happen?
Best,
07-31-2018 06:03 PM - edited 07-31-2018 07:06 PM
This is a perfect use case for the SIP Profile Test Tool
SIP Profile
voice class sip-profiles 1 request INVITE sip-header Diversion modify "sip:\d*(\d{4})@" "sip:\1@" !
SIP Input Message
INVITE sip:user@domain SIP/2.0 Diversion: <sip:1234563333@192.168.0.1:5060;user=phone>
SIP Profile Magic
INVITE sip:user@domain SIP/2.0 Diversion: <sip:3333@192.168.0.1:5060;user=phone>
The magic is in the regular expression matching pattern: sip:\d*(\d{4})@
Let's break that down.
First up, we have a prefix on our pattern, which if it doesn't exist, then we'll ignore the input. This is a pretty standard way of qualifying the input.
sip: matches Diversion: <sip:1234563333@192.168.0.1:5060;user=phone>
Then we stipulate that the next character could be missing, but if it's present, it has to be a digit, and there could be more than on of them.
\d* matches Diversion: <sip:1234563333@192.168.0.1:5060;user=phone>
If you're wondering why it didn't match the entire number, it's because we then stipulate that there must be at least 4 digits in there, after those optional leading digits.
(\d{4}) matches Diversion: <sip:1234563333@192.168.0.1:5060;user=phone>
The parenthesis around it simply means "remember what you matched." This is because the modify command, requires that we replace whatever we matched with something else, and we want to be able to reference something we matched; in this case, the last 4 digits.
Lastly, much like the prefix matching, we match postfix, and stipulate that the number should be followed by an at sign (@).
@ matches Diversion: <sip:1234563333@192.168.0.1:5060;user=phone>
Ok, this is actually the last part, we have to do the replace, on what we matched. So we specify our prefix and postfix yet again, followed by recalling what we told the profile to remember about our match.
sip:\1@
08-01-2018 08:39 AM
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide