#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.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"
Include dependency graph for image.c:
Go to the source code of this file.
Defines | |
#define | FORMAT "%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_MUTEX_DEFINE_STATIC (listlock) | |
ast_frame * | ast_read_image (char *filename, 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, char *preflang, char *ext) |
static int | show_image_formats (int fd, int argc, char *argv[]) |
Variables | |
static struct ast_imager * | list |
ast_cli_entry | show_images |
Definition in file image.c.
#define FORMAT "%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 214 of file image.c.
References ast_cli_register(), and show_images.
Referenced by main().
00215 { 00216 ast_cli_register(&show_images); 00217 return 0; 00218 }
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 51 of file image.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), ast_imager::desc, list, ast_imager::name, ast_imager::next, option_verbose, and VERBOSE_PREFIX_2.
Referenced by load_module().
00052 { 00053 if (option_verbose > 1) 00054 ast_verbose(VERBOSE_PREFIX_2 "Registered format '%s' (%s)\n", img->name, img->desc); 00055 ast_mutex_lock(&listlock); 00056 img->next = list; 00057 list = img; 00058 ast_mutex_unlock(&listlock); 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_mutex_lock(), ast_mutex_unlock(), ast_verbose(), ast_imager::desc, list, ast_imager::name, ast_imager::next, option_verbose, and VERBOSE_PREFIX_2.
Referenced by unload_module().
00063 { 00064 struct ast_imager *i, *prev = NULL; 00065 ast_mutex_lock(&listlock); 00066 i = list; 00067 while(i) { 00068 if (i == img) { 00069 if (prev) 00070 prev->next = i->next; 00071 else 00072 list = i->next; 00073 break; 00074 } 00075 prev = i; 00076 i = i->next; 00077 } 00078 ast_mutex_unlock(&listlock); 00079 if (i && (option_verbose > 1)) 00080 ast_verbose(VERBOSE_PREFIX_2 "Unregistered format '%s' (%s)\n", img->name, img->desc); 00081 }
AST_MUTEX_DEFINE_STATIC | ( | listlock | ) |
struct ast_frame* ast_read_image | ( | char * | filename, | |
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 117 of file image.c.
References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_imager::exts, file_exists(), ast_imager::format, ast_imager::identify, list, LOG_WARNING, make_filename(), ast_imager::name, ast_imager::next, ast_imager::read_image, and strsep().
Referenced by ast_send_image().
00118 { 00119 struct ast_imager *i; 00120 char buf[256]; 00121 char tmp[80]; 00122 char *e; 00123 struct ast_imager *found = NULL; 00124 int fd; 00125 int len=0; 00126 struct ast_frame *f = NULL; 00127 #if 0 /* We need to have some sort of read-only lock */ 00128 ast_mutex_lock(&listlock); 00129 #endif 00130 i = list; 00131 while(!found && i) { 00132 if (i->format & format) { 00133 char *stringp=NULL; 00134 strncpy(tmp, i->exts, sizeof(tmp)-1); 00135 stringp=tmp; 00136 e = strsep(&stringp, "|"); 00137 while(e) { 00138 make_filename(buf, sizeof(buf), filename, preflang, e); 00139 if ((len = file_exists(buf))) { 00140 found = i; 00141 break; 00142 } 00143 make_filename(buf, sizeof(buf), filename, NULL, e); 00144 if ((len = file_exists(buf))) { 00145 found = i; 00146 break; 00147 } 00148 e = strsep(&stringp, "|"); 00149 } 00150 } 00151 i = i->next; 00152 } 00153 if (found) { 00154 fd = open(buf, O_RDONLY); 00155 if (fd > -1) { 00156 if (!found->identify || found->identify(fd)) { 00157 /* Reset file pointer */ 00158 lseek(fd, 0, SEEK_SET); 00159 f = found->read_image(fd,len); 00160 } else 00161 ast_log(LOG_WARNING, "%s does not appear to be a %s file\n", buf, found->name); 00162 close(fd); 00163 } else 00164 ast_log(LOG_WARNING, "Unable to open '%s': %s\n", buf, strerror(errno)); 00165 } else 00166 ast_log(LOG_WARNING, "Image file '%s' not found\n", filename); 00167 #if 0 00168 ast_mutex_unlock(&listlock); 00169 #endif 00170 return f; 00171 }
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 174 of file image.c.
References ast_frfree(), ast_read_image(), ast_channel::language, ast_channel_tech::send_image, and ast_channel::tech.
Referenced by handle_sendimage(), and sendimage_exec().
00175 { 00176 struct ast_frame *f; 00177 int res = -1; 00178 if (chan->tech->send_image) { 00179 f = ast_read_image(filename, chan->language, -1); 00180 if (f) { 00181 res = chan->tech->send_image(chan, f); 00182 ast_frfree(f); 00183 } 00184 } 00185 return res; 00186 }
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 83 of file image.c.
References ast_channel_tech::send_image, and ast_channel::tech.
Referenced by sendimage_exec().
00084 { 00085 if (!chan || !chan->tech) 00086 return 0; 00087 if (!chan->tech->send_image) 00088 return 0; 00089 return 1; 00090 }
static int file_exists | ( | char * | filename | ) | [static] |
Definition at line 92 of file image.c.
Referenced by ast_read_image().
00093 { 00094 int res; 00095 struct stat st; 00096 res = stat(filename, &st); 00097 if (!res) 00098 return st.st_size; 00099 return 0; 00100 }
static void make_filename | ( | char * | buf, | |
int | len, | |||
char * | filename, | |||
char * | preflang, | |||
char * | ext | |||
) | [static] |
Definition at line 102 of file image.c.
References ast_config_AST_DATA_DIR.
Referenced by ast_read_image().
00103 { 00104 if (filename[0] == '/') { 00105 if (preflang && strlen(preflang)) 00106 snprintf(buf, len, "%s-%s.%s", filename, preflang, ext); 00107 else 00108 snprintf(buf, len, "%s.%s", filename, ext); 00109 } else { 00110 if (preflang && strlen(preflang)) 00111 snprintf(buf, len, "%s/%s/%s-%s.%s", ast_config_AST_DATA_DIR, "images", filename, preflang, ext); 00112 else 00113 snprintf(buf, len, "%s/%s/%s.%s", ast_config_AST_DATA_DIR, "images", filename, ext); 00114 } 00115 }
static int show_image_formats | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 188 of file image.c.
References ast_cli(), ast_getformatname(), ast_imager::desc, ast_imager::exts, ast_imager::format, FORMAT, FORMAT2, list, ast_imager::name, ast_imager::next, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00189 { 00190 #define FORMAT "%10s %10s %50s %10s\n" 00191 #define FORMAT2 "%10s %10s %50s %10s\n" 00192 struct ast_imager *i; 00193 if (argc != 3) 00194 return RESULT_SHOWUSAGE; 00195 ast_cli(fd, FORMAT, "Name", "Extensions", "Description", "Format"); 00196 i = list; 00197 while(i) { 00198 ast_cli(fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format)); 00199 i = i->next; 00200 }; 00201 return RESULT_SUCCESS; 00202 }
struct ast_imager* list [static] |
Definition at line 48 of file image.c.
Referenced by __ast_device_state_changed_literal(), acf_odbc_read(), acf_odbc_write(), add_sip_domain(), add_to_interfaces(), app_exec(), ast_add_hint(), ast_cdr_register(), ast_cdr_unregister(), ast_change_hint(), ast_channel_spy_add(), ast_channel_spy_remove(), ast_channel_spy_stop_by_type(), ast_devstate_add(), ast_devstate_del(), ast_dnsmgr_get(), ast_dnsmgr_release(), ast_do_masquerade(), ast_extension_state_add(), ast_extension_state_del(), ast_image_register(), ast_image_unregister(), ast_merge_contexts_and_delete(), ast_netsock_bind(), ast_netsock_bindaddr(), ast_netsock_find(), ast_netsock_init(), ast_netsock_release(), ast_read_image(), ast_register_file_version(), ast_register_translator(), ast_register_verbose(), ast_remove_hint(), ast_unregister_file_version(), ast_unregister_translator(), ast_verbose(), ast_verbose_dmesg(), changethread(), check_sip_domain(), cl_dequeue_chan(), cl_queue_chan(), clear_and_free_interfaces(), clear_sip_domains(), close_logger(), complete_show_version_files(), detach_spies(), do_devstate_changes(), do_state_change(), find_chan_by_bc(), find_chan_by_pid(), find_holded(), gen_nextfile(), gen_readframe(), getSearchPath(), handle_cli_status(), handle_show_version_files(), odbc_load_module(), odbc_unload_module(), post_cdr(), queue_frame_to_spies(), rebuild_matrix(), refresh_list(), reload(), remove_from_interfaces(), show_image_formats(), and sip_show_domains().
struct ast_cli_entry show_images |