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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 10 12:54:33 CDT 2013


Author: mmichelson
Date: Wed Apr 10 12:54:30 2013
New Revision: 385257

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385257
Log:
Regroup some functionality and fix compilation errors.


Modified:
    team/mmichelson/pub_sub/res/res_sip_mwi.c
    team/mmichelson/pub_sub/res/res_sip_pubsub.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=385257&r1=385256&r2=385257
==============================================================================
--- team/mmichelson/pub_sub/res/res_sip_mwi.c (original)
+++ team/mmichelson/pub_sub/res/res_sip_mwi.c Wed Apr 10 12:54:30 2013
@@ -39,9 +39,34 @@
  ***/
 
 struct ao2_container *mwi_subscriptions;
+struct mwi_subscription;
 
 #define STASIS_BUCKETS 13
 #define MWI_BUCKETS 53
+static void mwi_subscription_shutdown(struct ast_sip_subscription *sub);
+static struct ast_sip_subscription *mwi_new_subscribe(struct ast_sip_endpoint *endpoint,
+		pjsip_rx_data *rdata);
+static struct ast_sip_subscription_response_data *mwi_resubscribe(struct ast_sip_subscription *sub,
+		pjsip_rx_data *rdata);
+static void mwi_subscription_timeout(struct ast_sip_subscription *sub);
+static void mwi_subscription_terminated(struct ast_sip_subscription *sub, pjsip_rx_data *rdata);
+static void mwi_notify_response(struct ast_sip_subscription *sub, pjsip_rx_data *rdata);
+static struct ast_sip_subscription_response_data *mwi_notify_request(struct ast_sip_subscription *sub,
+		pjsip_rx_data *rdata);
+static int mwi_refresh_subscription(struct ast_sip_subscription *sub);
+
+static struct ast_sip_subscription_handler mwi_handler = {
+	.event_name = "message-summary",
+	.accept = { "application/simple-message-summary", },
+	.subscription_shutdown = mwi_subscription_shutdown,
+	.new_subscribe = mwi_new_subscribe,
+	.resubscribe = mwi_resubscribe,
+	.subscription_timeout = mwi_subscription_timeout,
+	.subscription_terminated = mwi_subscription_terminated,
+	.notify_response = mwi_notify_response,
+	.notify_request = mwi_notify_request,
+	.refresh_subscription = mwi_refresh_subscription,
+};
 
 struct mwi_stasis_subscription {
 	struct stasis_subscription *stasis_sub;
@@ -57,6 +82,28 @@
 	}
 }
 
+static void mwi_stasis_cb(void *userdata, struct stasis_subscription *sub,
+		struct stasis_topic *topic, struct stasis_message *msg);
+
+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;
+	
+	mwi_stasis_sub = ao2_alloc(sizeof(*mwi_stasis_sub) + strlen(mailbox),
+			mwi_stasis_subscription_destructor);
+	if (!mwi_stasis_sub) {
+		return NULL;
+	}
+
+	topic = stasis_mwi_topic(mailbox);
+
+	/* Safe strcpy */
+	strcpy(mwi_stasis_sub->mailbox, mailbox);
+	mwi_stasis_sub->stasis_sub = stasis_subscribe(topic, mwi_stasis_cb, mwi_sub);
+	return mwi_stasis_sub;
+}
+
 static int stasis_sub_hash(const void *obj, int flags)
 {
 	const struct mwi_stasis_subscription *mwi_stasis = obj;
@@ -75,6 +122,7 @@
 struct mwi_subscription {
 	struct ao2_container *stasis_subs;
 	struct ast_sip_subscription *sip_sub;
+	unsigned int is_solicited;
 	char id[1];
 };
 
@@ -83,6 +131,41 @@
 	struct mwi_subscription *sub = obj;
 	ao2_cleanup(sub->sip_sub);
 	ao2_cleanup(sub->stasis_subs);
+}
+
+static struct mwi_subscription *mwi_subscription_alloc(struct ast_sip_endpoint *endpoint, unsigned int is_solicited)
+{
+	struct mwi_subscription *sub;
+	const char *endpoint_id = ast_sorcery_object_get_id(endpoint);
+
+	sub = ao2_alloc(sizeof(*sub) + strlen(endpoint_id),
+			mwi_subscription_destructor);
+
+	if (!sub) {
+		return NULL;
+	}
+
+	/* Safe strcpy */
+	strcpy(sub->id, endpoint_id);
+	/* MWI is an interesting case because the NOTIFYs we send are
+	 * unsolicited. We get around the requirement of needing an
+	 * incoming SUBSCRIBE by pretending that we are the subscriber
+	 */
+	sub->sip_sub = ast_sip_create_subscription(&mwi_handler,
+			AST_SIP_SUBSCRIBER, endpoint, NULL);
+	if (!sub->sip_sub) {
+		ao2_cleanup(sub);
+		return NULL;
+	}
+
+	sub->stasis_subs = ao2_container_alloc(STASIS_BUCKETS, stasis_sub_hash, stasis_sub_cmp);
+	if (!sub->stasis_subs) {
+		ao2_cleanup(sub);
+		return NULL;
+	}
+	sub->is_solicited = is_solicited;
+
+	return sub;
 }
 
 static int mwi_sub_hash(const void *obj, int flags)
@@ -163,7 +246,7 @@
 static struct ast_sip_subscription *mwi_new_subscribe(struct ast_sip_endpoint *endpoint,
 		pjsip_rx_data *rdata)
 {
-	/* XXX STUB */
+	/*XXX STUB*/
 	return NULL;
 }
 
@@ -192,28 +275,15 @@
 static struct ast_sip_subscription_response_data *mwi_notify_request(struct ast_sip_subscription *sub,
 		pjsip_rx_data *rdata)
 {
-	/* XXX STUB */
+	ast_log(LOG_WARNING, "Received an MWI NOTIFY request? This should not happen\n");
 	return NULL;
 }
 
 static int mwi_refresh_subscription(struct ast_sip_subscription *sub)
 {
-	/* XXX STUB */
+	ast_log(LOG_WARNING, "Being told to refresh an MWI subscription? This should not happen\n");
 	return 0;
 }
-
-static struct ast_sip_subscription_handler mwi_handler = {
-	.event_name = "message-summary",
-	.accept = { "application/simple-message-summary", },
-	.subscription_shutdown = mwi_subscription_shutdown,
-	.new_subscribe = mwi_new_subscribe,
-	.resubscribe = mwi_resubscribe,
-	.subscription_timeout = mwi_subscription_timeout,
-	.subscription_terminated = mwi_subscription_terminated,
-	.notify_response = mwi_notify_response,
-	.notify_request = mwi_notify_request,
-	.refresh_subscription = mwi_refresh_subscription,
-};
 
 static void mwi_stasis_cb(void *userdata, struct stasis_subscription *sub,
 		struct stasis_topic *topic, struct stasis_message *msg)
@@ -228,40 +298,6 @@
 	}
 }
 
-static struct mwi_subscription *mwi_subscription_alloc(struct ast_sip_endpoint *endpoint)
-{
-	struct mwi_subscription *sub;
-	const char *endpoint_id = ast_sorcery_object_get_id(endpoint);
-
-	sub = ao2_alloc(sizeof(*sub) + strlen(endpoint_id),
-			mwi_subscription_destructor);
-
-	if (!sub) {
-		return NULL;
-	}
-
-	/* Safe strcpy */
-	strcpy(sub->id, endpoint_id);
-	/* MWI is an interesting case because the NOTIFYs we send are
-	 * unsolicited. We get around the requirement of needing an
-	 * incoming SUBSCRIBE by pretending that we are the subscriber
-	 */
-	sub->sip_sub = ast_sip_create_subscription(&mwi_handler,
-			AST_SIP_SUBSCRIBER, endpoint, NULL);
-	if (!sub->sip_sub) {
-		ao2_cleanup(sub);
-		return NULL;
-	}
-
-	sub->stasis_subs = ao2_container_alloc(STASIS_BUCKETS, stasis_sub_hash, stasis_sub_cmp);
-	if (!sub->stasis_subs) {
-		ao2_cleanup(sub);
-		return NULL;
-	}
-
-	return sub;
-}
-
 static int create_mwi_subscriptions_for_endpoint(void *obj, void *arg, int flags)
 {
 	RAII_VAR(struct mwi_subscription *, sub, NULL, ao2_cleanup);
@@ -273,7 +309,7 @@
 		return 0;
 	}
 
-	sub = mwi_subscription_alloc(endpoint);
+	sub = mwi_subscription_alloc(endpoint, 0);
 	if (!sub) {
 		return 0;
 	}
@@ -281,16 +317,10 @@
 	mailboxes = ast_strdupa(endpoint->mailboxes);
 	while ((mailbox = strsep(&mailboxes, ","))) {
 		RAII_VAR(struct mwi_stasis_subscription *, mwi_stasis_sub,
-				ao2_alloc(sizeof(*mwi_stasis_sub) + strlen(mailbox),
-					mwi_stasis_subscription_destructor), ao2_cleanup);
-		struct stasis_topic *topic;
-
-		topic = stasis_mwi_topic(mailbox);
-
-		/* Safe strcpy */
-		strcpy(mwi_stasis_sub->mailbox, mailbox);
-		mwi_stasis_sub->stasis_sub = stasis_subscribe(topic, mwi_stasis_cb, sub);
-		ao2_link(sub->stasis_subs, mwi_stasis_sub);
+				mwi_stasis_subscription_alloc(mailbox, sub), ao2_cleanup);
+		if (mwi_stasis_sub) {
+			ao2_link(sub->stasis_subs, mwi_stasis_sub);
+		}
 	}
 	ao2_link(mwi_subscriptions, sub);
 	return 0;

Modified: team/mmichelson/pub_sub/res/res_sip_pubsub.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pub_sub/res/res_sip_pubsub.c?view=diff&rev=385257&r1=385256&r2=385257
==============================================================================
--- team/mmichelson/pub_sub/res/res_sip_pubsub.c (original)
+++ team/mmichelson/pub_sub/res/res_sip_pubsub.c Wed Apr 10 12:54:30 2013
@@ -266,6 +266,13 @@
 
 AST_RWLIST_HEAD_STATIC(subscription_handlers, ast_sip_subscription_handler);
 
+static void add_handler(struct ast_sip_subscription_handler *handler)
+{
+	SCOPED_LOCK(lock, &subscription_handlers, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
+	AST_RWLIST_INSERT_TAIL(&subscription_handlers, handler, next);
+	ast_module_ref(ast_module_info->self);
+}
+
 int ast_sip_register_subscription_handler(struct ast_sip_subscription_handler *handler)
 {
 	/* TODO Ensure duplicate events can't get registered */
@@ -288,14 +295,15 @@
 		pj_cstr(&accept[i], handler->accept[i]);
 	}
 
-	pjsip_evsub_register_pkg(&sub_module, &event, DEFAULT_EXPIRES, i, accept);
-
-	{
-		SCOPED_LOCK(lock, &subscription_handlers, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
-		AST_RWLIST_INSERT_TAIL(&subscription_handlers, handler, next);
-	}
-
-	ast_module_ref(ast_module_info->self);
+	if (!strcmp(handler->event_name, "message-summary")) {
+		pjsip_mwi_init_module(ast_sip_get_pjsip_endpoint(), pjsip_evsub_instance());
+	} else if (!strcmp(handler->event_name, "presence")) {
+		pjsip_pres_init_module(ast_sip_get_pjsip_endpoint(), pjsip_evsub_instance());
+	} else {
+		pjsip_evsub_register_pkg(&sub_module, &event, DEFAULT_EXPIRES, i, accept);
+	}
+
+	add_handler(handler);
 	return 0;
 }
  




More information about the asterisk-commits mailing list