<p>Torrey Searle has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14729">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_diversion: implement support for History-Info<br><br>Implemention of History-Info capable of interworking with Diversion<br>Header<br><br>Change-Id: I2296369582d4b295c5ea1e60bec391dd1d318fa6<br>---<br>M include/asterisk/res_pjsip.h<br>M res/res_pjsip.c<br>M res/res_pjsip/pjsip_configuration.c<br>M res/res_pjsip_diversion.c<br>4 files changed, 274 insertions(+), 23 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/29/14729/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h</span><br><span>index 2fc0519..ae50564 100644</span><br><span>--- a/include/asterisk/res_pjsip.h</span><br><span>+++ b/include/asterisk/res_pjsip.h</span><br><span>@@ -578,6 +578,8 @@</span><br><span> unsigned int rpid_immediate;</span><br><span> /*! Do we add Diversion headers to applicable outgoing requests/responses? */</span><br><span> unsigned int send_diversion;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Do we add History-Info headers to applicable outgoing requests/responses? */</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int send_history_info;</span><br><span> /*! When performing connected line update, which method should be used */</span><br><span> enum ast_sip_session_refresh_method refresh_method;</span><br><span> };</span><br><span>diff --git a/res/res_pjsip.c b/res/res_pjsip.c</span><br><span>index 809451a..76c69ca 100644</span><br><span>--- a/res/res_pjsip.c</span><br><span>+++ b/res/res_pjsip.c</span><br><span>@@ -426,6 +426,10 @@</span><br><span> <synopsis>Send the Diversion header, conveying the diversion</span><br><span> information to the called user agent</synopsis></span><br><span> </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+ <configOption name="send_history_info" default="no"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>Send the History-Info header, conveying the diversion</span><br><span style="color: hsl(120, 100%, 40%);">+ information to the called and calling user agents</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ </configOption></span><br><span> <configOption name="send_pai" default="no"></span><br><span> <synopsis>Send the P-Asserted-Identity header</synopsis></span><br><span> </configOption></span><br><span>diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c</span><br><span>index 2452e54..3864c7b 100644</span><br><span>--- a/res/res_pjsip/pjsip_configuration.c</span><br><span>+++ b/res/res_pjsip/pjsip_configuration.c</span><br><span>@@ -1882,6 +1882,7 @@</span><br><span> ast_sorcery_object_field_register(sip_sorcery, "endpoint", "send_rpid", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, id.send_rpid));</span><br><span> ast_sorcery_object_field_register(sip_sorcery, "endpoint", "rpid_immediate", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, id.rpid_immediate));</span><br><span> ast_sorcery_object_field_register(sip_sorcery, "endpoint", "send_diversion", "yes", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, id.send_diversion));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_object_field_register(sip_sorcery, "endpoint", "send_history_info", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, id.send_history_info));</span><br><span> ast_sorcery_object_field_register(sip_sorcery, "endpoint", "mailboxes", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, subscription.mwi.mailboxes));</span><br><span> ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "voicemail_extension", "", voicemail_extension_handler, voicemail_extension_to_str, NULL, 0, 0);</span><br><span> ast_sorcery_object_field_register(sip_sorcery, "endpoint", "aggregate_mwi", "yes", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, subscription.mwi.aggregate));</span><br><span>diff --git a/res/res_pjsip_diversion.c b/res/res_pjsip_diversion.c</span><br><span>index 856fb8c..d94a7dc 100644</span><br><span>--- a/res/res_pjsip_diversion.c</span><br><span>+++ b/res/res_pjsip_diversion.c</span><br><span>@@ -36,6 +36,7 @@</span><br><span> #include "asterisk/strings.h"</span><br><span> </span><br><span> static const pj_str_t diversion_name = { "Diversion", 9 };</span><br><span style="color: hsl(120, 100%, 40%);">+static const pj_str_t history_info_name = { "History-Info", 12 };</span><br><span> </span><br><span> /*!</span><br><span> * \internal</span><br><span>@@ -80,22 +81,41 @@</span><br><span> static const struct reasons {</span><br><span> enum AST_REDIRECTING_REASON code;</span><br><span> const char *text;</span><br><span style="color: hsl(120, 100%, 40%);">+ const unsigned int cause;</span><br><span> } reason_table[] = {</span><br><span style="color: hsl(0, 100%, 40%);">- { AST_REDIRECTING_REASON_UNKNOWN, "unknown" },</span><br><span style="color: hsl(0, 100%, 40%);">- { AST_REDIRECTING_REASON_USER_BUSY, "user-busy" },</span><br><span style="color: hsl(0, 100%, 40%);">- { AST_REDIRECTING_REASON_NO_ANSWER, "no-answer" },</span><br><span style="color: hsl(0, 100%, 40%);">- { AST_REDIRECTING_REASON_UNAVAILABLE, "unavailable" },</span><br><span style="color: hsl(0, 100%, 40%);">- { AST_REDIRECTING_REASON_UNCONDITIONAL, "unconditional" },</span><br><span style="color: hsl(0, 100%, 40%);">- { AST_REDIRECTING_REASON_TIME_OF_DAY, "time-of-day" },</span><br><span style="color: hsl(0, 100%, 40%);">- { AST_REDIRECTING_REASON_DO_NOT_DISTURB, "do-not-disturb" },</span><br><span style="color: hsl(0, 100%, 40%);">- { AST_REDIRECTING_REASON_DEFLECTION, "deflection" },</span><br><span style="color: hsl(0, 100%, 40%);">- { AST_REDIRECTING_REASON_FOLLOW_ME, "follow-me" },</span><br><span style="color: hsl(0, 100%, 40%);">- { AST_REDIRECTING_REASON_OUT_OF_ORDER, "out-of-service" },</span><br><span style="color: hsl(0, 100%, 40%);">- { AST_REDIRECTING_REASON_AWAY, "away" },</span><br><span style="color: hsl(0, 100%, 40%);">- { AST_REDIRECTING_REASON_CALL_FWD_DTE, "cf_dte" }, /* Non-standard */</span><br><span style="color: hsl(0, 100%, 40%);">- { AST_REDIRECTING_REASON_SEND_TO_VM, "send_to_vm" }, /* Non-standard */</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_REDIRECTING_REASON_UNKNOWN, "unknown", 404 },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_REDIRECTING_REASON_USER_BUSY, "user-busy", 486 },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_REDIRECTING_REASON_NO_ANSWER, "no-answer", 408 },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_REDIRECTING_REASON_UNAVAILABLE, "unavailable", 503 },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_REDIRECTING_REASON_UNCONDITIONAL, "unconditional", 302 },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_REDIRECTING_REASON_TIME_OF_DAY, "time-of-day", 404 },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_REDIRECTING_REASON_DO_NOT_DISTURB, "do-not-disturb", 404 },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_REDIRECTING_REASON_DEFLECTION, "deflection", 480 },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_REDIRECTING_REASON_FOLLOW_ME, "follow-me", 404 },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_REDIRECTING_REASON_OUT_OF_ORDER, "out-of-service", 404 },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_REDIRECTING_REASON_AWAY, "away", 404 },</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_REDIRECTING_REASON_CALL_FWD_DTE, "cf_dte", 404 }, /* Non-standard */</span><br><span style="color: hsl(120, 100%, 40%);">+ { AST_REDIRECTING_REASON_SEND_TO_VM, "send_to_vm", 404 }, /* Non-standard */</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static enum AST_REDIRECTING_REASON cause_to_reason(const unsigned long cause) {</span><br><span style="color: hsl(120, 100%, 40%);">+ switch(cause) {</span><br><span style="color: hsl(120, 100%, 40%);">+ case 302:</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_REDIRECTING_REASON_UNCONDITIONAL;</span><br><span style="color: hsl(120, 100%, 40%);">+ case 486:</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_REDIRECTING_REASON_USER_BUSY;</span><br><span style="color: hsl(120, 100%, 40%);">+ case 408:</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_REDIRECTING_REASON_NO_ANSWER;</span><br><span style="color: hsl(120, 100%, 40%);">+ case 480:</span><br><span style="color: hsl(120, 100%, 40%);">+ case 487:</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_REDIRECTING_REASON_DEFLECTION;</span><br><span style="color: hsl(120, 100%, 40%);">+ case 503:</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_REDIRECTING_REASON_UNAVAILABLE;</span><br><span style="color: hsl(120, 100%, 40%);">+ default:</span><br><span style="color: hsl(120, 100%, 40%);">+ return AST_REDIRECTING_REASON_UNKNOWN;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static const char *reason_code_to_str(const struct ast_party_redirecting_reason *reason)</span><br><span> {</span><br><span> int idx;</span><br><span>@@ -116,6 +136,21 @@</span><br><span> return "unknown";</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static const unsigned int reason_code_to_cause(const struct ast_party_redirecting_reason *reason)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int idx;</span><br><span style="color: hsl(120, 100%, 40%);">+ int code;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ code = reason->code;</span><br><span style="color: hsl(120, 100%, 40%);">+ for (idx = 0; idx < ARRAY_LEN(reason_table); ++idx) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (code == reason_table[idx].code) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return reason_table[idx].cause;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 404;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static pjsip_fromto_hdr *get_diversion_header(pjsip_rx_data *rdata)</span><br><span> {</span><br><span> static const pj_str_t from_name = { "From", 4 };</span><br><span>@@ -135,6 +170,81 @@</span><br><span> pj_strlen(&value), &size);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static pjsip_fromto_hdr *get_history_info_header_to(pjsip_rx_data *rdata)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ static const pj_str_t from_name = { "From", 4 };</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_fromto_hdr * result_hdr = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_generic_string_hdr *hdr = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ hdr = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &history_info_name, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!hdr) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ do {</span><br><span style="color: hsl(120, 100%, 40%);">+ static const pj_str_t index_name = { "index", 5 };</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_str_t value;</span><br><span style="color: hsl(120, 100%, 40%);">+ int size;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_fromto_hdr * fromto_hdr = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strdup_with_null(rdata->tp_info.pool, &value, &hdr->hvalue);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* parse as a fromto header */</span><br><span style="color: hsl(120, 100%, 40%);">+ fromto_hdr = pjsip_parse_hdr(rdata->tp_info.pool, &from_name, value.ptr,</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strlen(&value), &size);</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_param *index = pjsip_param_find(&fromto_hdr->other_param, &index_name);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (index) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!pj_strcmp2(&index->value, "1")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ continue;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ result_hdr = fromto_hdr;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ } while ((hdr = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &history_info_name, hdr->next)));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return result_hdr;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static pjsip_fromto_hdr *get_history_info_header_from(pjsip_rx_data *rdata)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ static const pj_str_t from_name = { "From", 4 };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_generic_string_hdr *hdr = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ hdr = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &history_info_name, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!hdr) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ do {</span><br><span style="color: hsl(120, 100%, 40%);">+ static const pj_str_t index_name = { "index", 5 };</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_str_t value;</span><br><span style="color: hsl(120, 100%, 40%);">+ int size;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_fromto_hdr * fromto_hdr = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strdup_with_null(rdata->tp_info.pool, &value, &hdr->hvalue);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* parse as a fromto header */</span><br><span style="color: hsl(120, 100%, 40%);">+ fromto_hdr = pjsip_parse_hdr(rdata->tp_info.pool, &from_name, value.ptr,</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strlen(&value), &size);</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_param *index = pjsip_param_find(&fromto_hdr->other_param, &index_name);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (index) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!pj_strcmp2(&index->value, "1")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return fromto_hdr;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ } while ((hdr = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg, &history_info_name, hdr->next)));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void set_redirecting_value(char **dst, const pj_str_t *src)</span><br><span> {</span><br><span> ast_free(*dst);</span><br><span>@@ -197,14 +307,33 @@</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-static void set_redirecting_reason(pjsip_fromto_hdr *hdr,</span><br><span style="color: hsl(120, 100%, 40%);">+static void set_redirecting_reason_by_cause(pjsip_name_addr *name_addr,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_party_redirecting_reason *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ static const pj_str_t cause_name = { "cause", 5 };</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_sip_uri *uri = pjsip_uri_get_uri(name_addr);</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_param *cause = pjsip_param_find(&uri->other_param, &cause_name);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!cause) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ const unsigned long cause_value = pj_strtoul(&cause->value);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ data->code = cause_to_reason(cause_value);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(data->str);</span><br><span style="color: hsl(120, 100%, 40%);">+ data->str = ast_strdup("");</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void set_redirecting_reason(pjsip_fromto_hdr *from_info, pjsip_name_addr *to_info,</span><br><span> struct ast_party_redirecting_reason *data)</span><br><span> {</span><br><span> static const pj_str_t reason_name = { "reason", 6 };</span><br><span style="color: hsl(0, 100%, 40%);">- pjsip_param *reason = pjsip_param_find(&hdr->other_param, &reason_name);</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_param *reason = pjsip_param_find(&from_info->other_param, &reason_name);</span><br><span> char *reason_str;</span><br><span> </span><br><span> if (!reason) {</span><br><span style="color: hsl(120, 100%, 40%);">+ set_redirecting_reason_by_cause(to_info, data);</span><br><span> return;</span><br><span> }</span><br><span> </span><br><span>@@ -246,7 +375,8 @@</span><br><span> if (from_info) {</span><br><span> set_redirecting_id((pjsip_name_addr*)from_info->uri,</span><br><span> &data.from, &update.from);</span><br><span style="color: hsl(0, 100%, 40%);">- set_redirecting_reason(from_info, &data.reason);</span><br><span style="color: hsl(120, 100%, 40%);">+ set_redirecting_reason(from_info, to_info, &data.reason);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_set_party_id_all(&update.priv_to);</span><br><span> } else {</span><br><span> copy_redirecting_id(&data.from, &session->id, &update.from);</span><br><span> }</span><br><span>@@ -282,6 +412,8 @@</span><br><span> </span><br><span> pjsip_status_line status = rdata->msg_info.msg->line.status;</span><br><span> pjsip_fromto_hdr *div_hdr;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_fromto_hdr *history_info_to;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_fromto_hdr *history_info_from;</span><br><span> pjsip_contact_hdr *contact_hdr;</span><br><span> </span><br><span> if ((status.code != 302) && (status.code != 181)) {</span><br><span>@@ -289,15 +421,35 @@</span><br><span> }</span><br><span> </span><br><span> /* use the diversion header info if there is one. if not one then use the</span><br><span style="color: hsl(0, 100%, 40%);">- session caller id info. if that doesn't exist use info from the To hdr*/</span><br><span style="color: hsl(0, 100%, 40%);">- if (!(div_hdr = get_diversion_header(rdata)) && !session->id.number.valid) {</span><br><span style="color: hsl(0, 100%, 40%);">- div_hdr = PJSIP_MSG_TO_HDR(rdata->msg_info.msg);</span><br><span style="color: hsl(120, 100%, 40%);">+ the history-info, if that doesn't exist, usesession caller id info. if</span><br><span style="color: hsl(120, 100%, 40%);">+ that doesn't exist use info from the To hdr*/</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!(div_hdr = get_diversion_header(rdata))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ history_info_to = get_history_info_header_to(rdata);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (history_info_to) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* If History-Info is present, then it will also include the original</span><br><span style="color: hsl(120, 100%, 40%);">+ redirected-from in addition to the redirected-to */</span><br><span style="color: hsl(120, 100%, 40%);">+ history_info_from = get_history_info_header_from(rdata);</span><br><span style="color: hsl(120, 100%, 40%);">+ set_redirecting(session, history_info_from, (pjsip_name_addr*)history_info_to->uri);</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!div_hdr && !session->id.number.valid) {</span><br><span style="color: hsl(120, 100%, 40%);">+ div_hdr = PJSIP_MSG_TO_HDR(rdata->msg_info.msg);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- contact_hdr = pjsip_msg_find_hdr_by_names(rdata->msg_info.msg, &contact_name, &contact_name_s, NULL);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- set_redirecting(session, div_hdr, contact_hdr ? (pjsip_name_addr*)contact_hdr->uri :</span><br><span style="color: hsl(0, 100%, 40%);">- (pjsip_name_addr*)PJSIP_MSG_FROM_HDR(rdata->msg_info.msg)->uri);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (status.code == 302) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* With 302, Contact indicates the final destination and possibly Diversion indicates the hop before */</span><br><span style="color: hsl(120, 100%, 40%);">+ contact_hdr = pjsip_msg_find_hdr_by_names(rdata->msg_info.msg, &contact_name, &contact_name_s, NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ set_redirecting(session, div_hdr, contact_hdr ? (pjsip_name_addr*)contact_hdr->uri :</span><br><span style="color: hsl(120, 100%, 40%);">+ (pjsip_name_addr*)PJSIP_MSG_FROM_HDR(rdata->msg_info.msg)->uri);</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* With 181, Diversion is non-standard, but if present indicates the new final destination, and To indicating the original */</span><br><span style="color: hsl(120, 100%, 40%);">+ set_redirecting(session, PJSIP_MSG_TO_HDR(rdata->msg_info.msg),</span><br><span style="color: hsl(120, 100%, 40%);">+ (pjsip_name_addr*)div_hdr->uri);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span> /*!</span><br><span>@@ -318,7 +470,14 @@</span><br><span> const char *quote_str;</span><br><span> char *reason_buf;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_party_id *id = &data->from;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_party_id *id = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ if (tdata->msg->type == PJSIP_REQUEST_MSG) {</span><br><span style="color: hsl(120, 100%, 40%);">+ id = &data->from;</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* In responses indicate the new destination */</span><br><span style="color: hsl(120, 100%, 40%);">+ id = &data->to;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> pjsip_uri *base = PJSIP_MSG_FROM_HDR(tdata->msg)->uri;</span><br><span> </span><br><span> if (!id->number.valid || ast_strlen_zero(id->number.str)) {</span><br><span>@@ -358,6 +517,87 @@</span><br><span> pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)hdr);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Adds history-info header information to an outbound SIP message</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param tdata The outbound message</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param data The redirecting data used to fill parts of the history-info header</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static void add_history_info_header(pjsip_tx_data *tdata, struct ast_party_redirecting *data)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_fromto_hdr *hdr;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_name_addr *name_addr;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_sip_uri *uri;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_param *param;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_fromto_hdr *old_hdr;</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int cause;</span><br><span style="color: hsl(120, 100%, 40%);">+ char *cause_buf;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_party_id *to = &data->to;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_party_id *from = &data->from;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_uri *base = PJSIP_MSG_TO_HDR(tdata->msg)->uri;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ hdr = pjsip_from_hdr_create(tdata->pool);</span><br><span style="color: hsl(120, 100%, 40%);">+ hdr->type = PJSIP_H_OTHER;</span><br><span style="color: hsl(120, 100%, 40%);">+ hdr->sname = hdr->name = history_info_name;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ name_addr = pjsip_uri_clone(tdata->pool, base);</span><br><span style="color: hsl(120, 100%, 40%);">+ uri = pjsip_uri_get_uri(name_addr->uri);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* if no redirecting information, then TO is the original destination */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (from->number.valid && ast_strlen_zero(from->number.str) != 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strdup2(tdata->pool, &name_addr->display, from->name.str);</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strdup2(tdata->pool, &uri->user, from->number.str);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ param = PJ_POOL_ALLOC_T(tdata->pool, pjsip_param);</span><br><span style="color: hsl(120, 100%, 40%);">+ param->name = pj_str("index");</span><br><span style="color: hsl(120, 100%, 40%);">+ param->value = pj_str("1");</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_list_insert_before(&hdr->other_param, param);</span><br><span style="color: hsl(120, 100%, 40%);">+ hdr->uri = (pjsip_uri *) name_addr;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ while ((old_hdr = pjsip_msg_find_hdr_by_name(tdata->msg, &history_info_name, NULL)) != NULL) {</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_list_erase(old_hdr);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)hdr);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!to->number.valid || ast_strlen_zero(to->number.str)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ hdr = pjsip_from_hdr_create(tdata->pool);</span><br><span style="color: hsl(120, 100%, 40%);">+ hdr->type = PJSIP_H_OTHER;</span><br><span style="color: hsl(120, 100%, 40%);">+ hdr->sname = hdr->name = history_info_name;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ name_addr = pjsip_uri_clone(tdata->pool, base);</span><br><span style="color: hsl(120, 100%, 40%);">+ uri = pjsip_uri_get_uri(name_addr->uri);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strdup2(tdata->pool, &name_addr->display, to->name.str);</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strdup2(tdata->pool, &uri->user, to->number.str);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ param = PJ_POOL_ALLOC_T(tdata->pool, pjsip_param);</span><br><span style="color: hsl(120, 100%, 40%);">+ param->name = pj_str("index");</span><br><span style="color: hsl(120, 100%, 40%);">+ param->value = pj_str("1.1");</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_list_insert_before(&hdr->other_param, param);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ param = PJ_POOL_ALLOC_T(tdata->pool, pjsip_param);</span><br><span style="color: hsl(120, 100%, 40%);">+ param->name = pj_str("cause");</span><br><span style="color: hsl(120, 100%, 40%);">+ cause = reason_code_to_cause(&data->reason);</span><br><span style="color: hsl(120, 100%, 40%);">+ cause_buf = pj_pool_alloc(tdata->pool, 4);</span><br><span style="color: hsl(120, 100%, 40%);">+ snprintf(cause_buf, 4, "%ud", cause);</span><br><span style="color: hsl(120, 100%, 40%);">+ param->value = pj_str(cause_buf);</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_list_insert_before(&uri->other_param, param);</span><br><span style="color: hsl(120, 100%, 40%);">+ hdr->uri = (pjsip_uri *) name_addr;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)hdr);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void get_redirecting_add_diversion(struct ast_sip_session *session, pjsip_tx_data *tdata)</span><br><span> {</span><br><span> struct ast_party_redirecting *data;</span><br><span>@@ -366,6 +606,10 @@</span><br><span> (data = ast_channel_redirecting(session->channel))->count) {</span><br><span> add_diversion_header(tdata, data);</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (session->channel && session->endpoint->id.send_history_info) {</span><br><span style="color: hsl(120, 100%, 40%);">+ data = ast_channel_redirecting(session->channel);</span><br><span style="color: hsl(120, 100%, 40%);">+ add_history_info_header(tdata, data);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span> /*!</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14729">change 14729</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/14729"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I2296369582d4b295c5ea1e60bec391dd1d318fa6 </div>
<div style="display:none"> Gerrit-Change-Number: 14729 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Torrey Searle <tsearle@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>