<p>Alexei Gradinari has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/5875">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, 27 insertions(+), 30 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/75/5875/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 206a373..06e8c18 100644<br>--- a/res/res_pjsip_mwi.c<br>+++ b/res/res_pjsip_mwi.c<br>@@ -1102,6 +1102,12 @@<br> }<br> <br> if (endpoint->subscription.mwi.aggregate) {<br>+ const char *endpoint_id = ast_sorcery_object_get_id(endpoint);<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 +1119,9 @@<br> struct mwi_subscription *sub;<br> struct mwi_stasis_subscription *mwi_stasis_sub;<br> <br>- if (ast_strlen_zero(mailbox)) {<br>+ if (ast_strlen_zero(mailbox) ||<br>+ (!aggregate_sub && endpoint_receives_unsolicited_mwi_for_mailbox(endpoint, mailbox))) {<br>+ /* check if subscription exists */<br> continue;<br> }<br> <br>@@ -1189,44 +1197,33 @@<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>-<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 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>+/*! \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> <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>+ 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>+ 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/5875">change 5875</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/5875"/><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: I47e265af9296ca09aa42a316fdacac104148cee4 </div>
<div style="display:none"> Gerrit-Change-Number: 5875 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Alexei Gradinari <alex2grad@gmail.com> </div>