<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/9966">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  George Joseph: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved
  Joshua Colp: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip: Reduce processing when a Contact is updated.<br><br>When a Contact is updated the only material change that qualify<br>support cares about is the underlying configuration for the AOR.<br>In this case we will update things with the new AOR information but<br>otherwise the callback to indicate the Contact has changed can be<br>ignored.<br><br>This is because it is only when a Contact is added or deleted that<br>material changes occur within the qualify support. An update can't<br>change the URI since it would result in a new Contact so it can be<br>ignored.<br><br>Change-Id: I2f97ebfa79969a36a97bb7b9afd5b6268cf1a07d<br>---<br>M UPGRADE.txt<br>M res/res_pjsip/pjsip_options.c<br>2 files changed, 9 insertions(+), 57 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/UPGRADE.txt b/UPGRADE.txt</span><br><span>index 8b4fdf7..41e22c6 100644</span><br><span>--- a/UPGRADE.txt</span><br><span>+++ b/UPGRADE.txt</span><br><span>@@ -39,6 +39,8 @@</span><br><span>  - The ContactStatus and Status fields for the manager events ContactStatus</span><br><span>    and ContactStatusDetail are now set to "NonQualified" when a contact exists</span><br><span>    but has not been qualified.</span><br><span style="color: hsl(120, 100%, 40%);">+ - The ContactStatus event will no longer be sent by PJSIP when a device</span><br><span style="color: hsl(120, 100%, 40%);">+   refreshes its registration.</span><br><span> </span><br><span> ARI:</span><br><span>  - The ContactInfo event's contact_status field is now set to "NonQualified"</span><br><span>diff --git a/res/res_pjsip/pjsip_options.c b/res/res_pjsip/pjsip_options.c</span><br><span>index eb84c1b..f2439c4 100644</span><br><span>--- a/res/res_pjsip/pjsip_options.c</span><br><span>+++ b/res/res_pjsip/pjsip_options.c</span><br><span>@@ -2065,7 +2065,7 @@</span><br><span> /*!</span><br><span>  * \brief Check if the contact qualify options are different than local aor qualify options</span><br><span>  */</span><br><span style="color: hsl(0, 100%, 40%);">-static int has_qualify_changed (struct ast_sip_contact *contact, struct sip_options_aor *aor_options)</span><br><span style="color: hsl(120, 100%, 40%);">+static int has_qualify_changed (const struct ast_sip_contact *contact, const struct sip_options_aor *aor_options)</span><br><span> {</span><br><span>         if (!contact) {</span><br><span>          return 0;</span><br><span>@@ -2186,77 +2186,27 @@</span><br><span>              sip_options_contact_add_management_task, (void *) obj);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-/*!</span><br><span style="color: hsl(0, 100%, 40%);">- * \brief Task which updates a dynamic contact to an AOR</span><br><span style="color: hsl(0, 100%, 40%);">- * \note Run by aor_options->serializer</span><br><span style="color: hsl(0, 100%, 40%);">- */</span><br><span style="color: hsl(0, 100%, 40%);">-static int sip_options_contact_update_task(void *obj)</span><br><span style="color: hsl(0, 100%, 40%);">-{</span><br><span style="color: hsl(0, 100%, 40%);">-  struct sip_options_contact_observer_task_data *task_data = obj;</span><br><span style="color: hsl(0, 100%, 40%);">- struct ast_sip_contact_status *contact_status;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-  contact_status = ast_sip_get_contact_status(task_data->contact);</span><br><span style="color: hsl(0, 100%, 40%);">-     if (contact_status) {</span><br><span style="color: hsl(0, 100%, 40%);">-           switch (contact_status->status) {</span><br><span style="color: hsl(0, 100%, 40%);">-            case CREATED:</span><br><span style="color: hsl(0, 100%, 40%);">-           case UNAVAILABLE:</span><br><span style="color: hsl(0, 100%, 40%);">-               case AVAILABLE:</span><br><span style="color: hsl(0, 100%, 40%);">-         case UNKNOWN:</span><br><span style="color: hsl(0, 100%, 40%);">-                   /* Refresh the ContactStatus AMI events. */</span><br><span style="color: hsl(0, 100%, 40%);">-                     sip_options_contact_status_update(contact_status);</span><br><span style="color: hsl(0, 100%, 40%);">-                      break;</span><br><span style="color: hsl(0, 100%, 40%);">-          case REMOVED:</span><br><span style="color: hsl(0, 100%, 40%);">-                   break;</span><br><span style="color: hsl(0, 100%, 40%);">-          }</span><br><span style="color: hsl(0, 100%, 40%);">-               ao2_ref(contact_status, -1);</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%);">-       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(0, 100%, 40%);">-    return 0;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</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%);">+     const struct ast_sip_contact *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(0, 100%, 40%);">-</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(0, 100%, 40%);">-    }</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/9966">change 9966</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/9966"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16.0 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I2f97ebfa79969a36a97bb7b9afd5b6268cf1a07d </div>
<div style="display:none"> Gerrit-Change-Number: 9966 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>