[asterisk-commits] jrothenberger: branch jrothenberger/asterisk-urgent r103717 - /team/jrothenbe...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Feb 15 10:57:26 CST 2008
Author: jrothenberger
Date: Fri Feb 15 10:57:26 2008
New Revision: 103717
URL: http://svn.digium.com/view/asterisk?view=rev&rev=103717
Log:
Merged changes from other branches into code.
Modified:
team/jrothenberger/asterisk-urgent/apps/app_voicemail.c
Modified: team/jrothenberger/asterisk-urgent/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/jrothenberger/asterisk-urgent/apps/app_voicemail.c?view=diff&rev=103717&r1=103716&r2=103717
==============================================================================
--- team/jrothenberger/asterisk-urgent/apps/app_voicemail.c (original)
+++ team/jrothenberger/asterisk-urgent/apps/app_voicemail.c Fri Feb 15 10:57:26 2008
@@ -448,7 +448,7 @@
#define RETRIEVE(a,b,c,d) (imap_retrieve_file(a,b,c,d ))
#define DISPOSE(a,b) (imap_remove_file(a,b))
#define STORE(a,b,c,d,e,f,g,h,i,j) (imap_store_file(a,b,c,d,e,f,g,h,i,j))
-#define EXISTS(a,b,c,d) (ast_fileexists(c,NULL,d) > 0)
+#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 IMAP_DELETE(a,b,c,d) (vm_imap_delete(b,d))
@@ -457,9 +457,9 @@
#define RETRIEVE(a,b,c,d)
#define DISPOSE(a,b)
#define STORE(a,b,c,d,e,f,g,h,i,j)
-#define EXISTS(a,b,c,d) (ast_fileexists(c,NULL,d) > 0)
+#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 COPY(a,b,c,d,e,f,g,h) (copy_plain_file(g,h));
#define DELETE(a,b,c) (vm_delete(c))
#endif
#endif
@@ -722,31 +722,31 @@
#endif
} else if (!strcasecmp(var, "delete") || !strcasecmp(var, "deletevoicemail")) {
ast_set2_flag(vmu, ast_true(value), VM_DELETE);
- } else if (!strcasecmp(var, "saycid")){
+ } else if (!strcasecmp(var, "saycid")) {
ast_set2_flag(vmu, ast_true(value), VM_SAYCID);
- } else if (!strcasecmp(var,"sendvoicemail")){
+ } else if (!strcasecmp(var, "sendvoicemail")) {
ast_set2_flag(vmu, ast_true(value), VM_SVMAIL);
- } else if (!strcasecmp(var, "review")){
+ } else if (!strcasecmp(var, "review")) {
ast_set2_flag(vmu, ast_true(value), VM_REVIEW);
- } else if (!strcasecmp(var, "tempgreetwarn")){
+ } else if (!strcasecmp(var, "tempgreetwarn")) {
ast_set2_flag(vmu, ast_true(value), VM_TEMPGREETWARN);
- } else if (!strcasecmp(var, "operator")){
+ } else if (!strcasecmp(var, "operator")) {
ast_set2_flag(vmu, ast_true(value), VM_OPERATOR);
- } else if (!strcasecmp(var, "envelope")){
+ } else if (!strcasecmp(var, "envelope")) {
ast_set2_flag(vmu, ast_true(value), VM_ENVELOPE);
- } else if (!strcasecmp(var, "moveheard")){
+ } else if (!strcasecmp(var, "moveheard")) {
ast_set2_flag(vmu, ast_true(value), VM_MOVEHEARD);
- } else if (!strcasecmp(var, "sayduration")){
+ } else if (!strcasecmp(var, "sayduration")) {
ast_set2_flag(vmu, ast_true(value), VM_SAYDURATION);
- } else if (!strcasecmp(var, "saydurationm")){
+ } else if (!strcasecmp(var, "saydurationm")) {
if (sscanf(value, "%d", &x) == 1) {
vmu->saydurationm = x;
} else {
ast_log(LOG_WARNING, "Invalid min duration for say duration\n");
}
- } else if (!strcasecmp(var, "forcename")){
+ } else if (!strcasecmp(var, "forcename")) {
ast_set2_flag(vmu, ast_true(value), VM_FORCENAME);
- } else if (!strcasecmp(var, "forcegreetings")){
+ } else if (!strcasecmp(var, "forcegreetings")) {
ast_set2_flag(vmu, ast_true(value), VM_FORCEGREET);
} else if (!strcasecmp(var, "callback")) {
ast_copy_string(vmu->callback, value, sizeof(vmu->callback));
@@ -903,7 +903,7 @@
static struct ast_vm_user *find_user(struct ast_vm_user *ivm, const char *context, const char *mailbox)
{
/* This function could be made to generate one from a database, too */
- struct ast_vm_user *vmu=NULL, *cur;
+ struct ast_vm_user *vmu = NULL, *cur;
AST_LIST_LOCK(&users);
if (!context && !ast_test_flag((&globalflags), VM_SEARCH))
@@ -949,11 +949,11 @@
static void vm_change_password(struct ast_vm_user *vmu, const char *newpassword)
{
- struct ast_config *cfg=NULL;
- struct ast_variable *var=NULL;
- struct ast_category *cat=NULL;
- char *category=NULL, *value=NULL, *new=NULL;
- const char *tmp=NULL;
+ struct ast_config *cfg = NULL;
+ struct ast_variable *var = NULL;
+ struct ast_category *cat = NULL;
+ char *category = NULL, *value = NULL, *new = NULL;
+ const char *tmp = NULL;
struct ast_flags config_flags = { CONFIG_FLAG_WITHCOMMENTS };
if (!change_password_realtime(vmu, newpassword))
return;
@@ -966,13 +966,13 @@
ast_log(LOG_WARNING, "We could not find the mailbox.\n");
break;
}
- value = strstr(tmp,",");
+ value = strstr(tmp, ",");
if (!value) {
ast_log(LOG_WARNING, "variable has bad format.\n");
break;
}
- new = alloca((strlen(value)+strlen(newpassword)+1));
- sprintf(new,"%s%s", newpassword, value);
+ new = alloca(strlen(value) + strlen(newpassword) + 1);
+ sprintf(new, "%s%s", newpassword, value);
if (!(cat = ast_category_get(cfg, category))) {
ast_log(LOG_WARNING, "Failed to get category structure.\n");
break;
@@ -998,7 +998,7 @@
ast_debug(3, "looks like we need to make vmsecret!\n");
var = ast_variable_new("vmsecret", newpassword, "");
}
- new = alloca(strlen(newpassword)+1);
+ new = alloca(strlen(newpassword) + 1);
sprintf(new, "%s", newpassword);
if (!(cat = ast_category_get(cfg, category))) {
ast_debug(4, "failed to get category!\n");
@@ -1020,7 +1020,7 @@
static void vm_change_password_shell(struct ast_vm_user *vmu, char *newpassword)
{
char buf[255];
- snprintf(buf,255,"%s %s %s %s",ext_pass_cmd,vmu->context,vmu->mailbox,newpassword);
+ snprintf(buf, sizeof(buf), "%s %s %s %s", ext_pass_cmd, vmu->context, vmu->mailbox, newpassword);
if (!ast_safe_system(buf)) {
ast_copy_string(vmu->password, newpassword, sizeof(vmu->password));
/* Reset the password in memory, too */
@@ -1054,13 +1054,13 @@
messageNum = vms->msgArray[msgnum];
if (messageNum == 0) {
- ast_log(LOG_WARNING, "msgnum %d, mailbox message %lu is zero.\n",msgnum,messageNum);
+ ast_log(LOG_WARNING, "msgnum %d, mailbox message %lu is zero.\n", msgnum, messageNum);
return;
}
- ast_debug(3, "deleting msgnum %d, which is mailbox message %lu\n",msgnum,messageNum);
+ ast_debug(3, "deleting msgnum %d, which is mailbox message %lu\n", msgnum, messageNum);
/* delete message */
- snprintf (arg, sizeof(arg), "%lu",messageNum);
- mail_setflag (vms->mailstream,arg,"\\DELETED");
+ snprintf(arg, sizeof(arg), "%lu", messageNum);
+ mail_setflag(vms->mailstream, arg, "\\DELETED");
}
#endif
@@ -1139,13 +1139,13 @@
{
int x = 0;
int res;
- int fd=-1;
+ int fd = -1;
size_t fdlen = 0;
void *fdm = MAP_FAILED;
- SQLSMALLINT colcount=0;
+ SQLSMALLINT colcount = 0;
SQLHSTMT stmt;
char sql[PATH_MAX];
- char fmt[80]="";
+ char fmt[80] = "";
char *c;
char coltitle[256];
SQLSMALLINT collen;
@@ -1154,7 +1154,7 @@
SQLSMALLINT nullable;
SQLULEN colsize;
SQLLEN colsize2;
- FILE *f=NULL;
+ FILE *f = NULL;
char rowdata[80];
char fn[PATH_MAX];
char full_fn[PATH_MAX];
@@ -1171,7 +1171,7 @@
*c = '\0';
if (!strcasecmp(fmt, "wav49"))
strcpy(fmt, "WAV");
- snprintf(msgnums, sizeof(msgnums),"%d", msgnum);
+ snprintf(msgnums, sizeof(msgnums), "%d", msgnum);
if (msgnum > -1)
make_file(fn, sizeof(fn), dir, msgnum);
else
@@ -1184,7 +1184,7 @@
}
snprintf(full_fn, sizeof(full_fn), "%s.%s", fn, fmt);
- snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE dir=? AND msgnum=?",odbc_table);
+ snprintf(sql, sizeof(sql), "SELECT * FROM %s WHERE dir=? AND msgnum=?", odbc_table);
stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
if (!stmt) {
ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
@@ -1219,7 +1219,7 @@
}
if (f)
fprintf(f, "[message]\n");
- for (x=0;x<colcount;x++) {
+ for (x = 0; x < colcount; x++) {
rowdata[0] = '\0';
collen = sizeof(coltitle);
res = SQLDescribeCol(stmt, x + 1, (unsigned char *)coltitle, sizeof(coltitle), &collen,
@@ -1235,7 +1235,7 @@
res = SQLGetData(stmt, x + 1, SQL_BINARY, rowdata, 0, &colsize2);
fdlen = colsize2;
if (fd > -1) {
- char tmp[1]="";
+ char tmp[1] = "";
lseek(fd, fdlen - 1, SEEK_SET);
if (write(fd, tmp, 1) != 1) {
close(fd);
@@ -1320,7 +1320,7 @@
struct odbc_obj *obj;
obj = ast_odbc_request_obj(odbc_database, 0);
if (obj) {
- snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir=?",odbc_table);
+ snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir=?", odbc_table);
stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
if (!stmt) {
ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
@@ -1366,7 +1366,7 @@
obj = ast_odbc_request_obj(odbc_database, 0);
if (obj) {
snprintf(msgnums, sizeof(msgnums), "%d", msgnum);
- snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir=? AND msgnum=?",odbc_table);
+ snprintf(sql, sizeof(sql), "SELECT COUNT(*) FROM %s WHERE dir=? AND msgnum=?", odbc_table);
stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
if (!stmt) {
ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
@@ -1414,7 +1414,7 @@
obj = ast_odbc_request_obj(odbc_database, 0);
if (obj) {
snprintf(msgnums, sizeof(msgnums), "%d", smsg);
- snprintf(sql, sizeof(sql), "DELETE FROM %s WHERE dir=? AND msgnum=?",odbc_table);
+ snprintf(sql, sizeof(sql), "DELETE FROM %s WHERE dir=? AND msgnum=?", odbc_table);
stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
if (!stmt)
ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
@@ -1441,7 +1441,7 @@
if (obj) {
snprintf(msgnums, sizeof(msgnums), "%d", smsg);
snprintf(msgnumd, sizeof(msgnumd), "%d", dmsg);
- snprintf(sql, sizeof(sql), "INSERT INTO %s (dir, msgnum, context, macrocontext, callerid, origtime, duration, recording, mailboxuser, mailboxcontext) SELECT ?,?,context,macrocontext,callerid,origtime,duration,recording,?,? FROM %s WHERE dir=? AND msgnum=?",odbc_table,odbc_table);
+ snprintf(sql, sizeof(sql), "INSERT INTO %s (dir, msgnum, context, macrocontext, callerid, origtime, duration, recording, mailboxuser, mailboxcontext) SELECT ?,?,context,macrocontext,callerid,origtime,duration,recording,?,? FROM %s WHERE dir=? AND msgnum=?", odbc_table, odbc_table);
stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
if (!stmt)
ast_log(LOG_WARNING, "SQL Execute error!\n[%s] (You probably don't have MySQL 4.1 or later installed)\n\n", sql);
@@ -1466,11 +1466,11 @@
char msgnums[20];
char fn[PATH_MAX];
char full_fn[PATH_MAX];
- char fmt[80]="";
+ char fmt[80] = "";
char *c;
- const char *context="", *macrocontext="", *callerid="", *origtime="", *duration="";
+ const char *context = "", *macrocontext = "", *callerid = "", *origtime = "", *duration = "";
const char *category = "";
- struct ast_config *cfg=NULL;
+ struct ast_config *cfg = NULL;
struct odbc_obj *obj;
struct ast_flags config_flags = { CONFIG_FLAG_NOCACHE };
@@ -1483,7 +1483,7 @@
*c = '\0';
if (!strcasecmp(fmt, "wav49"))
strcpy(fmt, "WAV");
- snprintf(msgnums, sizeof(msgnums),"%d", msgnum);
+ snprintf(msgnums, sizeof(msgnums), "%d", msgnum);
if (msgnum > -1)
make_file(fn, sizeof(fn), dir, msgnum);
else
@@ -1514,7 +1514,7 @@
fdlen = lseek(fd, 0, SEEK_END);
lseek(fd, 0, SEEK_SET);
printf("Length is %zd\n", fdlen);
- fdm = mmap(NULL, fdlen, PROT_READ | PROT_WRITE, MAP_SHARED,fd, 0);
+ fdm = mmap(NULL, fdlen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (fdm == MAP_FAILED) {
ast_log(LOG_WARNING, "Memory map failed!\n");
ast_odbc_release_obj(obj);
@@ -1527,9 +1527,9 @@
goto yuck;
}
if (!ast_strlen_zero(category))
- snprintf(sql, sizeof(sql), "INSERT INTO %s (dir,msgnum,recording,context,macrocontext,callerid,origtime,duration,mailboxuser,mailboxcontext,category) VALUES (?,?,?,?,?,?,?,?,?,?,?)",odbc_table);
+ snprintf(sql, sizeof(sql), "INSERT INTO %s (dir,msgnum,recording,context,macrocontext,callerid,origtime,duration,mailboxuser,mailboxcontext,category) VALUES (?,?,?,?,?,?,?,?,?,?,?)", odbc_table);
else
- snprintf(sql, sizeof(sql), "INSERT INTO %s (dir,msgnum,recording,context,macrocontext,callerid,origtime,duration,mailboxuser,mailboxcontext) VALUES (?,?,?,?,?,?,?,?,?,?)",odbc_table);
+ snprintf(sql, sizeof(sql), "INSERT INTO %s (dir,msgnum,recording,context,macrocontext,callerid,origtime,duration,mailboxuser,mailboxcontext) VALUES (?,?,?,?,?,?,?,?,?,?)", odbc_table);
res = SQLPrepare(stmt, (unsigned char *)sql, SQL_NTS);
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
@@ -1586,7 +1586,7 @@
if (obj) {
snprintf(msgnums, sizeof(msgnums), "%d", smsg);
snprintf(msgnumd, sizeof(msgnumd), "%d", dmsg);
- snprintf(sql, sizeof(sql), "UPDATE %s SET dir=?, msgnum=?, mailboxuser=?, mailboxcontext=? WHERE dir=? AND msgnum=?",odbc_table);
+ snprintf(sql, sizeof(sql), "UPDATE %s SET dir=?, msgnum=?, mailboxuser=?, mailboxcontext=? WHERE dir=? AND msgnum=?", odbc_table);
stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
if (!stmt)
ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
@@ -1635,7 +1635,7 @@
{
char stxt[PATH_MAX];
char dtxt[PATH_MAX];
- ast_filerename(sfn,dfn,NULL);
+ ast_filerename(sfn, dfn, NULL);
snprintf(stxt, sizeof(stxt), "%s.txt", sfn);
snprintf(dtxt, sizeof(dtxt), "%s.txt", dfn);
if (ast_check_realtime("voicemail_data")) {
@@ -1643,6 +1643,42 @@
}
rename(stxt, dtxt);
}
+#endif
+
+#ifndef IMAP_STORAGE
+/*! \brief
+ * A negative return value indicates an error.
+ * \note Should always be called with a lock already set on dir.
+ */
+static int last_message_index(struct ast_vm_user *vmu, char *dir)
+{
+ int x;
+ unsigned char map[MAXMSGLIMIT] = "";
+ DIR *msgdir;
+ struct dirent *msgdirent;
+ int msgdirint;
+
+ /* Reading the entire directory into a file map scales better than
+ * doing a stat repeatedly on a predicted sequence. I suspect this
+ * is partially due to stat(2) internally doing a readdir(2) itself to
+ * find each file. */
+ msgdir = opendir(dir);
+ while ((msgdirent = readdir(msgdir))) {
+ if (sscanf(msgdirent->d_name, "msg%d", &msgdirint) == 1 && msgdirint < MAXMSGLIMIT)
+ map[msgdirint] = 1;
+ }
+ closedir(msgdir);
+
+ for (x = 0; x < vmu->maxmsg; x++) {
+ if (map[x] == 0)
+ break;
+ }
+
+ return x - 1;
+}
+
+#endif /*#ifndef IMAP_STORAGE*/
+#endif /*#else of #ifdef ODBC_STORAGE*/
static int copy(char *infile, char *outfile)
{
@@ -1694,10 +1730,10 @@
#endif
}
-static void copy_file(char *frompath, char *topath)
+static void copy_plain_file(char *frompath, char *topath)
{
char frompath2[PATH_MAX], topath2[PATH_MAX];
- struct ast_variable *tmp,*var = NULL;
+ struct ast_variable *tmp, *var = NULL;
const char *origmailbox = NULL, *context = NULL, *macrocontext = NULL, *exten = NULL, *priority = NULL, *callerchan = NULL, *callerid = NULL, *origdate = NULL, *origtime = NULL, *category = NULL, *duration = NULL;
ast_filecopy(frompath, topath, NULL);
snprintf(frompath2, sizeof(frompath2), "%s.txt", frompath);
@@ -1735,46 +1771,13 @@
copy(frompath2, topath2);
ast_variables_destroy(var);
}
-/*! \brief
- * A negative return value indicates an error.
- * \note Should always be called with a lock already set on dir.
- */
-static int last_message_index(struct ast_vm_user *vmu, char *dir)
-{
- int x;
- unsigned char map[MAXMSGLIMIT] = "";
- DIR *msgdir;
- struct dirent *msgdirent;
- int msgdirint;
-
- /* Reading the entire directory into a file map scales better than
- * doing a stat repeatedly on a predicted sequence. I suspect this
- * is partially due to stat(2) internally doing a readdir(2) itself to
- * find each file. */
- msgdir = opendir(dir);
- while ((msgdirent = readdir(msgdir))) {
- if (sscanf(msgdirent->d_name, "msg%d", &msgdirint) == 1 && msgdirint < MAXMSGLIMIT)
- map[msgdirint] = 1;
- }
- closedir(msgdir);
-
- for (x = 0; x < vmu->maxmsg; x++) {
- if (map[x] == 0)
- break;
- }
-
- return x - 1;
-}
-
-#endif /*#ifndef IMAP_STORAGE*/
-#endif /*#else of #ifdef ODBC_STORAGE*/
-#ifndef ODBC_STORAGE
+
static int vm_delete(char *file)
{
char *txt;
int txtsize = 0;
- txtsize = (strlen(file) + 5)*sizeof(char);
+ txtsize = (strlen(file) + 5) * sizeof(char);
txt = alloca(txtsize);
/* Sprintf here would safe because we alloca'd exactly the right length,
* but trying to eliminate all sprintf's anyhow
@@ -1786,7 +1789,6 @@
unlink(txt);
return ast_filedelete(file, NULL);
}
-#endif
static int inbuf(struct baseio *bio, FILE *fi)
{
@@ -1795,7 +1797,7 @@
if (bio->ateof)
return 0;
- if ((l = fread(bio->iobuf,1,BASEMAXINLINE,fi)) <= 0) {
+ if ((l = fread(bio->iobuf, 1, BASEMAXINLINE, fi)) <= 0) {
if (ferror(fi))
return -1;
@@ -1803,15 +1805,15 @@
return 0;
}
- bio->iolen= l;
- bio->iocp= 0;
+ bio->iolen = l;
+ bio->iocp = 0;
return 1;
}
static int inchar(struct baseio *bio, FILE *fi)
{
- if (bio->iocp>=bio->iolen) {
+ if (bio->iocp >= bio->iolen) {
if (!inbuf(bio, fi))
return EOF;
}
@@ -1822,13 +1824,13 @@
static int ochar(struct baseio *bio, int c, FILE *so)
{
if (bio->linelength >= BASELINELEN) {
- if (fputs(eol,so) == EOF)
+ if (fputs(eol, so) == EOF)
return -1;
bio->linelength= 0;
}
- if (putc(((unsigned char)c),so) == EOF)
+ if (putc(((unsigned char)c), so) == EOF)
return -1;
bio->linelength++;
@@ -1842,7 +1844,7 @@
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0',
'1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'};
- int i,hiteof= 0;
+ int i, hiteof = 0;
FILE *fi;
struct baseio bio;
@@ -1854,42 +1856,42 @@
return -1;
}
- while (!hiteof){
+ while (!hiteof) {
unsigned char igroup[3], ogroup[4];
- int c,n;
-
- igroup[0]= igroup[1]= igroup[2]= 0;
-
- for (n= 0;n<3;n++) {
+ int c, n;
+
+ igroup[0] = igroup[1] = igroup[2] = 0;
+
+ for (n = 0; n < 3; n++) {
if ((c = inchar(&bio, fi)) == EOF) {
- hiteof= 1;
+ hiteof = 1;
break;
}
- igroup[n]= (unsigned char)c;
- }
-
- if (n> 0) {
- ogroup[0]= dtable[igroup[0]>>2];
- ogroup[1]= dtable[((igroup[0]&3)<<4) | (igroup[1]>>4)];
- ogroup[2]= dtable[((igroup[1]&0xF)<<2) | (igroup[2]>>6)];
- ogroup[3]= dtable[igroup[2]&0x3F];
-
- if (n<3) {
- ogroup[3]= '=';
-
- if (n<2)
- ogroup[2]= '=';
- }
-
- for (i= 0;i<4;i++)
+ igroup[n] = (unsigned char)c;
+ }
+
+ if (n > 0) {
+ ogroup[0] = dtable[igroup[0] >> 2];
+ ogroup[1] = dtable[((igroup[0] & 3) << 4) | (igroup[1] >> 4)];
+ ogroup[2] = dtable[((igroup[1] & 0xF) << 2) | (igroup[2] >> 6)];
+ ogroup[3] = dtable[igroup[2] & 0x3F];
+
+ if (n < 3) {
+ ogroup[3] = '=';
+
+ if (n < 2)
+ ogroup[2] = '=';
+ }
+
+ for (i = 0; i < 4; i++)
ochar(&bio, ogroup[i], so);
}
}
fclose(fi);
- if (fputs(eol,so)==EOF)
+ if (fputs(eol, so) == EOF)
return 0;
return 1;
@@ -1989,7 +1991,7 @@
#define ENDL "\n"
#endif
- gethostname(host, sizeof(host)-1);
+ gethostname(host, sizeof(host) - 1);
if (strchr(srcemail, '@'))
ast_copy_string(who, srcemail, sizeof(who));
@@ -2011,7 +2013,7 @@
struct ast_channel *ast;
if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", 0, 0))) {
char *passdata;
- int vmlen = strlen(fromstring)*3 + 200;
+ int vmlen = strlen(fromstring) * 3 + 200;
passdata = alloca(vmlen);
memset(passdata, 0, vmlen);
prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category, flag);
@@ -2096,7 +2098,7 @@
struct ast_channel *ast;
if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", 0, 0))) {
char *passdata;
- int vmlen = strlen(emailbody)*3 + 200;
+ int vmlen = strlen(emailbody) * 3 + 200;
passdata = alloca(vmlen);
memset(passdata, 0, vmlen);
prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category, flag);
@@ -2105,7 +2107,7 @@
ast_channel_free(ast);
} else
ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n");
- } else if (msgnum > -1){
+ } else if (msgnum > -1) {
fprintf(p, "Dear %s:" ENDL ENDL "\tJust wanted to let you know you were just left a %s long %s message (number %d)" ENDL
"in mailbox %s from %s, on %s so you might" ENDL
@@ -2159,7 +2161,7 @@
static int sendmail(char *srcemail, struct ast_vm_user *vmu, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, char *attach, char *format, int duration, int attach_user_voicemail, struct ast_channel *chan, const char *category, char *flag)
{
- FILE *p=NULL;
+ FILE *p = NULL;
char tmp[80] = "/tmp/astmail-XXXXXX";
char tmp2[256];
@@ -2200,7 +2202,7 @@
ast_log(LOG_WARNING, "Unable to launch '%s' (can't create temporary file)\n", mailcmd);
return -1;
}
- gethostname(host, sizeof(host)-1);
+ gethostname(host, sizeof(host) - 1);
if (strchr(srcemail, '@'))
ast_copy_string(who, srcemail, sizeof(who));
else
@@ -2213,7 +2215,7 @@
struct ast_channel *ast;
if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", 0, 0))) {
char *passdata;
- int vmlen = strlen(fromstring)*3 + 200;
+ int vmlen = strlen(fromstring) * 3 + 200;
passdata = alloca(vmlen);
memset(passdata, 0, vmlen);
prep_email_sub_vars(ast, vmu, msgnum + 1, context, mailbox, cidnum, cidname, dur, date, passdata, vmlen, category, flag);
@@ -2281,36 +2283,55 @@
return ast_strftime(s, len, "%a %b %e %r UTC %Y", &tm);
}
-static int invent_message(struct ast_channel *chan, char *context, char *ext, int busy, char *ecodes)
+static int play_greeting(struct ast_channel *chan, struct ast_vm_user *vmu, char *filename, char *ecodes)
+{
+ int res = -2;
+
+#ifdef ODBC_STORAGE
+ int success =
+#endif
+ RETRIEVE(filename, -1, vmu->mailbox, vmu->context);
+ if (ast_fileexists(filename, NULL, NULL) > 0) {
+ res = ast_streamfile(chan, filename, chan->language);
+ if (res > -1)
+ res = ast_waitstream(chan, ecodes);
+#ifdef ODBC_STORAGE
+ if (success == -1) {
+ /* We couldn't retrieve the file from the database, but we found it on the file system. Let's put it in the database. */
+ ast_debug(1, "Greeting not retrieved from database, but found in file storage. Inserting into database\n");
+ store_file(filename, vmu->mailbox, vmu->context, -1);
+ }
+#endif
+ }
+ DISPOSE(filename, -1);
+
+ return res;
+}
+
+static int invent_message(struct ast_channel *chan, struct ast_vm_user *vmu, char *ext, int busy, char *ecodes)
{
int res;
char fn[PATH_MAX];
char dest[PATH_MAX];
- snprintf(fn, sizeof(fn), "%s%s/%s/greet", VM_SPOOL_DIR, context, ext);
-
- if ((res = create_dirpath(dest, sizeof(dest), context, ext, ""))) {
+ snprintf(fn, sizeof(fn), "%s%s/%s/greet", VM_SPOOL_DIR, vmu->context, ext);
+
+ if ((res = create_dirpath(dest, sizeof(dest), vmu->context, ext, ""))) {
ast_log(LOG_WARNING, "Failed to make directory(%s)\n", fn);
return -1;
}
- RETRIEVE(fn, -1, ext, context);
- if (ast_fileexists(fn, NULL, NULL) > 0) {
- res = ast_stream_and_wait(chan, fn, ecodes);
- if (res) {
- DISPOSE(fn, -1);
- return res;
- }
- } else {
- /* Dispose just in case */
- DISPOSE(fn, -1);
+ res = play_greeting(chan, vmu, fn, ecodes);
+ if (res == -2) {
+ /* File did not exist */
res = ast_stream_and_wait(chan, "vm-theperson", ecodes);
if (res)
return res;
res = ast_say_digit_str(chan, ext, ecodes, chan->language);
- if (res)
- return res;
- }
+ }
+ if (res)
+ return res;
+
res = ast_stream_and_wait(chan, busy ? "vm-isonphone" : "vm-isunavail", ecodes);
return res;
}
@@ -2347,7 +2368,7 @@
"Cust5",
"Deleted",
};
- return (id >= 0 && id < (sizeof(msgs)/sizeof(msgs[0]))) ? msgs[id] : "Unknown";
+ return (id >= 0 && id < (sizeof(msgs) / sizeof(msgs[0]))) ? msgs[id] : "tmp";
}
#ifdef IMAP_STORAGE
static int folder_int(const char *folder)
@@ -2548,7 +2569,7 @@
char fn[PATH_MAX];
char mailbox[256];
char *stringp;
- FILE *p=NULL;
+ FILE *p = NULL;
char tmp[80] = "/tmp/astmail-XXXXXX";
long len;
void *buf;
@@ -2558,7 +2579,7 @@
char *imapflags = NIL;
/* Set urgent flag for IMAP message */
- if (ast_strlen_zero(flag) && !strcmp(flag,"URGENT")) {
+ if (!ast_strlen_zero(flag) && !strcmp(flag,"URGENT")) {
ast_debug(3, "Setting message flag \\\\FLAGGED.\n");
imapflags="\\FLAGGED";
}
@@ -2607,8 +2628,8 @@
/* read mail file to memory */
len = ftell(p);
rewind(p);
- if (!(buf = ast_malloc(len+1))) {
- ast_log(LOG_ERROR, "Can't allocate %ld bytes to read message\n", len+1);
+ if (!(buf = ast_malloc(len + 1))) {
+ ast_log(LOG_ERROR, "Can't allocate %ld bytes to read message\n", len + 1);
fclose(p);
if (tempcopy)
*(vmu->email) = '\0';
@@ -2655,30 +2676,30 @@
return 0;
/* We have to get the user before we can open the stream! */
- /* ast_log (LOG_DEBUG,"Before find_user, context is %s and mailbox is %s\n",context,mailbox); */
+ /* ast_log(LOG_DEBUG, "Before find_user, context is %s and mailbox is %s\n", context, mailbox); */
vmu = find_user(&vmus, context, mailbox);
if (!vmu) {
- ast_log (LOG_ERROR,"Couldn't find mailbox %s in context %s\n",mailbox,context);
+ ast_log(LOG_ERROR, "Couldn't find mailbox %s in context %s\n", mailbox, context);
return -1;
} else {
/* No IMAP account available */
if (vmu->imapuser[0] == '\0') {
- ast_log (LOG_WARNING,"IMAP user not set for mailbox %s\n",vmu->mailbox);
+ ast_log(LOG_WARNING, "IMAP user not set for mailbox %s\n", vmu->mailbox);
return -1;
}
}
/* No IMAP account available */
if (vmu->imapuser[0] == '\0') {
- ast_log (LOG_WARNING,"IMAP user not set for mailbox %s\n",vmu->mailbox);
+ ast_log(LOG_WARNING, "IMAP user not set for mailbox %s\n", vmu->mailbox);
free_user(vmu);
return -1;
}
/* check if someone is accessing this box right now... */
- vms_p = get_vm_state_by_imapuser(vmu->imapuser,1);
+ vms_p = get_vm_state_by_imapuser(vmu->imapuser, 1);
if (!vms_p) {
- vms_p = get_vm_state_by_mailbox(mailbox,1);
+ vms_p = get_vm_state_by_mailbox(mailbox, 1);
}
if (vms_p) {
ast_debug(3, "Returning before search - user is logged in\n");
@@ -2694,29 +2715,33 @@
}
/* add one if not there... */
- vms_p = get_vm_state_by_imapuser(vmu->imapuser,0);
+ vms_p = get_vm_state_by_imapuser(vmu->imapuser, 0);
if (!vms_p) {
- vms_p = get_vm_state_by_mailbox(mailbox,0);
+ vms_p = get_vm_state_by_mailbox(mailbox, 0);
}
if (!vms_p) {
- ast_debug(3,"Adding new vmstate for %s\n",vmu->imapuser);
+ ast_debug(3, "Adding new vmstate for %s\n", vmu->imapuser);
if (!(vms_p = ast_calloc(1, sizeof(*vms_p)))) {
return -1;
}
- ast_copy_string(vms_p->imapuser,vmu->imapuser, sizeof(vms_p->imapuser));
+ ast_copy_string(vms_p->imapuser, vmu->imapuser, sizeof(vms_p->imapuser));
ast_copy_string(vms_p->username, mailbox, sizeof(vms_p->username)); /* save for access from interactive entry point */
vms_p->mailstream = NIL; /* save for access from interactive entry point */
- ast_debug(3, "Copied %s to %s\n",vmu->imapuser,vms_p->imapuser);
+ ast_debug(3, "Copied %s to %s\n", vmu->imapuser, vms_p->imapuser);
vms_p->updated = 1;
/* set mailbox to INBOX! */
ast_copy_string(vms_p->curbox, mbox(fold), sizeof(vms_p->curbox));
init_vm_state(vms_p);
vmstate_insert(vms_p);
}
- ret = init_mailstream(vms_p, fold);
+ if (fold == 11) /* open INBOX for urgent messages */
+ ret = init_mailstream(vms_p, 0);
+ else
+ ret = init_mailstream(vms_p, fold);
+
if (!vms_p->mailstream) {
- ast_log (LOG_ERROR,"Houston we have a problem - IMAP mailstream is NULL\n");
+ ast_log(LOG_ERROR, "Houston we have a problem - IMAP mailstream is NULL\n");
return -1;
}
if (ret == 0) {
@@ -2773,7 +2798,7 @@
if (urgentmsgs)
*urgentmsgs = 0;
- ast_debug(3,"Mailbox is set to %s\n",mailbox_context);
+ ast_debug(3, "Mailbox is set to %s\n", mailbox_context);
/* If no mailbox, return immediately */
if (ast_strlen_zero(mailbox_context))
return 0;
@@ -2920,7 +2945,7 @@
return 0;
}
flag = ast_variable_retrieve(msg_cfg, "message", "flag");
- if (!ast_strlen_zero(flag) && strcmp(flag,"URGENT") == 0) {
+ if (!ast_strlen_zero(flag) && !strcmp(flag,"URGENT")) {
ast_debug(5, "Found URGENT flag %s in file %s\n", flag, path);
return 1;
}
@@ -3221,25 +3246,12 @@
/* Play the beginning intro if desired */
if (!ast_strlen_zero(prefile)) {
-#ifdef ODBC_STORAGE
- int success =
-#endif
- RETRIEVE(prefile, -1, ext, context);
- if (ast_fileexists(prefile, NULL, NULL) > 0) {
- if (ast_streamfile(chan, prefile, chan->language) > -1)
- res = ast_waitstream(chan, ecodes);
-#ifdef ODBC_STORAGE
- if (success == -1) {
- /* We couldn't retrieve the file from the database, but we found it on the file system. Let's put it in the database. */
- ast_debug(1, "Greeting not retrieved from database, but found in file storage. Inserting into database\n");
- store_file(prefile, vmu->mailbox, vmu->context, -1);
- }
-#endif
- } else {
+ res = play_greeting(chan, vmu, prefile, ecodes);
+ if (res == -2) {
+ /* The file did not exist */
ast_debug(1, "%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);
+ res = invent_message(chan, vmu, ext, ast_test_flag(options, OPT_BUSY_GREETING), ecodes);
+ }
if (res < 0) {
ast_debug(1, "Hang up during prefile playback\n");
free_user(vmu);
@@ -3320,10 +3332,10 @@
/* must open stream for this user to get info! */
res = inboxcount(ext_context, &urgentmsgs, &newmsgs, &oldmsgs);
if (res < 0) {
- ast_log(LOG_NOTICE,"Can not leave voicemail, unable to count messages\n");
+ ast_log(LOG_NOTICE, "Can not leave voicemail, unable to count messages\n");
return -1;
}
- if (!(vms = get_vm_state_by_mailbox(ext,0))) {
+ if (!(vms = get_vm_state_by_mailbox(ext, 0))) {
/*It is possible under certain circumstances that inboxcount did not create a vm_state when it was needed. This is a catchall which will
* rarely be used*/
if (!(vms = ast_calloc(1, sizeof(*vms)))) {
@@ -3334,17 +3346,17 @@
ast_copy_string(vms->username, ext, sizeof(vms->username));
vms->mailstream = NIL;
ast_debug(3, "Copied %s to %s\n", vmu->imapuser, vms->imapuser);
- vms->updated=1;
+ vms->updated = 1;
ast_copy_string(vms->curbox, mbox(0), sizeof(vms->curbox));
init_vm_state(vms);
vmstate_insert(vms);
- vms = get_vm_state_by_mailbox(ext,0);
+ vms = get_vm_state_by_mailbox(ext, 0);
}
vms->newmessages++;
/* here is a big difference! We add one to it later */
msgnum = newmsgs + oldmsgs;
- ast_debug(3, "Messagecount set to %d\n",msgnum);
+ ast_debug(3, "Messagecount set to %d\n", msgnum);
snprintf(fn, sizeof(fn), "%s/imap/msg%s%04d", VM_SPOOL_DIR, vmu->mailbox, msgnum);
/* set variable for compatibility */
pbx_builtin_setvar_helper(chan, "VM_MESSAGEFILE", "IMAP_STORAGE");
@@ -3441,8 +3453,7 @@
fprintf(txt, "flag=%s\n", flag);
if (duration < vmminsecs) {
fclose(txt);
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Recording was %d seconds long but needs to be at least %d - abandoning\n", duration, vmminsecs);
+ ast_verb(3, "Recording was %d seconds long but needs to be at least %d - abandoning\n", duration, vmminsecs);
ast_filedelete(tmptxtfile, NULL);
unlink(tmptxtfile);
if (ast_check_realtime("voicemail_data")) {
@@ -3547,7 +3558,7 @@
{
/* we know max messages, so stop process when number is hit */
- int x,dest;
+ int x, dest;
char sfn[PATH_MAX];
char dfn[PATH_MAX];
@@ -3591,8 +3602,8 @@
if (box == 1) return 10;
/* get the real IMAP message number for this message */
snprintf(sequence, sizeof(sequence), "%ld", vms->msgArray[msg]);
- ast_debug(3, "Copying sequence %s to mailbox %s\n",sequence,mbox(box));
- res = mail_copy(vms->mailstream,sequence,(char *) mbox(box));
+ ast_debug(3, "Copying sequence %s to mailbox %s\n", sequence, mbox(box));
+ res = mail_copy(vms->mailstream, sequence, (char *)mbox(box));
if (res == 1) return 0;
return 1;
#else
@@ -3649,7 +3660,7 @@
static int adsi_load_vmail(struct ast_channel *chan, int *useadsi)
{
unsigned char buf[256];
- int bytes=0;
+ int bytes = 0;
int x;
char num[5];
@@ -3724,7 +3735,7 @@
#endif
bytes = 0;
- for (x=0;x<5;x++) {
+ for (x = 0; x < 5; x++) {
snprintf(num, sizeof(num), "%d", x);
bytes += ast_adsi_load_soft_key(buf + bytes, ADSI_KEY_APPS + 12 + x, mbox(x), mbox(x), num, 1);
}
@@ -3795,13 +3806,13 @@
static void adsi_login(struct ast_channel *chan)
{
unsigned char buf[256];
- int bytes=0;
+ int bytes = 0;
unsigned char keys[8];
int x;
if (!ast_adsi_available(chan))
return;
- for (x=0;x<8;x++)
+ for (x = 0; x < 8; x++)
keys[x] = 0;
/* Set one key for next */
keys[3] = ADSI_KEY_APPS + 3;
@@ -3821,13 +3832,13 @@
static void adsi_password(struct ast_channel *chan)
{
unsigned char buf[256];
- int bytes=0;
+ int bytes = 0;
unsigned char keys[8];
int x;
if (!ast_adsi_available(chan))
return;
- for (x=0;x<8;x++)
+ for (x = 0; x < 8; x++)
keys[x] = 0;
/* Set one key for next */
keys[3] = ADSI_KEY_APPS + 3;
@@ -3843,14 +3854,14 @@
static void adsi_folders(struct ast_channel *chan, int start, char *label)
{
unsigned char buf[256];
- int bytes=0;
+ int bytes = 0;
unsigned char keys[8];
- int x,y;
+ int x, y;
if (!ast_adsi_available(chan))
return;
- for (x=0;x<5;x++) {
+ for (x = 0; x < 5; x++) {
y = ADSI_KEY_APPS + 12 + start + x;
if (y > ADSI_KEY_APPS + 12 + 4)
y = 0;
@@ -3871,15 +3882,15 @@
static void adsi_message(struct ast_channel *chan, struct vm_state *vms)
{
- int bytes=0;
+ int bytes = 0;
unsigned char buf[256];
char buf1[256], buf2[256];
char fn2[PATH_MAX];
- char cid[256]="";
+ char cid[256] = "";
char *val;
char *name, *num;
- char datetime[21]="";
+ char datetime[21] = "";
FILE *f;
unsigned char keys[8];
@@ -3896,7 +3907,7 @@
while (!feof(f)) {
fgets((char *)buf, sizeof(buf), f);
if (!feof(f)) {
- char *stringp=NULL;
+ char *stringp = NULL;
stringp = (char *)buf;
strsep(&stringp, "=");
val = strsep(&stringp, "=");
@@ -3911,7 +3922,7 @@
fclose(f);
}
/* New meaning for keys */
- for (x=0;x<5;x++)
+ for (x = 0; x < 5; x++)
keys[x] = ADSI_KEY_SKT | (ADSI_KEY_APPS + 6 + x);
keys[6] = 0x0;
keys[7] = 0x0;
@@ -3964,7 +3975,7 @@
static void adsi_delete(struct ast_channel *chan, struct vm_state *vms)
{
- int bytes=0;
+ int bytes = 0;
unsigned char buf[256];
unsigned char keys[8];
@@ -3974,7 +3985,7 @@
return;
/* New meaning for keys */
- for (x=0;x<5;x++)
+ for (x = 0; x < 5; x++)
keys[x] = ADSI_KEY_SKT | (ADSI_KEY_APPS + 6 + x);
keys[6] = 0x0;
@@ -4011,7 +4022,7 @@
{
unsigned char buf[256] = "";
char buf1[256] = "", buf2[256] = "";
- int bytes=0;
+ int bytes = 0;
unsigned char keys[8];
int x;
@@ -4039,7 +4050,7 @@
bytes += ast_adsi_display(buf + bytes, ADSI_COMM_PAGE, 2, ADSI_JUST_LEFT, 0, buf2, "");
bytes += ast_adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
- for (x=0;x<6;x++)
+ for (x = 0; x < 6; x++)
keys[x] = ADSI_KEY_SKT | (ADSI_KEY_APPS + x);
keys[6] = 0;
keys[7] = 0;
@@ -4058,7 +4069,7 @@
{
unsigned char buf[256] = "";
char buf1[256] = "", buf2[256] = "";
- int bytes=0;
+ int bytes = 0;
unsigned char keys[8];
int x;
@@ -4068,7 +4079,7 @@
return;
/* Original command keys */
- for (x=0;x<6;x++)
+ for (x = 0; x < 6; x++)
keys[x] = ADSI_KEY_SKT | (ADSI_KEY_APPS + x);
keys[6] = 0;
@@ -4100,7 +4111,7 @@
static void adsi_clear(struct ast_channel *chan)
{
char buf[256];
- int bytes=0;
+ int bytes = 0;
if (!ast_adsi_available(chan))
return;
bytes += ast_adsi_set_line(buf + bytes, ADSI_COMM_PAGE, 1);
@@ -4113,7 +4124,7 @@
static void adsi_goodbye(struct ast_channel *chan)
{
unsigned char buf[256];
- int bytes=0;
+ int bytes = 0;
if (!ast_adsi_available(chan))
return;
@@ -4138,7 +4149,7 @@
d = ast_play_and_wait(chan, "vm-press"); /* "Press" */
if (d)
return d;
- for (x = start; x< 5; x++) { /* For all folders */
+ for (x = start; x < 5; x++) { /* For all folders */
if ((d = ast_say_number(chan, x, AST_DIGIT_ANY, chan->language, NULL)))
return d;
d = ast_play_and_wait(chan, "vm-for"); /* "for" */
@@ -4174,9 +4185,26 @@
char *context, signed char record_gain, long *duration, struct vm_state *vms)
{
int cmd = 0;
- int retries = 0;
+ int retries = 0, prepend_duration = 0, already_recorded = 0;
signed char zero_gain = 0;
struct ast_flags config_flags = { CONFIG_FLAG_NOCACHE };
+ struct ast_config *msg_cfg;
+ const char *duration_str;
+ char msgfile[PATH_MAX], backup[PATH_MAX];
+ char textfile[PATH_MAX];
+
+ /* Must always populate duration correctly */
+ make_file(msgfile, sizeof(msgfile), curdir, curmsg);
+ strcpy(textfile, msgfile);
+ strcpy(backup, msgfile);
+ strncat(textfile, ".txt", sizeof(textfile) - 1);
+ strncat(backup, "-bak", sizeof(backup) - 1);
+
+ msg_cfg = ast_config_load(textfile, config_flags);
+
+ *duration = 0;
+ if ((duration_str = ast_variable_retrieve(msg_cfg, "message", "duration")))
+ *duration = atoi(duration_str);
while ((cmd >= 0) && (cmd != 't') && (cmd != '*')) {
if (cmd)
@@ -4185,16 +4213,7 @@
case '1':
/* prepend a message to the current message, update the metadata and return */
{
- char msgfile[PATH_MAX];
- char textfile[PATH_MAX];
- int prepend_duration = 0;
- struct ast_config *msg_cfg;
- const char *duration_str;
-
- make_file(msgfile, sizeof(msgfile), curdir, curmsg);
- strcpy(textfile, msgfile);
- strncat(textfile, ".txt", sizeof(textfile) - 1);
- *duration = 0;
+ prepend_duration = 0;
/* if we can't read the message metadata, stop now */
if (!(msg_cfg = ast_config_load(textfile, config_flags))) {
@@ -4202,33 +4221,34 @@
break;
}
+ /* Back up the original file, so we can retry the prepend */
+ if (already_recorded)
+ ast_filecopy(backup, msgfile, NULL);
+ else
+ ast_filecopy(msgfile, backup, NULL);
+ already_recorded = 1;
+
if (record_gain)
ast_channel_setoption(chan, AST_OPTION_RXGAIN, &record_gain, sizeof(record_gain), 0);
cmd = ast_play_and_prepend(chan, NULL, msgfile, 0, vmfmts, &prepend_duration, 1, silencethreshold, maxsilence);
if (record_gain)
ast_channel_setoption(chan, AST_OPTION_RXGAIN, &zero_gain, sizeof(zero_gain), 0);
-
-
- if ((duration_str = ast_variable_retrieve(msg_cfg, "message", "duration")))
- *duration = atoi(duration_str);
if (prepend_duration) {
struct ast_category *msg_cat;
/* need enough space for a maximum-length message duration */
char duration_str[12];
- *duration += prepend_duration;
+ prepend_duration += *duration;
msg_cat = ast_category_get(msg_cfg, "message");
- snprintf(duration_str, 11, "%ld", *duration);
+ snprintf(duration_str, sizeof(duration_str), "%d", prepend_duration);
if (!ast_variable_update(msg_cat, "duration", duration_str, NULL, 0)) {
config_text_file_save(textfile, msg_cfg, "app_voicemail");
/* flags not set, so not sent here */
- STORE(curdir, vmu->mailbox, context, curmsg, chan, vmu, vmfmts, *duration, vms, NULL);
+ STORE(curdir, vmu->mailbox, context, curmsg, chan, vmu, vmfmts, prepend_duration, vms, NULL);
}
}
-
- ast_config_destroy(msg_cfg);
break;
}
[... 1547 lines stripped ...]
More information about the asterisk-commits
mailing list