chan_pjsip: Add Referred-By header to the PJSIP REFER packet.
authorDebian Amtelco <dan@amtelco.com>
Wed, 26 Aug 2015 21:58:04 +0000 (21:58 +0000)
committerDebian Amtelco <dan@amtelco.com>
Mon, 5 Oct 2015 21:45:24 +0000 (21:45 +0000)
Some systems require the REFER packet to include a Referred-By header.
If the channel variable SIPREFERREDBYHDR is set, it passes that value as the
Referred-By header value.  Otherwise, it adds the current dialog’s local info.

Reported by: Dan Cropp
Tested by: Dan Cropp

Change-Id: I3d17912ce548667edf53cb549e88a25475eda245

channels/chan_pjsip.c

index 153b2a3..523a015 100644 (file)
@@ -1435,6 +1435,8 @@ static void transfer_refer(struct ast_sip_session *session, const char *target)
        enum ast_control_transfer message = AST_TRANSFER_SUCCESS;
        pj_str_t tmp;
        pjsip_tx_data *packet;
+       const char *ref_by_val;
+       char local_info[pj_strlen(&session->inv_session->dlg->local.info_str) + 1];
 
        if (pjsip_xfer_create_uac(session->inv_session->dlg, NULL, &sub) != PJ_SUCCESS) {
                message = AST_TRANSFER_FAILED;
@@ -1451,6 +1453,14 @@ static void transfer_refer(struct ast_sip_session *session, const char *target)
                return;
        }
 
+       ref_by_val = pbx_builtin_getvar_helper(session->channel, "SIPREFERREDBYHDR");
+       if (!ast_strlen_zero(ref_by_val)) {
+               ast_sip_add_header(packet, "Referred-By", ref_by_val);
+       } else {
+               ast_copy_pj_str(local_info, &session->inv_session->dlg->local.info_str, sizeof(local_info));
+               ast_sip_add_header(packet, "Referred-By", local_info);
+       }
+
        pjsip_xfer_send_request(sub, packet);
        ast_queue_control_data(session->channel, AST_CONTROL_TRANSFER, &message, sizeof(message));
 }