[asterisk-commits] kmoore: branch kmoore/stasis-mwi r382149 - in /team/kmoore/stasis-mwi: apps/ ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Feb 26 15:02:47 CST 2013


Author: kmoore
Date: Tue Feb 26 15:02:43 2013
New Revision: 382149

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382149
Log:
Initial pass of MWI event conversion to Stasis

This covers generation of Stasis messages and converts consumption of
event cache to consumption of Stasis cache.  AST_EVENT_MWI events are
still created and pushed.  Subscriptions have not yet been converted
and need a slightly more complicated individual topic/aggregation setup
than I have here right now.  Pollmailboxes in voicemail needs to be
notified of changes in subscription which is not currently possible.

Modified:
    team/kmoore/stasis-mwi/apps/app_minivm.c
    team/kmoore/stasis-mwi/apps/app_voicemail.c
    team/kmoore/stasis-mwi/channels/chan_dahdi.c
    team/kmoore/stasis-mwi/channels/chan_iax2.c
    team/kmoore/stasis-mwi/channels/chan_mgcp.c
    team/kmoore/stasis-mwi/channels/chan_sip.c
    team/kmoore/stasis-mwi/channels/chan_unistim.c
    team/kmoore/stasis-mwi/channels/sig_pri.c
    team/kmoore/stasis-mwi/include/asterisk/app.h
    team/kmoore/stasis-mwi/main/app.c
    team/kmoore/stasis-mwi/main/asterisk.c
    team/kmoore/stasis-mwi/res/res_jabber.c
    team/kmoore/stasis-mwi/res/res_xmpp.c

Modified: team/kmoore/stasis-mwi/apps/app_minivm.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/apps/app_minivm.c?view=diff&rev=382149&r1=382148&r2=382149
==============================================================================
--- team/kmoore/stasis-mwi/apps/app_minivm.c (original)
+++ team/kmoore/stasis-mwi/apps/app_minivm.c Tue Feb 26 15:02:43 2013
@@ -2015,12 +2015,14 @@
 {
 	struct ast_event *event;
 	char *mailbox, *context;
+	struct ast_str *uniqueid = ast_str_alloca(128);
 
 	mailbox = ast_strdupa(mbx);
 	context = ast_strdupa(ctx);
 	if (ast_strlen_zero(context)) {
 		context = "default";
 	}
+	ast_str_set(&uniqueid, 0, "%s@%s", mbx, ctx);
 
 	if (!(event = ast_event_new(AST_EVENT_MWI,
 			AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
@@ -2032,6 +2034,7 @@
 	}
 
 	ast_event_queue_and_cache(event);
+	stasis_publish_mwi_state(ast_str_buffer(uniqueid), mailbox, context, new + urgent, old);
 }
 
 /*!\internal

Modified: team/kmoore/stasis-mwi/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/apps/app_voicemail.c?view=diff&rev=382149&r1=382148&r2=382149
==============================================================================
--- team/kmoore/stasis-mwi/apps/app_voicemail.c (original)
+++ team/kmoore/stasis-mwi/apps/app_voicemail.c Tue Feb 26 15:02:43 2013
@@ -7740,6 +7740,7 @@
 	}
 
 	ast_event_queue_and_cache(event);
+	stasis_publish_mwi_state(box, mailbox, context, new + urgent, old);
 }
 
 /*!

Modified: team/kmoore/stasis-mwi/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/channels/chan_dahdi.c?view=diff&rev=382149&r1=382148&r2=382149
==============================================================================
--- team/kmoore/stasis-mwi/channels/chan_dahdi.c (original)
+++ team/kmoore/stasis-mwi/channels/chan_dahdi.c Tue Feb 26 15:02:43 2013
@@ -3772,6 +3772,7 @@
 	}
 
 	ast_event_queue_and_cache(event);
+	stasis_publish_mwi_state(mailbox_full, mailbox, context, thereornot, thereornot);
 
 	if (!ast_strlen_zero(mailbox) && !ast_strlen_zero(mwimonitornotify)) {
 		snprintf(s, sizeof(s), "%s %s %d", mwimonitornotify, mailbox, thereornot);
@@ -5413,24 +5414,25 @@
 static int has_voicemail(struct dahdi_pvt *p)
 {
 	int new_msgs;
-	struct ast_event *event;
 	char *mailbox, *context;
+	struct stasis_message *mwi_message;
+	struct ast_str *uniqueid = ast_str_alloca(128);
 
 	mailbox = context = ast_strdupa(p->mailbox);
 	strsep(&context, "@");
-	if (ast_strlen_zero(context))
+	if (ast_strlen_zero(context)) {
 		context = "default";
-
-	event = ast_event_get_cached(AST_EVENT_MWI,
-		AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
-		AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
-		AST_EVENT_IE_END);
-
-	if (event) {
-		new_msgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
-		ast_event_destroy(event);
-	} else
+	}
+
+	ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
+	mwi_message = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_message_type(), ast_str_buffer(uniqueid));
+
+	if (mwi_message) {
+		struct stasis_mwi_state *mwi_state = stasis_message_data(mwi_message);
+		new_msgs = mwi_state->new_msgs;
+	} else {
 		new_msgs = ast_app_has_voicemail(p->mailbox, NULL);
+	}
 
 	return new_msgs;
 }

Modified: team/kmoore/stasis-mwi/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/channels/chan_iax2.c?view=diff&rev=382149&r1=382148&r2=382149
==============================================================================
--- team/kmoore/stasis-mwi/channels/chan_iax2.c (original)
+++ team/kmoore/stasis-mwi/channels/chan_iax2.c Tue Feb 26 15:02:43 2013
@@ -8743,23 +8743,24 @@
 		iax_ie_append_short(&ied, IAX_IE_REFRESH, p->expiry);
 		iax_ie_append_addr(&ied, IAX_IE_APPARENT_ADDR, &peer_addr);
 		if (!ast_strlen_zero(p->mailbox)) {
-			struct ast_event *event;
 			int new, old;
 			char *mailbox, *context;
+			struct stasis_message *msg;
+			struct ast_str *uniqueid = ast_str_alloca(128);
 
 			context = mailbox = ast_strdupa(p->mailbox);
 			strsep(&context, "@");
-			if (ast_strlen_zero(context))
+			if (ast_strlen_zero(context)) {
 				context = "default";
-
-			event = ast_event_get_cached(AST_EVENT_MWI,
-				AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
-				AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
-				AST_EVENT_IE_END);
-			if (event) {
-				new = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
-				old = ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS);
-				ast_event_destroy(event);
+			}
+
+			ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
+			msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_message_type(), ast_str_buffer(uniqueid));
+
+			if (msg) {
+				struct stasis_mwi_state *mwi_state = stasis_message_data(msg);
+				new = mwi_state->new_msgs;
+				old = mwi_state->old_msgs;
 			} else { /* Fall back on checking the mailbox directly */
 				ast_app_inboxcount(p->mailbox, &new, &old);
 			}

Modified: team/kmoore/stasis-mwi/channels/chan_mgcp.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/channels/chan_mgcp.c?view=diff&rev=382149&r1=382148&r2=382149
==============================================================================
--- team/kmoore/stasis-mwi/channels/chan_mgcp.c (original)
+++ team/kmoore/stasis-mwi/channels/chan_mgcp.c Tue Feb 26 15:02:43 2013
@@ -494,24 +494,26 @@
 static int has_voicemail(struct mgcp_endpoint *p)
 {
 	int new_msgs;
-	struct ast_event *event;
+	struct stasis_message *msg;
+	struct ast_str *uniqueid = ast_str_alloca(128);
 	char *mbox, *cntx;
 
 	cntx = mbox = ast_strdupa(p->mailbox);
 	strsep(&cntx, "@");
-	if (ast_strlen_zero(cntx))
+	if (ast_strlen_zero(cntx)) {
 		cntx = "default";
-
-	event = ast_event_get_cached(AST_EVENT_MWI,
-		AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mbox,
-		AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, cntx,
-		AST_EVENT_IE_END);
+	}
+
+	ast_str_set(&uniqueid, 0, "%s@%s", mbox, cntx);
+
+	msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_message_type(), ast_str_buffer(uniqueid));
 
 	if (event) {
-		new_msgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
-		ast_event_destroy(event);
-	} else
+		struct stasis_mwi_state = stasis_message_data(msg);
+		new_msgs = mwi_state->new_msgs;
+	} else {
 		new_msgs = ast_app_has_voicemail(p->mailbox, NULL);
+	}
 
 	return new_msgs;
 }

Modified: team/kmoore/stasis-mwi/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/channels/chan_sip.c?view=diff&rev=382149&r1=382148&r2=382149
==============================================================================
--- team/kmoore/stasis-mwi/channels/chan_sip.c (original)
+++ team/kmoore/stasis-mwi/channels/chan_sip.c Tue Feb 26 15:02:43 2013
@@ -294,6 +294,7 @@
 #include "sip/include/dialplan_functions.h"
 #include "sip/include/security_events.h"
 #include "asterisk/sip_api.h"
+#include "asterisk/app.h"
 
 /*** DOCUMENTATION
 	<application name="SIPDtmfMode" language="en_US">
@@ -24592,13 +24593,20 @@
 		if (!ast_strlen_zero(mailbox) && !ast_strlen_zero(c)) {
 			char *old = strsep(&c, " ");
 			char *new = strsep(&old, "/");
+			int new_msgs = atoi(new);
+			int old_msgs = atoi(old);
+			char *context = "SIP_Remote";
 			struct ast_event *event;
+			struct ast_str *uniqueid = ast_str_alloca(128);
+
+			ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
+			stasis_publish_mwi_state(ast_str_buffer(uniqueid), mailbox, context, new_msgs, old_msgs);
 
 			if ((event = ast_event_new(AST_EVENT_MWI,
 						   AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
-						   AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, "SIP_Remote",
-						   AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, atoi(new),
-						   AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, atoi(old),
+						   AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
+						   AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, new_msgs,
+						   AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, old_msgs,
 						   AST_EVENT_IE_END))) {
 				ast_event_queue_and_cache(event);
 			}
@@ -28648,19 +28656,24 @@
 {
 	struct sip_mailbox *mailbox;
 	int in_cache;
+	struct ast_str *uniqueid = ast_str_alloca(128);
 
 	in_cache = 0;
 	AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) {
-		struct ast_event *event;
-		event = ast_event_get_cached(AST_EVENT_MWI,
-			AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox->mailbox,
-			AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, S_OR(mailbox->context, "default"),
-			AST_EVENT_IE_END);
-		if (!event)
+		struct stasis_message *msg;
+		struct stasis_mwi_state *mwi_state;
+
+		ast_str_reset(uniqueid);
+		ast_str_set(&uniqueid, 0, "%s@%s", mailbox->mailbox, S_OR(mailbox->context, "default"));
+
+		msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_message_type(), ast_str_buffer(uniqueid));
+		if (!msg) {
 			continue;
-		*new += ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
-		*old += ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS);
-		ast_event_destroy(event);
+		}
+
+		mwi_state = stasis_message_data(msg);
+		*new += mwi_state->new_msgs;
+		*old += mwi_state->old_msgs;
 		in_cache = 1;
 	}
 

Modified: team/kmoore/stasis-mwi/channels/chan_unistim.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/channels/chan_unistim.c?view=diff&rev=382149&r1=382148&r2=382149
==============================================================================
--- team/kmoore/stasis-mwi/channels/chan_unistim.c (original)
+++ team/kmoore/stasis-mwi/channels/chan_unistim.c Tue Feb 26 15:02:43 2013
@@ -5498,23 +5498,24 @@
 /*--- unistim_send_mwi_to_peer: Send message waiting indication ---*/
 static int unistim_send_mwi_to_peer(struct unistim_line *peer, unsigned int tick)
 {
-	struct ast_event *event;
 	int new;
 	char *mailbox, *context;
+	struct stasis_message *msg;
+	struct ast_str *uniqueid = ast_str_alloca(128);
 
 	context = mailbox = ast_strdupa(peer->mailbox);
 	strsep(&context, "@");
 	if (ast_strlen_zero(context)) {
 		context = "default";
 	}
-	event = ast_event_get_cached(AST_EVENT_MWI,
-		AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
-		AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
-		AST_EVENT_IE_END);
-
-	if (event) {
-		new = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
-		ast_event_destroy(event);
+
+	ast_str_set(&uniqueid, 0, "%s@%s", mailbox, context);
+
+	msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_message_type(), ast_str_buffer(uniqueid));
+
+	if (msg) {
+		struct stasis_mwi_state *mwi_state = stasis_message_data(msg);
+		new = mwi_state->new_msgs;
 	} else { /* Fall back on checking the mailbox directly */
 		new = ast_app_has_voicemail(peer->mailbox, "INBOX");
 	}

Modified: team/kmoore/stasis-mwi/channels/sig_pri.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/channels/sig_pri.c?view=diff&rev=382149&r1=382148&r2=382149
==============================================================================
--- team/kmoore/stasis-mwi/channels/sig_pri.c (original)
+++ team/kmoore/stasis-mwi/channels/sig_pri.c Tue Feb 26 15:02:43 2013
@@ -8799,8 +8799,9 @@
 static void sig_pri_mwi_cache_update(struct sig_pri_span *pri)
 {
 	int idx;
-	int num_messages;
-	struct ast_event *event;
+	struct ast_str *uniqueid = ast_str_alloca(128);
+	struct stasis_message *msg;
+	struct stasis_mwi_state *mwi_state;
 
 	for (idx = 0; idx < ARRAY_LEN(pri->mbox); ++idx) {
 		if (!pri->mbox[idx].sub) {
@@ -8808,18 +8809,18 @@
 			continue;
 		}
 
-		event = ast_event_get_cached(AST_EVENT_MWI,
-			AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, pri->mbox[idx].number,
-			AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, pri->mbox[idx].context,
-			AST_EVENT_IE_END);
-		if (!event) {
+		ast_str_reset(uniqueid);
+		ast_str_set(&uniqueid, 0, "%s@%s", pri->mbox[idx].number, pri->mbox[idx].context);
+
+		msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_message_type(), ast_str_buffer(uniqueid));
+		if (!msg) {
 			/* No cached event for this mailbox. */
 			continue;
 		}
-		num_messages = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
+
+		mwi_state = stasis_message_data(msg);
 		sig_pri_send_mwi_indication(pri, pri->mbox[idx].vm_number, pri->mbox[idx].number,
-			pri->mbox[idx].context, num_messages);
-		ast_event_destroy(event);
+			pri->mbox[idx].context, mwi_state->new_msgs);
 	}
 }
 #endif	/* defined(HAVE_PRI_MWI) */

Modified: team/kmoore/stasis-mwi/include/asterisk/app.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/include/asterisk/app.h?view=diff&rev=382149&r1=382148&r2=382149
==============================================================================
--- team/kmoore/stasis-mwi/include/asterisk/app.h (original)
+++ team/kmoore/stasis-mwi/include/asterisk/app.h Tue Feb 26 15:02:43 2013
@@ -1086,8 +1086,72 @@
  */
 int ast_app_parse_timelen(const char *timestr, int *result, enum ast_timelen defunit);
 
+/*!
+ * \brief Publish a MWI state update via stasis
+ * \param[in] uniqueid A unique identifier for this mailbox (usually mailbox at context)
+ * \param[in] mailbox The number identifying this mailbox
+ * \param[in] context The context this mailbox resides in
+ * \param[in] new_msgs The number of new messages in this mailbox
+ * \param[in] old_msgs The number of old messages in this mailbox
+ * \retval 0 Success
+ * \retval -1 Failure
+ * \since 12
+ */
+int stasis_publish_mwi_state(
+			const char *uniqueid,
+			const char *mailbox,
+			const char *context,
+			int new_msgs,
+			int old_msgs);
+
+/*!
+ * \brief The structure that contains MWI state
+ * \since 12
+ */
+struct stasis_mwi_state {
+	AST_DECLARE_STRING_FIELDS(
+		AST_STRING_FIELD(uniqueid);	/*!< Unique identifier for this mailbox/context */
+		AST_STRING_FIELD(mailbox);	/*!< Mailbox for this event */
+		AST_STRING_FIELD(context);	/*!< Context that this mailbox belongs to */
+	);
+	int new_msgs;				/*!< The current number of new messages for this mailbox */
+	int old_msgs;				/*!< The current number of old messages for this mailbox */
+};
+
+/*!
+ * \brief Get the Stasis topic for MWI messages
+ * \retval The topic structure for MWI messages
+ * \retval NULL if it has not been allocated
+ * \since 12
+ */
+struct stasis_topic *stasis_mwi_topic(void);
+
+/*!
+ * \brief Get the Stasis caching topic for MWI messages
+ * \retval The caching topic structure for MWI messages
+ * \retval NULL if it has not been allocated
+ * \since 12
+ */
+struct stasis_caching_topic *stasis_mwi_topic_cached(void);
+
+/*!
+ * \brief Get the Stasis message type for MWI messages
+ * \retval The message type structure for MWI messages
+ * \retval NULL if it has not been allocated
+ * \since 12
+ */
+struct stasis_message_type *stasis_mwi_message_type(void);
+
+/*!
+ * \brief Initialize the application core
+ * \retval 0 Success
+ * \retval -1 Failure
+ * \since 12
+ */
+int app_init(void);
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif
 
 #endif /* _ASTERISK_APP_H */
+

Modified: team/kmoore/stasis-mwi/main/app.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/main/app.c?view=diff&rev=382149&r1=382148&r2=382149
==============================================================================
--- team/kmoore/stasis-mwi/main/app.c (original)
+++ team/kmoore/stasis-mwi/main/app.c Tue Feb 26 15:02:43 2013
@@ -66,6 +66,8 @@
 #include "asterisk/threadstorage.h"
 #include "asterisk/test.h"
 #include "asterisk/module.h"
+#include "asterisk/astobj2.h"
+#include "asterisk/stasis.h"
 
 AST_THREADSTORAGE_PUBLIC(ast_str_thread_global_buf);
 
@@ -77,6 +79,10 @@
 };
 
 static AST_LIST_HEAD_STATIC(zombies, zombie);
+
+static struct stasis_topic *__mwi_topic;
+static struct stasis_caching_topic *__mwi_topic_cached;
+static struct stasis_message_type *__mwi_message_type;
 
 static void *shaun_of_the_dead(void *data)
 {
@@ -2632,3 +2638,85 @@
 	return 0;
 }
 
+
+
+static void mwi_state_dtor(void *obj)
+{
+	struct stasis_mwi_state *mwi_state = obj;
+	ast_string_field_free_memory(mwi_state);
+}
+
+struct stasis_topic *stasis_mwi_topic(void)
+{
+	return __mwi_topic;
+}
+
+struct stasis_caching_topic *stasis_mwi_topic_cached(void)
+{
+	return __mwi_topic_cached;
+}
+
+struct stasis_message_type *stasis_mwi_message_type(void)
+{
+	return __mwi_message_type;
+}
+
+int stasis_publish_mwi_state(
+			const char *uniqueid,
+			const char *mailbox,
+			const char *context,
+			int new_msgs,
+			int old_msgs)
+{
+	RAII_VAR(struct stasis_mwi_state *, mwi_state, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
+
+	mwi_state = ao2_alloc(sizeof(*mwi_state), mwi_state_dtor);
+	if (ast_string_field_init(mwi_state, 256)) {
+		return -1;
+	}
+
+	ast_string_field_set(mwi_state, mailbox, mailbox);
+	ast_string_field_set(mwi_state, context, context);
+	mwi_state->new_msgs = new_msgs;
+	mwi_state->old_msgs = old_msgs;
+
+	message = stasis_message_create(stasis_mwi_message_type(), mwi_state);
+
+	ast_assert(stasis_mwi_topic() != NULL);
+	stasis_publish(stasis_mwi_topic(), message);
+
+	ao2_ref(mwi_state, +1);
+	return 0;
+}
+
+static const char *mwi_state_get_id(struct stasis_message *message)
+{
+	struct stasis_mwi_state *mwi_state;
+	if (stasis_mwi_message_type() != stasis_message_type(message)) {
+		return NULL;
+	}
+
+	mwi_state = stasis_message_data(message);
+	return mwi_state->uniqueid;
+}
+
+static void app_exit(void)
+{
+	ao2_cleanup(__mwi_topic);
+	__mwi_topic = NULL;
+	ao2_cleanup(__mwi_topic_cached);
+	__mwi_topic_cached = NULL;
+	ao2_cleanup(__mwi_message_type);
+	__mwi_message_type = NULL;
+}
+
+int app_init(void)
+{
+	__mwi_topic = stasis_topic_create("stasis_mwi_topic");
+	__mwi_topic_cached = stasis_caching_topic_create(__mwi_topic, mwi_state_get_id);
+	__mwi_message_type = stasis_message_type_create("stasis_mwi_state");
+	ast_register_atexit(app_exit);
+	return 0;
+}
+

Modified: team/kmoore/stasis-mwi/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/main/asterisk.c?view=diff&rev=382149&r1=382148&r2=382149
==============================================================================
--- team/kmoore/stasis-mwi/main/asterisk.c (original)
+++ team/kmoore/stasis-mwi/main/asterisk.c Tue Feb 26 15:02:43 2013
@@ -4126,6 +4126,11 @@
 		exit(1);
 	}
 
+	if (app_init()) {
+		printf("App core initialization failed.\n%s", term_quit());
+		exit(1);
+	}
+
 	ast_makesocket();
 	sigemptyset(&sigs);
 	sigaddset(&sigs, SIGHUP);

Modified: team/kmoore/stasis-mwi/res/res_jabber.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/res/res_jabber.c?view=diff&rev=382149&r1=382148&r2=382149
==============================================================================
--- team/kmoore/stasis-mwi/res/res_jabber.c (original)
+++ team/kmoore/stasis-mwi/res/res_jabber.c Tue Feb 26 15:02:43 2013
@@ -3361,9 +3361,13 @@
 			return IKS_FILTER_EAT;
 		}
 	} else if (!strcasecmp(iks_name(item_content), "mailbox")) {
+		char *uniqueid = ast_strdupa(item_id);
 		context = strsep(&item_id, "@");
 		sscanf(iks_find_cdata(item_content, "OLDMSGS"), "%10d", &oldmsgs);
 		sscanf(iks_find_cdata(item_content, "NEWMSGS"), "%10d", &newmsgs);
+
+		stasis_publish_mwi_state(uniqueid, item_id, context, newmsgs, oldmsgs);
+
 		if (!(event = ast_event_new(AST_EVENT_MWI, AST_EVENT_IE_MAILBOX,
 			AST_EVENT_IE_PLTYPE_STR, item_id, AST_EVENT_IE_CONTEXT,
 			AST_EVENT_IE_PLTYPE_STR, context, AST_EVENT_IE_OLDMSGS,

Modified: team/kmoore/stasis-mwi/res/res_xmpp.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/res/res_xmpp.c?view=diff&rev=382149&r1=382148&r2=382149
==============================================================================
--- team/kmoore/stasis-mwi/res/res_xmpp.c (original)
+++ team/kmoore/stasis-mwi/res/res_xmpp.c Tue Feb 26 15:02:43 2013
@@ -1476,9 +1476,13 @@
 			return IKS_FILTER_EAT;
 		}
 	} else if (!strcasecmp(iks_name(item_content), "mailbox")) {
+		char *uniqueid = ast_strdupa(item_id);
 		context = strsep(&item_id, "@");
 		sscanf(iks_find_cdata(item_content, "OLDMSGS"), "%10d", &oldmsgs);
 		sscanf(iks_find_cdata(item_content, "NEWMSGS"), "%10d", &newmsgs);
+
+		stasis_publish_mwi_state(uniqueid, item_id, context, newmsgs, oldmsgs);
+
 		if (!(event = ast_event_new(AST_EVENT_MWI, AST_EVENT_IE_MAILBOX,
 					    AST_EVENT_IE_PLTYPE_STR, item_id, AST_EVENT_IE_CONTEXT,
 					    AST_EVENT_IE_PLTYPE_STR, context, AST_EVENT_IE_OLDMSGS,




More information about the asterisk-commits mailing list