[Asterisk-cvs] asterisk/apps app_voicemail.c,1.193,1.194

markster at lists.digium.com markster at lists.digium.com
Sun Jan 9 22:13:59 CST 2005


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

Modified Files:
	app_voicemail.c 
Log Message:
Fix voicemail symlinks (bug #3024)


Index: app_voicemail.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_voicemail.c,v
retrieving revision 1.193
retrieving revision 1.194
diff -u -d -r1.193 -r1.194
--- app_voicemail.c	8 Jan 2005 19:00:46 -0000	1.193
+++ app_voicemail.c	10 Jan 2005 04:18:18 -0000	1.194
@@ -63,8 +63,6 @@
 
 #define MAXMSG 100
 
-#define VM_SPOOL_DIR AST_SPOOL_DIR "/vm"
-
 #define BASEMAXINLINE 256
 #define BASELINELEN 72
 #define BASEMAXINLINE 256
@@ -210,6 +208,8 @@
 #define DELETE(a,b,c) (vm_delete(c))
 #endif
 
+static char VM_SPOOL_DIR[AST_CONFIG_MAX_PATH];
+
 static char ext_pass_cmd[128];
 
 static char *tdesc = "Comedian Mail (Voicemail System)";
@@ -633,7 +633,7 @@
 
 static int make_dir(char *dest, int len, char *context, char *ext, char *mailbox)
 {
-	return snprintf(dest, len, "%s/voicemail/%s/%s/%s", (char *)ast_config_AST_SPOOL_DIR,context, ext, mailbox);
+	return snprintf(dest, len, "%s%s/%s/%s", VM_SPOOL_DIR, context, ext, mailbox);
 }
 
 static int make_file(char *dest, int len, char *dir, int num)
@@ -654,7 +654,6 @@
 	SQLSMALLINT colcount=0;
 	SQLHSTMT stmt;
 	char sql[256];
-	char rdir[256];
 	char fmt[80]="";
 	char *c;
 	char coltitle[256];
@@ -672,10 +671,6 @@
 	odbc_obj *obj;
 	obj = fetch_odbc_obj(odbc_database);
 	if (obj) {
-		if (dir[0] != '/') {
-			snprintf(rdir, sizeof(rdir), "%s/%s", ast_config_AST_SPOOL_DIR, dir);
-			dir = rdir;
-		}
 		strncpy(fmt, vmfmts, sizeof(fmt) - 1);
 		c = strchr(fmt, '|');
 		if (c)
@@ -809,12 +804,7 @@
 	char fn[256];
 	char full_fn[256];
 	char msgnums[80];
-	char rdir[256];
 	
-	if (dir[0] != '/') {
-		snprintf(rdir, sizeof(rdir), "%s/%s", ast_config_AST_SPOOL_DIR, dir);
-		dir = rdir;
-	}
 	if (msgnum > -1) {
 		snprintf(msgnums, sizeof(msgnums), "%d", msgnum);
 		make_file(fn, sizeof(fn), dir, msgnum);
@@ -833,16 +823,11 @@
 	SQLLEN rowcount=0;
 	SQLHSTMT stmt;
 	char sql[256];
-	char rdir[256];
 	char rowdata[20];
 	
 	odbc_obj *obj;
 	obj = fetch_odbc_obj(odbc_database);
 	if (obj) {
-		if (dir[0] != '/') {
-			snprintf(rdir, sizeof(rdir), "%s/%s", ast_config_AST_SPOOL_DIR, dir);
-			dir = rdir;
-		}
 		res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
 		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
 			ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
@@ -896,17 +881,12 @@
 	SQLLEN rowcount=0;
 	SQLHSTMT stmt;
 	char sql[256];
-	char rdir[256];
 	char rowdata[20];
 	char msgnums[20];
 	
 	odbc_obj *obj;
 	obj = fetch_odbc_obj(odbc_database);
 	if (obj) {
-		if (dir[0] != '/') {
-			snprintf(rdir, sizeof(rdir), "%s/%s", ast_config_AST_SPOOL_DIR, dir);
-			dir = rdir;
-		}
 		snprintf(msgnums, sizeof(msgnums), "%d", msgnum);
 		res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
 		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
@@ -967,15 +947,10 @@
 	SQLHSTMT stmt;
 	char sql[256];
 	char msgnums[20];
-	char rdir[256];
 	
 	odbc_obj *obj;
 	obj = fetch_odbc_obj(odbc_database);
 	if (obj) {
-		if (sdir[0] != '/') {
-			snprintf(rdir, sizeof(rdir), "%s/%s", ast_config_AST_SPOOL_DIR, sdir);
-			sdir = rdir;
-		}
 		snprintf(msgnums, sizeof(msgnums), "%d", smsg);
 		res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
 		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
@@ -1018,21 +993,11 @@
 	char sql[256];
 	char msgnums[20];
 	char msgnumd[20];
-	char rsdir[256];
-	char rddir[256];
 	odbc_obj *obj;
 
 	delete_file(ddir, dmsg);
 	obj = fetch_odbc_obj(odbc_database);
 	if (obj) {
-		if (ddir[0] != '/') {
-			snprintf(rddir, sizeof(rddir), "%s/%s", ast_config_AST_SPOOL_DIR, ddir);
-			ddir = rddir;
-		}
-		if (sdir[0] != '/') {
-			snprintf(rsdir, sizeof(rsdir), "%s/%s", ast_config_AST_SPOOL_DIR, sdir);
-			sdir = rsdir;
-		}
 		snprintf(msgnums, sizeof(msgnums), "%d", smsg);
 		snprintf(msgnumd, sizeof(msgnumd), "%d", dmsg);
 		res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
@@ -1081,7 +1046,6 @@
 	SQLHSTMT stmt;
 	SQLINTEGER len;
 	char sql[256];
-	char rdir[256];
 	char msgnums[20];
 	char fn[256];
 	char full_fn[256];
@@ -1095,10 +1059,6 @@
 	delete_file(dir, msgnum);
 	obj = fetch_odbc_obj(odbc_database);
 	if (obj) {
-		if (dir[0] != '/') {
-			snprintf(rdir, sizeof(rdir), "%s/%s", ast_config_AST_SPOOL_DIR, dir);
-			dir = rdir;
-		}
 		strncpy(fmt, vmfmts, sizeof(fmt) - 1);
 		c = strchr(fmt, '|');
 		if (c)
@@ -1199,21 +1159,11 @@
 	char sql[256];
 	char msgnums[20];
 	char msgnumd[20];
-	char rsdir[256];
-	char rddir[256];
 	odbc_obj *obj;
 
 	delete_file(ddir, dmsg);
 	obj = fetch_odbc_obj(odbc_database);
 	if (obj) {
-		if (ddir[0] != '/') {
-			snprintf(rddir, sizeof(rddir), "%s/%s", ast_config_AST_SPOOL_DIR, ddir);
-			ddir = rddir;
-		}
-		if (sdir[0] != '/') {
-			snprintf(rsdir, sizeof(rsdir), "%s/%s", ast_config_AST_SPOOL_DIR, sdir);
-			sdir = rsdir;
-		}
 		snprintf(msgnums, sizeof(msgnums), "%d", smsg);
 		snprintf(msgnumd, sizeof(msgnumd), "%d", dmsg);
 		res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
@@ -1766,7 +1716,7 @@
 {
 	int res;
 	char fn[256];
-	snprintf(fn, sizeof(fn), "voicemail/%s/%s/greet", context, ext);
+	snprintf(fn, sizeof(fn), "%s%s/%s/greet", VM_SPOOL_DIR, context, ext);
 	RETRIEVE(fn, -1);
 	if (ast_fileexists(fn, NULL, NULL) > 0) {
 		res = ast_streamfile(chan, fn, chan->language);
@@ -1874,7 +1824,7 @@
 		context++;
 	} else
 		context = "default";
-	snprintf(fn, sizeof(fn), "%s/voicemail/%s/%s/%s", (char *)ast_config_AST_SPOOL_DIR, context, tmp, folder);
+	snprintf(fn, sizeof(fn), "%s/%s/%s/%s", VM_SPOOL_DIR, context, tmp, folder);
 	dir = opendir(fn);
 	if (!dir)
 		return 0;
@@ -1931,7 +1881,7 @@
 	} else
 		context = "default";
 	if (newmsgs) {
-		snprintf(fn, sizeof(fn), "%s/voicemail/%s/%s/INBOX", (char *)ast_config_AST_SPOOL_DIR, context, tmp);
+		snprintf(fn, sizeof(fn), "%s/%s/%s/INBOX", VM_SPOOL_DIR, context, tmp);
 		dir = opendir(fn);
 		if (dir) {
 			while ((de = readdir(dir))) {
@@ -1944,7 +1894,7 @@
 		}
 	}
 	if (oldmsgs) {
-		snprintf(fn, sizeof(fn), "%s/voicemail/%s/%s/Old", (char *)ast_config_AST_SPOOL_DIR, context, tmp);
+		snprintf(fn, sizeof(fn), "%s/%s/%s/Old", VM_SPOOL_DIR, context, tmp);
 		dir = opendir(fn);
 		if (dir) {
 			while ((de = readdir(dir))) {
@@ -2066,10 +2016,10 @@
 		else
 			strncpy(ext_context, vmu->context, sizeof(ext_context) - 1);		
 		if (busy)
-			snprintf(prefile, sizeof(prefile), "voicemail/%s/%s/busy", vmu->context, ext);
+			snprintf(prefile, sizeof(prefile), "%s%s/%s/busy", VM_SPOOL_DIR, vmu->context, ext);
 		else if (unavail)
-			snprintf(prefile, sizeof(prefile), "voicemail/%s/%s/unavail", vmu->context, ext);
-		snprintf(tempfile, sizeof(tempfile), "voicemail/%s/%s/temp", vmu->context, ext);
+			snprintf(prefile, sizeof(prefile), "%s%s/%s/unavail", VM_SPOOL_DIR, vmu->context, ext);
+		snprintf(tempfile, sizeof(tempfile), "%s%s/%s/temp", VM_SPOOL_DIR, vmu->context, ext);
 		RETRIEVE(tempfile, -1);
 		if (ast_fileexists(tempfile, NULL, NULL) > 0)
 			strncpy(prefile, tempfile, sizeof(prefile) - 1);
@@ -3105,7 +3055,7 @@
 				/* if (ast_play_and_wait(chan, "vm-savedto"))
 					break;
 				*/
-				snprintf(todir, sizeof(todir), "%s/voicemail/%s/%s/INBOX",  (char *)ast_config_AST_SPOOL_DIR, vmtmp->context, vmtmp->mailbox);
+				snprintf(todir, sizeof(todir), "%s%s/%s/INBOX",  VM_SPOOL_DIR, vmtmp->context, vmtmp->mailbox);
 				snprintf(sys, sizeof(sys), "mkdir -p %s\n", todir);
 				snprintf(ext_context, sizeof(ext_context), "%s@%s", vmtmp->mailbox, vmtmp->context);
 				ast_log(LOG_DEBUG, "%s", sys);
@@ -3297,7 +3247,7 @@
 		}
 		if (i != MAX_NUM_CID_CONTEXTS){ /* internal context? */
 			if (!res) {
-				snprintf(prefile, sizeof(prefile), "voicemail/%s/%s/greet", context, callerid);
+				snprintf(prefile, sizeof(prefile), "%s%s/%s/greet", VM_SPOOL_DIR, context, callerid);
 				if (!ast_strlen_zero(prefile)) {
 				/* See if we can find a recorded name for this person instead of their extension number */
 					if (ast_fileexists(prefile, NULL, NULL) > 0) {
@@ -4115,7 +4065,7 @@
 
 	/* If forcename is set, have the user record their name */	
 	if (ast_test_flag(vmu, VM_FORCENAME)) {
-		snprintf(prefile,sizeof(prefile),"voicemail/%s/%s/greet",vmu->context, vms->username);
+		snprintf(prefile,sizeof(prefile), "%s%s/%s/greet", VM_SPOOL_DIR, vmu->context, vms->username);
 		cmd = play_record_review(chan,"vm-rec-name",prefile, maxgreet, fmtc, 0, vmu, &duration);
 		if (cmd < 0 || cmd == 't' || cmd == '#')
 			return cmd;
@@ -4123,11 +4073,11 @@
 
 	/* If forcegreetings is set, have the user record their greetings */
 	if (ast_test_flag(vmu, VM_FORCEGREET)) {
-		snprintf(prefile,sizeof(prefile),"voicemail/%s/%s/unavail",vmu->context, vms->username);
+		snprintf(prefile,sizeof(prefile), "%s%s/%s/unavail", VM_SPOOL_DIR, vmu->context, vms->username);
 		cmd = play_record_review(chan,"vm-rec-unv",prefile, maxgreet, fmtc, 0, vmu, &duration);
 		if (cmd < 0 || cmd == 't' || cmd == '#')
 			return cmd;
-		snprintf(prefile,sizeof(prefile),"voicemail/%s/%s/busy",vmu->context, vms->username);
+		snprintf(prefile,sizeof(prefile), "%s%s/%s/busy", VM_SPOOL_DIR, vmu->context, vms->username);
 		cmd = play_record_review(chan,"vm-rec-busy",prefile, maxgreet, fmtc, 0, vmu, &duration);
 		if (cmd < 0 || cmd == 't' || cmd == '#')
 			return cmd;
@@ -4161,15 +4111,15 @@
 			retries = 0;
 		switch (cmd) {
 		case '1':
-			snprintf(prefile,sizeof(prefile),"voicemail/%s/%s/unavail",vmu->context, vms->username);
+			snprintf(prefile,sizeof(prefile), "%s%s/%s/unavail", VM_SPOOL_DIR, vmu->context, vms->username);
 			cmd = play_record_review(chan,"vm-rec-unv",prefile, maxgreet, fmtc, 0, vmu, &duration);
 			break;
 		case '2': 
-			snprintf(prefile,sizeof(prefile),"voicemail/%s/%s/busy",vmu->context, vms->username);
+			snprintf(prefile,sizeof(prefile), "%s%s/%s/busy", VM_SPOOL_DIR, vmu->context, vms->username);
 			cmd = play_record_review(chan,"vm-rec-busy",prefile, maxgreet, fmtc, 0, vmu, &duration);
 			break;
 		case '3': 
-			snprintf(prefile,sizeof(prefile),"voicemail/%s/%s/greet",vmu->context, vms->username);
+			snprintf(prefile,sizeof(prefile), "%s%s/%s/greet", VM_SPOOL_DIR, vmu->context, vms->username);
 			cmd = play_record_review(chan,"vm-rec-name",prefile, maxgreet, fmtc, 0, vmu, &duration);
 			break;
 		case '4': 
@@ -4251,7 +4201,7 @@
 		bytes += adsi_voice_mode(buf + bytes, 0);
 		adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY);
 	}
-	snprintf(prefile,sizeof(prefile),"voicemail/%s/%s/temp",vmu->context, vms->username);
+	snprintf(prefile,sizeof(prefile), "%s%s/%s/temp", VM_SPOOL_DIR, vmu->context, vms->username);
 	while((cmd >= 0) && (cmd != 't')) {
 		if (cmd)
 			retries = 0;
@@ -4586,9 +4536,9 @@
 		/* Set language from config to override channel language */
 		if (vmu->language && !ast_strlen_zero(vmu->language))
 			strncpy(chan->language, vmu->language, sizeof(chan->language)-1);
-		snprintf(vms.curdir, sizeof(vms.curdir), "%s/voicemail/%s", (char *)ast_config_AST_SPOOL_DIR, vmu->context);
+		snprintf(vms.curdir, sizeof(vms.curdir), "%s/%s", VM_SPOOL_DIR, vmu->context);
 		mkdir(vms.curdir, 0700);
-		snprintf(vms.curdir, sizeof(vms.curdir), "%s/voicemail/%s/%s", (char *)ast_config_AST_SPOOL_DIR, vmu->context, vms.username);
+		snprintf(vms.curdir, sizeof(vms.curdir), "%s/%s/%s", VM_SPOOL_DIR, vmu->context, vms.username);
 		mkdir(vms.curdir, 0700);
 		/* Retrieve old and new message counts */
 		open_mailbox(&vms, vmu, 1);
@@ -5556,6 +5506,9 @@
 	ast_cli_register(&show_voicemail_users_cli);
 	ast_cli_register(&show_voicemail_zones_cli);
 
+	/* 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);
 
 	return res;




More information about the svn-commits mailing list