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 | |
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 (const char *filename, const char *preflang, int format) |
Make an image. | |
int | ast_send_image (struct ast_channel *chan, const 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 | image_shutdown (void) |
static void | make_filename (char *buf, int len, const char *filename, const char *preflang, char *ext) |
Variables | |
static struct ast_cli_entry | cli_image [] |
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 213 of file image.c.
References ARRAY_LEN, ast_cli_register_multiple(), ast_register_atexit(), and image_shutdown().
Referenced by main().
00214 { 00215 ast_cli_register_multiple(cli_image, ARRAY_LEN(cli_image)); 00216 ast_register_atexit(image_shutdown); 00217 return 0; 00218 }
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 50 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().
00051 { 00052 AST_RWLIST_WRLOCK(&imagers); 00053 AST_RWLIST_INSERT_HEAD(&imagers, img, list); 00054 AST_RWLIST_UNLOCK(&imagers); 00055 ast_verb(2, "Registered format '%s' (%s)\n", img->name, img->desc); 00056 return 0; 00057 }
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 59 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().
00060 { 00061 AST_RWLIST_WRLOCK(&imagers); 00062 img = AST_RWLIST_REMOVE(&imagers, img, list); 00063 AST_RWLIST_UNLOCK(&imagers); 00064 00065 if (img) 00066 ast_verb(2, "Unregistered format '%s' (%s)\n", img->name, img->desc); 00067 }
struct ast_frame* ast_read_image | ( | const 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 103 of file image.c.
References ast_copy_string(), ast_log(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, errno, ast_imager::exts, f, file_exists(), ast_imager::format, ast_imager::identify, len(), LOG_WARNING, make_filename(), ast_imager::name, and ast_imager::read_image.
Referenced by ast_send_image().
00104 { 00105 struct ast_imager *i; 00106 char buf[256]; 00107 char tmp[80]; 00108 char *e; 00109 struct ast_imager *found = NULL; 00110 int fd; 00111 int len=0; 00112 struct ast_frame *f = NULL; 00113 00114 AST_RWLIST_RDLOCK(&imagers); 00115 AST_RWLIST_TRAVERSE(&imagers, i, list) { 00116 if (i->format & format) { 00117 char *stringp=NULL; 00118 ast_copy_string(tmp, i->exts, sizeof(tmp)); 00119 stringp = tmp; 00120 e = strsep(&stringp, "|"); 00121 while (e) { 00122 make_filename(buf, sizeof(buf), filename, preflang, e); 00123 if ((len = file_exists(buf))) { 00124 found = i; 00125 break; 00126 } 00127 make_filename(buf, sizeof(buf), filename, NULL, e); 00128 if ((len = file_exists(buf))) { 00129 found = i; 00130 break; 00131 } 00132 e = strsep(&stringp, "|"); 00133 } 00134 } 00135 if (found) 00136 break; 00137 } 00138 00139 if (found) { 00140 fd = open(buf, O_RDONLY); 00141 if (fd > -1) { 00142 if (!found->identify || found->identify(fd)) { 00143 /* Reset file pointer */ 00144 lseek(fd, 0, SEEK_SET); 00145 f = found->read_image(fd, len); 00146 } else 00147 ast_log(LOG_WARNING, "%s does not appear to be a %s file\n", buf, found->name); 00148 close(fd); 00149 } else 00150 ast_log(LOG_WARNING, "Unable to open '%s': %s\n", buf, strerror(errno)); 00151 } else 00152 ast_log(LOG_WARNING, "Image file '%s' not found\n", filename); 00153 00154 AST_RWLIST_UNLOCK(&imagers); 00155 00156 return f; 00157 }
int ast_send_image | ( | struct ast_channel * | chan, | |
const 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 159 of file image.c.
References ast_frfree, ast_read_image(), f, ast_channel_tech::send_image, and ast_channel::tech.
Referenced by handle_sendimage(), and sendimage_exec().
00160 { 00161 struct ast_frame *f; 00162 int res = -1; 00163 if (chan->tech->send_image) { 00164 f = ast_read_image(filename, chan->language, -1); 00165 if (f) { 00166 res = chan->tech->send_image(chan, f); 00167 ast_frfree(f); 00168 } 00169 } 00170 return res; 00171 }
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 69 of file image.c.
References ast_channel_tech::send_image, and ast_channel::tech.
Referenced by sendimage_exec().
00070 { 00071 if (!chan || !chan->tech) 00072 return 0; 00073 if (!chan->tech->send_image) 00074 return 0; 00075 return 1; 00076 }
static int file_exists | ( | char * | filename | ) | [static] |
Definition at line 78 of file image.c.
Referenced by ast_read_image().
static char* handle_core_show_image_formats | ( | struct ast_cli_entry * | e, | |
int | cmd, | |||
struct ast_cli_args * | a | |||
) | [static] |
Definition at line 173 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::name, and ast_cli_entry::usage.
00174 { 00175 #define FORMAT "%10s %10s %50s %10s\n" 00176 #define FORMAT2 "%10s %10s %50s %10s\n" 00177 struct ast_imager *i; 00178 int count_fmt = 0; 00179 00180 switch (cmd) { 00181 case CLI_INIT: 00182 e->command = "core show image formats"; 00183 e->usage = 00184 "Usage: core show image formats\n" 00185 " Displays currently registered image formats (if any).\n"; 00186 return NULL; 00187 case CLI_GENERATE: 00188 return NULL; 00189 } 00190 if (a->argc != 4) 00191 return CLI_SHOWUSAGE; 00192 ast_cli(a->fd, FORMAT, "Name", "Extensions", "Description", "Format"); 00193 ast_cli(a->fd, FORMAT, "----", "----------", "-----------", "------"); 00194 AST_RWLIST_RDLOCK(&imagers); 00195 AST_RWLIST_TRAVERSE(&imagers, i, list) { 00196 ast_cli(a->fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format)); 00197 count_fmt++; 00198 } 00199 AST_RWLIST_UNLOCK(&imagers); 00200 ast_cli(a->fd, "\n%d image format%s registered.\n", count_fmt, count_fmt == 1 ? "" : "s"); 00201 return CLI_SUCCESS; 00202 }
static void image_shutdown | ( | void | ) | [static] |
Definition at line 208 of file image.c.
References ARRAY_LEN, and ast_cli_unregister_multiple().
Referenced by ast_image_init().
00209 { 00210 ast_cli_unregister_multiple(cli_image, ARRAY_LEN(cli_image)); 00211 }
static void make_filename | ( | char * | buf, | |
int | len, | |||
const char * | filename, | |||
const char * | preflang, | |||
char * | ext | |||
) | [static] |
Definition at line 88 of file image.c.
References ast_config_AST_DATA_DIR, and ast_strlen_zero().
Referenced by ast_read_image().
00089 { 00090 if (filename[0] == '/') { 00091 if (!ast_strlen_zero(preflang)) 00092 snprintf(buf, len, "%s-%s.%s", filename, preflang, ext); 00093 else 00094 snprintf(buf, len, "%s.%s", filename, ext); 00095 } else { 00096 if (!ast_strlen_zero(preflang)) 00097 snprintf(buf, len, "%s/%s/%s-%s.%s", ast_config_AST_DATA_DIR, "images", filename, preflang, ext); 00098 else 00099 snprintf(buf, len, "%s/%s/%s.%s", ast_config_AST_DATA_DIR, "images", filename, ext); 00100 } 00101 }
struct ast_cli_entry cli_image[] [static] |
{ AST_CLI_DEFINE(handle_core_show_image_formats, "Displays image formats") }