Add the ability to dynamically specify weights for responses to DUNDi queries.
[asterisk/asterisk.git] / main / image.c
index ff67c03..a0a4100 100644 (file)
@@ -46,15 +46,16 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/cli.h"
 #include "asterisk/lock.h"
 
-static AST_LIST_HEAD_STATIC(imagers, ast_imager);
+/* XXX Why don't we just use the formats struct for this? */
+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;
 }
 
@@ -62,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);
 }
@@ -120,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;
@@ -160,12 +161,11 @@ 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;
 }
 
-
 int ast_send_image(struct ast_channel *chan, char *filename)
 {
        struct ast_frame *f;
@@ -185,26 +185,26 @@ static int show_image_formats(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)
+       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 show_images =
-{
-       { "show", "image", "formats" },
-       show_image_formats,
-       "Displays image formats",
-"Usage: show image formats\n"
-"       displays currently registered image formats (if any)\n"
+struct ast_cli_entry cli_image[] = {
+       { { "core", "show", "image", "formats" },
+       show_image_formats, "Displays image formats",
+       "Usage: core show image formats\n"
+       "       displays currently registered image formats (if any)\n" },
 };
 
-
 int ast_image_init(void)
 {
-       return ast_cli_register(&show_images);
+       ast_cli_register_multiple(cli_image, sizeof(cli_image) / sizeof(struct ast_cli_entry));
+       return 0;
 }
-