[asterisk-commits] res pjsip mwi: unsubscribe unsolicited MWI on deleting endpo... (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jun 20 05:47:46 CDT 2017


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/5864 )

Change subject: res_pjsip_mwi: unsubscribe unsolicited MWI on deleting endpoint last contact
......................................................................

res_pjsip_mwi: unsubscribe unsolicited MWI on deleting endpoint last contact

If the endpoint's last contact is deleted unsolicited MWI has to be
unsubscribed.

ASTERISK-27051 #close

Change-Id: I33e174e0b9dba0998927d16d6d100fda5c7254e0
---
M res/res_pjsip_mwi.c
1 file changed, 40 insertions(+), 0 deletions(-)

Approvals:
  George Joseph: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Approved for Submit



diff --git a/res/res_pjsip_mwi.c b/res/res_pjsip_mwi.c
index 3dfccef..f73f10c 100644
--- a/res/res_pjsip_mwi.c
+++ b/res/res_pjsip_mwi.c
@@ -1229,10 +1229,50 @@
 	mwi_contact_updated(object);
 }
 
+/*! \brief Function called when a contact is deleted */
+static void mwi_contact_deleted(const void *object)
+{
+	const struct ast_sip_contact *contact = object;
+	struct ao2_iterator *mwi_subs;
+	struct mwi_subscription *mwi_sub;
+	RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_sip_contact *, found_contact, NULL, ao2_cleanup);
+
+	if (contact->endpoint) {
+		endpoint = ao2_bump(contact->endpoint);
+	} else {
+		if (!ast_strlen_zero(contact->endpoint_name)) {
+			endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", contact->endpoint_name);
+		}
+	}
+
+	if (!endpoint || ast_strlen_zero(endpoint->subscription.mwi.mailboxes)) {
+		return;
+	}
+
+	/* Check if there is another contact */
+	found_contact = ast_sip_location_retrieve_contact_from_aor_list(endpoint->aors);
+	if (found_contact) {
+		return;
+	}
+
+	ao2_lock(unsolicited_mwi);
+	mwi_subs = ao2_find(unsolicited_mwi, contact->endpoint_name,
+		OBJ_SEARCH_KEY | OBJ_MULTIPLE | OBJ_NOLOCK | OBJ_UNLINK);
+	if (mwi_subs) {
+		for (; (mwi_sub = ao2_iterator_next(mwi_subs)); ao2_cleanup(mwi_sub)) {
+			unsubscribe(mwi_sub, NULL, 0);
+		}
+		ao2_iterator_destroy(mwi_subs);
+	}
+	ao2_unlock(unsolicited_mwi);
+}
+
 /*! \brief Observer for contacts so unsolicited MWI is sent when a contact changes */
 static const struct ast_sorcery_observer mwi_contact_observer = {
 	.created = mwi_contact_added,
 	.updated = mwi_contact_updated,
+	.deleted = mwi_contact_deleted,
 };
 
 /*! \brief Task invoked to send initial MWI NOTIFY for unsolicited */

-- 
To view, visit https://gerrit.asterisk.org/5864
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I33e174e0b9dba0998927d16d6d100fda5c7254e0
Gerrit-Change-Number: 5864
Gerrit-PatchSet: 2
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-commits/attachments/20170620/0c6ed608/attachment-0001.html>


More information about the asterisk-commits mailing list