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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 11 13:57:27 CDT 2013


Author: mmichelson
Date: Thu Apr 11 13:57:24 2013
New Revision: 385346

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385346
Log:
Fill in callback to create new MWI subscription on incoming SUBSCRIBE.


Modified:
    team/mmichelson/pub_sub/include/asterisk/res_sip.h
    team/mmichelson/pub_sub/res/res_sip/location.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=385346&r1=385345&r2=385346
==============================================================================
--- team/mmichelson/pub_sub/include/asterisk/res_sip.h (original)
+++ team/mmichelson/pub_sub/include/asterisk/res_sip.h Thu Apr 11 13:57:24 2013
@@ -155,6 +155,10 @@
 struct ast_sip_aor {
 	/*! Sorcery object details, the id is the AOR name */
 	SORCERY_OBJECT(details);
+	AST_DECLARE_STRING_FIELDS(
+		/*! Voicemail boxes for this AOR */
+		AST_STRING_FIELD(mailboxes);
+	);
 	/*! Minimum expiration time */
 	unsigned int minimum_expiration;
 	/*! Maximum expiration time */

Modified: team/mmichelson/pub_sub/res/res_sip/location.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pub_sub/res/res_sip/location.c?view=diff&rev=385346&r1=385345&r2=385346
==============================================================================
--- team/mmichelson/pub_sub/res/res_sip/location.c (original)
+++ team/mmichelson/pub_sub/res/res_sip/location.c Thu Apr 11 13:57:24 2013
@@ -31,12 +31,18 @@
 	struct ast_sip_aor *aor = obj;
 
 	ao2_cleanup(aor->permanent_contacts);
+	ast_string_field_free_memory(aor);
 }
 
 /*! \brief Allocator for AOR */
 static void *aor_alloc(const char *name)
 {
-	return ao2_alloc_options(sizeof(struct ast_sip_aor), aor_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
+	struct ast_sip_aor *aor = ao2_alloc_options(sizeof(struct ast_sip_aor), aor_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
+	if (!aor) {
+		return NULL;
+	}
+	ast_string_field_init(aor, 128);
+	return aor;
 }
 
 /*! \brief Destructor for contact */

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=385346&r1=385345&r2=385346
==============================================================================
--- team/mmichelson/pub_sub/res/res_sip_mwi.c (original)
+++ team/mmichelson/pub_sub/res/res_sip_mwi.c Thu Apr 11 13:57:24 2013
@@ -243,11 +243,73 @@
 	/* XXX STUB */
 }
 
+static struct ast_datastore_info mwi_ds_info = { };
+
+static int add_mwi_datastore(struct mwi_subscription *sub)
+{
+	RAII_VAR(struct ast_datastore *, mwi_datastore, NULL, ao2_cleanup);
+
+	mwi_datastore = ast_sip_subscription_alloc_datastore(&mwi_ds_info, "MWI datastore");
+	if (!mwi_datastore) {
+		return -1;
+	}
+	mwi_datastore->data = sub;
+
+	ast_sip_subscription_add_datastore(sub->sip_sub, mwi_datastore);
+	return 0;
+}
+
 static struct ast_sip_subscription *mwi_new_subscribe(struct ast_sip_endpoint *endpoint,
 		pjsip_rx_data *rdata)
 {
-	/*XXX STUB*/
-	return NULL;
+	RAII_VAR(struct ast_sip_aor *, aor, NULL, ao2_cleanup);
+	RAII_VAR(struct mwi_subscription *, sub, NULL, ao2_cleanup);
+	pjsip_uri *ruri = rdata->msg_info.msg->line.req.uri;
+	pjsip_sip_uri *sip_ruri;
+	char aor_name[80];
+	char *mailboxes;
+	char *mailbox;
+
+	if (!PJSIP_URI_SCHEME_IS_SIP(ruri) && !PJSIP_URI_SCHEME_IS_SIPS(ruri)) {
+		ast_log(LOG_WARNING, "Attempt to SUBSCRIBE to a non-SIP URI\n");
+		return NULL;
+	}
+	sip_ruri = pjsip_uri_get_uri(ruri);
+	ast_copy_pj_str(aor_name, &sip_ruri->user, sizeof(aor_name));
+
+	aor = ast_sip_location_retrieve_aor(aor_name);
+	if (!aor) {
+		ast_log(LOG_WARNING, "Unable to locate aor %s\n", aor_name);
+		return NULL;
+	}
+
+	if (ast_strlen_zero(aor->mailboxes)) {
+		ast_log(LOG_WARNING, "AOR %s has no configured mailboxes\n", aor_name);
+		return NULL;
+	}
+
+	sub = mwi_subscription_alloc(endpoint, 1);
+	if (!sub) {
+		return NULL;
+	}
+
+	if (add_mwi_datastore(sub)) {
+		return NULL;
+	}
+
+	mailboxes = ast_strdupa(aor->mailboxes);
+	while ((mailbox = strsep(&mailboxes, ","))) {
+		RAII_VAR(struct mwi_stasis_subscription *, 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);
+
+	send_mwi_notify(sub);
+
+	return sub->sip_sub;
 }
 
 static struct ast_sip_subscription_response_data *mwi_resubscribe(struct ast_sip_subscription *sub,




More information about the asterisk-commits mailing list