[Asterisk-code-review] MWI: Update modules that subscribe to MWI to use new API calls (...asterisk[master])

Kevin Harwell asteriskteam at digium.com
Fri Jul 12 09:19:20 CDT 2019


Kevin Harwell has submitted this change and it was merged. ( https://gerrit.asterisk.org/c/asterisk/+/11464 )

Change subject: MWI: Update modules that subscribe to MWI to use new API calls
......................................................................

MWI: Update modules that subscribe to MWI to use new API calls

The MWI core recently got some new API calls that make tracking MWI state
lifetime more reliable. This patch updates those modules that subscribe to
specific MWI topics to use the new API. Specifically, these modules now
subscribe to both MWI topics and MWI state.

ASTERISK-28442

Change-Id: I32bef880b647246823dbccdf44a98d384fcabfbd
---
M channels/chan_dahdi.c
M channels/chan_dahdi.h
M channels/chan_iax2.c
M channels/chan_mgcp.c
M channels/chan_sip.c
M channels/chan_skinny.c
M channels/sig_pri.c
M channels/sig_pri.h
M channels/sip/include/sip.h
M res/res_pjsip_mwi.c
10 files changed, 52 insertions(+), 96 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, approved; Approved for Submit



diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 434bd16..a721d7b 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -5540,7 +5540,7 @@
 		ao2_cleanup(p->smdi_iface);
 	}
 	if (p->mwi_event_sub) {
-		p->mwi_event_sub = stasis_unsubscribe(p->mwi_event_sub);
+		p->mwi_event_sub = ast_mwi_unsubscribe(p->mwi_event_sub);
 	}
 	if (p->vars) {
 		ast_variables_destroy(p->vars);
@@ -12607,18 +12607,11 @@
 		tmp->cid_subaddr[0] = '\0';
 		ast_copy_string(tmp->mailbox, conf->chan.mailbox, sizeof(tmp->mailbox));
 		if (channel != CHAN_PSEUDO && !ast_strlen_zero(tmp->mailbox)) {
-			struct stasis_topic *mailbox_specific_topic;
-
-			mailbox_specific_topic = ast_mwi_topic(tmp->mailbox);
-			if (mailbox_specific_topic) {
-				/* This module does not handle MWI in an event-based manner.  However, it
-				 * subscribes to MWI for each mailbox that is configured so that the core
-				 * knows that we care about it.  Then, chan_dahdi will get the MWI from the
-				 * event cache instead of checking the mailbox directly. */
-				tmp->mwi_event_sub = stasis_subscribe_pool(mailbox_specific_topic, stasis_subscription_cb_noop, NULL);
-				stasis_subscription_accept_message_type(tmp->mwi_event_sub, ast_mwi_state_type());
-				stasis_subscription_set_filter(tmp->mwi_event_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
-			}
+			/* This module does not handle MWI in an event-based manner.  However, it
+			 * subscribes to MWI for each mailbox that is configured so that the core
+			 * knows that we care about it.  Then, chan_dahdi will get the MWI from the
+			 * event cache instead of checking the mailbox directly. */
+			tmp->mwi_event_sub = ast_mwi_subscribe_pool(tmp->mailbox, stasis_subscription_cb_noop, NULL);
 		}
 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
 		tmp->mwisend_setting = conf->chan.mwisend_setting;
diff --git a/channels/chan_dahdi.h b/channels/chan_dahdi.h
index 212a0bf..d84be51 100644
--- a/channels/chan_dahdi.h
+++ b/channels/chan_dahdi.h
@@ -653,7 +653,7 @@
 	 */
 	char mailbox[AST_MAX_MAILBOX_UNIQUEID];
 	/*! \brief Opaque event subscription parameters for message waiting indication support. */
-	struct stasis_subscription *mwi_event_sub;
+	struct ast_mwi_subscriber *mwi_event_sub;
 	/*! \brief Delayed dialing for E911.  Overlap digits for ISDN. */
 	char dialdest[256];
 #ifdef HAVE_DAHDI_LINEREVERSE_VMWI
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index a7b2f26..30f9496 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -582,7 +582,7 @@
 	int smoothing;					/*!< Sample over how many units to determine historic ms */
 	uint16_t maxcallno;				/*!< Max call number limit for this peer.  Set on registration */
 
-	struct stasis_subscription *mwi_event_sub;	/*!< This subscription lets pollmailboxes know which mailboxes need to be polled */
+	struct ast_mwi_subscriber *mwi_event_sub;	/*!< This subscription lets pollmailboxes know which mailboxes need to be polled */
 
 	struct ast_acl_list *acl;
 	enum calltoken_peer_enum calltoken_required;	/*!< Is calltoken validation required or not, can be YES, NO, or AUTO */
@@ -12764,7 +12764,9 @@
 	if (peer->dnsmgr)
 		ast_dnsmgr_release(peer->dnsmgr);
 
-	peer->mwi_event_sub = stasis_unsubscribe(peer->mwi_event_sub);
+	if (peer->mwi_event_sub) {
+		peer->mwi_event_sub = ast_mwi_unsubscribe(peer->mwi_event_sub);
+	}
 
 	ast_string_field_free_memory(peer);
 
@@ -13069,17 +13071,10 @@
 	}
 
 	if (!ast_strlen_zero(peer->mailbox) && !peer->mwi_event_sub) {
-		struct stasis_topic *mailbox_specific_topic;
-
-		mailbox_specific_topic = ast_mwi_topic(peer->mailbox);
-		if (mailbox_specific_topic) {
-			/* The MWI subscriptions exist just so the core knows we care about those
-			 * mailboxes.  However, we just grab the events out of the cache when it
-			 * is time to send MWI, since it is only sent with a REGACK. */
-			peer->mwi_event_sub = stasis_subscribe_pool(mailbox_specific_topic, stasis_subscription_cb_noop, NULL);
-			stasis_subscription_accept_message_type(peer->mwi_event_sub, ast_mwi_state_type());
-			stasis_subscription_set_filter(peer->mwi_event_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
-		}
+		/* The MWI subscriptions exist just so the core knows we care about those
+		 * mailboxes.  However, we just grab the events out of the cache when it
+		 * is time to send MWI, since it is only sent with a REGACK. */
+		peer->mwi_event_sub = ast_mwi_subscribe_pool(peer->mailbox, stasis_subscription_cb_noop, NULL);
 	}
 
 	if (subscribe_acl_change) {
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c
index fa3a081..2c8c525 100644
--- a/channels/chan_mgcp.c
+++ b/channels/chan_mgcp.c
@@ -346,7 +346,7 @@
 	char curtone[80];			/*!< Current tone */
 	char mailbox[AST_MAX_EXTENSION];
 	char parkinglot[AST_MAX_CONTEXT];   /*!< Parkinglot */
-	struct stasis_subscription *mwi_event_sub;
+	struct ast_mwi_subscriber *mwi_event_sub;
 	ast_group_t callgroup;
 	ast_group_t pickupgroup;
 	int callwaiting;
@@ -4234,18 +4234,11 @@
 				ast_copy_string(e->mailbox, mailbox, sizeof(e->mailbox));
 				ast_copy_string(e->parkinglot, parkinglot, sizeof(e->parkinglot));
 				if (!ast_strlen_zero(e->mailbox)) {
-					struct stasis_topic *mailbox_specific_topic;
-
-					mailbox_specific_topic = ast_mwi_topic(e->mailbox);
-					if (mailbox_specific_topic) {
-						/* This module does not handle MWI in an event-based manner.  However, it
-						 * subscribes to MWI for each mailbox that is configured so that the core
-						 * knows that we care about it.  Then, chan_mgcp will get the MWI from the
-						 * event cache instead of checking the mailbox directly. */
-						e->mwi_event_sub = stasis_subscribe_pool(mailbox_specific_topic, stasis_subscription_cb_noop, NULL);
-						stasis_subscription_accept_message_type(e->mwi_event_sub, ast_mwi_state_type());
-						stasis_subscription_set_filter(e->mwi_event_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
-					}
+					/* This module does not handle MWI in an event-based manner.  However, it
+					 * subscribes to MWI for each mailbox that is configured so that the core
+					 * knows that we care about it.  Then, chan_mgcp will get the MWI from the
+					 * event cache instead of checking the mailbox directly. */
+					e->mwi_event_sub = ast_mwi_subscribe_pool(e->mailbox, stasis_subscription_cb_noop, NULL);
 				}
 				snprintf(e->rqnt_ident, sizeof(e->rqnt_ident), "%08lx", (unsigned long)ast_random());
 				e->msgstate = -1;
@@ -4587,7 +4580,7 @@
 	}
 
 	if (e->mwi_event_sub) {
-		e->mwi_event_sub = stasis_unsubscribe(e->mwi_event_sub);
+		e->mwi_event_sub = ast_mwi_unsubscribe(e->mwi_event_sub);
 	}
 
 	if (e->chanvars) {
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index cd0db38..eef0d41 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -5251,7 +5251,7 @@
 static void destroy_mailbox(struct sip_mailbox *mailbox)
 {
 	if (mailbox->event_sub) {
-		mailbox->event_sub = stasis_unsubscribe_and_join(mailbox->event_sub);
+		mailbox->event_sub = ast_mwi_unsubscribe_and_join(mailbox->event_sub);
 	}
 	ast_free(mailbox);
 }
@@ -28384,18 +28384,14 @@
 	struct sip_mailbox *mailbox;
 
 	AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) {
-		struct stasis_topic *mailbox_specific_topic;
-
 		if (mailbox->status != SIP_MAILBOX_STATUS_NEW) {
 			continue;
 		}
-
-		mailbox_specific_topic = ast_mwi_topic(mailbox->id);
-		if (mailbox_specific_topic) {
-			mailbox->event_sub = stasis_subscribe_pool(mailbox_specific_topic, mwi_event_cb, peer);
-			stasis_subscription_accept_message_type(mailbox->event_sub, ast_mwi_state_type());
-			stasis_subscription_accept_message_type(mailbox->event_sub, stasis_subscription_change_type());
-			stasis_subscription_set_filter(mailbox->event_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
+		mailbox->event_sub = ast_mwi_subscribe_pool(mailbox->id, mwi_event_cb, peer);
+		if (mailbox->event_sub) {
+			stasis_subscription_accept_message_type(
+				ast_mwi_subscriber_subscription(mailbox->event_sub),
+				stasis_subscription_change_type());
 		}
 	}
 }
diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c
index fb31c9f..17bc039 100644
--- a/channels/chan_skinny.c
+++ b/channels/chan_skinny.c
@@ -1466,7 +1466,7 @@
 	SKINNY_LINE_OPTIONS
 	ast_mutex_t lock;
 	struct skinny_container *container;
-	struct stasis_subscription *mwi_event_sub; /* Event based MWI */
+	struct ast_mwi_subscriber *mwi_event_sub; /* Event based MWI */
 	struct skinny_subchannel *activesub;
 	AST_LIST_HEAD(, skinny_subchannel) sub;
 	AST_LIST_HEAD(, skinny_subline) sublines;
@@ -8328,16 +8328,8 @@
 	config_parse_variables(TYPE_LINE, l, v);
 
 	if (!ast_strlen_zero(l->mailbox)) {
-		struct stasis_topic *mailbox_specific_topic;
-
 		ast_verb(3, "Setting mailbox '%s' on line %s\n", l->mailbox, l->name);
-
-		mailbox_specific_topic = ast_mwi_topic(l->mailbox);
-		if (mailbox_specific_topic) {
-			l->mwi_event_sub = stasis_subscribe_pool(mailbox_specific_topic, mwi_event_cb, l);
-			stasis_subscription_accept_message_type(l->mwi_event_sub, ast_mwi_state_type());
-			stasis_subscription_set_filter(l->mwi_event_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
-		}
+		l->mwi_event_sub = ast_mwi_subscribe_pool(l->mailbox, mwi_event_cb, l);
 	}
 
 	if (!ast_strlen_zero(vmexten) && ast_strlen_zero(l->vmexten)) {
@@ -8640,7 +8632,7 @@
 		   will happen below. */
 		while ((l = AST_LIST_REMOVE_HEAD(&d->lines, list))) {
 			if (l->mwi_event_sub) {
-				l->mwi_event_sub = stasis_unsubscribe(l->mwi_event_sub);
+				l->mwi_event_sub = ast_mwi_unsubscribe(l->mwi_event_sub);
 			}
 		}
 		/* Delete all speeddials for this device */
@@ -8797,7 +8789,7 @@
 				skinny_unlocksub(sub);
 			}
 			if (l->mwi_event_sub) {
-				l->mwi_event_sub = stasis_unsubscribe_and_join(l->mwi_event_sub);
+				l->mwi_event_sub = ast_mwi_unsubscribe_and_join(l->mwi_event_sub);
 			}
 			ast_mutex_unlock(&l->lock);
 			unregister_exten(l);
diff --git a/channels/sig_pri.c b/channels/sig_pri.c
index 102e3c4..a8c042f 100644
--- a/channels/sig_pri.c
+++ b/channels/sig_pri.c
@@ -8982,7 +8982,7 @@
 #if defined(HAVE_PRI_MWI)
 	for (idx = 0; idx < ARRAY_LEN(pri->mbox); ++idx) {
 		if (pri->mbox[idx].sub) {
-			pri->mbox[idx].sub = stasis_unsubscribe_and_join(pri->mbox[idx].sub);
+			pri->mbox[idx].sub = ast_mwi_unsubscribe_and_join(pri->mbox[idx].sub);
 		}
 	}
 #endif	/* defined(HAVE_PRI_MWI) */
@@ -9051,7 +9051,7 @@
 	/* Prepare the mbox[] for use. */
 	for (i = 0; i < ARRAY_LEN(pri->mbox); ++i) {
 		if (pri->mbox[i].sub) {
-			pri->mbox[i].sub = stasis_unsubscribe(pri->mbox[i].sub);
+			pri->mbox[i].sub = ast_mwi_unsubscribe(pri->mbox[i].sub);
 		}
 	}
 #endif	/* defined(HAVE_PRI_MWI) */
@@ -9108,7 +9108,6 @@
 	saveptr = pri->mwi_mailboxes;
 	for (i = 0; i < ARRAY_LEN(pri->mbox); ++i) {
 		char *mbox_id;
-		struct stasis_topic *mailbox_specific_topic;
 
 		mbox_id = strsep(&saveptr, ",");
 		if (mbox_id) {
@@ -9127,16 +9126,10 @@
 			continue;
 		}
 
-		mailbox_specific_topic = ast_mwi_topic(mbox_id);
-		if (mailbox_specific_topic) {
-			pri->mbox[i].sub = stasis_subscribe_pool(mailbox_specific_topic, sig_pri_mwi_event_cb, pri);
-		}
+		pri->mbox[i].sub = ast_mwi_subscribe_pool(mbox_id, sig_pri_mwi_event_cb, pri);
 		if (!pri->mbox[i].sub) {
 			ast_log(LOG_ERROR, "%s span %d could not subscribe to MWI events for %s(%s).\n",
 				sig_pri_cc_type_name, pri->span, pri->mbox[i].vm_box, mbox_id);
-		} else {
-			stasis_subscription_accept_message_type(pri->mbox[i].sub, ast_mwi_state_type());
-			stasis_subscription_set_filter(pri->mbox[i].sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
 		}
 #if defined(HAVE_PRI_MWI_V2)
 		if (ast_strlen_zero(pri->mbox[i].vm_number)) {
diff --git a/channels/sig_pri.h b/channels/sig_pri.h
index 8c9babd..497e834 100644
--- a/channels/sig_pri.h
+++ b/channels/sig_pri.h
@@ -424,7 +424,7 @@
 	 * \brief MWI mailbox event subscription.
 	 * \note NULL if mailbox not configured.
 	 */
-	struct stasis_subscription *sub;
+	struct ast_mwi_subscriber *sub;
 	/*! \brief Mailbox uniqueid. */
 	const char *uniqueid;
 	/*! \brief Mailbox number sent to span. */
diff --git a/channels/sip/include/sip.h b/channels/sip/include/sip.h
index 86f8967..4ee2041 100644
--- a/channels/sip/include/sip.h
+++ b/channels/sip/include/sip.h
@@ -1252,7 +1252,7 @@
  */
 struct sip_mailbox {
 	/*! Associated MWI subscription */
-	struct stasis_subscription *event_sub;
+	struct ast_mwi_subscriber *event_sub;
 	AST_LIST_ENTRY(sip_mailbox) entry;
 	struct sip_peer *peer;
 	enum sip_mailbox_status status;
diff --git a/res/res_pjsip_mwi.c b/res/res_pjsip_mwi.c
index abd7ac0..2ea5f89 100644
--- a/res/res_pjsip_mwi.c
+++ b/res/res_pjsip_mwi.c
@@ -90,7 +90,7 @@
  */
 struct mwi_stasis_subscription {
 	/*! The MWI stasis subscription */
-	struct stasis_subscription *stasis_sub;
+	struct ast_mwi_subscriber *mwi_subscriber;
 	/*! The mailbox corresponding with the MWI subscription. Used as a hash key */
 	char mailbox[1];
 };
@@ -243,7 +243,6 @@
 static struct mwi_stasis_subscription *mwi_stasis_subscription_alloc(const char *mailbox, struct mwi_subscription *mwi_sub)
 {
 	struct mwi_stasis_subscription *mwi_stasis_sub;
-	struct stasis_topic *topic;
 
 	if (!mwi_sub) {
 		return NULL;
@@ -254,26 +253,22 @@
 		return NULL;
 	}
 
-	topic = ast_mwi_topic(mailbox);
-
 	/* Safe strcpy */
 	strcpy(mwi_stasis_sub->mailbox, mailbox);
 
-	ast_debug(3, "Creating stasis MWI subscription to mailbox %s for endpoint %s.  Topic: '%s':%p %d\n",
-		mailbox, mwi_sub->id, stasis_topic_name(topic), topic, (int)ao2_ref(topic, 0));
 	ao2_ref(mwi_sub, +1);
-	mwi_stasis_sub->stasis_sub = stasis_subscribe_pool(topic, mwi_stasis_cb, mwi_sub);
-	ao2_ref(topic, -1);
-
-	if (!mwi_stasis_sub->stasis_sub) {
+	mwi_stasis_sub->mwi_subscriber = ast_mwi_subscribe_pool(mailbox, mwi_stasis_cb, mwi_sub);
+	if (!mwi_stasis_sub->mwi_subscriber) {
 		/* Failed to subscribe. */
 		ao2_ref(mwi_stasis_sub, -1);
 		ao2_ref(mwi_sub, -1);
-		mwi_stasis_sub = NULL;
+		return NULL;
 	}
-	stasis_subscription_accept_message_type(mwi_stasis_sub->stasis_sub, ast_mwi_state_type());
-	stasis_subscription_accept_message_type(mwi_stasis_sub->stasis_sub, stasis_subscription_change_type());
-	stasis_subscription_set_filter(mwi_stasis_sub->stasis_sub, STASIS_SUBSCRIPTION_FILTER_SELECTIVE);
+
+	stasis_subscription_accept_message_type(
+		ast_mwi_subscriber_subscription(mwi_stasis_sub->mwi_subscriber),
+		stasis_subscription_change_type());
+
 	return mwi_stasis_sub;
 }
 
@@ -433,21 +428,19 @@
 
 static int get_message_count(void *obj, void *arg, int flags)
 {
-	struct stasis_message *msg;
 	struct mwi_stasis_subscription *mwi_stasis = obj;
 	struct ast_sip_message_accumulator *counter = arg;
 	struct ast_mwi_state *mwi_state;
 
-	msg = stasis_cache_get(ast_mwi_state_cache(), ast_mwi_state_type(), mwi_stasis->mailbox);
-	if (!msg) {
+	mwi_state = ast_mwi_subscriber_data(mwi_stasis->mwi_subscriber);
+	if (!mwi_state) {
 		return 0;
 	}
 
-	mwi_state = stasis_message_data(msg);
 	counter->old_msgs += mwi_state->old_msgs;
 	counter->new_msgs += mwi_state->new_msgs;
 
-	ao2_ref(msg, -1);
+	ao2_ref(mwi_state, -1);
 
 	return 0;
 }
@@ -683,10 +676,11 @@
 static int unsubscribe_stasis(void *obj, void *arg, int flags)
 {
 	struct mwi_stasis_subscription *mwi_stasis = obj;
-	if (mwi_stasis->stasis_sub) {
+	if (mwi_stasis->mwi_subscriber) {
 		ast_debug(3, "Removing stasis subscription to mailbox %s\n", mwi_stasis->mailbox);
-		mwi_stasis->stasis_sub = stasis_unsubscribe_and_join(mwi_stasis->stasis_sub);
+		mwi_stasis->mwi_subscriber = ast_mwi_unsubscribe_and_join(mwi_stasis->mwi_subscriber);
 	}
+
 	return CMP_MATCH;
 }
 

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/11464
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I32bef880b647246823dbccdf44a98d384fcabfbd
Gerrit-Change-Number: 11464
Gerrit-PatchSet: 6
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190712/3b91e8ab/attachment-0001.html>


More information about the asterisk-code-review mailing list