Table Of Contents
SIP URI APIs
applyNumberMask
getHost
getUser
encode
SIP URI APIs
The Lua environment provides a set of APIs that allows a parsed SIP URI to be manipulated. The following SIP URI APIs are availabe:
•
applyNumberMask
•
getHost
•
getUser
•
encode
applyNumberMask
applyNumberMask(mask, mask-char)
Given a number mask, this function applies the specified number mask to the user part of the parsed URI and stores the modified user in the parse sipUri object. A string representation of the user part of the modified URI is returned.
Application of the number mask
The mask parameter defines the transformation to be applied to the user part of the URI.. The upper case "X" specifies the wildcard portion of the number mask. For example, if the mask "+1888XXXXXXX" and mask is applied to the example user part "4441234", the resulting sting is "+18884441234".
If the number of characters found in user part to be masked is less than the number of wildcard characters in the mask, the left most wildcard characters will left as "X". Applying the previous mask to the example user part "1234" yields the resulting string "+1888XXX1234". If the number of characters found in the user part to be masked is greater than the number of wildcard characters in the mask, the left most characters of the user part are truncated. For example, if the mask "+1888XXXX" is applied to the user part "4441234", the resulting string is "+18881234".
Example: Set a local variable to the value of the user part of URI in the P-Asserted-Identity after having applied a number mask to the user part of the URI
Script
function M.inbound_INVITE(msg)
local uriString = msg:getUri("P-Asserted-Identity")
local uri = sipUtils.parseUri(uriString)
local user = uri:applyNumberMask("+1919476XXXX")
Message
INVITE sip:1234@10.10.10.1 SIP/2.0
P-Asserted-Identity: <sip:1234@10.10.10.1>
Output/Results
Local variable user is set to "+19194761234"
getHost
This function retrieves the host portion of the parsed sipUri object and returns it to the caller as a string.
Example: Set a local variable to the host portion of the URI in the P-Asserted-Identity header.
Script
function M.inbound_INVITE(msg)
local uriString = msg:getUri("P-Asserted-Identity")
local uri = sipUtils.parseUri(uriString)
local host = uri:getHost()
Message
INVITE sip:1234@10.10.10.1 SIP/2.0
P-Asserted-Identity: <sip:1234@10.10.10.1>
Output/Results
Local variable host is set to "10.10.10.1"
getUser
This function retrieves the user portion of the parsed sipUri object and returns it to the caller as a string.
Example: Set a local variable to the user portion of the URI in the P-Asserted-Identity header
Script
function M.inbound_INVITE(msg)
local uriString = msg:getUri("P-Asserted-Identity")
local uri = sipUtils.parseUri(uriString)
local user = uri:getUser()
Message
IINVITE sip:1234@10.10.10.1 SIP/2.0
P-Asserted-Identity: <sip:1234@10.10.10.1>
Output/Results
Local variable user is set to "1234"
encode
This function encodes the parsed sipUri object into a string and returns it to the caller. Any changes made to the parsed sipUri object prior to encoding will be reflected in the resulting string.
Example: Parse the URI from the P-Asserted-Identity header, apply a number mask, and then encode the resulting URI
Script
function M.inbound_INVITE(msg)
local uriString = msg:getUri("P-Asserted-Identity")
local uri = sipUtils.parseUri(uriString)
uri:applyNumberMask("+1919476XXXX")
Message
INVITE sip:1234@10.10.10.1 SIP/2.0
P-Asserted-Identity: <sip:1234@10.10.10.1>
Output/Results
Local variable uriString is set to "<sip:+19194761234@10.10.10.1>"