[Asterisk-cvs] asterisk app.c,1.37,1.38

markster at lists.digium.com markster at lists.digium.com
Thu Dec 30 20:16:54 CST 2004


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv29770

Modified Files:
	app.c 
Log Message:
Make voicemail registration apps register (bug #3034)


Index: app.c
===================================================================
RCS file: /usr/cvsroot/asterisk/app.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- app.c	29 Dec 2004 13:24:10 -0000	1.37
+++ app.c	31 Dec 2004 01:11:33 -0000	1.38
@@ -150,121 +150,46 @@
 	return 0;
 }
 
+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;
+
+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))
+{
+	ast_has_voicemail_func = has_voicemail_func;
+	ast_messagecount_func = messagecount_func;
+}
+
+void ast_uninstall_vm_functions(void)
+{
+	ast_has_voicemail_func = NULL;
+	ast_messagecount_func = NULL;
+}
+
 int ast_app_has_voicemail(const char *mailbox, const char *folder)
 {
-	DIR *dir;
-	struct dirent *de;
-	char fn[256];
-	char tmp[256]="";
-	char *mb, *cur;
-	char *context;
-	int ret;
-	if (!folder)
-		folder = "INBOX";
-	/* If no mailbox, return immediately */
-	if (ast_strlen_zero(mailbox))
-		return 0;
-	if (strchr(mailbox, ',')) {
-		strncpy(tmp, mailbox, sizeof(tmp) - 1);
-		mb = tmp;
-		ret = 0;
-		while((cur = strsep(&mb, ","))) {
-			if (!ast_strlen_zero(cur)) {
-				if (ast_app_has_voicemail(cur, folder))
-					return 1; 
-			}
-		}
-		return 0;
-	}
-	strncpy(tmp, mailbox, sizeof(tmp) - 1);
-	context = strchr(tmp, '@');
-	if (context) {
-		*context = '\0';
-		context++;
-	} else
-		context = "default";
-	snprintf(fn, sizeof(fn), "%s/voicemail/%s/%s/%s", (char *)ast_config_AST_SPOOL_DIR, context, tmp, folder);
-	dir = opendir(fn);
-	if (!dir)
-		return 0;
-	while ((de = readdir(dir))) {
-		if (!strncasecmp(de->d_name, "msg", 3))
-			break;
-	}
-	closedir(dir);
-	if (de)
-		return 1;
+	if (ast_has_voicemail_func)
+		return ast_has_voicemail_func(mailbox, folder);
+
+        if (option_verbose > 2)
+                ast_verbose(VERBOSE_PREFIX_3 "Message check requested for mailbox %s/folder %s but voicemail not loaded.", mailbox, folder);
+
 	return 0;
 }
 
+
 int ast_app_messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
 {
-	DIR *dir;
-	struct dirent *de;
-	char fn[256];
-	char tmp[256]="";
-	char *mb, *cur;
-	char *context;
-	int ret;
 	if (newmsgs)
 		*newmsgs = 0;
 	if (oldmsgs)
 		*oldmsgs = 0;
-	/* If no mailbox, return immediately */
-	if (ast_strlen_zero(mailbox))
-		return 0;
-	if (strchr(mailbox, ',')) {
-		int tmpnew, tmpold;
-		strncpy(tmp, mailbox, sizeof(tmp) - 1);
-		mb = tmp;
-		ret = 0;
-		while((cur = strsep(&mb, ", "))) {
-			if (!ast_strlen_zero(cur)) {
-				if (ast_app_messagecount(cur, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
-					return -1;
-				else {
-					if (newmsgs)
-						*newmsgs += tmpnew; 
-					if (oldmsgs)
-						*oldmsgs += tmpold;
-				}
-			}
-		}
-		return 0;
-	}
-	strncpy(tmp, mailbox, sizeof(tmp) - 1);
-	context = strchr(tmp, '@');
-	if (context) {
-		*context = '\0';
-		context++;
-	} else
-		context = "default";
-	if (newmsgs) {
-		snprintf(fn, sizeof(fn), "%s/voicemail/%s/%s/INBOX", (char *)ast_config_AST_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/voicemail/%s/%s/Old", (char *)ast_config_AST_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 (ast_messagecount_func)
+		return ast_messagecount_func(mailbox, newmsgs, oldmsgs);
+
+        if (option_verbose > 2)
+                ast_verbose(VERBOSE_PREFIX_3 "Message count requested for mailbox %s but voicemail not loaded.", mailbox);
+
 	return 0;
 }
 




More information about the svn-commits mailing list