Add the ability to dynamically specify weights for responses to DUNDi queries.
[asterisk/asterisk.git] / main / image.c
index 377ce92..a0a4100 100644 (file)
@@ -47,15 +47,15 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/lock.h"
 
 /* XXX Why don't we just use the formats struct for this? */
-static AST_LIST_HEAD_STATIC(imagers, ast_imager);
+static AST_RWLIST_HEAD_STATIC(imagers, ast_imager);
 
 int ast_image_register(struct ast_imager *img)
 {
        if (option_verbose > 1)
                ast_verbose(VERBOSE_PREFIX_2 "Registered format '%s' (%s)\n", img->name, img->desc);
-       AST_LIST_LOCK(&imagers);
-       AST_LIST_INSERT_HEAD(&imagers, img, list);
-       AST_LIST_UNLOCK(&imagers);
+       AST_RWLIST_WRLOCK(&imagers);
+       AST_RWLIST_INSERT_HEAD(&imagers, img, list);
+       AST_RWLIST_UNLOCK(&imagers);
        return 0;
 }
 
@@ -63,15 +63,15 @@ void ast_image_unregister(struct ast_imager *img)
 {
        struct ast_imager *i;
        
-       AST_LIST_LOCK(&imagers);
-       AST_LIST_TRAVERSE_SAFE_BEGIN(&imagers, i, list) {       
+       AST_RWLIST_WRLOCK(&imagers);
+       AST_RWLIST_TRAVERSE_SAFE_BEGIN(&imagers, i, list) {     
                if (i == img) {
-                       AST_LIST_REMOVE_CURRENT(&imagers, list);
+                       AST_RWLIST_REMOVE_CURRENT(&imagers, list);
                        break;
                }
        }
-       AST_LIST_TRAVERSE_SAFE_END
-       AST_LIST_UNLOCK(&imagers);
+       AST_RWLIST_TRAVERSE_SAFE_END
+       AST_RWLIST_UNLOCK(&imagers);
        if (i && (option_verbose > 1))
                ast_verbose(VERBOSE_PREFIX_2 "Unregistered format '%s' (%s)\n", img->name, img->desc);
 }
@@ -121,14 +121,14 @@ struct ast_frame *ast_read_image(char *filename, const char *preflang, int forma
        int len=0;
        struct ast_frame *f = NULL;
        
-       AST_LIST_LOCK(&imagers);
-       AST_LIST_TRAVERSE(&imagers, i, list) {
+       AST_RWLIST_RDLOCK(&imagers);
+       AST_RWLIST_TRAVERSE(&imagers, i, list) {
                if (i->format & format) {
                        char *stringp=NULL;
-                       strncpy(tmp, i->exts, sizeof(tmp)-1);
+                       ast_copy_string(tmp, i->exts, sizeof(tmp));
                        stringp=tmp;
                        e = strsep(&stringp, "|");
-                       while(e) {
+                       while (e) {
                                make_filename(buf, sizeof(buf), filename, preflang, e);
                                if ((len = file_exists(buf))) {
                                        found = i;
@@ -161,7 +161,7 @@ struct ast_frame *ast_read_image(char *filename, const char *preflang, int forma
        } else
                ast_log(LOG_WARNING, "Image file '%s' not found\n", filename);
        
-       AST_LIST_UNLOCK(&imagers);
+       AST_RWLIST_UNLOCK(&imagers);
        
        return f;
 }
@@ -180,19 +180,6 @@ int ast_send_image(struct ast_channel *chan, char *filename)
        return res;
 }
 
-static int show_image_formats_deprecated(int fd, int argc, char *argv[])
-{
-#define FORMAT "%10s %10s %50s %10s\n"
-#define FORMAT2 "%10s %10s %50s %10s\n"
-       struct ast_imager *i;
-       if (argc != 3)
-               return RESULT_SHOWUSAGE;
-       ast_cli(fd, FORMAT, "Name", "Extensions", "Description", "Format");
-       AST_LIST_TRAVERSE(&imagers, i, list)
-               ast_cli(fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format));
-       return RESULT_SUCCESS;
-}
-
 static int show_image_formats(int fd, int argc, char *argv[])
 {
 #define FORMAT "%10s %10s %50s %10s\n"
@@ -201,21 +188,19 @@ static int show_image_formats(int fd, int argc, char *argv[])
        if (argc != 4)
                return RESULT_SHOWUSAGE;
        ast_cli(fd, FORMAT, "Name", "Extensions", "Description", "Format");
-       AST_LIST_TRAVERSE(&imagers, i, list)
+       AST_RWLIST_RDLOCK(&imagers);
+       AST_RWLIST_TRAVERSE(&imagers, i, list) {
                ast_cli(fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format));
+       }
+       AST_RWLIST_UNLOCK(&imagers);
        return RESULT_SUCCESS;
 }
 
-struct ast_cli_entry cli_show_image_formats_deprecated = {
-       { "show", "image", "formats" },
-       show_image_formats_deprecated, NULL,
-       NULL };
-
 struct ast_cli_entry cli_image[] = {
-       { { "file", "list", "formats", "image" },
+       { { "core", "show", "image", "formats" },
        show_image_formats, "Displays image formats",
-       "Usage: file list formats image\n"
-       "       displays currently registered image formats (if any)\n", NULL, &cli_show_image_formats_deprecated },
+       "Usage: core show image formats\n"
+       "       displays currently registered image formats (if any)\n" },
 };
 
 int ast_image_init(void)