[Freeswitch-svn] [commit] r9375 - freeswitch/trunk/src/mod/applications/mod_voicemail

Freeswitch SVN mikej at freeswitch.org
Thu Aug 28 01:02:18 EDT 2008


Author: mikej
Date: Thu Aug 28 01:02:18 2008
New Revision: 9375

Modified:
   freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c

Log:
merge voicemail_3_improve_storage_dir.diff  patch from MODAPP-133

allows the "storage-dir" parameter to be set on a per-user basis 
  <param name="storage-dir" value="/path/to/storage" /> 

prevents mod_voicemail to always create recursively SWITCH_GLOBAL_dirs.storage_dir. 
That may be useless when the old storage-dir (or the new per user i have introduced) is used. 
In fact, the directory is anyway always checked and maked, if necessary 


Modified: freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	Thu Aug 28 01:02:18 2008
@@ -1336,6 +1336,7 @@
 	int total_saved_urgent_messages = 0;
 	int heard_auto_saved = 0, heard_auto_new = 0;
 	char *vm_email = NULL;
+	char *vm_storage_dir = NULL;
 	char global_buf[2] = "";
 	switch_input_args_t args = { 0 };
 	const char *caller_id_name = NULL;
@@ -1739,6 +1740,8 @@
 						thepass = val;
 					} else if (!strcasecmp(var, "vm-mailto")) {
 						vm_email = switch_core_session_strdup(session, val);
+					} else if (!strcasecmp(var, "storage-dir")) {
+						vm_storage_dir = switch_core_session_strdup(session, val);
 					} else if (!switch_strlen_zero(cbt.password) && !thepass) {
 						thepass = cbt.password;
 					}
@@ -1749,13 +1752,15 @@
 				if (auth || !thepass || (thepass && mypass && !strcmp(thepass, mypass)) || 
 					(!switch_strlen_zero(cbt.password) && !strcmp(cbt.password, mypass))) {
 					if (!dir_path) {
-						if (switch_strlen_zero(profile->storage_dir)) {
+						if (!switch_strlen_zero(vm_storage_dir)) {
+							dir_path = switch_core_session_sprintf(session, "%s%s%s", vm_storage_dir, SWITCH_PATH_SEPARATOR, myid);
+						} else if ( !switch_strlen_zero(profile->storage_dir) ) {
+							dir_path = switch_core_session_sprintf(session, "%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR, myid);
+						} else {
 							dir_path = switch_core_session_sprintf(session, "%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir,
 																   SWITCH_PATH_SEPARATOR,
 																   SWITCH_PATH_SEPARATOR,
 																   profile->name, SWITCH_PATH_SEPARATOR, domain_name, SWITCH_PATH_SEPARATOR, myid);
-						} else {
-							dir_path = switch_core_session_sprintf(session, "%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR, myid);
 						}
 
 						if (switch_dir_make_recursive(dir_path, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
@@ -1824,6 +1829,7 @@
 	int send_notify = 0;
 	int insert_db = 1;
 	int email_attach = 0;
+	char *vm_storage_dir = NULL;
 	char *myfolder = "inbox";
 	int priority = 3;
 	const char *tmp;
@@ -1879,13 +1885,14 @@
 		}
 	}
 
-
-	if (switch_strlen_zero(profile->storage_dir)) {
+	if (!switch_strlen_zero(vm_storage_dir)) {
+		dir_path = switch_mprintf("%s%s%s", vm_storage_dir, SWITCH_PATH_SEPARATOR, myid);
+	} else if (!switch_strlen_zero(profile->storage_dir)) {
+		dir_path = switch_mprintf("%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR, myid);
+	} else {
 		dir_path = switch_mprintf("%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir,
 								  SWITCH_PATH_SEPARATOR,
 								  SWITCH_PATH_SEPARATOR, profile->name, SWITCH_PATH_SEPARATOR, domain_name, SWITCH_PATH_SEPARATOR, myid);
-	} else {
-		dir_path = switch_mprintf("%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR, myid);
 	}
 
 	if (switch_dir_make_recursive(dir_path, SWITCH_DEFAULT_DIR_PERMS, pool) != SWITCH_STATUS_SUCCESS) {
@@ -2257,6 +2264,7 @@
 	switch_size_t retsize;
 	switch_time_t ts = switch_timestamp_now();
 	char *dbuf = NULL;
+	char *vm_storage_dir = NULL;
 	int send_main = 0;
 	int send_notify = 0;
 	int insert_db = 1;
@@ -2280,19 +2288,6 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-	if (switch_strlen_zero(profile->storage_dir)) {
-		dir_path = switch_core_session_sprintf(session, "%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir,
-											   SWITCH_PATH_SEPARATOR,
-											   SWITCH_PATH_SEPARATOR, profile->name, SWITCH_PATH_SEPARATOR, domain_name, SWITCH_PATH_SEPARATOR, id);
-	} else {
-		dir_path = switch_core_session_sprintf(session, "%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR, id);
-	}
-
-	if (switch_dir_make_recursive(dir_path, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", dir_path);
-		goto end;
-	}
-
 	if (id) {
 		int ok = 1;
 		switch_event_t *params = NULL;
@@ -2318,6 +2313,8 @@
 					} else if (!strcasecmp(var, "vm-email-all-messages")) {
 						send_main = switch_true(val);
 						send_mail++;
+					} else if (!strcasecmp(var, "storage-dir")) {
+						vm_storage_dir = switch_core_session_strdup(session, val);
 					} else if (!strcasecmp(var, "vm-notify-email-all-messages")) {
 						send_notify = switch_true(val);
 						send_mail++;
@@ -2367,6 +2364,21 @@
 		}
 	}
 
+	if (!switch_strlen_zero(vm_storage_dir)) {
+		dir_path = switch_core_session_sprintf(session, "%s%s%s", vm_storage_dir, SWITCH_PATH_SEPARATOR, id);
+	} else if (!switch_strlen_zero(profile->storage_dir)) {
+		dir_path = switch_core_session_sprintf(session, "%s%s%s", profile->storage_dir, SWITCH_PATH_SEPARATOR, id);
+	} else {
+		dir_path = switch_core_session_sprintf(session, "%s%svoicemail%s%s%s%s%s%s", SWITCH_GLOBAL_dirs.storage_dir,
+											   SWITCH_PATH_SEPARATOR,
+											   SWITCH_PATH_SEPARATOR, profile->name, SWITCH_PATH_SEPARATOR, domain_name, SWITCH_PATH_SEPARATOR, id);
+	}
+
+	if (switch_dir_make_recursive(dir_path, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", dir_path);
+		goto end;
+	}
+
 	switch_snprintf(sql, sizeof(sql), "select * from voicemail_prefs where username='%s' and domain='%s'", id, domain_name);
 	vm_execute_sql_callback(profile, profile->mutex, sql, prefs_callback, &cbt);
 
@@ -2524,12 +2536,6 @@
 	int x = 0, check = 0, auth = 0;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 
-	if (switch_dir_make_recursive(SWITCH_GLOBAL_dirs.storage_dir, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) !=
-		SWITCH_STATUS_SUCCESS) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", SWITCH_GLOBAL_dirs.storage_dir);
-		return;
-	}
-
 	if (!switch_strlen_zero(data)) {
 		mydata = switch_core_session_strdup(session, data);
 		argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));



More information about the Freeswitch-svn mailing list