[asterisk-commits] mmichelson: branch mmichelson/trunk-digiumphones r362865 - in /team/mmichelso...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 20 10:49:44 CDT 2012


Author: mmichelson
Date: Fri Apr 20 10:49:40 2012
New Revision: 362865

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=362865
Log:
Add initial changes for voicemail API improvements.

* Add an ao2_container to the ast_vm_mailbox_snapshot
* Add a function that can create a mailbox snapshot from memory
* Rename function that creates mailbox snapshot from file


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=362865&r1=362864&r2=362865
==============================================================================
--- team/mmichelson/trunk-digiumphones/apps/app_voicemail.c (original)
+++ team/mmichelson/trunk-digiumphones/apps/app_voicemail.c Fri Apr 20 10:49:40 2012
@@ -780,6 +780,10 @@
 	int imapversion;                 /*!< If configuration changes, use the new values */
 #endif
 	double volgain;                  /*!< Volume gain for voicemails sent via email */
+	/*!
+	 * Collection of data for all messages in this user's mailbox
+	 */
+	struct ast_vm_mailbox_snapshot *snapshot;
 	AST_LIST_ENTRY(ast_vm_user) list;
 };
 
@@ -14465,6 +14469,40 @@
 
 #endif
 
+static int __attribute__((unused))vm_msg_snapshot_create_from_data(struct ast_vm_user *vmu,
+	const char *msg_id,
+	const char *callerid,
+	const char *exten,
+	const char *origdate,
+	const char *origtime,
+	const char *duration,
+	const char *folder_name,
+	const char *folder_dir,
+	const char *flag)
+{
+	struct ast_vm_msg_snapshot *msg_snapshot = vm_msg_snapshot_alloc();
+	if (!msg_snapshot) {
+		return -1;
+	}
+
+	ast_string_field_set(msg_snapshot, msg_id, S_OR(msg_id, ""));
+	ast_string_field_set(msg_snapshot, callerid, S_OR(callerid, ""));
+	ast_string_field_set(msg_snapshot, exten, S_OR(exten, ""));
+	ast_string_field_set(msg_snapshot, origdate, S_OR(origdate, ""));
+	ast_string_field_set(msg_snapshot, origtime, S_OR(origtime, ""));
+	ast_string_field_set(msg_snapshot, duration, S_OR(duration, ""));
+	ast_string_field_set(msg_snapshot, folder_name, S_OR(folder_name, ""));
+	ast_string_field_set(msg_snapshot, folder_dir, S_OR(folder_dir, ""));
+	ast_string_field_set(msg_snapshot, flag, S_OR(flag, ""));
+	
+	/* XXX Here, we need to link the message snapshot into the user's mailbox
+	 * snapshot. ao2_linking is an easy thing. Placing the message in the folder
+	 * list may be a tad trickier, but nothing too crazy.
+	 */
+
+	return 0;
+}
+
 /*!
  * \brief Create and store off all the msgs in an open mailbox
  *
@@ -14476,7 +14514,7 @@
  *       writing it to the file system.  This is an area that needs
  *       to be made more efficient.
  */
-static int vm_msg_snapshot_create(struct ast_vm_user *vmu,
+static int vm_msg_snapshot_create_from_file(struct ast_vm_user *vmu,
 	struct vm_state *vms,
 	struct ast_vm_mailbox_snapshot *mailbox_snapshot,
 	int snapshot_index,
@@ -14572,8 +14610,6 @@
 			AST_LIST_INSERT_TAIL(&mailbox_snapshot->snapshots[snapshot_index], msg_snapshot, msg);
 		}
 
-		mailbox_snapshot->total_msg_num++;
-
 		/* cleanup configs and msg */
 		ast_config_destroy(msg_cfg);
 		DISPOSE(vms->curdir, vms->curmsg);
@@ -14658,7 +14694,7 @@
 
 		/* Iterate through each msg, storing off info */
 		if (vms.lastmsg != -1) {
-			if ((vm_msg_snapshot_create(vmu, &vms, mailbox_snapshot, combining_old ? inbox_index : i, i, descending, sort_val))) {
+			if ((vm_msg_snapshot_create_from_file(vmu, &vms, mailbox_snapshot, combining_old ? inbox_index : i, i, descending, sort_val))) {
 				ast_log(LOG_WARNING, "Failed to create msg snapshots for %s@%s\n", mailbox, context);
 				goto snapshot_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=362865&r1=362864&r2=362865
==============================================================================
--- team/mmichelson/trunk-digiumphones/include/asterisk/app_voicemail.h (original)
+++ team/mmichelson/trunk-digiumphones/include/asterisk/app_voicemail.h Fri Apr 20 10:49:40 2012
@@ -26,6 +26,7 @@
 
 #include "asterisk/stringfields.h"
 #include "asterisk/linkedlists.h"
+#include "asterisk/astobj2.h"
 
 #define AST_VM_FOLDER_NUMBER 12
 
@@ -53,7 +54,20 @@
 };
 
 struct ast_vm_mailbox_snapshot {
-	int total_msg_num;
+	/*!
+	 * This ao2_container contains ALL voicemail messages in the
+	 * mailbox. The messages are indexed by their unique message
+	 * ID. When it comes time to quickly retrieve a message, this is
+	 * your best bet.
+	 */
+	struct ao2_container *messages;
+	/*!
+	 * This is an array of lists of the voicemail messages in the
+	 * mailbox. Each index in the array corresponds to a folder. The
+	 * messages in each folder are listed chronologically. This arrangement
+	 * is useful for cases where the messages are presented to a voicemail
+	 * user.
+	 */
 	AST_LIST_HEAD_NOLOCK(, ast_vm_msg_snapshot) snapshots[AST_VM_FOLDER_NUMBER];
 };
 

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=362865&r1=362864&r2=362865
==============================================================================
--- team/mmichelson/trunk-digiumphones/tests/test_voicemail_api.c (original)
+++ team/mmichelson/trunk-digiumphones/tests/test_voicemail_api.c Fri Apr 20 10:49:40 2012
@@ -194,7 +194,7 @@
 		return AST_TEST_FAIL; \
 	} \
 	VM_API_SNAPSHOT_CREATE((mailbox), (context), (folder), 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0); \
-	VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 0); \
+	VM_API_INT_VERIFY(ao2_container_count(test_mbox_snapshot->messages), 0); \
 	test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot); \
 } while (0)
 
@@ -732,60 +732,60 @@
 
 	ast_test_status_update(test, "Test retrieving message 1 from INBOX of test_vm_1234\n");
 	VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
-	VM_API_INT_VERIFY(1, test_mbox_snapshot->total_msg_num);
+	VM_API_INT_VERIFY(1, ao2_container_count(test_mbox_snapshot->messages));
 	VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[1], test_mbox_snapshot, "INBOX", 0);
 	ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	ast_test_status_update(test, "Test retrieving message 0 from Old of test_vm_1234\n");
 	VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "Old", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
-	VM_API_INT_VERIFY(1, test_mbox_snapshot->total_msg_num);
+	VM_API_INT_VERIFY(1, ao2_container_count(test_mbox_snapshot->messages));
 	VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[0], test_mbox_snapshot, "Old", 0);
 	ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	ast_test_status_update(test, "Test retrieving message 0, 1 from Old and INBOX of test_vm_1234 ordered by time\n");
 	VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 1);
-	VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
+	VM_API_INT_VERIFY(2, ao2_container_count(test_mbox_snapshot->messages));
 	VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[0], test_mbox_snapshot, "INBOX", 0);
 	VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[1], test_mbox_snapshot, "INBOX", 1);
 
 	ast_test_status_update(test, "Test retrieving message 1, 0 from Old and INBOX of test_vm_1234 ordered by time desc\n");
 	VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 1, AST_VM_SNAPSHOT_SORT_BY_TIME, 1);
-	VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
+	VM_API_INT_VERIFY(2, ao2_container_count(test_mbox_snapshot->messages));
 	VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[1], test_mbox_snapshot, "INBOX", 0);
 	VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[0], test_mbox_snapshot, "INBOX", 1);
 	ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	ast_test_status_update(test, "Test retrieving message 0, 1 from Old and INBOX of test_vm_1234 ordered by id\n");
 	VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_ID, 1);
-	VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
+	VM_API_INT_VERIFY(2, ao2_container_count(test_mbox_snapshot->messages));
 	VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[1], test_mbox_snapshot, "INBOX", 0);
 	VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[0], test_mbox_snapshot, "INBOX", 1);
 	ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	ast_test_status_update(test, "Test retrieving message 1, 0 from Old and INBOX of test_vm_1234 ordered by id desc\n");
 	VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 1, AST_VM_SNAPSHOT_SORT_BY_ID, 1);
-	VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
+	VM_API_INT_VERIFY(2, ao2_container_count(test_mbox_snapshot->messages));
 	VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[0], test_mbox_snapshot, "INBOX", 0);
 	VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[1], test_mbox_snapshot, "INBOX", 1);
 	ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	ast_test_status_update(test, "Test retrieving message 0, 1 from all folders of test_vm_1234 ordered by id\n");
 	VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", NULL, 0, AST_VM_SNAPSHOT_SORT_BY_ID, 0);
-	VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
+	VM_API_INT_VERIFY(2, ao2_container_count(test_mbox_snapshot->messages));
 	VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[0], test_mbox_snapshot, "Old", 0);
 	VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[1], test_mbox_snapshot, "INBOX", 0);
 	ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	ast_test_status_update(test, "Test retrieving message 0, 1 from all folders of test_vm_1234 ordered by time\n");
 	VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", NULL, 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
-	VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
+	VM_API_INT_VERIFY(2, ao2_container_count(test_mbox_snapshot->messages));
 	VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[0], test_mbox_snapshot, "Old", 0);
 	VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[1], test_mbox_snapshot, "INBOX", 0);
 	ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	ast_test_status_update(test, "Test retrieving message 0, 1 from all folders of test_vm_1234, default context ordered by time\n");
 	VM_API_SNAPSHOT_CREATE("test_vm_api_1234", NULL, NULL, 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
-	VM_API_INT_VERIFY(2, test_mbox_snapshot->total_msg_num);
+	VM_API_INT_VERIFY(2, ao2_container_count(test_mbox_snapshot->messages));
 	VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[0], test_mbox_snapshot, "Old", 0);
 	VM_API_SNAPSHOT_MSG_VERIFY(test_snapshots[1], test_mbox_snapshot, "INBOX", 0);
 	ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
@@ -1098,12 +1098,12 @@
 
 	/* 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);
-	VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 1);
+	VM_API_INT_VERIFY(ao2_container_count(test_mbox_snapshot->messages), 1);
 	test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	/* We should now have a total of 3 messages in test_vm_api_2345 INBOX */
 	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, 3);
+	VM_API_INT_VERIFY(ao2_container_count(test_mbox_snapshot->messages), 3);
 	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");
@@ -1111,12 +1111,12 @@
 
 	/* 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);
-	VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 1);
+	VM_API_INT_VERIFY(ao2_container_count(test_mbox_snapshot->messages), 1);
 	test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	/* We should now have a total of 4 messages in test_vm_api_2345 INBOX */
 	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);
+	VM_API_INT_VERIFY(ao2_container_count(test_mbox_snapshot->messages), 4);
 	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");
@@ -1124,12 +1124,12 @@
 
 	/* 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);
-	VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 1);
+	VM_API_INT_VERIFY(ao2_container_count(test_mbox_snapshot->messages), 1);
 	test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	/* We should now have a total of 5 messages in test_vm_api_2345 INBOX */
 	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, 5);
+	VM_API_INT_VERIFY(ao2_container_count(test_mbox_snapshot->messages), 5);
 	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");
@@ -1137,12 +1137,12 @@
 
 	/* Make sure we deleted the message */
 	VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
-	VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 0);
+	VM_API_INT_VERIFY(ao2_container_count(test_mbox_snapshot->messages), 0);
 	test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	/* We should now have a total of 6 messages in test_vm_api_2345 INBOX */
 	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, 6);
+	VM_API_INT_VERIFY(ao2_container_count(test_mbox_snapshot->messages), 6);
 	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");
@@ -1150,24 +1150,24 @@
 
 	/* 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);
-	VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 6);
+	VM_API_INT_VERIFY(ao2_container_count(test_mbox_snapshot->messages), 6);
 	test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	/* We should now have a total of 2 messages in test_vm_api_1234 INBOX */
 	VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "INBOX", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
-	VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 2);
+	VM_API_INT_VERIFY(ao2_container_count(test_mbox_snapshot->messages), 2);
 	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);
 	/* 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);
+	VM_API_INT_VERIFY(ao2_container_count(test_mbox_snapshot->messages), 4);
 	test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	/* We should now have a total of 2 messages in test_vm_api_1234 Family */
 	VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "Family", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
-	VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 2);
+	VM_API_INT_VERIFY(ao2_container_count(test_mbox_snapshot->messages), 2);
 	test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	VM_API_TEST_CLEANUP;
@@ -1293,11 +1293,11 @@
 	global_entered_playback_callback = 0;
 
 	VM_API_SNAPSHOT_CREATE("test_vm_api_1234", "default", "Old", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
-	VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 2);
+	VM_API_INT_VERIFY(ao2_container_count(test_mbox_snapshot->messages), 2);
 	test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	VM_API_SNAPSHOT_CREATE("test_vm_api_2345", "default", "Old", 0, AST_VM_SNAPSHOT_SORT_BY_TIME, 0);
-	VM_API_INT_VERIFY(test_mbox_snapshot->total_msg_num, 2);
+	VM_API_INT_VERIFY(ao2_container_count(test_mbox_snapshot->messages), 2);
 	test_mbox_snapshot = ast_vm_mailbox_snapshot_destroy(test_mbox_snapshot);
 
 	if (test_channel) {




More information about the asterisk-commits mailing list