Asterisk.org: Developer Documentation (28 Oct 2009)

Wed Oct 28 15:49:00 2009

## Asterisk developer's documentation

# image.c File Reference

Image Management. More...

`#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)
struct 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
struct ast_cli_entry | show_images

## Detailed Description

Image Management.

Definition in file image.c.

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

References ast_cli_register().

Referenced by main().

    00215 {
    00216    ast_cli_register(&show_images);
    00217    return 0;
    00218 }

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

References ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), ast_imager::desc, 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 | ) |

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

References ast_mutex_lock(), ast_mutex_unlock(), ast_verbose(), ast_imager::desc, 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 |
| ) |  |  | `[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 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, 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 |
| ) |  |  |

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

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 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_VAR_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_VAR_DIR, "images", filename, preflang, ext);
    00112       else
    00113          snprintf(buf, len, "%s/%s/%s.%s", ast_config_AST_VAR_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, 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 }

## Variable Documentation

struct ast_imager* list`[static]`

Definition at line 48 of file image.c.

Referenced by __ast_device_state_changed_literal(), add_sip_domain(), app_exec(), ast_add_hint(), ast_app_group_discard(), ast_app_group_get_count(), ast_app_group_match_get_count(), ast_app_group_set_channel(), ast_app_group_update(), ast_cdr_register(), ast_cdr_unregister(), ast_change_hint(), ast_devstate_add(), ast_devstate_del(), ast_extension_state_add(), ast_extension_state_del(), ast_register_file_version(), ast_register_verbose(), ast_remove_hint(), ast_unregister_file_version(), ast_verbose(), ast_verbose_dmesg(), check_sip_domain(), clear_sip_domains(), close_logger(), complete_show_version_files(), do_devstate_changes(), do_state_change(), gen_nextfile(), gen_readframe(), getSearchPath(), group_function_read(), group_list_function_read(), group_show_channels(), handle_cli_status(), handle_show_version_files(), post_cdr(), and sip_show_domains().

struct ast_cli_entry show_images

Definition at line 204 of file image.c.