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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 9 18:35:51 CDT 2013


Author: mmichelson
Date: Tue Apr  9 18:35:48 2013
New Revision: 385166

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385166
Log:
Write function to send MWI notify.


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=385166&r1=385165&r2=385166
==============================================================================
--- team/mmichelson/pub_sub/res/res_sip_mwi.c (original)
+++ team/mmichelson/pub_sub/res/res_sip_mwi.c Tue Apr  9 18:35:48 2013
@@ -100,8 +100,59 @@
 	return strcmp(mwi_sub1->id, mwi_sub2->id) ? 0 : CMP_MATCH;
 }
 
+struct message_accumulator {
+	int old_msgs;
+	int new_msgs;
+};
+
+static int get_message_count(void *obj, void *arg, int flags)
+{
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+	struct mwi_stasis_subscription *mwi_stasis = obj;
+	struct message_accumulator *counter = arg;
+	struct stasis_mwi_state *mwi_state;
+
+	msg = stasis_cache_get(stasis_mwi_topic_cached(), stasis_mwi_state_type(), mwi_stasis->mailbox);
+	if (!msg) {
+		return 0;
+	}
+
+	mwi_state = stasis_message_data(msg);
+	counter->old_msgs += mwi_state->old_msgs;
+	counter->new_msgs += mwi_state->new_msgs;
+	return 0;
+}
+
 static void send_mwi_notify(struct mwi_subscription *sub)
 {
+	static pj_str_t active_str = { "active", 6 };
+	static pjsip_media_type mwi_type = {
+		.type = { "application", 11 },
+		.subtype = { "simple-message-summary", 22 },
+	};
+	struct message_accumulator counter = {
+		.old_msgs = 0,
+		.new_msgs = 0,
+	};
+	RAII_VAR(struct ast_str *, body, ast_str_create(64), ast_free_ptr);
+	pjsip_tx_data *tdata;
+	pj_str_t pj_body;
+
+	ao2_callback(sub->stasis_subs, OBJ_NODATA, get_message_count, &counter);
+
+	/* XXX Not sure if the \r\n is actually necessary */
+	ast_str_append(&body, 0, "%d/%d(0/0)\r\n", counter.new_msgs, counter.old_msgs);
+	pj_cstr(&pj_body, ast_str_buffer(body));
+
+	pjsip_mwi_notify(ast_sip_subscription_get_evsub(sub->sip_sub),
+			PJSIP_EVSUB_STATE_ACTIVE,
+			&active_str,
+			NULL,
+			&mwi_type,
+			&pj_body,
+			&tdata);
+
+	ast_sip_subscription_send_request(sub->sip_sub, tdata);
 }
 
 static void mwi_subscription_shutdown(struct ast_sip_subscription *sub)




More information about the asterisk-commits mailing list