<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10529">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved; Approved for Submit
</div><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>ASTERISK-28087 #close<br><br>Change-Id: I9a720e058323f6862a91c62f8a8c1a4b5c087b95<br>---<br>A contrib/ast-db-manage/config/versions/2bb1a85135ad_pjsip_add_use_callerid_contact.py<br>M include/asterisk/res_pjsip.h<br>M res/res_pjsip/config_global.c<br>M res/res_pjsip_session.c<br>4 files changed, 74 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/contrib/ast-db-manage/config/versions/2bb1a85135ad_pjsip_add_use_callerid_contact.py b/contrib/ast-db-manage/config/versions/2bb1a85135ad_pjsip_add_use_callerid_contact.py</span><br><span>new file mode 100644</span><br><span>index 0000000..88c94f5</span><br><span>--- /dev/null</span><br><span>+++ b/contrib/ast-db-manage/config/versions/2bb1a85135ad_pjsip_add_use_callerid_contact.py</span><br><span>@@ -0,0 +1,34 @@</span><br><span style="color: hsl(120, 100%, 40%);">+"""pjsip add use_callerid_contact</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Revision ID: 2bb1a85135ad</span><br><span style="color: hsl(120, 100%, 40%);">+Revises: 7f85dd44c775</span><br><span style="color: hsl(120, 100%, 40%);">+Create Date: 2018-10-18 15:13:40.462354</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%);">+# revision identifiers, used by Alembic.</span><br><span style="color: hsl(120, 100%, 40%);">+revision = '2bb1a85135ad'</span><br><span style="color: hsl(120, 100%, 40%);">+down_revision = '7f85dd44c775'</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+from alembic import op</span><br><span style="color: hsl(120, 100%, 40%);">+import sqlalchemy as sa</span><br><span style="color: hsl(120, 100%, 40%);">+from sqlalchemy.dialects.postgresql import ENUM</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+YESNO_NAME = 'yesno_values'</span><br><span style="color: hsl(120, 100%, 40%);">+YESNO_VALUES = ['yes', 'no']</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%);">+def upgrade():</span><br><span style="color: hsl(120, 100%, 40%);">+ ############################# Enums ##############################</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ # yesno_values have already been created, so use postgres enum object</span><br><span style="color: hsl(120, 100%, 40%);">+ # type to get around "already created" issue - works okay with mysql</span><br><span style="color: hsl(120, 100%, 40%);">+ yesno_values = ENUM(*YESNO_VALUES, name=YESNO_NAME, create_type=False)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ op.add_column('ps_globals', sa.Column('use_callerid_contact', yesno_values))</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%);">+def downgrade():</span><br><span style="color: hsl(120, 100%, 40%);">+ if op.get_context().bind.dialect.name == 'mssql':</span><br><span style="color: hsl(120, 100%, 40%);">+ op.drop_constraint('ck_ps_globals_use_callerid_contact_yesno_values','ps_globals')</span><br><span style="color: hsl(120, 100%, 40%);">+ op.drop_column('ps_globals', 'use_callerid_contact')</span><br><span>diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h</span><br><span>index b323bc1..d9e6f2e 100644</span><br><span>--- a/include/asterisk/res_pjsip.h</span><br><span>+++ b/include/asterisk/res_pjsip.h</span><br><span>@@ -2748,6 +2748,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..a02cacd 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_YESNO_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 e681dcb..13c123a 100644</span><br><span>--- a/res/res_pjsip_session.c</span><br><span>+++ b/res/res_pjsip_session.c</span><br><span>@@ -1404,8 +1404,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>@@ -1426,11 +1428,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, S_COR(connected_id.number.valid, 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>@@ -1460,6 +1467,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/10529">change 10529</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/10529"/><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-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I9a720e058323f6862a91c62f8a8c1a4b5c087b95 </div>
<div style="display:none"> Gerrit-Change-Number: 10529 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Torrey Searle <tsearle@gmail.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>