[Asterisk-code-review] app_voicemail: Fix pollmailboxes (asterisk[13])

Friendly Automation asteriskteam at digium.com
Mon Aug 31 08:50:18 CDT 2020


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/14812 )

Change subject: app_voicemail: Fix pollmailboxes
......................................................................

app_voicemail: Fix pollmailboxes

The name of the voicemail context was overwriting the name of the
subscribed mailbox. Fix by simplifying how we create the MWI
subscription.

ASTERISK-29029 #close

Change-Id: Ie8a7db6a0b68f3995b0846bbb733a21909ba44e5
---
M apps/app_voicemail.c
1 file changed, 23 insertions(+), 49 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 742c9c3..a192122 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -1017,23 +1017,9 @@
 	int old_new;
 	int old_old;
 	char *uniqueid;
-	char mailbox[0];
+	char *mailbox;
 };
 
-struct mwi_sub_task {
-	const char *mailbox;
-	const char *context;
-	const char *uniqueid;
-};
-
-static void mwi_sub_task_dtor(struct mwi_sub_task *mwist)
-{
-	ast_free((void *) mwist->mailbox);
-	ast_free((void *) mwist->context);
-	ast_free((void *) mwist->uniqueid);
-	ast_free(mwist);
-}
-
 static struct ast_taskprocessor *mwi_subscription_tps;
 
 static AST_RWLIST_HEAD_STATIC(mwi_subs, mwi_sub);
@@ -13286,6 +13272,7 @@
 static void mwi_sub_destroy(struct mwi_sub *mwi_sub)
 {
 	ast_free(mwi_sub->uniqueid);
+	ast_free(mwi_sub->mailbox);
 	ast_free(mwi_sub);
 }
 
@@ -13364,35 +13351,12 @@
 
 static int handle_subscribe(void *datap)
 {
-	unsigned int len;
-	struct mwi_sub *mwi_sub;
-	struct mwi_sub_task *p = datap;
-	size_t context_len;
-
-	len = sizeof(*mwi_sub) + 1;
-	if (!ast_strlen_zero(p->mailbox))
-		len += strlen(p->mailbox);
-
-	context_len = strlen(p->context) + 1; /* Allow for seperator */
-	if (!ast_strlen_zero(p->context))
-		len += context_len;
-
-	if (!(mwi_sub = ast_calloc(1, len)))
-		return -1;
-
-	mwi_sub->uniqueid = ast_strdup(p->uniqueid);
-	if (!ast_strlen_zero(p->mailbox))
-		strcpy(mwi_sub->mailbox, p->mailbox);
-
-	if (!ast_strlen_zero(p->context)) {
-		strcat(mwi_sub->mailbox, "@");
-		ast_copy_string(mwi_sub->mailbox, p->context, context_len);
-	}
+	struct mwi_sub *mwi_sub = datap;
 
 	AST_RWLIST_WRLOCK(&mwi_subs);
 	AST_RWLIST_INSERT_TAIL(&mwi_subs, mwi_sub, entry);
 	AST_RWLIST_UNLOCK(&mwi_subs);
-	mwi_sub_task_dtor(p);
+
 	poll_subscribed_mailbox(mwi_sub);
 	return 0;
 }
@@ -13413,29 +13377,39 @@
 
 static void mwi_sub_event_cb(struct stasis_subscription_change *change)
 {
-	struct mwi_sub_task *mwist;
+	struct mwi_sub *mwi_sub;
 	const char *topic;
 	char *context;
 	char *mailbox;
 
-	mwist = ast_calloc(1, (sizeof(*mwist)));
-	if (!mwist) {
+	mwi_sub = ast_calloc(1, sizeof(*mwi_sub));
+	if (!mwi_sub) {
 		return;
 	}
 
 	/* The topic name is prefixed with "mwi:all/" as this is a pool topic */
 	topic = stasis_topic_name(change->topic) + 8;
 	if (separate_mailbox(ast_strdupa(topic), &mailbox, &context)) {
-		ast_free(mwist);
+		mwi_sub_destroy(mwi_sub);
 		return;
 	}
 
-	mwist->mailbox = ast_strdup(mailbox);
-	mwist->context = ast_strdup(context);
-	mwist->uniqueid = ast_strdup(change->uniqueid);
+	/* separate_mailbox() guarantees a non-NULL, non-empty mailbox and context */
+	if (ast_asprintf(&mwi_sub->mailbox, "%s@%s", mailbox, context) < 0) {
+		mwi_sub_destroy(mwi_sub);
+		return;
+	}
 
-	if (ast_taskprocessor_push(mwi_subscription_tps, handle_subscribe, mwist) < 0) {
-		mwi_sub_task_dtor(mwist);
+	/* The stasis subscription uniqueid will never be NULL */
+	mwi_sub->uniqueid = ast_strdup(change->uniqueid);
+	if (!mwi_sub->uniqueid) {
+		mwi_sub_destroy(mwi_sub);
+		return;
+	}
+
+	if (ast_taskprocessor_push(mwi_subscription_tps, handle_subscribe, mwi_sub) < 0) {
+		mwi_sub_destroy(mwi_sub);
+		return;
 	}
 }
 

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14812
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: Ie8a7db6a0b68f3995b0846bbb733a21909ba44e5
Gerrit-Change-Number: 14812
Gerrit-PatchSet: 5
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200831/36973790/attachment-0001.html>


More information about the asterisk-code-review mailing list