[asterisk-commits] mmichelson: branch mmichelson/pub_sub r385159 - in /team/mmichelson/pub_sub: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 9 16:12:43 CDT 2013


Author: mmichelson
Date: Tue Apr  9 16:12:40 2013
New Revision: 385159

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385159
Log:
Some forward progress for MWI.

This will use endpoint configuration in order to subscribe to stasis MWI stuff.


Modified:
    team/mmichelson/pub_sub/include/asterisk/res_sip.h
    team/mmichelson/pub_sub/res/res_sip/sip_configuration.c
    team/mmichelson/pub_sub/res/res_sip_mwi.c

Modified: team/mmichelson/pub_sub/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pub_sub/include/asterisk/res_sip.h?view=diff&rev=385159&r1=385158&r2=385159
==============================================================================
--- team/mmichelson/pub_sub/include/asterisk/res_sip.h (original)
+++ team/mmichelson/pub_sub/include/asterisk/res_sip.h Tue Apr  9 16:12:40 2013
@@ -267,6 +267,8 @@
                 AST_STRING_FIELD(mohsuggest);
 		/*! Optional external media address to use in SDP */
 		AST_STRING_FIELD(external_media_address);
+		/*! Configured voicemail boxes for this endpoint. Used for MWI */
+		AST_STRING_FIELD(mailboxes);
 	);
 	/*! Identification information for this endpoint */
 	struct ast_party_id id;

Modified: team/mmichelson/pub_sub/res/res_sip/sip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pub_sub/res/res_sip/sip_configuration.c?view=diff&rev=385159&r1=385158&r2=385159
==============================================================================
--- team/mmichelson/pub_sub/res/res_sip/sip_configuration.c (original)
+++ team/mmichelson/pub_sub/res/res_sip/sip_configuration.c Tue Apr  9 16:12:40 2013
@@ -298,6 +298,7 @@
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "direct_media_method", "invite", direct_media_method_handler, NULL, 0, 0);
 	ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "direct_media_glare_mitigation", "none", direct_media_glare_mitigation_handler, NULL, 0, 0);
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "disable_direct_media_on_nat", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, disable_direct_media_on_nat));
+	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "mailboxes", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, mailboxes));
 
 	if (ast_sip_initialize_sorcery_transport(sip_sorcery)) {
 		ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n");

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=385159&r1=385158&r2=385159
==============================================================================
--- team/mmichelson/pub_sub/res/res_sip_mwi.c (original)
+++ team/mmichelson/pub_sub/res/res_sip_mwi.c Tue Apr  9 16:12:40 2013
@@ -22,9 +22,21 @@
 #include <pjsip_simple.h>
 #include <pjlib.h>
 
+#include "asterisk/res_sip.h"
 #include "asterisk/res_sip_pubsub.h"
 #include "asterisk/module.h"
 #include "asterisk/logger.h"
+#include "asterisk/astobj2.h"
+#include "asterisk/sorcery.h"
+#include "asterisk/stasis.h"
+#include "asterisk/app.h"
+
+/*** MODULEINFO
+	<depend>pjproject</depend>
+	<depend>res_sip</depend>
+	<depend>res_sip_pubsub</depend>
+	<support_level>core</support_level>
+ ***/
 
 static void mwi_subscription_shutdown(struct ast_sip_subscription *sub)
 {
@@ -86,11 +98,79 @@
 	.refresh_subscription = mwi_refresh_subscription,
 };
 
+struct ao2_container *mwi_subscriptions;
+
+struct mwi_subscription {
+	const char *id;
+	struct stasis_subscription *event_sub;
+	struct ast_sip_subscription *sip_sub;
+};
+
+static void mwi_subscription_destructor(void *obj)
+{
+	struct mwi_subscription *sub = obj;
+	ao2_cleanup(sub->sip_sub);
+	ast_free((char *)sub->id);
+}
+
+static void send_mwi_notify(struct ast_sip_subscription *sub)
+{
+}
+
+static void mwi_stasis_cb(void *userdata, struct stasis_subscription *sub,
+		struct stasis_topic *topic, struct stasis_message *msg)
+{
+	struct mwi_subscription *mwi_sub = userdata;
+	if (stasis_subscription_final_message(sub, msg)) {
+		ao2_cleanup(mwi_sub);
+		return;
+	}
+	if (stasis_mwi_state_type() == stasis_message_type(msg)) {
+		send_mwi_notify(mwi_sub->sip_sub);
+	}
+}
+
+static int create_mwi_subscriptions_for_endpoint(void *obj, void *arg, int flags)
+{
+	struct ast_sip_endpoint *endpoint = obj;
+	char *mailboxes = ast_strdupa(endpoint->mailboxes);
+	char *mailbox;
+
+	while ((mailbox = strsep(&mailboxes, ","))) {
+		struct mwi_subscription *sub;
+		struct stasis_topic *topic;
+
+		topic = stasis_mwi_topic(mailbox);
+			
+		sub = ao2_alloc(sizeof(*sub), mwi_subscription_destructor);
+		sub->id = ast_strdup(ast_sorcery_object_get_id(endpoint));
+		/* 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);
+		sub->event_sub = stasis_subscribe(topic, mwi_stasis_cb, sub);
+		ao2_link(mwi_subscriptions, sub);
+	}
+	return 0;
+}
+
+static void create_mwi_subscriptions(void)
+{
+	RAII_VAR(struct ao2_container *, endpoints, ast_sorcery_retrieve_by_fields(
+				ast_sip_get_sorcery(), "endpoint", AST_RETRIEVE_FLAG_ALL, NULL),
+			ao2_cleanup);
+
+	ao2_callback(endpoints, OBJ_NODATA, create_mwi_subscriptions_for_endpoint, NULL);
+}
+
 static int load_module(void)
 {
 	if (ast_sip_register_subscription_handler(&mwi_handler)) {
 		return AST_MODULE_LOAD_DECLINE;
 	}
+	create_mwi_subscriptions();
 	return AST_MODULE_LOAD_SUCCESS;
 }
 




More information about the asterisk-commits mailing list