[asterisk-commits] mmichelson: branch mmichelson/trunk-digiumphones r363308 - in /team/mmichelso...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Apr 23 15:59:40 CDT 2012
Author: mmichelson
Date: Mon Apr 23 15:59:36 2012
New Revision: 363308
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=363308
Log:
Change Voicemail APIs to use unique message IDs instead of message indexes.
This is not the most efficient operation since messages have to be retrieved
from their storage medium and then read from the file system to be searched. It
would be more efficient to have an in-memory store of the voicemail's current state.
However, doing so is a *HUGE* undertaking, much larger than anything we would be
comfortable adding to Asterisk 11.
In addition, the voicemail API tests have been updated to pass with these API
changes.
Modified:
team/mmichelson/trunk-digiumphones/apps/app_voicemail.c
team/mmichelson/trunk-digiumphones/include/asterisk/app_voicemail.h
team/mmichelson/trunk-digiumphones/tests/test_voicemail_api.c
Modified: team/mmichelson/trunk-digiumphones/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/apps/app_voicemail.c?view=diff&rev=363308&r1=363307&r2=363308
==============================================================================
--- team/mmichelson/trunk-digiumphones/apps/app_voicemail.c (original)
+++ team/mmichelson/trunk-digiumphones/apps/app_voicemail.c Mon Apr 23 15:59:36 2012
@@ -14742,43 +14742,62 @@
*
* \details
* This is called by ast_vm_msg_move, ast_vm_msg_remove, and ast_vm_msg_forward to
- * ensure that data passed in are valid. This tests the following:
- *
- * 1. No negative indexes are given.
- * 2. No index greater than the highest message index for the folder is given.
- * 3. All message indexes given point to messages that exist.
+ * ensure that data passed in are valid. This ensures that given the
+ * desired message IDs, they can be found.
*
* \param vms The voicemail state corresponding to an open mailbox
* \param msg_ids An array of message identifiers
* \param num_msgs The number of identifiers in msg_ids
+ * \param msg_nums [out] The message indexes corresponding to the given
+ * message IDs
+ * \pre vms must have open_mailbox() called on it prior to this function.
*
* \retval -1 Failure
* \retval 0 Success
*/
-static int message_range_and_existence_check(struct vm_state *vms, int *msg_ids, size_t num_msgs)
+static int message_range_and_existence_check(struct vm_state *vms, const char *msg_ids [], size_t num_msgs, int *msg_nums)
{
int i;
int res = 0;
for (i = 0; i < num_msgs; ++i) {
- int cur_msg = msg_ids[i];
- if (cur_msg < 0) {
- ast_log(LOG_WARNING, "Message has negative index\n");
+ const char *msg_id = msg_ids[i];
+ int found = 0;
+ for (vms->curmsg = 0; vms->curmsg <= vms->lastmsg; vms->curmsg++) {
+ const char *other_msg_id;
+ char filename[PATH_MAX];
+ struct ast_config *msg_cfg;
+ struct ast_flags config_flags = { CONFIG_FLAG_NOCACHE };
+
+ make_file(vms->fn, sizeof(vms->fn), vms->curdir, vms->curmsg);
+ snprintf(filename, sizeof(filename), "%s.txt", vms->fn);
+ RETRIEVE(vms->curdir, vms->curmsg, vmu->mailbox, vmu->context);
+ msg_cfg = ast_config_load(filename, config_flags);
+ if (!msg_cfg || msg_cfg == CONFIG_STATUS_FILEINVALID) {
+ DISPOSE(vms->curdir, vms->curmsg);
+ res = -1;
+ goto done;
+ }
+
+ other_msg_id = ast_variable_retrieve(msg_cfg, "message", "msg_id");
+
+ if (!ast_strlen_zero(other_msg_id) && !strcmp(other_msg_id, msg_id)) {
+ /* Message found. We can get out of this inner loop
+ * and move on to the next message to find
+ */
+ found = 1;
+ msg_nums[i] = vms->curmsg;
+ ast_config_destroy(msg_cfg);
+ break;
+ }
+ }
+ if (!found) {
+ /* If we can't find one of the message IDs requested, then OH NO! */
res = -1;
- break;
- }
- if (vms->lastmsg < cur_msg) {
- ast_log(LOG_WARNING, "Message %d is out of range. Last message is %d\n", cur_msg, vms->lastmsg);
- res = -1;
- break;
- }
- make_file(vms->fn, sizeof(vms->fn), vms->curdir, cur_msg);
- if (!EXISTS(vms->curdir, cur_msg, vms->fn, NULL)) {
- ast_log(LOG_WARNING, "Message %d does not exist.\n", cur_msg);
- res = -1;
- break;
- }
- }
-
+ goto done;
+ }
+ }
+
+done:
return res;
}
@@ -14800,7 +14819,7 @@
const char *to_context,
const char *to_folder,
size_t num_msgs,
- int *msg_ids,
+ const char *msg_ids [],
int delete_old)
{
struct vm_state from_vms;
@@ -14813,6 +14832,7 @@
int open = 0;
int res = 0;
int i;
+ int *msg_nums;
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");
@@ -14871,13 +14891,15 @@
goto vm_forward_cleanup;
}
- if ((res = message_range_and_existence_check(&from_vms, msg_ids, num_msgs) < 0)) {
+ msg_nums = alloca(sizeof(int) * num_msgs);
+
+ if ((res = message_range_and_existence_check(&from_vms, msg_ids, num_msgs, msg_nums) < 0)) {
goto vm_forward_cleanup;
}
/* Now we actually forward the messages */
for (i = 0; i < num_msgs; i++) {
- int cur_msg = msg_ids[i];
+ int cur_msg = msg_nums[i];
int duration = 0;
const char *value;
@@ -14934,9 +14956,8 @@
const char *context,
size_t num_msgs,
const char *oldfolder,
- int *old_msg_nums,
- const char *newfolder,
- int *new_msg_nums)
+ const char *old_msg_ids [],
+ const char *newfolder)
{
struct vm_state vms;
struct ast_vm_user *vmu = NULL, vmus;
@@ -14945,6 +14966,7 @@
int open = 0;
int res = 0;
int i;
+ int *old_msg_nums;
if (ast_strlen_zero(mailbox)) {
ast_log(LOG_WARNING, "Cannot move message because no mailbox was specified\n");
@@ -14988,13 +15010,20 @@
open = 1;
- if ((res = message_range_and_existence_check(&vms, old_msg_nums, num_msgs)) < 0) {
+ if ((vms.lastmsg + 1) < num_msgs) {
+ ast_log(LOG_WARNING, "Folder %s has less than %zu messages\n", oldfolder, num_msgs);
+ res = -1;
+ goto vm_move_cleanup;
+ }
+
+ old_msg_nums = alloca(sizeof(int) * num_msgs);
+ if ((res = message_range_and_existence_check(&vms, old_msg_ids, num_msgs, old_msg_nums)) < 0) {
goto vm_move_cleanup;
}
/* Now actually move the message */
for (i = 0; i < num_msgs; ++i) {
- if (save_to_folder(vmu, &vms, old_msg_nums[i], new_folder_index, new_msg_nums ? (new_msg_nums + i) : NULL)) {
+ if (save_to_folder(vmu, &vms, old_msg_nums[i], new_folder_index, NULL)) {
res = -1;
goto vm_move_cleanup;
}
@@ -15029,7 +15058,7 @@
const char *context,
size_t num_msgs,
const char *folder,
- int *msgs)
+ const char *msgs[])
{
struct vm_state vms;
struct ast_vm_user *vmu = NULL, vmus;
@@ -15037,6 +15066,7 @@
int open = 0;
int res = 0;
int i;
+ int *msg_nums;
if (ast_strlen_zero(mailbox)) {
ast_log(LOG_WARNING, "Cannot remove message because no mailbox was specified\n");
@@ -15086,12 +15116,13 @@
goto vm_remove_cleanup;
}
- if ((res = message_range_and_existence_check(&vms, msgs, num_msgs)) < 0) {
+ msg_nums = alloca(sizeof(int) * num_msgs);
+ if ((res = message_range_and_existence_check(&vms, msgs, num_msgs, msg_nums)) < 0) {
goto vm_remove_cleanup;
}
for (i = 0; i < num_msgs; i++) {
- vms.deleted[msgs[i]] = 1;
+ vms.deleted[msg_nums[i]] = 1;
}
/* close mailbox */
@@ -15131,7 +15162,7 @@
const char *mailbox,
const char *context,
const char *folder,
- const char *msg_num,
+ const char *msg_id,
ast_vm_msg_play_cb cb)
{
struct vm_state vms;
@@ -15155,7 +15186,7 @@
return -1;
}
- if (ast_strlen_zero(msg_num)) {
+ if (ast_strlen_zero(msg_id)) {
ast_log(LOG_WARNING, "Cannot play message because no message number was specified\n");
return -1;
}
@@ -15180,8 +15211,7 @@
}
open = 1;
- vms.curmsg = atoi(msg_num);
- if (vms.curmsg > vms.lastmsg || vms.curmsg < 0) {
+ if (message_range_and_existence_check(&vms, &msg_id, 1, &vms.curmsg)) {
res = -1;
goto play2_msg_cleanup;
}
Modified: team/mmichelson/trunk-digiumphones/include/asterisk/app_voicemail.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/include/asterisk/app_voicemail.h?view=diff&rev=363308&r1=363307&r2=363308
==============================================================================
--- team/mmichelson/trunk-digiumphones/include/asterisk/app_voicemail.h (original)
+++ team/mmichelson/trunk-digiumphones/include/asterisk/app_voicemail.h Mon Apr 23 15:59:36 2012
@@ -105,9 +105,8 @@
const char *context,
size_t num_msgs,
const char *oldfolder,
- int *old_msg_ids,
- const char *newfolder,
- int *new_msg_ids);
+ const char *old_msg_ids [],
+ const char *newfolder);
/*!
* \brief Remove/delete messages from a mailbox folder.
@@ -125,7 +124,7 @@
const char *context,
size_t num_msgs,
const char *folder,
- int *msgs);
+ const char *msgs []);
/*!
* \brief forward a message from one mailbox to another.
@@ -151,7 +150,7 @@
const char *to_context,
const char *to_folder,
size_t num_msgs,
- int *msg_ids,
+ const char *msg_ids [],
int delete_old);
/*!
@@ -179,7 +178,7 @@
const char *mailbox,
const char *context,
const char *folder,
- const char *msg_num,
+ const char *msg_id,
ast_vm_msg_play_cb cb);
/*!
Modified: team/mmichelson/trunk-digiumphones/tests/test_voicemail_api.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/trunk-digiumphones/tests/test_voicemail_api.c?view=diff&rev=363308&r1=363307&r2=363308
==============================================================================
--- team/mmichelson/trunk-digiumphones/tests/test_voicemail_api.c (original)
+++ team/mmichelson/trunk-digiumphones/tests/test_voicemail_api.c Mon Apr 23 15:59:36 2012
@@ -168,8 +168,8 @@
} } while (0)
/*! \internal \brief Move a voicemail message, failing the test if the message could not be moved */
-#define VM_API_MOVE_MESSAGE(mailbox, context, number_of_messages, source, message_numbers_in, dest, message_numbers_out) do { \
- if (ast_vm_msg_move((mailbox), (context), (number_of_messages), (source), (message_numbers_in), (dest), (message_numbers_out))) { \
+#define VM_API_MOVE_MESSAGE(mailbox, context, number_of_messages, source, message_numbers_in, dest) do { \
+ if (ast_vm_msg_move((mailbox), (context), (number_of_messages), (source), (message_numbers_in), (dest))) { \
ast_test_status_update(test, "Failed to move message %s@%s from %s to %s\n", \
(mailbox) ? (mailbox): "(NULL)", (context) ? (context) : "(NULL)", (source) ? (source) : "(NULL)", (dest) ? (dest) : "(NULL)"); \
VM_API_TEST_CLEANUP; \
@@ -177,8 +177,8 @@
} } while (0)
/*! \internal \brief Attempt to move a voicemail message, failing the test if the message could be moved */
-#define VM_API_MOVE_MESSAGE_OFF_NOMINAL(mailbox, context, number_of_messages, source, message_numbers_in, dest, message_numbers_out) do { \
- if (!ast_vm_msg_move((mailbox), (context), (number_of_messages), (source), (message_numbers_in), (dest), (message_numbers_out))) { \
+#define VM_API_MOVE_MESSAGE_OFF_NOMINAL(mailbox, context, number_of_messages, source, message_numbers_in, dest) do { \
+ if (!ast_vm_msg_move((mailbox), (context), (number_of_messages), (source), (message_numbers_in), (dest))) { \
ast_test_status_update(test, "Succeeded to move message %s@%s from %s to %s when we really shouldn't\n", \
(mailbox) ? (mailbox): "(NULL)", (context) ? (context) : "(NULL)", (source) ? (source) : "(NULL)", (dest) ? (dest) : "(NULL)"); \
VM_API_TEST_CLEANUP; \
@@ -840,9 +840,9 @@
AST_TEST_DEFINE(voicemail_api_nominal_move)
{
struct ast_vm_mailbox_snapshot *test_mbox_snapshot = NULL;
- int single_msg_nums[] = { 0, };
- int multi_msg_nums[] = { 0, 1, };
- int output_msg_nums[] = { -1, -1, };
+ const char *inbox_msg_id;
+ const char *old_msg_id;
+ const char *multi_msg_ids[2];
switch (cmd) {
case TEST_INIT:
@@ -859,20 +859,23 @@
}
VM_API_TEST_SETUP;
+ old_msg_id = test_snapshots[0]->msg_id;
+ inbox_msg_id = test_snapshots[1]->msg_id;
+
+ multi_msg_ids[0] = test_snapshots[2]->msg_id;
+ multi_msg_ids[1] = test_snapshots[3]->msg_id;
ast_test_status_update(test, "Test move of test_vm_api_1234 message from INBOX to Family\n");
- VM_API_MOVE_MESSAGE("test_vm_api_1234", "default", 1, "INBOX", single_msg_nums, "Family", output_msg_nums);
- VM_API_INT_VERIFY(output_msg_nums[0], 0);
+ VM_API_MOVE_MESSAGE("test_vm_api_1234", "default", 1, "INBOX", &inbox_msg_id, "Family");
ast_test_status_update(test, "Test move of test_vm_api_1234 message from Old to Family\n");
- VM_API_MOVE_MESSAGE("test_vm_api_1234", NULL, 1, "Old", single_msg_nums, "Family", output_msg_nums);
+ VM_API_MOVE_MESSAGE("test_vm_api_1234", NULL, 1, "Old", &old_msg_id, "Family");
/* Take a snapshot and update the test snapshots for verification */
VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "Family", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
test_vm_api_update_test_snapshots(test_mbox_snapshot);
test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
- VM_API_INT_VERIFY(output_msg_nums[0], 1);
VM_API_STRING_FIELD_VERIFY(test_snapshots[0]->folder_name, "Family");
VM_API_STRING_FIELD_VERIFY(test_snapshots[1]->folder_name, "Family");
VM_API_INT_VERIFY(test_snapshots[1]->msg_number, 0);
@@ -880,20 +883,18 @@
/* Move both of the 2345 messages to Family */
ast_test_status_update(test, "Test move of test_vm_api_2345 messages from Inbox to Family\n");
- VM_API_MOVE_MESSAGE("test_vm_api_2345", "default", 2, "INBOX", multi_msg_nums, "Family", output_msg_nums);
+ VM_API_MOVE_MESSAGE("test_vm_api_2345", "default", 2, "INBOX", multi_msg_ids, "Family");
/* Take a snapshot and update the test snapshots for verification */
VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "Family", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
test_vm_api_update_test_snapshots(test_mbox_snapshot);
test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
- VM_API_INT_VERIFY(output_msg_nums[0], 0);
- VM_API_INT_VERIFY(output_msg_nums[1], 1);
VM_API_STRING_FIELD_VERIFY(test_snapshots[2]->folder_name, "Family");
VM_API_STRING_FIELD_VERIFY(test_snapshots[3]->folder_name, "Family");
ast_test_status_update(test, "Test move of test_vm_api_2345 message from Family to INBOX\n");
- VM_API_MOVE_MESSAGE("test_vm_api_2345", "default", 2, "Family", multi_msg_nums, "INBOX", NULL);
+ VM_API_MOVE_MESSAGE("test_vm_api_2345", "default", 2, "Family", multi_msg_ids, "INBOX");
VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
test_vm_api_update_test_snapshots(test_mbox_snapshot);
@@ -909,8 +910,8 @@
AST_TEST_DEFINE(voicemail_api_off_nominal_move)
{
- int single_msg_nums[] = { 0, };
- int multi_msg_nums[] = { 0, 1, 2, 3};
+ const char *inbox_msg_id;
+ const char *multi_msg_ids[4];
switch (cmd) {
case TEST_INIT:
@@ -933,43 +934,50 @@
VM_API_TEST_SETUP;
+ inbox_msg_id = test_snapshots[1]->msg_id;
+
+ multi_msg_ids[0] = test_snapshots[0]->msg_id;
+ multi_msg_ids[1] = test_snapshots[1]->msg_id;
+ multi_msg_ids[2] = test_snapshots[2]->msg_id;
+ multi_msg_ids[3] = test_snapshots[3]->msg_id;
+
ast_test_status_update(test, "Test move attempt for invalid mailbox test_vm_3456\n");
- VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_3456", "default", 1, "INBOX", single_msg_nums, "Family", NULL);
-
- VM_API_MOVE_MESSAGE_OFF_NOMINAL(NULL, "default", 1, "INBOX", single_msg_nums, "Family", NULL);
+ VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_3456", "default", 1, "INBOX", &inbox_msg_id, "Family");
+
+ VM_API_MOVE_MESSAGE_OFF_NOMINAL(NULL, "default", 1, "INBOX", &inbox_msg_id, "Family");
ast_test_status_update(test, "Test move attempt for invalid context test_vm_api_defunct\n");
- VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "test_vm_api_defunct", 1, "INBOX", single_msg_nums, "Family", NULL);
+ VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "test_vm_api_defunct", 1, "INBOX", &inbox_msg_id, "Family");
ast_test_status_update(test, "Test move attempt to invalid folder\n");
- VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", single_msg_nums, "SPAMALOT", NULL);
+ VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", &inbox_msg_id, "SPAMALOT");
ast_test_status_update(test, "Test move attempt from invalid folder\n");
- VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "MEATINACAN", single_msg_nums, "Family", NULL);
+ VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "MEATINACAN", &inbox_msg_id, "Family");
ast_test_status_update(test, "Test move attempt to NULL folder\n");
- VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", single_msg_nums, NULL, NULL);
+ VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", &inbox_msg_id, NULL);
ast_test_status_update(test, "Test move attempt from NULL folder\n");
- VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, NULL, single_msg_nums, "Family", NULL);
+ VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, NULL, &inbox_msg_id, "Family");
ast_test_status_update(test, "Test move attempt with non-existent message number\n");
- single_msg_nums[0] = 6;
- VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", single_msg_nums, "Family", NULL);
+ inbox_msg_id = "6";
+ VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", &inbox_msg_id, "Family");
ast_test_status_update(test, "Test move attempt with invalid message number\n");
- single_msg_nums[0] = -4;
- VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", single_msg_nums, "Family", NULL);
+ inbox_msg_id = "";
+ VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", &inbox_msg_id, "Family");
ast_test_status_update(test, "Test move attempt with 0 number of messages\n");
- single_msg_nums[0] = 0;
- VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 0, "INBOX", single_msg_nums, "Family", NULL);
+ inbox_msg_id = test_snapshots[1]->msg_id;
+ VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 0, "INBOX", &inbox_msg_id, "Family");
ast_test_status_update(test, "Test move attempt with invalid number of messages\n");
- VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", -30, "INBOX", single_msg_nums, "Family", NULL);
+ VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", -30, "INBOX", &inbox_msg_id, "Family");
ast_test_status_update(test, "Test move attempt with non-existent multiple messages, where some messages exist\n");
- VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 4, "INBOX", multi_msg_nums, "Family", NULL);
+ VM_API_MOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 4, "INBOX", multi_msg_ids, "Family");
VM_API_TEST_CLEANUP;
@@ -979,8 +987,9 @@
AST_TEST_DEFINE(voicemail_api_nominal_remove)
{
struct ast_vm_mailbox_snapshot *test_mbox_snapshot = NULL;
- int single_msg_nums[] = { 0, };
- int multi_msg_nums[] = { 0, 1, };
+ const char *inbox_msg_id;
+ const char *old_msg_id;
+ const char *multi_msg_ids[2];
switch (cmd) {
case TEST_INIT:
@@ -997,14 +1006,20 @@
VM_API_TEST_SETUP;
+ old_msg_id = test_snapshots[0]->msg_id;
+ inbox_msg_id = test_snapshots[1]->msg_id;
+
+ multi_msg_ids[0] = test_snapshots[2]->msg_id;
+ multi_msg_ids[1] = test_snapshots[3]->msg_id;
+
ast_test_status_update(test, "Test removing a single message from INBOX\n");
- VM_API_REMOVE_MESSAGE("test_vm_api_1234", "default", 1, "INBOX", single_msg_nums);
+ VM_API_REMOVE_MESSAGE("test_vm_api_1234", "default", 1, "INBOX", &inbox_msg_id);
ast_test_status_update(test, "Test removing a single message from Old\n");
- VM_API_REMOVE_MESSAGE("test_vm_api_1234", "default", 1, "Old", single_msg_nums);
+ VM_API_REMOVE_MESSAGE("test_vm_api_1234", "default", 1, "Old", &old_msg_id);
ast_test_status_update(test, "Test removing multiple messages from INBOX\n");
- VM_API_REMOVE_MESSAGE("test_vm_api_2345", "default", 2, "INBOX", multi_msg_nums);
+ VM_API_REMOVE_MESSAGE("test_vm_api_2345", "default", 2, "INBOX", multi_msg_ids);
VM_API_TEST_CLEANUP;
@@ -1013,9 +1028,9 @@
AST_TEST_DEFINE(voicemail_api_off_nominal_remove)
{
- int single_msg_nums[] = { 0, };
- int multi_msg_nums[] = { 0, 1, };
- int empty_msg_nums[] = { };
+ const char *inbox_msg_id;
+ const char *multi_msg_ids[2];
+ const char *empty_msg_ids[] = { };
switch (cmd) {
case TEST_INIT:
@@ -1038,34 +1053,38 @@
VM_API_TEST_SETUP;
+ inbox_msg_id = test_snapshots[1]->msg_id;
+ multi_msg_ids[0] = test_snapshots[2]->msg_id;
+ multi_msg_ids[1] = test_snapshots[3]->msg_id;
+
ast_test_status_update(test, "Test removing a single message with an invalid mailbox\n");
- VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_3456", "default", 1, "INBOX", single_msg_nums);
+ VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_3456", "default", 1, "INBOX", &inbox_msg_id);
ast_test_status_update(test, "Test removing a single message with a NULL mailbox\n");
- VM_API_REMOVE_MESSAGE_OFF_NOMINAL(NULL, "default", 1, "INBOX", single_msg_nums);
+ VM_API_REMOVE_MESSAGE_OFF_NOMINAL(NULL, "default", 1, "INBOX", &inbox_msg_id);
ast_test_status_update(test, "Test removing a single message with an invalid context\n");
- VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "defunct", 1, "INBOX", single_msg_nums);
+ VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "defunct", 1, "INBOX", &inbox_msg_id);
ast_test_status_update(test, "Test removing a single message with an invalid folder\n");
- VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "SPAMINACAN", single_msg_nums);
+ VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "SPAMINACAN", &inbox_msg_id);
ast_test_status_update(test, "Test removing a single message with a NULL folder\n");
- VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, NULL, single_msg_nums);
+ VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, NULL, &inbox_msg_id);
ast_test_status_update(test, "Test removing a single message with an invalid message number\n");
- single_msg_nums[0] = 6;
- VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", single_msg_nums);
+ inbox_msg_id = "POOPOO";
+ VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 1, "INBOX", &inbox_msg_id);
ast_test_status_update(test, "Test removing multiple messages with a single invalid message number\n");
- multi_msg_nums[1] = 6;
- VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_2345", "default", 2, "INBOX", multi_msg_nums);
+ multi_msg_ids[1] = "POOPOO";
+ VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_2345", "default", 2, "INBOX", multi_msg_ids);
ast_test_status_update(test, "Test removing no messages with no message numbers\n");
- VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 0, "INBOX", empty_msg_nums);
+ VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", 0, "INBOX", empty_msg_ids);
ast_test_status_update(test, "Test removing multiple messages with an invalid size specifier\n");
- VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_2345", "default", -30, "INBOX", multi_msg_nums);
+ VM_API_REMOVE_MESSAGE_OFF_NOMINAL("test_vm_api_2345", "default", -30, "INBOX", multi_msg_ids);
VM_API_TEST_CLEANUP;
@@ -1075,8 +1094,9 @@
AST_TEST_DEFINE(voicemail_api_nominal_forward)
{
struct ast_vm_mailbox_snapshot *test_mbox_snapshot = NULL;
- int single_msg_nums[] = { 0, };
- int multi_msg_nums[] = { 0, 1, };
+ const char *inbox_msg_id;
+ const char *old_msg_id;
+ const char *multi_msg_ids[2];
switch (cmd) {
case TEST_INIT:
@@ -1093,8 +1113,14 @@
VM_API_TEST_SETUP;
+ old_msg_id = test_snapshots[0]->msg_id;
+ inbox_msg_id = test_snapshots[1]->msg_id;
+
+ multi_msg_ids[0] = test_snapshots[2]->msg_id;
+ multi_msg_ids[1] = test_snapshots[3]->msg_id;
+
ast_test_status_update(test, "Test forwarding message 0 from test_vm_api_1234 INBOX to test_vm_api_2345 INBOX\n");
- VM_API_FORWARD_MESSAGE("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "INBOX", 1, single_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "INBOX", 1, &inbox_msg_id, 0);
/* Make sure we didn't delete the message */
VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
@@ -1107,7 +1133,7 @@
test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
ast_test_status_update(test, "Test forwarding message 0 from test_vm_api_1234 INBOX with default context to test_vm_api_2345 INBOX\n");
- VM_API_FORWARD_MESSAGE("test_vm_api_1234", NULL, "INBOX", "test_vm_api_2345", "default", "INBOX", 1, single_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE("test_vm_api_1234", NULL, "INBOX", "test_vm_api_2345", "default", "INBOX", 1, &inbox_msg_id, 0);
/* Make sure we didn't delete the message */
VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
@@ -1120,7 +1146,7 @@
test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
ast_test_status_update(test, "Test forwarding message 0 from test_vm_api_1234 INBOX to test_vm_api_2345 INBOX with default context\n");
- VM_API_FORWARD_MESSAGE("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", NULL, "INBOX", 1, single_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", NULL, "INBOX", 1, &inbox_msg_id, 0);
/* Make sure we didn't delete the message */
VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
@@ -1133,7 +1159,7 @@
test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
ast_test_status_update(test, "Test forwarding message 0 from test_vm_api_1234 INBOX to test_vm_api_2345 INBOX, deleting original\n");
- VM_API_FORWARD_MESSAGE("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", NULL, "INBOX", 1, single_msg_nums, 1);
+ VM_API_FORWARD_MESSAGE("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", NULL, "INBOX", 1, &inbox_msg_id, 1);
/* Make sure we deleted the message */
VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
@@ -1146,7 +1172,7 @@
test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
ast_test_status_update(test, "Test forwarding 2 messages from test_vm_api_2345 INBOX to test_vm_api_1234 INBOX");
- VM_API_FORWARD_MESSAGE("test_vm_api_2345", "default", "INBOX", "test_vm_api_1234", "default", "INBOX", 2, multi_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE("test_vm_api_2345", "default", "INBOX", "test_vm_api_1234", "default", "INBOX", 2, multi_msg_ids, 0);
/* Make sure we didn't delete the messages */
VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
@@ -1159,7 +1185,7 @@
test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
ast_test_status_update(test, "Test forwarding 2 messages from test_vm_api_2345 INBOX to test_vm_api_1234 Family, deleting original\n");
- VM_API_FORWARD_MESSAGE("test_vm_api_2345", "default", "INBOX", "test_vm_api_1234", "default", "Family", 2, multi_msg_nums, 1);
+ VM_API_FORWARD_MESSAGE("test_vm_api_2345", "default", "INBOX", "test_vm_api_1234", "default", "Family", 2, multi_msg_ids, 1);
/* Make sure we deleted the messages */
VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 4);
@@ -1177,10 +1203,10 @@
AST_TEST_DEFINE(voicemail_api_off_nominal_forward)
{
- int single_msg_nums[] = { 0, };
- int multi_msg_nums[] = { 0, 1, 2, 3};
-
- int empty_msg_nums[] = { };
+ const char *inbox_msg_id;
+ const char *multi_msg_ids[4];
+
+ const char *empty_msg_ids[] = { };
switch (cmd) {
case TEST_INIT:
@@ -1204,49 +1230,56 @@
VM_API_TEST_SETUP;
+ inbox_msg_id = test_snapshots[1]->msg_id;
+
+ multi_msg_ids[0] = test_snapshots[0]->msg_id;
+ multi_msg_ids[1] = test_snapshots[1]->msg_id;
+ multi_msg_ids[2] = test_snapshots[2]->msg_id;
+ multi_msg_ids[3] = test_snapshots[3]->msg_id;
+
ast_test_status_update(test, "Test forwarding from an invalid mailbox\n");
- VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_3456", "default", "INBOX", "test_vm_api_2345", "default", "INBOX", 1, single_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_3456", "default", "INBOX", "test_vm_api_2345", "default", "INBOX", 1, &inbox_msg_id, 0);
ast_test_status_update(test, "Test forwarding from a NULL mailbox\n");
- VM_API_FORWARD_MESSAGE_OFF_NOMINAL(NULL, "default", "INBOX", "test_vm_api_2345", "default", "INBOX", 1, single_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE_OFF_NOMINAL(NULL, "default", "INBOX", "test_vm_api_2345", "default", "INBOX", 1, &inbox_msg_id, 0);
ast_test_status_update(test, "Test forwarding from an invalid context\n");
- VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "defunct", "INBOX", "test_vm_api_2345", "default", "INBOX", 1, single_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "defunct", "INBOX", "test_vm_api_2345", "default", "INBOX", 1, &inbox_msg_id, 0);
ast_test_status_update(test, "Test forwarding from an invalid folder\n");
- VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "POTTEDMEAT", "test_vm_api_2345", "default", "INBOX", 1, single_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "POTTEDMEAT", "test_vm_api_2345", "default", "INBOX", 1, &inbox_msg_id, 0);
ast_test_status_update(test, "Test forwarding from a NULL folder\n");
- VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", NULL, "test_vm_api_2345", "default", "INBOX", 1, single_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", NULL, "test_vm_api_2345", "default", "INBOX", 1, &inbox_msg_id, 0);
ast_test_status_update(test, "Test forwarding to an invalid mailbox\n");
- VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_3456", "default", "INBOX", 1, single_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_3456", "default", "INBOX", 1, &inbox_msg_id, 0);
ast_test_status_update(test, "Test forwarding to a NULL mailbox\n");
- VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", NULL, "default", "INBOX", 1, single_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", NULL, "default", "INBOX", 1, &inbox_msg_id, 0);
ast_test_status_update(test, "Test forwarding to an invalid context\n");
- VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "defunct", "INBOX", 1, single_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "defunct", "INBOX", 1, &inbox_msg_id, 0);
ast_test_status_update(test, "Test forwarding to an invalid folder\n");
- VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "POTTEDMEAT", 1, single_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "POTTEDMEAT", 1, &inbox_msg_id, 0);
ast_test_status_update(test, "Test forwarding to a NULL folder\n");
- VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", NULL, 1, single_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", NULL, 1, &inbox_msg_id, 0);
ast_test_status_update(test, "Test forwarding when no messages are select\n");
- VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "INBOX", 0, empty_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "INBOX", 0, empty_msg_ids, 0);
ast_test_status_update(test, "Test forwarding a message that doesn't exist\n");
- single_msg_nums[0] = 6;
- VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "INBOX", 1, single_msg_nums, 0);
+ inbox_msg_id = "POOPOO";
+ VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "INBOX", 1, &inbox_msg_id, 0);
ast_test_status_update(test, "Test forwarding multiple messages, where some messages don't exist\n");
- VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_2345", "default", "INBOX", "test_vm_api_1234", "default", "INBOX", 4, multi_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_2345", "default", "INBOX", "test_vm_api_1234", "default", "INBOX", 4, multi_msg_ids, 0);
ast_test_status_update(test, "Test forwarding a message with an invalid size specifier\n");
- VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "INBOX", -30, single_msg_nums, 0);
+ VM_API_FORWARD_MESSAGE_OFF_NOMINAL("test_vm_api_1234", "default", "INBOX", "test_vm_api_2345", "default", "INBOX", -30, &inbox_msg_id, 0);
VM_API_TEST_CLEANUP;
@@ -1257,6 +1290,8 @@
{
struct ast_vm_mailbox_snapshot *test_mbox_snapshot = NULL;
struct ast_channel *test_channel;
+ const char *message_id_1234;
+ const char *message_id_2345[2];
switch (cmd) {
case TEST_INIT:
@@ -1273,6 +1308,10 @@
VM_API_TEST_SETUP;
+ message_id_1234 = test_snapshots[1]->msg_id;
+ message_id_2345[0] = test_snapshots[2]->msg_id;
+ message_id_2345[1] = test_snapshots[3]->msg_id;
+
if (!(test_channel = test_vm_api_create_mock_channel())) {
ast_log(AST_LOG_ERROR, "Failed to create mock channel for testing\n");
VM_API_TEST_CLEANUP;
@@ -1280,15 +1319,15 @@
}
ast_test_status_update(test, "Playing back message from test_vm_api_1234 to mock channel\n");
- VM_API_PLAYBACK_MESSAGE(test_channel, "test_vm_api_1234", "default", "INBOX", "0", NULL);
+ VM_API_PLAYBACK_MESSAGE(test_channel, "test_vm_api_1234", "default", "INBOX", message_id_1234, NULL);
ast_test_status_update(test, "Playing back message from test_vm_api_2345 to callback function\n");
- VM_API_PLAYBACK_MESSAGE(test_channel, "test_vm_api_2345", "default", "INBOX", "0", &message_playback_callback_fn);
+ VM_API_PLAYBACK_MESSAGE(test_channel, "test_vm_api_2345", "default", "INBOX", message_id_2345[0], &message_playback_callback_fn);
VM_API_INT_VERIFY(global_entered_playback_callback, 1);
global_entered_playback_callback = 0;
ast_test_status_update(test, "Playing back message from test_vm_api_2345 to callback function with default context\n");
- VM_API_PLAYBACK_MESSAGE(test_channel, "test_vm_api_2345", NULL, "INBOX", "0", &message_playback_callback_fn);
+ VM_API_PLAYBACK_MESSAGE(test_channel, "test_vm_api_2345", NULL, "INBOX", message_id_2345[1], &message_playback_callback_fn);
VM_API_INT_VERIFY(global_entered_playback_callback, 1);
global_entered_playback_callback = 0;
@@ -1311,6 +1350,8 @@
AST_TEST_DEFINE(voicemail_api_off_nominal_msg_playback)
{
struct ast_channel *test_channel;
+ const char *msg_id;
+ const char *invalid_msg_id = "POOPOO";
switch (cmd) {
case TEST_INIT:
@@ -1330,6 +1371,7 @@
}
VM_API_TEST_SETUP;
+ msg_id = test_snapshots[0]->msg_id;
if (!(test_channel = test_vm_api_create_mock_channel())) {
ast_log(AST_LOG_ERROR, "Failed to create mock channel for testing\n");
@@ -1338,22 +1380,22 @@
}
ast_test_status_update(test, "Playing back message from invalid mailbox\n");
- VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_3456", "default", "INBOX", "0", NULL);
+ VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_3456", "default", "INBOX", msg_id, NULL);
ast_test_status_update(test, "Playing back message from NULL mailbox\n");
- VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, NULL, "default", "INBOX", "0", NULL);
+ VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, NULL, "default", "INBOX", msg_id, NULL);
ast_test_status_update(test, "Playing back message from invalid context\n");
- VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_1234", "defunct", "INBOX", "0", NULL);
+ VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_1234", "defunct", "INBOX", msg_id, NULL);
ast_test_status_update(test, "Playing back message from invalid folder\n");
- VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_1234", "default", "BACON", "0", NULL);
+ VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_1234", "default", "BACON", msg_id, NULL);
ast_test_status_update(test, "Playing back message from NULL folder\n");
- VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_1234", "default", NULL, "0", NULL);
+ VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_1234", "default", NULL, msg_id, NULL);
ast_test_status_update(test, "Playing back message with invalid message specifier\n");
- VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_1234", "default", "INBOX", "6", NULL);
+ VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_1234", "default", "INBOX", invalid_msg_id, NULL);
ast_test_status_update(test, "Playing back message with NULL message specifier\n");
VM_API_PLAYBACK_MESSAGE_OFF_NOMINAL(test_channel, "test_vm_api_1234", "default", "INBOX", NULL, NULL);
More information about the asterisk-commits
mailing list