Image Management. More...
#include "asterisk.h"
#include <sys/time.h>
#include <sys/stat.h>
#include <signal.h>
#include "asterisk/paths.h"
#include "asterisk/sched.h"
#include "asterisk/channel.h"
#include "asterisk/file.h"
#include "asterisk/image.h"
#include "asterisk/translate.h"
#include "asterisk/cli.h"
#include "asterisk/lock.h"
Go to the source code of this file.
Data Structures | |
struct | imagers |
Defines | |
#define | FORMAT "%10s %10s %50s %10s\n" |
#define | FORMAT2 "%10s %10s %50s %10s\n" |
Functions | |
static void | __fini_imagers (void) |
static void | __init_imagers (void) |
int | ast_image_init (void) |
Initialize image stuff Initializes all the various image stuff. Basically just registers the cli stuff. | |
int | ast_image_register (struct ast_imager *img) |
Register image format. | |
void | ast_image_unregister (struct ast_imager *img) |
Unregister an image format. | |
struct ast_frame * | ast_read_image (char *filename, const char *preflang, int format) |
Make an image. | |
int | ast_send_image (struct ast_channel *chan, char *filename) |
Sends an image. | |
int | ast_supports_images (struct ast_channel *chan) |
Check for image support on a channel. | |
static int | file_exists (char *filename) |
static char * | handle_core_show_image_formats (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
static void | make_filename (char *buf, int len, char *filename, const char *preflang, char *ext) |
Variables | |
struct ast_cli_entry | cli_image [] |
static struct imagers | imagers |
Image Management.
Definition in file image.c.
#define FORMAT "%10s %10s %50s %10s\n" |
#define FORMAT2 "%10s %10s %50s %10s\n" |
int ast_image_init | ( | void | ) |
Initialize image stuff Initializes all the various image stuff. Basically just registers the cli stuff.
Definition at line 204 of file image.c.
References ARRAY_LEN, and ast_cli_register_multiple().
Referenced by main().
{ ast_cli_register_multiple(cli_image, ARRAY_LEN(cli_image)); return 0; }
int ast_image_register | ( | struct ast_imager * | imgdrv | ) |
Register image format.
imgdrv | Populated ast_imager structure with info to register Registers an image format |
Definition at line 46 of file image.c.
References AST_RWLIST_INSERT_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, ast_imager::desc, and ast_imager::name.
Referenced by load_module().
{ AST_RWLIST_WRLOCK(&imagers); AST_RWLIST_INSERT_HEAD(&imagers, img, list); AST_RWLIST_UNLOCK(&imagers); ast_verb(2, "Registered format '%s' (%s)\n", img->name, img->desc); return 0; }
void ast_image_unregister | ( | struct ast_imager * | imgdrv | ) |
Unregister an image format.
imgdrv | pointer to the ast_imager structure you wish to unregister Unregisters the image format passed in. Returns nothing |
Definition at line 55 of file image.c.
References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, ast_imager::desc, and ast_imager::name.
Referenced by unload_module().
{ AST_RWLIST_WRLOCK(&imagers); img = AST_RWLIST_REMOVE(&imagers, img, list); AST_RWLIST_UNLOCK(&imagers); if (img) ast_verb(2, "Unregistered format '%s' (%s)\n", img->name, img->desc); }
struct ast_frame* ast_read_image | ( | char * | filename, |
const char * | preflang, | ||
int | format | ||
) | [read] |
Make an image.
filename | filename of image to prepare |
preflang | preferred language to get the image...? |
format | the format of the file Make an image from a filename ??? No estoy positivo |
an | ast_frame on success |
NULL | on failure |
Definition at line 99 of file image.c.
References ast_copy_string(), ast_log(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, buf, errno, ast_imager::exts, f, file_exists(), ast_imager::format, ast_imager::identify, len(), LOG_WARNING, make_filename(), ast_imager::name, ast_imager::read_image, and strsep().
Referenced by ast_send_image().
{ struct ast_imager *i; char buf[256]; char tmp[80]; char *e; struct ast_imager *found = NULL; int fd; int len=0; struct ast_frame *f = NULL; AST_RWLIST_RDLOCK(&imagers); AST_RWLIST_TRAVERSE(&imagers, i, list) { if (i->format & format) { char *stringp=NULL; ast_copy_string(tmp, i->exts, sizeof(tmp)); stringp = tmp; e = strsep(&stringp, "|"); while (e) { make_filename(buf, sizeof(buf), filename, preflang, e); if ((len = file_exists(buf))) { found = i; break; } make_filename(buf, sizeof(buf), filename, NULL, e); if ((len = file_exists(buf))) { found = i; break; } e = strsep(&stringp, "|"); } } if (found) break; } if (found) { fd = open(buf, O_RDONLY); if (fd > -1) { if (!found->identify || found->identify(fd)) { /* Reset file pointer */ lseek(fd, 0, SEEK_SET); f = found->read_image(fd, len); } else ast_log(LOG_WARNING, "%s does not appear to be a %s file\n", buf, found->name); close(fd); } else ast_log(LOG_WARNING, "Unable to open '%s': %s\n", buf, strerror(errno)); } else ast_log(LOG_WARNING, "Image file '%s' not found\n", filename); AST_RWLIST_UNLOCK(&imagers); return f; }
int ast_send_image | ( | struct ast_channel * | chan, |
char * | filename | ||
) |
Sends an image.
chan | channel to send image on |
filename | filename of image to send (minus extension) Sends an image on the given channel. |
0 | on success |
-1 | on error |
Definition at line 155 of file image.c.
References ast_frfree, ast_read_image(), f, ast_channel::language, ast_channel_tech::send_image, and ast_channel::tech.
Referenced by handle_sendimage(), and sendimage_exec().
{ struct ast_frame *f; int res = -1; if (chan->tech->send_image) { f = ast_read_image(filename, chan->language, -1); if (f) { res = chan->tech->send_image(chan, f); ast_frfree(f); } } return res; }
int ast_supports_images | ( | struct ast_channel * | chan | ) |
Check for image support on a channel.
chan | channel to check Checks the channel to see if it supports the transmission of images |
Definition at line 65 of file image.c.
References ast_channel_tech::send_image, and ast_channel::tech.
Referenced by sendimage_exec().
{ if (!chan || !chan->tech) return 0; if (!chan->tech->send_image) return 0; return 1; }
static int file_exists | ( | char * | filename | ) | [static] |
Definition at line 74 of file image.c.
Referenced by ast_read_image().
{ int res; struct stat st; res = stat(filename, &st); if (!res) return st.st_size; return 0; }
static char* handle_core_show_image_formats | ( | struct ast_cli_entry * | e, |
int | cmd, | ||
struct ast_cli_args * | a | ||
) | [static] |
Definition at line 169 of file image.c.
References ast_cli_args::argc, ast_cli(), ast_getformatname(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_imager::desc, ast_imager::exts, ast_cli_args::fd, ast_imager::format, FORMAT, FORMAT2, ast_imager::list, ast_imager::name, and ast_cli_entry::usage.
{ #define FORMAT "%10s %10s %50s %10s\n" #define FORMAT2 "%10s %10s %50s %10s\n" struct ast_imager *i; int count_fmt = 0; switch (cmd) { case CLI_INIT: e->command = "core show image formats"; e->usage = "Usage: core show image formats\n" " Displays currently registered image formats (if any).\n"; return NULL; case CLI_GENERATE: return NULL; } if (a->argc != 4) return CLI_SHOWUSAGE; ast_cli(a->fd, FORMAT, "Name", "Extensions", "Description", "Format"); ast_cli(a->fd, FORMAT, "----", "----------", "-----------", "------"); AST_RWLIST_RDLOCK(&imagers); AST_RWLIST_TRAVERSE(&imagers, i, list) { ast_cli(a->fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format)); count_fmt++; } AST_RWLIST_UNLOCK(&imagers); ast_cli(a->fd, "\n%d image format%s registered.\n", count_fmt, count_fmt == 1 ? "" : "s"); return CLI_SUCCESS; }
static void make_filename | ( | char * | buf, |
int | len, | ||
char * | filename, | ||
const char * | preflang, | ||
char * | ext | ||
) | [static] |
Definition at line 84 of file image.c.
References ast_config_AST_DATA_DIR, and ast_strlen_zero().
Referenced by ast_read_image().
{ if (filename[0] == '/') { if (!ast_strlen_zero(preflang)) snprintf(buf, len, "%s-%s.%s", filename, preflang, ext); else snprintf(buf, len, "%s.%s", filename, ext); } else { if (!ast_strlen_zero(preflang)) snprintf(buf, len, "%s/%s/%s-%s.%s", ast_config_AST_DATA_DIR, "images", filename, preflang, ext); else snprintf(buf, len, "%s/%s/%s.%s", ast_config_AST_DATA_DIR, "images", filename, ext); } }
struct ast_cli_entry cli_image[] |
{ AST_CLI_DEFINE(handle_core_show_image_formats, "Displays image formats") }