<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/5875">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Richard Mudgett: 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: 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, 41 insertions(+), 31 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 0e8c460..513be8c 100644<br>--- a/res/res_pjsip_mwi.c<br>+++ b/res/res_pjsip_mwi.c<br>@@ -1102,6 +1102,13 @@<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,45 @@<br> return 0;<br> }<br> <br>+/*! \brief Create mwi subscriptions and notify */<br>+static void mwi_contact_changed(const struct ast_sip_contact *contact)<br>+{<br>+ char *id = ast_strdupa(ast_sorcery_object_get_id(contact));<br>+ char *aor = NULL;<br>+ struct ast_sip_endpoint *endpoint = NULL;<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>+ ao2_cleanup(endpoint);<br>+ return;<br>+ }<br>+<br>+ ao2_lock(unsolicited_mwi);<br>+ create_mwi_subscriptions_for_endpoint(endpoint, NULL, 0);<br>+ ao2_unlock(unsolicited_mwi);<br>+ ao2_cleanup(endpoint);<br>+<br>+ aor = strsep(&id, ";@");<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>- 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>+ 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 Function called when a contact is deleted */<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: merged </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: 5 </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>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>