summaryrefslogtreecommitdiff
path: root/res/res_pjsip_refer.c
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2014-05-02 16:39:58 +0000
committerRichard Mudgett <rmudgett@digium.com>2014-05-02 16:39:58 +0000
commit119599407b95f96c15535d1c86e88b840c933ee7 (patch)
tree08712380fd4e6f1b73f92923bbb60cb639423a86 /res/res_pjsip_refer.c
parent57372e61d23543c70158ba8a0fec40e4848ee44e (diff)
res_pjsip_refer: Add Referred-By header on INVITE for blind transfers.
Per rfc3892, the Referred-By header in a REFER must be copied into the referenced request (IE. The outgoing INVITE to the transfer target). * Automatically put the Referred-By header in the outgoing INVITE message if the SIPREFERREDBYHDR channel variable is defined with a value. * Made chan_sip.c:get_refer_info() set SIPREFERREDBYHDR for inheritance so chan_pjsip has a better chance to interoperate. * Fixed refer_blind_callback() and refer_incoming_refer_request() to not modify the data in the pointer returned by pjsip_msg_find_hdr_by_name(). It seems wrong to modify that data since the calling routine doesn't own the buffer. ASTERISK-23501 #close Reported by: John Bigelow Review: https://reviewboard.asterisk.org/r/3514/ ........ Merged revisions 413210 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@413211 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_pjsip_refer.c')
-rw-r--r--res/res_pjsip_refer.c74
1 files changed, 49 insertions, 25 deletions
diff --git a/res/res_pjsip_refer.c b/res/res_pjsip_refer.c
index 3f03f46bd..e6ec25f02 100644
--- a/res/res_pjsip_refer.c
+++ b/res/res_pjsip_refer.c
@@ -476,8 +476,9 @@ struct refer_blind {
static void refer_blind_callback(struct ast_channel *chan, void *user_data, enum ast_transfer_type transfer_type)
{
struct refer_blind *refer = user_data;
- const pj_str_t str_referred_by = { "Referred-By", 11 };
- pjsip_generic_string_hdr *referred_by = pjsip_msg_find_hdr_by_name(refer->rdata->msg_info.msg, &str_referred_by, NULL);
+ pjsip_generic_string_hdr *referred_by;
+
+ static const pj_str_t str_referred_by = { "Referred-By", 11 };
pbx_builtin_setvar_helper(chan, "SIPTRANSFER", "yes");
@@ -544,29 +545,36 @@ static void refer_blind_callback(struct ast_channel *chan, void *user_data, enum
}
}
- if (!ast_strlen_zero(refer->context)) {
- pbx_builtin_setvar_helper(chan, "SIPREFERRINGCONTEXT", refer->context);
- }
+ pbx_builtin_setvar_helper(chan, "SIPREFERRINGCONTEXT", S_OR(refer->context, NULL));
+ referred_by = pjsip_msg_find_hdr_by_name(refer->rdata->msg_info.msg,
+ &str_referred_by, NULL);
if (referred_by) {
- char *uri = referred_by->hvalue.ptr;
+ size_t uri_size = pj_strlen(&referred_by->hvalue) + 1;
+ char *uri = ast_alloca(uri_size);
- uri[referred_by->hvalue.slen] = '\0';
- pbx_builtin_setvar_helper(chan, "SIPREFERREDBYHDR", uri);
+ ast_copy_pj_str(uri, &referred_by->hvalue, uri_size);
+ pbx_builtin_setvar_helper(chan, "__SIPREFERREDBYHDR", S_OR(uri, NULL));
+ } else {
+ pbx_builtin_setvar_helper(chan, "SIPREFERREDBYHDR", NULL);
}
if (refer->replaces) {
char replaces[512];
pjsip_hdr_print_on(refer->replaces, replaces, sizeof(replaces));
- pbx_builtin_setvar_helper(chan, "SIPREPLACESHDR", replaces);
+ pbx_builtin_setvar_helper(chan, "__SIPREPLACESHDR", S_OR(replaces, NULL));
+ } else {
+ pbx_builtin_setvar_helper(chan, "SIPREPLACESHDR", NULL);
}
if (refer->refer_to) {
char refer_to[PJSIP_MAX_URL_SIZE];
pjsip_uri_print(PJSIP_URI_IN_REQ_URI, refer->refer_to, refer_to, sizeof(refer_to));
- pbx_builtin_setvar_helper(chan, "SIPREFERTOHDR", refer_to);
+ pbx_builtin_setvar_helper(chan, "SIPREFERTOHDR", S_OR(refer_to, NULL));
+ } else {
+ pbx_builtin_setvar_helper(chan, "SIPREFERTOHDR", NULL);
}
}
@@ -811,17 +819,17 @@ end:
static int refer_incoming_refer_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
{
- const pj_str_t str_refer_to = { "Refer-To", 8 };
pjsip_generic_string_hdr *refer_to;
- char *uri;
- const pj_str_t str_to = { "To", 2 };
pjsip_fromto_hdr *target;
pjsip_sip_uri *target_uri;
RAII_VAR(struct refer_progress *, progress, NULL, ao2_cleanup);
- const pj_str_t str_replaces = { "Replaces", 8 };
pjsip_param *replaces;
int response;
+ static const pj_str_t str_refer_to = { "Refer-To", 8 };
+ static const pj_str_t str_to = { "To", 2 };
+ static const pj_str_t str_replaces = { "Replaces", 8 };
+
if (!session->endpoint->allowtransfer) {
pjsip_dlg_respond(session->inv_session->dlg, rdata, 603, NULL, NULL, NULL);
ast_log(LOG_WARNING, "Endpoint %s transfer attempt blocked due to configuration\n",
@@ -830,18 +838,25 @@ static int refer_incoming_refer_request(struct ast_sip_session *session, struct
}
/* A Refer-To header is required */
- if (!(refer_to = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str_refer_to, NULL))) {
+ refer_to = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &str_refer_to, NULL);
+ if (!refer_to) {
pjsip_dlg_respond(session->inv_session->dlg, rdata, 400, NULL, NULL, NULL);
ast_debug(3, "Received a REFER without Refer-To on channel '%s' from endpoint '%s'\n",
ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint));
return 0;
}
- uri = refer_to->hvalue.ptr;
- uri[refer_to->hvalue.slen] = '\0';
/* Parse the provided URI string as a To header so we can get the target */
- if (!(target = pjsip_parse_hdr(rdata->tp_info.pool, &str_to, refer_to->hvalue.ptr, refer_to->hvalue.slen, NULL)) ||
- (!PJSIP_URI_SCHEME_IS_SIP(target->uri) && !PJSIP_URI_SCHEME_IS_SIPS(target->uri))) {
+ target = pjsip_parse_hdr(rdata->tp_info.pool, &str_to,
+ (char *) pj_strbuf(&refer_to->hvalue), pj_strlen(&refer_to->hvalue), NULL);
+ if (!target
+ || (!PJSIP_URI_SCHEME_IS_SIP(target->uri)
+ && !PJSIP_URI_SCHEME_IS_SIPS(target->uri))) {
+ size_t uri_size = pj_strlen(&refer_to->hvalue) + 1;
+ char *uri = ast_alloca(uri_size);
+
+ ast_copy_pj_str(uri, &refer_to->hvalue, uri_size);
+
pjsip_dlg_respond(session->inv_session->dlg, rdata, 400, NULL, NULL, NULL);
ast_debug(3, "Received a REFER without a parseable Refer-To ('%s') on channel '%s' from endpoint '%s'\n",
uri, ast_channel_name(session->channel), ast_sorcery_object_get_id(session->endpoint));
@@ -910,16 +925,25 @@ static int refer_incoming_request(struct ast_sip_session *session, pjsip_rx_data
static void refer_outgoing_request(struct ast_sip_session *session, struct pjsip_tx_data *tdata)
{
- const char *replaces;
+ const char *hdr;
- if (pjsip_method_cmp(&tdata->msg->line.req.method, &pjsip_invite_method) ||
- !session->channel ||
- (session->inv_session->state != PJSIP_INV_STATE_CALLING) ||
- !(replaces = pbx_builtin_getvar_helper(session->channel, "SIPREPLACESHDR"))) {
+ if (pjsip_method_cmp(&tdata->msg->line.req.method, &pjsip_invite_method)
+ || !session->channel
+ || session->inv_session->state != PJSIP_INV_STATE_NULL) {
return;
}
- ast_sip_add_header(tdata, "Replaces", replaces);
+ ast_channel_lock(session->channel);
+ hdr = pbx_builtin_getvar_helper(session->channel, "SIPREPLACESHDR");
+ if (!ast_strlen_zero(hdr)) {
+ ast_sip_add_header(tdata, "Replaces", hdr);
+ }
+
+ hdr = pbx_builtin_getvar_helper(session->channel, "SIPREFERREDBYHDR");
+ if (!ast_strlen_zero(hdr)) {
+ ast_sip_add_header(tdata, "Referred-By", hdr);
+ }
+ ast_channel_unlock(session->channel);
}
static struct ast_sip_session_supplement refer_supplement = {