image.c File Reference

#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/channel_pvt.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 "asterisk.h"
#include "astconf.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

 AST_MUTEX_DEFINE_STATIC (listlock)
int ast_image_register (struct ast_imager *img)
 Register image format.
void ast_image_unregister (struct ast_imager *img)
 Unregister an image format.
int ast_supports_images (struct ast_channel *chan)
 Check for image support on a channel.
struct ast_frameast_read_image (char *filename, char *preflang, int format)
 Make an image.
int ast_send_image (struct ast_channel *chan, char *filename)
 Sends an image.
int ast_image_init (void)
 Initialize image stuff.

Variables

struct ast_cli_entry show_images


Define Documentation

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

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


Function Documentation

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 201 of file image.c.

00202 {
00203    ast_cli_register(&show_images);
00204    return 0;
00205 }

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 38 of file image.c.

00039 {
00040    if (option_verbose > 1)
00041       ast_verbose(VERBOSE_PREFIX_2 "Registered format '%s' (%s)\n", img->name, img->desc);
00042    ast_mutex_lock(&listlock);
00043    img->next = list;
00044    list = img;
00045    ast_mutex_unlock(&listlock);
00046    return 0;
00047 }

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 49 of file image.c.

00050 {
00051    struct ast_imager *i, *prev = NULL;
00052    ast_mutex_lock(&listlock);
00053    i = list;
00054    while(i) {
00055       if (i == img) {
00056          if (prev) 
00057             prev->next = i->next;
00058          else
00059             list = i->next;
00060          break;
00061       }
00062       prev = i;
00063       i = i->next;
00064    }
00065    ast_mutex_unlock(&listlock);
00066    if (i && (option_verbose > 1))
00067       ast_verbose(VERBOSE_PREFIX_2 "Unregistered format '%s' (%s)\n", img->name, img->desc);
00068 }

AST_MUTEX_DEFINE_STATIC ( listlock   ) 

struct ast_frame* ast_read_image ( char *  filename,
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 Returns an ast_frame on success, NULL on failure

Definition at line 104 of file image.c.

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

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. Returns 0 on success, -1 on error

Definition at line 161 of file image.c.

00162 {
00163    struct ast_frame *f;
00164    int res = -1;
00165    if (chan->pvt->send_image) {
00166       f = ast_read_image(filename, chan->language, -1);
00167       if (f) {
00168          res = chan->pvt->send_image(chan, f);
00169          ast_frfree(f);
00170       }
00171    }
00172    return res;
00173 }

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 70 of file image.c.

00071 {
00072    if (!chan || !chan->pvt)
00073       return 0;
00074    if (!chan->pvt->send_image)
00075       return 0;
00076    return 1;
00077 }


Variable Documentation

Definition at line 191 of file image.c.


Generated on Wed Oct 28 17:00:55 2009 for Asterisk by  doxygen 1.5.6