[asterisk-commits] mjordan: branch mjordan/voicemail_refactor_01_08_11 r333946 - in /team/mjorda...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Aug 30 14:37:15 CDT 2011
Author: mjordan
Date: Tue Aug 30 14:37:11 2011
New Revision: 333946
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=333946
Log:
Updating branch
Added:
team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/test_vm_apps.c (with props)
Modified:
team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/include/voicemail.h
team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/vm_filesystem.c
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=333946&r1=333945&r2=333946
==============================================================================
--- 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 Tue Aug 30 14:37:11 2011
@@ -35,6 +35,10 @@
#define VOICEMAIL_FILE_MODE 0666
#define MAX_DTMF_LENGTH 16
+
+#define MAX_MSG_NAME_LENGTH 32
+
+#define MAX_FOLDER_NAME_LENGTH 64
#define MAX_FORMAT_LENGTH 64
@@ -70,9 +74,13 @@
};
enum vm_message_flags {
- VM_MSG_NEW = (1 << 0),
- VM_MSG_TMP = (1 << 1),
- VM_MSG_OLD = (1 << 2)
+ VM_MSG_NEW = (1 << 0),
+ VM_MSG_TMP = (1 << 1),
+ VM_MSG_OLD = (1 << 2),
+ VM_MSG_GREETING_TEMP = (1 << 3),
+ VM_MSG_GREETING_NAME = (1 << 4),
+ VM_MSG_GREETING_BUSY = (1 << 5),
+ VM_MSG_GREETING_UNAVAIL = (1 << 6)
};
enum vm_passwordlocation {
@@ -119,7 +127,7 @@
* \brief In memory representation of a voicemail
*/
struct vm_voicemail_object {
- char msg_name[32]; /*!< The name of the message, unique within a folder */
+ char msg_name[MAX_MSG_NAME_LENGTH]; /*!< 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 */
@@ -131,7 +139,7 @@
};
struct vm_folder {
- char name[32]; /*!< The unique name of the folder */
+ char name[MAX_FOLDER_NAME_LENGTH]; /*!< 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 */
@@ -364,7 +372,7 @@
*
* \returns 0 on success, any other value on failure or if the voicemail could not be found
*/
- int (* const retrieve_voicemail)(struct vm_folder * folder, const int msgnum, struct vm_voicemail_object * * vm_object);
+ int (* const retrieve_voicemail)(struct vm_folder *folder, const int msgnum, struct vm_voicemail_object **vm_object);
/*!
* \brief Dispose of the voicemail, if the voicemail is a temporary object
@@ -377,7 +385,7 @@
*
* \returns 0 if the vm_object was ignored or successfully dispose of, 1 if an error occurred in disposing of the voicemail.
*/
- int (* const dispose_voicemail)(struct vm_voicemail_object * vm_object);
+ int (* const dispose_voicemail)(struct vm_voicemail_object *vm_object);
/*!
* \brief Check that the voicemail exists in the backing storage
@@ -390,7 +398,7 @@
* \returns 0 if the vm_object does not exist
* \returns 1 if the vm_object does exist
*/
- int (* const voicemail_exists)(const struct vm_voicemail_object * const vm_object);
+ int (* const voicemail_exists)(const struct vm_voicemail_object *const vm_object);
/*!
* \brief Determine if a folder exists
@@ -405,7 +413,7 @@
* \returns 0 if the folder does not exist
* \returns 1 if the folder does exist
*/
- int (* const folder_exists)(const char * const name, const struct ast_vm_user * const vmu);
+ int (* const folder_exists)(const char *const name, const struct ast_vm_user *const vmu);
/*!
* \brief Permanently delete a voicemail
@@ -422,7 +430,7 @@
* \returns 0 if the voicemail was successfully removed
* \returns any other value if an error occurred
*/
- int (* const delete_voicemail)(struct vm_voicemail_object * vm_object);
+ int (* const delete_voicemail)(struct vm_voicemail_object *vm_object);
/*!
* \brief Copy a voicemail to a destination folder
@@ -439,7 +447,7 @@
* \returns 0 on success
* \returns any other value on failure
*/
- int (* const copy_voicemail)(struct vm_voicemail_object * vm_obj_src, struct vm_folder * dest_folder);
+ int (* const copy_voicemail)(struct vm_voicemail_object *vm_obj_src, struct vm_folder *dest_folder);
/*!
* \brief Renames a voicemail object within a folder
@@ -456,7 +464,7 @@
* \returns 0 on success
* \returns any other value on error
*/
- int (* const rename_voicemail)(struct vm_voicemail_object * vm_object, const int msgnum);
+ int (* const rename_voicemail)(struct vm_voicemail_object *vm_object, const int msgnum);
/*!
* \brief Return the count in the current folder. If no folder is specified, returns a count across all folders for the user.
@@ -466,7 +474,7 @@
* \details
* \returns The number of voicemails the user has, either in a folder or cumulative across all folders
*/
- int (* const count_voicemail)(const struct ast_vm_user * const vmu, const struct vm_folder * folder);
+ int (* const count_voicemail)(const struct ast_vm_user *const vmu, const struct vm_folder *folder);
/*!
* \brief Open the voicemail folders for the specified user, loading them and their current voicemails into memory
@@ -484,7 +492,7 @@
* \returns 0 on success
* \returns any other value on failure
*/
- int (* const open_voicemail)(struct ast_vm_user * vmu);
+ int (* const open_voicemail)(struct ast_vm_user *vmu);
/*!
* \brief Initialize the backing storage
@@ -500,14 +508,14 @@
* \returns 0 on successful intialization
* \returns any other value on error
*/
- int (* const init_backend)(struct ast_config * cfg, struct vm_config * vmcfg);
+ int (* const init_backend)(struct ast_config *cfg, struct vm_config *vmcfg);
};
/* TODO: this is preferable, and each of the backends would be a module. However, currently they aren't being compiled
* as a shared object, so this blows up spectacularly. For now, we're going to put some methods in here that are called
* directly from the app_voicemail to build up the backends. These should be removed when possible.
*/
-int vm_register_backend(struct vm_backend_tech * vm_backend);
+int vm_register_backend(struct vm_backend_tech *vm_backend);
/* OR */
struct vm_backend_tech * vm_allocate_filesystem(void);
Added: team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/test_vm_apps.c
URL: http://svnview.digium.com/svn/asterisk/team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/test_vm_apps.c?view=auto&rev=333946
==============================================================================
--- team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/test_vm_apps.c (added)
+++ team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/test_vm_apps.c Tue Aug 30 14:37:11 2011
@@ -1,0 +1,455 @@
+/*
+ * test_vm_apps.c
+ *
+ * Created on: Aug 2, 2011
+ * Author: mjordan
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/test.h"
+#include "asterisk/app.h"
+
+#include "include/voicemail.h"
+#include "include/test_voicemail.h"
+
+/*AST_TEST_DEFINE(test_vm_app_)
+{
+ int result = AST_TEST_PASS;
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "test_vm_app_";
+ info->category = "/apps/app_voicemail/";
+ info->summary = "VoiceMail unit test";
+ info->description =
+ "This tests ...";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ return result;
+}*/
+
+//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 mock_write(struct ast_channel *ast, struct ast_frame *frame)
+//{
+// return 0;
+//}
+//
+//static struct ast_frame *mock_read(struct ast_channel *ast)
+//{
+// struct ast_frame *ret_frame = &ast_null_frame;
+//
+// return ret_frame;
+//}
+//
+//static const struct ast_channel_tech mock_channel_tech = {
+// .write = mock_write,
+// .read = mock_read,
+//};
+//
+//struct mock_channel_thread_args {
+// void *(* const callback_fn)(void*);
+// void *data;
+//};
+//
+
+AST_TEST_DEFINE(test_vm_app_leave_voicemail_)
+{
+ int result = AST_TEST_PASS;
+
+ switch (cmd) {
+ case TEST_INIT:
+ info->name = "test_vm_app_";
+ info->category = "/apps/app_voicemail/";
+ info->summary = "VoiceMail unit test";
+ info->description =
+ "This tests ...";
+ return AST_TEST_NOT_RUN;
+ case TEST_EXECUTE:
+ break;
+ }
+
+ return result;
+}
+
+void vm_register_app_tests(void)
+{
+
+}
+
+void vm_unregister_app_tests(void)
+{
+
+}
Propchange: team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/test_vm_apps.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/test_vm_apps.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/mjordan/voicemail_refactor_01_08_11/apps/voicemail/test_vm_apps.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=333946&r1=333945&r2=333946
==============================================================================
--- 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 Tue Aug 30 14:37:11 2011
@@ -156,7 +156,7 @@
static int retrieve_voicemail_no_lock(struct vm_folder * folder, const int msgnum, struct vm_voicemail_object * * vm_object)
{
char msg_path[PATH_MAX];
- char msg_name[32];
+ char msg_name[MAX_MSG_NAME_LENGTH];
char msg_env_path[PATH_MAX];
struct ast_config * msg_info = NULL;
struct ast_variable * ast_var = NULL;
@@ -606,6 +606,7 @@
if (!vm_object || !(vm_object->msg_info) || !(vm_object->curfolder)) {
return 1;
}
+
msginfo = vm_object->msg_info;
/* Lock the location on disk */
@@ -704,6 +705,7 @@
if (!vm_object)
return 0;
+ /* Determine if the voicemail has been added to its folder */
if (vm_object->curfolder) {
AST_LIST_TRAVERSE(&(vm_object->curfolder->voicemails), it_object, list) {
if (it_object == vm_object) {
@@ -712,9 +714,18 @@
}
}
- snprintf(msg_env_path, sizeof(msg_env_path), "%s.txt", vm_object->msg_location);
- retStatus |= ast_fileexists(vm_object->msg_location, NULL, NULL);
- retStatus |= !stat(msg_env_path, &st);
+ /* Check the physical location on disk */
+ if (vm_object->curfolder) {
+ if (ast_lock_path(vm_object->curfolder->directory)) {
+ /* Failed to lock - return false */
+ return 0;
+ }
+ snprintf(msg_env_path, sizeof(msg_env_path), "%s.txt", vm_object->msg_location);
+ retStatus |= ast_fileexists(vm_object->msg_location, NULL, NULL);
+ retStatus |= !stat(msg_env_path, &st);
+
+ ast_unlock_path(vm_object->curfolder->directory);
+ }
return retStatus;
}
@@ -816,7 +827,7 @@
make_file_path(new_vm_object->msg_location, sizeof(new_vm_object->msg_location), dest_folder->directory, vm_object->msgnum);
snprintf(msg_env_path, sizeof(msg_env_path), "%s.txt", new_vm_object->msg_location);
- /* Clear any flags, and set the flag on the message to new */
+ /* Clear old / temp flags, and set the flag on the message to new */
ast_set2_flag(&(new_vm_object->msg_info->msg_flags), 0, VM_MSG_TMP);
ast_set2_flag(&(new_vm_object->msg_info->msg_flags), 0, VM_MSG_OLD);
ast_set2_flag(&(new_vm_object->msg_info->msg_flags), 1, VM_MSG_NEW);
More information about the asterisk-commits
mailing list