fix compiler warnings
[asterisk/asterisk.git] / image.c
diff --git a/image.c b/image.c
index 61eefde..894e660 100755 (executable)
--- a/image.c
+++ b/image.c
@@ -1,54 +1,68 @@
 /*
 /*
- * Asterisk -- A telephony toolkit for Linux.
+ * Asterisk -- An open source telephony toolkit.
  *
  *
- * Channel Management
- * 
- * Copyright (C) 1999, Mark Spencer
+ * Copyright (C) 1999 - 2005, Digium, Inc.
+ *
+ * Mark Spencer <markster@digium.com>
  *
  *
- * Mark Spencer <markster@linux-support.net>
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
  *
  * This program is free software, distributed under the terms of
  *
  * This program is free software, distributed under the terms of
- * the GNU General Public License
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Image Management
+ * 
  */
 
 #include <stdio.h>
 #include <stdlib.h>
  */
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <pthread.h>
 #include <string.h>
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <signal.h>
 #include <errno.h>
 #include <unistd.h>
 #include <string.h>
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <signal.h>
 #include <errno.h>
 #include <unistd.h>
-#include <asterisk/sched.h>
-#include <asterisk/options.h>
-#include <asterisk/channel.h>
-#include <asterisk/channel_pvt.h>
-#include <asterisk/logger.h>
-#include <asterisk/file.h>
-#include <asterisk/image.h>
-#include <asterisk/translate.h>
-#include <asterisk/cli.h>
+
 #include "asterisk.h"
 
 #include "asterisk.h"
 
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/sched.h"
+#include "asterisk/options.h"
+#include "asterisk/channel.h"
+#include "asterisk/logger.h"
+#include "asterisk/file.h"
+#include "asterisk/image.h"
+#include "asterisk/translate.h"
+#include "asterisk/cli.h"
+#include "asterisk/lock.h"
+
 static struct ast_imager *list;
 static struct ast_imager *list;
-static pthread_mutex_t listlock = PTHREAD_MUTEX_INITIALIZER;
+AST_MUTEX_DEFINE_STATIC(listlock);
 
 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);
 
 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_pthread_mutex_lock(&listlock);
+       ast_mutex_lock(&listlock);
        img->next = list;
        list = img;
        img->next = list;
        list = img;
-       ast_pthread_mutex_unlock(&listlock);
+       ast_mutex_unlock(&listlock);
        return 0;
 }
 
 void ast_image_unregister(struct ast_imager *img)
 {
        struct ast_imager *i, *prev = NULL;
        return 0;
 }
 
 void ast_image_unregister(struct ast_imager *img)
 {
        struct ast_imager *i, *prev = NULL;
-       ast_pthread_mutex_lock(&listlock);
+       ast_mutex_lock(&listlock);
        i = list;
        while(i) {
                if (i == img) {
        i = list;
        while(i) {
                if (i == img) {
@@ -61,14 +75,16 @@ void ast_image_unregister(struct ast_imager *img)
                prev = i;
                i = i->next;
        }
                prev = i;
                i = i->next;
        }
-       ast_pthread_mutex_unlock(&listlock);
+       ast_mutex_unlock(&listlock);
        if (i && (option_verbose > 1))
        if (i && (option_verbose > 1))
-               ast_verbose(VERBOSE_PREFIX_2 "Registered format '%s' (%s)\n", img->name, img->desc);
+               ast_verbose(VERBOSE_PREFIX_2 "Unregistered format '%s' (%s)\n", img->name, img->desc);
 }
 
 int ast_supports_images(struct ast_channel *chan)
 {
 }
 
 int ast_supports_images(struct ast_channel *chan)
 {
-       if (!chan->pvt->send_image)
+       if (!chan || !chan->tech)
+               return 0;
+       if (!chan->tech->send_image)
                return 0;
        return 1;
 }
                return 0;
        return 1;
 }
@@ -92,9 +108,9 @@ static void make_filename(char *buf, int len, char *filename, char *preflang, ch
                        snprintf(buf, len, "%s.%s", filename, ext);
        } else {
                if (preflang && strlen(preflang))
                        snprintf(buf, len, "%s.%s", filename, ext);
        } else {
                if (preflang && strlen(preflang))
-                       snprintf(buf, len, "%s/%s-%s.%s", AST_IMAGES, filename, preflang, ext);
+                       snprintf(buf, len, "%s/%s/%s-%s.%s", ast_config_AST_VAR_DIR, "images", filename, preflang, ext);
                else
                else
-                       snprintf(buf, len, "%s/%s.%s", AST_IMAGES, filename, ext);
+                       snprintf(buf, len, "%s/%s/%s.%s", ast_config_AST_VAR_DIR, "images", filename, ext);
        }
 }
 
        }
 }
 
@@ -109,13 +125,15 @@ struct ast_frame *ast_read_image(char *filename, char *preflang, int format)
        int len=0;
        struct ast_frame *f = NULL;
 #if 0 /* We need to have some sort of read-only lock */
        int len=0;
        struct ast_frame *f = NULL;
 #if 0 /* We need to have some sort of read-only lock */
-       ast_pthread_mutex_lock(&listlock);
+       ast_mutex_lock(&listlock);
 #endif 
        i = list;
        while(!found && i) {
                if (i->format & format) {
 #endif 
        i = list;
        while(!found && i) {
                if (i->format & format) {
-                       strncpy(tmp, i->exts, sizeof(tmp));
-                       e = strtok(tmp, "|");
+                       char *stringp=NULL;
+                       strncpy(tmp, i->exts, sizeof(tmp)-1);
+                       stringp=tmp;
+                       e = strsep(&stringp, "|");
                        while(e) {
                                make_filename(buf, sizeof(buf), filename, preflang, e);
                                if ((len = file_exists(buf))) {
                        while(e) {
                                make_filename(buf, sizeof(buf), filename, preflang, e);
                                if ((len = file_exists(buf))) {
@@ -127,7 +145,7 @@ struct ast_frame *ast_read_image(char *filename, char *preflang, int format)
                                        found = i;
                                        break;
                                }
                                        found = i;
                                        break;
                                }
-                               e = strtok(NULL, "|");
+                               e = strsep(&stringp, "|");
                        }
                }
                i = i->next;
                        }
                }
                i = i->next;
@@ -147,7 +165,7 @@ struct ast_frame *ast_read_image(char *filename, char *preflang, int format)
        } else
                ast_log(LOG_WARNING, "Image file '%s' not found\n", filename);
 #if 0
        } else
                ast_log(LOG_WARNING, "Image file '%s' not found\n", filename);
 #if 0
-       ast_pthread_mutex_unlock(&listlock);
+       ast_mutex_unlock(&listlock);
 #endif 
        return f;
 }
 #endif 
        return f;
 }
@@ -157,10 +175,10 @@ int ast_send_image(struct ast_channel *chan, char *filename)
 {
        struct ast_frame *f;
        int res = -1;
 {
        struct ast_frame *f;
        int res = -1;
-       if (chan->pvt->send_image) {
+       if (chan->tech->send_image) {
                f = ast_read_image(filename, chan->language, -1);
                if (f) {
                f = ast_read_image(filename, chan->language, -1);
                if (f) {
-                       res = chan->pvt->send_image(chan, f);
+                       res = chan->tech->send_image(chan, f);
                        ast_frfree(f);
                }
        }
                        ast_frfree(f);
                }
        }
@@ -170,14 +188,14 @@ int ast_send_image(struct ast_channel *chan, char *filename)
 static int show_image_formats(int fd, int argc, char *argv[])
 {
 #define FORMAT "%10s %10s %50s %10s\n"
 static int show_image_formats(int fd, int argc, char *argv[])
 {
 #define FORMAT "%10s %10s %50s %10s\n"
-#define FORMAT2 "%10s %10s %50s %10d\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");
        i = list;
        while(i) {
        struct ast_imager *i;
        if (argc != 3)
                return RESULT_SHOWUSAGE;
        ast_cli(fd, FORMAT, "Name", "Extensions", "Description", "Format");
        i = list;
        while(i) {
-               ast_cli(fd, FORMAT2, i->name, i->exts, i->desc, i->format);
+               ast_cli(fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format));
                i = i->next;
        };
        return RESULT_SUCCESS;
                i = i->next;
        };
        return RESULT_SUCCESS;