cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3394
Views
10
Helpful
3
Replies

SIP Normalization Script Assistance

rynard.coetzee
Level 1
Level 1

Hi All

I hope someone can possible assist me here ,we have a CUCM version 11.5 that has a Trunk to a Genesys server ,problem is that randomly the Genesys server sends a SIP Invite with a malformed x-farenaddr in the From field. 

Below is an excerpt of what it looks like :

SIP From URI parameter: x-farendaddr=%23msml=T9LOJ5CEUL3MH2678AI75CUTIG0008NB

I am looking for a normalization script that will match all calls that have the x-farendaddr as "=%23msml=" and replace that with "x-farendaddr=unknown

I have the following which i have tried to construct using multiple sources ,but i might be completely missing it here ,any assistance will be greatly appreciated :

 

M={}

function M.inbound_INVITE(msg)

local from = msg:getHeader("From") --Get FROM Header

local b = string.gsub(from, "x-farendaddr=%23msml=*", "x-farendaddr=unknown") --New FROM Header

msg:modifyHeader("From", b) --Replace FROM Header

end

return M

 

1 Accepted Solution

Accepted Solutions

Complete code:

 

M={}

function M.inbound_INVITE(msg)

local from = msg:getHeader("From") --Get FROM Header

if string.match(from,'x-farendaddr=%%23msml=') then
    from=string.gsub(from,"=.+=.+","=unknown")
    msg:modifyHeader("From", from) --Replace FROM Header
end

end

 

return M

View solution in original post

3 Replies 3

davidn#
Cisco Employee
Cisco Employee

Rynard,

 

Try this:

 

if string.match(from,'x-farendaddr=%%23msml=') then
    from=string.gsub(from,"=.+=.+","=unknown")
end

 

HTH.

 

-david

Complete code:

 

M={}

function M.inbound_INVITE(msg)

local from = msg:getHeader("From") --Get FROM Header

if string.match(from,'x-farendaddr=%%23msml=') then
    from=string.gsub(from,"=.+=.+","=unknown")
    msg:modifyHeader("From", from) --Replace FROM Header
end

end

 

return M

Thank you David , that looks like it will work ,we are currently testing with the following script which our Recording guys wrote :

M = {}
trace.disable()
-- trace.enable()

-- Remove potentially invalid x-farendaddr parameter from From address
-- Reason: sometimes the value contains a "=" (not valid), which causes DataVoice recorder to ignore the INVITE
-- ASSUME: x-farendaddr a parameter INSIDE address i.e. somewhere before ">"
-- Cater for situation where x-farendaddr is the last parameter AND where it is not.

-- To see tracing output - SSH to CUCM: file tail activelog /cm/trace/ccm/sdl recent regexp "SIPLua"

function M.outbound_INVITE(msg)

local fromHdr = msg:getHeader("From")

trace.format("DataVoice | old From: %s", fromHdr)

local pos1 = string.find(fromHdr, "x-farendaddr=", 1, true)
local posOfNextGT = string.find(fromHdr, ">", pos1, true)
local posOfNextSemicolon = string.find(fromHdr, ";", pos1, true)
local pos2 = nil

if posOfNextGT ~= nil then
if (posOfNextSemicolon == nil) or (posOfNextGT < posOfNextSemicolon) then
-- last parameter
pos2 = posOfNextGT
else
-- not the last parameter
pos2 = posOfNextSemicolon
end
local newHdr = string.sub(fromHdr, 1, pos1 - 1).."x-farendaddr=Removed_for_DV"..string.sub(fromHdr, pos2)
trace.format("DataVoice | new From: %s", newHdr)

msg:modifyHeader("From", newHdr)
else
trace.format("DataVoice | unexpected - did not find a '>'")
end

end
return M