Make meetme operate in linear so as to keep alaw folk happy, minor iax2
[asterisk/asterisk.git] / file.c
diff --git a/file.c b/file.c
index f9a421e..1e896e8 100755 (executable)
--- a/file.c
+++ b/file.c
@@ -19,6 +19,7 @@
 #include <asterisk/sched.h>
 #include <asterisk/options.h>
 #include <asterisk/translate.h>
+#include <asterisk/utils.h>
 #include <errno.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -78,7 +79,7 @@ struct ast_filestream {
        struct ast_channel *owner;
 };
 
-static ast_mutex_t formatlock = AST_MUTEX_INITIALIZER;
+AST_MUTEX_DEFINE_STATIC(formatlock);
 
 static struct ast_format *formats = NULL;
 
@@ -153,6 +154,7 @@ int ast_format_unregister(char *name)
                                ast_verbose( VERBOSE_PREFIX_2 "Unregistered format %s\n", name);
                        return 0;
                }
+               tmpl = tmp;
                tmp = tmp->next;
        }
        ast_log(LOG_WARNING, "Tried to unregister format %s, already unregistered\n", name);
@@ -287,6 +289,22 @@ static char *build_filename(char *filename, char *ext)
        
 }
 
+static int exts_compare(char *exts, char *type)
+{
+       char *stringp = NULL, *ext;
+       char tmp[256];
+
+       strncpy(tmp, exts, sizeof(tmp) - 1);
+       stringp = tmp;
+       while ((ext = strsep(&stringp, "|"))) {
+               if (!strcmp(ext, type)) {
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+
 #define ACTION_EXISTS 1
 #define ACTION_DELETE 2
 #define ACTION_RENAME 3
@@ -319,7 +337,7 @@ static int ast_filehelper(char *filename, char *filename2, char *fmt, int action
        }
        f = formats;
        while(f) {
-               if (!fmt || !strcasecmp(f->name, fmt)) {
+               if (!fmt || exts_compare(f->exts, fmt)) {
                        char *stringp=NULL;
                        exts = strdup(f->exts);
                        /* Try each kind of extension */
@@ -376,7 +394,7 @@ static int ast_filehelper(char *filename, char *filename2, char *fmt, int action
                                                                                        chan->vstream = s;
                                                                        } else {
                                                                                close(ret);
-                                                                               ast_log(LOG_WARNING, "Unable to open fd on %s\n", filename);
+                                                                               ast_log(LOG_WARNING, "Unable to open fd on %s\n", fn);
                                                                        }
                                                                } else
                                                                        ast_log(LOG_WARNING, "Couldn't open file %s\n", fn);
@@ -427,7 +445,7 @@ struct ast_filestream *ast_openstream(struct ast_channel *chan, char *filename,
        /* do this first, otherwise we detect the wrong writeformat */
        if (chan->generator)
                ast_deactivate_generator(chan);
-       if (preflang && strlen(preflang)) {
+       if (preflang && !ast_strlen_zero(preflang)) {
                strncpy(filename3, filename, sizeof(filename3) - 1);
                endpart = strrchr(filename3, '/');
                if (endpart) {
@@ -476,7 +494,7 @@ struct ast_filestream *ast_openvstream(struct ast_channel *chan, char *filename,
        char lang2[MAX_LANGUAGE];
        /* XXX H.263 only XXX */
        char *fmt = "h263";
-       if (preflang && strlen(preflang)) {
+       if (preflang && !ast_strlen_zero(preflang)) {
                snprintf(filename2, sizeof(filename2), "%s/%s", preflang, filename);
                fmts = ast_fileexists(filename2, fmt, NULL);
                if (fmts < 1) {
@@ -661,7 +679,7 @@ int ast_fileexists(char *filename, char *fmt, char *preflang)
        char *c;
        char lang2[MAX_LANGUAGE];
        int res = -1;
-       if (preflang && strlen(preflang)) {
+       if (preflang && !ast_strlen_zero(preflang)) {
                /* Insert the language between the last two parts of the path */
                strncpy(tmp, filename, sizeof(tmp) - 1);
                c = strrchr(tmp, '/');
@@ -748,7 +766,7 @@ struct ast_filestream *ast_readfile(char *filename, char *type, char *comment, i
        }
        f = formats;
        while(f) {
-               if (!strcasecmp(f->name, type)) {
+               if (exts_compare(f->exts, type)) {
                        char *stringp=NULL;
                        /* XXX Implement check XXX */
                        ext = strdup(f->exts);
@@ -803,7 +821,7 @@ struct ast_filestream *ast_writefile(char *filename, char *type, char *comment,
 
        f = formats;
        while(f) {
-               if (!strcasecmp(f->name, type)) {
+               if (exts_compare(f->exts, type)) {
                        char *stringp=NULL;
                        /* XXX Implement check XXX */
                        ext = strdup(f->exts);