#include "asterisk.h"
#include <stdio.h>
#include <stdlib.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/logger.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 | FORMAT "%10s %10s %50s %10s\n" |
#define | FORMAT2 "%10s %10s %50s %10s\n" |
#define | FORMAT2 "%10s %10s %50s %10s\n" |
Functions | |
int | ast_image_init (void) |
int | ast_image_register (struct ast_imager *img) |
void | ast_image_unregister (struct ast_imager *img) |
ast_frame * | ast_read_image (char *filename, const char *preflang, int format) |
int | ast_send_image (struct ast_channel *chan, char *filename) |
int | ast_supports_images (struct ast_channel *chan) |
static int | file_exists (char *filename) |
static void | make_filename (char *buf, int len, char *filename, const char *preflang, char *ext) |
static int | show_image_formats (int fd, int argc, char *argv[]) |
static int | show_image_formats_deprecated (int fd, int argc, char *argv[]) |
Variables | |
ast_cli_entry | cli_image [] |
ast_cli_entry | cli_show_image_formats_deprecated |
Definition in file image.c.
#define FORMAT "%10s %10s %50s %10s\n" |
#define FORMAT "%10s %10s %50s %10s\n" |
#define FORMAT2 "%10s %10s %50s %10s\n" |
#define FORMAT2 "%10s %10s %50s %10s\n" |
int ast_image_init | ( | void | ) |
Initializes all the various image stuff. Basically just registers the cli stuff Returns 0 all the time
Definition at line 221 of file image.c.
References ast_cli_register_multiple(), and cli_image.
Referenced by main().
00222 { 00223 ast_cli_register_multiple(cli_image, sizeof(cli_image) / sizeof(struct ast_cli_entry)); 00224 return 0; 00225 }
int ast_image_register | ( | struct ast_imager * | imgdrv | ) |
imgdrv | Populated ast_imager structure with info to register Registers an image format Returns 0 regardless |
Definition at line 52 of file image.c.
References AST_LIST_INSERT_HEAD, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_verbose(), ast_imager::desc, ast_imager::name, option_verbose, and VERBOSE_PREFIX_2.
Referenced by load_module().
00053 { 00054 if (option_verbose > 1) 00055 ast_verbose(VERBOSE_PREFIX_2 "Registered format '%s' (%s)\n", img->name, img->desc); 00056 AST_LIST_LOCK(&imagers); 00057 AST_LIST_INSERT_HEAD(&imagers, img, list); 00058 AST_LIST_UNLOCK(&imagers); 00059 return 0; 00060 }
void ast_image_unregister | ( | struct ast_imager * | imgdrv | ) |
imgdrv | pointer to the ast_imager structure you wish to unregister Unregisters the image format passed in Returns nothing |
Definition at line 62 of file image.c.
References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_verbose(), ast_imager::desc, ast_imager::name, option_verbose, and VERBOSE_PREFIX_2.
Referenced by unload_module().
00063 { 00064 struct ast_imager *i; 00065 00066 AST_LIST_LOCK(&imagers); 00067 AST_LIST_TRAVERSE_SAFE_BEGIN(&imagers, i, list) { 00068 if (i == img) { 00069 AST_LIST_REMOVE_CURRENT(&imagers, list); 00070 break; 00071 } 00072 } 00073 AST_LIST_TRAVERSE_SAFE_END 00074 AST_LIST_UNLOCK(&imagers); 00075 if (i && (option_verbose > 1)) 00076 ast_verbose(VERBOSE_PREFIX_2 "Unregistered format '%s' (%s)\n", img->name, img->desc); 00077 }
struct ast_frame* ast_read_image | ( | char * | filename, | |
const char * | preflang, | |||
int | format | |||
) |
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 Returns an ast_frame on success, NULL on failure |
Definition at line 113 of file image.c.
References ast_copy_string(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_log(), 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().
00114 { 00115 struct ast_imager *i; 00116 char buf[256]; 00117 char tmp[80]; 00118 char *e; 00119 struct ast_imager *found = NULL; 00120 int fd; 00121 int len=0; 00122 struct ast_frame *f = NULL; 00123 00124 AST_LIST_LOCK(&imagers); 00125 AST_LIST_TRAVERSE(&imagers, i, list) { 00126 if (i->format & format) { 00127 char *stringp=NULL; 00128 ast_copy_string(tmp, i->exts, sizeof(tmp)); 00129 stringp=tmp; 00130 e = strsep(&stringp, "|"); 00131 while(e) { 00132 make_filename(buf, sizeof(buf), filename, preflang, e); 00133 if ((len = file_exists(buf))) { 00134 found = i; 00135 break; 00136 } 00137 make_filename(buf, sizeof(buf), filename, NULL, e); 00138 if ((len = file_exists(buf))) { 00139 found = i; 00140 break; 00141 } 00142 e = strsep(&stringp, "|"); 00143 } 00144 } 00145 if (found) 00146 break; 00147 } 00148 00149 if (found) { 00150 fd = open(buf, O_RDONLY); 00151 if (fd > -1) { 00152 if (!found->identify || found->identify(fd)) { 00153 /* Reset file pointer */ 00154 lseek(fd, 0, SEEK_SET); 00155 f = found->read_image(fd,len); 00156 } else 00157 ast_log(LOG_WARNING, "%s does not appear to be a %s file\n", buf, found->name); 00158 close(fd); 00159 } else 00160 ast_log(LOG_WARNING, "Unable to open '%s': %s\n", buf, strerror(errno)); 00161 } else 00162 ast_log(LOG_WARNING, "Image file '%s' not found\n", filename); 00163 00164 AST_LIST_UNLOCK(&imagers); 00165 00166 return f; 00167 }
int ast_send_image | ( | struct ast_channel * | chan, | |
char * | filename | |||
) |
chan | channel to send image on | |
filename | filename of image to send (minus extension) Sends an image on the given channel. Returns 0 on success, -1 on error |
Definition at line 169 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().
00170 { 00171 struct ast_frame *f; 00172 int res = -1; 00173 if (chan->tech->send_image) { 00174 f = ast_read_image(filename, chan->language, -1); 00175 if (f) { 00176 res = chan->tech->send_image(chan, f); 00177 ast_frfree(f); 00178 } 00179 } 00180 return res; 00181 }
int ast_supports_images | ( | struct ast_channel * | chan | ) |
chan | channel to check Checks the channel to see if it supports the transmission of images Returns non-zero if image transmission is supported |
Definition at line 79 of file image.c.
References ast_channel_tech::send_image, and ast_channel::tech.
Referenced by sendimage_exec().
00080 { 00081 if (!chan || !chan->tech) 00082 return 0; 00083 if (!chan->tech->send_image) 00084 return 0; 00085 return 1; 00086 }
static int file_exists | ( | char * | filename | ) | [static] |
Definition at line 88 of file image.c.
Referenced by ast_read_image().
00089 { 00090 int res; 00091 struct stat st; 00092 res = stat(filename, &st); 00093 if (!res) 00094 return st.st_size; 00095 return 0; 00096 }
static void make_filename | ( | char * | buf, | |
int | len, | |||
char * | filename, | |||
const char * | preflang, | |||
char * | ext | |||
) | [static] |
Definition at line 98 of file image.c.
References ast_config_AST_DATA_DIR, and ast_strlen_zero().
Referenced by ast_read_image().
00099 { 00100 if (filename[0] == '/') { 00101 if (!ast_strlen_zero(preflang)) 00102 snprintf(buf, len, "%s-%s.%s", filename, preflang, ext); 00103 else 00104 snprintf(buf, len, "%s.%s", filename, ext); 00105 } else { 00106 if (!ast_strlen_zero(preflang)) 00107 snprintf(buf, len, "%s/%s/%s-%s.%s", ast_config_AST_DATA_DIR, "images", filename, preflang, ext); 00108 else 00109 snprintf(buf, len, "%s/%s/%s.%s", ast_config_AST_DATA_DIR, "images", filename, ext); 00110 } 00111 }
static int show_image_formats | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 196 of file image.c.
References ast_cli(), ast_getformatname(), AST_LIST_TRAVERSE, ast_imager::desc, ast_imager::exts, ast_imager::format, FORMAT, FORMAT2, ast_imager::name, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00197 { 00198 #define FORMAT "%10s %10s %50s %10s\n" 00199 #define FORMAT2 "%10s %10s %50s %10s\n" 00200 struct ast_imager *i; 00201 if (argc != 4) 00202 return RESULT_SHOWUSAGE; 00203 ast_cli(fd, FORMAT, "Name", "Extensions", "Description", "Format"); 00204 AST_LIST_TRAVERSE(&imagers, i, list) 00205 ast_cli(fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format)); 00206 return RESULT_SUCCESS; 00207 }
static int show_image_formats_deprecated | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 183 of file image.c.
References ast_cli(), ast_getformatname(), AST_LIST_TRAVERSE, ast_imager::desc, ast_imager::exts, ast_imager::format, FORMAT, FORMAT2, ast_imager::name, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00184 { 00185 #define FORMAT "%10s %10s %50s %10s\n" 00186 #define FORMAT2 "%10s %10s %50s %10s\n" 00187 struct ast_imager *i; 00188 if (argc != 3) 00189 return RESULT_SHOWUSAGE; 00190 ast_cli(fd, FORMAT, "Name", "Extensions", "Description", "Format"); 00191 AST_LIST_TRAVERSE(&imagers, i, list) 00192 ast_cli(fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format)); 00193 return RESULT_SUCCESS; 00194 }
struct ast_cli_entry cli_image[] |
Initial value:
{ { "show", "image", "formats" }, show_image_formats_deprecated, NULL, NULL }