[asterisk-commits] mmichelson: branch mmichelson/subscription_abstraction r416435 - in /team/mmi...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 16 16:17:00 CDT 2014


Author: mmichelson
Date: Mon Jun 16 16:16:53 2014
New Revision: 416435

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=416435
Log:
Necessary changes for MWI tests to pass.

* Make sure the exports file has new API calls added.
* Change the real and virtual subscriptions not to be pointers.
* Be sure to return early if returning a failure response to a subscription.
* Validate MWI resource integrity before responding to SUBSCRIBE.


Modified:
    team/mmichelson/subscription_abstraction/include/asterisk/res_pjsip_pubsub.h
    team/mmichelson/subscription_abstraction/res/res_pjsip_mwi.c
    team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c
    team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.exports.in

Modified: team/mmichelson/subscription_abstraction/include/asterisk/res_pjsip_pubsub.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/subscription_abstraction/include/asterisk/res_pjsip_pubsub.h?view=diff&rev=416435&r1=416434&r2=416435
==============================================================================
--- team/mmichelson/subscription_abstraction/include/asterisk/res_pjsip_pubsub.h (original)
+++ team/mmichelson/subscription_abstraction/include/asterisk/res_pjsip_pubsub.h Mon Jun 16 16:16:53 2014
@@ -243,8 +243,6 @@
 };
 
 struct ast_sip_subscriber {
-	/*! The types of body this subscriber accepts. */
-	const char *accept[AST_SIP_MAX_ACCEPT];
 	/*!
 	 * \brief A NOTIFY has been received.
 	 *
@@ -264,6 +262,8 @@
 struct ast_sip_subscription_handler {
 	/*! The name of the event this subscriber deals with */
 	const char *event_name;
+	/*! The types of body this subscriber accepts. */
+	const char *accept[AST_SIP_MAX_ACCEPT];
 	/*!
 	 * \brief Called when a subscription is to be destroyed
 	 *

Modified: team/mmichelson/subscription_abstraction/res/res_pjsip_mwi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/subscription_abstraction/res/res_pjsip_mwi.c?view=diff&rev=416435&r1=416434&r2=416435
==============================================================================
--- team/mmichelson/subscription_abstraction/res/res_pjsip_mwi.c (original)
+++ team/mmichelson/subscription_abstraction/res/res_pjsip_mwi.c Mon Jun 16 16:16:53 2014
@@ -63,6 +63,7 @@
 
 static struct ast_sip_subscription_handler mwi_handler = {
 	.event_name = "message-summary",
+	.accept = { MWI_TYPE"/"MWI_SUBTYPE, },
 	.subscription_shutdown = mwi_subscription_shutdown,
 	.to_ami = mwi_to_ami,
 	.notifier = &mwi_notifier,
@@ -610,54 +611,68 @@
 	struct mwi_subscription *sub;
 
 	if (!aor) {
+		/*! I suppose it's possible for the AOR to disappear on us
+		 * between accepting the subscription and sending the first
+		 * NOTIFY...
+		 */
 		ast_log(LOG_WARNING, "Unable to locate aor %s. MWI "
 			"subscription failed.\n", name);
 		return NULL;
 	}
 
+	if (!(sub = mwi_create_subscription(endpoint, sip_sub))) {
+		return NULL;
+	}
+
+	mwi_on_aor(aor, sub, 0);
+	return sub;
+}
+
+static struct mwi_subscription *mwi_subscribe_all(
+	struct ast_sip_endpoint *endpoint, struct ast_sip_subscription *sip_sub)
+{
+	struct mwi_subscription *sub;
+
+	sub = mwi_create_subscription(endpoint, sip_sub);
+
+	if (!sub) {
+		return NULL;
+	}
+
+	ast_sip_for_each_aor(endpoint->aors, mwi_on_aor, sub);
+	return sub;
+}
+
+static int mwi_new_subscribe(struct ast_sip_endpoint *endpoint,
+		const char *resource)
+{
+	struct ast_sip_aor *aor;
+
+	if (ast_strlen_zero(resource)) {
+		if (ast_sip_for_each_aor(endpoint->aors, mwi_validate_for_aor, endpoint)) {
+			return 500;
+		}
+		return 200;
+	}
+
+	aor = ast_sip_location_retrieve_aor(resource);
+	
+	if (!aor) {
+		ast_log(LOG_WARNING, "Unable to locate aor %s. MWI "
+			"subscription failed.\n", resource);
+		return 404;
+	}
+
 	if (ast_strlen_zero(aor->mailboxes)) {
 		ast_log(LOG_WARNING, "AOR %s has no configured mailboxes. "
-			"MWI subscription failed\n", name);
-		return NULL;
+			"MWI subscription failed\n", resource);
+		return 404;
 	}
 
 	if (mwi_validate_for_aor(aor, endpoint, 0)) {
-		return NULL;
-	}
-
-	if (!(sub = mwi_create_subscription(endpoint, sip_sub))) {
-		return NULL;
-	}
-
-	mwi_on_aor(aor, sub, 0);
-	return sub;
-}
-
-static struct mwi_subscription *mwi_subscribe_all(
-	struct ast_sip_endpoint *endpoint, struct ast_sip_subscription *sip_sub)
-{
-	struct mwi_subscription *sub;
-
-	if (ast_sip_for_each_aor(endpoint->aors, mwi_validate_for_aor, endpoint)) {
-		return NULL;
-	}
-
-	sub = mwi_create_subscription(endpoint, sip_sub);
-
-	if (!sub) {
-		return NULL;
-	}
-
-	ast_sip_for_each_aor(endpoint->aors, mwi_on_aor, sub);
-	return sub;
-}
-
-static int mwi_new_subscribe(struct ast_sip_endpoint *endpoint,
-		const char *resource)
-{
-	/* The MWI notifier does not care what resource is being subscribed to. We'll happily
-	 * accept whatever resource is thrown our way.
-	 */
+		return 500;
+	}
+
 	return 200;
 }
 

Modified: team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c?view=diff&rev=416435&r1=416434&r2=416435
==============================================================================
--- team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c (original)
+++ team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.c Mon Jun 16 16:16:53 2014
@@ -296,8 +296,8 @@
 	enum sip_subscription_type type;
 	/*! Real and virtual components of the subscription */
 	union {
-		struct ast_sip_real_subscription *real;
-		struct ast_sip_virtual_subscription *virtual;
+		struct ast_sip_real_subscription real;
+		struct ast_sip_virtual_subscription virtual;
 	} pants;
 	/*! Body generaator for NOTIFYs */
 	struct ast_sip_pubsub_body_generator *body_generator;
@@ -323,12 +323,12 @@
 
 static pjsip_evsub *sip_subscription_get_evsub(struct ast_sip_subscription *sub)
 {
-	return sub->pants.real->evsub;
+	return sub->pants.real.evsub;
 }
 
 static pjsip_dialog *sip_subscription_get_dlg(struct ast_sip_subscription *sub)
 {
-	return sub->pants.real->dlg;
+	return sub->pants.real.dlg;
 }
 
 /*! \brief Destructor for subscription persistence */
@@ -771,6 +771,7 @@
 	struct subscription_persistence *persistence;
 	size_t resource_size;
 	pjsip_sip_uri *request_uri;
+	struct pjsip_evsub *evsub;
 
 	request_uri = pjsip_uri_get_uri(rdata->msg_info.msg->line.req.uri);
 	resource_size = pj_strlen(&request_uri->user) + 1;
@@ -813,12 +814,13 @@
 		dlg->remote.cseq = persistence->cseq;
 	}
 
-	pjsip_evsub_create_uas(dlg, &pubsub_cb, rdata, 0, &sub->pants.real->evsub);
+	pjsip_evsub_create_uas(dlg, &pubsub_cb, rdata, 0, &evsub);
+	sub->pants.real.evsub = evsub;
 	/* We keep a reference to the dialog until our subscription is destroyed. See
 	 * the subscription_destructor for more details
 	 */
 	pjsip_dlg_inc_session(dlg, &pubsub_module);
-	sub->pants.real->dlg = dlg;
+	sub->pants.real.dlg = dlg;
 	ast_sip_dialog_set_serializer(dlg, sub->serializer);
 	pjsip_evsub_set_mod_data(sip_subscription_get_evsub(sub), pubsub_module.id, sub);
 	sub->endpoint = ao2_bump(endpoint);
@@ -869,12 +871,12 @@
 	}
 
 	pj_cstr(&event, handler->event_name);
-	pjsip_evsub_create_uac(dlg, &pubsub_cb, &event, 0, &sub->pants.real->evsub);
+	pjsip_evsub_create_uac(dlg, &pubsub_cb, &event, 0, &sub->pants.real.evsub);
 	/* We keep a reference to the dialog until our subscription is destroyed. See
 	 * the subscription_destructor for more details
 	 */
 	pjsip_dlg_inc_session(dlg, &pubsub_module);
-	sub->pants.real->dlg = dlg;
+	sub->pants.real.dlg = dlg;
 	ast_sip_dialog_set_serializer(dlg, sub->serializer);
 	pjsip_evsub_set_mod_data(sip_subscription_get_evsub(sub), pubsub_module.id, sub);
 	ao2_ref(endpoint, +1);
@@ -931,6 +933,7 @@
 	struct ast_str *body_text = ast_str_create(64);
 	pjsip_evsub *evsub = sip_subscription_get_evsub(sub);
 	pjsip_tx_data *tdata;
+	pjsip_evsub_state state = pjsip_evsub_get_state(evsub);
 
 	if (!body_text) {
 		return -1;
@@ -943,7 +946,11 @@
 
 	body.body_text = ast_str_buffer(body_text);
 
-	if (pjsip_evsub_notify(evsub, pjsip_evsub_get_state(evsub), NULL, NULL, &tdata) != PJ_SUCCESS) {
+	state = state <= PJSIP_EVSUB_STATE_ACTIVE ? PJSIP_EVSUB_STATE_ACTIVE : PJSIP_EVSUB_STATE_TERMINATED;
+
+	ast_log_backtrace();
+
+	if (pjsip_evsub_notify(evsub, state, NULL, NULL, &tdata) != PJ_SUCCESS) {
 		ast_free(body_text);
 		return -1;
 	}
@@ -1184,10 +1191,8 @@
 		return -1;
 	}
 
-	if (handler->subscriber) {
-		for (i = 0; i < AST_SIP_MAX_ACCEPT && !ast_strlen_zero(handler->subscriber->accept[i]); ++i) {
-			pj_cstr(&accept[i], handler->subscriber->accept[i]);
-		}
+	for (i = 0; i < AST_SIP_MAX_ACCEPT && !ast_strlen_zero(handler->accept[i]); ++i) {
+		pj_cstr(&accept[i], handler->accept[i]);
 	}
 
 	pj_cstr(&event, handler->event_name);
@@ -1322,6 +1327,7 @@
 	resp = handler->notifier->new_subscribe(endpoint, resource);
 	if (resp < 200 || resp >= 300) {
 		pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, resp, NULL, NULL, NULL);
+		return PJ_TRUE;
 	}
 	sub = notifier_create_subscription(handler, endpoint, rdata);
 	if (!sub) {

Modified: team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.exports.in?view=diff&rev=416435&r1=416434&r2=416435
==============================================================================
--- team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.exports.in (original)
+++ team/mmichelson/subscription_abstraction/res/res_pjsip_pubsub.exports.in Mon Jun 16 16:16:53 2014
@@ -1,7 +1,7 @@
 {
 	global:
 		LINKER_SYMBOL_PREFIXast_sip_create_subscription;
-		LINKER_SYMBOL_PREFIXast_sip_subsription_get_endpoint;
+		LINKER_SYMBOL_PREFIXast_sip_subscription_get_endpoint;
 		LINKER_SYMBOL_PREFIXast_sip_subscription_get_serializer;
 		LINKER_SYMBOL_PREFIXast_sip_subscription_get_evsub;
 		LINKER_SYMBOL_PREFIXast_sip_subscription_get_dlg;
@@ -30,6 +30,10 @@
 		LINKER_SYMBOL_PREFIXast_sip_pubsub_generate_body_content;
 		LINKER_SYMBOL_PREFIXast_sip_subscription_get_body_type;
 		LINKER_SYMBOL_PREFIXast_sip_subscription_get_body_subtype;
+		LINKER_SYMBOL_PREFIXast_sip_subscription_get_resource_name;
+		LINKER_SYMBOL_PREFIXast_sip_subscription_notify;
+		LINKER_SYMBOL_PREFIXast_sip_subscription_get_local_uri;
+		LINKER_SYMBOL_PREFIXast_sip_subscription_get_remote_uri;
 	local:
 		*;
 };




More information about the asterisk-commits mailing list