[svn-commits] kharwell: trunk r407015 - in /trunk: ./ res/res_pjsip_mwi.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Jan 31 16:08:49 CST 2014


Author: kharwell
Date: Fri Jan 31 16:08:46 2014
New Revision: 407015

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=407015
Log:
res_pjsip_mwi: Subscribe fails when missing aor name

When subscribing to MWI (res_pjsip_mwi) and the sip uri did not contain a name
(ex: sip:<ip address>) then the subscription would fail since it would be unable
to locate an associated aor.  This patch makes it so that when a subscribe comes
with no aor name then it will subscribe to all aors on the located endpoint.

(closes issue ASTERISK-23072)
Reported by: Bob M
Review: https://reviewboard.asterisk.org/r/3164/
........

Merged revisions 407014 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/res/res_pjsip_mwi.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-12-merged' - no diff available.

Modified: trunk/res/res_pjsip_mwi.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_mwi.c?view=diff&rev=407015&r1=407014&r2=407015
==============================================================================
--- trunk/res/res_pjsip_mwi.c (original)
+++ trunk/res/res_pjsip_mwi.c Fri Jan 31 16:08:46 2014
@@ -453,10 +453,92 @@
 	return 0;
 }
 
+static int mwi_on_aor(void *obj, void *arg, int flags)
+{
+	struct ast_sip_aor *aor = obj;
+	struct mwi_subscription *sub = arg;
+	char *mailboxes;
+	char *mailbox;
+
+	if (ast_strlen_zero(aor->mailboxes)) {
+		return 0;
+	}
+
+	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);
+		}
+	}
+
+	return 0;
+}
+
+static struct mwi_subscription *mwi_create_subscription(
+	struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
+{
+	struct mwi_subscription *sub = mwi_subscription_alloc(
+		endpoint, AST_SIP_NOTIFIER, 1, rdata);
+
+	if (!sub) {
+		return NULL;
+	}
+
+	if (add_mwi_datastore(sub)) {
+		ast_log(LOG_WARNING, "Unable to allocate datastore on MWI "
+			"subscription from %s\n", sub->id);
+		ao2_ref(sub, -1);
+		return NULL;
+	}
+
+	return sub;
+}
+
+static struct mwi_subscription *mwi_subscribe_single(
+	struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata, const char *name)
+{
+	RAII_VAR(struct ast_sip_aor *, aor,
+		 ast_sip_location_retrieve_aor(name), ao2_cleanup);
+	struct mwi_subscription *sub;
+
+	if (!aor) {
+		ast_log(LOG_WARNING, "Unable to locate aor %s. MWI "
+			"subscription failed.\n", name);
+		return NULL;
+	}
+
+	if (ast_strlen_zero(aor->mailboxes)) {
+		ast_log(LOG_WARNING, "AOR %s has no configured mailboxes. "
+			"MWI subscription failed\n", name);
+		return NULL;
+	}
+
+	if (!(sub = mwi_create_subscription(endpoint, rdata))) {
+		return NULL;
+	}
+
+	mwi_on_aor(aor, sub, 0);
+	return sub;
+}
+
+static struct mwi_subscription *mwi_subscribe_all(
+	struct ast_sip_endpoint *endpoint, pjsip_rx_data *rdata)
+{
+	struct mwi_subscription *sub = mwi_create_subscription(endpoint, rdata);
+
+	if (!sub) {
+		return NULL;
+	}
+
+	ast_sip_for_each_aor(endpoint->aors, mwi_on_aor, sub);
+	return sub;
+}
+
 static struct ast_sip_subscription *mwi_new_subscribe(struct ast_sip_endpoint *endpoint,
 		pjsip_rx_data *rdata)
 {
-	RAII_VAR(struct ast_sip_aor *, aor, NULL, ao2_cleanup);
 	/* It's not obvious here, but the reference(s) to this subscription,
 	 * once this function exits, is held by the stasis subscription(s)
 	 * created in mwi_stasis_subscription_alloc()
@@ -466,8 +548,6 @@
 	pjsip_sip_uri *sip_ruri;
 	pjsip_evsub *evsub;
 	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");
@@ -476,34 +556,10 @@
 	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. MWI subscription failed.\n", aor_name);
-		return NULL;
-	}
-
-	if (ast_strlen_zero(aor->mailboxes)) {
-		ast_log(LOG_WARNING, "AOR %s has no configured mailboxes. MWI subscription failed\n", aor_name);
-		return NULL;
-	}
-
-	sub = mwi_subscription_alloc(endpoint, AST_SIP_NOTIFIER, 1, rdata);
-	if (!sub) {
-		return NULL;
-	}
-
-	if (add_mwi_datastore(sub)) {
-		ast_log(LOG_WARNING, "Unable to allocate datastore on MWI subscription from %s\n", sub->id);
-		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);
-		}
+	/* no aor in uri? subscribe to all on endpoint */
+	if (!(sub = ast_strlen_zero(aor_name) ? mwi_subscribe_all(endpoint, rdata) :
+	      mwi_subscribe_single(endpoint, rdata, aor_name))) {
+		return NULL;
 	}
 
 	evsub = ast_sip_subscription_get_evsub(sub->sip_sub);




More information about the svn-commits mailing list