[Asterisk-code-review] voicemail: Fixed wrong voicemail message count (asterisk[master])

sungtae kim asteriskteam at digium.com
Tue Mar 6 08:16:25 CST 2018


sungtae kim has uploaded this change for review. ( https://gerrit.asterisk.org/8442


Change subject: voicemail: Fixed wrong voicemail message count
......................................................................

voicemail: Fixed wrong voicemail message count

Fixed wrong voicemail mailbox reference for Action: VoicemailUsersList.

ASTERISK-27703

Change-Id: Ie6578ad80bba2bfaf34b84f0be978f59045ce6cd
---
M apps/app_voicemail.c
1 file changed, 47 insertions(+), 16 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/42/8442/1

diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 72e3e59..cc786ba 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -6089,22 +6089,33 @@
 	return 0;
 }
 
-
+/*!
+ * \brief Check the given mailbox's message count.\n
+ * \param mailbox The \@ delimited string for user\@context. If no context is found, uses 'default' for the context.
+ * \param urgentmsgs  urgent message count.
+ * \param newmsgs new message count.
+ * \param oldmsgs old message count pointer
+ * \return -1 if error occurred, 0 otherwise.
+ */
 static int inboxcount2(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
 {
 	char tmp[256];
 	char *context;
 
 	/* If no mailbox, return immediately */
-	if (ast_strlen_zero(mailbox))
+	if (ast_strlen_zero(mailbox)) {
 		return 0;
+	}
 
-	if (newmsgs)
+	if (newmsgs) {
 		*newmsgs = 0;
-	if (oldmsgs)
+	}
+	if (oldmsgs) {
 		*oldmsgs = 0;
-	if (urgentmsgs)
+	}
+	if (urgentmsgs) {
 		*urgentmsgs = 0;
+	}
 
 	if (strchr(mailbox, ',')) {
 		int tmpnew, tmpold, tmpurgent;
@@ -6114,15 +6125,19 @@
 		mb = tmp;
 		while ((cur = strsep(&mb, ", "))) {
 			if (!ast_strlen_zero(cur)) {
-				if (inboxcount2(cur, urgentmsgs ? &tmpurgent : NULL, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
+				if (inboxcount2(cur, urgentmsgs ? &tmpurgent : NULL, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL)) {
 					return -1;
+				}
 				else {
-					if (newmsgs)
+					if (newmsgs) {
 						*newmsgs += tmpnew;
-					if (oldmsgs)
+					}
+					if (oldmsgs) {
 						*oldmsgs += tmpold;
-					if (urgentmsgs)
+					}
+					if (urgentmsgs) {
 						*urgentmsgs += tmpurgent;
+					}
 				}
 			}
 		}
@@ -6131,17 +6146,22 @@
 
 	ast_copy_string(tmp, mailbox, sizeof(tmp));
 
-	if ((context = strchr(tmp, '@')))
+	if ((context = strchr(tmp, '@'))) {
 		*context++ = '\0';
-	else
+	}
+	else {
 		context = "default";
+	}
 
-	if (newmsgs)
+	if (newmsgs) {
 		*newmsgs = __has_voicemail(context, tmp, "INBOX", 0);
-	if (oldmsgs)
+	}
+	if (oldmsgs) {
 		*oldmsgs = __has_voicemail(context, tmp, "Old", 0);
-	if (urgentmsgs)
+	}
+	if (urgentmsgs) {
 		*urgentmsgs = __has_voicemail(context, tmp, "Urgent", 0);
+	}
 
 	return 0;
 }
@@ -13241,7 +13261,10 @@
 	poll_thread = AST_PTHREADT_NULL;
 }
 
-/*! \brief Append vmu info string into given astman with event_name. */
+/*!
+ * \brief Append vmu info string into given astman with event_name.
+ * \return 0 failed. 1 otherwise.
+*/
 static int append_vmu_info_astman(
 		struct mansession *s,
 		struct ast_vm_user *vmu,
@@ -13251,6 +13274,8 @@
 {
 	int new;
 	int old;
+	char *mailbox;
+	int ret;
 
 	if((s == NULL) || (vmu == NULL) || (event_name == NULL) || (actionid == NULL)) {
 		ast_log(LOG_ERROR, "Wrong input parameter.");
@@ -13258,7 +13283,13 @@
 	}
 
 	/* get mailbox count */
-	inboxcount(vmu->mailbox, &new, &old);
+	ast_asprintf(&mailbox, "%s@%s", vmu->mailbox, vmu->context);
+	ret = inboxcount(mailbox, &new, &old);
+	ast_free(mailbox);
+	if(ret == -1) {
+		ast_log(LOG_ERROR, "Could not get mailbox count. user[%s], context[%s]", vmu->mailbox? : "", vmu->context? : "");
+		return 0;
+	}
 
 	astman_append(s,
 		"Event: %s\r\n"

-- 
To view, visit https://gerrit.asterisk.org/8442
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie6578ad80bba2bfaf34b84f0be978f59045ce6cd
Gerrit-Change-Number: 8442
Gerrit-PatchSet: 1
Gerrit-Owner: sungtae kim <pchero21 at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180306/a823abab/attachment-0001.html>


More information about the asterisk-code-review mailing list