How to send variable information via sip header

For anyone stuck in a similar situation, wanting access to the SIP
headers, this is how we got it done. Not pretty, but it works until a
better solution can be devised:

in chan_sip.c: (find this section… and insert from /* Fetch Header
*/ to the end.

                     switch (found) {
                     case SIP_REQ_MATCH:
                             sip_pvt_lock(sip_pvt_ptr);
                             if (args.method != SIP_RESPONSE && 

args.authentication_present
&& strcmp(args.fromtag,
sip_pvt_ptr->theirtag)) {
/* If we have a request that
uses athentication and the fromtag is
* different from that in the
original call dialog, update the
* fromtag in the saved call
dialog */
ast_string_field_set(sip_pvt_ptr, theirtag, args.fromtag);
}

/* Fetch Header */
const char *twilio_callid = sip_get_header(req, “X-Twilio-CallSid”);

/* Set Field Name */
const char *target_call = “twil_call_sid”;

/* X-Twilio-CallSid */

/* jkc debug next line only */
// ast_debug(2, “Hello world - we are here!\n”);

if (!ast_strlen_zero(twilio_callid)){
if(sip_pvt_ptr->owner){
ast_verbose("#ACC X-Twilio-CallSid %s\n", twilio_callid);
ast_cdr_setvar(ast_channel_name(sip_pvt_ptr->owner),target_call,twilio_callid);
}
}

1 Like