Add headers from SIPAddHeader to outbound REFER requests.

This is a patch from kkm from review board.

This is useful for adding headers to REFER requests that
emanate from a Transfer() dialplan application call.

This also fixes some uses of the Referred-by header, removing
an extra set of angle brackets.

I've modified the reporter's original patch to not require
any additions to the sip_refer header and to just remove the
referred_by_name from sip_refer since it is no longer needed
or used.

(closes Issue ASTERISK-17639)
reported by Kirill Katsnelson
Patches:
	019059-sip-refer-addheaders-trunk-353549.diff
	uploaded by Kirill Katsnelson (license #5845)

Review: https://reviewboard.asterisk.org/r/1159



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@370691 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Michelson
2012-07-31 22:28:16 +00:00
parent 58f281a670
commit 4377d511ae
4 changed files with 21 additions and 29 deletions

View File

@@ -643,6 +643,11 @@ Scripts
behavior and uses the current working directory.
SIP changes
--------------------------
* Extra headers specified with SIPAddHeader are sent with the REFER message
when using Transfer application. See refer_addheaders in sip.conf.sample.
------------------------------------------------------------------------------
--- Functionality changes from Asterisk 1.8 to Asterisk 10 -------------------
------------------------------------------------------------------------------

View File

@@ -795,6 +795,7 @@ static int global_max_se; /*!< Highest threshold for session
static int global_store_sip_cause; /*!< Whether the MASTER_CHANNEL(HASH(SIP_CAUSE,[chan_name])) var should be set */
static int global_dynamic_exclude_static = 0; /*!< Exclude static peers from contact registrations */
static unsigned char global_refer_addheaders; /*!< Add extra headers to outgoing REFER */
/*@}*/
/*!
@@ -13334,17 +13335,11 @@ static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init,
}
add_date(&req);
if (sipmethod == SIP_REFER && p->refer) { /* Call transfer */
char buf[SIPBUFSIZE];
if (!ast_strlen_zero(p->refer->refer_to)) {
add_header(&req, "Refer-To", p->refer->refer_to);
}
if (!ast_strlen_zero(p->refer->referred_by)) {
snprintf(buf, sizeof(buf), "%s%s%s",
p->refer->referred_by_name,
!ast_strlen_zero(p->refer->referred_by_name) ? " " : "",
p->refer->referred_by);
add_header(&req, "Referred-By", buf);
add_header(&req, "Referred-By", p->refer->referred_by);
}
} else if (sipmethod == SIP_SUBSCRIBE) {
if (p->subscribed == MWI_NOTIFICATION) {
@@ -13383,7 +13378,8 @@ static int transmit_invite(struct sip_pvt *p, int sipmethod, int sdp, int init,
add_header(&req, "Allow", ALLOWED_METHODS);
add_supported(p, &req);
if (p->options && p->options->addsipheaders && p->owner) {
if (p->owner && ((p->options && p->options->addsipheaders)
|| (p->refer && global_refer_addheaders))) {
struct ast_channel *chan = p->owner; /* The owner channel */
struct varshead *headp;
@@ -14662,9 +14658,6 @@ static int sip_notify_alloc(struct sip_pvt *p)
*/
static int transmit_refer(struct sip_pvt *p, const char *dest)
{
struct sip_request req = {
.headers = 0,
};
char from[256];
const char *of;
char *c;
@@ -14711,17 +14704,7 @@ static int transmit_refer(struct sip_pvt *p, const char *dest)
ast_string_field_set(p->refer, referred_by, p->our_contact);
p->refer->status = REFER_SENT; /* Set refer status */
reqprep(&req, p, SIP_REFER, 0, 1);
add_header(&req, "Refer-To", referto);
add_header(&req, "Allow", ALLOWED_METHODS);
add_supported(p, &req);
if (!ast_strlen_zero(p->our_contact)) {
add_header(&req, "Referred-By", p->our_contact);
}
return send_request(p, &req, XMIT_RELIABLE, p->ocseq);
return transmit_invite(p, SIP_REFER, FALSE, 0, NULL);
/* We should propably wait for a NOTIFY here until we ack the transfer */
/* Maybe fork a new thread and wait for a STATUS of REFER_200OK on the refer status before returning to app_transfer */
@@ -16897,12 +16880,6 @@ static int get_refer_info(struct sip_pvt *transferer, struct sip_request *outgoi
if (!ast_strlen_zero(p_referred_by)) {
h_referred_by = ast_strdupa(p_referred_by);
/* Store referrer's caller ID name */
ast_string_field_set(refer, referred_by_name, h_referred_by);
if ((ptr = strchr(refer->referred_by_name, '<')) > refer->referred_by_name) {
*(ptr - 1) = '\0'; /* Space */
}
referred_by_uri = get_in_brackets(h_referred_by);
if (!strncasecmp(referred_by_uri, "sip:", 4)) {
@@ -30347,6 +30324,7 @@ static int reload_config(enum channelreloadreason reason)
global_qualifyfreq = DEFAULT_QUALIFYFREQ;
global_t38_maxdatagram = -1;
global_shrinkcallerid = 1;
global_refer_addheaders = TRUE;
authlimit = DEFAULT_AUTHLIMIT;
authtimeout = DEFAULT_AUTHTIMEOUT;
global_store_sip_cause = DEFAULT_STORE_SIP_CAUSE;
@@ -30904,6 +30882,8 @@ static int reload_config(enum channelreloadreason reason)
ast_set2_flag(&global_flags[2], ast_true(v->value), SIP_PAGE3_ICE_SUPPORT);
} else if (!strcasecmp(v->name, "parkinglot")) {
ast_copy_string(default_parkinglot, v->value, sizeof(default_parkinglot));
} else if (!strcasecmp(v->name, "refer_addheaders")) {
global_refer_addheaders = ast_true(v->value);
}
}

View File

@@ -926,7 +926,6 @@ struct sip_refer {
AST_STRING_FIELD(refer_to_urioption); /*!< Place to store REFER-TO uri options */
AST_STRING_FIELD(refer_to_context); /*!< Place to store REFER-TO context */
AST_STRING_FIELD(referred_by); /*!< Place to store REFERRED-BY extension */
AST_STRING_FIELD(referred_by_name); /*!< Place to store REFERRED-BY extension */
AST_STRING_FIELD(refer_contact); /*!< Place to store Contact info from a REFER extension */
AST_STRING_FIELD(replaces_callid); /*!< Replace info: callid */
AST_STRING_FIELD(replaces_callid_totag); /*!< Replace info: to-tag */

View File

@@ -502,6 +502,14 @@ srvlookup=yes ; Enable DNS SRV lookups on outbound calls
;use_q850_reason = no ; Default "no"
; Set to yes add Reason header and use Reason header if it is available.
; When the Transfer() application sends a REFER SIP message, extra headers specified in
; the dialplan by way of SIPAddHeader are sent out with that message. 1.8 and earlier did not
; add the extra headers. To revert to 1.8- behavior, call SIPRemoveHeader with no arguments
; before calling Transfer() to remove all additional headers from the channel. The setting
; below is for transitional compatibility only.
;
;refer_addheaders=yes ; on by default
;autocreatepeers=no ; Allow any not exsplicitly defined here UAC to register
; WITHOUT AUTHENTICATION. Enabling this options poses a high
; potential security risk and should be avoided unless the