<p>Alexei Gradinari has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/5883">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip_mwi: update unsolicited MWI subscriptions on updating contact<br><br>Do not need to unsubscribe/subscribe on creating the ednpoint's contact.<br>The modified function create_mwi_subscriptions_for_endpoint adds<br>the subscription only if it does not exist.<br><br>The subscriptions aren't added for active contacts<br>which are retrieved on startup from realtime<br>if mwi_disable_initial_unsolicited=yes.<br>Because the mwi_contact_added is not called.<br>So the subscriptions also should be created on updating contact.<br><br>ASTERISK-26230 #close<br><br>Change-Id: I47e265af9296ca09aa42a316fdacac104148cee4<br>---<br>M res/res_pjsip_mwi.c<br>1 file changed, 38 insertions(+), 31 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/83/5883/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..630349f 100644<br>--- a/res/res_pjsip_mwi.c<br>+++ b/res/res_pjsip_mwi.c<br>@@ -1097,11 +1097,18 @@<br>     struct ast_sip_endpoint *endpoint = obj;<br>      char *mailboxes, *mailbox;<br> <br>-        if (ast_strlen_zero(endpoint->subscription.mwi.mailboxes)) {<br>+      if (!endpoint || ast_strlen_zero(endpoint->subscription.mwi.mailboxes)) {<br>          return 0;<br>     }<br> <br>  if (endpoint->subscription.mwi.aggregate) {<br>+               const char *endpoint_id = ast_sorcery_object_get_id(endpoint);<br>+<br>+            /* Check if subscription exists */<br>+           aggregate_sub = ao2_find(unsolicited_mwi, endpoint_id, OBJ_SEARCH_KEY | OBJ_NOLOCK);<br>+         if (aggregate_sub) {<br>+                 return 0;<br>+            }<br>             aggregate_sub = mwi_subscription_alloc(endpoint, 0, NULL);<br>            if (!aggregate_sub) {<br>                         return 0;<br>@@ -1113,7 +1120,9 @@<br>              struct mwi_subscription *sub;<br>                 struct mwi_stasis_subscription *mwi_stasis_sub;<br> <br>-           if (ast_strlen_zero(mailbox)) {<br>+              /* check if subscription exists */<br>+           if (ast_strlen_zero(mailbox) ||<br>+                      (!aggregate_sub && endpoint_receives_unsolicited_mwi_for_mailbox(endpoint, mailbox))) {<br>                       continue;<br>             }<br> <br>@@ -1189,44 +1198,42 @@<br>         return 0;<br> }<br> <br>-/*! \brief Function called when a contact is updated */<br>-static void mwi_contact_updated(const void *object)<br>-{<br>- char *id = ast_strdupa(ast_sorcery_object_get_id(object)), *aor = NULL;<br>+/*! \brief Create mwi subscriptions and notify */<br>+static void mwi_contact_changed(const struct ast_sip_contact *contact) {<br>+       char *id = ast_strdupa(ast_sorcery_object_get_id(contact)), *aor = NULL;<br>+     RAII_VAR(struct ast_sip_endpoint *, endpoint, 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>+ ao2_lock(unsolicited_mwi);<br>+   create_mwi_subscriptions_for_endpoint(endpoint, NULL, 0);<br>+    ao2_unlock(unsolicited_mwi);<br> <br>       aor = strsep(&id, ";@");<br> <br>     ao2_callback(unsolicited_mwi, OBJ_NODATA, send_contact_notify, aor);<br> }<br> <br>+/*! \brief Function called when a contact is updated */<br>+static void mwi_contact_updated(const void *object)<br>+{<br>+      mwi_contact_changed(object);<br>+}<br>+<br> /*! \brief Function called when a contact is added */<br> static void mwi_contact_added(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>-    const char *endpoint_id = ast_sorcery_object_get_id(contact->endpoint);<br>-<br>-        if (ast_strlen_zero(contact->endpoint->subscription.mwi.mailboxes)) {<br>-          return;<br>-      }<br>-<br>- ao2_lock(unsolicited_mwi);<br>-<br>-        mwi_subs = ao2_find(unsolicited_mwi, endpoint_id,<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>-<br>- create_mwi_subscriptions_for_endpoint(contact->endpoint, NULL, 0);<br>-<br>-     ao2_unlock(unsolicited_mwi);<br>-<br>-      mwi_contact_updated(object);<br>+ mwi_contact_changed(object);<br> }<br> <br> /*! \brief Observer for contacts so unsolicited MWI is sent when a contact changes */<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/5883">change 5883</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/5883"/><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: I47e265af9296ca09aa42a316fdacac104148cee4 </div>
<div style="display:none"> Gerrit-Change-Number: 5883 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Alexei Gradinari <alex2grad@gmail.com> </div>