Wed Oct 28 11:52:43 2009

Asterisk developer's documentation


image.c File Reference

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"

Include dependency graph for image.c:

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_frameast_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 []


Detailed Description

Image Management.

Author:
Mark Spencer <markster@digium.com>

Definition in file image.c.


Define Documentation

#define FORMAT   "%10s %10s %50s %10s\n"

#define FORMAT2   "%10s %10s %50s %10s\n"


Function Documentation

static void __fini_imagers ( void   )  [static]

Definition at line 44 of file image.c.

00047 {

static void __init_imagers ( void   )  [static]

Definition at line 44 of file image.c.

00047 {

int ast_image_init ( void   ) 

Initialize image stuff Initializes all the various image stuff. Basically just registers the cli stuff.

Returns:
0 all the time

Definition at line 204 of file image.c.

References ARRAY_LEN, and ast_cli_register_multiple().

Referenced by main().

00205 {
00206    ast_cli_register_multiple(cli_image, ARRAY_LEN(cli_image));
00207    return 0;
00208 }

int ast_image_register ( struct ast_imager imgdrv  ) 

Register image format.

Parameters:
imgdrv Populated ast_imager structure with info to register Registers an image format
Returns:
0 regardless

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().

00047 {
00048    AST_RWLIST_WRLOCK(&imagers);
00049    AST_RWLIST_INSERT_HEAD(&imagers, img, list);
00050    AST_RWLIST_UNLOCK(&imagers);
00051    ast_verb(2, "Registered format '%s' (%s)\n", img->name, img->desc);
00052    return 0;
00053 }

void ast_image_unregister ( struct ast_imager imgdrv  ) 

Unregister an image format.

Parameters:
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().

00056 {
00057    AST_RWLIST_WRLOCK(&imagers);
00058    img = AST_RWLIST_REMOVE(&imagers, img, list);
00059    AST_RWLIST_UNLOCK(&imagers);
00060 
00061    if (img)
00062       ast_verb(2, "Unregistered format '%s' (%s)\n", img->name, img->desc);
00063 }

struct ast_frame* ast_read_image ( char *  filename,
const char *  preflang,
int  format 
) [read]

Make an image.

Parameters:
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
Return values:
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().

00100 {
00101    struct ast_imager *i;
00102    char buf[256];
00103    char tmp[80];
00104    char *e;
00105    struct ast_imager *found = NULL;
00106    int fd;
00107    int len=0;
00108    struct ast_frame *f = NULL;
00109    
00110    AST_RWLIST_RDLOCK(&imagers);
00111    AST_RWLIST_TRAVERSE(&imagers, i, list) {
00112       if (i->format & format) {
00113          char *stringp=NULL;
00114          ast_copy_string(tmp, i->exts, sizeof(tmp));
00115          stringp = tmp;
00116          e = strsep(&stringp, "|");
00117          while (e) {
00118             make_filename(buf, sizeof(buf), filename, preflang, e);
00119             if ((len = file_exists(buf))) {
00120                found = i;
00121                break;
00122             }
00123             make_filename(buf, sizeof(buf), filename, NULL, e);
00124             if ((len = file_exists(buf))) {
00125                found = i;
00126                break;
00127             }
00128             e = strsep(&stringp, "|");
00129          }
00130       }
00131       if (found)
00132          break;   
00133    }
00134 
00135    if (found) {
00136       fd = open(buf, O_RDONLY);
00137       if (fd > -1) {
00138          if (!found->identify || found->identify(fd)) {
00139             /* Reset file pointer */
00140             lseek(fd, 0, SEEK_SET);
00141             f = found->read_image(fd, len); 
00142          } else
00143             ast_log(LOG_WARNING, "%s does not appear to be a %s file\n", buf, found->name);
00144          close(fd);
00145       } else
00146          ast_log(LOG_WARNING, "Unable to open '%s': %s\n", buf, strerror(errno));
00147    } else
00148       ast_log(LOG_WARNING, "Image file '%s' not found\n", filename);
00149    
00150    AST_RWLIST_UNLOCK(&imagers);
00151    
00152    return f;
00153 }

int ast_send_image ( struct ast_channel chan,
char *  filename 
)

Sends an image.

Parameters:
chan channel to send image on
filename filename of image to send (minus extension) Sends an image on the given channel.
Return values:
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().

00156 {
00157    struct ast_frame *f;
00158    int res = -1;
00159    if (chan->tech->send_image) {
00160       f = ast_read_image(filename, chan->language, -1);
00161       if (f) {
00162          res = chan->tech->send_image(chan, f);
00163          ast_frfree(f);
00164       }
00165    }
00166    return res;
00167 }

int ast_supports_images ( struct ast_channel chan  ) 

Check for image support on a channel.

Parameters:
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 65 of file image.c.

References ast_channel_tech::send_image, and ast_channel::tech.

Referenced by sendimage_exec().

00066 {
00067    if (!chan || !chan->tech)
00068       return 0;
00069    if (!chan->tech->send_image)
00070       return 0;
00071    return 1;
00072 }

static int file_exists ( char *  filename  )  [static]

Definition at line 74 of file image.c.

Referenced by ast_read_image().

00075 {
00076    int res;
00077    struct stat st;
00078    res = stat(filename, &st);
00079    if (!res)
00080       return st.st_size;
00081    return 0;
00082 }

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::name, and ast_cli_entry::usage.

00170 {
00171 #define FORMAT "%10s %10s %50s %10s\n"
00172 #define FORMAT2 "%10s %10s %50s %10s\n"
00173    struct ast_imager *i;
00174    int count_fmt = 0;
00175 
00176    switch (cmd) {
00177    case CLI_INIT:
00178       e->command = "core show image formats";
00179       e->usage =
00180          "Usage: core show image formats\n"
00181          "       Displays currently registered image formats (if any).\n";
00182       return NULL;
00183    case CLI_GENERATE:
00184       return NULL;
00185    }
00186    if (a->argc != 4)
00187       return CLI_SHOWUSAGE;
00188    ast_cli(a->fd, FORMAT, "Name", "Extensions", "Description", "Format");
00189    ast_cli(a->fd, FORMAT, "----", "----------", "-----------", "------");
00190    AST_RWLIST_RDLOCK(&imagers);
00191    AST_RWLIST_TRAVERSE(&imagers, i, list) {
00192       ast_cli(a->fd, FORMAT2, i->name, i->exts, i->desc, ast_getformatname(i->format));
00193       count_fmt++;
00194    }
00195    AST_RWLIST_UNLOCK(&imagers);
00196    ast_cli(a->fd, "\n%d image format%s registered.\n", count_fmt, count_fmt == 1 ? "" : "s");
00197    return CLI_SUCCESS;
00198 }

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().

00085 {
00086    if (filename[0] == '/') {
00087       if (!ast_strlen_zero(preflang))
00088          snprintf(buf, len, "%s-%s.%s", filename, preflang, ext);
00089       else
00090          snprintf(buf, len, "%s.%s", filename, ext);
00091    } else {
00092       if (!ast_strlen_zero(preflang))
00093          snprintf(buf, len, "%s/%s/%s-%s.%s", ast_config_AST_DATA_DIR, "images", filename, preflang, ext);
00094       else
00095          snprintf(buf, len, "%s/%s/%s.%s", ast_config_AST_DATA_DIR, "images", filename, ext);
00096    }
00097 }


Variable Documentation

Initial value:

 {
   AST_CLI_DEFINE(handle_core_show_image_formats, "Displays image formats")
}

Definition at line 200 of file image.c.


Generated on Wed Oct 28 11:52:44 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6