[Asterisk-code-review] res pjsip mwi: update unsolicited MWI subscriptions on updat... (asterisk[13])

Alexei Gradinari asteriskteam at digium.com
Fri Jun 16 18:27:59 CDT 2017


Alexei Gradinari has uploaded this change for review. ( https://gerrit.asterisk.org/5875


Change subject: res_pjsip_mwi: update unsolicited MWI subscriptions on updating contact
......................................................................

res_pjsip_mwi: update unsolicited MWI subscriptions on updating contact

Do not need to unsubscribe/subscribe on creating the ednpoint's contact.
The modified function create_mwi_subscriptions_for_endpoint adds
the subscription only if it does not exist.

The subscriptions aren't added for active contacts
which are retrieved on startup from realtime
if mwi_disable_initial_unsolicited=yes.
Because the mwi_contact_added is not called.
So the subscriptions also should be created on updating contact.

ASTERISK-26230 #close

Change-Id: I47e265af9296ca09aa42a316fdacac104148cee4
---
M res/res_pjsip_mwi.c
1 file changed, 27 insertions(+), 30 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/75/5875/1

diff --git a/res/res_pjsip_mwi.c b/res/res_pjsip_mwi.c
index 206a373..06e8c18 100644
--- a/res/res_pjsip_mwi.c
+++ b/res/res_pjsip_mwi.c
@@ -1102,6 +1102,12 @@
 	}
 
 	if (endpoint->subscription.mwi.aggregate) {
+		const char *endpoint_id = ast_sorcery_object_get_id(endpoint);
+		/* Check if subscription exists */
+		aggregate_sub = ao2_find(unsolicited_mwi, endpoint_id, OBJ_SEARCH_KEY | OBJ_NOLOCK);
+		if (aggregate_sub) {
+			return 0;
+		}
 		aggregate_sub = mwi_subscription_alloc(endpoint, 0, NULL);
 		if (!aggregate_sub) {
 			return 0;
@@ -1113,7 +1119,9 @@
 		struct mwi_subscription *sub;
 		struct mwi_stasis_subscription *mwi_stasis_sub;
 
-		if (ast_strlen_zero(mailbox)) {
+		if (ast_strlen_zero(mailbox) ||
+			(!aggregate_sub && endpoint_receives_unsolicited_mwi_for_mailbox(endpoint, mailbox))) {
+			/* check if subscription exists */
 			continue;
 		}
 
@@ -1189,44 +1197,33 @@
 	return 0;
 }
 
-/*! \brief Function called when a contact is updated */
-static void mwi_contact_updated(const void *object)
-{
-	char *id = ast_strdupa(ast_sorcery_object_get_id(object)), *aor = NULL;
-
-	aor = strsep(&id, ";@");
-
-	ao2_callback(unsolicited_mwi, OBJ_NODATA, send_contact_notify, aor);
-}
-
-/*! \brief Function called when a contact is added */
-static void mwi_contact_added(const void *object)
-{
-	const struct ast_sip_contact *contact = object;
-	struct ao2_iterator *mwi_subs;
-	struct mwi_subscription *mwi_sub;
-	const char *endpoint_id = ast_sorcery_object_get_id(contact->endpoint);
+/*! \brief Create mwi subscriptions and notify */
+static void mwi_contact_changed(const struct ast_sip_contact *contact) {
+	char *id = ast_strdupa(ast_sorcery_object_get_id(contact)), *aor = NULL;
 
 	if (ast_strlen_zero(contact->endpoint->subscription.mwi.mailboxes)) {
 		return;
 	}
 
 	ao2_lock(unsolicited_mwi);
-
-	mwi_subs = ao2_find(unsolicited_mwi, endpoint_id,
-		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);
-	}
-
 	create_mwi_subscriptions_for_endpoint(contact->endpoint, NULL, 0);
-
 	ao2_unlock(unsolicited_mwi);
 
-	mwi_contact_updated(object);
+	aor = strsep(&id, ";@");
+
+	ao2_callback(unsolicited_mwi, OBJ_NODATA, send_contact_notify, aor);
+}
+
+/*! \brief Function called when a contact is updated */
+static void mwi_contact_updated(const void *object)
+{
+	mwi_contact_changed(object);
+}
+
+/*! \brief Function called when a contact is added */
+static void mwi_contact_added(const void *object)
+{
+	mwi_contact_changed(object);
 }
 
 /*! \brief Observer for contacts so unsolicited MWI is sent when a contact changes */

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

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: I47e265af9296ca09aa42a316fdacac104148cee4
Gerrit-Change-Number: 5875
Gerrit-PatchSet: 1
Gerrit-Owner: Alexei Gradinari <alex2grad at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20170616/2bc4bff2/attachment-0001.html>


More information about the asterisk-code-review mailing list