Search code examples
sipkamailio

Why append HF doesn't work in event_route?


I'm trying to connect kamailio to Microsoft Teams. Dispatch is correctly configured and sended. Following this tutorial : https://skalatan.de/en/blog/kamailio-sbc-teams, I added an Event_Route to add contact header to SIP OPTION from dispath to MS :

event_route[tm:local-request] {
   xlog("*** tm:local-request *** ");
        if(is_method("OPTIONS") && $ru =~ "pstnhub.microsoft.com") {
               xlog("L_INFO", "Append new contact !\n");
               append_hf("Contact: <sip:MY_SBC_NAME.COM:5061;transport=tls>\r\n");
        }
        xlog("L_INFO", "Sent out tm request: $mb\n");
}

When I check the log to see my sended frame, I don't see a contact header field :

INFO: <script>: Append new contact !
INFO: <script>: Sent out tm request :
OPTIONS sip:sip.pstnhub.microsoft.com;transport=tls SIP/2.0
Via: SIP/2.0/TLS MY_SBC_NAME.COM:5061;branch=z9hG4bK4497.f3e5e754000000000000000000000000.0
To: <sip:sip.pstnhub.microsoft.com;transport=tls>
From: <sip:MY_SBC_NAME.COM.fr>;tag=a76e006ace3802951ed860e08df964af-7971
CSeq: 10 OPTIONS
Call-ID: 2e1278ea77796160-9837@MY_SBC_IP
Max-Forwards: 70
Content-Length: 0
User-Agent: kamailio (5.2.1 (x86_64/linux))``` 

According the documentation about textop, append_hf(txt[, hdr]) : This function can be used from REQUEST_ROUTE, ONREPLY_ROUTE, FAILURE_ROUTE, BRANCH_ROUTE.

So my question is append HF can be used in Event_route an why it doesn't work ?

Many thanks.


Solution

  • Changes to the SIP message headers are not visible immediately, see:

    If it would be inside request_route, then you would be able to use msg_apply_changes(), but in this case you can just look at what is sent out and Contact should be there. Being over TLS, you can use modules like sipdump or siptrace to view the incoming/outgoing SIP traffic.