[asterisk-commits] branch oej/voicemail-ng r12489 - in
/team/oej/voicemail-ng: ./ apps/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Fri Mar 10 01:08:43 MST 2006
Author: oej
Date: Fri Mar 10 02:08:41 2006
New Revision: 12489
URL: http://svn.digium.com/view/asterisk?rev=12489&view=rev
Log:
Patch from issue #6504 - storage abstraction
Modified:
team/oej/voicemail-ng/ (props changed)
team/oej/voicemail-ng/apps/app_voicemail.c
Propchange: team/oej/voicemail-ng/
------------------------------------------------------------------------------
svnmerge-integrated = /trunk:1-12486
Modified: team/oej/voicemail-ng/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/oej/voicemail-ng/apps/app_voicemail.c?rev=12489&r1=12488&r2=12489&view=diff
==============================================================================
--- team/oej/voicemail-ng/apps/app_voicemail.c (original)
+++ team/oej/voicemail-ng/apps/app_voicemail.c Fri Mar 10 02:08:41 2006
@@ -266,6 +266,28 @@
int starting;
int repeats;
};
+
+struct vm_storage {
+ /* Database storage/retrieval functions */
+ int (*retrieve_file)(char *dir, int msgnum);
+ int (*dispose_file)(char *dir, int msgnum);
+ int (*store_file)(char *dir, char *mailbox, char *mailboxcontext, int msgnum);
+
+ /* File operations */
+ void (*rename_file)(char *sdir, int smsg, char *mailbox, char *mailboxcontext, char *ddir, int dmsg, char *sfn, char *dfn);
+ void (*copy_file)(char *sdir, int smsg, char *ddir, int dmsg, char *dmailbox, char *dmailboxcontext, char *frompath, char *topath);
+ void (*delete_file)(char *sdir, int smsg, char *file);
+
+ /* Message operations */
+ int (*message_exists)(char *dir, int msgnum, char *filename, const char *preflang);
+ int (*count_messages)(struct ast_vm_user *vmu, char *dir);
+ int (*last_message_index)(struct ast_vm_user *vmu, char *dir);
+
+ /* Message operations -- exported to the rest of asterisk via ast_install_vm_functions */
+ int (*message_count)(const char *mailbox, int *newmsgs, int *oldmsgs);
+ int (*has_voicemail)(const char *mailbox, const char *folder);
+};
+
static int advanced_options(struct ast_channel *chan, struct ast_vm_user *vmu, struct vm_state *vms, int msg,
int option, signed char record_gain);
static int dialout(struct ast_channel *chan, struct ast_vm_user *vmu, char *num, char *outgoing_context);
@@ -277,24 +299,11 @@
static void apply_options(struct ast_vm_user *vmu, const char *options);
+static int vm_delete(char *file);
+
#ifdef USE_ODBC_STORAGE
static char odbc_database[80];
static char odbc_table[80];
-#define RETRIEVE(a,b) retrieve_file(a,b)
-#define DISPOSE(a,b) remove_file(a,b)
-#define STORE(a,b,c,d) store_file(a,b,c,d)
-#define EXISTS(a,b,c,d) (message_exists(a,b))
-#define RENAME(a,b,c,d,e,f,g,h) (rename_file(a,b,c,d,e,f))
-#define COPY(a,b,c,d,e,f,g,h) (copy_file(a,b,c,d,e,f))
-#define DELETE(a,b,c) (delete_file(a,b))
-#else
-#define RETRIEVE(a,b)
-#define DISPOSE(a,b)
-#define STORE(a,b,c,d)
-#define EXISTS(a,b,c,d) (ast_fileexists(c,NULL,d) > 0)
-#define RENAME(a,b,c,d,e,f,g,h) (rename_file(g,h));
-#define COPY(a,b,c,d,e,f,g,h) (copy_file(g,h));
-#define DELETE(a,b,c) (vm_delete(c))
#endif
static char VM_SPOOL_DIR[AST_CONFIG_MAX_PATH];
@@ -429,6 +438,8 @@
static unsigned char adsisec[4] = "\x9B\xDB\xF7\xAC";
static int adsiver = 1;
static char emaildateformat[32] = "%A, %B %d, %Y at %r";
+
+static struct vm_storage *storage = NULL;
LOCAL_USER_DECL;
@@ -829,7 +840,7 @@
#ifdef USE_ODBC_STORAGE
-static int retrieve_file(char *dir, int msgnum)
+static int odbc_retrieve_file(char *dir, int msgnum)
{
int x = 0;
int res;
@@ -971,7 +982,7 @@
return x - 1;
}
-static int remove_file(char *dir, int msgnum)
+static int odbc_dispose_file(char *dir, int msgnum)
{
char fn[256];
char full_fn[256];
@@ -988,7 +999,7 @@
return 0;
}
-static int last_message_index(struct ast_vm_user *vmu, char *dir)
+static int odbc_last_message_index(struct ast_vm_user *vmu, char *dir)
{
int x = 0;
int res;
@@ -1039,7 +1050,7 @@
return x - 1;
}
-static int message_exists(char *dir, int msgnum)
+static int odbc_message_exists(char *dir, int msgnum, char *filename, const char *preflang)
{
int x = 0;
int res;
@@ -1093,12 +1104,12 @@
return x;
}
-static int count_messages(struct ast_vm_user *vmu, char *dir)
-{
- return last_message_index(vmu, dir) + 1;
-}
-
-static void delete_file(char *sdir, int smsg)
+static int odbc_count_messages(struct ast_vm_user *vmu, char *dir)
+{
+ return odbc_last_message_index(vmu, dir) + 1;
+}
+
+static void odbc_delete_file(char *sdir, int smsg, char *file)
{
int res;
SQLHSTMT stmt;
@@ -1136,7 +1147,7 @@
return;
}
-static void copy_file(char *sdir, int smsg, char *ddir, int dmsg, char *dmailboxuser, char *dmailboxcontext)
+static void odbc_copy_file(char *sdir, int smsg, char *ddir, int dmsg, char *dmailboxuser, char *dmailboxcontext, char *frompath, char *topath)
{
int res;
SQLHSTMT stmt;
@@ -1145,7 +1156,7 @@
char msgnumd[20];
odbc_obj *obj;
- delete_file(ddir, dmsg);
+ odbc_delete_file(ddir, dmsg, topath);
obj = fetch_odbc_obj(odbc_database, 0);
if (obj) {
snprintf(msgnums, sizeof(msgnums), "%d", smsg);
@@ -1190,7 +1201,7 @@
return;
}
-static int store_file(char *dir, char *mailboxuser, char *mailboxcontext, int msgnum)
+static int odbc_store_file(char *dir, char *mailboxuser, char *mailboxcontext, int msgnum)
{
int x = 0;
int res;
@@ -1210,7 +1221,7 @@
struct ast_config *cfg=NULL;
odbc_obj *obj;
- delete_file(dir, msgnum);
+ odbc_delete_file(dir, msgnum, NULL);
obj = fetch_odbc_obj(odbc_database, 0);
if (obj) {
ast_copy_string(fmt, vmfmts, sizeof(fmt));
@@ -1314,7 +1325,7 @@
return x;
}
-static void rename_file(char *sdir, int smsg, char *mailboxuser, char *mailboxcontext, char *ddir, int dmsg)
+static void odbc_rename_file(char *sdir, int smsg, char *mailboxuser, char *mailboxcontext, char *ddir, int dmsg, char *sfn, char *dfn)
{
int res;
SQLHSTMT stmt;
@@ -1323,7 +1334,7 @@
char msgnumd[20];
odbc_obj *obj;
- delete_file(ddir, dmsg);
+ odbc_delete_file(ddir, dmsg, dfn);
obj = fetch_odbc_obj(odbc_database, 0);
if (obj) {
snprintf(msgnums, sizeof(msgnums), "%d", smsg);
@@ -1368,9 +1379,19 @@
return;
}
-#else
-
-static int count_messages(struct ast_vm_user *vmu, char *dir)
+#endif
+
+static int spool_message_exists(char *dir, int msgnum, char *filename, const char *preflang)
+{
+ return ast_fileexists(filename, NULL, preflang) > 0;
+};
+
+static void spool_delete_file(char *sdir, int smsg, char *file)
+{
+ vm_delete(file);
+}
+
+static int spool_count_messages(struct ast_vm_user *vmu, char *dir)
{
/* Find all .txt files - even if they are not in sequence from 0000 */
@@ -1393,7 +1414,7 @@
return vmcount;
}
-static void rename_file(char *sfn, char *dfn)
+static void spool_rename_file(char *sdir, int smsg, char *mailboxuser, char *mailboxcontext, char *ddir, int dmsg, char *sfn, char *dfn)
{
char stxt[256];
char dtxt[256];
@@ -1403,7 +1424,7 @@
rename(stxt, dtxt);
}
-static int copy(char *infile, char *outfile)
+static int spool_copy(char *infile, char *outfile)
{
int ifd;
int ofd;
@@ -1453,19 +1474,19 @@
#endif
}
-static void copy_file(char *frompath, char *topath)
+static void spool_copy_file(char *sdir, int smsg, char *ddir, int dmsg, char *dmailboxuser, char *dmailboxcontext, char *frompath, char *topath)
{
char frompath2[256],topath2[256];
ast_filecopy(frompath, topath, NULL);
snprintf(frompath2, sizeof(frompath2), "%s.txt", frompath);
snprintf(topath2, sizeof(topath2), "%s.txt", topath);
- copy(frompath2, topath2);
+ spool_copy(frompath2, topath2);
}
/*
* A negative return value indicates an error.
*/
-static int last_message_index(struct ast_vm_user *vmu, char *dir)
+static int spool_last_message_index(struct ast_vm_user *vmu, char *dir)
{
int x;
char fn[256];
@@ -1498,8 +1519,6 @@
return ast_filedelete(file, NULL);
}
-
-#endif
static int
inbuf(struct baseio *bio, FILE *fi)
{
@@ -1905,21 +1924,21 @@
int res;
char fn[256];
snprintf(fn, sizeof(fn), "%s%s/%s/greet", VM_SPOOL_DIR, context, ext);
- RETRIEVE(fn, -1);
+ storage->retrieve_file(fn, -1);
if (ast_fileexists(fn, NULL, NULL) > 0) {
res = ast_streamfile(chan, fn, chan->language);
if (res) {
- DISPOSE(fn, -1);
+ storage->dispose_file(fn, -1);
return -1;
}
res = ast_waitstream(chan, ecodes);
if (res) {
- DISPOSE(fn, -1);
+ storage->dispose_file(fn, -1);
return res;
}
} else {
/* Dispose just in case */
- DISPOSE(fn, -1);
+ storage->dispose_file(fn, -1);
res = ast_streamfile(chan, "vm-theperson", chan->language);
if (res)
return -1;
@@ -1980,7 +1999,7 @@
}
#ifdef USE_ODBC_STORAGE
-static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
+static int odbc_messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
{
int x = 0;
int res;
@@ -2083,7 +2102,7 @@
return x;
}
-static int has_voicemail(const char *mailbox, const char *folder)
+static int odbc_has_voicemail(const char *mailbox, const char *folder)
{
int nummsgs = 0;
int res;
@@ -2152,9 +2171,9 @@
return 0;
}
-#else
-
-static int has_voicemail(const char *mailbox, const char *folder)
+#endif
+
+static int spool_has_voicemail(const char *mailbox, const char *folder)
{
DIR *dir;
struct dirent *de;
@@ -2174,7 +2193,7 @@
ret = 0;
while((cur = strsep(&mb, ","))) {
if (!ast_strlen_zero(cur)) {
- if (has_voicemail(cur, folder))
+ if (spool_has_voicemail(cur, folder))
return 1;
}
}
@@ -2202,7 +2221,7 @@
}
-static int messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
+static int spool_messagecount(const char *mailbox, int *newmsgs, int *oldmsgs)
{
DIR *dir;
struct dirent *de;
@@ -2225,7 +2244,7 @@
ret = 0;
while((cur = strsep(&mb, ", "))) {
if (!ast_strlen_zero(cur)) {
- if (messagecount(cur, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
+ if (spool_messagecount(cur, newmsgs ? &tmpnew : NULL, oldmsgs ? &tmpold : NULL))
return -1;
else {
if (newmsgs)
@@ -2273,8 +2292,6 @@
return 0;
}
-#endif
-
static int notify_new_message(struct ast_channel *chan, struct ast_vm_user *vmu, int msgnum, long duration, char *fmt, char *cidnum, char *cidname);
static int copy_message(struct ast_channel *chan, struct ast_vm_user *vmu, int imbox, int msgnum, long duration, struct ast_vm_user *recip, char *fmt)
@@ -2296,12 +2313,12 @@
recipmsgnum = 0;
do {
make_file(topath, sizeof(topath), todir, recipmsgnum);
- if (!EXISTS(todir, recipmsgnum, topath, chan->language))
+ if (!storage->message_exists(todir, recipmsgnum, topath, chan->language))
break;
recipmsgnum++;
} while (recipmsgnum < recip->maxmsg);
if (recipmsgnum < recip->maxmsg) {
- COPY(fromdir, msgnum, todir, recipmsgnum, recip->mailbox, recip->context, frompath, topath);
+ storage->copy_file(fromdir, msgnum, todir, recipmsgnum, recip->mailbox, recip->context, frompath, topath);
} else {
ast_log(LOG_ERROR, "Recipient mailbox %s@%s is full\n", recip->mailbox, recip->context);
}
@@ -2347,7 +2364,7 @@
#else
if (!ast_strlen_zero(externnotify)) {
#endif
- if (messagecount(ext_context, &newvoicemails, &oldvoicemails)) {
+ if (storage->message_count(ext_context, &newvoicemails, &oldvoicemails)) {
ast_log(LOG_ERROR, "Problem in calculating number of voicemail messages available for extension %s\n", extension);
} else {
snprintf(arguments, sizeof(arguments), "%s %s %s %d&", externnotify, context, extension, newvoicemails);
@@ -2422,10 +2439,10 @@
else if (ast_test_flag(options, OPT_UNAVAIL_GREETING))
snprintf(prefile, sizeof(prefile), "%s%s/%s/unavail", VM_SPOOL_DIR, vmu->context, ext);
snprintf(tempfile, sizeof(tempfile), "%s%s/%s/temp", VM_SPOOL_DIR, vmu->context, ext);
- RETRIEVE(tempfile, -1);
+ storage->retrieve_file(tempfile, -1);
if (ast_fileexists(tempfile, NULL, NULL) > 0)
ast_copy_string(prefile, tempfile, sizeof(prefile));
- DISPOSE(tempfile, -1);
+ storage->dispose_file(tempfile, -1);
/* It's easier just to try to make it than to check for its existence */
create_dirpath(dir, sizeof(dir), vmu->context, ext, "INBOX");
@@ -2452,7 +2469,7 @@
/* Play the beginning intro if desired */
if (!ast_strlen_zero(prefile)) {
- RETRIEVE(prefile, -1);
+ storage->retrieve_file(prefile, -1);
if (ast_fileexists(prefile, NULL, NULL) > 0) {
if (ast_streamfile(chan, prefile, chan->language) > -1)
res = ast_waitstream(chan, ecodes);
@@ -2460,7 +2477,7 @@
ast_log(LOG_DEBUG, "%s doesn't exist, doing what we can\n", prefile);
res = invent_message(chan, vmu->context, ext, ast_test_flag(options, OPT_BUSY_GREETING), ecodes);
}
- DISPOSE(prefile, -1);
+ storage->dispose_file(prefile, -1);
if (res < 0) {
ast_log(LOG_DEBUG, "Hang up during prefile playback\n");
free_user(vmu);
@@ -2543,7 +2560,7 @@
*/
do {
make_file(fn, sizeof(fn), dir, msgnum);
- if (!EXISTS(dir,msgnum,fn,chan->language))
+ if (!storage->message_exists(dir,msgnum,fn,chan->language))
break;
msgnum++;
} while (msgnum < vmu->maxmsg);
@@ -2606,7 +2623,7 @@
if (duration < vmminmessage) {
if (option_verbose > 2)
ast_verbose( VERBOSE_PREFIX_3 "Recording was %d seconds long but needs to be at least %d - abandoning\n", duration, vmminmessage);
- DELETE(dir,msgnum,fn);
+ storage->delete_file(dir,msgnum,fn);
/* XXX We should really give a prompt too short/option start again, with leave_vm_out called only after a timeout XXX */
pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED");
goto leave_vm_out;
@@ -2628,9 +2645,9 @@
}
}
if (ast_fileexists(fn, NULL, NULL)) {
- STORE(dir, vmu->mailbox, vmu->context, msgnum);
+ storage->store_file(dir, vmu->mailbox, vmu->context, msgnum);
notify_new_message(chan, vmu, msgnum, duration, fmt, chan->cid.cid_num, chan->cid.cid_name);
- DISPOSE(dir, msgnum);
+ storage->dispose_file(dir, msgnum);
}
pbx_builtin_setvar_helper(chan, "VMSTATUS", "SUCCESS");
} else {
@@ -2662,11 +2679,11 @@
for (x = 0, dest = 0; x < vmu->maxmsg; x++) {
make_file(sfn, sizeof(sfn), dir, x);
- if (EXISTS(dir, x, sfn, NULL)) {
+ if (storage->message_exists(dir, x, sfn, NULL)) {
if(x != dest) {
make_file(dfn, sizeof(dfn), dir, dest);
- RENAME(dir, x, vmu->mailbox, vmu->context, dir, dest, sfn, dfn);
+ storage->rename_file(dir, x, vmu->mailbox, vmu->context, dir, dest, sfn, dfn);
}
dest++;
@@ -2700,7 +2717,7 @@
for (x = 0; x < vmu->maxmsg; x++) {
make_file(dfn, sizeof(dfn), ddir, x);
- if (!EXISTS(ddir, x, dfn, NULL))
+ if (!storage->message_exists(ddir, x, dfn, NULL))
break;
}
if (x >= vmu->maxmsg) {
@@ -2708,7 +2725,7 @@
return -1;
}
if (strcmp(sfn, dfn)) {
- COPY(dir, msg, ddir, x, username, context, sfn, dfn);
+ storage->copy_file(dir, msg, ddir, x, username, context, sfn, dfn);
}
ast_unlock_path(ddir);
@@ -3329,7 +3346,7 @@
}
if (ast_test_flag(vmu, VM_DELETE)) {
- DELETE(todir, msgnum, fn);
+ storage->delete_file(todir, msgnum, fn);
}
/* Leave voicemail for someone */
@@ -3479,7 +3496,7 @@
} else {
/* Forward VoiceMail */
- RETRIEVE(dir, curmsg);
+ storage->retrieve_file(dir, curmsg);
cmd = vm_forwardoptions(chan, sender, dir, curmsg, vmfmts, context, record_gain);
if (!cmd) {
AST_LIST_TRAVERSE_SAFE_BEGIN(&extensions, vmtmp, list) {
@@ -3492,7 +3509,7 @@
ast_log(LOG_DEBUG, "%s", sys);
ast_safe_system(sys);
- res = count_messages(receiver, todir);
+ res = storage->count_messages(receiver, todir);
if ( (res == ERROR_LOCK_PATH) || (res < 0) ) {
if (res == ERROR_LOCK_PATH)
@@ -3517,7 +3534,7 @@
ast_safe_system(sys);
snprintf(fn, sizeof(fn), "%s/msg%04d", todir,todircount);
- STORE(todir, vmtmp->mailbox, vmtmp->context, todircount);
+ storage->store_file(todir, vmtmp->mailbox, vmtmp->context, todircount);
/* load the information on the source message so we can send an e-mail like a new message */
snprintf(miffile, sizeof(miffile), "%s/msg%04d.txt", dir, curmsg);
@@ -3550,7 +3567,7 @@
ast_config_destroy(mif); /* or here */
}
/* Leave voicemail for someone */
- manager_event(EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s\r\nWaiting: %d\r\n", ext_context, has_voicemail(ext_context, NULL));
+ manager_event(EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s\r\nWaiting: %d\r\n", ext_context, storage->has_voicemail(ext_context, NULL));
run_externnotify(vmtmp->context, vmtmp->mailbox);
saved_messages++;
@@ -3779,7 +3796,7 @@
/* Retrieve info from VM attribute file */
make_file(vms->fn2, sizeof(vms->fn2), vms->curdir, vms->curmsg);
snprintf(filename,sizeof(filename), "%s.txt", vms->fn2);
- RETRIEVE(vms->curdir, vms->curmsg);
+ storage->retrieve_file(vms->curdir, vms->curmsg);
msg_cfg = ast_config_load(filename);
if (!msg_cfg) {
ast_log(LOG_WARNING, "No message attribute file?!! (%s)\n", filename);
@@ -3788,7 +3805,7 @@
if (!(origtime = ast_variable_retrieve(msg_cfg, "message", "origtime"))) {
ast_log(LOG_WARNING, "No origtime?!\n");
- DISPOSE(vms->curdir, vms->curmsg);
+ storage->dispose_file(vms->curdir, vms->curmsg);
ast_config_destroy(msg_cfg);
return 0;
}
@@ -3819,7 +3836,7 @@
vms->heard[vms->curmsg] = 1;
res = wait_file(chan, vms, vms->fn);
}
- DISPOSE(vms->curdir, vms->curmsg);
+ storage->dispose_file(vms->curdir, vms->curmsg);
return res;
}
@@ -3836,7 +3853,7 @@
snprintf(vms->vmbox, sizeof(vms->vmbox), "vm-%s", vms->curbox);
make_dir(vms->curdir, sizeof(vms->curdir), vmu->context, vms->username, vms->curbox);
- count_msg = count_messages(vmu, vms->curdir);
+ count_msg = storage->count_messages(vmu, vms->curdir);
if (count_msg < 0)
return count_msg;
else
@@ -3849,7 +3866,7 @@
detected.
*/
- last_msg = last_message_index(vmu, vms->curdir);
+ last_msg = storage->last_message_index(vmu, vms->curdir);
if (last_msg < 0)
return last_msg;
else if(vms->lastmsg != last_msg)
@@ -3880,12 +3897,12 @@
if (!vms->deleted[x] && (strcasecmp(vms->curbox, "INBOX") || !vms->heard[x])) {
/* Save this message. It's not in INBOX or hasn't been heard */
make_file(vms->fn, sizeof(vms->fn), vms->curdir, x);
- if (!EXISTS(vms->curdir, x, vms->fn, NULL))
+ if (!storage->message_exists(vms->curdir, x, vms->fn, NULL))
break;
vms->curmsg++;
make_file(vms->fn2, sizeof(vms->fn2), vms->curdir, vms->curmsg);
if (strcmp(vms->fn, vms->fn2)) {
- RENAME(vms->curdir, x, vmu->mailbox,vmu->context, vms->curdir, vms->curmsg, vms->fn, vms->fn2);
+ storage->rename_file(vms->curdir, x, vmu->mailbox,vmu->context, vms->curdir, vms->curmsg, vms->fn, vms->fn2);
}
} else if (!strcasecmp(vms->curbox, "INBOX") && vms->heard[x] && !vms->deleted[x]) {
/* Move to old folder before deleting */
@@ -3903,8 +3920,8 @@
nummsg = x - 1;
for (x = vms->curmsg + 1; x <= nummsg; x++) {
make_file(vms->fn, sizeof(vms->fn), vms->curdir, x);
- if (EXISTS(vms->curdir, x, vms->fn, NULL))
- DELETE(vms->curdir, x, vms->fn);
+ if (storage->message_exists(vms->curdir, x, vms->fn, NULL))
+ storage->delete_file(vms->curdir, x, vms->fn);
}
ast_unlock_path(vms->curdir);
@@ -4845,7 +4862,7 @@
while (cmd >= 0 && cmd != 't') {
if (cmd)
retries = 0;
- RETRIEVE(prefile, -1);
+ storage->retrieve_file(prefile, -1);
if (ast_fileexists(prefile, NULL, NULL) <= 0) {
play_record_review(chan, "vm-rec-temp", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain);
cmd = 't';
@@ -4855,7 +4872,7 @@
cmd = play_record_review(chan, "vm-rec-temp", prefile, maxgreet, fmtc, 0, vmu, &duration, NULL, record_gain);
break;
case '2':
- DELETE(prefile, -1, prefile);
+ storage->delete_file(prefile, -1, prefile);
ast_play_and_wait(chan, "vm-tempremoved");
cmd = 't';
break;
@@ -4874,7 +4891,7 @@
cmd = 't';
}
}
- DISPOSE(prefile, -1);
+ storage->dispose_file(prefile, -1);
}
if (cmd == 't')
cmd = 0;
@@ -5578,7 +5595,7 @@
close_mailbox(&vms, vmu);
if (valid) {
snprintf(ext_context, sizeof(ext_context), "%s@%s", vms.username, vmu->context);
- manager_event(EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s\r\nWaiting: %d\r\n", ext_context, has_voicemail(ext_context, NULL));
+ manager_event(EVENT_FLAG_CALL, "MessageWaiting", "Mailbox: %s\r\nWaiting: %d\r\n", ext_context, storage->has_voicemail(ext_context, NULL));
run_externnotify(vmu->context, vmu->mailbox);
}
if (vmu)
@@ -5919,6 +5936,50 @@
{ { "show", "voicemail", "zones", NULL },
handle_show_voicemail_zones, "List zone message formats",
show_voicemail_zones_help, NULL };
+
+static int noop2(char *a, int b)
+{
+ return 0;
+}
+
+static int noop4(char *a, char *b, char *c, int d)
+{
+ return 0;
+}
+
+static struct vm_storage spool_storage =
+{
+ noop2,
+ noop2,
+ noop4,
+ spool_rename_file,
+ spool_copy_file,
+ spool_delete_file,
+ spool_message_exists,
+ spool_count_messages,
+ spool_last_message_index,
+ spool_messagecount,
+ spool_has_voicemail,
+};
+
+#ifdef USE_ODBC_STORAGE
+
+static struct vm_storage odbc_storage =
+{
+ odbc_retrieve_file,
+ odbc_dispose_file,
+ odbc_store_file,
+ odbc_rename_file,
+ odbc_copy_file,
+ odbc_delete_file,
+ odbc_message_exists,
+ odbc_count_messages,
+ odbc_last_message_index,
+ odbc_messagecount,
+ odbc_has_voicemail,
+};
+
+#endif
static int load_config(void)
{
@@ -5956,6 +6017,12 @@
char *emaildateformatstr;
int x;
int tmpadsi[4];
+
+#ifdef USE_ODBC_STORAGE
+ storage = &odbc_storage;
+#else
+ storage = &spool_storage;
+#endif
cfg = ast_config_load(VOICEMAIL_CONFIG);
AST_LIST_LOCK(&users);
@@ -6415,7 +6482,7 @@
/* compute the location of the voicemail spool directory */
snprintf(VM_SPOOL_DIR, sizeof(VM_SPOOL_DIR), "%s/voicemail/", ast_config_AST_SPOOL_DIR);
- ast_install_vm_functions(has_voicemail, messagecount);
+ ast_install_vm_functions(storage->has_voicemail, storage->message_count);
#if defined(USE_ODBC_STORAGE) && !defined(EXTENDED_ODBC_STORAGE)
ast_log(LOG_WARNING, "The current ODBC storage table format will be changed soon."
@@ -6504,9 +6571,9 @@
make_file(vms->fn2, sizeof(vms->fn2), vms->curdir, vms->curmsg);
snprintf(filename,sizeof(filename), "%s.txt", vms->fn2);
- RETRIEVE(vms->curdir, vms->curmsg);
+ storage->retrieve_file(vms->curdir, vms->curmsg);
msg_cfg = ast_config_load(filename);
- DISPOSE(vms->curdir, vms->curmsg);
+ storage->dispose_file(vms->curdir, vms->curmsg);
if (!msg_cfg) {
ast_log(LOG_WARNING, "No message attribute file?!! (%s)\n", filename);
return 0;
@@ -6686,8 +6753,8 @@
ast_verbose(VERBOSE_PREFIX_3 "Saving message as is\n");
ast_streamfile(chan, "vm-msgsaved", chan->language);
ast_waitstream(chan, "");
- STORE(recordfile, vmu->mailbox, vmu->context, -1);
- DISPOSE(recordfile, -1);
+ storage->store_file(recordfile, vmu->mailbox, vmu->context, -1);
+ storage->dispose_file(recordfile, -1);
cmd = 't';
return res;
}
@@ -6782,7 +6849,7 @@
cmd = '0';
} else {
ast_play_and_wait(chan, "vm-deleted");
- DELETE(recordfile, -1, recordfile);
+ storage->delete_file(recordfile, -1, recordfile);
cmd = '0';
}
}
More information about the asterisk-commits
mailing list