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

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_mwi: unsubscribe unsolicited MWI on deleting endpoint last contact<br><br>If the endpoint's last contact is deleted unsolicited MWI has to be<br>unsubscribed.<br><br>ASTERISK-27051 #close<br><br>Change-Id: I33e174e0b9dba0998927d16d6d100fda5c7254e0<br>---<br>M res/res_pjsip_mwi.c<br>1 file changed, 40 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_pjsip_mwi.c b/res/res_pjsip_mwi.c<br>index 3dfccef..f73f10c 100644<br>--- a/res/res_pjsip_mwi.c<br>+++ b/res/res_pjsip_mwi.c<br>@@ -1229,10 +1229,50 @@<br>     mwi_contact_updated(object);<br> }<br> <br>+/*! \brief Function called when a contact is deleted */<br>+static void mwi_contact_deleted(const void *object)<br>+{<br>+      const struct ast_sip_contact *contact = object;<br>+      struct ao2_iterator *mwi_subs;<br>+       struct mwi_subscription *mwi_sub;<br>+    RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);<br>+    RAII_VAR(struct ast_sip_contact *, found_contact, NULL, ao2_cleanup);<br>+<br>+     if (contact->endpoint) {<br>+          endpoint = ao2_bump(contact->endpoint);<br>+   } else {<br>+             if (!ast_strlen_zero(contact->endpoint_name)) {<br>+                   endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", contact->endpoint_name);<br>+               }<br>+    }<br>+<br>+ if (!endpoint || ast_strlen_zero(endpoint->subscription.mwi.mailboxes)) {<br>+         return;<br>+      }<br>+<br>+ /* Check if there is another contact */<br>+      found_contact = ast_sip_location_retrieve_contact_from_aor_list(endpoint->aors);<br>+  if (found_contact) {<br>+         return;<br>+      }<br>+<br>+ ao2_lock(unsolicited_mwi);<br>+   mwi_subs = ao2_find(unsolicited_mwi, contact->endpoint_name,<br>+              OBJ_SEARCH_KEY | OBJ_MULTIPLE | OBJ_NOLOCK | OBJ_UNLINK);<br>+    if (mwi_subs) {<br>+              for (; (mwi_sub = ao2_iterator_next(mwi_subs)); ao2_cleanup(mwi_sub)) {<br>+                      unsubscribe(mwi_sub, NULL, 0);<br>+               }<br>+            ao2_iterator_destroy(mwi_subs);<br>+      }<br>+    ao2_unlock(unsolicited_mwi);<br>+}<br>+<br> /*! \brief Observer for contacts so unsolicited MWI is sent when a contact changes */<br> static const struct ast_sorcery_observer mwi_contact_observer = {<br>       .created = mwi_contact_added,<br>         .updated = mwi_contact_updated,<br>+      .deleted = mwi_contact_deleted,<br> };<br> <br> /*! \brief Task invoked to send initial MWI NOTIFY for unsolicited */<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/5864">change 5864</a>. To unsubscribe, 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/5864"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I33e174e0b9dba0998927d16d6d100fda5c7254e0 </div>
<div style="display:none"> Gerrit-Change-Number: 5864 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Alexei Gradinari <alex2grad@gmail.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>