summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Jordan <mjordan@digium.com>2015-06-26 11:27:00 -0500
committerGerrit Code Review <gerrit2@gerrit.digium.api>2015-06-26 11:27:00 -0500
commitc69c8d4e807a9d98c30e039770d6174e05cfe8db (patch)
treef5f71c5cf06a27fea3f7988c291ab90a2950eb37
parente5499c32336d80af86fa1ebac9ca36b3718d77db (diff)
parent05a2cc129396df9d75d1dbafc040eca117f982ba (diff)
Merge "res_pjsip_refer: Prevent sending duplicate headers." into 13
-rw-r--r--res/res_pjsip_refer.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/res/res_pjsip_refer.c b/res/res_pjsip_refer.c
index 5195177d5..4896a00e8 100644
--- a/res/res_pjsip_refer.c
+++ b/res/res_pjsip_refer.c
@@ -1087,10 +1087,41 @@ 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)
+/*!
+ * \brief Use the value of a channel variable as the value of a SIP header
+ *
+ * This looks up a variable name on a channel, then takes that value and adds
+ * it to an outgoing SIP request. If the header already exists on the message,
+ * then no action is taken.
+ *
+ * \pre chan is locked.
+ *
+ * \param chan The channel on which to find the variable.
+ * \param var_name The name of the channel variable to use.
+ * \param header_name The name of the SIP header to add to the outgoing message.
+ * \param tdata The outgoing SIP message on which to add the header
+ */
+static void add_header_from_channel_var(struct ast_channel *chan, const char *var_name, const char *header_name, pjsip_tx_data *tdata)
{
- const char *hdr;
+ const char *var_value;
+ pj_str_t pj_header_name;
+ pjsip_hdr *header;
+
+ var_value = pbx_builtin_getvar_helper(chan, var_name);
+ if (ast_strlen_zero(var_value)) {
+ return;
+ }
+ pj_cstr(&pj_header_name, header_name);
+ header = pjsip_msg_find_hdr_by_name(tdata->msg, &pj_header_name, NULL);
+ if (header) {
+ return;
+ }
+ ast_sip_add_header(tdata, header_name, var_value);
+}
+
+static void refer_outgoing_request(struct ast_sip_session *session, struct pjsip_tx_data *tdata)
+{
if (pjsip_method_cmp(&tdata->msg->line.req.method, &pjsip_invite_method)
|| !session->channel
|| session->inv_session->state != PJSIP_INV_STATE_NULL) {
@@ -1098,15 +1129,8 @@ static void refer_outgoing_request(struct ast_sip_session *session, struct pjsip
}
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);
- }
+ add_header_from_channel_var(session->channel, "SIPREPLACESHDR", "Replaces", tdata);
+ add_header_from_channel_var(session->channel, "SIPREFERREDBYHDR", "Referred-By", tdata);
ast_channel_unlock(session->channel);
}