<p>Alexei Gradinari has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/5863">View Change</a></p><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, 38 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/63/5863/1</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..3d24c66 100644<br>--- a/res/res_pjsip_mwi.c<br>+++ b/res/res_pjsip_mwi.c<br>@@ -1229,10 +1229,48 @@<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 (ast_strlen_zero(contact->endpoint_name)) {<br>+            return;<br>+      }<br>+<br>+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", contact->endpoint_name);<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/5863">change 5863</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/5863"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 14 </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I33e174e0b9dba0998927d16d6d100fda5c7254e0 </div>
<div style="display:none"> Gerrit-Change-Number: 5863 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Alexei Gradinari <alex2grad@gmail.com> </div>