]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Merged revisions 231688 via svnmerge from
authorMatthew Nicholson <mnicholson@digium.com>
Mon, 30 Nov 2009 21:36:53 +0000 (21:36 +0000)
committerMatthew Nicholson <mnicholson@digium.com>
Mon, 30 Nov 2009 21:36:53 +0000 (21:36 +0000)
https://origsvn.digium.com/svn/asterisk/trunk

................
  r231688 | mnicholson | 2009-11-30 15:31:55 -0600 (Mon, 30 Nov 2009) | 15 lines

  Merged revisions 231614 via svnmerge from
  https://origsvn.digium.com/svn/asterisk/branches/1.4

  ........
    r231614 | mnicholson | 2009-11-30 15:11:44 -0600 (Mon, 30 Nov 2009) | 8 lines

    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/
  ........
................

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.1@231690 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_voicemail.c
include/asterisk/file.h
main/app.c
main/file.c

index 796fe8be80459177e90c1e40574f8594d841a0e4..27c07628862f13fb01af44910db521aa84576e84 100644 (file)
@@ -10362,7 +10362,7 @@ static int load_config(int reload)
        char *cat;
        struct ast_variable *var;
        const char *val;
-       char *q, *stringp;
+       char *q, *stringp, *tmp;
        int x;
        int tmpadsi[4];
        struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
@@ -10656,8 +10656,16 @@ static int load_config(int reload)
                }
 
                val = ast_variable_retrieve(cfg, "general", "format");
-               if (!val)
+               if (!val) {
                        val = "wav";    
+               } else {
+                       tmp = ast_strdupa(val);
+                       val = ast_format_str_reduce(tmp);
+                       if (!val) {
+                               ast_log(LOG_ERROR, "Error processing format string, defaulting to format 'wav'\n");
+                               val = "wav";
+                       }
+               }
                ast_copy_string(vmfmts, val, sizeof(vmfmts));
 
                skipms = 3000;
index 43b32fd12a7faf61712976bd5534435f3a2f7fe5..8def42ae5d41fb169285ad47df4f2abcb487d537 100644 (file)
@@ -40,6 +40,9 @@ extern "C" {
 struct ast_filestream;
 struct ast_format;
 
+/*! 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"
 #define AST_DIGIT_ANYNUM "0123456789"
@@ -325,6 +328,14 @@ int ast_file_init(void);
 
 #define AST_RESERVED_POINTERS 20
 
+/*! 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);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif
index 80bdd4a03338c9edc8bf5f364ebb6b527c75241e..494db102187344fc55e18bf980f64bba1388ecef 100644 (file)
@@ -48,7 +48,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/indications.h"
 #include "asterisk/linkedlists.h"
 
-#define MAX_OTHER_FORMATS 10
+#define AST_MAX_FORMATS 10
 
 static AST_RWLIST_HEAD_STATIC(groups, ast_group_info);
 
@@ -620,8 +620,8 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
        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 */
@@ -667,8 +667,8 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
        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);
@@ -850,7 +850,7 @@ static int __ast_play_and_record(struct ast_channel *chan, const char *playfile,
        }
 
        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++) {
index 12e3fcb30fe137f3cd48209166b0ebe98988e7b2..f35ff6fa39e8fd3e191a11f16b4cf29e095be3e3 100644 (file)
@@ -1351,6 +1351,66 @@ int ast_stream_and_wait(struct ast_channel *chan, const char *file, const char *
        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_RWLIST_RDLOCK(&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_RWLIST_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_RWLIST_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 char *handle_cli_core_show_file_formats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 #define FORMAT "%-10s %-10s %-20s\n"