<p>Torrey Searle has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/10357">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_session: add new flag use_callerid_contact<br><br>Add a new global flag to res_pjsip to allow the callerid to be used<br>as the username in the contact header. This allows chan_pjsip to have<br>the same behavour as chan_sip<br><br>AST-28087 #close<br><br>Change-Id: I9a720e058323f6862a91c62f8a8c1a4b5c087b95<br>---<br>M include/asterisk/res_pjsip.h<br>M res/res_pjsip/config_global.c<br>M res/res_pjsip_session.c<br>3 files changed, 40 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/57/10357/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 17282d6..eb0905b 100644</span><br><span>--- a/include/asterisk/res_pjsip.h</span><br><span>+++ b/include/asterisk/res_pjsip.h</span><br><span>@@ -2774,6 +2774,14 @@</span><br><span> unsigned int ast_sip_get_mwi_disable_initial_unsolicited(void);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Retrieve the global setting 'use_callerid_contact'.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.24.0</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval non zero if CALLERID(num) is to be used as the default username in the contact</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+unsigned int ast_sip_get_use_callerid_contact(void);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Retrieve the global setting 'ignore_uri_user_options'.</span><br><span> * \since 13.12.0</span><br><span> *</span><br><span>diff --git a/res/res_pjsip/config_global.c b/res/res_pjsip/config_global.c</span><br><span>index b3d6fa2..6e2260a 100644</span><br><span>--- a/res/res_pjsip/config_global.c</span><br><span>+++ b/res/res_pjsip/config_global.c</span><br><span>@@ -48,6 +48,7 @@</span><br><span> #define DEFAULT_MWI_TPS_QUEUE_LOW -1</span><br><span> #define DEFAULT_MWI_DISABLE_INITIAL_UNSOLICITED 0</span><br><span> #define DEFAULT_IGNORE_URI_USER_OPTIONS 0</span><br><span style="color: hsl(120, 100%, 40%);">+#define DEFAULT_USE_CALLERID_CONTACT 0</span><br><span> </span><br><span> /*!</span><br><span> * \brief Cached global config object</span><br><span>@@ -103,6 +104,8 @@</span><br><span> } mwi;</span><br><span> /*! Nonzero if URI user field options are ignored. */</span><br><span> unsigned int ignore_uri_user_options;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Nonzero if CALLERID(num) is to be used as the default contact username instead of default_from_user */</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int use_callerid_contact;</span><br><span> };</span><br><span> </span><br><span> static void global_destructor(void *obj)</span><br><span>@@ -402,6 +405,21 @@</span><br><span> return ignore_uri_user_options;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+unsigned int ast_sip_get_use_callerid_contact(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int use_callerid_contact;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct global_config *cfg;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ cfg = get_global_cfg();</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!cfg) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return DEFAULT_USE_CALLERID_CONTACT;</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%);">+ use_callerid_contact = cfg->use_callerid_contact;</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(cfg, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ return use_callerid_contact;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*!</span><br><span> * \internal</span><br><span> * \brief Observer to set default global object if none exist.</span><br><span>@@ -553,6 +571,9 @@</span><br><span> ast_sorcery_object_field_register(sorcery, "global", "ignore_uri_user_options",</span><br><span> DEFAULT_IGNORE_URI_USER_OPTIONS ? "yes" : "no",</span><br><span> OPT_BOOL_T, 1, FLDSET(struct global_config, ignore_uri_user_options));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_object_field_register(sorcery, "global", "use_callerid_contact",</span><br><span style="color: hsl(120, 100%, 40%);">+ DEFAULT_USE_CALLERID_CONTACT ? "yes" : "no",</span><br><span style="color: hsl(120, 100%, 40%);">+ OPT_BOOL_T, 1, FLDSET(struct global_config, use_callerid_contact));</span><br><span> </span><br><span> if (ast_sorcery_instance_observer_add(sorcery, &observer_callbacks_global)) {</span><br><span> return -1;</span><br><span>diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c</span><br><span>index ff40e55..c92933a 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -761,8 +761,10 @@</span><br><span> struct ast_party_id connected_id;</span><br><span> pj_pool_t *dlg_pool;</span><br><span> pjsip_fromto_hdr *dlg_info;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_contact_hdr *dlg_contact;</span><br><span> pjsip_name_addr *dlg_info_name_addr;</span><br><span> pjsip_sip_uri *dlg_info_uri;</span><br><span style="color: hsl(120, 100%, 40%);">+ pjsip_sip_uri *dlg_contact_uri;</span><br><span> int restricted;</span><br><span> </span><br><span> if (!session->channel || session->saved_from_hdr) {</span><br><span>@@ -783,11 +785,16 @@</span><br><span> </span><br><span> dlg_pool = session->inv_session->dlg->pool;</span><br><span> dlg_info = session->inv_session->dlg->local.info;</span><br><span style="color: hsl(120, 100%, 40%);">+ dlg_contact = session->inv_session->dlg->local.contact;</span><br><span> dlg_info_name_addr = (pjsip_name_addr *) dlg_info->uri;</span><br><span> dlg_info_uri = pjsip_uri_get_uri(dlg_info_name_addr);</span><br><span style="color: hsl(120, 100%, 40%);">+ dlg_contact_uri = (pjsip_sip_uri*)pjsip_uri_get_uri(dlg_contact->uri);</span><br><span> </span><br><span> if (session->endpoint->id.trust_outbound || !restricted) {</span><br><span> ast_sip_modify_id_header(dlg_pool, dlg_info, &connected_id);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sip_get_use_callerid_contact() && ast_strlen_zero(session->endpoint->contact_user)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strdup2(dlg_pool, &dlg_contact_uri->user, connected_id.number.str);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span> </span><br><span> ast_party_id_free(&connected_id);</span><br><span>@@ -817,6 +824,10 @@</span><br><span> pj_strdup2(dlg_pool, &dlg_info_uri->user, "anonymous");</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sip_get_use_callerid_contact() && ast_strlen_zero(session->endpoint->contact_user)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ pj_strdup2(dlg_pool, &dlg_contact_uri->user, "anonymous");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (ast_strlen_zero(session->endpoint->fromdomain)) {</span><br><span> pj_strdup2(dlg_pool, &dlg_info_uri->host, "anonymous.invalid");</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10357">change 10357</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/10357"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I9a720e058323f6862a91c62f8a8c1a4b5c087b95 </div>
<div style="display:none"> Gerrit-Change-Number: 10357 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Torrey Searle <tsearle@gmail.com> </div>