From 77160b6f1040bcde69e83fc53084acbd07202480 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Thu, 28 Aug 2008 05:02:18 +0000 Subject: [PATCH] merge voicemail_3_improve_storage_dir.diff patch from MODAPP-133 allows the "storage-dir" parameter to be set on a per-user basis 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 git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9375 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../mod_voicemail/mod_voicemail.c | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/src/mod/applications/mod_voicemail/mod_voicemail.c b/src/mod/applications/mod_voicemail/mod_voicemail.c index f284d6885b..b1811ab390 100644 --- a/src/mod/applications/mod_voicemail/mod_voicemail.c +++ b/src/mod/applications/mod_voicemail/mod_voicemail.c @@ -1336,6 +1336,7 @@ static void voicemail_check_main(switch_core_session_t *session, const char *pro 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 @@ static void voicemail_check_main(switch_core_session_t *session, const char *pro 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 @@ static void voicemail_check_main(switch_core_session_t *session, const char *pro 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 @@ static void deliver_vm(vm_profile_t *profile, 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 @@ static void deliver_vm(vm_profile_t *profile, } } - - 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 @@ static switch_status_t voicemail_leave_main(switch_core_session_t *session, cons 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 @@ static switch_status_t voicemail_leave_main(switch_core_session_t *session, cons 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 @@ static switch_status_t voicemail_leave_main(switch_core_session_t *session, cons } 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 @@ static switch_status_t voicemail_leave_main(switch_core_session_t *session, cons } } + 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 @@ SWITCH_STANDARD_APP(voicemail_function) 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])));