|
|
|
@ -692,6 +692,19 @@ static int make_file(char *dest, int len, char *dir, int num)
|
|
|
|
|
return snprintf(dest, len, "%s/msg%04d", dir, num);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* only return failure if ast_lock_path returns 'timeout',
|
|
|
|
|
not if the path does not exist or any other reason
|
|
|
|
|
*/
|
|
|
|
|
static int vm_lock_path(const char *path)
|
|
|
|
|
{
|
|
|
|
|
switch (ast_lock_path(path)) {
|
|
|
|
|
case AST_LOCK_TIMEOUT:
|
|
|
|
|
return -1;
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_ODBC_STORAGE
|
|
|
|
|
static int retrieve_file(char *dir, int msgnum)
|
|
|
|
@ -982,9 +995,9 @@ yuck:
|
|
|
|
|
*/
|
|
|
|
|
static int count_messages(struct ast_vm_user *vmu, char *dir)
|
|
|
|
|
{
|
|
|
|
|
int res = 0;
|
|
|
|
|
int res;
|
|
|
|
|
|
|
|
|
|
res = last_message_index(vmu, dir) + 1;
|
|
|
|
|
res = last_message_index(vmu, dir);
|
|
|
|
|
return res >= 0 ? res + 1 : res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -1259,23 +1272,19 @@ static int count_messages(struct ast_vm_user *vmu, char *dir)
|
|
|
|
|
DIR *vmdir = NULL;
|
|
|
|
|
struct dirent *vment = NULL;
|
|
|
|
|
|
|
|
|
|
if (!ast_lock_path(dir)) {
|
|
|
|
|
if (vm_lock_path(dir))
|
|
|
|
|
return ERROR_LOCK_PATH;
|
|
|
|
|
|
|
|
|
|
if ((vmdir = opendir(dir))) {
|
|
|
|
|
while ((vment = readdir(vmdir)))
|
|
|
|
|
{
|
|
|
|
|
while ((vment = readdir(vmdir))) {
|
|
|
|
|
if (strlen(vment->d_name) > 7 && !strncmp(vment->d_name + 7, ".txt", 4))
|
|
|
|
|
{
|
|
|
|
|
vmcount++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
closedir(vmdir);
|
|
|
|
|
}
|
|
|
|
|
ast_unlock_path(dir);
|
|
|
|
|
|
|
|
|
|
return vmcount;
|
|
|
|
|
} else {
|
|
|
|
|
return ERROR_LOCK_PATH;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void rename_file(char *sfn, char *dfn)
|
|
|
|
@ -1354,17 +1363,18 @@ static int last_message_index(struct ast_vm_user *vmu, char *dir)
|
|
|
|
|
{
|
|
|
|
|
int x;
|
|
|
|
|
char fn[256];
|
|
|
|
|
if (!ast_lock_path(dir)) {
|
|
|
|
|
|
|
|
|
|
if (vm_lock_path(dir))
|
|
|
|
|
return ERROR_LOCK_PATH;
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < vmu->maxmsg; x++) {
|
|
|
|
|
make_file(fn, sizeof(fn), dir, x);
|
|
|
|
|
if (ast_fileexists(fn, NULL, NULL) < 1)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
ast_unlock_path(dir);
|
|
|
|
|
|
|
|
|
|
return x - 1;
|
|
|
|
|
} else {
|
|
|
|
|
return ERROR_LOCK_PATH;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int vm_delete(char *file)
|
|
|
|
@ -1997,7 +2007,10 @@ static int copy_message(struct ast_channel *chan, struct ast_vm_user *vmu, int i
|
|
|
|
|
|
|
|
|
|
make_dir(fromdir, sizeof(fromdir), vmu->context, vmu->mailbox, frombox);
|
|
|
|
|
make_file(frompath, sizeof(frompath), fromdir, msgnum);
|
|
|
|
|
if (!ast_lock_path(topath)) {
|
|
|
|
|
|
|
|
|
|
if (vm_lock_path(topath))
|
|
|
|
|
return ERROR_LOCK_PATH;
|
|
|
|
|
|
|
|
|
|
recipmsgnum = 0;
|
|
|
|
|
do {
|
|
|
|
|
make_file(topath, sizeof(topath), todir, recipmsgnum);
|
|
|
|
@ -2012,9 +2025,6 @@ static int copy_message(struct ast_channel *chan, struct ast_vm_user *vmu, int i
|
|
|
|
|
}
|
|
|
|
|
ast_unlock_path(topath);
|
|
|
|
|
notify_new_message(chan, recip, recipmsgnum, duration, fmt, chan->cid.cid_num, chan->cid.cid_name);
|
|
|
|
|
} else {
|
|
|
|
|
return ERROR_LOCK_PATH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -2208,7 +2218,12 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, int silent, int
|
|
|
|
|
ast_copy_string(fmt, vmfmts, sizeof(fmt));
|
|
|
|
|
if (!ast_strlen_zero(fmt)) {
|
|
|
|
|
msgnum = 0;
|
|
|
|
|
if (!ast_lock_path(dir)) {
|
|
|
|
|
|
|
|
|
|
if (vm_lock_path(dir)) {
|
|
|
|
|
free_user(vmu);
|
|
|
|
|
return ERROR_LOCK_PATH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (res >= 0) {
|
|
|
|
|
/* Unless we're *really* silent, try to send the beep */
|
|
|
|
|
res = ast_streamfile(chan, "beep", chan->language);
|
|
|
|
@ -2222,7 +2237,6 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, int silent, int
|
|
|
|
|
msgnum++;
|
|
|
|
|
} while (msgnum < vmu->maxmsg);
|
|
|
|
|
if (msgnum < vmu->maxmsg) {
|
|
|
|
|
|
|
|
|
|
/* assign a variable with the name of the voicemail file */
|
|
|
|
|
pbx_builtin_setvar_helper(chan, "VM_MESSAGEFILE", fn);
|
|
|
|
|
|
|
|
|
@ -2305,10 +2319,6 @@ static int leave_voicemail(struct ast_channel *chan, char *ext, int silent, int
|
|
|
|
|
res = ast_waitstream(chan, "");
|
|
|
|
|
ast_log(LOG_WARNING, "No more messages possible\n");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
free_user(vmu);
|
|
|
|
|
return ERROR_LOCK_PATH;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
ast_log(LOG_WARNING, "No format for saving voicemail?\n");
|
|
|
|
|
leave_vm_out:
|
|
|
|
@ -2316,8 +2326,7 @@ leave_vm_out:
|
|
|
|
|
} else {
|
|
|
|
|
ast_log(LOG_WARNING, "No entry in voicemail config file for '%s'\n", ext);
|
|
|
|
|
/*Send the call to n+101 priority, where n is the current priority*/
|
|
|
|
|
if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num))
|
|
|
|
|
chan->priority+=100;
|
|
|
|
|
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
@ -2332,7 +2341,9 @@ static int resequence_mailbox(struct ast_vm_user *vmu, char *dir)
|
|
|
|
|
char sfn[256];
|
|
|
|
|
char dfn[256];
|
|
|
|
|
|
|
|
|
|
if (!ast_lock_path(dir)) {
|
|
|
|
|
if (vm_lock_path(dir))
|
|
|
|
|
return ERROR_LOCK_PATH;
|
|
|
|
|
|
|
|
|
|
for (x = 0, dest = 0; x < vmu->maxmsg; x++) {
|
|
|
|
|
make_file(sfn, sizeof(sfn), dir, x);
|
|
|
|
|
if (EXISTS(dir, x, sfn, NULL)) {
|
|
|
|
@ -2346,9 +2357,6 @@ static int resequence_mailbox(struct ast_vm_user *vmu, char *dir)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ast_unlock_path(dir);
|
|
|
|
|
} else {
|
|
|
|
|
return ERROR_LOCK_PATH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -2371,7 +2379,10 @@ static int save_to_folder(struct ast_vm_user *vmu, char *dir, int msg, char *con
|
|
|
|
|
make_file(sfn, sizeof(sfn), dir, msg);
|
|
|
|
|
make_dir(ddir, sizeof(ddir), context, username, dbox);
|
|
|
|
|
mkdir(ddir, 0700);
|
|
|
|
|
if (!ast_lock_path(ddir)) {
|
|
|
|
|
|
|
|
|
|
if (vm_lock_path(ddir))
|
|
|
|
|
return ERROR_LOCK_PATH;
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < vmu->maxmsg; x++) {
|
|
|
|
|
make_file(dfn, sizeof(dfn), ddir, x);
|
|
|
|
|
if (!EXISTS(ddir, x, dfn, NULL))
|
|
|
|
@ -2385,9 +2396,6 @@ static int save_to_folder(struct ast_vm_user *vmu, char *dir, int msg, char *con
|
|
|
|
|
COPY(dir, msg, ddir, x, sfn, dfn);
|
|
|
|
|
}
|
|
|
|
|
ast_unlock_path(ddir);
|
|
|
|
|
} else {
|
|
|
|
|
return ERROR_LOCK_PATH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -3526,9 +3534,14 @@ static int close_mailbox(struct vm_state *vms, struct ast_vm_user *vmu)
|
|
|
|
|
{
|
|
|
|
|
int x;
|
|
|
|
|
int res = 0;
|
|
|
|
|
if (vms->lastmsg > -1) {
|
|
|
|
|
|
|
|
|
|
if (vms->lastmsg <= -1)
|
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
|
|
/* Get the deleted messages fixed */
|
|
|
|
|
if (!ast_lock_path(vms->curdir)) {
|
|
|
|
|
if (vm_lock_path(vms->curdir))
|
|
|
|
|
return ERROR_LOCK_PATH;
|
|
|
|
|
|
|
|
|
|
vms->curmsg = -1;
|
|
|
|
|
for (x=0;x < vmu->maxmsg;x++) {
|
|
|
|
|
if (!vms->deleted[x] && (strcasecmp(vms->curbox, "INBOX") || !vms->heard[x])) {
|
|
|
|
@ -3559,12 +3572,11 @@ static int close_mailbox(struct vm_state *vms, struct ast_vm_user *vmu)
|
|
|
|
|
DELETE(vms->curdir, x, vms->fn);
|
|
|
|
|
}
|
|
|
|
|
ast_unlock_path(vms->curdir);
|
|
|
|
|
} else {
|
|
|
|
|
return ERROR_LOCK_PATH;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
memset(vms->deleted, 0, sizeof(vms->deleted));
|
|
|
|
|
memset(vms->heard, 0, sizeof(vms->heard));
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|