[asterisk-commits] mmichelson: branch mmichelson/pub_sub r385820 - /team/mmichelson/pub_sub/res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 15 16:28:47 CDT 2013


Author: mmichelson
Date: Mon Apr 15 16:28:43 2013
New Revision: 385820

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385820
Log:
Added some helpful debugging and comments.


Modified:
    team/mmichelson/pub_sub/res/res_sip_mwi.c

Modified: team/mmichelson/pub_sub/res/res_sip_mwi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pub_sub/res/res_sip_mwi.c?view=diff&rev=385820&r1=385819&r2=385820
==============================================================================
--- team/mmichelson/pub_sub/res/res_sip_mwi.c (original)
+++ team/mmichelson/pub_sub/res/res_sip_mwi.c Mon Apr 15 16:28:43 2013
@@ -68,8 +68,16 @@
 	.refresh_subscription = mwi_refresh_subscription,
 };
 
+/*!
+ * \brief Wrapper for stasis subscription
+ *
+ * An MWI subscription has a container of these. This
+ * represents a stasis subscription for MWI state.
+ */
 struct mwi_stasis_subscription {
+	/*! The MWI stasis subscription */
 	struct stasis_subscription *stasis_sub;
+	/*! The mailbox corresponding with the MWI subscription. Used as a hash key */
 	char mailbox[1];
 };
 
@@ -91,6 +99,7 @@
 	/* Safe strcpy */
 	strcpy(mwi_stasis_sub->mailbox, mailbox);
 	ao2_ref(mwi_sub, +1);
+	ast_debug(3, "Creating stasis MWI subscription to mailbox %s for endpoint %s\n", mailbox, mwi_sub->id);
 	mwi_stasis_sub->stasis_sub = stasis_subscribe(topic, mwi_stasis_cb, mwi_sub);
 	return mwi_stasis_sub;
 }
@@ -110,10 +119,32 @@
 	return strcmp(mwi_stasis1->mailbox, mwi_stasis2->mailbox) ? 0 : CMP_MATCH;
 }
 
+/*!
+ * \brief A subscription for MWI
+ *
+ * This subscription is the basis for MWI for an endpoint. Each
+ * endpoint that uses MWI will have a corresponding mwi_subscription.
+ *
+ * This structure acts as the owner for the underlying SIP subscription.
+ * When the mwi_subscription is destroyed, the SIP subscription dies, too.
+ * The mwi_subscription's lifetime is governed by its underlying stasis
+ * subscriptions. When all stasis subscriptions are destroyed, the
+ * mwi_subscription is destroyed as well.
+ */
 struct mwi_subscription {
+	/*! Container of \ref mwi_stasis_subscription structures.
+	 * A single MWI subscription may be fore multiple mailboxes, thus
+	 * requiring multiple stasis subscriptions
+	 */
 	struct ao2_container *stasis_subs;
+	/*! The SIP subscription. Unsolicited MWI does not use this */
 	struct ast_sip_subscription *sip_sub;
+	/*! Is the MWI solicited (i.e. Initiated with an external SUBSCRIBE) ? */
 	unsigned int is_solicited;
+	/*! Identifier for the subscription.
+	 * The identifier is the same as the corresponding endpoint's stasis ID.
+	 * Used as a hash key
+	 */
 	char id[1];
 };
 
@@ -152,6 +183,7 @@
 		sub->sip_sub = ast_sip_create_subscription(&mwi_handler,
 				role, endpoint, rdata);
 		if (!sub->sip_sub) {
+			ast_log(LOG_WARNING, "Unable to create MWI SIP subscription for endpoint %s\n", sub->id);
 			ao2_cleanup(sub);
 			return NULL;
 		}
@@ -163,6 +195,8 @@
 		return NULL;
 	}
 	sub->is_solicited = is_solicited;
+
+	ast_debug(3, "Created %s MWI subscription for endpoint %s\n", is_solicited ? "solicited" : "unsolicited", sub->id);
 
 	return sub;
 }
@@ -216,6 +250,7 @@
 	pjsip_event_hdr *event;
 	pjsip_tx_data *tdata;
 	const pjsip_hdr *allow_events = pjsip_evsub_get_allow_events_hdr(NULL);
+
 	if (!endpoint) {
 		ast_log(LOG_WARNING, "Unable to send unsolicited MWI to %s because endpoint does not exist\n",
 				sub->id);
@@ -278,6 +313,10 @@
 	ast_str_append(&body, 0, "Voice-Message: %d/%d (0/0)\r\n", counter.new_msgs, counter.old_msgs);
 	pj_cstr(&pj_body, ast_str_buffer(body));
 
+	ast_debug(5, "Sending  %s MWI NOTIFY to endpoint %s, new messages: %d, old messages: %d\n",
+			sub->is_solicited ? "solicited" : "unsolicited", sub->id, counter.new_messages,
+			counter.old_messages);
+
 	if (sub->is_solicited) {
 		if (pjsip_mwi_notify(ast_sip_subscription_get_evsub(sub->sip_sub),
 				state,
@@ -286,11 +325,11 @@
 				&mwi_type,
 				&pj_body,
 				&tdata) != PJ_SUCCESS) {
-			ast_log(LOG_WARNING, "Unable to create MWI NOTIFY request.\n");
+			ast_log(LOG_WARNING, "Unable to create MWI NOTIFY request to %s.\n", sub->id);
 			return;
 		}
 		if (ast_sip_subscription_send_request(sub->sip_sub, tdata) != PJ_SUCCESS) {
-			ast_log(LOG_NOTICE, "Unable to send MWI NOTIFY request\n");
+			ast_log(LOG_WARNING, "Unable to send MWI NOTIFY request to %s\n", sub->id);
 			return;
 		}
 	} else {
@@ -302,7 +341,7 @@
 {
 	struct mwi_stasis_subscription *mwi_stasis = obj;
 	if (mwi_stasis->stasis_sub) {
-		ast_log(LOG_NOTICE, "Removing stasis subscription\n");
+		ast_debug(3, "Removing stasis subscription to mailbox %s\n", mwi_stasis->mailbox);
 		mwi_stasis->stasis_sub = stasis_unsubscribe(mwi_stasis->stasis_sub);
 	}
 	return CMP_MATCH;
@@ -359,12 +398,12 @@
 
 	aor = ast_sip_location_retrieve_aor(aor_name);
 	if (!aor) {
-		ast_log(LOG_WARNING, "Unable to locate aor %s\n", aor_name);
+		ast_log(LOG_WARNING, "Unable to locate aor %s. MWI subscription failed.\n", aor_name);
 		return NULL;
 	}
 
 	if (ast_strlen_zero(aor->mailboxes)) {
-		ast_log(LOG_WARNING, "AOR %s has no configured mailboxes\n", aor_name);
+		ast_log(LOG_WARNING, "AOR %s has no configured mailboxes. MWI subscription failed\n", aor_name);
 		return NULL;
 	}
 
@@ -374,6 +413,7 @@
 	}
 
 	if (add_mwi_datastore(sub)) {
+		ast_log(LOG_WARNING, "Unable to allocate datastore on MWI subscription from %s\n", sub->id);
 		return NULL;
 	}
 
@@ -413,7 +453,10 @@
 		return;
 	}
 
+
 	mwi_sub = mwi_datastore->data;
+
+	ast_log(LOG_NOTICE, "MWI subscription for %s has timed out.\n", mwi_sub->id);
 
 	send_mwi_notify(mwi_sub, PJSIP_EVSUB_STATE_TERMINATED, "timeout");
 }
@@ -430,6 +473,8 @@
 
 	mwi_sub = mwi_datastore->data;
 
+	ast_log(LOG_NOTICE, "MWI subscription for %s has been terminated\n", mwi_sub->id);
+
 	send_mwi_notify(mwi_sub, PJSIP_EVSUB_STATE_TERMINATED, NULL);
 }
 
@@ -466,6 +511,7 @@
 	struct mwi_subscription *mwi_sub = userdata;
 
 	if (stasis_subscription_final_message(sub, msg)) {
+		ast_debug(3, "Stasis subscription for mailbox %s has ended. Removing MWI subscription\n", sub->mailbox);
 		ao2_cleanup(mwi_sub);
 		return;
 	}
@@ -537,6 +583,12 @@
 		return;
 	}
 
+	/* We remove all the old stasis subscriptions first before applying the new configuration. This
+	 * prevents a situation where there might be multiple overlapping stasis subscriptions for an
+	 * endpoint for mailboxes. Though there may be mailbox changes during the gap between unsubscribing
+	 * and resubscribing, up-to-date mailbox state will be sent out to the endpoint when the
+	 * new stasis subscription is established
+	 */
 	if (old_mwi_subscriptions) {
 		ao2_callback(old_mwi_subscriptions, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, unsubscribe, NULL);
 	}




More information about the asterisk-commits mailing list