Dave_Wiley
Feb 20, 2006Nimbostratus
SIP Rule to Insert Data into method CANCEL
Greetings! I wrote the following iRule in order to overcome a very specific problem with a SoftSwitch that's handling SIP signaling. The problem only occurs when someone enters *67 before they dial to make themselves anonymous and then they hang-up before the signaling connects to the remote endpoint. I was wondering if there was a better way to handle the mush at the end of the iRule where I'm having to insert a double 0d0a to end the payload. Read below and you'll see what I mean.
Thanks!
Dave
-------------------------------------------
rule invite_and_cancel
when RULE_INIT {
array set ::callidtable{ }
}
when CLIENT_DATA {
Get the UDP Header, Payload, and Call-ID info
set header [UDP::payload 48]
set fullpacket [UDP::payload [UDP::payload length]]
set callid [findstr $fullpacket "Call-ID:" 9 "
" ]
Check if this is a SIP Method INVITE and the FROM field is "anonymous"
if { $header contains "INVITE" } {
if { $fullpacket contains "From: " } {
Find the P-Asserted-Identity field and insert it into the array
This next command MUST have the carriage return in it to pick up the right amount of data.
set ::callidtable($callid) [findstr $fullpacket "P-Asserted-Identity:" 0 "
" ]
return
}
return
}
Check if we've previously stored this Call-ID and this is a CANCEL
if { [info exists ::callidtable($callid)] } {
if { $header contains "CANCEL"} {
Make the P-Asserted-Identity header insert at the right place
set newlength [UDP::payload length]
incr newlength -2
UDP::payload replace $newlength 0 $::callidtable($callid)
Insert a double "0d0a" to end the payload correctly
set newlength [UDP::payload length]
incr newlength -2
UDP::payload replace $newlength 0 "\n"
Clear the array for this callerid
unset ::callidtable($callid)
return
}
else {
If we're here, we're seeing a different message than INVITE or CANCEL
log "Message other than INVITE / CANCEL for CALL-ID $callid"
}
}
}