You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
564 lines
22 KiB
564 lines
22 KiB
From: Sipwise Development Team <support@sipwise.com>
|
|
Date: Thu, 26 Sep 2024 01:07:31 +0200
|
|
Subject: sipwise_vm_add_actions_wmi
|
|
|
|
---
|
|
apps/app_voicemail.c | 297 +++++++++++++++++++++++++++++++++++++++++++++++----
|
|
1 file changed, 276 insertions(+), 21 deletions(-)
|
|
|
|
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
|
|
index 6823da2..080d378 100644
|
|
--- a/apps/app_voicemail.c
|
|
+++ b/apps/app_voicemail.c
|
|
@@ -1182,6 +1182,52 @@ static int adsiver = 1;
|
|
static char emaildateformat[32] = "%A, %B %d, %Y at %r";
|
|
static char pagerdateformat[32] = "%A, %B %d, %Y at %r";
|
|
|
|
+/* This structure is for holding all actions made per notification.
|
|
+ When accessing the voicemail multiple actions could be taken: add, read or remove(delete) a message
|
|
+*/
|
|
+typedef struct _node
|
|
+{
|
|
+ char action;
|
|
+ char id[256];
|
|
+ char callid[256];
|
|
+ int size;
|
|
+} vm_node;
|
|
+
|
|
+void vm_node_create(vm_node* node, int size);
|
|
+int vm_node_find_avail(vm_node* node);
|
|
+int vm_node_insert(vm_node* node, char action, char* id, char* callid);
|
|
+
|
|
+void vm_node_create(vm_node* node, int size) {
|
|
+ node->size = size;
|
|
+ for (int i = 0; i < size; i++)
|
|
+ {
|
|
+ node[i].action = 0;
|
|
+ memset(node[i].id, 0, sizeof(node[i].id));
|
|
+ memset(node[i].callid, 0, sizeof(node[i].callid));
|
|
+ }
|
|
+}
|
|
+
|
|
+int vm_node_find_avail(vm_node* node) {
|
|
+ int size = node->size;
|
|
+ for (int i = 0; i < size; i++) {
|
|
+ if(strlen(node[i].id) == 0) {
|
|
+ return i;
|
|
+ }
|
|
+ }
|
|
+ return -1;
|
|
+}
|
|
+
|
|
+int vm_node_insert(vm_node* node, char action, char* id, char* callid) {
|
|
+ int index = vm_node_find_avail(node);
|
|
+ if (index != -1) {
|
|
+ node[index].action = action;
|
|
+ strncpy(node[index].id, id, sizeof(node[index].id)-1);
|
|
+ strncpy(node[index].callid, callid, sizeof(node[index].callid)-1);
|
|
+ return 1; //added
|
|
+ }
|
|
+ return 0; //full
|
|
+}
|
|
+
|
|
/* Forward declarations - generic */
|
|
#ifdef ODBC_STORAGE
|
|
static struct ast_vm_user *find_user_realtime_by_alias(struct ast_vm_user *ivm, const char *context, const char *alias);
|
|
@@ -1204,9 +1250,10 @@ static void read_password_from_file(const char *secretfn, char *password, int pa
|
|
static int write_password_to_file(const char *secretfn, const char *password);
|
|
static const char *substitute_escapes(const char *value);
|
|
static int message_range_and_existence_check(struct vm_state *vms, const char *msg_ids [], size_t num_msgs, int *msg_nums, struct ast_vm_user *vmu);
|
|
-static void notify_new_state(struct ast_vm_user *vmu);
|
|
+static void notify_new_state(struct ast_vm_user *vmu, vm_node *vm_actions);
|
|
static int append_vmu_info_astman(struct mansession *s, struct ast_vm_user *vmu, const char* event_name, const char* actionid);
|
|
static int append_vmbox_info_astman(struct mansession *s, const struct message *m, struct ast_vm_user *vmu, const char* event_name, const char* actionid);
|
|
+static void get_id_callid(char *dir, int msg_num, char *msg_id, char *callid);
|
|
|
|
|
|
/*!
|
|
@@ -4866,8 +4913,8 @@ static void odbc_delete_message(const char *sdir, int smsg)
|
|
* This method is used for the COPY macro when mailboxes are stored in an ODBC back end.
|
|
*/
|
|
#define COPY_SQL_FMT "INSERT INTO %s (dir, msgnum, msg_id, context, callerid, origtime, " \
|
|
- "duration, recording, flag, mailboxuser, mailboxcontext) " \
|
|
- "SELECT ?,?,msg_id,context,callerid,origtime,duration,recording,flag,?,? " \
|
|
+ "duration, recording, flag, mailboxuser, mailboxcontext, call_id) " \
|
|
+ "SELECT ?,?,msg_id,context,callerid,origtime,duration,recording,flag,?,?,? " \
|
|
"FROM %s WHERE dir=? AND msgnum=?"
|
|
static void odbc_copy_message(char *sdir, int smsg, char *ddir, int dmsg, char *dmailboxuser, char *dmailboxcontext)
|
|
{
|
|
@@ -4875,9 +4922,11 @@ static void odbc_copy_message(char *sdir, int smsg, char *ddir, int dmsg, char *
|
|
char *sql = MAKE_SQL_PTRA2(COPY_SQL_FMT);
|
|
char msgnums[20];
|
|
char msgnumd[20];
|
|
+ char mid[256] = "";
|
|
+ char callid[256] = "";
|
|
struct odbc_obj *obj;
|
|
- char *argv[] = { ddir, msgnumd, dmailboxuser, dmailboxcontext, sdir, msgnums };
|
|
- struct generic_prepare_struct gps = { .sql = sql, .argc = 6, .argv = argv };
|
|
+ char *argv[] = { ddir, msgnumd, dmailboxuser, dmailboxcontext, callid, sdir, msgnums };
|
|
+ struct generic_prepare_struct gps = { .sql = sql, .argc = 7, .argv = argv };
|
|
SCOPE_ENTER(3, "sdir: %s smsg: %d duser: %s dcontext: %s ddir: %s dmsg: %d\n",
|
|
sdir, smsg, dmailboxuser, dmailboxcontext, ddir, dmsg);
|
|
|
|
@@ -4890,7 +4939,7 @@ static void odbc_copy_message(char *sdir, int smsg, char *ddir, int dmsg, char *
|
|
|
|
snprintf(msgnums, sizeof(msgnums), "%d", smsg);
|
|
snprintf(msgnumd, sizeof(msgnumd), "%d", dmsg);
|
|
-
|
|
+ get_id_callid(sdir, smsg, mid, callid);
|
|
stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
|
|
if (!stmt)
|
|
ast_log(AST_LOG_WARNING, "SQL Execute error!\n[%s] (You probably don't have MySQL 4.1 or later installed)\n\n", sql);
|
|
@@ -6785,8 +6834,9 @@ static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
|
|
return res;
|
|
}
|
|
|
|
-static void run_externnotify(const char *context, const char *extension, const char *flag, const char *dialed_num, int msgnum, char *cidnum, struct timeval *msg_time, int duration, char *timezonename)
|
|
+static void run_externnotify(const char *context, const char *extension, const char *flag, const char *dialed_num, int msgnum, char *cidnum, struct timeval *msg_time, int duration, char *timezonename, vm_node *vm_actions)
|
|
{
|
|
+ struct timeval timetemp;
|
|
char arguments[2048];
|
|
char date[256];
|
|
struct ast_tm tm;
|
|
@@ -6829,14 +6879,39 @@ static void run_externnotify(const char *context, const char *extension, const c
|
|
} else if (ast_strlen_zero(number) || !strcmp(extension, number)) {
|
|
ast_log(AST_LOG_WARNING, "Missing user number to run externnotify on context '%s'\n", ext_context);
|
|
} else {
|
|
- if (msg_time) {
|
|
- ast_localtime(msg_time, &tm, timezonename);
|
|
- ast_strftime(date, sizeof(date), "%Y-%m-%dT%H:%M:%S%z", &tm);
|
|
- snprintf(arguments, sizeof(arguments), "%s %s %s %s %d %d %d %d %s %s %d &",
|
|
+ int size = vm_actions->size;
|
|
+ char actions[1024];
|
|
+ memset(actions, 0, sizeof(actions));
|
|
+
|
|
+ for (int i = 0; i < size; i++)
|
|
+ {
|
|
+ if (strlen(vm_actions[i].id) > 0) {
|
|
+ char temp[301]="";
|
|
+ snprintf(temp, sizeof(temp),
|
|
+ "%c %s %s ",
|
|
+ vm_actions[i].action,
|
|
+ vm_actions[i].id,
|
|
+ strlen(vm_actions[i].callid)>0?vm_actions[i].callid:"nocallid");
|
|
+ temp[sizeof(temp) - 1] = '\0';
|
|
+ strncat(actions, temp, sizeof(actions) - strlen(actions) - 1);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ if (msg_time || actions[0] != '\0') {
|
|
+ if (!msg_time && gettimeofday(&timetemp, NULL) != -1){
|
|
+ msg_time = &timetemp;
|
|
+ }
|
|
+ if (msg_time) {
|
|
+ ast_localtime(msg_time, &tm, timezonename);
|
|
+ ast_strftime(date, sizeof(date), "%Y-%m-%dT%H:%M:%S%z", &tm);
|
|
+ } else {
|
|
+ strncpy(date, "00-00-00T00:00:00", sizeof(date));
|
|
+ }
|
|
+ snprintf(arguments, sizeof(arguments), "%s %s %s %s %d %d %d %d %s %s %d %s &",
|
|
externnotify, S_OR(context, "\"\""),
|
|
number, extension, newvoicemails,
|
|
oldvoicemails, urgentvoicemails,
|
|
- msgnum, cidnum, date, duration);
|
|
+ msgnum, (cidnum == NULL?"-1":cidnum), date, duration, actions);
|
|
} else { // original short notify + extension
|
|
snprintf(arguments, sizeof(arguments), "%s %s %s %s %d %d %d &",
|
|
externnotify, S_OR(context, "\"\""),
|
|
@@ -6921,6 +6996,9 @@ static int msg_create_from_file(struct ast_vm_recording_data *recdata)
|
|
const char *category = NULL; /* pointless for now */
|
|
char msg_id[MSG_ID_LEN];
|
|
|
|
+ vm_node messages;
|
|
+ vm_node_create(&messages, 1);
|
|
+
|
|
/* Start by checking to see if the file actually exists... */
|
|
if (!(ast_fileexists(recdata->recording_file, recdata->recording_ext, NULL))) {
|
|
ast_log(LOG_ERROR, "File: %s not found.\n", recdata->recording_file);
|
|
@@ -7174,7 +7252,9 @@ static int msg_create_from_file(struct ast_vm_recording_data *recdata)
|
|
if (send_email) { /* We tried and failed. */
|
|
ast_log(LOG_WARNING, "Failed to allocate dummy channel, email will not be sent\n");
|
|
}
|
|
- notify_new_state(recipient);
|
|
+ vm_node_insert(&messages, 'a', "", "");
|
|
+ get_id_callid(dir, msgnum, messages.id, messages.callid);
|
|
+ notify_new_state(recipient, &messages);
|
|
}
|
|
}
|
|
|
|
@@ -8669,6 +8749,74 @@ static void load_vmu_timezone(struct ast_vm_user *vmu)
|
|
return;
|
|
}
|
|
|
|
+static void get_id_callid(char *dir, int msg_num, char *msg_id, char *callid)
|
|
+{
|
|
+ int res;
|
|
+ int x = 0;
|
|
+ SQLSMALLINT colcount = 0;
|
|
+ SQLSMALLINT collen;
|
|
+ SQLSMALLINT datatype;
|
|
+ SQLSMALLINT decimaldigits;
|
|
+ SQLSMALLINT nullable;
|
|
+ SQLHSTMT stmt;
|
|
+ SQLULEN colsize;
|
|
+ SQLLEN colsize2;
|
|
+ char coltitle[256];
|
|
+ char rowdata[255];
|
|
+ char sql[PATH_MAX];
|
|
+ struct odbc_obj *obj;
|
|
+ char msg_num_str[20];
|
|
+ char *argv[] = { dir, msg_num_str };
|
|
+ struct generic_prepare_struct gps = { .sql = sql, .argc = 2, .argv = argv };
|
|
+
|
|
+ obj = ast_odbc_request_obj(odbc_database, 0);
|
|
+ if (!obj) {
|
|
+ ast_log(LOG_WARNING, "Unable to quary for CallId for message %d in %s\n", msg_num, dir);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ snprintf(msg_num_str, sizeof(msg_num_str), "%d", msg_num);
|
|
+ snprintf(sql, sizeof(sql), "SELECT id, msg_id, call_id FROM %s WHERE dir=? AND msgnum=?", odbc_table);
|
|
+ stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
|
|
+ if (!stmt) {
|
|
+ ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
|
|
+ goto bail;
|
|
+ }
|
|
+
|
|
+ res = SQLFetch(stmt);
|
|
+ if (!SQL_SUCCEEDED(res)) {
|
|
+ if (res != SQL_NO_DATA) {
|
|
+ ast_log(AST_LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
|
+ }
|
|
+ goto bail_with_handle;
|
|
+ }
|
|
+
|
|
+ res = SQLNumResultCols(stmt, &colcount);
|
|
+ if (!SQL_SUCCEEDED(res)) {
|
|
+ ast_log(AST_LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
|
|
+ goto bail_with_handle;
|
|
+ }
|
|
+
|
|
+ for (x = 0; x < colcount; x++) {
|
|
+ rowdata[0] = '\0';
|
|
+ collen = sizeof(coltitle);
|
|
+ res = SQLDescribeCol(stmt, x + 1, (unsigned char *) coltitle, sizeof(coltitle), &collen,
|
|
+ &datatype, &colsize, &decimaldigits, &nullable);
|
|
+ res = SQLGetData(stmt, x + 1, SQL_C_CHAR, rowdata, sizeof(rowdata), NULL);
|
|
+ if (strcasecmp(coltitle, "call_id") ==0) {
|
|
+ snprintf(callid, 256, "%s", rowdata);
|
|
+ } else if (strcasecmp(coltitle, "id") == 0) {
|
|
+ snprintf(msg_id, 256, "%s", rowdata);
|
|
+ }
|
|
+ }
|
|
+
|
|
+bail_with_handle:
|
|
+ SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
|
+bail:
|
|
+ ast_odbc_release_obj(obj);
|
|
+ return;
|
|
+}
|
|
+
|
|
/*!
|
|
* \brief Sends email notification that a user has a new voicemail waiting for them.
|
|
* \param chan
|
|
@@ -8692,6 +8840,9 @@ static int notify_new_message(struct ast_channel *chan, struct ast_vm_user *vmu,
|
|
struct timeval msg_time = ast_tvnow();
|
|
struct vm_zone *tz = get_vmu_timezone(vmu);
|
|
|
|
+ vm_node messages;
|
|
+ vm_node_create(&messages, 1);
|
|
+
|
|
ast_channel_lock(chan);
|
|
if ((category = pbx_builtin_getvar_helper(chan, "VM_CATEGORY"))) {
|
|
category = ast_strdupa(category);
|
|
@@ -8759,7 +8910,9 @@ static int notify_new_message(struct ast_channel *chan, struct ast_vm_user *vmu,
|
|
ast_app_inboxcount2(ext_context, &urgentmsgs, &newmsgs, &oldmsgs);
|
|
|
|
queue_mwi_event(ast_channel_uniqueid(chan), ext_context, urgentmsgs, newmsgs, oldmsgs);
|
|
- run_externnotify(vmu->context, vmu->mailbox, flag, vmu->dialed_num, msgnum, cidnum, &msg_time, duration, S_COR(tz, tz->timezone, ""));
|
|
+ vm_node_insert(&messages, 'a', "", "");
|
|
+ get_id_callid(todir, msgnum, messages.id, messages.callid);
|
|
+ run_externnotify(vmu->context, vmu->mailbox, flag, vmu->dialed_num, msgnum, cidnum, &msg_time, duration, S_COR(tz, tz->timezone, ""), &messages);
|
|
|
|
#ifdef IMAP_STORAGE
|
|
vm_delete(fn); /* Delete the file, but not the IMAP message */
|
|
@@ -12311,6 +12464,9 @@ static int vm_execmain(struct ast_channel *chan, const char *data)
|
|
int deleted = 0;
|
|
#endif
|
|
SCOPE_ENTER(3, "%s:\n", ast_channel_name(chan));
|
|
+ int mt = -1;
|
|
+ vm_node messages[50];
|
|
+ vm_node_create(messages, 50);
|
|
|
|
/* Add the vm_state to the active list and keep it active */
|
|
vms.curmsg = -1;
|
|
@@ -12510,6 +12666,11 @@ static int vm_execmain(struct ast_channel *chan, const char *data)
|
|
if (vms.lastmsg == -1) {
|
|
in_urgent = 0;
|
|
cmd = vm_browse_messages(chan, &vms, vmu);
|
|
+ if (!cmd) {
|
|
+ vm_node_insert(messages, 'r', "", "");
|
|
+ mt = vm_node_find_avail(messages);
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages[mt].id, messages[mt].callid);
|
|
+ }
|
|
res = 0;
|
|
goto out;
|
|
}
|
|
@@ -12588,6 +12749,11 @@ static int vm_execmain(struct ast_channel *chan, const char *data)
|
|
case '5': /* Play current message */
|
|
ast_test_suite_event_notify("BROWSE", "Message: browsing message %d\r\nVoicemail: %d", vms.curmsg, vms.curmsg);
|
|
cmd = vm_browse_messages(chan, &vms, vmu);
|
|
+ if (!cmd) {
|
|
+ vm_node_insert(messages, 'r', "", "");
|
|
+ mt = vm_node_find_avail(messages);
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages[mt].id, messages[mt].callid);
|
|
+ }
|
|
break;
|
|
case '2': /* Change folders */
|
|
folder_change = 1;
|
|
@@ -12683,6 +12849,11 @@ static int vm_execmain(struct ast_channel *chan, const char *data)
|
|
if (vms.curmsg > 0) {
|
|
vms.curmsg--;
|
|
cmd = SCOPE_CALL_WITH_INT_RESULT(-1, play_message, chan, vmu, &vms);
|
|
+ if (!cmd) {
|
|
+ vm_node_insert(messages, 'r', "", "");
|
|
+ mt = vm_node_find_avail(messages);
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages[mt].id, messages[mt].callid);
|
|
+ }
|
|
} else {
|
|
/* Check if we were listening to new
|
|
messages. If so, go to Urgent messages
|
|
@@ -12709,6 +12880,11 @@ static int vm_execmain(struct ast_channel *chan, const char *data)
|
|
} else if (ast_test_flag(vmu, VM_MESSAGEWRAP) && vms.lastmsg > 0) {
|
|
vms.curmsg = vms.lastmsg;
|
|
cmd = SCOPE_CALL_WITH_INT_RESULT(-1, play_message, chan, vmu, &vms);
|
|
+ if (!cmd) {
|
|
+ vm_node_insert(messages, 'r', "", "");
|
|
+ mt = vm_node_find_avail(messages);
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages[mt].id, messages[mt].callid);
|
|
+ }
|
|
} else {
|
|
cmd = ast_play_and_wait(chan, "vm-nomore");
|
|
}
|
|
@@ -12719,6 +12895,11 @@ static int vm_execmain(struct ast_channel *chan, const char *data)
|
|
if (vms.curmsg < vms.lastmsg) {
|
|
vms.curmsg++;
|
|
cmd = SCOPE_CALL_WITH_INT_RESULT(-1, play_message, chan, vmu, &vms);
|
|
+ if (!cmd) {
|
|
+ vm_node_insert(messages, 'r', "", "");
|
|
+ mt = vm_node_find_avail(messages);
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages[mt].id, messages[mt].callid);
|
|
+ }
|
|
} else {
|
|
if (in_urgent && vms.newmessages > 0) {
|
|
/* Check if we were listening to urgent
|
|
@@ -12744,6 +12925,11 @@ static int vm_execmain(struct ast_channel *chan, const char *data)
|
|
} else if (ast_test_flag(vmu, VM_MESSAGEWRAP) && vms.lastmsg > 0) {
|
|
vms.curmsg = 0;
|
|
cmd = SCOPE_CALL_WITH_INT_RESULT(-1, play_message, chan, vmu, &vms);
|
|
+ if (!cmd) {
|
|
+ vm_node_insert(messages, 'r', "", "");
|
|
+ mt = vm_node_find_avail(messages);
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages[mt].id, messages[mt].callid);
|
|
+ }
|
|
} else {
|
|
cmd = ast_play_and_wait(chan, "vm-nomore");
|
|
}
|
|
@@ -12765,6 +12951,9 @@ static int vm_execmain(struct ast_channel *chan, const char *data)
|
|
else if (play_folder == 1)
|
|
vms.oldmessages--;
|
|
cmd = ast_play_and_wait(chan, "vm-deleted");
|
|
+ vm_node_insert(messages, 'd', "", "");
|
|
+ mt = vm_node_find_avail(messages);
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages[mt].id, messages[mt].callid);
|
|
} else {
|
|
if (play_folder == 0) {
|
|
if (in_urgent) {
|
|
@@ -12776,14 +12965,27 @@ static int vm_execmain(struct ast_channel *chan, const char *data)
|
|
else if (play_folder == 1)
|
|
vms.oldmessages++;
|
|
cmd = ast_play_and_wait(chan, "vm-undeleted");
|
|
+ vm_node_insert(messages, 'u', "", "");
|
|
+ mt = vm_node_find_avail(messages);
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages[mt].id, messages[mt].callid);
|
|
}
|
|
if (ast_test_flag(vmu, VM_SKIPAFTERCMD)) {
|
|
if (vms.curmsg < vms.lastmsg) {
|
|
vms.curmsg++;
|
|
cmd = SCOPE_CALL_WITH_INT_RESULT(-1, play_message, chan, vmu, &vms);
|
|
+ if (!cmd) {
|
|
+ vm_node_insert(messages, 'r', "", "");
|
|
+ mt = vm_node_find_avail(messages);
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages[mt].id, messages[mt].callid);
|
|
+ }
|
|
} else if (ast_test_flag(vmu, VM_MESSAGEWRAP) && vms.lastmsg > 0) {
|
|
vms.curmsg = 0;
|
|
cmd = SCOPE_CALL_WITH_INT_RESULT(-1, play_message, chan, vmu, &vms);
|
|
+ if (!cmd) {
|
|
+ vm_node_insert(messages, 'r', "", "");
|
|
+ mt = vm_node_find_avail(messages);
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages[mt].id, messages[mt].callid);
|
|
+ }
|
|
} else {
|
|
/* Check if we were listening to urgent
|
|
messages. If so, go to regular new messages
|
|
@@ -12838,6 +13040,29 @@ static int vm_execmain(struct ast_channel *chan, const char *data)
|
|
} else if (cmd > 0) {
|
|
box = cmd = cmd - '0';
|
|
cmd = SCOPE_CALL_WITH_INT_RESULT(-1, save_to_folder, vmu, &vms, vms.curmsg, cmd, NULL, 0);
|
|
+ if (!cmd) {
|
|
+ switch (box) {
|
|
+ case 0: // INBOX
|
|
+ vm_node_insert(messages, 'x', "", "");
|
|
+ mt = vm_node_find_avail(messages);
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages[mt].id, messages[mt].callid);
|
|
+ break;
|
|
+ case 1: // OLD
|
|
+ vm_node_insert(messages, 'r', "", "");
|
|
+ mt = vm_node_find_avail(messages);
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages[mt].id, messages[mt].callid);
|
|
+ break;
|
|
+ case 10: // OLD
|
|
+ vm_node_insert(messages, 'd', "", "");
|
|
+ mt = vm_node_find_avail(messages);
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages[mt].id, messages[mt].callid);
|
|
+ break;
|
|
+ default:
|
|
+ vm_node_insert(messages, 'm', "", "");
|
|
+ mt = vm_node_find_avail(messages);
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages[mt].id, messages[mt].callid);
|
|
+ }
|
|
+ }
|
|
if (cmd == ERROR_LOCK_PATH) {
|
|
res = cmd;
|
|
ast_trace(-1, "save to folder: %d\n", res);
|
|
@@ -12870,9 +13095,19 @@ static int vm_execmain(struct ast_channel *chan, const char *data)
|
|
if (vms.curmsg < vms.lastmsg) {
|
|
vms.curmsg++;
|
|
cmd = SCOPE_CALL_WITH_INT_RESULT(-1, play_message, chan, vmu, &vms);
|
|
+ if (!cmd) {
|
|
+ vm_node_insert(messages, 'r', "", "");
|
|
+ mt = vm_node_find_avail(messages);
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages[mt].id, messages[mt].callid);
|
|
+ }
|
|
} else if (ast_test_flag(vmu, VM_MESSAGEWRAP) && vms.lastmsg > 0) {
|
|
vms.curmsg = 0;
|
|
cmd = SCOPE_CALL_WITH_INT_RESULT(-1, play_message, chan, vmu, &vms);
|
|
+ if (!cmd) {
|
|
+ vm_node_insert(messages, 'r', "", "");
|
|
+ mt = vm_node_find_avail(messages);
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages[mt].id, messages[mt].callid);
|
|
+ }
|
|
} else {
|
|
/* Check if we were listening to urgent
|
|
messages. If so, go to regular new messages
|
|
@@ -12995,7 +13230,7 @@ out:
|
|
int new = 0, old = 0, urgent = 0;
|
|
snprintf(ext_context, sizeof(ext_context), "%s@%s", vms.username, vmu->context);
|
|
/* Urgent flag not passwd to externnotify here */
|
|
- run_externnotify(vmu->context, vmu->mailbox, NULL, vmu->dialed_num, 0, NULL, NULL, 0, NULL);
|
|
+ run_externnotify(vmu->context, vmu->mailbox, NULL, vmu->dialed_num, 0, NULL, NULL, 0, NULL, messages);
|
|
ast_app_inboxcount2(ext_context, &urgent, &new, &old);
|
|
queue_mwi_event(ast_channel_uniqueid(chan), ext_context, urgent, new, old);
|
|
}
|
|
@@ -17196,13 +17431,13 @@ done:
|
|
return res;
|
|
}
|
|
|
|
-static void notify_new_state(struct ast_vm_user *vmu)
|
|
+static void notify_new_state(struct ast_vm_user *vmu, vm_node *vm_actions)
|
|
{
|
|
int new = 0, old = 0, urgent = 0;
|
|
char ext_context[1024];
|
|
|
|
snprintf(ext_context, sizeof(ext_context), "%s@%s", vmu->mailbox, vmu->context);
|
|
- run_externnotify(vmu->context, vmu->mailbox, NULL, vmu->dialed_num, 0, NULL, NULL, 0, NULL);
|
|
+ run_externnotify(vmu->context, vmu->mailbox, NULL, vmu->dialed_num, 0, NULL, NULL, 0, NULL, vm_actions);
|
|
ast_app_inboxcount2(ext_context, &urgent, &new, &old);
|
|
queue_mwi_event(NULL, ext_context, urgent, new, old);
|
|
}
|
|
@@ -17229,6 +17464,9 @@ static int vm_msg_forward(const char *from_mailbox,
|
|
int i;
|
|
int *msg_nums;
|
|
|
|
+ vm_node messages;
|
|
+ vm_node_create(&messages, 1);
|
|
+
|
|
if (ast_strlen_zero(from_mailbox) || ast_strlen_zero(to_mailbox)) {
|
|
ast_log(LOG_WARNING, "Cannot forward message because either the from or to mailbox was not specified\n");
|
|
return -1;
|
|
@@ -17342,7 +17580,9 @@ vm_forward_cleanup:
|
|
#endif
|
|
|
|
if (!res) {
|
|
- notify_new_state(to_vmu);
|
|
+ vm_node_insert(&messages, 'f', "", "");
|
|
+ get_id_callid(from_vms.curdir, from_vms.curmsg, messages.id, messages.callid);
|
|
+ notify_new_state(to_vmu, (vm_node*) NULL);
|
|
}
|
|
|
|
free_user(vmu);
|
|
@@ -17366,6 +17606,9 @@ static int vm_msg_move(const char *mailbox,
|
|
int i;
|
|
int *old_msg_nums;
|
|
|
|
+ vm_node messages;
|
|
+ vm_node_create(&messages, 1);
|
|
+
|
|
if (ast_strlen_zero(mailbox)) {
|
|
ast_log(LOG_WARNING, "Cannot move message because no mailbox was specified\n");
|
|
return -1;
|
|
@@ -17447,7 +17690,9 @@ vm_move_cleanup:
|
|
#endif
|
|
|
|
if (!res) {
|
|
- notify_new_state(vmu);
|
|
+ vm_node_insert(&messages, 'm', "", "");
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages.id, messages.callid);
|
|
+ notify_new_state(vmu, &messages);
|
|
}
|
|
|
|
free_user(vmu);
|
|
@@ -17468,6 +17713,9 @@ static int vm_msg_remove(const char *mailbox,
|
|
int i;
|
|
int *msg_nums;
|
|
|
|
+ vm_node messages;
|
|
+ vm_node_create(&messages, 1);
|
|
+
|
|
if (ast_strlen_zero(mailbox)) {
|
|
ast_log(LOG_WARNING, "Cannot remove message because no mailbox was specified\n");
|
|
return -1;
|
|
@@ -17545,7 +17793,9 @@ vm_remove_cleanup:
|
|
#endif
|
|
|
|
if (!res) {
|
|
- notify_new_state(vmu);
|
|
+ vm_node_insert(&messages, 'd', "", "");
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages.id, messages.callid);
|
|
+ notify_new_state(vmu, &messages);
|
|
}
|
|
|
|
free_user(vmu);
|
|
@@ -17570,6 +17820,9 @@ static int vm_msg_play(struct ast_channel *chan,
|
|
int duration = 0;
|
|
const char *value;
|
|
|
|
+ vm_node messages;
|
|
+ vm_node_create(&messages, 1);
|
|
+
|
|
if (ast_strlen_zero(mailbox)) {
|
|
ast_log(LOG_WARNING, "Cannot play message because no mailbox was specified\n");
|
|
return -1;
|
|
@@ -17659,7 +17912,9 @@ play2_msg_cleanup:
|
|
#endif
|
|
|
|
if (!res) {
|
|
- notify_new_state(vmu);
|
|
+ vm_node_insert(&messages, 'r', "", "");
|
|
+ get_id_callid(vms.curdir, vms.curmsg, messages.id, messages.callid);
|
|
+ notify_new_state(vmu, &messages);
|
|
}
|
|
|
|
free_user(vmu);
|