[asterisk-commits] mjordan: branch mjordan/voicemail_refactor_01_08_11 r333782 - in /team/mjorda...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Aug 29 15:26:33 CDT 2011
Author: mjordan
Date: Mon Aug 29 15:26:29 2011
New Revision: 333782
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=333782
Log:
Adding mail migrations
Modified:
team/mjordan/voicemail_refactor_01_08_11/ (props changed)
team/mjordan/voicemail_refactor_01_08_11/apps/app_voicemail.c
team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/include/test_voicemail.h
team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/include/voicemail.h
team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/test_vm_filesystem.c
team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/vm_config_parser.c
team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/vm_filesystem.c
team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/vm_mail.c
Propchange: team/mjordan/voicemail_refactor_01_08_11/
------------------------------------------------------------------------------
automerge = *
Propchange: team/mjordan/voicemail_refactor_01_08_11/
------------------------------------------------------------------------------
automerge-email = mjordan at digium.com
Modified: team/mjordan/voicemail_refactor_01_08_11/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_01_08_11/apps/app_voicemail.c?view=diff&rev=333782&r1=333781&r2=333782
==============================================================================
--- team/mjordan/voicemail_refactor_01_08_11/apps/app_voicemail.c (original)
+++ team/mjordan/voicemail_refactor_01_08_11/apps/app_voicemail.c Mon Aug 29 15:26:29 2011
@@ -1574,49 +1574,64 @@
-//#if !(defined(IMAP_STORAGE) || defined(ODBC_STORAGE))
-//
-//static int messagecount(const char *context, const char *mailbox, const char *folder)
-//{
-// return __has_voicemail(context, mailbox, folder, 0) + (folder && strcmp(folder, "INBOX") ? 0 : __has_voicemail(context, mailbox, "Urgent", 0));
-//}
-//
-//static int __has_voicemail(const char *context, const char *mailbox, const char *folder, int shortcircuit)
-//{
-// DIR *dir;
-// struct dirent *de;
-// char fn[256];
-// int ret = 0;
-//
-// /* If no mailbox, return immediately */
-// if (ast_strlen_zero(mailbox))
-// return 0;
-//
-// if (ast_strlen_zero(folder))
-// folder = "INBOX";
-// if (ast_strlen_zero(context))
-// context = "default";
-//
-// snprintf(fn, sizeof(fn), "%s%s/%s/%s", VM_SPOOL_DIR, context, mailbox, folder);
-//
-// if (!(dir = opendir(fn)))
-// return 0;
-//
-// while ((de = readdir(dir))) {
-// if (!strncasecmp(de->d_name, "msg", 3)) {
-// if (shortcircuit) {
-// ret = 1;
-// break;
-// } else if (!strncasecmp(de->d_name + 8, "txt", 3)) {
-// ret++;
-// }
-// }
-// }
-//
-// closedir(dir);
-//
-// return ret;
-//}
+/*!
+ * \brief Application that returns the number of messages in a specified folder
+ * \param context The context to search in; if not specified, "default" is used
+ * \param mailbox The mailbox to search in
+ * \param folder The folder to search in; if not specified, "INBOX" is used
+ *
+ * \details
+ * Returns the number of voicemails in the folder. This includes old messages, priority, new,
+ * etc. For counts based on types of voicemails (such as old, new, etc.) use the inboxcount2
+ * method
+ *
+ * \returns The number of voicemails contained in the folder
+ */
+static int messagecount(const char *context, const char *mailbox, const char *folder)
+{
+ struct ast_vm_user *vmu;
+ struct vm_folder *tmp_folder;
+ int res = 0;
+
+ /* If no mailbox, return immediately */
+ if (ast_strlen_zero(mailbox))
+ return 0;
+
+ if (ast_strlen_zero(folder))
+ folder = "INBOX";
+ if (ast_strlen_zero(context))
+ context = "default";
+
+ if ((vmu = vm_find_user(context, mailbox))) {
+ ao2_lock(vmu);
+
+ /* Open their voicemail */
+ if (vm_backend->open_voicemail(vmu)) {
+ ast_log(AST_LOG_WARNING, "Failed to open voicemail for user at %s@%s\n", mailbox, context);
+ ao2_unlock(vmu);
+ ao2_ref(vmu, -1);
+ return 0;
+ }
+
+ /* Remember their current folder */
+ tmp_folder = vmu->vms->curfolder;
+ if (browse_folder(vmu, &folder, folder_name_comparator)) {
+ ast_log(AST_LOG_WARNING, "Failed to find folder %s for user at %s@%s\n", folder, mailbox, context);
+ } else {
+ res = vmu->vms->curfolder->number_voicemails;
+ }
+
+ /* Reset the folder */
+ vmu->vms->curfolder = tmp_folder;
+
+ ao2_unlock(vmu);
+ ao2_ref(vmu, -1);
+ } else {
+ ast_log(AST_LOG_WARNING, "Unable to find voicemail user %s\n", mailbox);
+ }
+
+ return res;
+}
/*
* \brief Determines if the given folder has new messages.
@@ -1687,6 +1702,8 @@
char *context;
enum vm_message_priorities priority;
unsigned int flag;
+ struct ast_vm_user *vmu;
+ struct vm_folder *it_folder;
/* If no mailbox, return immediately */
if (ast_strlen_zero(mailbox))
@@ -1729,34 +1746,46 @@
else
context = "default";
- if (newmsgs) {
- flag = VM_MSG_NEW;
- *newmsgs = message_operation(NULL, &flag, message_count_by_flag);
- }
- if (oldmsgs) {
- flag = VM_MSG_OLD;
- *oldmsgs = message_operation(NULL, &flag, message_count_by_flag);
- }
- if (urgentmsgs) {
- priority = VM_PRIORITY_URGENT;
- *urgentmsgs = message_operation(NULL, &priority, message_count_by_priority);
+ if ((vmu = vm_find_user(context, tmp))) {
+ ao2_lock(vmu);
+
+ /* Open their voicemail */
+ if (vm_backend->open_voicemail(vmu)) {
+ ast_log(AST_LOG_WARNING, "Failed to open voicemail for user at mailbox %s\n", mailbox);
+ ao2_unlock(vmu);
+ ao2_ref(vmu, -1);
+ return -1;
+ }
+
+ /* Get the counts for all folders */
+ AST_LIST_TRAVERSE(&(vmu->vms->folders), it_folder, list) {
+ if (newmsgs) {
+ flag = VM_MSG_NEW;
+ *newmsgs += message_operation(it_folder, &flag, message_count_by_flag);
+ }
+ if (oldmsgs) {
+ flag = VM_MSG_OLD;
+ *oldmsgs += message_operation(it_folder, &flag, message_count_by_flag);
+ }
+ if (urgentmsgs) {
+ priority = VM_PRIORITY_URGENT;
+ *urgentmsgs += message_operation(it_folder, &priority, message_count_by_priority);
+ }
+ }
+
+ ao2_unlock(vmu);
+ ao2_ref(vmu, -1);
+ } else {
+ ast_log(AST_LOG_WARNING, "Unable to find voicemail user %s\n", mailbox);
}
return 0;
}
-//
-//#endif
-//
-///* Exactly the same function for file-based, ODBC-based, and IMAP-based, so why create 3 different copies? */
-//static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
-//{
-// int urgentmsgs = 0;
-// int res = inboxcount2(mailbox, &urgentmsgs, newmsgs, oldmsgs);
-// if (newmsgs) {
-// *newmsgs += urgentmsgs;
-// }
-// return res;
-//}
+
+static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
+{
+ return inboxcount2(mailbox, NULL, newmsgs, oldmsgs);
+}
static void run_externnotify(char *context, char *extension, const char *flag)
{
@@ -2279,11 +2308,9 @@
if (vm_backend->open_voicemail(recip)) {
ast_log(AST_LOG_WARNING, "Failed to open voicemail for recipient %s:%s", recip->context, recip->mailbox);
} else {
- ao2_lock(vmu);
- if (copy_new_message(chan, vmu, vm_object)) {
+ if (copy_new_message(chan, recip, vm_object)) {
ast_log(AST_LOG_WARNING, "Failed to deliver voicemail %s to recipient %s:%s", vm_object->msg_location, recip->context, recip->mailbox);
}
- ao2_unlock(vmu);
}
ao2_unlock(recip);
ao2_ref(recip, -1);
@@ -7661,21 +7688,21 @@
// return ast_str_buffer(str);
//}
-//static int sayname(struct ast_channel *chan, const char *mailbox, const char *context)
-//{
-// int res = -1;
-// char dir[PATH_MAX];
-// snprintf(dir, sizeof(dir), "%s%s/%s/greet", VM_SPOOL_DIR, context, mailbox);
-// ast_debug(2, "About to try retrieving name file %s\n", dir);
-// vm_backend->retrieve_voicemail(NULL, NULL); /* FIXME: put in the voicemail object and the vmu */
-// /*RETRIEVE(dir, -1, mailbox, context);*/
-// if (ast_fileexists(dir, NULL, NULL)) {
-// res = ast_stream_and_wait(chan, dir, AST_DIGIT_ANY);
-// }
-// vm_backend->dispose_voicemail(NULL); /* FIXME: put in the voice mail object */
-// /*DISPOSE(dir, -1);*/
-// return res;
-//}
+static int sayname(struct ast_channel *chan, const char *mailbox, const char *context)
+{
+ int res = -1;
+ char dir[PATH_MAX];
+ /*snprintf(dir, sizeof(dir), "%s%s/%s/greet", VM_SPOOL_DIR, context, mailbox);*/
+ ast_debug(2, "About to try retrieving name file %s\n", dir);
+ /*vm_backend->retrieve_voicemail(NULL, NULL); FIXME: put in the voicemail object and the vmu */
+ /*RETRIEVE(dir, -1, mailbox, context);*/
+ if (ast_fileexists(dir, NULL, NULL)) {
+ res = ast_stream_and_wait(chan, dir, AST_DIGIT_ANY);
+ }
+ vm_backend->dispose_voicemail(NULL); /* FIXME: put in the voice mail object */
+ /*DISPOSE(dir, -1);*/
+ return res;
+}
void vm_read_password_from_file(const char *secretfn, char *password, int passwordlen) {
struct ast_config *pwconf;
@@ -7747,374 +7774,7 @@
// return res;
//}
//
-//#ifdef TEST_FRAMEWORK
-//static int fake_write(struct ast_channel *ast, struct ast_frame *frame)
-//{
-// return 0;
-//}
-//
-//static struct ast_frame *fake_read(struct ast_channel *ast)
-//{
-// return &ast_null_frame;
-//}
-//
-//AST_TEST_DEFINE(test_voicemail_vmsayname)
-//{
-// char dir[PATH_MAX];
-// char dir2[PATH_MAX];
-// static const char TEST_CONTEXT[] = "very_long_unique_context_so_that_nobody_will_ever_have_the_same_one_configured_3141592653";
-// static const char TEST_EXTENSION[] = "1234";
-//
-// struct ast_channel *test_channel1 = NULL;
-// int res = -1;
-//
-// static const struct ast_channel_tech fake_tech = {
-// .write = fake_write,
-// .read = fake_read,
-// };
-//
-// switch (cmd) {
-// case TEST_INIT:
-// info->name = "vmsayname_exec";
-// info->category = "/apps/app_voicemail/";
-// info->summary = "Vmsayname unit test";
-// info->description =
-// "This tests passing various parameters to vmsayname";
-// return AST_TEST_NOT_RUN;
-// case TEST_EXECUTE:
-// break;
-// }
-//
-// if (!(test_channel1 = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, NULL,
-// NULL, NULL, 0, 0, "TestChannel1"))) {
-// goto exit_vmsayname_test;
-// }
-//
-// /* normally this is done in the channel driver */
-// ast_format_set(&test_channel1->writeformat, AST_FORMAT_GSM, 0);
-// ast_format_cap_add(test_channel1->nativeformats, &test_channel1->writeformat);
-// ast_format_set(&test_channel1->rawwriteformat, AST_FORMAT_GSM, 0);
-// ast_format_set(&test_channel1->readformat, AST_FORMAT_GSM, 0);
-// ast_format_set(&test_channel1->rawreadformat, AST_FORMAT_GSM, 0);
-// test_channel1->tech = &fake_tech;
-//
-// ast_test_status_update(test, "Test playing of extension when greeting is not available...\n");
-// snprintf(dir, sizeof(dir), "%s@%s", TEST_EXTENSION, TEST_CONTEXT); /* not a dir, don't get confused */
-// if (!(res = vmsayname_exec(test_channel1, dir))) {
-// snprintf(dir, sizeof(dir), "%s%s/%s/greet", VM_SPOOL_DIR, TEST_CONTEXT, TEST_EXTENSION);
-// if (ast_fileexists(dir, NULL, NULL)) {
-// ast_test_status_update(test, "This should not happen, most likely means clean up from previous test failed\n");
-// res = -1;
-// goto exit_vmsayname_test;
-// } else {
-// /* no greeting already exists as expected, let's create one to fully test sayname */
-// if ((res = create_dirpath(dir, sizeof(dir), TEST_CONTEXT, TEST_EXTENSION, ""))) {
-// ast_log(AST_LOG_WARNING, "Failed to make test directory\n");
-// goto exit_vmsayname_test;
-// }
-// snprintf(dir, sizeof(dir), "%s/sounds/beep.gsm", ast_config_AST_VAR_DIR);
-// snprintf(dir2, sizeof(dir2), "%s%s/%s/greet.gsm", VM_SPOOL_DIR, TEST_CONTEXT, TEST_EXTENSION);
-// /* we're not going to hear the sound anyway, just use a valid gsm audio file */
-// if ((res = symlink(dir, dir2))) {
-// ast_log(LOG_WARNING, "Symlink reported %s\n", strerror(errno));
-// goto exit_vmsayname_test;
-// }
-// ast_test_status_update(test, "Test playing created mailbox greeting...\n");
-// snprintf(dir, sizeof(dir), "%s@%s", TEST_EXTENSION, TEST_CONTEXT); /* not a dir, don't get confused */
-// res = vmsayname_exec(test_channel1, dir);
-//
-// /* TODO: there may be a better way to do this */
-// unlink(dir2);
-// snprintf(dir2, sizeof(dir2), "%s%s/%s", VM_SPOOL_DIR, TEST_CONTEXT, TEST_EXTENSION);
-// rmdir(dir2);
-// snprintf(dir2, sizeof(dir2), "%s%s", VM_SPOOL_DIR, TEST_CONTEXT);
-// rmdir(dir2);
-// }
-// }
-//
-//exit_vmsayname_test:
-//
-// if (test_channel1) {
-// ast_hangup(test_channel1);
-// }
-//
-// return res ? AST_TEST_FAIL : AST_TEST_PASS;
-//}
-//
-//AST_TEST_DEFINE(test_voicemail_msgcount)
-//{
-// int i, j, res = AST_TEST_PASS, syserr;
-// struct ast_vm_user *vmu;
-// struct vm_state vms;
-//#ifdef IMAP_STORAGE
-// struct ast_channel *chan = NULL;
-//#endif
-// struct {
-// char dir[256];
-// char file[256];
-// char txtfile[256];
-// } tmp[3];
-// char syscmd[256];
-// const char origweasels[] = "tt-weasels";
-// const char testcontext[] = "test";
-// const char testmailbox[] = "00000000";
-// const char testspec[] = "00000000 at test";
-// FILE *txt;
-// int new, old, urgent;
-// const char *folders[3] = { "Old", "Urgent", "INBOX" };
-// const int folder2mbox[3] = { 1, 11, 0 };
-// const int expected_results[3][12] = {
-// /* hasvm-old, hasvm-urgent, hasvm-new, ic-old, ic-urgent, ic-new, ic2-old, ic2-urgent, ic2-new, mc-old, mc-urgent, mc-new */
-// { 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 },
-// { 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1 },
-// { 1, 1, 1, 1, 0, 2, 1, 1, 1, 1, 1, 2 },
-// };
-//
-// switch (cmd) {
-// case TEST_INIT:
-// info->name = "test_voicemail_msgcount";
-// info->category = "/apps/app_voicemail/";
-// info->summary = "Test Voicemail status checks";
-// info->description =
-// "Verify that message counts are correct when retrieved through the public API";
-// return AST_TEST_NOT_RUN;
-// case TEST_EXECUTE:
-// break;
-// }
-//
-// /* Make sure the original path was completely empty */
-// snprintf(syscmd, sizeof(syscmd), "rm -rf \"%s%s/%s\"", VM_SPOOL_DIR, testcontext, testmailbox);
-// if ((syserr = ast_safe_system(syscmd))) {
-// ast_test_status_update(test, "Unable to clear test directory: %s\n",
-// syserr > 0 ? strerror(syserr) : "unable to fork()");
-// return AST_TEST_FAIL;
-// }
-//
-//#ifdef IMAP_STORAGE
-// if (!(chan = ast_dummy_channel_alloc())) {
-// ast_test_status_update(test, "Unable to create dummy channel\n");
-// return AST_TEST_FAIL;
-// }
-//#endif
-//
-// if (!(vmu = find_user(NULL, testcontext, testmailbox)) &&
-// !(vmu = find_or_create(testcontext, testmailbox))) {
-// ast_test_status_update(test, "Cannot create vmu structure\n");
-// ast_unreplace_sigchld();
-// return AST_TEST_FAIL;
-// }
-//
-// populate_defaults(vmu);
-// memset(&vms, 0, sizeof(vms));
-//
-// /* Create temporary voicemail */
-// for (i = 0; i < 3; i++) {
-// create_dirpath(tmp[i].dir, sizeof(tmp[i].dir), testcontext, testmailbox, folders[i]);
-// make_file(tmp[i].file, sizeof(tmp[i].file), tmp[i].dir, 0);
-// snprintf(tmp[i].txtfile, sizeof(tmp[i].txtfile), "%s.txt", tmp[i].file);
-//
-// if (ast_fileexists(origweasels, "gsm", "en") > 0) {
-// snprintf(syscmd, sizeof(syscmd), "cp \"%s/sounds/en/%s.gsm\" \"%s/%s/%s/%s/msg0000.gsm\"", ast_config_AST_DATA_DIR, origweasels,
-// VM_SPOOL_DIR, testcontext, testmailbox, folders[i]);
-// if ((syserr = ast_safe_system(syscmd))) {
-// ast_test_status_update(test, "Unable to create test voicemail: %s\n",
-// syserr > 0 ? strerror(syserr) : "unable to fork()");
-// ast_unreplace_sigchld();
-// return AST_TEST_FAIL;
-// }
-// }
-//
-// if ((txt = fopen(tmp[i].txtfile, "w+"))) {
-// fprintf(txt, "; just a stub\n[message]\nflag=%s\n", strcmp(folders[i], "Urgent") ? "" : "Urgent");
-// fclose(txt);
-// } else {
-// ast_test_status_update(test, "Unable to write message file '%s'\n", tmp[i].txtfile);
-// res = AST_TEST_FAIL;
-// break;
-// }
-// open_mailbox(&vms, vmu, folder2mbox[i]);
-// vm_backend->store_voicemail(NULL); /* FIXME: need to store the actual voicemail object */
-// /*STORE(tmp[i].dir, testmailbox, testcontext, 0, chan, vmu, "gsm", 600, &vms, strcmp(folders[i], "Urgent") ? "" : "Urgent");*/
-//
-// /* hasvm-old, hasvm-urgent, hasvm-new, ic-old, ic-urgent, ic-new, ic2-old, ic2-urgent, ic2-new, mc-old, mc-urgent, mc-new */
-// for (j = 0; j < 3; j++) {
-// /* folder[2] is INBOX, __has_voicemail will default back to INBOX */
-// if (ast_app_has_voicemail(testspec, (j==2 ? NULL : folders[j])) != expected_results[i][0 + j]) {
-// ast_test_status_update(test, "has_voicemail(%s, %s) returned %d and we expected %d\n",
-// testspec, folders[j], ast_app_has_voicemail(testspec, folders[j]), expected_results[i][0 + j]);
-// res = AST_TEST_FAIL;
-// }
-// }
-//
-// new = old = urgent = 0;
-// if (ast_app_inboxcount(testspec, &new, &old)) {
-// ast_test_status_update(test, "inboxcount returned failure\n");
-// res = AST_TEST_FAIL;
-// } else if (old != expected_results[i][3 + 0] || new != expected_results[i][3 + 2]) {
-// ast_test_status_update(test, "inboxcount(%s) returned old=%d (expected %d) and new=%d (expected %d)\n",
-// testspec, old, expected_results[i][3 + 0], new, expected_results[i][3 + 2]);
-// res = AST_TEST_FAIL;
-// }
-//
-// new = old = urgent = 0;
-// if (ast_app_inboxcount2(testspec, &urgent, &new, &old)) {
-// ast_test_status_update(test, "inboxcount2 returned failure\n");
-// res = AST_TEST_FAIL;
-// } else if (old != expected_results[i][6 + 0] ||
-// urgent != expected_results[i][6 + 1] ||
-// new != expected_results[i][6 + 2] ) {
-// ast_test_status_update(test, "inboxcount2(%s) returned old=%d (expected %d), urgent=%d (expected %d), and new=%d (expected %d)\n",
-// testspec, old, expected_results[i][6 + 0], urgent, expected_results[i][6 + 1], new, expected_results[i][6 + 2]);
-// res = AST_TEST_FAIL;
-// }
-//
-// new = old = urgent = 0;
-// for (j = 0; j < 3; j++) {
-// if (ast_app_messagecount(testcontext, testmailbox, folders[j]) != expected_results[i][9 + j]) {
-// ast_test_status_update(test, "messagecount(%s, %s) returned %d and we expected %d\n",
-// testspec, folders[j], ast_app_messagecount(testcontext, testmailbox, folders[j]), expected_results[i][9 + j]);
-// res = AST_TEST_FAIL;
-// }
-// }
-// }
-//
-// for (i = 0; i < 3; i++) {
-// /* This is necessary if the voicemails are stored on an ODBC/IMAP
-// * server, in which case, the rm below will not affect the
-// * voicemails. */
-// DELETE(tmp[i].dir, 0, tmp[i].file, vmu);
-// vm_backend->dispose_voicemail(NULL); /* FIXME: put in the voice mail object */
-// /*DISPOSE(tmp[i].dir, 0);*/
-// }
-//
-// if (vms.deleted) {
-// ast_free(vms.deleted);
-// }
-// if (vms.heard) {
-// ast_free(vms.heard);
-// }
-//
-//#ifdef IMAP_STORAGE
-// chan = ast_channel_release(chan);
-//#endif
-//
-// /* And remove test directory */
-// snprintf(syscmd, sizeof(syscmd), "rm -rf \"%s%s/%s\"", VM_SPOOL_DIR, testcontext, testmailbox);
-// if ((syserr = ast_safe_system(syscmd))) {
-// ast_test_status_update(test, "Unable to clear test directory: %s\n",
-// syserr > 0 ? strerror(syserr) : "unable to fork()");
-// }
-//
-// return res;
-//}
-//
-//AST_TEST_DEFINE(test_voicemail_notify_endl)
-//{
-// int res = AST_TEST_PASS;
-// char testcontext[] = "test";
-// char testmailbox[] = "00000000";
-// char from[] = "test at example.net", cidnum[] = "1234", cidname[] = "Mark Spencer", format[] = "gsm";
-// char attach[256], attach2[256];
-// char buf[256] = ""; /* No line should actually be longer than 80 */
-// struct ast_channel *chan = NULL;
-// struct ast_vm_user *vmu, vmus = {
-// .flags = 0,
-// };
-// FILE *file;
-// struct {
-// char *name;
-// enum { INT, FLAGVAL, STATIC, STRPTR } type;
-// void *location;
-// union {
-// int intval;
-// char *strval;
-// } u;
-// } test_items[] = {
-// { "plain jane config", STATIC, vmus.password, .u.strval = "1234" }, /* No, this doesn't change this test any. */
-// { "emailsubject", STRPTR, vmus.emailsubject, .u.strval = "Oogly boogly\xf8koogly with what appears to be UTF-8" },
-// { "emailbody", STRPTR, vmus.emailbody, .u.strval = "This is a test\n\twith multiple\nlines\nwithin\n" },
-// { "serveremail", STATIC, vmus.serveremail, .u.strval = "\"\xf8Something\xe8that\xd8seems to have UTF-8 chars\" <test at example.net>" },
-// { "attachment flag", FLAGVAL, &vmus.flags, .u.intval = VM_ATTACH },
-// { "attach2", STRPTR, attach2, .u.strval = "" },
-// { "attach", STRPTR, attach, .u.strval = "" },
-// };
-// int which;
-//
-// switch (cmd) {
-// case TEST_INIT:
-// info->name = "test_voicemail_notify_endl";
-// info->category = "/apps/app_voicemail/";
-// info->summary = "Test Voicemail notification end-of-line";
-// info->description =
-// "Verify that notification emails use a consistent end-of-line character";
-// return AST_TEST_NOT_RUN;
-// case TEST_EXECUTE:
-// break;
-// }
-//
-// snprintf(attach, sizeof(attach), "%s/sounds/en/tt-weasels", ast_config_AST_VAR_DIR);
-// snprintf(attach2, sizeof(attach2), "%s/sounds/en/tt-somethingwrong", ast_config_AST_VAR_DIR);
-//
-// if (!(vmu = find_user(&vmus, testcontext, testmailbox)) &&
-// !(vmu = find_or_create(testcontext, testmailbox))) {
-// ast_test_status_update(test, "Cannot create vmu structure\n");
-// return AST_TEST_NOT_RUN;
-// }
-//
-// if (vmu != &vmus && !(vmu = find_user(&vmus, testcontext, testmailbox))) {
-// ast_test_status_update(test, "Cannot find vmu structure?!!\n");
-// return AST_TEST_NOT_RUN;
-// }
-//
-// populate_defaults(vmu);
-// ast_copy_string(vmu->email, "test2 at example.net", sizeof(vmu->email));
-//#ifdef IMAP_STORAGE
-// /* TODO When we set up the IMAP server test, we'll need to have credentials for the VMU structure added here */
-//#endif
-//
-// file = tmpfile();
-// for (which = 0; which < ARRAY_LEN(test_items); which++) {
-// /* Kill previous test, if any */
-// rewind(file);
-// if (ftruncate(fileno(file), 0)) {
-// ast_test_status_update(test, "Cannot truncate test output file: %s\n", strerror(errno));
-// res = AST_TEST_FAIL;
-// break;
-// }
-//
-// /* Make each change, in order, to the test mailbox */
-// if (test_items[which].type == INT) {
-// *((int *) test_items[which].location) = test_items[which].u.intval;
-// } else if (test_items[which].type == FLAGVAL) {
-// if (ast_test_flag(vmu, test_items[which].u.intval)) {
-// ast_clear_flag(vmu, test_items[which].u.intval);
-// } else {
-// ast_set_flag(vmu, test_items[which].u.intval);
-// }
-// } else if (test_items[which].type == STATIC) {
-// strcpy(test_items[which].location, test_items[which].u.strval);
-// } else if (test_items[which].type == STRPTR) {
-// test_items[which].location = test_items[which].u.strval;
-// }
-//
-// make_email_file(file, from, vmu, 0, testcontext, testmailbox, "INBOX", cidnum, cidname, attach, attach2, format, 999, 1, chan, NULL, 0, NULL);
-// rewind(file);
-// while (fgets(buf, sizeof(buf), file)) {
-// if (
-//#ifdef IMAP_STORAGE
-// buf[strlen(buf) - 2] != '\r'
-//#else
-// buf[strlen(buf) - 2] == '\r'
-//#endif
-// || buf[strlen(buf) - 1] != '\n') {
-// res = AST_TEST_FAIL;
-// }
-// }
-// }
-// fclose(file);
-// return res;
-//}
-//#endif /* defined(TEST_FRAMEWORK) */
+
static int reload(void)
{
Modified: team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/include/test_voicemail.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/include/test_voicemail.h?view=diff&rev=333782&r1=333781&r2=333782
==============================================================================
--- team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/include/test_voicemail.h (original)
+++ team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/include/test_voicemail.h Mon Aug 29 15:26:29 2011
@@ -61,6 +61,10 @@
void vm_unregister_config_tests(void);
+void vm_register_app_tests(void);
+
+void vm_unregister_app_tests(void);
+
/* TODO: add other backends / test entry points */
#endif /* TEST_VOICEMAIL_H_ */
Modified: team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/include/voicemail.h
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/include/voicemail.h?view=diff&rev=333782&r1=333781&r2=333782
==============================================================================
--- team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/include/voicemail.h (original)
+++ team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/include/voicemail.h Mon Aug 29 15:26:29 2011
@@ -1,7 +1,7 @@
/*
* Asterisk -- An open source telephony toolkit.
*
- * Copyright (C) 1999 - 2006, Digium, Inc.
+ * Copyright (C) 1999 - 2011, Digium, Inc.
*
* Mark Spencer <markster at digium.com>
*
@@ -82,8 +82,9 @@
};
enum vm_message_priorities {
- VM_PRIORITY_URGENT = 0,
- VM_PRIORITY_PRIORITY = 1,
+ VM_PRIORITY_NONE = 0,
+ VM_PRIORITY_URGENT = 1,
+ VM_PRIORITY_PRIORITY = 2,
VM_PRIORITY_NORMAL = 100,
VM_PRIORITY_LOW = INT_MAX
};
@@ -93,27 +94,32 @@
VM_PWD_CHANGE_INTERNAL = (1 << 1)
};
-/* TODO: not sure about all the char * */
+/*!
+ * \brief Object that defines properties of a voicemail, including message flags, priorities, duration, etc.
+ */
struct vm_msg_info {
- char origmailbox[AST_MAX_EXTENSION];
- char context[AST_MAX_CONTEXT];
- char macrocontext[AST_MAX_CONTEXT];
- char exten[AST_MAX_EXTENSION];
+ char origmailbox[AST_MAX_EXTENSION]; /*!< The originating mailbox */
+ char context[AST_MAX_CONTEXT]; /*!< The context that left this message */
+ char macrocontext[AST_MAX_CONTEXT]; /*!< Macro context */
+ char exten[AST_MAX_EXTENSION]; /*!< Extension that left this message */
char * rdnis;
- int exten_priority; /*!< The channel extension priority (NOT the message */
+ int exten_priority; /*!< The channel extension priority (NOT the message) */
struct ast_flags msg_flags; /*!< Flags on the message */
enum vm_message_priorities msg_priority; /*!< The message priority */
- char callerchan[AST_CHANNEL_NAME];
- char * callerid;
- char * origdate;
- long origtime;
- const char * category;
- int flag;
- int duration;
-};
-
+ char callerchan[AST_CHANNEL_NAME]; /*!< The caller channel name */
+ char * callerid; /*!< Caller ID */
+ char * origdate; /*!< The originating date */
+ long origtime; /*!< The originating time, in seconds */
+ const char * category; /*!< The category */
+ int flag; /*!< Flag codes (deprecated?) */
+ int duration; /*!< Message duration, in seconds */
+};
+
+/*!
+ * \brief In memory representation of a voicemail
+ */
struct vm_voicemail_object {
- char msg_name[32];
+ char msg_name[32]; /*!< The name of the message, unique within a folder */
char msg_location[PATH_MAX]; /*!< The directory path containing the message files */
char format[MAX_FORMAT_LENGTH]; /*!< The supported message formats */
int msgnum; /*!< The message number */
@@ -125,11 +131,10 @@
};
struct vm_folder {
- char name[32];
- char directory[PATH_MAX];
- int priority;
- int number_voicemails;
- int ignore;
+ char name[32]; /*!< The unique name of the folder */
+ char directory[PATH_MAX]; /*!< If local on a file system, the location on the file system that the folder is at */
+ int priority; /*!< If specified, all voicemails in the folder are set to have this priority */
+ int number_voicemails; /*!< The number of voicemails in the folder */
AST_LIST_HEAD_NOLOCK(voicemails, vm_voicemail_object) voicemails;
AST_LIST_ENTRY(vm_folder) list;
};
@@ -138,16 +143,16 @@
struct vm_timezone {
AST_LIST_ENTRY(vm_zone) list;
AST_DECLARE_STRING_FIELDS(
- AST_STRING_FIELD(name);
- AST_STRING_FIELD(timezone);
- AST_STRING_FIELD(msg_format);
+ AST_STRING_FIELD(name); /*!< The name of the timezone */
+ AST_STRING_FIELD(timezone); /*!< The timezone code */
+ AST_STRING_FIELD(msg_format); /*!< Formatting code for the timezone */
);
};
struct vm_sound_config {
AST_DECLARE_STRING_FIELDS(
- AST_STRING_FIELD(vm_password);
- AST_STRING_FIELD(vm_newpassword);
+ AST_STRING_FIELD(vm_password); /*!< Full name of the sound file to play for password prompt */
+ AST_STRING_FIELD(vm_newpassword); /*!< Full name of the sound file to play for prompting for a new password */
AST_STRING_FIELD(vm_invalid_password);
AST_STRING_FIELD(vm_password_changed);
AST_STRING_FIELD(vm_reenter_password);
Modified: team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/test_vm_filesystem.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/test_vm_filesystem.c?view=diff&rev=333782&r1=333781&r2=333782
==============================================================================
--- team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/test_vm_filesystem.c (original)
+++ team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/test_vm_filesystem.c Mon Aug 29 15:26:29 2011
@@ -420,6 +420,7 @@
int fieldsfound = 0;
int nTemp;
long lTemp;
+ char msg_env_loc[PATH_MAX];
int result = AST_TEST_PASS;
switch (cmd) {
@@ -458,7 +459,7 @@
vm_object->curfolder = folder;
snprintf(vm_object->format, sizeof(vm_object->format), "%s", "wav|gsm");
vm_object->msgnum = 4;
- snprintf(vm_object->msg_envelope_location, sizeof(vm_object->msg_envelope_location), "%s/msg%04d.txt", folder->directory, vm_object->msgnum);
+ snprintf(vm_object->msg_name, sizeof(vm_object->msg_name), "msg%04d", vm_object->msgnum);
vm_object->owner = vmu;
ast_copy_string(vm_object->msg_location, folder->directory, sizeof(vm_object->msg_location));
snprintf(vm_object->msg_info->callerchan, sizeof(vm_object->msg_info->callerchan), "%s", "test caller channel");
@@ -484,21 +485,22 @@
}
if (fs_backend->store_voicemail(vm_object)) {
- ast_test_status_update(test, "Failed to store voicemail object %s", vm_object->msg_envelope_location);
+ ast_test_status_update(test, "Failed to store voicemail object %s", vm_object->msg_name);
result = AST_TEST_FAIL;
goto cleanup;
}
/* Determine if the voicemail exists at the location specified */
- if (stat(vm_object->msg_envelope_location, &st)) {
- result = AST_TEST_FAIL;
- ast_test_status_update(test, "Voicemail was not physically present at the expected location: %s\n", vm_object->msg_envelope_location);
+ snprintf(msg_env_loc, sizeof(msg_env_loc), "%s.txt", vm_object->msg_location);
+ if (stat(msg_env_loc, &st)) {
+ result = AST_TEST_FAIL;
+ ast_test_status_update(test, "Voicemail was not physically present at the expected location: %s\n", vm_object->msg_name);
goto cleanup;
}
- msg_info = ast_config_load(vm_object->msg_envelope_location, config_flags);
+ msg_info = ast_config_load(msg_env_loc, config_flags);
if (!msg_info || msg_info == CONFIG_STATUS_FILEINVALID) {
- ast_test_status_update(test, "Failed to load message envelope file %s\n", vm_object->msg_envelope_location);
+ ast_test_status_update(test, "Failed to load message envelope file %s\n", msg_env_loc);
result = AST_TEST_FAIL;
goto cleanup;
}
@@ -680,7 +682,7 @@
vm_object->curfolder = folder;
snprintf(vm_object->format, sizeof(vm_object->format), "%s", "wav|gsm");
vm_object->msgnum = 4;
- snprintf(vm_object->msg_envelope_location, sizeof(vm_object->msg_envelope_location), "%s/msg%04d.txt", folder->directory, vm_object->msgnum);
+ snprintf(vm_object->msg_name, sizeof(vm_object->msg_name), "msg%04d", vm_object->msgnum);
vm_object->owner = vmu;
ast_copy_string(vm_object->msg_location, folder->directory, sizeof(vm_object->msg_location));
snprintf(vm_object->msg_info->callerchan, sizeof(vm_object->msg_info->callerchan), "%s", "test caller channel");
@@ -701,7 +703,7 @@
/* Store the voicemail */
if (fs_backend->store_voicemail(vm_object)) {
- ast_test_status_update(test, "Failed to store voicemail object %s", vm_object->msg_envelope_location);
+ ast_test_status_update(test, "Failed to store voicemail object %s", vm_object->msg_name);
result = AST_TEST_FAIL;
goto cleanup;
}
@@ -914,7 +916,7 @@
if (vm_object) {
/* Delete the real voicemail */
strcpy(msg_location, vm_object->msg_location);
- strcpy(msg_env_location, vm_object->msg_envelope_location);
+ snprintf(msg_env_location, sizeof(msg_env_location), "%s.txt", vm_object->msg_location);
if (fs_backend->delete_voicemail(vm_object)) {
result = AST_TEST_FAIL;
ast_test_status_update(test, "Failed to delete voicemail %s\n", msg_location);
@@ -952,6 +954,7 @@
struct vm_voicemail_object * expected;
struct vm_folder * temp_folder;
char temp_directory_path[PATH_MAX];
+ char msg_env_loc[PATH_MAX];
struct stat st;
int result = AST_TEST_PASS;
@@ -1045,10 +1048,11 @@
VM_TEST_NUMERIC_EQUAL(1, inbox_folder->number_voicemails);
VM_TEST_NUMERIC_EQUAL(1, (expected != NULL));
if (expected) {
- if (stat(expected->msg_envelope_location, &st)) {
+ snprintf(msg_env_loc, sizeof(msg_env_loc), "%s.txt", expected->msg_location);
+ if (stat(msg_env_loc, &st)) {
/* File not found */
result = AST_TEST_FAIL;
- ast_test_status_update(test, "Failed to copy message envelope file %s\n", expected->msg_envelope_location);
+ ast_test_status_update(test, "Failed to copy message envelope file %s\n", msg_env_loc);
}
if (!ast_fileexists(expected->msg_location, NULL, NULL)) {
@@ -1077,9 +1081,12 @@
struct vm_voicemail_object * vmobj = NULL;
char orig_src_path[PATH_MAX];
char orig_msg_env_path[PATH_MAX];
+ char orig_name[32];
int orig_msg_num;
char expected_src_path[PATH_MAX];
char expected_msg_env_path[PATH_MAX];
+ char expected_name[32];
+ char actual_msg_env_path[PATH_MAX];
int expected_msg_num;
int result = AST_TEST_PASS;
struct stat st;
@@ -1160,7 +1167,8 @@
/* Rename the voicemail */
if (vmobj) {
strcpy(orig_src_path, vmobj->msg_location);
- strcpy(orig_msg_env_path, vmobj->msg_envelope_location);
+ strcpy(orig_name, vmobj->msg_name);
+ snprintf(orig_msg_env_path, sizeof(orig_msg_env_path), "%s.txt", vmobj->msg_location);
orig_msg_num = vmobj->msgnum;
strcpy(expected_src_path, vmobj->curfolder->directory);
@@ -1170,15 +1178,20 @@
if (fs_backend->rename_voicemail(vmobj, 20)) {
result = AST_TEST_FAIL;
- ast_test_status_update(test, "Failed to rename voicemail [%s]\n", vmobj->msg_envelope_location);
+ ast_test_status_update(test, "Failed to rename voicemail [%s]\n", vmobj->msg_name);
} else {
/* Verify that the message properties have changed */
if (strcmp(expected_src_path, vmobj->msg_location)) {
ast_test_status_update(test, "Bad msg_location:\n\tExpected: %s\n\tActual: %s\n", expected_src_path, vmobj->msg_location);
result = AST_TEST_FAIL;
}
- if (strcmp(expected_msg_env_path, vmobj->msg_envelope_location)) {
- ast_test_status_update(test, "Bad msg_envelope_location:\n\tExpected: %s\n\tActual: %s\n", expected_msg_env_path, vmobj->msg_envelope_location);
+ snprintf(actual_msg_env_path, sizeof(actual_msg_env_path), "%s.txt", vmobj->msg_location);
+ if (strcmp(expected_msg_env_path, actual_msg_env_path)) {
+ ast_test_status_update(test, "Bad msg_envelope_location:\n\tExpected: %s\n\tActual: %s\n", expected_msg_env_path, actual_msg_env_path);
+ result = AST_TEST_FAIL;
+ }
+ if (strcmp(expected_name, vmobj->msg_name)) {
+ ast_test_status_update(test, "Bad msg_name:\n\tExpected: %s\n\tActual: %s\n", expected_name, vmobj->msg_name);
result = AST_TEST_FAIL;
}
if (expected_msg_num != vmobj->msgnum) {
@@ -1191,8 +1204,8 @@
ast_test_status_update(test, "Failed to find sound files for file %s, format %s\n", vmobj->msg_location, vmobj->format);
result = AST_TEST_FAIL;
}
- if ( stat(vmobj->msg_envelope_location, &st) ) {
- ast_test_status_update(test, "Failed to find message envelope file %s\n", vmobj->msg_envelope_location);
+ if ( stat(actual_msg_env_path, &st) ) {
+ ast_test_status_update(test, "Failed to find message envelope file %s\n", actual_msg_env_path);
result = AST_TEST_FAIL;
}
}
Modified: team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/vm_config_parser.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/vm_config_parser.c?view=diff&rev=333782&r1=333781&r2=333782
==============================================================================
--- team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/vm_config_parser.c (original)
+++ team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/vm_config_parser.c Mon Aug 29 15:26:29 2011
@@ -512,52 +512,6 @@
}
return vmu;
-}
-
-struct ast_vm_user * vm_find_user(const char * context, const char * mailbox)
-{
- struct ast_vm_user * vmu = NULL;
- struct ast_vm_user * tmp = NULL;
-
- if (!(tmp = vm_voicemail_user_new(context, mailbox))) {
- ast_log(AST_LOG_ERROR, "Failed to create temporary voicemail search object for context %s, extension %s\n", context, mailbox);
- } else {
- ao2_lock(voicemail_users);
-
- vmu = ao2_find(voicemail_users, tmp, OBJ_POINTER);
-
- ao2_unlock(voicemail_users);
-
- ao2_ref(tmp, -1);
-
- if (vmu) {
- ao2_ref(vmu, +1);
- }
- }
-
- return vmu;
-}
-
-struct vm_timezone * vm_find_timezone(const char * name)
-{
- struct vm_timezone * tmp_tz = NULL;
- struct vm_timezone * tz = NULL;
-
- if (!(tmp_tz = vm_timezone_new())) {
- ast_log(AST_LOG_ERROR, "Failed to create temporary timezone search object for timezone %s\n", name);
- } else {
- ast_string_field_set(tmp_tz, name, name);
-
- tz = ao2_find(timezones, tmp_tz, OBJ_POINTER);
- ao2_ref(tmp_tz, -1);
-
- if (tz) {
- ao2_ref(tz, +1);
- }
-
- }
-
- return tz;
}
/*!
@@ -1111,6 +1065,53 @@
/* Object is managed by ao2_alloc - no need to free it explicitly */
}
+struct ast_vm_user * vm_find_user(const char * context, const char * mailbox)
+{
+ struct ast_vm_user * vmu = NULL;
+ struct ast_vm_user * tmp = NULL;
+
+ /* TODO: use the new mechanism for searching */
+ if (!(tmp = vm_voicemail_user_new(context, mailbox))) {
+ ast_log(AST_LOG_ERROR, "Failed to create temporary voicemail search object for context %s, extension %s\n", context, mailbox);
+ } else {
+ ao2_lock(voicemail_users);
+
+ vmu = ao2_find(voicemail_users, tmp, OBJ_POINTER);
+
+ ao2_unlock(voicemail_users);
+
+ ao2_ref(tmp, -1);
+
+ if (vmu) {
+ ao2_ref(vmu, +1);
+ }
+ }
+
+ return vmu;
+}
+
+struct vm_timezone * vm_find_timezone(const char * name)
+{
+ struct vm_timezone * tmp_tz = NULL;
+ struct vm_timezone * tz = NULL;
+
+ if (!(tmp_tz = vm_timezone_new())) {
+ ast_log(AST_LOG_ERROR, "Failed to create temporary timezone search object for timezone %s\n", name);
+ } else {
+ ast_string_field_set(tmp_tz, name, name);
+
+ tz = ao2_find(timezones, tmp_tz, OBJ_POINTER);
+ ao2_ref(tmp_tz, -1);
+
+ if (tz) {
+ ao2_ref(tz, +1);
+ }
+
+ }
+
+ return tz;
+}
+
int vm_load_config(const int reload, struct ast_config ** base_config, struct vm_config ** main_config)
{
/*struct ast_config * ucfg;*/
Modified: team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/vm_filesystem.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/vm_filesystem.c?view=diff&rev=333782&r1=333781&r2=333782
==============================================================================
--- team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/vm_filesystem.c (original)
+++ team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/vm_filesystem.c Mon Aug 29 15:26:29 2011
@@ -265,9 +265,12 @@
[... 106 lines stripped ...]
More information about the asterisk-commits
mailing list