[asterisk-commits] mnicholson: branch 1.4 r231614 - in /branches/1.4: apps/ include/asterisk/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Nov 30 15:11:48 CST 2009
Author: mnicholson
Date: Mon Nov 30 15:11:44 2009
New Revision: 231614
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=231614
Log:
Remove duplicate entries from voicemail format lists. This prevents app_voicemail from entering an infinite loop when the same format is specified twice in the format list.
(closes issue #15625)
Reported by: Shagg63
Tested by: mnicholson
Review: https://reviewboard.asterisk.org/r/429/
Modified:
branches/1.4/apps/app_voicemail.c
branches/1.4/include/asterisk/file.h
branches/1.4/main/app.c
branches/1.4/main/file.c
Modified: branches/1.4/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/apps/app_voicemail.c?view=diff&rev=231614&r1=231613&r2=231614
==============================================================================
--- branches/1.4/apps/app_voicemail.c (original)
+++ branches/1.4/apps/app_voicemail.c Mon Nov 30 15:11:44 2009
@@ -8333,7 +8333,7 @@
const char *astforcename;
const char *astforcegreet;
const char *s;
- char *q,*stringp;
+ char *q,*stringp, *tmp;
const char *dialoutcxt = NULL;
const char *callbackcxt = NULL;
const char *exitcxt = NULL;
@@ -8542,8 +8542,17 @@
}
}
fmt = ast_variable_retrieve(cfg, "general", "format");
- if (!fmt)
+ if (!fmt) {
fmt = "wav";
+ } else {
+ tmp = ast_strdupa(fmt);
+ fmt = ast_format_str_reduce(tmp);
+ if (!fmt) {
+ ast_log(LOG_ERROR, "Error processing format string, defaulting to format 'wav'\n");
+ fmt = "wav";
+ }
+ }
+
ast_copy_string(vmfmts, fmt, sizeof(vmfmts));
skipms = 3000;
Modified: branches/1.4/include/asterisk/file.h
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/include/asterisk/file.h?view=diff&rev=231614&r1=231613&r2=231614
==============================================================================
--- branches/1.4/include/asterisk/file.h (original)
+++ branches/1.4/include/asterisk/file.h Mon Nov 30 15:11:44 2009
@@ -35,6 +35,8 @@
extern "C" {
#endif
+/*! The maximum number of formats we expect to see in a format string */
+#define AST_MAX_FORMATS 10
/*! Convenient for waiting */
#define AST_DIGIT_ANY "0123456789#*ABCD"
@@ -402,6 +404,14 @@
*/
struct ast_frame *ast_readframe(struct ast_filestream *s);
+/*! Remove duplicate formats from a format string. */
+/*!
+ * \param fmts a format string, this string will be modified
+ * \retval NULL error
+ * \return a pointer to the reduced format string, this is a pointer to fmts
+ */
+char *ast_format_str_reduce(char *fmts);
+
/*! Initialize file stuff */
/*!
* Initializes all the various file stuff. Basically just registers the cli stuff
Modified: branches/1.4/main/app.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/main/app.c?view=diff&rev=231614&r1=231613&r2=231614
==============================================================================
--- branches/1.4/main/app.c (original)
+++ branches/1.4/main/app.c Mon Nov 30 15:11:44 2009
@@ -51,7 +51,7 @@
#include "asterisk/indications.h"
#include "asterisk/linkedlists.h"
-#define MAX_OTHER_FORMATS 10
+#define AST_MAX_FORMATS 10
static AST_LIST_HEAD_STATIC(groups, ast_group_info);
@@ -507,8 +507,8 @@
char *fmts;
char comment[256];
int x, fmtcnt = 1, res = -1, outmsg = 0;
- struct ast_filestream *others[MAX_OTHER_FORMATS];
- char *sfmt[MAX_OTHER_FORMATS];
+ struct ast_filestream *others[AST_MAX_FORMATS];
+ char *sfmt[AST_MAX_FORMATS];
char *stringp = NULL;
time_t start, end;
struct ast_dsp *sildet = NULL; /* silence detector dsp */
@@ -556,8 +556,8 @@
sfmt[0] = ast_strdupa(fmts);
while ((fmt = strsep(&stringp, "|"))) {
- if (fmtcnt > MAX_OTHER_FORMATS - 1) {
- ast_log(LOG_WARNING, "Please increase MAX_OTHER_FORMATS in app.c\n");
+ if (fmtcnt > AST_MAX_FORMATS - 1) {
+ ast_log(LOG_WARNING, "Please increase AST_MAX_FORMATS in file.h\n");
break;
}
sfmt[fmtcnt++] = ast_strdupa(fmt);
@@ -747,7 +747,7 @@
}
if (prepend && outmsg) {
- struct ast_filestream *realfiles[MAX_OTHER_FORMATS];
+ struct ast_filestream *realfiles[AST_MAX_FORMATS];
struct ast_frame *fr;
for (x = 0; x < fmtcnt; x++) {
Modified: branches/1.4/main/file.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.4/main/file.c?view=diff&rev=231614&r1=231613&r2=231614
==============================================================================
--- branches/1.4/main/file.c (original)
+++ branches/1.4/main/file.c Mon Nov 30 15:11:44 2009
@@ -1358,6 +1358,66 @@
return res;
}
+char *ast_format_str_reduce(char *fmts)
+{
+ struct ast_format *f;
+ struct ast_format *fmts_ptr[AST_MAX_FORMATS];
+ char *fmts_str[AST_MAX_FORMATS];
+ char *stringp, *type;
+ char *orig = fmts;
+ int i, j, x, found;
+ int len = strlen(fmts) + 1;
+
+ if (AST_LIST_LOCK(&formats)) {
+ ast_log(LOG_WARNING, "Unable to lock format list\n");
+ return NULL;
+ }
+
+ stringp = ast_strdupa(fmts);
+
+ for (x = 0; (type = strsep(&stringp, "|")) && x < AST_MAX_FORMATS; x++) {
+ AST_LIST_TRAVERSE(&formats, f, list) {
+ if (exts_compare(f->exts, type)) {
+ found = 1;
+ break;
+ }
+ }
+
+ fmts_str[x] = type;
+ if (found) {
+ fmts_ptr[x] = f;
+ } else {
+ fmts_ptr[x] = NULL;
+ }
+ }
+ AST_LIST_UNLOCK(&formats);
+
+ for (i = 0; i < x; i++) {
+ /* special handling for the first entry */
+ if (i == 0) {
+ fmts += snprintf(fmts, len, "%s", fmts_str[i]);
+ len -= (fmts - orig);
+ continue;
+ }
+
+ found = 0;
+ for (j = 0; j < i; j++) {
+ /* this is a duplicate */
+ if (fmts_ptr[j] == fmts_ptr[i]) {
+ found = 1;
+ break;
+ }
+ }
+
+ if (!found) {
+ fmts += snprintf(fmts, len, "|%s", fmts_str[i]);
+ len -= (fmts - orig);
+ }
+ }
+
+ return orig;
+}
+
static int show_file_formats(int fd, int argc, char *argv[])
{
#define FORMAT "%-10s %-10s %-20s\n"
More information about the asterisk-commits
mailing list