2007-10-12 03:28:59 +00:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
* Copyright (C) 2005/2006, Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
*
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Anthony Minessale II <anthmct@yahoo.com>
|
2007-10-23 14:45:22 +00:00
|
|
|
* Bret McDanel <trixter AT 0xdecafbad.com>
|
2007-10-12 03:28:59 +00:00
|
|
|
*
|
|
|
|
* mod_voicemail.c -- Voicemail Module
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <switch.h>
|
|
|
|
|
|
|
|
#ifdef SWITCH_HAVE_ODBC
|
|
|
|
#include <switch_odbc.h>
|
|
|
|
#endif
|
|
|
|
|
2007-10-12 20:14:41 +00:00
|
|
|
#ifdef _MSC_VER /* compilers are stupid sometimes */
|
|
|
|
#define TRY_CODE(code) for(;;) {status = code; if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;}
|
|
|
|
#else
|
2007-11-02 21:58:04 +00:00
|
|
|
#define TRY_CODE(code) do { status = code; if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) { goto end; } break;} while(status)
|
2007-10-12 20:14:41 +00:00
|
|
|
#endif
|
2007-10-12 03:28:59 +00:00
|
|
|
|
|
|
|
SWITCH_MODULE_LOAD_FUNCTION(mod_voicemail_load);
|
|
|
|
SWITCH_MODULE_DEFINITION(mod_voicemail, mod_voicemail_load, NULL, NULL);
|
|
|
|
|
|
|
|
static struct {
|
|
|
|
switch_hash_t *profile_hash;
|
|
|
|
int debug;
|
|
|
|
switch_memory_pool_t *pool;
|
|
|
|
} globals;
|
|
|
|
|
|
|
|
struct vm_profile {
|
|
|
|
char *name;
|
|
|
|
char *dbname;
|
|
|
|
char *odbc_dsn;
|
|
|
|
char *odbc_user;
|
|
|
|
char *odbc_pass;
|
|
|
|
char terminator_key[2];
|
|
|
|
char play_new_messages_key[2];
|
|
|
|
char play_saved_messages_key[2];
|
|
|
|
|
|
|
|
char main_menu_key[2];
|
|
|
|
char config_menu_key[2];
|
|
|
|
char record_greeting_key[2];
|
|
|
|
char choose_greeting_key[2];
|
|
|
|
char record_name_key[2];
|
|
|
|
|
|
|
|
char record_file_key[2];
|
|
|
|
char listen_file_key[2];
|
|
|
|
char save_file_key[2];
|
|
|
|
char delete_file_key[2];
|
|
|
|
char undelete_file_key[2];
|
2007-10-12 13:31:12 +00:00
|
|
|
char email_key[2];
|
2007-10-20 00:24:03 +00:00
|
|
|
char callback_key[2];
|
2007-10-12 22:08:30 +00:00
|
|
|
char pause_key[2];
|
|
|
|
char restart_key[2];
|
|
|
|
char ff_key[2];
|
|
|
|
char rew_key[2];
|
|
|
|
char urgent_key[2];
|
2007-11-02 21:58:04 +00:00
|
|
|
char operator_key[2];
|
2007-10-12 13:31:12 +00:00
|
|
|
char file_ext[10];
|
2007-11-02 21:58:04 +00:00
|
|
|
char *operator_ext;
|
2007-10-12 03:28:59 +00:00
|
|
|
char *tone_spec;
|
2007-10-20 00:09:41 +00:00
|
|
|
char *storage_dir;
|
2007-10-20 00:24:03 +00:00
|
|
|
char *callback_dialplan;
|
|
|
|
char *callback_context;
|
2007-10-23 14:45:22 +00:00
|
|
|
char *email_body;
|
|
|
|
char *email_headers;
|
2007-11-29 01:05:05 +00:00
|
|
|
char *web_head;
|
|
|
|
char *web_tail;
|
2007-10-23 14:45:22 +00:00
|
|
|
char *email_from;
|
|
|
|
char *date_fmt;
|
2007-10-12 03:28:59 +00:00
|
|
|
uint32_t digit_timeout;
|
|
|
|
uint32_t max_login_attempts;
|
|
|
|
uint32_t max_record_len;
|
|
|
|
switch_mutex_t *mutex;
|
2007-11-24 21:09:52 +00:00
|
|
|
uint32_t record_threshold;
|
|
|
|
uint32_t record_silence_hits;
|
2007-11-26 23:41:00 +00:00
|
|
|
uint32_t record_sample_rate;
|
2007-10-12 03:28:59 +00:00
|
|
|
#ifdef SWITCH_HAVE_ODBC
|
|
|
|
switch_odbc_handle_t *master_odbc;
|
|
|
|
#else
|
|
|
|
void *filler1;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
typedef struct vm_profile vm_profile_t;
|
|
|
|
|
|
|
|
static switch_status_t vm_execute_sql(vm_profile_t *profile, char *sql, switch_mutex_t *mutex)
|
|
|
|
{
|
|
|
|
switch_core_db_t *db;
|
|
|
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
if (mutex) {
|
|
|
|
switch_mutex_lock(mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SWITCH_HAVE_ODBC
|
|
|
|
if (profile->odbc_dsn) {
|
|
|
|
SQLHSTMT stmt;
|
|
|
|
if (switch_odbc_handle_exec(profile->master_odbc, sql, &stmt) != SWITCH_ODBC_SUCCESS) {
|
|
|
|
char *err_str;
|
|
|
|
err_str = switch_odbc_handle_get_error(profile->master_odbc, stmt);
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
|
|
|
|
switch_safe_free(err_str);
|
|
|
|
status = SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
if (!(db = switch_core_db_open_file(profile->dbname))) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
|
|
|
|
status = SWITCH_STATUS_FALSE;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = switch_core_db_persistant_execute(db, sql, 25);
|
|
|
|
switch_core_db_close(db);
|
|
|
|
|
|
|
|
#ifdef SWITCH_HAVE_ODBC
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
if (mutex) {
|
|
|
|
switch_mutex_unlock(mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static switch_bool_t vm_execute_sql_callback(vm_profile_t *profile,
|
2007-10-23 15:09:29 +00:00
|
|
|
switch_mutex_t *mutex,
|
|
|
|
char *sql,
|
|
|
|
switch_core_db_callback_func_t callback,
|
|
|
|
void *pdata)
|
2007-10-12 03:28:59 +00:00
|
|
|
{
|
|
|
|
switch_bool_t ret = SWITCH_FALSE;
|
|
|
|
switch_core_db_t *db;
|
|
|
|
char *errmsg = NULL;
|
|
|
|
|
|
|
|
if (mutex) {
|
|
|
|
switch_mutex_lock(mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef SWITCH_HAVE_ODBC
|
|
|
|
if (profile->odbc_dsn) {
|
|
|
|
switch_odbc_handle_callback_exec(profile->master_odbc, sql, callback, pdata);
|
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!(db = switch_core_db_open_file(profile->dbname))) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", profile->dbname);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
switch_core_db_exec(db, sql, callback, pdata, &errmsg);
|
|
|
|
|
|
|
|
if (errmsg) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
|
|
|
|
free(errmsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (db) {
|
|
|
|
switch_core_db_close(db);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SWITCH_HAVE_ODBC
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
|
|
|
if (mutex) {
|
|
|
|
switch_mutex_unlock(mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char vm_sql[] =
|
|
|
|
"CREATE TABLE voicemail_data (\n"
|
2007-11-26 23:41:00 +00:00
|
|
|
" created_epoch INTEGER,\n"
|
|
|
|
" read_epoch INTEGER,\n"
|
2007-10-12 03:28:59 +00:00
|
|
|
" user VARCHAR(255),\n"
|
|
|
|
" domain VARCHAR(255),\n"
|
|
|
|
" uuid VARCHAR(255),\n"
|
|
|
|
" cid_name VARCHAR(255),\n"
|
|
|
|
" cid_number VARCHAR(255),\n"
|
|
|
|
" in_folder VARCHAR(255),\n"
|
|
|
|
" file_path VARCHAR(255),\n"
|
2007-11-26 23:41:00 +00:00
|
|
|
" message_len INTEGER,\n"
|
2007-10-12 22:08:30 +00:00
|
|
|
" flags VARCHAR(255),\n"
|
|
|
|
" read_flags VARCHAR(255)\n"
|
2007-10-12 03:28:59 +00:00
|
|
|
");\n";
|
|
|
|
|
|
|
|
|
|
|
|
static char vm_pref_sql[] =
|
|
|
|
"CREATE TABLE voicemail_prefs (\n"
|
|
|
|
" user VARCHAR(255),\n"
|
|
|
|
" domain VARCHAR(255),\n"
|
|
|
|
" name_path VARCHAR(255),\n"
|
|
|
|
" greeting_path VARCHAR(255)\n"
|
|
|
|
");\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static switch_status_t load_config(void)
|
|
|
|
{
|
|
|
|
char *cf = "voicemail.conf";
|
|
|
|
vm_profile_t *profile = NULL;
|
2007-10-23 14:45:22 +00:00
|
|
|
switch_xml_t cfg, xml, settings, param, x_profile, x_profiles, x_email;
|
2007-10-12 03:28:59 +00:00
|
|
|
|
|
|
|
memset(&globals, 0, sizeof(globals));
|
|
|
|
switch_core_new_memory_pool(&globals.pool);
|
|
|
|
switch_core_hash_init(&globals.profile_hash, globals.pool);
|
|
|
|
|
|
|
|
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
|
|
|
|
return SWITCH_STATUS_TERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((settings = switch_xml_child(cfg, "settings"))) {
|
|
|
|
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
|
|
|
|
char *var = (char *) switch_xml_attr_soft(param, "name");
|
|
|
|
char *val = (char *) switch_xml_attr_soft(param, "value");
|
|
|
|
|
|
|
|
if (!strcasecmp(var, "debug")) {
|
|
|
|
globals.debug = atoi(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(x_profiles = switch_xml_child(cfg, "profiles"))) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (x_profile = switch_xml_child(x_profiles, "profile"); x_profile; x_profile = x_profile->next) {
|
|
|
|
char *name = (char *) switch_xml_attr_soft(x_profile, "name");
|
2007-10-12 16:49:14 +00:00
|
|
|
char *odbc_dsn = NULL, *odbc_user = NULL, *odbc_pass = NULL;
|
2007-10-12 03:28:59 +00:00
|
|
|
char *terminator_key = "#";
|
|
|
|
char *play_new_messages_key = "1";
|
|
|
|
char *play_saved_messages_key = "2";
|
|
|
|
|
|
|
|
char *main_menu_key = "0";
|
|
|
|
char *config_menu_key = "5";
|
|
|
|
char *record_greeting_key = "1";
|
|
|
|
char *choose_greeting_key = "2";
|
|
|
|
char *record_name_key = "3";
|
|
|
|
|
|
|
|
char *record_file_key = "3";
|
|
|
|
char *listen_file_key = "1";
|
|
|
|
char *save_file_key = "2";
|
|
|
|
char *delete_file_key = "7";
|
|
|
|
char *undelete_file_key = "8";
|
2007-10-12 13:31:12 +00:00
|
|
|
char *email_key = "4";
|
2007-10-20 00:24:03 +00:00
|
|
|
char *callback_key = "5";
|
2007-10-12 22:08:30 +00:00
|
|
|
char *pause_key = "0";
|
|
|
|
char *restart_key = "1";
|
|
|
|
char *ff_key = "6";
|
|
|
|
char *rew_key = "4";
|
|
|
|
char *urgent_key = "*";
|
2007-11-02 21:58:04 +00:00
|
|
|
char *operator_key = "";
|
|
|
|
char *operator_ext = "";
|
2007-10-12 03:28:59 +00:00
|
|
|
char *tone_spec = "%(1000, 0, 640)";
|
2007-10-12 13:31:12 +00:00
|
|
|
char *file_ext = "wav";
|
2007-10-20 00:09:41 +00:00
|
|
|
char *storage_dir = "";
|
2007-10-20 00:24:03 +00:00
|
|
|
char *callback_dialplan = "XML";
|
|
|
|
char *callback_context = "default";
|
2007-11-27 01:15:13 +00:00
|
|
|
char *email_body = NULL;
|
|
|
|
char *email_headers = NULL;
|
2007-10-23 14:45:22 +00:00
|
|
|
char *email_from = "";
|
|
|
|
char *date_fmt = "%A, %B %d %Y, %I %M %p";
|
2007-11-29 01:05:05 +00:00
|
|
|
char *web_head = NULL;
|
|
|
|
char *web_tail = NULL;
|
2007-11-24 21:09:52 +00:00
|
|
|
uint32_t record_threshold = 200;
|
|
|
|
uint32_t record_silence_hits = 2;
|
2007-11-26 23:41:00 +00:00
|
|
|
uint32_t record_sample_rate = 0;
|
2007-10-12 03:28:59 +00:00
|
|
|
|
|
|
|
switch_core_db_t *db;
|
|
|
|
uint32_t timeout = 10000, max_login_attempts = 3, max_record_len = 300;
|
|
|
|
|
|
|
|
db = NULL;
|
2007-10-23 14:45:22 +00:00
|
|
|
|
|
|
|
if ((x_email = switch_xml_child(x_profile, "email"))) {
|
2007-11-27 01:15:13 +00:00
|
|
|
if ((param = switch_xml_child(x_email, "body"))) {
|
|
|
|
email_body = switch_core_strdup(globals.pool, param->txt);
|
2007-10-23 14:45:22 +00:00
|
|
|
}
|
|
|
|
|
2007-11-27 01:15:13 +00:00
|
|
|
if ((param = switch_xml_child(x_email, "headers"))) {
|
|
|
|
email_headers = switch_core_strdup(globals.pool, param->txt);
|
2007-10-23 14:45:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (param = switch_xml_child(x_email, "param"); param; param = param->next) {
|
|
|
|
char *var, *val;
|
|
|
|
|
|
|
|
var = (char *) switch_xml_attr_soft(param, "name");
|
|
|
|
val = (char *) switch_xml_attr_soft(param, "value");
|
|
|
|
|
|
|
|
if (!strcasecmp(var, "date-fmt") && !switch_strlen_zero(val)) {
|
|
|
|
date_fmt = val;
|
|
|
|
} else if (!strcasecmp(var, "email-from") && !switch_strlen_zero(val)) {
|
|
|
|
email_from = val;
|
2007-11-27 19:50:32 +00:00
|
|
|
} else if (!strcasecmp(var, "template-file") && !switch_strlen_zero(val)) {
|
|
|
|
switch_stream_handle_t stream = { 0 };
|
|
|
|
int fd;
|
|
|
|
char *dpath = NULL;
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
if (switch_is_file_path(val)) {
|
|
|
|
path = val;
|
|
|
|
} else {
|
|
|
|
dpath = switch_mprintf("%s%s%s",
|
|
|
|
SWITCH_GLOBAL_dirs.conf_dir,
|
|
|
|
SWITCH_PATH_SEPARATOR,
|
|
|
|
val);
|
|
|
|
path = dpath;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((fd = open(path, O_RDONLY)) > -1) {
|
|
|
|
char buf[2048];
|
|
|
|
SWITCH_STANDARD_STREAM(stream);
|
|
|
|
while(switch_fd_read_line(fd, buf, sizeof(buf))) {
|
|
|
|
stream.write_function(&stream, "%s", buf);
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
email_headers = stream.data;
|
|
|
|
if ((email_body = strstr(email_headers, "\n\n"))) {
|
|
|
|
*email_body = '\0';
|
|
|
|
email_body += 2;
|
|
|
|
} else if ((email_body = strstr(email_headers, "\r\n\r\n"))) {
|
|
|
|
*email_body = '\0';
|
|
|
|
email_body += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch_safe_free(dpath);
|
2007-10-23 14:45:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
for (param = switch_xml_child(x_profile, "param"); param; param = param->next) {
|
|
|
|
char *var, *val;
|
|
|
|
|
|
|
|
var = (char *) switch_xml_attr_soft(param, "name");
|
|
|
|
val = (char *) switch_xml_attr_soft(param, "value");
|
|
|
|
|
|
|
|
if (!strcasecmp(var, "terminator-key") && !switch_strlen_zero(val)) {
|
|
|
|
terminator_key = val;
|
2007-11-29 01:05:05 +00:00
|
|
|
} else if (!strcasecmp(var, "web-template-file") && !switch_strlen_zero(val)) {
|
|
|
|
switch_stream_handle_t stream = { 0 };
|
|
|
|
int fd;
|
|
|
|
char *dpath = NULL;
|
|
|
|
char *path;
|
|
|
|
|
|
|
|
if (switch_is_file_path(val)) {
|
|
|
|
path = val;
|
|
|
|
} else {
|
|
|
|
dpath = switch_mprintf("%s%s%s",
|
|
|
|
SWITCH_GLOBAL_dirs.conf_dir,
|
|
|
|
SWITCH_PATH_SEPARATOR,
|
|
|
|
val);
|
|
|
|
path = dpath;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((fd = open(path, O_RDONLY)) > -1) {
|
|
|
|
char buf[2048];
|
|
|
|
SWITCH_STANDARD_STREAM(stream);
|
|
|
|
while(switch_fd_read_line(fd, buf, sizeof(buf))) {
|
|
|
|
stream.write_function(&stream, "%s", buf);
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
web_head = stream.data;
|
|
|
|
if ((web_tail = strstr(web_head, "<!break>\n"))) {
|
|
|
|
*web_tail = '\0';
|
|
|
|
web_tail += 9;
|
|
|
|
} else if ((web_tail = strstr(web_head, "<!break>\r\n"))) {
|
|
|
|
*web_tail = '\0';
|
|
|
|
web_tail += 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch_safe_free(dpath);
|
2007-10-12 03:28:59 +00:00
|
|
|
} else if (!strcasecmp(var, "play-new-messages-key") && !switch_strlen_zero(val)) {
|
|
|
|
play_new_messages_key = val;
|
|
|
|
} else if (!strcasecmp(var, "play-saved-messages-key") && !switch_strlen_zero(val)) {
|
|
|
|
play_saved_messages_key = val;
|
|
|
|
} else if (!strcasecmp(var, "main-menu-key") && !switch_strlen_zero(val)) {
|
|
|
|
main_menu_key = val;
|
|
|
|
} else if (!strcasecmp(var, "config-menu-key") && !switch_strlen_zero(val)) {
|
|
|
|
config_menu_key = val;
|
|
|
|
} else if (!strcasecmp(var, "record-greeting-key") && !switch_strlen_zero(val)) {
|
|
|
|
record_greeting_key = val;
|
|
|
|
} else if (!strcasecmp(var, "choose-greeting-key") && !switch_strlen_zero(val)) {
|
|
|
|
choose_greeting_key = val;
|
|
|
|
} else if (!strcasecmp(var, "record-name-key") && !switch_strlen_zero(val)) {
|
|
|
|
record_name_key = val;
|
|
|
|
} else if (!strcasecmp(var, "listen-file-key") && !switch_strlen_zero(val)) {
|
|
|
|
listen_file_key = val;
|
|
|
|
} else if (!strcasecmp(var, "save-file-key") && !switch_strlen_zero(val)) {
|
|
|
|
save_file_key = val;
|
|
|
|
} else if (!strcasecmp(var, "delete-file-key") && !switch_strlen_zero(val)) {
|
|
|
|
delete_file_key = val;
|
|
|
|
} else if (!strcasecmp(var, "undelete-file-key") && !switch_strlen_zero(val)) {
|
|
|
|
undelete_file_key = val;
|
2007-10-12 13:31:12 +00:00
|
|
|
} else if (!strcasecmp(var, "email-key") && !switch_strlen_zero(val)) {
|
|
|
|
email_key = val;
|
2007-10-20 00:24:03 +00:00
|
|
|
} else if (!strcasecmp(var, "callback-key") && !switch_strlen_zero(val)) {
|
|
|
|
callback_key = val;
|
2007-10-12 22:08:30 +00:00
|
|
|
} else if (!strcasecmp(var, "pause-key") && !switch_strlen_zero(val)) {
|
|
|
|
pause_key = val;
|
|
|
|
} else if (!strcasecmp(var, "restart-key") && !switch_strlen_zero(val)) {
|
|
|
|
restart_key = val;
|
|
|
|
} else if (!strcasecmp(var, "ff-key") && !switch_strlen_zero(val)) {
|
|
|
|
ff_key = val;
|
|
|
|
} else if (!strcasecmp(var, "rew-key") && !switch_strlen_zero(val)) {
|
|
|
|
rew_key = val;
|
|
|
|
} else if (!strcasecmp(var, "urgent-key") && !switch_strlen_zero(val)) {
|
|
|
|
urgent_key = val;
|
2007-11-02 21:58:04 +00:00
|
|
|
} else if (!strcasecmp(var, "operator-key") && !switch_strlen_zero(val)) {
|
|
|
|
operator_key = val;
|
|
|
|
} else if (!strcasecmp(var, "operator-extension") && !switch_strlen_zero(val)) {
|
|
|
|
operator_ext = val;
|
2007-10-20 00:09:41 +00:00
|
|
|
} else if (!strcasecmp(var, "storage-dir") && !switch_strlen_zero(val)) {
|
|
|
|
storage_dir = val;
|
2007-10-20 00:24:03 +00:00
|
|
|
} else if (!strcasecmp(var, "callback-dialplan") && !switch_strlen_zero(val)) {
|
|
|
|
callback_dialplan = val;
|
|
|
|
} else if (!strcasecmp(var, "callback-context") && !switch_strlen_zero(val)) {
|
|
|
|
callback_context = val;
|
2007-10-12 13:31:12 +00:00
|
|
|
} else if (!strcasecmp(var, "file-extension")) {
|
|
|
|
file_ext = val;
|
2007-11-24 21:09:52 +00:00
|
|
|
} else if (!strcasecmp(var, "record-silence-threshold")) {
|
|
|
|
int tmp = 0;
|
|
|
|
if (!switch_strlen_zero(val)) {
|
|
|
|
tmp = atoi(val);
|
|
|
|
}
|
|
|
|
if (tmp >= 0 && tmp <= 10000) {
|
|
|
|
record_threshold = tmp;
|
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "invalid threshold value [%s] must be between 0 and 10000 ms\n", val);
|
|
|
|
}
|
2007-11-26 23:41:00 +00:00
|
|
|
} else if (!strcasecmp(var, "record-sample-rate")) {
|
|
|
|
int tmp = 0;
|
|
|
|
if (!switch_strlen_zero(val)) {
|
|
|
|
tmp = atoi(val);
|
|
|
|
}
|
|
|
|
if (tmp == 8000 || tmp == 16000 || tmp == 32000 || tmp == 11025 || tmp == 22050 || tmp == 44100) {
|
|
|
|
record_sample_rate = tmp;
|
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "invalid samplerate %s\n", val);
|
|
|
|
}
|
2007-11-24 21:09:52 +00:00
|
|
|
} else if (!strcasecmp(var, "record-silence-hits")) {
|
|
|
|
int tmp = 0;
|
|
|
|
if (!switch_strlen_zero(val)) {
|
|
|
|
tmp = atoi(val);
|
|
|
|
}
|
|
|
|
if (tmp >= 0 && tmp <= 1000) {
|
|
|
|
record_silence_hits = tmp;
|
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "invalid threshold value [%s] must be between 0 and 1000 ms\n", val);
|
|
|
|
}
|
2007-10-12 03:28:59 +00:00
|
|
|
} else if (!strcasecmp(var, "tone-spec")) {
|
|
|
|
tone_spec = val;
|
|
|
|
} else if (!strcasecmp(var, "digit-timeout")) {
|
|
|
|
int tmp = 0;
|
|
|
|
if (!switch_strlen_zero(val)) {
|
|
|
|
tmp = atoi(val);
|
|
|
|
}
|
|
|
|
if (tmp >= 1000 && tmp <= 30000) {
|
|
|
|
timeout = tmp;
|
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "invalid timeout value [%s] must be between 1000 and 30000 ms\n", val);
|
|
|
|
}
|
|
|
|
} else if (!strcasecmp(var, "max-login-attempts")) {
|
|
|
|
int tmp = 0;
|
|
|
|
if (!switch_strlen_zero(val)) {
|
|
|
|
tmp = atoi(val);
|
|
|
|
}
|
|
|
|
if (tmp > 0 && tmp < 11) {
|
|
|
|
max_login_attempts = tmp;
|
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "invalid attempts [%s] must be between 1 and 10 ms\n", val);
|
|
|
|
}
|
|
|
|
} else if (!strcasecmp(var, "max-record-len")) {
|
|
|
|
int tmp = 0;
|
|
|
|
if (!switch_strlen_zero(val)) {
|
|
|
|
tmp = atoi(val);
|
|
|
|
}
|
|
|
|
if (tmp > 0 && tmp < 10000) {
|
|
|
|
max_record_len = tmp;
|
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "invalid attempts [%s] must be between 1 and 10000s\n", val);
|
|
|
|
}
|
2007-11-15 16:55:46 +00:00
|
|
|
} else if (!strcasecmp(var, "odbc-dsn") && !switch_strlen_zero(val)) {
|
2007-10-12 03:28:59 +00:00
|
|
|
#ifdef SWITCH_HAVE_ODBC
|
2007-10-12 16:49:14 +00:00
|
|
|
odbc_dsn = switch_core_strdup(globals.pool, val);
|
2007-10-12 03:28:59 +00:00
|
|
|
if ((odbc_user = strchr(odbc_dsn, ':'))) {
|
|
|
|
*odbc_user++ = '\0';
|
2007-11-15 16:55:46 +00:00
|
|
|
if ((odbc_pass = strchr(odbc_user, ':'))) {
|
|
|
|
*odbc_pass++ = '\0';
|
|
|
|
}
|
2007-10-12 03:28:59 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ODBC IS NOT AVAILABLE!\n");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_strlen_zero(name)) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No name specified.\n");
|
|
|
|
} else {
|
|
|
|
profile = switch_core_alloc(globals.pool, sizeof(*profile));
|
|
|
|
profile->name = switch_core_strdup(globals.pool, name);
|
|
|
|
|
|
|
|
if (!switch_strlen_zero(odbc_dsn) && !switch_strlen_zero(odbc_user) && !switch_strlen_zero(odbc_pass)) {
|
2007-10-12 16:49:14 +00:00
|
|
|
profile->odbc_dsn = odbc_dsn;
|
|
|
|
profile->odbc_user = odbc_user;
|
|
|
|
profile->odbc_pass = odbc_pass;
|
2007-10-12 03:28:59 +00:00
|
|
|
} else {
|
|
|
|
profile->dbname = switch_core_sprintf(globals.pool, "voicemail_%s", name);
|
|
|
|
}
|
|
|
|
#ifdef SWITCH_HAVE_ODBC
|
|
|
|
if (profile->odbc_dsn) {
|
|
|
|
if (!(profile->master_odbc = switch_odbc_handle_new(profile->odbc_dsn, profile->odbc_user, profile->odbc_pass))) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
|
|
|
|
continue;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (switch_odbc_handle_connect(profile->master_odbc) != SWITCH_ODBC_SUCCESS) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open ODBC Database!\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", profile->odbc_dsn);
|
2007-11-26 23:41:00 +00:00
|
|
|
if (switch_odbc_handle_exec(profile->master_odbc, "select count(message_len) from voicemail_data", NULL) != SWITCH_ODBC_SUCCESS) {
|
|
|
|
switch_odbc_handle_exec(profile->master_odbc, "drop table voicemail_data", NULL);
|
|
|
|
switch_odbc_handle_exec(profile->master_odbc, vm_sql, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_odbc_handle_exec(profile->master_odbc, "select count(user) from voicemail_prefs", NULL) != SWITCH_ODBC_SUCCESS) {
|
|
|
|
switch_odbc_handle_exec(profile->master_odbc, "drop table voicemail_data", NULL);
|
|
|
|
switch_odbc_handle_exec(profile->master_odbc, vm_pref_sql, NULL);
|
|
|
|
}
|
2007-10-12 03:28:59 +00:00
|
|
|
} else {
|
|
|
|
#endif
|
|
|
|
if ((db = switch_core_db_open_file(profile->dbname))) {
|
2007-11-26 23:41:00 +00:00
|
|
|
switch_core_db_test_reactive(db, "select count(message_len) from voicemail_data", "drop table voicemail_data", vm_sql);
|
|
|
|
switch_core_db_test_reactive(db, "select count(user) from voicemail_prefs", "drop table voicemail_data", vm_pref_sql);
|
2007-10-12 03:28:59 +00:00
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch_core_db_close(db);
|
|
|
|
#ifdef SWITCH_HAVE_ODBC
|
2007-10-12 16:49:14 +00:00
|
|
|
}
|
2007-10-12 03:28:59 +00:00
|
|
|
#endif
|
2007-11-29 01:05:05 +00:00
|
|
|
|
|
|
|
profile->web_head = web_head;
|
|
|
|
profile->web_tail = web_tail;
|
|
|
|
|
2007-10-23 14:45:22 +00:00
|
|
|
profile->email_body = email_body;
|
|
|
|
profile->email_headers = email_headers;
|
|
|
|
profile->email_from = email_from;
|
|
|
|
profile->date_fmt = date_fmt;
|
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
profile->digit_timeout = timeout;
|
|
|
|
profile->max_login_attempts = max_login_attempts;
|
|
|
|
profile->max_record_len = max_record_len;
|
|
|
|
*profile->terminator_key = *terminator_key;
|
|
|
|
*profile->play_new_messages_key = *play_new_messages_key;
|
|
|
|
*profile->play_saved_messages_key = *play_saved_messages_key;
|
|
|
|
*profile->main_menu_key = *main_menu_key;
|
|
|
|
*profile->config_menu_key = *config_menu_key;
|
|
|
|
*profile->record_greeting_key = *record_greeting_key;
|
|
|
|
*profile->choose_greeting_key = *choose_greeting_key;
|
|
|
|
*profile->record_name_key = *record_name_key;
|
|
|
|
*profile->record_file_key = *record_file_key;
|
|
|
|
*profile->listen_file_key = *listen_file_key;
|
|
|
|
*profile->save_file_key = *save_file_key;
|
|
|
|
*profile->delete_file_key = *delete_file_key;
|
|
|
|
*profile->undelete_file_key = *undelete_file_key;
|
2007-10-12 13:31:12 +00:00
|
|
|
*profile->email_key = *email_key;
|
2007-10-20 00:24:03 +00:00
|
|
|
*profile->callback_key = *callback_key;
|
2007-10-12 22:08:30 +00:00
|
|
|
*profile->pause_key = *pause_key;
|
|
|
|
*profile->restart_key = *restart_key;
|
|
|
|
*profile->ff_key = *ff_key;
|
|
|
|
*profile->rew_key = *rew_key;
|
|
|
|
*profile->urgent_key = *urgent_key;
|
2007-11-02 21:58:04 +00:00
|
|
|
*profile->operator_key = *operator_key;
|
2007-11-24 21:09:52 +00:00
|
|
|
profile->record_threshold = record_threshold;
|
|
|
|
profile->record_silence_hits = record_silence_hits;
|
2007-11-26 23:41:00 +00:00
|
|
|
profile->record_sample_rate = record_sample_rate;
|
2007-10-20 00:09:41 +00:00
|
|
|
|
2007-11-02 21:58:04 +00:00
|
|
|
profile->operator_ext = switch_core_strdup(globals.pool, operator_ext);
|
2007-10-20 00:09:41 +00:00
|
|
|
profile->storage_dir = switch_core_strdup(globals.pool, storage_dir);
|
2007-10-12 03:28:59 +00:00
|
|
|
profile->tone_spec = switch_core_strdup(globals.pool, tone_spec);
|
2007-10-20 00:24:03 +00:00
|
|
|
profile->callback_dialplan = switch_core_strdup(globals.pool, callback_dialplan);
|
|
|
|
profile->callback_context = switch_core_strdup(globals.pool, callback_context);
|
2007-10-12 13:31:12 +00:00
|
|
|
switch_copy_string(profile->file_ext, file_ext, sizeof(profile->file_ext));
|
2007-10-12 03:28:59 +00:00
|
|
|
switch_mutex_init(&profile->mutex, SWITCH_MUTEX_NESTED, globals.pool);
|
|
|
|
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Added Profile %s\n", profile->name);
|
|
|
|
switch_core_hash_insert(globals.profile_hash, profile->name, profile);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
|
|
|
switch_xml_free(xml);
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static switch_status_t cancel_on_dtmf(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
switch (itype) {
|
|
|
|
case SWITCH_INPUT_TYPE_DTMF:
|
|
|
|
{
|
|
|
|
char *dtmf = (char *) input;
|
|
|
|
if (buf && buflen) {
|
|
|
|
switch_copy_string(buf, dtmf, buflen);
|
|
|
|
}
|
|
|
|
return SWITCH_STATUS_BREAK;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-12 22:08:30 +00:00
|
|
|
struct call_control {
|
|
|
|
vm_profile_t *profile;
|
|
|
|
switch_file_handle_t *fh;
|
|
|
|
char buf[4];
|
2007-10-13 14:43:22 +00:00
|
|
|
int noexit;
|
2007-10-12 22:08:30 +00:00
|
|
|
};
|
|
|
|
typedef struct call_control cc_t;
|
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
static switch_status_t control_playback(switch_core_session_t *session, void *input, switch_input_type_t itype, void *buf, unsigned int buflen)
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
switch (itype) {
|
|
|
|
case SWITCH_INPUT_TYPE_DTMF:
|
|
|
|
{
|
|
|
|
char *dtmf = (char *) input;
|
2007-10-12 22:08:30 +00:00
|
|
|
cc_t *cc = (cc_t *) buf;
|
|
|
|
switch_file_handle_t *fh = cc->fh;
|
2007-10-12 03:28:59 +00:00
|
|
|
uint32_t pos = 0;
|
2007-10-12 22:08:30 +00:00
|
|
|
|
2007-10-13 14:43:22 +00:00
|
|
|
if (!cc->noexit && (*dtmf == *cc->profile->delete_file_key || *dtmf == *cc->profile->save_file_key || *dtmf == *cc->profile->terminator_key)) {
|
2007-10-12 22:08:30 +00:00
|
|
|
*cc->buf = *dtmf;
|
2007-10-12 03:28:59 +00:00
|
|
|
return SWITCH_STATUS_BREAK;
|
2007-10-12 22:08:30 +00:00
|
|
|
}
|
2007-10-13 14:43:22 +00:00
|
|
|
|
2007-10-12 22:08:30 +00:00
|
|
|
if (!fh) {
|
2007-10-12 03:28:59 +00:00
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2007-10-13 14:43:22 +00:00
|
|
|
|
2007-10-12 22:08:30 +00:00
|
|
|
if (*dtmf == *cc->profile->pause_key) {
|
|
|
|
if (switch_test_flag(fh, SWITCH_FILE_PAUSE)) {
|
|
|
|
switch_clear_flag(fh, SWITCH_FILE_PAUSE);
|
|
|
|
} else {
|
|
|
|
switch_set_flag(fh, SWITCH_FILE_PAUSE);
|
|
|
|
}
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*dtmf == *cc->profile->restart_key) {
|
|
|
|
unsigned int pos = 0;
|
|
|
|
fh->speed = 0;
|
|
|
|
switch_core_file_seek(fh, &pos, 0, SEEK_SET);
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*dtmf == *cc->profile->ff_key) {
|
|
|
|
int samps = 24000;
|
|
|
|
switch_core_file_seek(fh, &pos, samps, SEEK_CUR);
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*dtmf == *cc->profile->rew_key) {
|
|
|
|
int samps = 24000;
|
|
|
|
switch_core_file_seek(fh, &pos, fh->pos - samps, SEEK_SET);
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct prefs_callback {
|
|
|
|
char name_path[255];
|
|
|
|
char greeting_path[255];
|
|
|
|
};
|
|
|
|
typedef struct prefs_callback prefs_callback_t;
|
|
|
|
|
|
|
|
static int prefs_callback(void *pArg, int argc, char **argv, char **columnNames)
|
|
|
|
{
|
|
|
|
prefs_callback_t *cbt = (prefs_callback_t *) pArg;
|
|
|
|
|
|
|
|
switch_copy_string(cbt->name_path, argv[2], sizeof(cbt->name_path));
|
|
|
|
switch_copy_string(cbt->greeting_path, argv[3], sizeof(cbt->greeting_path));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
VM_CHECK_START,
|
|
|
|
VM_CHECK_AUTH,
|
|
|
|
VM_CHECK_MENU,
|
|
|
|
VM_CHECK_CONFIG,
|
|
|
|
VM_CHECK_PLAY_MESSAGES,
|
|
|
|
VM_CHECK_FOLDER_SUMMARY,
|
|
|
|
VM_CHECK_LISTEN
|
|
|
|
} vm_check_state_t;
|
|
|
|
|
|
|
|
|
|
|
|
#define VM_ACK_MACRO "voicemail_ack"
|
|
|
|
#define VM_SAY_DATE_MACRO "voicemail_say_date"
|
|
|
|
#define VM_PLAY_GREETING_MACRO "voicemail_play_greeting"
|
|
|
|
#define VM_SAY_MESSAGE_NUMBER_MACRO "voicemail_say_message_number"
|
|
|
|
#define VM_SAY_NUMBER_MACRO "voicemail_say_number"
|
|
|
|
#define VM_SAY_PHONE_NUMBER_MACRO "voicemail_say_phone_number"
|
|
|
|
#define VM_SAY_NAME_MACRO "voicemail_say_name"
|
|
|
|
|
|
|
|
#define VM_RECORD_MESSAGE_MACRO "voicemail_record_message"
|
|
|
|
#define VM_CHOOSE_GREETING_MACRO "voicemail_choose_greeting"
|
|
|
|
#define VM_CHOOSE_GREETING_FAIL_MACRO "voicemail_choose_greeting_fail"
|
|
|
|
#define VM_CHOOSE_GREETING_SELECTED_MACRO "voicemail_greeting_selected"
|
|
|
|
#define VM_RECORD_GREETING_MACRO "voicemail_record_greeting"
|
|
|
|
#define VM_RECORD_NAME_MACRO "voicemail_record_name"
|
|
|
|
#define VM_LISTEN_FILE_CHECK_MACRO "voicemail_listen_file_check"
|
|
|
|
#define VM_RECORD_FILE_CHECK_MACRO "voicemail_record_file_check"
|
2007-10-12 22:08:30 +00:00
|
|
|
#define VM_RECORD_URGENT_CHECK_MACRO "voicemail_record_urgent_check"
|
2007-10-12 03:28:59 +00:00
|
|
|
#define VM_MENU_MACRO "voicemail_menu"
|
|
|
|
#define VM_CONFIG_MENU_MACRO "voicemail_config_menu"
|
|
|
|
#define VM_ENTER_ID_MACRO "voicemail_enter_id"
|
|
|
|
#define VM_ENTER_PASS_MACRO "voicemail_enter_pass"
|
|
|
|
#define VM_FAIL_AUTH_MACRO "voicemail_fail_auth"
|
|
|
|
#define VM_ABORT_MACRO "voicemail_abort"
|
|
|
|
#define VM_HELLO_MACRO "voicemail_hello"
|
|
|
|
#define VM_GOODBYE_MACRO "voicemail_goodbye"
|
2007-10-12 22:08:30 +00:00
|
|
|
#define VM_MESSAGE_COUNT_MACRO "voicemail_message_count"
|
2007-10-13 00:22:13 +00:00
|
|
|
#define URGENT_FLAG_STRING "A_URGENT"
|
|
|
|
#define NORMAL_FLAG_STRING "B_NORMAL"
|
2007-10-12 03:28:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
static switch_status_t vm_macro_get(switch_core_session_t *session,
|
|
|
|
char *macro,
|
|
|
|
char *macro_arg,
|
|
|
|
char *buf,
|
|
|
|
switch_size_t buflen,
|
|
|
|
switch_size_t maxlen,
|
|
|
|
char *term_chars,
|
|
|
|
char *terminator_key,
|
|
|
|
uint32_t timeout)
|
|
|
|
{
|
|
|
|
switch_input_args_t args = { 0 }, *ap = NULL;
|
|
|
|
switch_channel_t *channel;
|
|
|
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
|
|
|
switch_size_t bslen;
|
|
|
|
|
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
assert(channel != NULL);
|
|
|
|
|
|
|
|
if (buf && buflen) {
|
2007-10-12 22:08:30 +00:00
|
|
|
memset(buf, 0, buflen);
|
2007-10-12 03:28:59 +00:00
|
|
|
args.input_callback = cancel_on_dtmf;
|
|
|
|
args.buf = buf;
|
2007-10-25 19:31:47 +00:00
|
|
|
args.buflen = (uint32_t)buflen;
|
2007-10-12 03:28:59 +00:00
|
|
|
ap = &args;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = switch_ivr_phrase_macro(session, macro, macro_arg, NULL, ap);
|
|
|
|
|
|
|
|
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
|
|
|
|
if (buf) {
|
|
|
|
memset(buf, 0, buflen);
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!buf) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
bslen = strlen(buf);
|
|
|
|
|
|
|
|
if (maxlen == 0 || maxlen > buflen - 1) {
|
|
|
|
maxlen = buflen -1;
|
|
|
|
}
|
|
|
|
if (bslen < maxlen) {
|
|
|
|
status = switch_ivr_collect_digits_count(session, buf + bslen, buflen, maxlen - bslen, term_chars, terminator_key, timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct callback {
|
|
|
|
char *buf;
|
|
|
|
size_t len;
|
|
|
|
int matches;
|
|
|
|
};
|
|
|
|
typedef struct callback callback_t;
|
|
|
|
|
|
|
|
static int sql2str_callback(void *pArg, int argc, char **argv, char **columnNames)
|
|
|
|
{
|
|
|
|
callback_t *cbt = (callback_t *) pArg;
|
|
|
|
|
|
|
|
switch_copy_string(cbt->buf, argv[0], cbt->len);
|
|
|
|
cbt->matches++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int unlink_callback(void *pArg, int argc, char **argv, char **columnNames)
|
|
|
|
{
|
|
|
|
if (argv[0]) {
|
|
|
|
unlink(argv[0]);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
MSG_NONE,
|
|
|
|
MSG_NEW,
|
|
|
|
MSG_SAVED
|
|
|
|
} msg_type_t;
|
|
|
|
|
|
|
|
|
2007-11-26 23:46:03 +00:00
|
|
|
static switch_status_t create_file(switch_core_session_t *session, vm_profile_t *profile, char *macro_name, char *file_path, switch_size_t *message_len)
|
2007-10-12 03:28:59 +00:00
|
|
|
{
|
|
|
|
switch_channel_t *channel;
|
|
|
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
|
|
|
switch_file_handle_t fh = { 0 };
|
|
|
|
switch_input_args_t args = { 0 };
|
|
|
|
char term;
|
|
|
|
char input[10] = "" , key_buf[80] = "";
|
2007-10-12 22:08:30 +00:00
|
|
|
cc_t cc = { 0 };
|
2007-11-26 23:41:00 +00:00
|
|
|
switch_codec_t *read_codec;
|
2007-10-12 03:28:59 +00:00
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
assert(channel != NULL);
|
|
|
|
|
2007-11-26 23:41:00 +00:00
|
|
|
read_codec = switch_core_session_get_read_codec(session);
|
2007-10-12 03:28:59 +00:00
|
|
|
|
|
|
|
while(switch_channel_ready(channel)) {
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s",
|
2007-10-12 03:28:59 +00:00
|
|
|
profile->listen_file_key,
|
|
|
|
profile->save_file_key,
|
|
|
|
profile->record_file_key);
|
|
|
|
|
|
|
|
|
|
|
|
record_file:
|
|
|
|
args.input_callback = cancel_on_dtmf;
|
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, macro_name, NULL, NULL, NULL));
|
|
|
|
TRY_CODE(switch_ivr_gentones(session, profile->tone_spec, 0, NULL));
|
|
|
|
|
|
|
|
memset(&fh, 0, sizeof(fh));
|
2007-11-24 21:09:52 +00:00
|
|
|
fh.thresh = profile->record_threshold;
|
|
|
|
fh.silence_hits = profile->record_silence_hits;
|
2007-11-26 23:41:00 +00:00
|
|
|
fh.samplerate = profile->record_sample_rate;
|
2007-10-12 03:28:59 +00:00
|
|
|
switch_ivr_record_file(session, &fh, file_path, &args, profile->max_record_len);
|
2007-11-26 23:41:00 +00:00
|
|
|
*message_len = fh.sample_count / read_codec->implementation->actual_samples_per_second;
|
2007-10-12 03:28:59 +00:00
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
play_file:
|
|
|
|
memset(&fh, 0, sizeof(fh));
|
|
|
|
args.input_callback = control_playback;
|
2007-10-12 22:08:30 +00:00
|
|
|
memset(&cc, 0, sizeof(cc));
|
|
|
|
cc.profile = profile;
|
|
|
|
cc.fh = &fh;
|
|
|
|
args.buf = &cc;
|
2007-10-12 03:28:59 +00:00
|
|
|
switch_ivr_play_file(session, &fh, file_path, &args);
|
|
|
|
|
|
|
|
|
|
|
|
while(switch_channel_ready(channel)) {
|
2007-10-12 22:08:30 +00:00
|
|
|
if (*cc.buf) {
|
|
|
|
*input = *cc.buf;
|
|
|
|
*(input+1) = '\0';
|
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
|
|
|
*cc.buf = '\0';
|
|
|
|
} else {
|
|
|
|
status = vm_macro_get(session, VM_RECORD_FILE_CHECK_MACRO,
|
2007-10-16 17:51:18 +00:00
|
|
|
key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout);
|
2007-10-12 22:08:30 +00:00
|
|
|
}
|
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
if (!strcmp(input, profile->listen_file_key)) {
|
|
|
|
goto play_file;
|
|
|
|
} else if (!strcmp(input, profile->record_file_key)) {
|
|
|
|
goto record_file;
|
|
|
|
} else {
|
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "saved", NULL, NULL));
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct listen_callback {
|
|
|
|
char created_epoch[255];
|
|
|
|
char read_epoch[255];
|
|
|
|
char user[255];
|
|
|
|
char domain[255];
|
|
|
|
char uuid[255];
|
|
|
|
char cid_name[255];
|
|
|
|
char cid_number[255];
|
|
|
|
char in_folder[255];
|
|
|
|
char file_path[255];
|
2007-11-26 23:41:00 +00:00
|
|
|
char message_len[255];
|
2007-10-12 03:28:59 +00:00
|
|
|
char flags[255];
|
2007-10-12 22:08:30 +00:00
|
|
|
char read_flags[255];
|
2007-10-12 13:31:12 +00:00
|
|
|
char *email;
|
2007-10-12 03:28:59 +00:00
|
|
|
int index;
|
|
|
|
int want;
|
|
|
|
msg_type_t type;
|
|
|
|
};
|
|
|
|
typedef struct listen_callback listen_callback_t;
|
|
|
|
|
|
|
|
static int listen_callback(void *pArg, int argc, char **argv, char **columnNames)
|
|
|
|
{
|
|
|
|
listen_callback_t *cbt = (listen_callback_t *) pArg;
|
|
|
|
|
|
|
|
if (cbt->index++ != cbt->want) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_copy_string(cbt->created_epoch, argv[0], 255);
|
|
|
|
switch_copy_string(cbt->read_epoch, argv[1], 255);
|
|
|
|
switch_copy_string(cbt->user, argv[2], 255);
|
|
|
|
switch_copy_string(cbt->domain, argv[3], 255);
|
|
|
|
switch_copy_string(cbt->uuid, argv[4], 255);
|
|
|
|
switch_copy_string(cbt->cid_name, argv[5], 255);
|
|
|
|
switch_copy_string(cbt->cid_number, argv[6], 255);
|
|
|
|
switch_copy_string(cbt->in_folder, argv[7], 255);
|
|
|
|
switch_copy_string(cbt->file_path, argv[8], 255);
|
2007-11-26 23:41:00 +00:00
|
|
|
switch_copy_string(cbt->message_len, argv[9], 255);
|
|
|
|
switch_copy_string(cbt->flags, argv[10], 255);
|
|
|
|
switch_copy_string(cbt->read_flags, argv[11], 255);
|
2007-10-12 03:28:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-01 11:28:26 +00:00
|
|
|
static void message_count(vm_profile_t *profile, const char *myid, const char *domain_name, char *myfolder,
|
2007-10-23 14:45:22 +00:00
|
|
|
int *total_new_messages, int *total_saved_messages, int *total_new_urgent_messages, int *total_saved_urgent_messages)
|
|
|
|
{
|
|
|
|
char msg_count[80] = "";
|
|
|
|
callback_t cbt = { 0 };
|
|
|
|
char sql[256];
|
|
|
|
|
|
|
|
cbt.buf = msg_count;
|
|
|
|
cbt.len = sizeof(msg_count);
|
|
|
|
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(sql, sizeof(sql),
|
2007-10-23 14:45:22 +00:00
|
|
|
"select count(*) from voicemail_data where user='%s' and domain='%s' and in_folder='%s' and read_epoch=0",
|
|
|
|
myid,
|
|
|
|
domain_name,
|
|
|
|
myfolder);
|
|
|
|
vm_execute_sql_callback(profile, profile->mutex, sql, sql2str_callback, &cbt);
|
|
|
|
*total_new_messages = atoi(msg_count);
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(sql, sizeof(sql),
|
2007-10-23 14:45:22 +00:00
|
|
|
"select count(*) from voicemail_data where user='%s' and domain='%s' and in_folder='%s' and read_epoch=0 and read_flags='%s'",
|
|
|
|
myid,
|
|
|
|
domain_name,
|
|
|
|
myfolder,
|
|
|
|
URGENT_FLAG_STRING);
|
|
|
|
vm_execute_sql_callback(profile, profile->mutex, sql, sql2str_callback, &cbt);
|
|
|
|
*total_new_urgent_messages = atoi(msg_count);
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(sql, sizeof(sql),
|
2007-10-23 14:45:22 +00:00
|
|
|
"select count(*) from voicemail_data where user='%s' and domain='%s' and in_folder='%s' and read_epoch!=0",
|
|
|
|
myid,
|
|
|
|
domain_name,
|
|
|
|
myfolder);
|
|
|
|
vm_execute_sql_callback(profile, profile->mutex, sql, sql2str_callback, &cbt);
|
|
|
|
*total_saved_messages = atoi(msg_count);
|
|
|
|
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(sql, sizeof(sql),
|
2007-10-23 14:45:22 +00:00
|
|
|
"select count(*) from voicemail_data where user='%s' and domain='%s' and in_folder='%s' and read_epoch!=0 and read_flags='%s'",
|
|
|
|
myid,
|
|
|
|
domain_name,
|
|
|
|
myfolder,
|
|
|
|
URGENT_FLAG_STRING);
|
|
|
|
vm_execute_sql_callback(profile, profile->mutex, sql, sql2str_callback, &cbt);
|
|
|
|
*total_saved_urgent_messages = atoi(msg_count);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
static switch_status_t listen_file(switch_core_session_t *session, vm_profile_t *profile, listen_callback_t *cbt)
|
|
|
|
{
|
|
|
|
switch_channel_t *channel;
|
|
|
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
|
|
|
switch_input_args_t args = { 0 };
|
|
|
|
char term;
|
|
|
|
char input[10] = "" , key_buf[80] = "";
|
|
|
|
switch_file_handle_t fh = { 0 };
|
2007-10-12 22:08:30 +00:00
|
|
|
cc_t cc = { 0 };
|
2007-10-12 03:28:59 +00:00
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
assert(channel != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
if(switch_channel_ready(channel)) {
|
|
|
|
|
|
|
|
args.input_callback = cancel_on_dtmf;
|
|
|
|
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s:%s:%s",
|
2007-10-12 03:28:59 +00:00
|
|
|
profile->listen_file_key,
|
|
|
|
profile->save_file_key,
|
|
|
|
profile->delete_file_key,
|
2007-10-20 00:24:03 +00:00
|
|
|
profile->email_key,
|
|
|
|
profile->callback_key);
|
2007-10-12 03:28:59 +00:00
|
|
|
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(input, sizeof(input), "%s:%d", cbt->type == MSG_NEW ? "new" : "saved", cbt->want+1);
|
2007-10-12 22:08:30 +00:00
|
|
|
memset(&cc, 0, sizeof(cc));
|
|
|
|
cc.profile = profile;
|
|
|
|
args.buf = &cc;
|
|
|
|
args.input_callback = control_playback;
|
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_SAY_MESSAGE_NUMBER_MACRO, input, NULL, &args));
|
|
|
|
if (!*cc.buf) {
|
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_SAY_DATE_MACRO, cbt->created_epoch, NULL, &args));
|
|
|
|
}
|
2007-10-12 03:28:59 +00:00
|
|
|
play_file:
|
|
|
|
|
2007-10-12 22:08:30 +00:00
|
|
|
if (!*cc.buf) {
|
|
|
|
memset(&fh, 0, sizeof(fh));
|
|
|
|
args.input_callback = control_playback;
|
|
|
|
memset(&cc, 0, sizeof(cc));
|
|
|
|
cc.profile = profile;
|
|
|
|
cc.fh = &fh;
|
|
|
|
args.buf = &cc;
|
|
|
|
TRY_CODE(switch_ivr_play_file(session, NULL, cbt->file_path, &args));
|
|
|
|
}
|
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
if (switch_channel_ready(channel)) {
|
2007-10-12 22:08:30 +00:00
|
|
|
if (*cc.buf) {
|
|
|
|
*input = *cc.buf;
|
|
|
|
*(input+1) = '\0';
|
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
|
|
|
*cc.buf = '\0';
|
|
|
|
} else {
|
|
|
|
status = vm_macro_get(session, VM_LISTEN_FILE_CHECK_MACRO,
|
2007-10-16 17:51:18 +00:00
|
|
|
key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout);
|
2007-10-12 22:08:30 +00:00
|
|
|
}
|
2007-10-12 03:28:59 +00:00
|
|
|
if (!strcmp(input, profile->listen_file_key)) {
|
|
|
|
goto play_file;
|
2007-10-20 00:24:03 +00:00
|
|
|
} else if (!strcmp(input, profile->callback_key)) {
|
|
|
|
switch_core_session_execute_exten(session, cbt->cid_number, profile->callback_dialplan, profile->callback_context);
|
2007-10-12 13:31:12 +00:00
|
|
|
} else if (!strcmp(input, profile->delete_file_key) || !strcmp(input, profile->email_key)) {
|
2007-10-12 03:28:59 +00:00
|
|
|
char *sql = switch_mprintf("update voicemail_data set flags='delete' where uuid='%s'", cbt->uuid);
|
|
|
|
vm_execute_sql(profile, sql, profile->mutex);
|
|
|
|
switch_safe_free(sql);
|
2007-10-12 13:31:12 +00:00
|
|
|
if (!strcmp(input, profile->email_key) && !switch_strlen_zero(cbt->email)) {
|
|
|
|
switch_event_t *event;
|
2007-10-23 14:45:22 +00:00
|
|
|
char *from;
|
2007-11-26 23:41:00 +00:00
|
|
|
char *headers, *header_string;
|
2007-10-12 13:31:12 +00:00
|
|
|
char *body;
|
2007-10-12 22:08:30 +00:00
|
|
|
int priority = 3;
|
2007-10-23 14:45:22 +00:00
|
|
|
switch_size_t retsize;
|
|
|
|
switch_time_exp_t tm;
|
|
|
|
char date[80] = "";
|
|
|
|
char tmp[50]="";
|
|
|
|
int total_new_messages = 0;
|
|
|
|
int total_saved_messages = 0;
|
|
|
|
int total_new_urgent_messages = 0;
|
|
|
|
int total_saved_urgent_messages = 0;
|
2007-11-26 23:41:00 +00:00
|
|
|
int32_t message_len = 0;
|
|
|
|
char *p;
|
2007-11-29 01:27:48 +00:00
|
|
|
long l_duration = 0;
|
|
|
|
switch_core_time_duration_t duration;
|
|
|
|
char duration_str[80];
|
|
|
|
|
2007-10-13 00:22:13 +00:00
|
|
|
if (!strcasecmp(cbt->read_flags, URGENT_FLAG_STRING)) {
|
2007-10-12 22:08:30 +00:00
|
|
|
priority = 1;
|
|
|
|
}
|
2007-10-23 14:45:22 +00:00
|
|
|
|
2007-11-26 23:41:00 +00:00
|
|
|
|
2007-10-23 14:45:22 +00:00
|
|
|
message_count(profile, cbt->user, cbt->domain, cbt->in_folder, &total_new_messages, &total_saved_messages,
|
|
|
|
&total_new_urgent_messages, &total_saved_urgent_messages);
|
|
|
|
|
2007-12-04 22:36:05 +00:00
|
|
|
switch_time_exp_lt(&tm, atoi(cbt->created_epoch) * 1000000);
|
2007-10-23 14:45:22 +00:00
|
|
|
switch_strftime(date, &retsize, sizeof(date), profile->date_fmt, &tm);
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(tmp,sizeof(tmp), "%d", total_new_messages);
|
2007-10-23 14:45:22 +00:00
|
|
|
switch_channel_set_variable(channel, "voicemail_total_new_messages", tmp);
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(tmp,sizeof(tmp), "%d", total_saved_messages);
|
2007-10-23 14:45:22 +00:00
|
|
|
switch_channel_set_variable(channel, "voicemail_total_saved_messages", tmp);
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(tmp,sizeof(tmp), "%d", total_new_urgent_messages);
|
2007-10-23 14:45:22 +00:00
|
|
|
switch_channel_set_variable(channel, "voicemail_urgent_new_messages", tmp);
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(tmp,sizeof(tmp), "%d", total_saved_urgent_messages);
|
2007-10-23 14:45:22 +00:00
|
|
|
switch_channel_set_variable(channel, "voicemail_urgent_saved_messages", tmp);
|
|
|
|
switch_channel_set_variable(channel, "voicemail_current_folder", cbt->in_folder);
|
|
|
|
switch_channel_set_variable(channel, "voicemail_account", cbt->user);
|
|
|
|
switch_channel_set_variable(channel, "voicemail_domain", cbt->domain);
|
|
|
|
switch_channel_set_variable(channel, "voicemail_caller_id_number", cbt->cid_number);
|
|
|
|
switch_channel_set_variable(channel, "voicemail_caller_id_name", cbt->cid_name);
|
|
|
|
switch_channel_set_variable(channel, "voicemail_file_path", cbt->file_path);
|
|
|
|
switch_channel_set_variable(channel, "voicemail_read_flags", cbt->read_flags);
|
|
|
|
switch_channel_set_variable(channel, "voicemail_time", date);
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(tmp,sizeof(tmp), "%d", priority);
|
2007-10-23 14:45:22 +00:00
|
|
|
switch_channel_set_variable(channel, "voicemail_priority", tmp);
|
2007-11-26 23:41:00 +00:00
|
|
|
message_len = atoi(cbt->message_len);
|
2007-11-29 01:27:48 +00:00
|
|
|
|
|
|
|
l_duration = atol(cbt->message_len) * 1000000;
|
|
|
|
switch_core_measure_time(l_duration, &duration);
|
|
|
|
duration.day += duration.yr * 365;
|
|
|
|
duration.hr += duration.day * 24;
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u",
|
2007-11-29 01:27:48 +00:00
|
|
|
duration.hr,
|
|
|
|
duration.min,
|
|
|
|
duration.sec
|
|
|
|
);
|
|
|
|
|
|
|
|
switch_channel_set_variable(channel, "voicemail_message_len", duration_str);
|
2007-11-26 23:41:00 +00:00
|
|
|
switch_channel_set_variable(channel, "voicemail_email", cbt->email);
|
|
|
|
|
2007-10-23 14:45:22 +00:00
|
|
|
if(switch_strlen_zero(profile->email_headers)) {
|
|
|
|
from = switch_core_session_sprintf(session, "%s@%s", cbt->user, cbt->domain);
|
|
|
|
} else {
|
|
|
|
from = switch_channel_expand_variables(channel,profile->email_from);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(switch_strlen_zero(profile->email_headers)) {
|
|
|
|
headers = switch_core_session_sprintf(session,
|
|
|
|
"From: FreeSWITCH mod_voicemail <%s@%s>\nSubject: Voicemail from %s %s\nX-Priority: %d",
|
|
|
|
cbt->user, cbt->domain, cbt->cid_name, cbt->cid_number, priority);
|
|
|
|
} else {
|
|
|
|
headers = switch_channel_expand_variables(channel,profile->email_headers);
|
|
|
|
}
|
|
|
|
|
2007-11-26 23:41:00 +00:00
|
|
|
p = headers + (strlen(headers) - 1);
|
|
|
|
if (*p == '\n') {
|
|
|
|
if (*(p-1) == '\r') {
|
|
|
|
p--;
|
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
header_string = switch_core_session_sprintf(session, "%s\nX-Voicemail-Length: %u", headers, message_len);
|
2007-10-12 13:31:12 +00:00
|
|
|
|
|
|
|
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
|
2007-10-23 14:45:22 +00:00
|
|
|
/* this isnt done? it was in the other place
|
|
|
|
* switch_channel_event_set_data(channel, event);
|
|
|
|
*/
|
2007-10-12 13:31:12 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Message-Type", "forwarded-voicemail");
|
|
|
|
switch_event_fire(&event);
|
2007-10-23 14:45:22 +00:00
|
|
|
}
|
|
|
|
|
2007-11-27 01:15:13 +00:00
|
|
|
if (profile->email_body) {
|
|
|
|
body = switch_channel_expand_variables(channel, profile->email_body);
|
2007-10-23 14:45:22 +00:00
|
|
|
} else {
|
2007-11-27 01:15:13 +00:00
|
|
|
body = switch_mprintf("%u second Voicemail from %s %s", message_len,
|
|
|
|
cbt->cid_name, cbt->cid_number);
|
2007-10-12 13:31:12 +00:00
|
|
|
}
|
|
|
|
|
2007-11-26 23:41:00 +00:00
|
|
|
switch_simple_email(cbt->email, from, header_string, body, cbt->file_path);
|
2007-10-12 13:31:12 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending message to %s\n", cbt->email);
|
|
|
|
switch_safe_free(body);
|
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "emailed", NULL, NULL));
|
|
|
|
} else {
|
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "deleted", NULL, NULL));
|
|
|
|
}
|
2007-10-12 03:28:59 +00:00
|
|
|
} else {
|
|
|
|
char *sql = switch_mprintf("update voicemail_data set flags='save' where uuid='%s'", cbt->uuid);
|
|
|
|
vm_execute_sql(profile, sql, profile->mutex);
|
|
|
|
switch_safe_free(sql);
|
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "saved", NULL, NULL));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2007-11-01 11:28:26 +00:00
|
|
|
static void voicemail_check_main(switch_core_session_t *session, const char *profile_name, const char *domain_name, const char *id, int auth)
|
2007-10-12 03:28:59 +00:00
|
|
|
{
|
|
|
|
vm_check_state_t vm_check_state = VM_CHECK_START;
|
|
|
|
switch_channel_t *channel;
|
2007-10-20 00:09:41 +00:00
|
|
|
switch_caller_profile_t *caller_profile;
|
2007-10-12 03:28:59 +00:00
|
|
|
vm_profile_t *profile;
|
|
|
|
switch_xml_t x_domain, x_domain_root, x_user, x_params, x_param;
|
|
|
|
switch_status_t status;
|
2007-11-01 11:28:26 +00:00
|
|
|
char pass_buf[80] = "", *mypass = NULL, id_buf[80] = "", *myfolder = NULL;
|
|
|
|
const char *thepass = NULL, *myid = id;
|
2007-10-12 03:28:59 +00:00
|
|
|
char term = 0;
|
|
|
|
uint32_t timeout, attempts = 0;
|
|
|
|
int failed = 0;
|
|
|
|
msg_type_t play_msg_type = MSG_NONE;
|
|
|
|
char *dir_path = NULL, *file_path = NULL;
|
|
|
|
int total_new_messages = 0;
|
|
|
|
int total_saved_messages = 0;
|
2007-10-12 22:08:30 +00:00
|
|
|
int total_new_urgent_messages = 0;
|
|
|
|
int total_saved_urgent_messages = 0;
|
2007-10-12 03:28:59 +00:00
|
|
|
int heard_auto_saved = 0, heard_auto_new = 0;
|
2007-10-12 13:31:12 +00:00
|
|
|
char *email_vm = NULL;
|
2007-10-23 15:07:14 +00:00
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
assert(channel != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
if (!(profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
|
2007-11-23 17:56:03 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error invalid profile %s\n", profile_name);
|
2007-10-12 03:28:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
x_user = x_domain = x_domain_root = NULL;
|
|
|
|
|
|
|
|
timeout = profile->digit_timeout;
|
|
|
|
attempts = profile->max_login_attempts;
|
|
|
|
|
|
|
|
status = switch_ivr_phrase_macro(session, VM_HELLO_MACRO, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
while(switch_channel_ready(channel)) {
|
|
|
|
|
|
|
|
switch_ivr_sleep(session, 100);
|
|
|
|
|
|
|
|
switch(vm_check_state) {
|
|
|
|
case VM_CHECK_START:
|
|
|
|
{
|
|
|
|
total_new_messages = 0;
|
|
|
|
total_saved_messages = 0;
|
2007-10-12 22:08:30 +00:00
|
|
|
total_new_urgent_messages = 0;
|
|
|
|
total_saved_urgent_messages = 0;
|
2007-10-12 03:28:59 +00:00
|
|
|
heard_auto_saved = 0;
|
|
|
|
heard_auto_new = 0;
|
|
|
|
play_msg_type = MSG_NONE;
|
|
|
|
attempts = profile->max_login_attempts;
|
|
|
|
myid = id;
|
|
|
|
mypass = NULL;
|
|
|
|
myfolder = "inbox";
|
|
|
|
vm_check_state = VM_CHECK_AUTH;
|
|
|
|
if (x_domain_root) {
|
|
|
|
switch_xml_free(x_domain_root);
|
|
|
|
}
|
|
|
|
x_user = x_domain = x_domain_root = NULL;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VM_CHECK_FOLDER_SUMMARY:
|
|
|
|
{
|
2007-10-15 18:02:21 +00:00
|
|
|
int informed = 0;
|
2007-10-12 03:28:59 +00:00
|
|
|
char msg_count[80] = "";
|
2007-11-07 23:37:22 +00:00
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
switch_channel_set_variable(channel, "voicemail_current_folder", myfolder);
|
2007-10-12 22:08:30 +00:00
|
|
|
message_count(profile, myid, domain_name, myfolder, &total_new_messages, &total_saved_messages,
|
|
|
|
&total_new_urgent_messages, &total_saved_urgent_messages);
|
2007-10-12 03:28:59 +00:00
|
|
|
|
2007-11-07 23:37:22 +00:00
|
|
|
|
|
|
|
|
2007-10-12 22:08:30 +00:00
|
|
|
if (total_new_urgent_messages > 0) {
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(msg_count, sizeof(msg_count), "%d:urgent-new", total_new_urgent_messages);
|
2007-10-15 18:02:21 +00:00
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, NULL));
|
|
|
|
informed++;
|
2007-10-12 22:08:30 +00:00
|
|
|
}
|
2007-10-17 21:26:33 +00:00
|
|
|
if (total_new_messages > 0 && total_new_messages != total_new_urgent_messages) {
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(msg_count, sizeof(msg_count), "%d:new", total_new_messages);
|
2007-10-15 18:02:21 +00:00
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, NULL));
|
|
|
|
informed++;
|
2007-10-12 22:08:30 +00:00
|
|
|
}
|
|
|
|
|
2007-10-17 21:26:33 +00:00
|
|
|
if (!heard_auto_new && total_new_messages + total_new_urgent_messages> 0) {
|
2007-10-12 03:28:59 +00:00
|
|
|
heard_auto_new = 1;
|
|
|
|
play_msg_type = MSG_NEW;
|
|
|
|
vm_check_state = VM_CHECK_PLAY_MESSAGES;
|
|
|
|
continue;
|
|
|
|
}
|
2007-10-12 22:08:30 +00:00
|
|
|
|
|
|
|
if (total_saved_urgent_messages > 0) {
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(msg_count, sizeof(msg_count), "%d:urgent-saved", total_saved_urgent_messages);
|
2007-10-15 18:02:21 +00:00
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, NULL));
|
|
|
|
informed++;
|
2007-10-12 22:08:30 +00:00
|
|
|
}
|
2007-10-12 03:28:59 +00:00
|
|
|
|
2007-10-17 21:26:33 +00:00
|
|
|
if (total_saved_messages > 0 && total_saved_messages != total_saved_urgent_messages) {
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(msg_count, sizeof(msg_count), "%d:saved", total_saved_messages);
|
2007-10-15 18:02:21 +00:00
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, NULL));
|
|
|
|
informed++;
|
2007-10-12 03:28:59 +00:00
|
|
|
}
|
|
|
|
|
2007-10-17 21:26:33 +00:00
|
|
|
if (!heard_auto_saved && total_saved_messages + total_saved_urgent_messages> 0) {
|
2007-10-12 03:28:59 +00:00
|
|
|
heard_auto_saved = 1;
|
|
|
|
play_msg_type = MSG_SAVED;
|
|
|
|
vm_check_state = VM_CHECK_PLAY_MESSAGES;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2007-10-15 18:02:21 +00:00
|
|
|
if (!informed) {
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(msg_count, sizeof(msg_count), "0:new");
|
2007-10-15 18:02:21 +00:00
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_MESSAGE_COUNT_MACRO, msg_count, NULL, NULL));
|
|
|
|
informed++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
vm_check_state = VM_CHECK_MENU;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VM_CHECK_PLAY_MESSAGES:
|
|
|
|
{
|
|
|
|
listen_callback_t cbt;
|
2007-10-12 16:49:14 +00:00
|
|
|
char sql[256];
|
2007-10-12 03:28:59 +00:00
|
|
|
int cur_message, total_messages;
|
2007-12-14 00:00:57 +00:00
|
|
|
switch_event_t *event;
|
|
|
|
|
2007-10-12 22:08:30 +00:00
|
|
|
message_count(profile, myid, domain_name, myfolder, &total_new_messages, &total_saved_messages,
|
|
|
|
&total_new_urgent_messages, &total_saved_urgent_messages);
|
2007-10-12 03:28:59 +00:00
|
|
|
memset(&cbt, 0, sizeof(cbt));
|
2007-10-12 13:31:12 +00:00
|
|
|
cbt.email = email_vm;
|
2007-10-12 03:28:59 +00:00
|
|
|
switch(play_msg_type) {
|
|
|
|
case MSG_NEW:
|
|
|
|
{
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(sql, sizeof(sql),
|
2007-10-13 00:22:13 +00:00
|
|
|
"select * from voicemail_data where user='%s' and domain='%s' and read_epoch=0 order by read_flags", myid, domain_name);
|
2007-10-12 03:28:59 +00:00
|
|
|
total_messages = total_new_messages;
|
|
|
|
heard_auto_new = heard_auto_saved = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MSG_SAVED:
|
|
|
|
default:
|
|
|
|
{
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(sql, sizeof(sql),
|
2007-10-13 00:22:13 +00:00
|
|
|
"select * from voicemail_data where user='%s' and domain='%s' and read_epoch !=0 order by read_flags", myid, domain_name);
|
2007-10-12 03:28:59 +00:00
|
|
|
total_messages = total_saved_messages;
|
|
|
|
heard_auto_new = heard_auto_saved = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
for (cur_message = 0; cur_message < total_messages; cur_message++) {
|
|
|
|
cbt.index = 0;
|
|
|
|
cbt.want = cur_message;
|
|
|
|
cbt.type = play_msg_type;
|
|
|
|
vm_execute_sql_callback(profile, profile->mutex, sql, listen_callback, &cbt);
|
|
|
|
status = listen_file(session, profile, &cbt);
|
|
|
|
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(sql, sizeof(sql), "update voicemail_data set read_epoch=%ld where user='%s' and domain='%s' and flags='save'",
|
2007-10-12 03:28:59 +00:00
|
|
|
(long)time(NULL), myid, domain_name);
|
|
|
|
vm_execute_sql(profile, sql, profile->mutex);
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(sql, sizeof(sql), "select file_path from voicemail_data where user='%s' and domain='%s' and flags='delete'", myid, domain_name);
|
2007-10-12 03:28:59 +00:00
|
|
|
vm_execute_sql_callback(profile, profile->mutex, sql, unlink_callback, NULL);
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(sql, sizeof(sql), "delete from voicemail_data where user='%s' and domain='%s' and flags='delete'", myid, domain_name);
|
2007-10-12 03:28:59 +00:00
|
|
|
vm_execute_sql(profile, sql, profile->mutex);
|
|
|
|
vm_check_state = VM_CHECK_FOLDER_SUMMARY;
|
2007-12-14 00:00:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
message_count(profile, id, domain_name, myfolder, &total_new_messages, &total_saved_messages,
|
|
|
|
&total_new_urgent_messages, &total_saved_urgent_messages);
|
|
|
|
|
|
|
|
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE_WAITING) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
char *mwi_id;
|
|
|
|
const char *yn = "no";
|
|
|
|
if (total_new_messages || total_saved_messages || total_new_urgent_messages || total_saved_urgent_messages) {
|
|
|
|
yn = "yes";
|
|
|
|
}
|
|
|
|
mwi_id = switch_mprintf("%s@%s", myid, domain_name);
|
|
|
|
switch_assert(mwi_id);
|
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", "%s", yn);
|
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Message-Account", mwi_id);
|
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)",
|
|
|
|
total_new_messages, total_saved_messages, total_new_urgent_messages, total_saved_urgent_messages);
|
|
|
|
switch_event_fire(&event);
|
|
|
|
switch_safe_free(mwi_id);
|
|
|
|
}
|
2007-10-12 03:28:59 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VM_CHECK_CONFIG:
|
|
|
|
{
|
|
|
|
char *sql = NULL;
|
|
|
|
char input[10] = "";
|
|
|
|
char key_buf[80] = "";
|
|
|
|
callback_t cbt = { 0 };
|
|
|
|
char msg_count[80] = "";
|
2007-10-12 22:08:30 +00:00
|
|
|
cc_t cc = { 0 };
|
2007-11-26 23:49:12 +00:00
|
|
|
switch_size_t message_len = 0;
|
2007-11-26 23:41:00 +00:00
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
cbt.buf = msg_count;
|
|
|
|
cbt.len = sizeof(msg_count);
|
|
|
|
sql = switch_mprintf("select count(*) from voicemail_prefs where user='%q' and domain = '%q'", myid, domain_name);
|
|
|
|
vm_execute_sql_callback(profile, profile->mutex, sql, sql2str_callback, &cbt);
|
|
|
|
switch_safe_free(sql);
|
2007-11-01 13:29:06 +00:00
|
|
|
if (*msg_count == '\0' || !atoi(msg_count)) {
|
2007-10-12 03:28:59 +00:00
|
|
|
sql = switch_mprintf("insert into voicemail_prefs values('%q','%q','','')", myid, domain_name);
|
|
|
|
vm_execute_sql(profile, sql, profile->mutex);
|
|
|
|
switch_safe_free(sql);
|
|
|
|
}
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s:%s",
|
2007-10-12 03:28:59 +00:00
|
|
|
profile->record_greeting_key,
|
|
|
|
profile->choose_greeting_key,
|
|
|
|
profile->record_name_key,
|
|
|
|
profile->main_menu_key);
|
|
|
|
|
|
|
|
|
2007-10-16 17:51:18 +00:00
|
|
|
TRY_CODE(vm_macro_get(session, VM_CONFIG_MENU_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout));
|
2007-10-12 03:28:59 +00:00
|
|
|
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(input, profile->main_menu_key)) {
|
|
|
|
vm_check_state = VM_CHECK_MENU;
|
|
|
|
} else if (!strcmp(input, profile->choose_greeting_key)) {
|
|
|
|
int num;
|
|
|
|
switch_input_args_t args = { 0 };
|
|
|
|
args.input_callback = cancel_on_dtmf;
|
|
|
|
|
2007-10-16 17:51:18 +00:00
|
|
|
TRY_CODE(vm_macro_get(session, VM_CHOOSE_GREETING_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout));
|
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
|
|
|
|
num = atoi(input);
|
2007-10-12 13:31:12 +00:00
|
|
|
file_path = switch_mprintf("%s%sgreeting_%d.%s", dir_path, SWITCH_PATH_SEPARATOR, num, profile->file_ext);
|
2007-10-12 03:28:59 +00:00
|
|
|
if (num < 1 || num > 3) {
|
|
|
|
status = SWITCH_STATUS_FALSE;
|
|
|
|
} else {
|
|
|
|
switch_file_handle_t fh = { 0 };
|
|
|
|
memset(&fh, 0, sizeof(fh));
|
|
|
|
args.input_callback = control_playback;
|
2007-10-12 22:08:30 +00:00
|
|
|
memset(&cc, 0, sizeof(cc));
|
|
|
|
cc.profile = profile;
|
|
|
|
cc.fh = &fh;
|
2007-10-13 14:43:22 +00:00
|
|
|
cc.noexit = 1;
|
2007-10-12 22:08:30 +00:00
|
|
|
args.buf = &cc;
|
2007-10-12 03:28:59 +00:00
|
|
|
status = switch_ivr_play_file(session, NULL, file_path, &args);
|
|
|
|
}
|
|
|
|
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
|
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_CHOOSE_GREETING_FAIL_MACRO, NULL, NULL, NULL));
|
|
|
|
} else {
|
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_CHOOSE_GREETING_SELECTED_MACRO, input, NULL, NULL));
|
|
|
|
sql = switch_mprintf("update voicemail_prefs set greeting_path='%s' where user='%s' and domain='%s'", file_path, myid, domain_name);
|
|
|
|
vm_execute_sql(profile, sql, profile->mutex);
|
|
|
|
switch_safe_free(sql);
|
|
|
|
}
|
|
|
|
switch_safe_free(file_path);
|
|
|
|
} else if (!strcmp(input, profile->record_greeting_key)) {
|
|
|
|
int num;
|
2007-10-16 17:51:18 +00:00
|
|
|
TRY_CODE(vm_macro_get(session, VM_CHOOSE_GREETING_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout));
|
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
|
|
|
|
num = atoi(input);
|
|
|
|
if (num < 1 || num > 3) {
|
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_CHOOSE_GREETING_FAIL_MACRO, NULL, NULL, NULL));
|
|
|
|
} else {
|
2007-10-12 13:31:12 +00:00
|
|
|
file_path = switch_mprintf("%s%sgreeting_%d.%s", dir_path, SWITCH_PATH_SEPARATOR, num, profile->file_ext);
|
2007-11-26 23:41:00 +00:00
|
|
|
TRY_CODE(create_file(session, profile, VM_RECORD_GREETING_MACRO, file_path, &message_len));
|
2007-10-12 03:28:59 +00:00
|
|
|
sql = switch_mprintf("update voicemail_prefs set greeting_path='%s' where user='%s' and domain='%s'", file_path, myid, domain_name);
|
|
|
|
vm_execute_sql(profile, sql, profile->mutex);
|
|
|
|
switch_safe_free(sql);
|
|
|
|
switch_safe_free(file_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (!strcmp(input, profile->record_name_key)) {
|
2007-10-12 13:31:12 +00:00
|
|
|
file_path = switch_mprintf("%s%srecorded_name.%s", dir_path, SWITCH_PATH_SEPARATOR, profile->file_ext);
|
2007-11-26 23:41:00 +00:00
|
|
|
TRY_CODE(create_file(session, profile, VM_RECORD_NAME_MACRO, file_path, &message_len));
|
2007-10-12 03:28:59 +00:00
|
|
|
sql = switch_mprintf("update voicemail_prefs set name_path='%s' where user='%s' and domain='%s'", file_path, myid, domain_name);
|
|
|
|
vm_execute_sql(profile, sql, profile->mutex);
|
|
|
|
switch_safe_free(file_path);
|
|
|
|
switch_safe_free(sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VM_CHECK_MENU:
|
|
|
|
{
|
|
|
|
char input[10] = "";
|
|
|
|
char key_buf[80] = "";
|
|
|
|
play_msg_type = MSG_NONE;
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(key_buf, sizeof(key_buf), "%s:%s:%s:%s",
|
2007-10-12 03:28:59 +00:00
|
|
|
profile->play_new_messages_key,
|
|
|
|
profile->play_saved_messages_key,
|
2007-10-12 16:49:14 +00:00
|
|
|
profile->config_menu_key,
|
|
|
|
profile->terminator_key);
|
2007-10-12 03:28:59 +00:00
|
|
|
|
2007-10-16 17:51:18 +00:00
|
|
|
status = vm_macro_get(session, VM_MENU_MACRO, key_buf, input, sizeof(input), 1, "", &term, timeout);
|
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
if (status != SWITCH_STATUS_SUCCESS && status != SWITCH_STATUS_BREAK) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp(input, profile->play_new_messages_key)) {
|
|
|
|
play_msg_type = MSG_NEW;
|
|
|
|
} else if (!strcmp(input, profile->play_saved_messages_key)) {
|
|
|
|
play_msg_type = MSG_SAVED;
|
2007-10-12 16:49:14 +00:00
|
|
|
} else if (!strcmp(input, profile->terminator_key)) {
|
|
|
|
goto end;
|
2007-10-12 03:28:59 +00:00
|
|
|
} else if (!strcmp(input, profile->config_menu_key)) {
|
|
|
|
vm_check_state = VM_CHECK_CONFIG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (play_msg_type) {
|
|
|
|
vm_check_state = VM_CHECK_PLAY_MESSAGES;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case VM_CHECK_AUTH:
|
|
|
|
{
|
|
|
|
if (!attempts) {
|
|
|
|
failed = 1;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
attempts--;
|
|
|
|
|
|
|
|
if (!myid) {
|
|
|
|
status = vm_macro_get(session, VM_ENTER_ID_MACRO, profile->terminator_key, id_buf, sizeof(id_buf), 0,
|
|
|
|
profile->terminator_key, &term, timeout);
|
|
|
|
if (status != SWITCH_STATUS_SUCCESS) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2007-11-01 13:29:06 +00:00
|
|
|
if (*id_buf == '\0') {
|
2007-10-12 03:28:59 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
myid = id_buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!x_user) {
|
2007-10-21 20:48:50 +00:00
|
|
|
char *xtra;
|
2007-10-12 03:28:59 +00:00
|
|
|
int ok = 1;
|
2007-10-20 00:09:41 +00:00
|
|
|
caller_profile = switch_channel_get_caller_profile(channel);
|
2007-11-07 23:37:22 +00:00
|
|
|
xtra = switch_mprintf("mailbox=%s&destination_number=%s&caller_id_number=%s",
|
|
|
|
myid,caller_profile->destination_number,caller_profile->caller_id_number);
|
2007-10-12 03:28:59 +00:00
|
|
|
|
|
|
|
assert(xtra);
|
|
|
|
|
2007-11-29 02:48:44 +00:00
|
|
|
if (switch_xml_locate_user("id", myid, domain_name, switch_channel_get_variable(channel, "network_addr"),
|
2007-10-12 03:28:59 +00:00
|
|
|
&x_domain_root, &x_domain, &x_user, xtra) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", myid, domain_name);
|
|
|
|
ok = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_safe_free(xtra);
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mypass) {
|
|
|
|
if (auth) {
|
|
|
|
mypass = "OK";
|
|
|
|
} else {
|
|
|
|
status = vm_macro_get(session, VM_ENTER_PASS_MACRO, profile->terminator_key,
|
|
|
|
pass_buf, sizeof(pass_buf), 0, profile->terminator_key, &term, timeout);
|
|
|
|
if (status != SWITCH_STATUS_SUCCESS) {
|
|
|
|
goto end;
|
|
|
|
}
|
2007-11-01 13:29:06 +00:00
|
|
|
if (*pass_buf == '\0') {
|
2007-10-12 03:28:59 +00:00
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
mypass = pass_buf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(x_params = switch_xml_child(x_user, "params"))) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find params for user [%s@%s]\n", myid, domain_name);
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
thepass = NULL;
|
|
|
|
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
|
|
|
|
const char *var = switch_xml_attr_soft(x_param, "name");
|
|
|
|
const char *val = switch_xml_attr_soft(x_param, "value");
|
|
|
|
|
|
|
|
if (!strcasecmp(var, "password")) {
|
|
|
|
thepass = val;
|
|
|
|
} else if (!strcasecmp(var, "vm-password")) {
|
|
|
|
thepass = val;
|
2007-10-12 13:31:12 +00:00
|
|
|
} else if (!strcasecmp(var, "vm-mailto")) {
|
|
|
|
email_vm = switch_core_session_strdup(session, val);
|
2007-10-12 03:28:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
switch_xml_free(x_domain_root);
|
|
|
|
x_domain_root = NULL;
|
|
|
|
|
|
|
|
if (auth || !thepass || (thepass && mypass && !strcmp(thepass, mypass))) {
|
|
|
|
if (!dir_path) {
|
2007-10-20 00:09:41 +00:00
|
|
|
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,
|
|
|
|
myid);
|
|
|
|
} else {
|
|
|
|
dir_path = switch_core_session_sprintf(session, "%s%s%s",
|
|
|
|
profile->storage_dir,
|
|
|
|
SWITCH_PATH_SEPARATOR,
|
|
|
|
myid);
|
|
|
|
}
|
2007-10-12 03:28:59 +00:00
|
|
|
|
|
|
|
|
2007-12-06 19:51:55 +00:00
|
|
|
if (switch_dir_make_recursive(dir_path, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
2007-11-23 17:56:03 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", dir_path);
|
2007-10-12 03:28:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vm_check_state = VM_CHECK_FOLDER_SUMMARY;
|
|
|
|
} else {
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
2007-10-12 13:31:12 +00:00
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
failed:
|
|
|
|
status = switch_ivr_phrase_macro(session, VM_FAIL_AUTH_MACRO, NULL, NULL, NULL);
|
|
|
|
myid = id;
|
|
|
|
mypass = NULL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
|
|
|
if (switch_channel_ready(channel)) {
|
|
|
|
if (failed) {
|
|
|
|
status = switch_ivr_phrase_macro(session, VM_ABORT_MACRO, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
status = switch_ivr_phrase_macro(session, VM_GOODBYE_MACRO, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x_domain_root) {
|
|
|
|
switch_xml_free(x_domain_root);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2007-10-12 13:31:12 +00:00
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
|
2007-11-01 11:28:26 +00:00
|
|
|
static switch_status_t voicemail_leave_main(switch_core_session_t *session, const char *profile_name, const char *domain_name, const char *id)
|
2007-10-12 03:28:59 +00:00
|
|
|
{
|
|
|
|
switch_channel_t *channel;
|
|
|
|
char *myfolder = "inbox";
|
2007-10-12 16:49:14 +00:00
|
|
|
char sql[256];
|
2007-10-12 03:28:59 +00:00
|
|
|
prefs_callback_t cbt;
|
|
|
|
vm_profile_t *profile;
|
|
|
|
char *uuid = switch_core_session_get_uuid(session);
|
|
|
|
char *file_path = NULL;
|
|
|
|
char *dir_path = NULL;
|
|
|
|
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
|
|
|
switch_caller_profile_t *caller_profile;
|
|
|
|
switch_file_handle_t fh = { 0 };
|
|
|
|
switch_input_args_t args = { 0 };
|
|
|
|
char *email_vm = NULL;
|
2007-10-12 13:31:12 +00:00
|
|
|
int send_mail = 0;
|
2007-10-12 22:08:30 +00:00
|
|
|
cc_t cc = { 0 };
|
2007-10-13 00:22:13 +00:00
|
|
|
char *read_flags = NORMAL_FLAG_STRING;
|
2007-10-12 22:08:30 +00:00
|
|
|
int priority = 3;
|
2007-10-23 15:07:14 +00:00
|
|
|
int email_attach = 1;
|
|
|
|
int email_delete = 1;
|
2007-10-23 15:44:04 +00:00
|
|
|
char buf[2];
|
2007-11-01 11:28:26 +00:00
|
|
|
char *greet_path = NULL;
|
|
|
|
const char *voicemail_greeting_number = NULL;
|
2007-11-26 23:49:12 +00:00
|
|
|
switch_size_t message_len = 0;
|
2007-11-26 23:41:00 +00:00
|
|
|
switch_time_exp_t tm;
|
|
|
|
char date[80] = "";
|
|
|
|
switch_size_t retsize;
|
|
|
|
switch_time_t ts = switch_timestamp_now();
|
|
|
|
char *dbuf = NULL;
|
2007-10-12 03:28:59 +00:00
|
|
|
|
|
|
|
memset(&cbt, 0, sizeof(cbt));
|
|
|
|
if (!(profile = switch_core_hash_find(globals.profile_hash, profile_name))) {
|
2007-11-23 17:56:03 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error invalid profile %s\n", profile_name);
|
2007-10-12 03:28:59 +00:00
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
assert(channel != NULL);
|
|
|
|
|
|
|
|
caller_profile = switch_channel_get_caller_profile(channel);
|
2007-10-20 00:09:41 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2007-12-06 19:51:55 +00:00
|
|
|
if (switch_dir_make_recursive(dir_path, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
2007-11-23 17:56:03 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", dir_path);
|
2007-10-12 03:28:59 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (id) {
|
|
|
|
int ok = 1;
|
|
|
|
char *xtra = switch_mprintf("mailbox=%s", id);
|
|
|
|
switch_xml_t x_domain, x_domain_root, x_user, x_params, x_param;
|
2007-10-23 15:07:14 +00:00
|
|
|
const char *email_addr = NULL;
|
2007-10-23 15:44:04 +00:00
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
assert(xtra);
|
|
|
|
x_user = x_domain = x_domain_root = NULL;
|
2007-11-29 02:48:44 +00:00
|
|
|
if (switch_xml_locate_user("id", id, domain_name, switch_channel_get_variable(channel, "network_addr"),
|
2007-10-12 13:31:12 +00:00
|
|
|
&x_domain_root, &x_domain, &x_user, xtra) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
if ((x_params = switch_xml_child(x_user, "params"))) {
|
|
|
|
for (x_param = switch_xml_child(x_params, "param"); x_param; x_param = x_param->next) {
|
|
|
|
const char *var = switch_xml_attr_soft(x_param, "name");
|
|
|
|
const char *val = switch_xml_attr_soft(x_param, "value");
|
|
|
|
|
|
|
|
if (!strcasecmp(var, "vm-mailto")) {
|
|
|
|
email_vm = switch_core_session_strdup(session, val);
|
2007-10-23 15:07:14 +00:00
|
|
|
} else if (!strcasecmp(var, "email-addr")) {
|
|
|
|
email_addr = val;
|
2007-10-12 13:31:12 +00:00
|
|
|
} else if (!strcasecmp(var, "vm-email-all-messages")) {
|
2007-10-23 14:45:22 +00:00
|
|
|
send_mail = switch_true(val);
|
2007-10-23 15:07:14 +00:00
|
|
|
} else if (!strcasecmp(var, "vm-delete-file")) {
|
|
|
|
email_delete = switch_true(val);
|
|
|
|
} else if (!strcasecmp(var, "vm-attach-file")) {
|
|
|
|
email_attach = switch_true(val);
|
2007-10-12 13:31:12 +00:00
|
|
|
}
|
2007-10-12 03:28:59 +00:00
|
|
|
}
|
|
|
|
}
|
2007-10-12 13:31:12 +00:00
|
|
|
|
2007-10-23 15:07:14 +00:00
|
|
|
if (send_mail && switch_strlen_zero(email_vm) && !switch_strlen_zero(email_addr)) {
|
|
|
|
email_vm = switch_core_session_strdup(session, email_addr);
|
|
|
|
}
|
|
|
|
|
2007-10-12 13:31:12 +00:00
|
|
|
} else {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "can't find user [%s@%s]\n", id, domain_name);
|
|
|
|
ok = 0;
|
2007-10-12 03:28:59 +00:00
|
|
|
}
|
2007-10-12 13:31:12 +00:00
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
|
|
|
|
switch_safe_free(xtra);
|
|
|
|
switch_xml_free(x_domain_root);
|
|
|
|
if (!ok) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(sql, sizeof(sql),
|
2007-10-12 03:28:59 +00:00
|
|
|
"select * from voicemail_prefs where user='%s' and domain='%s'",
|
|
|
|
id,
|
|
|
|
domain_name);
|
|
|
|
vm_execute_sql_callback(profile, profile->mutex, sql, prefs_callback, &cbt);
|
|
|
|
|
2007-10-12 13:31:12 +00:00
|
|
|
file_path = switch_mprintf("%s%smsg_%s.%s", dir_path, SWITCH_PATH_SEPARATOR, uuid, profile->file_ext);
|
2007-10-12 03:28:59 +00:00
|
|
|
|
2007-10-25 21:19:31 +00:00
|
|
|
if ((voicemail_greeting_number = switch_channel_get_variable(channel, "voicemail_greeting_number"))) {
|
|
|
|
int num = atoi(voicemail_greeting_number);
|
|
|
|
if (num > 0 && num < 3) {
|
|
|
|
greet_path = switch_mprintf("%s%sgreeting_%d.%s", dir_path, SWITCH_PATH_SEPARATOR, num, profile->file_ext);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
greet_path = cbt.greeting_path;
|
|
|
|
}
|
|
|
|
|
2007-10-23 15:44:04 +00:00
|
|
|
greet:
|
2007-10-25 17:36:06 +00:00
|
|
|
memset(buf, 0, sizeof(buf));
|
2007-10-23 15:44:04 +00:00
|
|
|
args.input_callback = cancel_on_dtmf;
|
|
|
|
args.buf = buf;
|
|
|
|
args.buflen = sizeof(buf);
|
|
|
|
|
2007-10-25 21:19:31 +00:00
|
|
|
if (!switch_strlen_zero(greet_path)) {
|
2007-10-23 15:44:04 +00:00
|
|
|
memset(buf, 0, sizeof(buf));
|
2007-10-25 21:19:31 +00:00
|
|
|
TRY_CODE(switch_ivr_play_file(session, NULL, greet_path, &args));
|
2007-10-23 15:44:04 +00:00
|
|
|
} else {
|
|
|
|
if (!switch_strlen_zero(cbt.name_path)) {
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
TRY_CODE(switch_ivr_play_file(session, NULL, cbt.name_path, &args));
|
|
|
|
}
|
2007-11-01 13:29:06 +00:00
|
|
|
if (*buf == '\0') {
|
2007-10-23 15:44:04 +00:00
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_PLAY_GREETING_MACRO, id, NULL, &args));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-01 13:29:06 +00:00
|
|
|
if (*buf != '\0') {
|
2007-10-25 17:49:42 +00:00
|
|
|
if (!strcasecmp(buf, profile->main_menu_key)) {
|
|
|
|
voicemail_check_main(session, profile_name, domain_name, id, 0);
|
2007-11-02 21:58:04 +00:00
|
|
|
} else if(!strcasecmp(buf, profile->operator_key) && !switch_strlen_zero(profile->operator_key)) {
|
|
|
|
int argc;
|
|
|
|
char *argv[4];
|
|
|
|
char *mycmd;
|
|
|
|
|
|
|
|
if (!switch_strlen_zero(profile->operator_ext) && (mycmd = switch_core_session_strdup(session, profile->operator_ext))) {
|
|
|
|
argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
|
|
|
if(argc >= 1 && argc <= 4) {
|
|
|
|
switch_ivr_session_transfer(session, argv[0], argv[1], argv[2]);
|
|
|
|
/* the application still runs after we leave it so we need to make sure that we dont do anything evil */
|
|
|
|
send_mail=0;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
2007-10-25 17:49:42 +00:00
|
|
|
} else {
|
|
|
|
goto greet;
|
|
|
|
}
|
2007-10-23 15:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
memset(&fh, 0, sizeof(fh));
|
|
|
|
args.input_callback = control_playback;
|
2007-10-12 22:08:30 +00:00
|
|
|
memset(&cc, 0, sizeof(cc));
|
|
|
|
cc.profile = profile;
|
|
|
|
cc.fh = &fh;
|
2007-10-13 14:43:22 +00:00
|
|
|
cc.noexit = 1;
|
2007-10-12 22:08:30 +00:00
|
|
|
args.buf = &cc;
|
2007-10-12 03:28:59 +00:00
|
|
|
|
2007-11-26 23:41:00 +00:00
|
|
|
dbuf = switch_mprintf("%s (%s)", caller_profile->caller_id_name, caller_profile->caller_id_number);
|
|
|
|
switch_channel_set_variable(channel, "RECORD_ARTIST", dbuf);
|
|
|
|
free(dbuf);
|
2007-10-12 03:28:59 +00:00
|
|
|
|
2007-11-26 23:41:00 +00:00
|
|
|
switch_time_exp_lt(&tm, ts);
|
|
|
|
switch_strftime(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm);
|
|
|
|
switch_channel_set_variable(channel, "RECORD_DATE", date);
|
|
|
|
switch_channel_set_variable(channel, "RECORD_SOFTWARE", "FreeSWITCH");
|
|
|
|
switch_channel_set_variable(channel, "RECORD_TITLE", "FreeSWITCH Voicemail");
|
|
|
|
switch_channel_set_variable(channel, "RECORD_COMMENT", "FreeSWITCH Voicemail");
|
|
|
|
switch_channel_set_variable(channel, "RECORD_COPYRIGHT", "http://www.freeswitch.org");
|
|
|
|
|
|
|
|
status = create_file(session, profile, VM_RECORD_MESSAGE_MACRO, file_path, &message_len);
|
2007-10-12 22:08:30 +00:00
|
|
|
|
2007-10-23 15:09:29 +00:00
|
|
|
if ((status == SWITCH_STATUS_SUCCESS || status == SWITCH_STATUS_BREAK) && switch_channel_ready(channel)) {
|
|
|
|
char input[10] = "", key_buf[80] = "", term = 0;
|
2007-10-12 22:08:30 +00:00
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(key_buf, sizeof(key_buf), "%s:%s",
|
2007-10-23 15:09:29 +00:00
|
|
|
profile->urgent_key,
|
|
|
|
profile->terminator_key);
|
2007-10-12 22:08:30 +00:00
|
|
|
|
2007-10-23 15:09:29 +00:00
|
|
|
vm_macro_get(session, VM_RECORD_URGENT_CHECK_MACRO, key_buf, input, sizeof(input), 1, "", &term, profile->digit_timeout);
|
|
|
|
if (*profile->urgent_key == *input) {
|
|
|
|
read_flags = URGENT_FLAG_STRING;
|
|
|
|
priority = 1;
|
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "marked-urgent", NULL, NULL));
|
|
|
|
} else {
|
|
|
|
TRY_CODE(switch_ivr_phrase_macro(session, VM_ACK_MACRO, "saved", NULL, NULL));
|
2007-10-12 03:28:59 +00:00
|
|
|
}
|
2007-10-23 15:09:29 +00:00
|
|
|
}
|
2007-10-12 03:28:59 +00:00
|
|
|
|
2007-10-23 15:44:04 +00:00
|
|
|
if(!send_mail && switch_file_exists(file_path, switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
|
2007-10-23 15:09:29 +00:00
|
|
|
char *usql;
|
|
|
|
switch_event_t *event;
|
|
|
|
char *mwi_id = NULL;
|
|
|
|
int total_new_messages = 0;
|
|
|
|
int total_saved_messages = 0;
|
|
|
|
int total_new_urgent_messages = 0;
|
|
|
|
int total_saved_urgent_messages = 0;
|
2007-10-12 22:08:30 +00:00
|
|
|
|
2007-11-26 23:41:00 +00:00
|
|
|
usql = switch_mprintf("insert into voicemail_data values(%ld,0,'%q','%q','%q','%q','%q','%q','%q','%u','','%q')", (long)time(NULL),
|
|
|
|
id, domain_name, uuid, caller_profile->caller_id_name, caller_profile->caller_id_number,
|
|
|
|
myfolder, file_path, message_len, read_flags);
|
2007-10-23 15:09:29 +00:00
|
|
|
vm_execute_sql(profile, usql, profile->mutex);
|
|
|
|
switch_safe_free(usql);
|
|
|
|
|
|
|
|
message_count(profile, id, domain_name, myfolder, &total_new_messages, &total_saved_messages,
|
|
|
|
&total_new_urgent_messages, &total_saved_urgent_messages);
|
|
|
|
|
|
|
|
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE_WAITING) == SWITCH_STATUS_SUCCESS) {
|
2007-12-14 00:00:57 +00:00
|
|
|
const char *yn = "no";
|
|
|
|
if (total_new_messages || total_saved_messages || total_new_urgent_messages || total_saved_urgent_messages) {
|
|
|
|
yn = "yes";
|
|
|
|
}
|
2007-10-23 15:09:29 +00:00
|
|
|
mwi_id = switch_mprintf("%s@%s", id, domain_name);
|
2007-12-14 00:00:57 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", "%s", yn);
|
2007-10-23 15:09:29 +00:00
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Message-Account", mwi_id);
|
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)",
|
|
|
|
total_new_messages, total_saved_messages, total_new_urgent_messages, total_saved_urgent_messages);
|
|
|
|
switch_event_fire(&event);
|
|
|
|
switch_safe_free(mwi_id);
|
|
|
|
}
|
|
|
|
}
|
2007-10-12 22:08:30 +00:00
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
end:
|
2007-10-23 14:45:22 +00:00
|
|
|
|
|
|
|
|
2007-10-12 13:31:12 +00:00
|
|
|
if (send_mail && !switch_strlen_zero(email_vm)) {
|
2007-10-12 03:28:59 +00:00
|
|
|
switch_event_t *event;
|
2007-10-23 14:45:22 +00:00
|
|
|
char *from;
|
2007-10-12 03:28:59 +00:00
|
|
|
char *body;
|
2007-10-12 22:08:30 +00:00
|
|
|
char *headers;
|
2007-11-26 23:41:00 +00:00
|
|
|
char *header_string;
|
2007-10-23 14:45:22 +00:00
|
|
|
switch_size_t retsize;
|
|
|
|
switch_time_exp_t tm;
|
|
|
|
char date[80] = "";
|
|
|
|
char tmp[50]="";
|
|
|
|
int total_new_messages = 0;
|
|
|
|
int total_saved_messages = 0;
|
|
|
|
int total_new_urgent_messages = 0;
|
|
|
|
int total_saved_urgent_messages = 0;
|
2007-11-26 23:41:00 +00:00
|
|
|
char *p;
|
2007-11-29 01:27:48 +00:00
|
|
|
long l_duration = 0;
|
|
|
|
switch_core_time_duration_t duration;
|
|
|
|
char duration_str[80];
|
|
|
|
|
2007-10-23 14:45:22 +00:00
|
|
|
message_count(profile, id, domain_name, myfolder, &total_new_messages, &total_saved_messages,
|
|
|
|
&total_new_urgent_messages, &total_saved_urgent_messages);
|
|
|
|
|
|
|
|
switch_time_exp_lt(&tm, switch_time_now());
|
|
|
|
switch_strftime(date, &retsize, sizeof(date), profile->date_fmt, &tm);
|
|
|
|
|
|
|
|
switch_channel_set_variable(channel, "voicemail_current_folder", myfolder);
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(tmp,sizeof(tmp), "%d", total_new_messages);
|
2007-10-23 14:45:22 +00:00
|
|
|
switch_channel_set_variable(channel, "voicemail_total_new_messages", tmp);
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(tmp,sizeof(tmp), "%d", total_saved_messages);
|
2007-10-23 14:45:22 +00:00
|
|
|
switch_channel_set_variable(channel, "voicemail_total_saved_messages", tmp);
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(tmp,sizeof(tmp), "%d", total_new_urgent_messages);
|
2007-10-23 14:45:22 +00:00
|
|
|
switch_channel_set_variable(channel, "voicemail_urgent_new_messages", tmp);
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(tmp,sizeof(tmp), "%d", total_saved_urgent_messages);
|
2007-10-23 14:45:22 +00:00
|
|
|
switch_channel_set_variable(channel, "voicemail_urgent_saved_messages", tmp);
|
|
|
|
switch_channel_set_variable(channel, "voicemail_account", id);
|
|
|
|
switch_channel_set_variable(channel, "voicemail_domain", domain_name);
|
|
|
|
switch_channel_set_variable(channel, "voicemail_caller_id_number", caller_profile->caller_id_number);
|
|
|
|
switch_channel_set_variable(channel, "voicemail_caller_id_name", caller_profile->caller_id_name);
|
|
|
|
switch_channel_set_variable(channel, "voicemail_file_path", file_path);
|
|
|
|
switch_channel_set_variable(channel, "voicemail_read_flags", read_flags);
|
|
|
|
switch_channel_set_variable(channel, "voicemail_time", date);
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(tmp,sizeof(tmp), "%d", priority);
|
2007-10-23 14:45:22 +00:00
|
|
|
switch_channel_set_variable(channel, "voicemail_priority", tmp);
|
2007-11-26 23:41:00 +00:00
|
|
|
switch_channel_set_variable(channel, "voicemail_email", email_vm);
|
2007-10-23 14:45:22 +00:00
|
|
|
|
2007-11-29 01:27:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
l_duration = (long)message_len * 1000000;
|
|
|
|
switch_core_measure_time(l_duration, &duration);
|
|
|
|
duration.day += duration.yr * 365;
|
|
|
|
duration.hr += duration.day * 24;
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u",
|
2007-11-29 01:27:48 +00:00
|
|
|
duration.hr,
|
|
|
|
duration.min,
|
|
|
|
duration.sec
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch_channel_set_variable(channel, "voicemail_message_len", duration_str);
|
2007-10-23 14:45:22 +00:00
|
|
|
|
2007-11-26 23:41:00 +00:00
|
|
|
if (switch_strlen_zero(profile->email_from)) {
|
2007-10-23 14:45:22 +00:00
|
|
|
from = switch_core_session_sprintf(session, "%s@%s", id, domain_name);
|
|
|
|
} else {
|
|
|
|
from = switch_channel_expand_variables(channel, profile->email_headers);
|
|
|
|
}
|
|
|
|
|
2007-11-26 23:41:00 +00:00
|
|
|
if (switch_strlen_zero(profile->email_headers)) {
|
|
|
|
headers = switch_core_session_sprintf(session,
|
|
|
|
"From: FreeSWITCH mod_voicemail <%s@%s>\n"
|
|
|
|
"Subject: Voicemail from %s %s\nX-Priority: %d",
|
2007-10-23 14:45:22 +00:00
|
|
|
id, domain_name,
|
|
|
|
caller_profile->caller_id_name,
|
|
|
|
caller_profile->caller_id_number,
|
|
|
|
priority);
|
|
|
|
} else {
|
2007-11-26 23:41:00 +00:00
|
|
|
headers = switch_channel_expand_variables(channel, profile->email_headers);
|
2007-10-23 14:45:22 +00:00
|
|
|
}
|
|
|
|
|
2007-11-26 23:41:00 +00:00
|
|
|
p = headers + (strlen(headers) - 1);
|
|
|
|
|
|
|
|
if (*p == '\n') {
|
|
|
|
if (*(p-1) == '\r') {
|
|
|
|
p--;
|
|
|
|
}
|
|
|
|
*p = '\0';
|
|
|
|
}
|
2007-10-12 22:08:30 +00:00
|
|
|
|
2007-11-26 23:41:00 +00:00
|
|
|
header_string = switch_core_session_sprintf(session, "%s\nX-Voicemail-Length: %u", headers, message_len);
|
2007-10-12 03:28:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_channel_event_set_data(channel, event);
|
|
|
|
switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Message-Type", "voicemail");
|
|
|
|
switch_event_fire(&event);
|
2007-10-23 14:45:22 +00:00
|
|
|
}
|
2007-11-27 01:15:13 +00:00
|
|
|
|
|
|
|
if (profile->email_body) {
|
|
|
|
body = switch_channel_expand_variables(channel, profile->email_body);
|
2007-10-23 14:45:22 +00:00
|
|
|
} else {
|
2007-11-27 01:15:13 +00:00
|
|
|
body = switch_mprintf("%u second Voicemail from %s %s", message_len,
|
|
|
|
caller_profile->caller_id_name, caller_profile->caller_id_number);
|
2007-10-12 03:28:59 +00:00
|
|
|
}
|
|
|
|
|
2007-11-26 23:41:00 +00:00
|
|
|
if (email_attach) {
|
|
|
|
switch_simple_email(email_vm, from, header_string, body, file_path);
|
2007-10-23 15:07:14 +00:00
|
|
|
} else {
|
2007-11-26 23:41:00 +00:00
|
|
|
switch_simple_email(email_vm, from, header_string, body, NULL);
|
2007-10-23 15:07:14 +00:00
|
|
|
}
|
|
|
|
|
2007-10-12 13:31:12 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sending message to %s\n", email_vm);
|
2007-10-12 03:28:59 +00:00
|
|
|
switch_safe_free(body);
|
2007-11-26 23:41:00 +00:00
|
|
|
if (email_delete) {
|
2007-10-23 15:07:14 +00:00
|
|
|
unlink(file_path);
|
|
|
|
}
|
2007-10-12 03:28:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch_safe_free(file_path);
|
|
|
|
|
|
|
|
if (switch_channel_ready(channel)) {
|
|
|
|
status = switch_ivr_phrase_macro(session, VM_GOODBYE_MACRO, NULL, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define VM_DESC "voicemail"
|
|
|
|
#define VM_USAGE "[check|auth] <profile_name> <domain_name> [<id>]"
|
|
|
|
|
|
|
|
SWITCH_STANDARD_APP(voicemail_function)
|
|
|
|
{
|
|
|
|
int argc = 0;
|
2007-10-17 21:26:33 +00:00
|
|
|
char *argv[6] = { 0 };
|
2007-10-12 03:28:59 +00:00
|
|
|
char *mydata = NULL;
|
2007-11-01 11:28:26 +00:00
|
|
|
const char *profile_name = NULL;
|
|
|
|
const char *domain_name = NULL;
|
|
|
|
const char *id = NULL;
|
|
|
|
const char *auth_var = NULL;
|
2007-10-12 03:28:59 +00:00
|
|
|
int x = 0, check = 0, auth = 0;
|
|
|
|
switch_channel_t *channel;
|
|
|
|
|
|
|
|
channel = switch_core_session_get_channel(session);
|
|
|
|
assert(channel != NULL);
|
2007-10-20 00:09:41 +00:00
|
|
|
|
2007-12-06 19:51:55 +00:00
|
|
|
if (switch_dir_make_recursive(SWITCH_GLOBAL_dirs.storage_dir, SWITCH_DEFAULT_DIR_PERMS, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
2007-11-23 17:56:03 +00:00
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error creating %s\n", SWITCH_GLOBAL_dirs.storage_dir);
|
2007-10-12 03:28:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!switch_strlen_zero(data)) {
|
|
|
|
mydata = switch_core_session_strdup(session, data);
|
|
|
|
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
|
|
|
}
|
|
|
|
|
2007-10-17 21:26:33 +00:00
|
|
|
for (;;) {
|
|
|
|
if (argv[x] && !strcasecmp(argv[x], "check")) {
|
|
|
|
check++;
|
|
|
|
x++;
|
|
|
|
} else if (argv[x] && !strcasecmp(argv[x], "auth")) {
|
|
|
|
auth++;
|
|
|
|
x++;
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2007-10-12 03:28:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (argv[x]) {
|
|
|
|
profile_name = argv[x++];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argv[x]) {
|
|
|
|
domain_name = argv[x++];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argv[x]) {
|
|
|
|
id = argv[x++];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((auth_var = switch_channel_get_variable(channel, "voicemail_authorized")) && switch_true(auth_var)) {
|
|
|
|
auth = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_strlen_zero(profile_name)) {
|
|
|
|
profile_name = switch_channel_get_variable(channel, "voicemail_profile_name");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_strlen_zero(domain_name)) {
|
|
|
|
domain_name = switch_channel_get_variable(channel, "voicemail_domain_name");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_strlen_zero(id)) {
|
|
|
|
id = switch_channel_get_variable(channel, "voicemail_id");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_strlen_zero(profile_name) || switch_strlen_zero(domain_name)) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Usage: %s\n", VM_USAGE);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (check) {
|
|
|
|
voicemail_check_main(session, profile_name, domain_name, id, auth);
|
|
|
|
} else {
|
|
|
|
voicemail_leave_main(session, profile_name, domain_name, id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-12 22:08:30 +00:00
|
|
|
static void message_query_handler(switch_event_t *event)
|
|
|
|
{
|
|
|
|
char *account = switch_event_get_header(event, "message-account");
|
|
|
|
int sent = 0;
|
|
|
|
switch_event_t *new_event = NULL;
|
|
|
|
|
|
|
|
if (account) {
|
|
|
|
switch_hash_index_t *hi;
|
|
|
|
int total_new_messages = 0;
|
|
|
|
int total_saved_messages = 0;
|
|
|
|
int total_new_urgent_messages = 0;
|
|
|
|
int total_saved_urgent_messages = 0;
|
|
|
|
void *val;
|
|
|
|
vm_profile_t *profile;
|
|
|
|
char *id, *domain;
|
|
|
|
|
|
|
|
if (!strncasecmp(account, "sip:", 4)) {
|
|
|
|
id = strdup(account + 4);
|
|
|
|
} else {
|
|
|
|
id = strdup(account);
|
|
|
|
}
|
|
|
|
assert(id);
|
2007-12-14 02:09:22 +00:00
|
|
|
|
2007-10-12 22:08:30 +00:00
|
|
|
if ((domain = strchr(id, '@'))) {
|
|
|
|
*domain++ = '\0';
|
|
|
|
for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
|
|
|
switch_hash_this(hi, NULL, NULL, &val);
|
|
|
|
profile = (vm_profile_t *) val;
|
|
|
|
total_new_messages = total_saved_messages = 0;
|
|
|
|
message_count(profile, id, domain, "inbox", &total_new_messages, &total_saved_messages,
|
|
|
|
&total_new_urgent_messages, &total_saved_urgent_messages);
|
|
|
|
if (total_new_messages || total_saved_messages) {
|
|
|
|
if (switch_event_create(&new_event, SWITCH_EVENT_MESSAGE_WAITING) == SWITCH_STATUS_SUCCESS) {
|
2007-12-14 00:00:57 +00:00
|
|
|
const char *yn = "no";
|
|
|
|
if (total_new_messages || total_saved_messages || total_new_urgent_messages || total_saved_urgent_messages) {
|
|
|
|
yn = "yes";
|
|
|
|
}
|
|
|
|
switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", "%s", yn);
|
2007-10-12 22:08:30 +00:00
|
|
|
switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, "MWI-Message-Account", account);
|
|
|
|
switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)",
|
|
|
|
total_new_messages, total_saved_messages, total_new_urgent_messages, total_saved_urgent_messages);
|
|
|
|
switch_event_fire(&new_event);
|
|
|
|
sent++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_safe_free(id);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sent) {
|
|
|
|
if (switch_event_create(&new_event, SWITCH_EVENT_MESSAGE_WAITING) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", "no");
|
|
|
|
switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, "MWI-Message-Account", account);
|
|
|
|
switch_event_fire(&new_event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-11-28 19:56:25 +00:00
|
|
|
#define VOICEMAIL_SYNTAX "rss [<host> <port> <uri> <user> <domain>]"
|
|
|
|
|
|
|
|
struct holder {
|
|
|
|
vm_profile_t *profile;
|
|
|
|
switch_memory_pool_t *pool;
|
|
|
|
switch_stream_handle_t *stream;
|
|
|
|
switch_xml_t xml;
|
|
|
|
switch_xml_t x_item;
|
|
|
|
switch_xml_t x_channel;
|
|
|
|
int items;
|
|
|
|
char *user;
|
|
|
|
char *domain;
|
|
|
|
char *host;
|
|
|
|
char *port;
|
|
|
|
char *uri;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int del_callback(void *pArg, int argc, char **argv, char **columnNames)
|
|
|
|
{
|
|
|
|
if (argc > 8) {
|
|
|
|
unlink(argv[8]);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int play_callback(void *pArg, int argc, char **argv, char **columnNames)
|
|
|
|
{
|
|
|
|
switch_file_t *fd;
|
|
|
|
struct holder *holder = (struct holder *) pArg;
|
|
|
|
char *fname, *ext;
|
|
|
|
switch_size_t flen;
|
|
|
|
uint8_t chunk[1024];
|
|
|
|
const char *mime_type = "audio/inline", *new_type;
|
|
|
|
|
|
|
|
if ((fname = strrchr(argv[8], '/'))) {
|
|
|
|
fname++;
|
|
|
|
} else {
|
|
|
|
fname = argv[8];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ext = strrchr(fname, '.'))) {
|
|
|
|
ext++;
|
|
|
|
if ((new_type = switch_core_mime_ext2type(ext))) {
|
|
|
|
mime_type = new_type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (switch_file_open(&fd, argv[8], SWITCH_FOPEN_READ, SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE, holder->pool) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
flen = switch_file_get_size(fd);
|
|
|
|
holder->stream->write_function(holder->stream, "Content-type: %s\n", mime_type);
|
|
|
|
holder->stream->write_function(holder->stream, "Content-length: %ld\n\n", (long)flen);
|
|
|
|
for(;;) {
|
|
|
|
switch_status_t status;
|
|
|
|
|
|
|
|
flen = sizeof(chunk);
|
|
|
|
status = switch_file_read(fd, chunk, &flen);
|
|
|
|
if (status != SWITCH_STATUS_SUCCESS || flen == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
holder->stream->raw_write_function(holder->stream, chunk, flen);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_file_close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_play(vm_profile_t *profile, char *user, char *domain, char *file, switch_stream_handle_t *stream)
|
|
|
|
{
|
|
|
|
char *sql;
|
|
|
|
struct holder holder;
|
|
|
|
|
|
|
|
sql = switch_mprintf("update voicemail_data set read_epoch=%ld where user='%s' and domain='%s' and file_path like '%%%s'",
|
|
|
|
(long)time(NULL), user, domain, file);
|
|
|
|
|
|
|
|
vm_execute_sql(profile, sql, profile->mutex);
|
|
|
|
free(sql);
|
|
|
|
|
|
|
|
sql = switch_mprintf("select * from voicemail_data where user='%s' and domain='%s' and file_path like '%%%s'", user, domain, file);
|
|
|
|
memset(&holder, 0, sizeof(holder));
|
|
|
|
holder.profile = profile;
|
|
|
|
holder.stream = stream;
|
|
|
|
switch_core_new_memory_pool(&holder.pool);
|
|
|
|
vm_execute_sql_callback(profile, profile->mutex, sql, play_callback, &holder);
|
|
|
|
switch_core_destroy_memory_pool(&holder.pool);
|
|
|
|
switch_safe_free(sql);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void do_del(vm_profile_t *profile, char *user, char *domain, char *file, switch_stream_handle_t *stream)
|
|
|
|
{
|
|
|
|
char *sql;
|
|
|
|
struct holder holder;
|
2007-11-29 01:05:05 +00:00
|
|
|
//char *uri, *host, *port;
|
|
|
|
char *ref = NULL;
|
|
|
|
|
|
|
|
//host = port = uri = NULL;
|
2007-11-28 19:56:25 +00:00
|
|
|
|
|
|
|
if (stream->event) {
|
2007-11-29 01:05:05 +00:00
|
|
|
//host = switch_event_get_header(stream->event, "http-host");
|
|
|
|
//port = switch_event_get_header(stream->event, "http-port");
|
|
|
|
//uri = switch_event_get_header(stream->event, "http-uri");
|
|
|
|
ref = switch_event_get_header(stream->event, "http-referer");
|
2007-11-28 19:56:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sql = switch_mprintf("select * from voicemail_data where user='%s' and domain='%s' and file_path like '%%%s'", user, domain, file);
|
|
|
|
memset(&holder, 0, sizeof(holder));
|
|
|
|
holder.profile = profile;
|
|
|
|
holder.stream = stream;
|
|
|
|
vm_execute_sql_callback(profile, profile->mutex, sql, del_callback, &holder);
|
|
|
|
|
|
|
|
switch_safe_free(sql);
|
|
|
|
sql = switch_mprintf("delete from voicemail_data where user='%s' and domain='%s' and file_path like '%%%s'", user, domain, file);
|
|
|
|
vm_execute_sql(profile, sql, profile->mutex);
|
|
|
|
free(sql);
|
|
|
|
|
2007-11-29 01:05:05 +00:00
|
|
|
if (ref) {
|
2007-11-28 19:56:25 +00:00
|
|
|
stream->write_function(stream,"Content-type: text/html\n\n<h2>Message Deleted</h2>\n"
|
2007-11-29 01:05:05 +00:00
|
|
|
"<META http-equiv=\"refresh\" content=\"1;URL=%s\">", ref);
|
2007-11-28 19:56:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-11-29 01:05:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int web_callback(void *pArg, int argc, char **argv, char **columnNames)
|
|
|
|
{
|
|
|
|
struct holder *holder = (struct holder *) pArg;
|
|
|
|
char *del, *get, *fname, *ext;
|
|
|
|
switch_time_exp_t tm;
|
|
|
|
char create_date[80] = "";
|
|
|
|
char read_date[80] = "";
|
|
|
|
char rss_date[80] = "";
|
|
|
|
switch_size_t retsize;
|
|
|
|
long l_created = 0;
|
|
|
|
long l_read = 0;
|
|
|
|
long l_duration = 0;
|
|
|
|
switch_core_time_duration_t duration;
|
|
|
|
char duration_str[80];
|
|
|
|
const char *fmt = "%a, %e %b %Y %T %z";
|
|
|
|
char heard[80];
|
|
|
|
char title_b4[128] = "";
|
|
|
|
char title_aft[128*3] = "";
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
l_created = atol(argv[0]) * 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
l_read = atol(argv[1]) * 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 9) {
|
|
|
|
l_duration = atol(argv[9]) * 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ((fname = strrchr(argv[8], '/'))) {
|
|
|
|
fname++;
|
|
|
|
} else {
|
|
|
|
fname = argv[8];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ext = strrchr(fname, '.'))) {
|
|
|
|
ext++;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_core_measure_time(l_duration, &duration);
|
|
|
|
duration.day += duration.yr * 365;
|
|
|
|
duration.hr += duration.day * 24;
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u",
|
2007-11-29 01:05:05 +00:00
|
|
|
duration.hr,
|
|
|
|
duration.min,
|
|
|
|
duration.sec
|
|
|
|
);
|
|
|
|
|
|
|
|
if (l_created) {
|
|
|
|
switch_time_exp_lt(&tm, l_created);
|
|
|
|
switch_strftime(create_date, &retsize, sizeof(create_date), fmt, &tm);
|
|
|
|
switch_strftime(rss_date, &retsize, sizeof(create_date), "%D %T", &tm);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l_read) {
|
|
|
|
switch_time_exp_lt(&tm, l_read);
|
|
|
|
switch_strftime(read_date, &retsize, sizeof(read_date), fmt, &tm);
|
|
|
|
}
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(heard, sizeof(heard), *read_date == '\0' ? "never" : read_date);
|
2007-11-29 01:05:05 +00:00
|
|
|
|
|
|
|
get = switch_mprintf("http://%s:%s%s/get/%s", holder->host, holder->port, holder->uri, fname);
|
|
|
|
del = switch_mprintf("http://%s:%s%s/del/%s", holder->host, holder->port, holder->uri, fname);
|
|
|
|
|
|
|
|
holder->stream->write_function(holder->stream, "<font face=tahoma><div class=title><b>Message from %s %s</b></div><hr noshade size=1>\n",
|
|
|
|
argv[5], argv[6]);
|
|
|
|
holder->stream->write_function(holder->stream, "Priority: %s<br>\n"
|
|
|
|
"Created: %s<br>\n"
|
|
|
|
"Last Heard: %s<br>\n"
|
|
|
|
"Duration: %s<br>\n",
|
|
|
|
//"<a href=%s>Delete This Message</a><br><hr noshade size=1>",
|
|
|
|
strcmp(argv[10], URGENT_FLAG_STRING) ? "normal" : "urgent", create_date, heard, duration_str);
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(title_b4, sizeof(title_b4), "%s <%s> %s", argv[5], argv[6], rss_date);
|
2007-11-29 01:05:05 +00:00
|
|
|
switch_url_encode(title_b4, title_aft, sizeof(title_aft)-1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
holder->stream->write_function(holder->stream,
|
|
|
|
"<br><object width=550 height=15 \n"
|
|
|
|
"type=\"application/x-shockwave-flash\" \n"
|
|
|
|
"data=\"http://%s:%s/pub/slim.swf?song_url=%s&player_title=%s\">\n"
|
|
|
|
"<param name=movie value=\"http://%s:%s/pub/slim.swf?song_url=%s&player_title=%s\"></object><br><br>\n"
|
2007-11-29 01:27:48 +00:00
|
|
|
"[<a href=%s>delete</a>] [<a href=%s>download</a>] [<a href=tel:%s>call</a>] <br><br><br></font>\n",
|
|
|
|
holder->host, holder->port, get, title_aft, holder->host, holder->port, get, title_aft, del, get, argv[6]);
|
2007-11-29 01:05:05 +00:00
|
|
|
|
|
|
|
free(get);
|
|
|
|
free(del);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-28 19:56:25 +00:00
|
|
|
static int rss_callback(void *pArg, int argc, char **argv, char **columnNames)
|
|
|
|
{
|
|
|
|
struct holder *holder = (struct holder *) pArg;
|
|
|
|
switch_xml_t x_tmp, x_link;
|
2007-11-28 20:44:18 +00:00
|
|
|
char *tmp, *del, *get;
|
2007-11-28 19:56:25 +00:00
|
|
|
switch_time_exp_t tm;
|
|
|
|
char create_date[80] = "";
|
|
|
|
char read_date[80] = "";
|
|
|
|
char rss_date[80] = "";
|
|
|
|
switch_size_t retsize;
|
|
|
|
const char *mime_type = "audio/inline", *new_type;
|
|
|
|
char *ext;
|
|
|
|
char *fname;
|
|
|
|
switch_size_t flen;
|
|
|
|
switch_file_t *fd;
|
|
|
|
long l_created = 0;
|
|
|
|
long l_read = 0;
|
|
|
|
long l_duration = 0;
|
|
|
|
switch_core_time_duration_t duration;
|
|
|
|
char duration_str[80];
|
|
|
|
const char *fmt = "%a, %e %b %Y %T %z";
|
|
|
|
char heard[80];
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
l_created = atol(argv[0]) * 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
l_read = atol(argv[1]) * 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 9) {
|
|
|
|
l_duration = atol(argv[9]) * 1000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch_core_measure_time(l_duration, &duration);
|
|
|
|
duration.day += duration.yr * 365;
|
|
|
|
duration.hr += duration.day * 24;
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(duration_str, sizeof(duration_str), "%.2u:%.2u:%.2u",
|
2007-11-28 19:56:25 +00:00
|
|
|
duration.hr,
|
|
|
|
duration.min,
|
|
|
|
duration.sec
|
|
|
|
);
|
|
|
|
|
|
|
|
if (l_created) {
|
|
|
|
switch_time_exp_lt(&tm, l_created);
|
|
|
|
switch_strftime(create_date, &retsize, sizeof(create_date), fmt, &tm);
|
|
|
|
switch_strftime(rss_date, &retsize, sizeof(create_date), fmt, &tm);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (l_read) {
|
|
|
|
switch_time_exp_lt(&tm, l_read);
|
|
|
|
switch_strftime(read_date, &retsize, sizeof(read_date), fmt, &tm);
|
|
|
|
}
|
|
|
|
|
|
|
|
holder->x_item = switch_xml_add_child_d(holder->x_channel, "item", holder->items++);
|
|
|
|
|
|
|
|
x_tmp = switch_xml_add_child_d(holder->x_item, "title", 0);
|
|
|
|
tmp = switch_mprintf("Message from %s %s on %s", argv[5], argv[6], create_date);
|
|
|
|
switch_xml_set_txt_d(x_tmp, tmp);
|
|
|
|
free(tmp);
|
|
|
|
|
|
|
|
x_tmp = switch_xml_add_child_d(holder->x_item, "description", 0);
|
|
|
|
|
2007-12-12 21:53:32 +00:00
|
|
|
switch_snprintf(heard, sizeof(heard), *read_date == '\0' ? "never" : read_date);
|
2007-11-28 19:56:25 +00:00
|
|
|
|
|
|
|
if ((fname = strrchr(argv[8], '/'))) {
|
|
|
|
fname++;
|
|
|
|
} else {
|
|
|
|
fname = argv[8];
|
|
|
|
}
|
|
|
|
|
2007-11-28 20:44:18 +00:00
|
|
|
get = switch_mprintf("http://%s:%s%s/get/%s", holder->host, holder->port, holder->uri, fname);
|
2007-11-28 19:56:25 +00:00
|
|
|
del = switch_mprintf("http://%s:%s%s/del/%s", holder->host, holder->port, holder->uri, fname);
|
|
|
|
x_link = switch_xml_add_child_d(holder->x_item, "fsvm:rmlink", 0);
|
|
|
|
switch_xml_set_txt_d(x_link, del);
|
|
|
|
|
2007-11-29 01:05:05 +00:00
|
|
|
|
2007-11-28 19:56:25 +00:00
|
|
|
|
2007-11-28 20:44:18 +00:00
|
|
|
tmp = switch_mprintf("<![CDATA[Priority: %s<br>"
|
|
|
|
"Last Heard: %s<br>Duration: %s<br>"
|
|
|
|
"<a href=%s>Delete This Message</a><br>"
|
|
|
|
"]]>",
|
|
|
|
strcmp(argv[10], URGENT_FLAG_STRING) ? "normal" : "urgent", heard, duration_str, del);
|
2007-11-28 19:56:25 +00:00
|
|
|
|
|
|
|
switch_xml_set_txt_d(x_tmp, tmp);
|
|
|
|
free(tmp);
|
|
|
|
free(del);
|
|
|
|
|
2007-11-28 20:44:18 +00:00
|
|
|
|
2007-11-28 19:56:25 +00:00
|
|
|
x_tmp = switch_xml_add_child_d(holder->x_item, "pubDate", 0);
|
|
|
|
switch_xml_set_txt_d(x_tmp, rss_date);
|
|
|
|
|
|
|
|
x_tmp = switch_xml_add_child_d(holder->x_item, "itunes:duration", 0);
|
|
|
|
switch_xml_set_txt_d(x_tmp, duration_str);
|
|
|
|
|
|
|
|
|
2007-11-28 20:44:18 +00:00
|
|
|
|
2007-11-28 19:56:25 +00:00
|
|
|
|
|
|
|
x_tmp = switch_xml_add_child_d(holder->x_item, "guid", 0);
|
2007-11-28 20:44:18 +00:00
|
|
|
switch_xml_set_txt_d(x_tmp, get);
|
2007-11-28 19:56:25 +00:00
|
|
|
|
|
|
|
x_link = switch_xml_add_child_d(holder->x_item, "link", 0);
|
2007-11-28 20:44:18 +00:00
|
|
|
switch_xml_set_txt_d(x_link, get);
|
2007-11-28 19:56:25 +00:00
|
|
|
|
|
|
|
x_tmp = switch_xml_add_child_d(holder->x_item, "enclosure", 0);
|
2007-11-28 20:44:18 +00:00
|
|
|
switch_xml_set_attr_d(x_tmp, "url", get);
|
|
|
|
free(get);
|
2007-11-28 19:56:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (switch_file_open(&fd, argv[8], SWITCH_FOPEN_READ, SWITCH_FPROT_UREAD | SWITCH_FPROT_UWRITE, holder->pool) == SWITCH_STATUS_SUCCESS) {
|
|
|
|
flen = switch_file_get_size(fd);
|
|
|
|
tmp = switch_mprintf("%ld", (long) flen);
|
|
|
|
switch_xml_set_attr_d(x_tmp, "length", tmp);
|
|
|
|
free(tmp);
|
|
|
|
switch_file_close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ext = strrchr(fname, '.'))) {
|
|
|
|
ext++;
|
|
|
|
if ((new_type = switch_core_mime_ext2type(ext))) {
|
|
|
|
mime_type = new_type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch_xml_set_attr_d(x_tmp, "type", mime_type);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void do_rss(vm_profile_t *profile, char *user, char *domain, char *host, char *port, char *uri, switch_stream_handle_t *stream)
|
|
|
|
{
|
|
|
|
|
|
|
|
struct holder holder;
|
|
|
|
switch_xml_t x_tmp;
|
|
|
|
char *sql, *xmlstr;
|
|
|
|
char *tmp = NULL;
|
|
|
|
|
|
|
|
stream->write_function(stream, "Content-type: text/xml\n\n");
|
|
|
|
memset(&holder, 0, sizeof(holder));
|
|
|
|
holder.profile = profile;
|
|
|
|
holder.stream = stream;
|
|
|
|
holder.xml = switch_xml_new("rss");
|
|
|
|
holder.user = user;
|
|
|
|
holder.domain = domain;
|
|
|
|
holder.host = host;
|
|
|
|
holder.port = port;
|
|
|
|
holder.uri = uri;
|
|
|
|
|
|
|
|
switch_core_new_memory_pool(&holder.pool);
|
|
|
|
assert(holder.xml);
|
|
|
|
|
|
|
|
switch_xml_set_attr_d(holder.xml, "xmlns:itunes", "http://www.itunes.com/dtds/podcast-1.0.dtd");
|
|
|
|
switch_xml_set_attr_d(holder.xml, "xmlns:fsvm", "http://www.freeswitch.org/dtd/fsvm.dtd");
|
|
|
|
switch_xml_set_attr_d(holder.xml, "version", "2.0");
|
|
|
|
holder.x_channel = switch_xml_add_child_d(holder.xml, "channel", 0);
|
|
|
|
|
|
|
|
x_tmp = switch_xml_add_child_d(holder.x_channel, "title", 0);
|
|
|
|
tmp = switch_mprintf("FreeSWITCH Voicemail for %s@%s", user, domain);
|
|
|
|
switch_xml_set_txt_d(x_tmp, tmp);
|
|
|
|
free(tmp);
|
|
|
|
|
|
|
|
x_tmp = switch_xml_add_child_d(holder.x_channel, "link", 0);
|
|
|
|
switch_xml_set_txt_d(x_tmp, "http://www.freeswitch.org");
|
|
|
|
|
|
|
|
x_tmp = switch_xml_add_child_d(holder.x_channel, "description", 0);
|
|
|
|
switch_xml_set_txt_d(x_tmp, "http://www.freeswitch.org");
|
|
|
|
|
|
|
|
x_tmp = switch_xml_add_child_d(holder.x_channel, "ttl", 0);
|
|
|
|
switch_xml_set_txt_d(x_tmp, "15");
|
|
|
|
|
|
|
|
|
|
|
|
sql = switch_mprintf("select * from voicemail_data where user='%s' and domain='%s' order by read_flags", user, domain);
|
|
|
|
vm_execute_sql_callback(profile, profile->mutex, sql, rss_callback, &holder);
|
|
|
|
|
2007-11-30 23:45:27 +00:00
|
|
|
xmlstr = switch_xml_toxml(holder.xml, SWITCH_TRUE);
|
2007-11-28 19:56:25 +00:00
|
|
|
|
|
|
|
stream->write_function(stream, "%s", xmlstr);
|
|
|
|
|
|
|
|
switch_safe_free(sql);
|
|
|
|
switch_safe_free(xmlstr);
|
|
|
|
switch_xml_free(holder.xml);
|
|
|
|
switch_core_destroy_memory_pool(&holder.pool);
|
|
|
|
}
|
|
|
|
|
2007-11-29 01:05:05 +00:00
|
|
|
|
|
|
|
static void do_web(vm_profile_t *profile, char *user, char *domain, char *host, char *port, char *uri, switch_stream_handle_t *stream)
|
|
|
|
{
|
|
|
|
char buf[80] = "";
|
|
|
|
struct holder holder;
|
|
|
|
char *sql;
|
|
|
|
callback_t cbt = { 0 };
|
|
|
|
int ttl = 0;
|
|
|
|
|
|
|
|
stream->write_function(stream, "Content-type: text/html\n\n");
|
|
|
|
memset(&holder, 0, sizeof(holder));
|
|
|
|
holder.profile = profile;
|
|
|
|
holder.stream = stream;
|
|
|
|
holder.user = user;
|
|
|
|
holder.domain = domain;
|
|
|
|
holder.host = host;
|
|
|
|
holder.port = port;
|
|
|
|
holder.uri = uri;
|
|
|
|
|
|
|
|
|
|
|
|
if (profile->web_head) {
|
|
|
|
stream->raw_write_function(stream, (uint8_t *)profile->web_head, strlen(profile->web_head));
|
|
|
|
}
|
|
|
|
|
|
|
|
cbt.buf = buf;
|
|
|
|
cbt.len = sizeof(buf);
|
|
|
|
|
|
|
|
sql = switch_mprintf("select * from voicemail_data where user='%s' and domain='%s' order by read_flags", user, domain);
|
|
|
|
vm_execute_sql_callback(profile, profile->mutex, sql, web_callback, &holder);
|
|
|
|
switch_safe_free(sql);
|
|
|
|
|
|
|
|
sql = switch_mprintf("select count(*) from voicemail_data where user='%s' and domain='%s' order by read_flags", user, domain);
|
|
|
|
vm_execute_sql_callback(profile, profile->mutex, sql, sql2str_callback, &cbt);
|
|
|
|
switch_safe_free(sql);
|
|
|
|
|
|
|
|
ttl = atoi(buf);
|
|
|
|
stream->write_function(stream, "%d message%s<br>", ttl, ttl == 1 ? "" : "s");
|
|
|
|
|
|
|
|
if (profile->web_tail) {
|
|
|
|
stream->raw_write_function(stream, (uint8_t *)profile->web_tail, strlen(profile->web_tail));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-11-28 19:56:25 +00:00
|
|
|
SWITCH_STANDARD_API(voicemail_api_function)
|
|
|
|
{
|
|
|
|
int argc = 0;
|
|
|
|
char *mydata = NULL, *argv[6];
|
|
|
|
char *host = NULL, *port = NULL, *uri = NULL;
|
|
|
|
char *user = NULL, *domain = NULL;
|
|
|
|
int ct = 0;
|
|
|
|
vm_profile_t *profile = NULL;
|
|
|
|
char *path_info = NULL;
|
|
|
|
int rss = 0, xarg = 0;
|
|
|
|
|
2007-11-30 22:56:01 +00:00
|
|
|
if (session) {
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
2007-11-28 19:56:25 +00:00
|
|
|
if (stream->event) {
|
|
|
|
host = switch_event_get_header(stream->event, "http-host");
|
|
|
|
port = switch_event_get_header(stream->event, "http-port");
|
|
|
|
uri = switch_event_get_header(stream->event, "http-uri");
|
|
|
|
user = switch_event_get_header(stream->event, "freeswitch-user");
|
|
|
|
domain = switch_event_get_header(stream->event, "freeswitch-domain");
|
|
|
|
path_info = switch_event_get_header(stream->event, "http-path-info");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!switch_strlen_zero(cmd)) {
|
|
|
|
mydata = strdup(cmd);
|
|
|
|
assert(mydata);
|
|
|
|
argc = switch_separate_string(mydata, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc > 0) {
|
|
|
|
if (!strcasecmp(argv[0], "rss")) {
|
|
|
|
rss++;
|
|
|
|
xarg++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!host) {
|
|
|
|
if (argc - rss < 5) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
host = argv[xarg++];
|
|
|
|
port = argv[xarg++];
|
|
|
|
uri = argv[xarg++];
|
|
|
|
user = argv[xarg++];
|
|
|
|
domain = argv[xarg++];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(host && port && uri && user && domain)) {
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
profile = switch_core_hash_find(globals.profile_hash, domain);
|
|
|
|
|
|
|
|
if (!profile) {
|
|
|
|
profile = switch_core_hash_find(globals.profile_hash, "default");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!profile) {
|
|
|
|
switch_hash_index_t *hi;
|
|
|
|
void *val;
|
|
|
|
|
|
|
|
for (hi = switch_hash_first(NULL, globals.profile_hash); hi; hi = switch_hash_next(hi)) {
|
|
|
|
switch_hash_this(hi, NULL, NULL, &val);
|
|
|
|
profile = (vm_profile_t *) val;
|
2007-11-28 22:27:33 +00:00
|
|
|
if (profile) {
|
|
|
|
break;
|
|
|
|
}
|
2007-11-28 19:56:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!profile) {
|
|
|
|
stream->write_function(stream, "Can't find profile.\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (path_info) {
|
|
|
|
if (!strncasecmp(path_info, "get/", 4)) {
|
|
|
|
do_play(profile, user, domain, path_info + 4, stream);
|
|
|
|
} else if (!strncasecmp(path_info, "del/", 4)) {
|
|
|
|
do_del(profile, user, domain, path_info + 4, stream);
|
2007-11-29 01:05:05 +00:00
|
|
|
} else if (!strncasecmp(path_info, "web", 3)) {
|
|
|
|
do_web(profile, user, domain, host, port, uri, stream);
|
2007-11-28 19:56:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rss || (path_info && !strncasecmp(path_info, "rss", 3))) {
|
|
|
|
do_rss(profile, user, domain, host, port, uri, stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (host) {
|
|
|
|
if (!ct) {
|
|
|
|
stream->write_function(stream, "Content-type: text/html\n\n<h2>");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stream->write_function(stream, "Error: %s\n", VOICEMAIL_SYNTAX);
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
|
|
switch_safe_free(mydata);
|
|
|
|
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-12 03:28:59 +00:00
|
|
|
SWITCH_MODULE_LOAD_FUNCTION(mod_voicemail_load)
|
|
|
|
{
|
|
|
|
switch_application_interface_t *app_interface;
|
2007-11-28 19:56:25 +00:00
|
|
|
switch_api_interface_t *commands_api_interface;
|
2007-10-12 03:28:59 +00:00
|
|
|
switch_status_t status;
|
|
|
|
|
|
|
|
if ((status = load_config()) != SWITCH_STATUS_SUCCESS) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
/* connect my internal structure to the blank pointer passed to me */
|
|
|
|
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
|
|
|
SWITCH_ADD_APP(app_interface, "voicemail", "Voicemail", VM_DESC, voicemail_function, VM_USAGE, SAF_NONE);
|
2007-10-12 22:08:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (switch_event_bind((char *) modname, SWITCH_EVENT_MESSAGE_QUERY, SWITCH_EVENT_SUBCLASS_ANY, message_query_handler, NULL)
|
|
|
|
!= SWITCH_STATUS_SUCCESS) {
|
|
|
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
|
|
|
|
return SWITCH_STATUS_GENERR;
|
|
|
|
}
|
2007-11-28 19:56:25 +00:00
|
|
|
|
|
|
|
SWITCH_ADD_API(commands_api_interface, "voicemail", "voicemail", voicemail_api_function, VOICEMAIL_SYNTAX);
|
2007-10-12 03:28:59 +00:00
|
|
|
|
|
|
|
/* indicate that the module should continue to be loaded */
|
|
|
|
return SWITCH_STATUS_NOUNLOAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
|
|
|
* indent-tabs-mode:nil
|
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4 expandtab:
|
|
|
|
*/
|