cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2056
Views
0
Helpful
2
Replies

LUA script to modify privacy inbound invite

Gaurav Purohit
Level 1
Level 1

Hi,

I'm struggling to get my LUA script to work. The RightFax server on other end does not allow SIP parameters to be altered and sends a basic invite with no privacy option. I'd like to alter my inbound invites to add P-Asserted-ID and alter From field. Here is my LUA script:


M = {}
trace.enable()
function M.inbound_INVITE(msg)
--get Header Values
local uriString = msg:getUri("From")
local nuri = sipUtils.parseUri(uriString)
trace.format("Parse success")
local nUser = nuri:getUser()
trace.format("user is '%s'", nUser)
local nHost = nuri:getHost()
trace.format("host is '%s'", nHost)
--get tag from From header
local fromtag = msg:getHeaderValueParameter("From", "tag")
trace.format("tag from From is '%s'", fromtag)
--create new from header
local newFromHeader = string.format("\"Anonymous\" <sip:Anonymous@%s>;tag=%s\r\n", nHost, fromtag)
trace.format("new From Header is '%s'", newFromHeader)
msg:modifyHeader("From", newFromHeader)
trace.format("From Header is updated successfully")
--create Remote party ID string with privacy
local newRPartyHeader = string.format("<sip:%s@%s>;party=calling;id-type=subscriber;privacy=full;screen=yes\r\n", nUser, nHost)
trace.format("header string created '%s'", newRPartyHeader)
--Add Remote party ID (not added for now)
--msg:addHeader("Remote-Party-ID", newRPartyHeader)
local newPAIHeader = string.format("\"RightFax\" <sip:%s@%s>\r\n", nUser, nHost)
trace.format("PAI header string created '%s'", newPAIHeader)
msg:addHeader("P-Asserted-Identity", newPAIHeader)
local ids = string.format("id\r\n")
trace.format("Adding ID")
msg:addHeader("Privacy", ids)
trace.format("All Done\r\n")
end
return M

Original Invite from RightFax:

INVITE sip:0385410508@172.22.5.31 SIP/2.0
From: Rightfax Dev <sip:0397277670@172.22.31.185>;tag=8be2690-b91f16ac-13c4-55013-312cf8-26efef6b-312cf8
To: <sip:0385410508@172.22.5.31>
Call-ID: 776a928-b91f16ac-13c4-55013-312cf8-70e1aefd-312cf8
CSeq: 1 INVITE
Via: SIP/2.0/UDP 172.22.31.185:5060;branch=z9hG4bK-312cf8-c017a9f1-27c0c9e1
Supported: 100rel
Max-Forwards: 70
User-Agent: Brktsip/6.5.2B5 (Dialogic)
Contact: <sip:172.22.31.185:5060>
Content-Type: application/sdp
Content-Length: 150

v=0
o=- 2212556890 0340060000 IN IP4 172.22.31.185
s=no_session_name
t=0 0
m=audio 56300 RTP/AVP 0
c=IN IP4 172.22.31.185
a=rtpmap:0 pcmu/8000

Altered Invite from RightFax:

INVITE sip:0385410508@172.22.5.31 SIP/2.0
From: "Anonymous" <sip:Anonymous@172.22.31.185>;tag=8be2690-b91f16ac-13c4-55013-312cf8-26efef6b-312cf8

P-Asserted-Identity: "RightFax" <sip:0397277670@172.22.31.185>

Supported: 100rel
Content-Length: 150
User-Agent: Brktsip/6.5.2B5 (Dialogic)
Privacy: id

To: <sip:0385410508@172.22.5.31>
Contact: <sip:172.22.31.185:5060>
Content-Type: application/sdp
Call-ID: 776a928-b91f16ac-13c4-55013-312cf8-70e1aefd-312cf8
CSeq: 1 INVITE
Via: SIP/2.0/UDP 172.22.31.185:5060;branch=z9hG4bK-312cf8-c017a9f1-27c0c9e1
Max-Forwards: 70

v=0
o=- 2212556890 0340060000 IN IP4 172.22.31.185
s=no_session_name
t=0 0
m=audio 56300 RTP/AVP 0
c=IN IP4 172.22.31.185
a=rtpmap:0 pcmu/8000

Error:

SIP/2.0 400 Bad Request - 'Malformed/Missing FROM: field'

1 Accepted Solution

Accepted Solutions

Mark Stover
Cisco Employee
Cisco Employee

Try removing ‘\r\n’ from your formatted strings. The header functions will insert those correctly.

View solution in original post

2 Replies 2

Mark Stover
Cisco Employee
Cisco Employee

Try removing ‘\r\n’ from your formatted strings. The header functions will insert those correctly.

Thanks heaps!

Can't believe I was so close.

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: