[asterisk-commits] trunk r28745 - in /trunk: ./ apps/ channels/ include/asterisk/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri May 19 11:21:31 MST 2006


Author: tilghman
Date: Fri May 19 13:21:31 2006
New Revision: 28745

URL: http://svn.digium.com/view/asterisk?rev=28745&view=rev
Log:
As requested by kpfleming, renaming messagecount to inboxcount and messagecount2 to messagecount.

Modified:
    trunk/UPGRADE.txt
    trunk/app.c
    trunk/apps/app_hasnewvoicemail.c
    trunk/apps/app_voicemail.c
    trunk/channels/chan_iax2.c
    trunk/channels/chan_sip.c
    trunk/channels/chan_skinny.c
    trunk/include/asterisk/app.h
    trunk/manager.c

Modified: trunk/UPGRADE.txt
URL: http://svn.digium.com/view/asterisk/trunk/UPGRADE.txt?rev=28745&r1=28744&r2=28745&view=diff
==============================================================================
--- trunk/UPGRADE.txt (original)
+++ trunk/UPGRADE.txt Fri May 19 13:21:31 2006
@@ -107,6 +107,12 @@
   to specify which DTMF digits can be used to accept a recording and
   which digits can be used to cancel a recording.
 
+* ast_app_messagecount has been renamed to ast_app_inboxcount.  There is now a
+  new ast_app_messagecount function which takes a single context/mailbox/folder
+  mailbox specification and returns the message count for that folder only.
+  This addresses the deficiency of not being able to count the number of
+  messages in folders other than INBOX and Old.
+
 Manager:
 
 * After executing the 'status' manager action, the "Status" manager events

Modified: trunk/app.c
URL: http://svn.digium.com/view/asterisk/trunk/app.c?rev=28745&r1=28744&r2=28745&view=diff
==============================================================================
--- trunk/app.c (original)
+++ trunk/app.c Fri May 19 13:21:31 2006
@@ -145,23 +145,23 @@
 }
 
 static int (*ast_has_voicemail_func)(const char *mailbox, const char *folder) = NULL;
-static int (*ast_messagecount_func)(const char *mailbox, int *newmsgs, int *oldmsgs) = NULL;
-static int (*ast_messagecount2_func)(const char *context, const char *mailbox, const char *folder) = NULL;
+static int (*ast_inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs) = NULL;
+static int (*ast_messagecount_func)(const char *context, const char *mailbox, const char *folder) = NULL;
 
 void ast_install_vm_functions(int (*has_voicemail_func)(const char *mailbox, const char *folder),
-			      int (*messagecount_func)(const char *mailbox, int *newmsgs, int *oldmsgs),
-			      int (*messagecount2_func)(const char *context, const char *mailbox, const char *folder))
+			      int (*inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs),
+			      int (*messagecount_func)(const char *context, const char *mailbox, const char *folder))
 {
 	ast_has_voicemail_func = has_voicemail_func;
+	ast_inboxcount_func = inboxcount_func;
 	ast_messagecount_func = messagecount_func;
-	ast_messagecount2_func = messagecount2_func;
 }
 
 void ast_uninstall_vm_functions(void)
 {
 	ast_has_voicemail_func = NULL;
+	ast_inboxcount_func = NULL;
 	ast_messagecount_func = NULL;
-	ast_messagecount2_func = NULL;
 }
 
 int ast_app_has_voicemail(const char *mailbox, const char *folder)
@@ -178,15 +178,15 @@
 }
 
 
-int ast_app_messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
+int ast_app_inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
 {
 	static int warned = 0;
 	if (newmsgs)
 		*newmsgs = 0;
 	if (oldmsgs)
 		*oldmsgs = 0;
-	if (ast_messagecount_func)
-		return ast_messagecount_func(mailbox, newmsgs, oldmsgs);
+	if (ast_inboxcount_func)
+		return ast_inboxcount_func(mailbox, newmsgs, oldmsgs);
 
 	if (!warned && (option_verbose > 2)) {
 		warned++;
@@ -196,11 +196,11 @@
 	return 0;
 }
 
-int ast_app_messagecount2(const char *context, const char *mailbox, const char *folder)
+int ast_app_messagecount(const char *context, const char *mailbox, const char *folder)
 {
 	static int warned = 0;
-	if (ast_messagecount2_func)
-		return ast_messagecount2_func(context, mailbox, folder);
+	if (ast_messagecount_func)
+		return ast_messagecount_func(context, mailbox, folder);
 
 	if (!warned && (option_verbose > 2)) {
 		warned++;

Modified: trunk/apps/app_hasnewvoicemail.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_hasnewvoicemail.c?rev=28745&r1=28744&r2=28745&view=diff
==============================================================================
--- trunk/apps/app_hasnewvoicemail.c (original)
+++ trunk/apps/app_hasnewvoicemail.c Fri May 19 13:21:31 2006
@@ -128,7 +128,7 @@
 			priority_jump = 1;
 	}
 
-	vmcount = ast_app_messagecount2(context, vmbox, vmfolder);
+	vmcount = ast_app_messagecount(context, vmbox, vmfolder);
 	/* Set the count in the channel variable */
 	if (varname) {
 		snprintf(tmp, sizeof(tmp), "%d", vmcount);
@@ -177,7 +177,7 @@
 		args.folder = "INBOX";
 	}
 
-	snprintf(buf, len, "%d", ast_app_messagecount2(context, args.vmbox, args.folder));
+	snprintf(buf, len, "%d", ast_app_messagecount(context, args.vmbox, args.folder));
 
 	LOCAL_USER_REMOVE(u);
 	

Modified: trunk/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_voicemail.c?rev=28745&r1=28744&r2=28745&view=diff
==============================================================================
--- trunk/apps/app_voicemail.c (original)
+++ trunk/apps/app_voicemail.c Fri May 19 13:21:31 2006
@@ -2012,7 +2012,7 @@
 }
 
 #ifdef USE_ODBC_STORAGE
-static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
+static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
 {
 	int x = -1;
 	int res;
@@ -2127,7 +2127,7 @@
 	return x;
 }
 
-static int messagecount2(const char *context, const char *mailbox, const char *folder)
+static int messagecount(const char *context, const char *mailbox, const char *folder)
 {
 	struct odbc_obj *obj = NULL;
 	int nummsgs = 0;
@@ -2193,7 +2193,7 @@
 	else
 		context = "default";
 
-	if (messagecount2(context, tmp, folder))
+	if (messagecount(context, tmp, folder))
 		return 1;
 	else
 		return 0;
@@ -2201,42 +2201,20 @@
 
 #else
 
-static int __has_voicemail(const char *mailbox, const char *folder, int shortcircuit)
+static int __has_voicemail(const char *context, const char *mailbox, const char *folder, int shortcircuit)
 {
 	DIR *dir;
 	struct dirent *de;
 	char fn[256];
-	char tmp[256]="";
-	char *mb, *cur;
-	char *context;
 	int ret = 0;
 	if (!folder)
 		folder = "INBOX";
 	/* If no mailbox, return immediately */
 	if (ast_strlen_zero(mailbox))
 		return 0;
-	if (strchr(mailbox, ',')) {
-		ast_copy_string(tmp, mailbox, sizeof(tmp));
-		mb = tmp;
-		ret = 0;
-		while((cur = strsep(&mb, ","))) {
-			if (!ast_strlen_zero(cur)) {
-				if ((ret += __has_voicemail(cur, folder, shortcircuit))) {
-					if (shortcircuit)
-						return 1; 
-				}
-			}
-		}
-		return ret;
-	}
-	ast_copy_string(tmp, mailbox, sizeof(tmp));
-	context = strchr(tmp, '@');
-	if (context) {
-		*context = '\0';
-		context++;
-	} else
+	if (!context)
 		context = "default";
-	snprintf(fn, sizeof(fn), "%s%s/%s/%s", VM_SPOOL_DIR, context, tmp, folder);
+	snprintf(fn, sizeof(fn), "%s%s/%s/%s", VM_SPOOL_DIR, context, mailbox, folder);
 	dir = opendir(fn);
 	if (!dir)
 		return 0;
@@ -2255,21 +2233,26 @@
 
 static int has_voicemail(const char *mailbox, const char *folder)
 {
-	return __has_voicemail(mailbox, folder, 1);
-}
-
-static int messagecount2(const char *context, const char *mailbox, const char *folder)
-{
-	char tmp[256];
-	snprintf(tmp, sizeof(tmp), "%s@%s", mailbox, context);
-	return __has_voicemail(tmp, folder, 0);
-}
-
-static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
-{
-	DIR *dir;
-	struct dirent *de;
-	char fn[256];
+	char tmp[256], *tmp2 = tmp, *mbox, *context;
+	ast_copy_string(tmp, mailbox, sizeof(tmp));
+	while ((mbox = strsep(&tmp2, ","))) {
+		if ((context = strchr(tmp2, '@')))
+			*context++ = '\0';
+		else
+			context = "default";
+		if (__has_voicemail(context, mbox, folder, 1))
+			return 1;
+	}
+	return 0;
+}
+
+static int messagecount(const char *context, const char *mailbox, const char *folder)
+{
+	return __has_voicemail(context, mailbox, folder, 0);
+}
+
+static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
+{
 	char tmp[256];
 	char *context;
 
@@ -2288,7 +2271,7 @@
 		mb = tmp;
 		while((cur = strsep(&mb, ", "))) {
 			if (!ast_strlen_zero(cur)) {
-				if (messagecount(cur, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
+				if (inboxcount(cur, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
 					return -1;
 				else {
 					if (newmsgs)
@@ -2307,32 +2290,10 @@
 		context++;
 	} else
 		context = "default";
-	if (newmsgs) {
-		snprintf(fn, sizeof(fn), "%s%s/%s/INBOX", VM_SPOOL_DIR, context, tmp);
-		dir = opendir(fn);
-		if (dir) {
-			while ((de = readdir(dir))) {
-				if ((strlen(de->d_name) > 3) && !strncasecmp(de->d_name, "msg", 3) &&
-					!strcasecmp(de->d_name + strlen(de->d_name) - 3, "txt"))
-						(*newmsgs)++;
-					
-			}
-			closedir(dir);
-		}
-	}
-	if (oldmsgs) {
-		snprintf(fn, sizeof(fn), "%s%s/%s/Old", VM_SPOOL_DIR, context, tmp);
-		dir = opendir(fn);
-		if (dir) {
-			while ((de = readdir(dir))) {
-				if ((strlen(de->d_name) > 3) && !strncasecmp(de->d_name, "msg", 3) &&
-					!strcasecmp(de->d_name + strlen(de->d_name) - 3, "txt"))
-						(*oldmsgs)++;
-					
-			}
-			closedir(dir);
-		}
-	}
+	if (newmsgs)
+		*newmsgs = __has_voicemail(context, tmp, "INBOX", 0);
+	if (oldmsgs)
+		*oldmsgs = __has_voicemail(context, tmp, "Old", 0);
 	return 0;
 }
 
@@ -2410,7 +2371,7 @@
 #else
 	if (!ast_strlen_zero(externnotify)) {
 #endif
-		if (messagecount(ext_context, &newvoicemails, &oldvoicemails)) {
+		if (inboxcount(ext_context, &newvoicemails, &oldvoicemails)) {
 			ast_log(LOG_ERROR, "Problem in calculating number of voicemail messages available for extension %s\n", extension);
 		} else {
 			snprintf(arguments, sizeof(arguments), "%s %s %s %d&", externnotify, context, extension, newvoicemails);
@@ -3417,7 +3378,7 @@
 
 	/* Leave voicemail for someone */
 	if (ast_app_has_voicemail(ext_context, NULL)) {
-		ast_app_messagecount(ext_context, &newmsgs, &oldmsgs);
+		ast_app_inboxcount(ext_context, &newmsgs, &oldmsgs);
 	}
 	manager_event(EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s@%s\r\nWaiting: %d\r\nNew: %d\r\nOld: %d\r\n", vmu->mailbox, vmu->context, ast_app_has_voicemail(ext_context, NULL), newmsgs, oldmsgs);
 	run_externnotify(vmu->context, vmu->mailbox);
@@ -6654,7 +6615,7 @@
 	/* compute the location of the voicemail spool directory */
 	snprintf(VM_SPOOL_DIR, sizeof(VM_SPOOL_DIR), "%s/voicemail/", ast_config_AST_SPOOL_DIR);
 
-	ast_install_vm_functions(has_voicemail, messagecount, messagecount2);
+	ast_install_vm_functions(has_voicemail, inboxcount, messagecount);
 
 #if defined(USE_ODBC_STORAGE) && !defined(EXTENDED_ODBC_STORAGE)
 	ast_log(LOG_WARNING, "The current ODBC storage table format will be changed soon."

Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?rev=28745&r1=28744&r2=28745&view=diff
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Fri May 19 13:21:31 2006
@@ -5677,7 +5677,7 @@
 		iax_ie_append_addr(&ied, IAX_IE_APPARENT_ADDR, &p->addr);
 		if (!ast_strlen_zero(p->mailbox)) {
 			int new, old;
-			ast_app_messagecount(p->mailbox, &new, &old);
+			ast_app_inboxcount(p->mailbox, &new, &old);
 			if (new > 255)
 				new = 255;
 			if (old > 255)

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=28745&r1=28744&r2=28745&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Fri May 19 13:21:31 2006
@@ -12193,7 +12193,7 @@
 	int newmsgs, oldmsgs;
 
 	/* Check for messages */
-	ast_app_messagecount(peer->mailbox, &newmsgs, &oldmsgs);
+	ast_app_inboxcount(peer->mailbox, &newmsgs, &oldmsgs);
 	
 	time(&peer->lastmsgcheck);
 	

Modified: trunk/channels/chan_skinny.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_skinny.c?rev=28745&r1=28744&r2=28745&view=diff
==============================================================================
--- trunk/channels/chan_skinny.c (original)
+++ trunk/channels/chan_skinny.c Fri May 19 13:21:31 2006
@@ -1311,7 +1311,7 @@
 		if (skinnydebug) {
 			ast_verbose("Checking for voicemail Skinny %s@%s\n", sub->parent->name, sub->parent->parent->name);
 		}
-		ast_app_messagecount(sub->parent->mailbox, &new, &old);
+		ast_app_inboxcount(sub->parent->mailbox, &new, &old);
 		if (skinnydebug) {
 			ast_verbose("Skinny %s@%s has voicemail!\n", sub->parent->name, sub->parent->parent->name);
 		}

Modified: trunk/include/asterisk/app.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/app.h?rev=28745&r1=28744&r2=28745&view=diff
==============================================================================
--- trunk/include/asterisk/app.h (original)
+++ trunk/include/asterisk/app.h Fri May 19 13:21:31 2006
@@ -100,8 +100,8 @@
 int ast_app_getdata_full(struct ast_channel *c, char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd);
 
 void ast_install_vm_functions(int (*has_voicemail_func)(const char *mailbox, const char *folder),
-			      int (*messagecount_func)(const char *mailbox, int *newmsgs, int *oldmsgs),
-			      int (*messagecount2_func)(const char *context, const char *mailbox, const char *folder));
+			      int (*inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs),
+			      int (*messagecount_func)(const char *context, const char *mailbox, const char *folder));
   
 void ast_uninstall_vm_functions(void);
 
@@ -109,10 +109,10 @@
 int ast_app_has_voicemail(const char *mailbox, const char *folder);
 
 /*! Determine number of new/old messages in a mailbox */
-int ast_app_messagecount(const char *mailbox, int *newmsgs, int *oldmsgs);
+int ast_app_inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs);
 
 /*! Determine number of messages in a given mailbox and folder */
-int ast_app_messagecount2(const char *context, const char *mailbox, const char *folder);
+int ast_app_messagecount(const char *context, const char *mailbox, const char *folder);
 
 /*! Safely spawn an external program while closing file descriptors 
 	\note This replaces the \b system call in all Asterisk modules

Modified: trunk/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/manager.c?rev=28745&r1=28744&r2=28745&view=diff
==============================================================================
--- trunk/manager.c (original)
+++ trunk/manager.c Fri May 19 13:21:31 2006
@@ -1520,7 +1520,7 @@
 		astman_send_error(s, m, "Mailbox not specified");
 		return 0;
 	}
-	ast_app_messagecount(mailbox, &newmsgs, &oldmsgs);
+	ast_app_inboxcount(mailbox, &newmsgs, &oldmsgs);
 	if (!ast_strlen_zero(id)) {
 		snprintf(idText, sizeof(idText), "ActionID: %s\r\n",id);
 	}



More information about the asterisk-commits mailing list