Hey Alex,
Thanks so much for the prompt reply!
The substitute and arbitrary position options look useful. In these cases, will Kamailio automatically recalculate the Content-Length, or do I need to manually rewrite this somehow?
I did read that in researching before emailing, from similar thread you responded to about 5 years ago! In this case, we have a specific upstream provider who reject our Contact header in the normal format we send, and require it to be in a specific format. As such, I can manipulate the header on our PBX or on Kamailio. Given Kamailio is aware of the provider we’re sending to and the PBX is not, it seems simpler to do on Kamailio.
Thanks!
Andrew
On 19 Mar 2020, at 12:49 pm, Alex Balashov abalashov@evaristesys.com wrote:
Hi Andrew,
The Content-Length header, if present, is the header that must appear last in a SIP message, per RFC 3261 § 7.5
So, any method of manipulation of the Contact must manipulate it in place. A common favourite - if you absolutely must manipulate the Contact - is to substitute it. You can also insert the header at an arbitrary position:
https://kamailio.org/docs/modules/5.3.x/modules/textopsx.html#textopsx.f.ins... https://kamailio.org/docs/modules/5.3.x/modules/textopsx.html#textopsx.f.insert_hf_value
But a better question might perhaps be: why do you want to manipulate the Contact header?
While it may perhaps be legitimately necessary occasionally, my finding has been that in 99% of cases, it's the wrong way to solve a problem.
-- Alex
On Thu, Mar 19, 2020 at 12:42:51PM +1100, Andrew White wrote:
Hi all,
Hope everyone is well, and looking forward to seeing you all whenever Kamailio World ends up being!
I’m currently dealing with an issue which I’m unsure if it’s due to my own implementation, or a bug.
When attempting to manipulate the Contact header via app_ruby, the SIP message I send ends up being malformed. Here’s the code I’m using:
def replace_contact_header(uri) #KSR::HDR.remove("Contact") if KSR::HDR.is_present('Contact') > 0 #KSR::HDR.append("Contact: #{uri}\r\n") KSR::HDR.rmappend("Contact", "Contact: #{uri}\r\n") end
Note that I have tried both rmappend and the commented out functions too. I call this with a custom built URI, such as <61400123123@kamailio.test.uconnected.com.au mailto:61400123123@kamailio.test.uconnected.com.au <mailto:61400123123@kamailio.test.uconnected.com.au mailto:61400123123@kamailio.test.uconnected.com.au>>. This function is called just before a KSR::TM.t_relay(). Here’s the result I get watching from tshark (some info scrubbed for privacy):
Record-Route: <sip:1.2.3.4;lr;ftag=e3p42efd3635HH;vst=AAAAAAAAAAAAAAAAAAAAAAoUXVFHDQAAs83AEGwAAFgwCQA8QY3RlZC5jb20uYXU-;did=927.f0f2 sip:1.2.3.4;lr;ftag=e3p42efd3635HH;vst=AAAAAAAAAAAAAAAAAAAAAAoUXVFHDQAAs83AEGwAAFgwCQA8QY3RlZC5jb20uYXU-;did=927.f0f2> … Call-ID: 3de29646-e423-1238-e712-023563fb337c CSeq: 17736747 INVITE sip:4.5.6.7:5060;alias=10.100.1.1~5060~1Content-Type: sip:4.5.6.7:5060;alias=10.100.1.1~5060~1Content-Type: application/sdp Content-Length: 483 Contact: <sip:61400123123@kamailio.test.uconnected.com.au sip:61400123123@kamailio.test.uconnected.com.au>
In this case, 4.5.6.7 is the PBX I made the call from (and the value of the original Contact header), and 1.2.3.4 is what kamailio.test.uconnected.com.au http://kamailio.test.uconnected.com.au/ <http://kamailio.test.uconnected.com.au/ http://kamailio.test.uconnected.com.au/> resolves to, and is this Kamailio instance.
Here’s a copy of the same thing when I don’t call my replace_contact_header function and t_relay:
Record-Route: <sip:1.2.3.4;lr;ftag=j6jebCSa5Qap6c;vst=AAAAAAAAAAAAAAAAAAAAAAoUXVND38dTgwEGEAEGwAAFgwCQA8Fdn83lZC5jb20uYXU-;did=827.40b sip:1.2.3.4;lr;ftag=j6jebCSa5Qap6c;vst=AAAAAAAAAAAAAAAAAAAAAAoUXVND38dTgwEGEAEGwAAFgwCQA8Fdn83lZC5jb20uYXU-;did=827.40b> ... Call-ID: 249571c5-e91a-ae91-6d8e-023563fb337c CSeq: 17735867 INVITE Contact: <sip:4.5.6.7:5060;alias=10.100.1.1~5060~1 sip:4.5.6.7:5060;alias=10.100.1.1~5060~1> Content-Type: application/sdp Content-Length: 483
Given the relative simplicity of the function, I have to assume this is an error with how the function is manipulating the existing Contact header? It seems that the “Contact: <“ part of the header is being removed as well as the “>\r\n", but the rest being left.
I’m currently using commit 283e468401d809ca9b71368c32badf3a70d48b8b <https://github.com/kamailio/kamailio/commit/283e46 https://github.com/kamailio/kamailio/commit/283e46> on Amazon Linux 2, which is CentOS/RHEL based.
Thanks!
Andrew
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org mailto:sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
-- Alex Balashov | Principal | Evariste Systems LLC
Tel: +1-706-510-6800 / +1-800-250-5920 (toll-free) Web: http://www.evaristesys.com/ http://www.evaristesys.com/, http://www.csrpswitch.com/ http://www.csrpswitch.com/
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org mailto:sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users