mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-11 23:28:59 +00:00
Bug #6118: Clean up list handling in image.c (drumkilla)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7728 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
51
image.c
51
image.c
@@ -46,37 +46,31 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|||||||
#include "asterisk/cli.h"
|
#include "asterisk/cli.h"
|
||||||
#include "asterisk/lock.h"
|
#include "asterisk/lock.h"
|
||||||
|
|
||||||
static struct ast_imager *list;
|
static AST_LIST_HEAD_STATIC(imagers, ast_imager);
|
||||||
AST_MUTEX_DEFINE_STATIC(listlock);
|
|
||||||
|
|
||||||
int ast_image_register(struct ast_imager *img)
|
int ast_image_register(struct ast_imager *img)
|
||||||
{
|
{
|
||||||
if (option_verbose > 1)
|
if (option_verbose > 1)
|
||||||
ast_verbose(VERBOSE_PREFIX_2 "Registered format '%s' (%s)\n", img->name, img->desc);
|
ast_verbose(VERBOSE_PREFIX_2 "Registered format '%s' (%s)\n", img->name, img->desc);
|
||||||
ast_mutex_lock(&listlock);
|
AST_LIST_LOCK(&imagers);
|
||||||
img->next = list;
|
AST_LIST_INSERT_HEAD(&imagers, img, list);
|
||||||
list = img;
|
AST_LIST_UNLOCK(&imagers);
|
||||||
ast_mutex_unlock(&listlock);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ast_image_unregister(struct ast_imager *img)
|
void ast_image_unregister(struct ast_imager *img)
|
||||||
{
|
{
|
||||||
struct ast_imager *i, *prev = NULL;
|
struct ast_imager *i;
|
||||||
ast_mutex_lock(&listlock);
|
|
||||||
i = list;
|
AST_LIST_LOCK(&imagers);
|
||||||
while(i) {
|
AST_LIST_TRAVERSE_SAFE_BEGIN(&imagers, i, list) {
|
||||||
if (i == img) {
|
if (i == img) {
|
||||||
if (prev)
|
AST_LIST_REMOVE_CURRENT(&imagers, list);
|
||||||
prev->next = i->next;
|
|
||||||
else
|
|
||||||
list = i->next;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
prev = i;
|
|
||||||
i = i->next;
|
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&listlock);
|
AST_LIST_TRAVERSE_SAFE_END
|
||||||
|
AST_LIST_UNLOCK(&imagers);
|
||||||
if (i && (option_verbose > 1))
|
if (i && (option_verbose > 1))
|
||||||
ast_verbose(VERBOSE_PREFIX_2 "Unregistered format '%s' (%s)\n", img->name, img->desc);
|
ast_verbose(VERBOSE_PREFIX_2 "Unregistered format '%s' (%s)\n", img->name, img->desc);
|
||||||
}
|
}
|
||||||
@@ -125,11 +119,9 @@ struct ast_frame *ast_read_image(char *filename, char *preflang, int format)
|
|||||||
int fd;
|
int fd;
|
||||||
int len=0;
|
int len=0;
|
||||||
struct ast_frame *f = NULL;
|
struct ast_frame *f = NULL;
|
||||||
#if 0 /* We need to have some sort of read-only lock */
|
|
||||||
ast_mutex_lock(&listlock);
|
AST_LIST_LOCK(&imagers);
|
||||||
#endif
|
AST_LIST_TRAVERSE(&imagers, i, list) {
|
||||||
i = list;
|
|
||||||
while(!found && i) {
|
|
||||||
if (i->format & format) {
|
if (i->format & format) {
|
||||||
char *stringp=NULL;
|
char *stringp=NULL;
|
||||||
strncpy(tmp, i->exts, sizeof(tmp)-1);
|
strncpy(tmp, i->exts, sizeof(tmp)-1);
|
||||||
@@ -149,8 +141,10 @@ struct ast_frame *ast_read_image(char *filename, char *preflang, int format)
|
|||||||
e = strsep(&stringp, "|");
|
e = strsep(&stringp, "|");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
i = i->next;
|
if (found)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
fd = open(buf, O_RDONLY);
|
fd = open(buf, O_RDONLY);
|
||||||
if (fd > -1) {
|
if (fd > -1) {
|
||||||
@@ -165,9 +159,9 @@ struct ast_frame *ast_read_image(char *filename, char *preflang, int format)
|
|||||||
ast_log(LOG_WARNING, "Unable to open '%s': %s\n", buf, strerror(errno));
|
ast_log(LOG_WARNING, "Unable to open '%s': %s\n", buf, strerror(errno));
|
||||||
} else
|
} else
|
||||||
ast_log(LOG_WARNING, "Image file '%s' not found\n", filename);
|
ast_log(LOG_WARNING, "Image file '%s' not found\n", filename);
|
||||||
#if 0
|
|
||||||
ast_mutex_unlock(&listlock);
|
AST_LIST_UNLOCK(&imagers);
|
||||||
#endif
|
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,11 +188,8 @@ static int show_image_formats(int fd, int argc, char *argv[])
|
|||||||
if (argc != 3)
|
if (argc != 3)
|
||||||
return RESULT_SHOWUSAGE;
|
return RESULT_SHOWUSAGE;
|
||||||
ast_cli(fd, FORMAT, "Name", "Extensions", "Description", "Format");
|
ast_cli(fd, FORMAT, "Name", "Extensions", "Description", "Format");
|
||||||
i = list;
|
AST_LIST_TRAVERSE(&imagers, i, list)
|
||||||
while(i) {
|
|
||||||
ast_cli(fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format));
|
ast_cli(fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format));
|
||||||
i = i->next;
|
|
||||||
};
|
|
||||||
return RESULT_SUCCESS;
|
return RESULT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -40,7 +40,7 @@ struct ast_imager {
|
|||||||
/*! Returns length written */
|
/*! Returns length written */
|
||||||
int (*write_image)(int fd, struct ast_frame *frame);
|
int (*write_image)(int fd, struct ast_frame *frame);
|
||||||
/*! For linked list */
|
/*! For linked list */
|
||||||
struct ast_imager *next;
|
AST_LIST_ENTRY(ast_imager) list;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*! Check for image support on a channel */
|
/*! Check for image support on a channel */
|
||||||
|
Reference in New Issue
Block a user