<p>Alexei Gradinari has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/10871">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip: add option to disable ContactStatus event when contact is updated<br><br>This patch adds a new PJSIP global configuration option<br>'send_contact_status_on_update_registration' to be able to have the same<br>performance benefits as version 16.<br><br>By default old behavior, i.e. the ContactStatus event will be sent when a<br>device refreshes its registration.<br><br>Change-Id: I706adf7584e7077eb6bde6d9799ca408bc82ce46<br>---<br>M CHANGES<br>M configs/samples/pjsip.conf.sample<br>A contrib/ast-db-manage/config/versions/0838f8db6a61_pjsip_add_send_contact_status_on_update_.py<br>M include/asterisk/res_pjsip.h<br>M res/res_pjsip.c<br>M res/res_pjsip/config_global.c<br>M res/res_pjsip/pjsip_options.c<br>7 files changed, 108 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/71/10871/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/CHANGES b/CHANGES</span><br><span>index 6d1d859..da58f29 100644</span><br><span>--- a/CHANGES</span><br><span>+++ b/CHANGES</span><br><span>@@ -12,6 +12,11 @@</span><br><span> --- Functionality changes from Asterisk 13.24.0 to Asterisk 13.25.0 ----------</span><br><span> ------------------------------------------------------------------------------</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+res_pjsip</span><br><span style="color: hsl(120, 100%, 40%);">+------------------</span><br><span style="color: hsl(120, 100%, 40%);">+ * Added "send_contact_status_on_update_registration" global configuration option</span><br><span style="color: hsl(120, 100%, 40%);">+ to enable sending AMI ContactStatus event when a device refreshes its registration.</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> Features</span><br><span> ------------------</span><br><span> * Before Asterisk 12, when using the automon or automixmon features defined</span><br><span>diff --git a/configs/samples/pjsip.conf.sample b/configs/samples/pjsip.conf.sample</span><br><span>index 56e7849..a04ce05 100644</span><br><span>--- a/configs/samples/pjsip.conf.sample</span><br><span>+++ b/configs/samples/pjsip.conf.sample</span><br><span>@@ -1107,6 +1107,11 @@</span><br><span> ; from incoming SIP URI user fields are always truncated at the</span><br><span> ; first semicolon.</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+;send_contact_status_on_update_registration=yes ; Enable sending AMI ContactStatus</span><br><span style="color: hsl(120, 100%, 40%);">+ ; event when a device refreshes its registration</span><br><span style="color: hsl(120, 100%, 40%);">+ ; (default: "yes")</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ; MODULE PROVIDING BELOW SECTION(S): res_pjsip_acl</span><br><span> ;==========================ACL SECTION OPTIONS=========================</span><br><span> ;[acl]</span><br><span>diff --git a/contrib/ast-db-manage/config/versions/0838f8db6a61_pjsip_add_send_contact_status_on_update_.py b/contrib/ast-db-manage/config/versions/0838f8db6a61_pjsip_add_send_contact_status_on_update_.py</span><br><span>new file mode 100644</span><br><span>index 0000000..2d31291</span><br><span>--- /dev/null</span><br><span>+++ b/contrib/ast-db-manage/config/versions/0838f8db6a61_pjsip_add_send_contact_status_on_update_.py</span><br><span>@@ -0,0 +1,39 @@</span><br><span style="color: hsl(120, 100%, 40%);">+"""pjsip add send_contact_status_on_update_registration</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+Revision ID: 0838f8db6a61</span><br><span style="color: hsl(120, 100%, 40%);">+Revises: 1ac563b350a8</span><br><span style="color: hsl(120, 100%, 40%);">+Create Date: 2018-12-18 14:45:07.811415</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 = '0838f8db6a61'</span><br><span style="color: hsl(120, 100%, 40%);">+down_revision = '1ac563b350a8'</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%);">+AST_BOOL_NAME = 'ast_bool_values'</span><br><span style="color: hsl(120, 100%, 40%);">+# We'll just ignore the n/y and f/t abbreviations as Asterisk does not write</span><br><span style="color: hsl(120, 100%, 40%);">+# those aliases.</span><br><span style="color: hsl(120, 100%, 40%);">+AST_BOOL_VALUES = [ '0', '1',</span><br><span style="color: hsl(120, 100%, 40%);">+ 'off', 'on',</span><br><span style="color: hsl(120, 100%, 40%);">+ 'false', 'true',</span><br><span style="color: hsl(120, 100%, 40%);">+ 'no', 'yes' ]</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%);">+ # ast_bool_values has 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%);">+ ast_bool_values = ENUM(*AST_BOOL_VALUES, name=AST_BOOL_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('send_contact_status_on_update_registration', ast_bool_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_send_contact_status_on_update_registration_ast_bool_values', 'ps_globals')</span><br><span style="color: hsl(120, 100%, 40%);">+ op.drop_column('ps_globals', 'send_contact_status_on_update_registration')</span><br><span>diff --git a/include/asterisk/res_pjsip.h b/include/asterisk/res_pjsip.h</span><br><span>index 902cfe8..7854df7 100644</span><br><span>--- a/include/asterisk/res_pjsip.h</span><br><span>+++ b/include/asterisk/res_pjsip.h</span><br><span>@@ -2794,6 +2794,15 @@</span><br><span> unsigned int ast_sip_get_ignore_uri_user_options(void);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Retrieve the global setting 'send_contact_status_on_update_registration'.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.25.0</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval non zero if need to send AMI ContactStatus event when a contact is updated.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+unsigned int ast_sip_get_send_contact_status_on_update_registration(void);</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> * \brief Truncate the URI user field options string if enabled.</span><br><span> * \since 13.12.0</span><br><span> *</span><br><span>diff --git a/res/res_pjsip.c b/res/res_pjsip.c</span><br><span>index 76ef59e..812c291 100644</span><br><span>--- a/res/res_pjsip.c</span><br><span>+++ b/res/res_pjsip.c</span><br><span>@@ -1841,6 +1841,9 @@</span><br><span> generated Contact headers.</para></span><br><span> </description></span><br><span> </configOption></span><br><span style="color: hsl(120, 100%, 40%);">+ <configOption name="send_contact_status_on_update_registration" default="yes"></span><br><span style="color: hsl(120, 100%, 40%);">+ <synopsis>Enable sending AMI ContactStatus event when a device refreshes its registration.</synopsis></span><br><span style="color: hsl(120, 100%, 40%);">+ </configOption></span><br><span> </configObject></span><br><span> </configFile></span><br><span> </configInfo></span><br><span>diff --git a/res/res_pjsip/config_global.c b/res/res_pjsip/config_global.c</span><br><span>index a02cacd..5b52574 100644</span><br><span>--- a/res/res_pjsip/config_global.c</span><br><span>+++ b/res/res_pjsip/config_global.c</span><br><span>@@ -49,6 +49,7 @@</span><br><span> #define DEFAULT_MWI_DISABLE_INITIAL_UNSOLICITED 0</span><br><span> #define DEFAULT_IGNORE_URI_USER_OPTIONS 0</span><br><span> #define DEFAULT_USE_CALLERID_CONTACT 0</span><br><span style="color: hsl(120, 100%, 40%);">+#define DEFAULT_SEND_CONTACT_STATUS_ON_UPDATE_REGISTRATION 1</span><br><span> </span><br><span> /*!</span><br><span> * \brief Cached global config object</span><br><span>@@ -106,6 +107,8 @@</span><br><span> unsigned int ignore_uri_user_options;</span><br><span> /*! Nonzero if CALLERID(num) is to be used as the default contact username instead of default_from_user */</span><br><span> unsigned int use_callerid_contact;</span><br><span style="color: hsl(120, 100%, 40%);">+ /*! Nonzero if need to send AMI ContactStatus event when a contact is updated */</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int send_contact_status_on_update_registration;</span><br><span> };</span><br><span> </span><br><span> static void global_destructor(void *obj)</span><br><span>@@ -420,6 +423,21 @@</span><br><span> return use_callerid_contact;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+unsigned int ast_sip_get_send_contact_status_on_update_registration(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ unsigned int send_contact_status_on_update_registration;</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_SEND_CONTACT_STATUS_ON_UPDATE_REGISTRATION;</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%);">+ send_contact_status_on_update_registration = cfg->send_contact_status_on_update_registration;</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(cfg, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ return send_contact_status_on_update_registration;</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>@@ -574,6 +592,9 @@</span><br><span> ast_sorcery_object_field_register(sorcery, "global", "use_callerid_contact",</span><br><span> DEFAULT_USE_CALLERID_CONTACT ? "yes" : "no",</span><br><span> OPT_YESNO_T, 1, FLDSET(struct global_config, use_callerid_contact));</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_sorcery_object_field_register(sorcery, "global", "send_contact_status_on_update_registration",</span><br><span style="color: hsl(120, 100%, 40%);">+ DEFAULT_SEND_CONTACT_STATUS_ON_UPDATE_REGISTRATION ? "yes" : "no",</span><br><span style="color: hsl(120, 100%, 40%);">+ OPT_YESNO_T, 1, FLDSET(struct global_config, send_contact_status_on_update_registration));</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/pjsip_options.c b/res/res_pjsip/pjsip_options.c</span><br><span>index f253dce..81e8304 100644</span><br><span>--- a/res/res_pjsip/pjsip_options.c</span><br><span>+++ b/res/res_pjsip/pjsip_options.c</span><br><span>@@ -2228,42 +2228,45 @@</span><br><span> /*! \brief Observer callback invoked on contact update */</span><br><span> static void contact_observer_updated(const void *obj)</span><br><span> {</span><br><span style="color: hsl(0, 100%, 40%);">- struct sip_options_contact_observer_task_data *task_data;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_sip_contact *contact = (struct ast_sip_contact *) obj;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct sip_options_aor *aor_options = ao2_find(sip_options_aors, contact->aor, OBJ_SEARCH_KEY);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- task_data = ast_malloc(sizeof(*task_data));</span><br><span style="color: hsl(0, 100%, 40%);">- if (!task_data) {</span><br><span style="color: hsl(0, 100%, 40%);">- return;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- task_data->contact = (struct ast_sip_contact *) obj;</span><br><span style="color: hsl(0, 100%, 40%);">- task_data->aor_options = ao2_find(sip_options_aors, task_data->contact->aor,</span><br><span style="color: hsl(0, 100%, 40%);">- OBJ_SEARCH_KEY);</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- if (has_qualify_changed(task_data->contact, task_data->aor_options)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (has_qualify_changed(contact, aor_options)) {</span><br><span> struct ast_sip_aor *aor;</span><br><span> </span><br><span> aor = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "aor",</span><br><span style="color: hsl(0, 100%, 40%);">- task_data->contact->aor);</span><br><span style="color: hsl(120, 100%, 40%);">+ contact->aor);</span><br><span> if (aor) {</span><br><span> ast_debug(3, "AOR '%s' qualify options have been modified. Synchronize an AOR local state\n",</span><br><span style="color: hsl(0, 100%, 40%);">- task_data->contact->aor);</span><br><span style="color: hsl(120, 100%, 40%);">+ contact->aor);</span><br><span> ast_sip_push_task_wait_serializer(management_serializer,</span><br><span> sip_options_aor_observer_modified_task, aor);</span><br><span> ao2_ref(aor, -1);</span><br><span> }</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (!task_data->aor_options) {</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(task_data);</span><br><span style="color: hsl(0, 100%, 40%);">- return;</span><br><span style="color: hsl(0, 100%, 40%);">- }</span><br><span style="color: hsl(120, 100%, 40%);">+ if (aor_options && ast_sip_get_send_contact_status_on_update_registration()) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct sip_options_contact_observer_task_data *task_data;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(task_data->contact, +1);</span><br><span style="color: hsl(0, 100%, 40%);">- if (ast_sip_push_task(task_data->aor_options->serializer,</span><br><span style="color: hsl(0, 100%, 40%);">- sip_options_contact_update_task, task_data)) {</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(task_data->contact, -1);</span><br><span style="color: hsl(0, 100%, 40%);">- ao2_ref(task_data->aor_options, -1);</span><br><span style="color: hsl(0, 100%, 40%);">- ast_free(task_data);</span><br><span style="color: hsl(120, 100%, 40%);">+ task_data = ast_malloc(sizeof(*task_data));</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!task_data) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(aor_options, -1);</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%);">+ task_data->contact = (struct ast_sip_contact *) contact;</span><br><span style="color: hsl(120, 100%, 40%);">+ /* task_data takes ownership of aor_options and will take care of releasing the ref */</span><br><span style="color: hsl(120, 100%, 40%);">+ task_data->aor_options = aor_options;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(task_data->contact, +1);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sip_push_task(task_data->aor_options->serializer,</span><br><span style="color: hsl(120, 100%, 40%);">+ sip_options_contact_update_task, task_data)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(task_data->contact, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_ref(task_data->aor_options, -1);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(task_data);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_cleanup(aor_options);</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/10871">change 10871</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/10871"/><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: I706adf7584e7077eb6bde6d9799ca408bc82ce46 </div>
<div style="display:none"> Gerrit-Change-Number: 10871 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Alexei Gradinari <alex2grad@gmail.com> </div>