Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:00:59 2007

Asterisk developer's documentation :: Codename Pineapple


app.h File Reference


Detailed Description

Application convenience functions, designed to give consistent look and feel to Asterisk apps.

Definition in file app.h.

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_app_option
 A structure to hold the description of an application 'option'. More...
struct  ast_ivr_menu
struct  ast_ivr_option

Defines

#define AST_APP_ARG(name)   char *name
 Define an application argument.
#define AST_APP_OPTION(option, flagno)   [option] = { .flag = flagno }
 Declares an application option that does not accept an argument.
#define AST_APP_OPTION_ARG(option, flagno, argno)   [option] = { .flag = flagno, .arg_index = argno + 1 }
 Declares an application option that accepts an argument.
#define AST_APP_OPTIONS(holder, options...)   static const struct ast_app_option holder[128] = options
 Declares an array of options for an application.
#define AST_DECLARE_APP_ARGS(name, arglist)
 Declare a structure to hold the application's arguments.
#define AST_IVR_DECLARE_MENU(holder, title, flags, foo...)
#define AST_IVR_FLAG_AUTORESTART   (1 << 0)
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)   args.argc = ast_app_separate_args(parse, sep, args.argv, (sizeof(args) - sizeof(args.argc)) / sizeof(args.argv[0]))
 Performs the 'nonstandard' argument separation process for an application.
#define AST_STANDARD_APP_ARGS(args, parse)   args.argc = ast_app_separate_args(parse, '|', args.argv, (sizeof(args) - sizeof(args.argc)) / sizeof(args.argv[0]))
 Performs the 'standard' argument separation process for an application.
#define GROUP_CATEGORY_PREFIX   "GROUP"

Typedefs

typedef int(* ast_ivr_callback )(struct ast_channel *chan, char *option, void *cbdata)
 Callback function for IVR.

Enumerations

enum  ast_ivr_action {
  AST_ACTION_UPONE, AST_ACTION_EXIT, AST_ACTION_CALLBACK, AST_ACTION_PLAYBACK,
  AST_ACTION_BACKGROUND, AST_ACTION_PLAYLIST, AST_ACTION_MENU, AST_ACTION_REPEAT,
  AST_ACTION_RESTART, AST_ACTION_TRANSFER, AST_ACTION_WAITOPTION, AST_ACTION_NOOP,
  AST_ACTION_BACKLIST
}
enum  AST_LOCK_RESULT { AST_LOCK_SUCCESS = 0, AST_LOCK_TIMEOUT = -1, AST_LOCK_PATH_NOT_FOUND = -2, AST_LOCK_FAILURE = -3 }

Functions

int ast_app_dtget (struct ast_channel *chan, const char *context, char *collect, size_t size, int maxlen, int timeout)
 Present a dialtone and collect a certain length extension.
int ast_app_getdata (struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout)
 Plays a stream and gets DTMF data from a channel.
int ast_app_getdata_full (struct ast_channel *c, char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd)
 Full version with audiofd and controlfd. NOTE: returns '2' on ctrlfd available, not '1' like other full functions.
int ast_app_group_get_count (const char *group, const char *category)
int ast_app_group_match_get_count (const char *groupmatch, const char *category)
int ast_app_group_set_channel (struct ast_channel *chan, const char *data)
int ast_app_group_split_group (const char *data, char *group, int group_max, char *category, int category_max)
int ast_app_has_voicemail (const char *mailbox, const char *folder)
int ast_app_inboxcount (const char *mailbox, int *newmsgs, int *oldmsgs)
int ast_app_messagecount (const char *context, const char *mailbox, const char *folder)
int ast_app_parse_options (const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
 Parses a string containing application options and sets flags/arguments.
unsigned int ast_app_separate_args (char *buf, char delim, char **array, int arraylen)
 Separate a string into arguments in an array.
int ast_control_streamfile (struct ast_channel *chan, const char *file, const char *fwd, const char *rev, const char *stop, const char *pause, const char *restart, int skipms)
int ast_dtmf_stream (struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between)
 Send DTMF to a channel.
void ast_install_vm_functions (int(*has_voicemail_func)(const char *mailbox, const char *folder), int(*inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs), int(*messagecount_func)(const char *context, const char *mailbox, const char *folder))
int ast_ivr_menu_run (struct ast_channel *c, struct ast_ivr_menu *menu, void *cbdata)
 Runs an IVR menu.
int ast_linear_stream (struct ast_channel *chan, const char *filename, int fd, int allowoverride)
enum AST_LOCK_RESULT ast_lock_path (const char *path)
 Lock a filesystem path.
int ast_play_and_prepend (struct ast_channel *chan, char *playfile, char *recordfile, int maxtime_sec, char *fmt, int *duration, int beep, int silencethreshold, int maxsilence_ms)
int ast_play_and_record (struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime_sec, const char *fmt, int *duration, int silencethreshold, int maxsilence_ms, const char *path)
int ast_play_and_record_full (struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime_sec, const char *fmt, int *duration, int silencethreshold, int maxsilence_ms, const char *path, const char *acceptdtmf, const char *canceldtmf)
int ast_play_and_wait (struct ast_channel *chan, const char *fn)
char * ast_read_textfile (const char *file)
int ast_record_review (struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, const char *path)
void ast_replace_sigchld (void)
 Replace the SIGCHLD handler.
int ast_safe_system (const char *s)
void ast_uninstall_vm_functions (void)
int ast_unlock_path (const char *path)
void ast_unreplace_sigchld (void)
 Restore the SIGCHLD handler.


Define Documentation

#define AST_APP_ARG name   )     char *name
 

Define an application argument.

Parameters:
name The name of the argument

Definition at line 226 of file app.h.

Referenced by __login_exec(), add_agent(), astman_get_variables(), func_header_read(), function_agent(), oss_call(), oss_request(), pbx_builtin_background(), and pbx_builtin_waitexten().

#define AST_APP_OPTION option,
flagno   )     [option] = { .flag = flagno }
 

Declares an application option that does not accept an argument.

Parameters:
option The single character representing the option
flagno The flag index to be set if this option is present
See also:
AST_APP_OPTIONS, ast_app_parse_options

Definition at line 368 of file app.h.

#define AST_APP_OPTION_ARG option,
flagno,
argno   )     [option] = { .flag = flagno, .arg_index = argno + 1 }
 

Declares an application option that accepts an argument.

Parameters:
option The single character representing the option
flagno The flag index to be set if this option is present
argno The index into the argument array where the argument should be placed
See also:
AST_APP_OPTIONS, ast_app_parse_options

Definition at line 379 of file app.h.

#define AST_APP_OPTIONS holder,
options...   )     static const struct ast_app_option holder[128] = options
 

Declares an array of options for an application.

Parameters:
holder The name of the array to be created
options The actual options to be placed into the array
See also:
ast_app_parse_options
This macro declares a 'static const' array of struct ast_option elements to hold the list of available options for an application. Each option must be declared using either the AST_APP_OPTION() or AST_APP_OPTION_ARG() macros.

Example usage:

  enum {
        OPT_JUMP = (1 << 0),
        OPT_BLAH = (1 << 1),
        OPT_BLORT = (1 << 2),
  } my_app_option_flags;

  enum {
        OPT_ARG_BLAH = 0,
        OPT_ARG_BLORT,
        !! this entry tells how many possible arguments there are,
           and must be the last entry in the list
        OPT_ARG_ARRAY_SIZE,
  } my_app_option_args;

  AST_APP_OPTIONS(my_app_options, {
        AST_APP_OPTION('j', OPT_JUMP),
        AST_APP_OPTION_ARG('b', OPT_BLAH, OPT_ARG_BLAH),
        AST_APP_OPTION_BLORT('B', OPT_BLORT, OPT_ARG_BLORT),
  });

  static int my_app_exec(struct ast_channel *chan, void *data)
  {
   char *options;
   struct ast_flags opts = { 0, };
   char *opt_args[OPT_ARG_ARRAY_SIZE];

   ... do any argument parsing here ...

   if (ast_parseoptions(my_app_options, &opts, opt_args, options)) {
      LOCAL_USER_REMOVE(u);
      return -1;
   }
  }

Definition at line 359 of file app.h.

#define AST_DECLARE_APP_ARGS name,
arglist   ) 
 

Value:

struct { \
      unsigned int argc; \
      char *argv[0]; \
      arglist \
   } name
Declare a structure to hold the application's arguments.

Parameters:
name The name of the structure
arglist The list of arguments, defined using AST_APP_ARG
This macro defines a structure intended to be used in a call to ast_app_separate_args(). The structure includes all the arguments specified, plus an argv array that overlays them and an argc argument counter. The arguments must be declared using AST_APP_ARG, and they will all be character pointers (strings).

Note:
The structure is not initialized, as the call to ast_app_separate_args() will perform that function before parsing the arguments.

Definition at line 243 of file app.h.

Referenced by __login_exec(), add_agent(), astman_get_variables(), func_header_read(), function_agent(), oss_call(), oss_request(), pbx_builtin_background(), and pbx_builtin_waitexten().

#define AST_IVR_DECLARE_MENU holder,
title,
flags,
foo...   ) 
 

Value:

static struct ast_ivr_option __options_##holder[] = foo;\
   static struct ast_ivr_menu holder = { title, flags, __options_##holder }

Definition at line 76 of file app.h.

#define AST_IVR_FLAG_AUTORESTART   (1 << 0)
 

Definition at line 74 of file app.h.

#define AST_NONSTANDARD_APP_ARGS args,
parse,
sep   )     args.argc = ast_app_separate_args(parse, sep, args.argv, (sizeof(args) - sizeof(args.argc)) / sizeof(args.argv[0]))
 

Performs the 'nonstandard' argument separation process for an application.

Parameters:
args An argument structure defined using AST_DECLARE_APP_ARGS
parse A modifiable buffer containing the input to be parsed
sep A nonstandard separator character
This function will separate the input string using the nonstandard argument separator character and fill in the provided structure, including the argc argument counter field.

Definition at line 272 of file app.h.

Referenced by add_agent(), function_agent(), oss_call(), and oss_request().

#define AST_STANDARD_APP_ARGS args,
parse   )     args.argc = ast_app_separate_args(parse, '|', args.argv, (sizeof(args) - sizeof(args.argc)) / sizeof(args.argv[0]))
 

Performs the 'standard' argument separation process for an application.

Parameters:
args An argument structure defined using AST_DECLARE_APP_ARGS
parse A modifiable buffer containing the input to be parsed
This function will separate the input string using the standard argument separator character '|' and fill in the provided structure, including the argc argument counter field.

Definition at line 259 of file app.h.

Referenced by __login_exec(), astman_get_variables(), func_header_read(), pbx_builtin_background(), and pbx_builtin_waitexten().

#define GROUP_CATEGORY_PREFIX   "GROUP"
 

Definition at line 208 of file app.h.

Referenced by ast_app_group_get_count(), ast_app_group_match_get_count(), ast_app_group_split_group(), clone_variables(), and group_show_channels().


Typedef Documentation

typedef int(* ast_ivr_callback)(struct ast_channel *chan, char *option, void *cbdata)
 

Callback function for IVR.

Returns:
returns 0 on completion, -1 on hangup or digit if interrupted

Definition at line 35 of file app.h.


Enumeration Type Documentation

enum ast_ivr_action
 

Enumerator:
AST_ACTION_UPONE  adata is unused
AST_ACTION_EXIT  adata is the return value for ast_ivr_menu_run if channel was not hungup
AST_ACTION_CALLBACK  adata is an ast_ivr_callback
AST_ACTION_PLAYBACK  adata is file to play
AST_ACTION_BACKGROUND  adata is file to play
AST_ACTION_PLAYLIST  adata is list of files, separated by ; to play
AST_ACTION_MENU  adata is a pointer to an ast_ivr_menu
AST_ACTION_REPEAT  adata is max # of repeats, cast to a pointer
AST_ACTION_RESTART  adata is like repeat, but resets repeats to 0
AST_ACTION_TRANSFER  adata is a string with exten[]
AST_ACTION_WAITOPTION  adata is a timeout, or 0 for defaults
AST_ACTION_NOOP  adata is unused
AST_ACTION_BACKLIST  adata is list of files separated by ; allows interruption

Definition at line 37 of file app.h.

00037              {
00038    AST_ACTION_UPONE, /*!< adata is unused */
00039    AST_ACTION_EXIT,  /*!< adata is the return value for ast_ivr_menu_run if channel was not hungup */
00040    AST_ACTION_CALLBACK, /*!< adata is an ast_ivr_callback */
00041    AST_ACTION_PLAYBACK, /*!< adata is file to play */
00042    AST_ACTION_BACKGROUND,  /*!< adata is file to play */
00043    AST_ACTION_PLAYLIST, /*!< adata is list of files, separated by ; to play */
00044    AST_ACTION_MENU,  /*!< adata is a pointer to an ast_ivr_menu */
00045    AST_ACTION_REPEAT,   /*!< adata is max # of repeats, cast to a pointer */
00046    AST_ACTION_RESTART,  /*!< adata is like repeat, but resets repeats to 0 */
00047    AST_ACTION_TRANSFER, /*!< adata is a string with exten[@context] */
00048    AST_ACTION_WAITOPTION,  /*!< adata is a timeout, or 0 for defaults */
00049    AST_ACTION_NOOP,  /*!< adata is unused */
00050    AST_ACTION_BACKLIST, /*!< adata is list of files separated by ; allows interruption */
00051 } ast_ivr_action;

enum AST_LOCK_RESULT
 

Enumerator:
AST_LOCK_SUCCESS 
AST_LOCK_TIMEOUT 
AST_LOCK_PATH_NOT_FOUND 
AST_LOCK_FAILURE 

Definition at line 188 of file app.h.

00188                      {
00189    AST_LOCK_SUCCESS = 0,
00190    AST_LOCK_TIMEOUT = -1,
00191    AST_LOCK_PATH_NOT_FOUND = -2,
00192    AST_LOCK_FAILURE = -3,
00193 };


Function Documentation

int ast_app_dtget struct ast_channel chan,
const char *  context,
char *  collect,
size_t  size,
int  maxlen,
int  timeout
 

Present a dialtone and collect a certain length extension.

Returns:
Returns 1 on valid extension entered, -1 on hangup, or 0 on invalid extension.
Note:
Note that if 'collect' holds digits already, new digits will be appended, so be sure it's initialized properly

Definition at line 63 of file app.c.

References ast_get_indication_tone(), ast_ignore_pattern(), ast_log(), ast_matchmore_extension(), ast_playtones_start(), ast_playtones_stop(), ast_waitfordigit(), ind_tone_zone_sound::data, ast_pbx::dtimeout, LOG_NOTICE, ast_channel::pbx, and ast_channel::zone.

Referenced by builtin_atxfer(), and builtin_blindtransfer().

00064 {
00065    struct ind_tone_zone_sound *ts;
00066    int res=0, x=0;
00067 
00068    if (maxlen > size)
00069       maxlen = size;
00070    
00071    if (!timeout && chan->pbx)
00072       timeout = chan->pbx->dtimeout;
00073    else if (!timeout)
00074       timeout = 5;
00075    
00076    ts = ast_get_indication_tone(chan->zone,"dial");
00077    if (ts && ts->data[0])
00078       res = ast_playtones_start(chan, 0, ts->data, 0);
00079    else 
00080       ast_log(LOG_NOTICE,"Huh....? no dial for indications?\n");
00081    
00082    for (x = strlen(collect); x < maxlen; ) {
00083       res = ast_waitfordigit(chan, timeout);
00084       if (!ast_ignore_pattern(context, collect))
00085          ast_playtones_stop(chan);
00086       if (res < 1)
00087          break;
00088       collect[x++] = res;
00089       if (!ast_matchmore_extension(chan, context, collect, 1, chan->cid.cid_num)) {
00090          if (collect[x-1] == '#') {
00091             /* Not a valid extension, ending in #, assume the # was to finish dialing */
00092             collect[x-1] = '\0';
00093          }
00094          break;
00095       }
00096    }
00097    if (res >= 0)
00098       res = ast_exists_extension(chan, context, collect, 1, chan->cid.cid_num) ? 1 : 0;
00099    return res;
00100 }

int ast_app_getdata struct ast_channel c,
const char *  prompt,
char *  s,
int  maxlen,
int  timeout
 

Plays a stream and gets DTMF data from a channel.

Parameters:
c The channel to read from
prompt The file to stream to the channel
s The string to read in to. Must be at least the size of your length
maxlen How many digits to read (maximum)
timeout set timeout to 0 for "standard" timeouts. Set timeout to -1 for "ludicrous time" (essentially never times out)

Definition at line 108 of file app.c.

References ast_readstring(), ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_pbx::dtimeout, ast_channel::pbx, ast_pbx::rtimeout, and strsep().

Referenced by __login_exec().

00109 {
00110    int res = 0, to, fto;
00111    char *front, *filename;
00112 
00113    /* XXX Merge with full version? XXX */
00114    
00115    if (maxlen)
00116       s[0] = '\0';
00117 
00118    if (!prompt)
00119       prompt="";
00120 
00121    filename = ast_strdupa(prompt);
00122    while ((front = strsep(&filename, "&"))) {
00123       if (!ast_strlen_zero(front)) {
00124          res = ast_streamfile(c, front, c->language);
00125          if (res)
00126             continue;
00127       }
00128       if (ast_strlen_zero(filename)) {
00129          /* set timeouts for the last prompt */
00130          fto = c->pbx ? c->pbx->rtimeout * 1000 : 6000;
00131          to = c->pbx ? c->pbx->dtimeout * 1000 : 2000;
00132 
00133          if (timeout > 0) 
00134             fto = to = timeout;
00135          if (timeout < 0) 
00136             fto = to = 1000000000;
00137       } else {
00138          /* there is more than one prompt, so
00139             get rid of the long timeout between 
00140             prompts, and make it 50ms */
00141          fto = 50;
00142          to = c->pbx ? c->pbx->dtimeout * 1000 : 2000;
00143       }
00144       res = ast_readstring(c, s, maxlen, to, fto, "#");
00145       if (!ast_strlen_zero(s))
00146          return res;
00147    }
00148    
00149    return res;
00150 }

int ast_app_getdata_full struct ast_channel c,
char *  prompt,
char *  s,
int  maxlen,
int  timeout,
int  audiofd,
int  ctrlfd
 

Full version with audiofd and controlfd. NOTE: returns '2' on ctrlfd available, not '1' like other full functions.

Definition at line 153 of file app.c.

References ast_readstring_full(), and ast_streamfile().

Referenced by handle_getdata().

00154 {
00155    int res, to, fto;
00156    if (prompt) {
00157       res = ast_streamfile(c, prompt, c->language);
00158       if (res < 0)
00159          return res;
00160    }
00161    fto = 6000;
00162    to = 2000;
00163    if (timeout > 0) 
00164       fto = to = timeout;
00165    if (timeout < 0) 
00166       fto = to = 1000000000;
00167    res = ast_readstring_full(c, s, maxlen, to, fto, "#", audiofd, ctrlfd);
00168    return res;
00169 }

int ast_app_group_get_count const char *  group,
const char *  category
 

Get the current channel count of the specified group and category.

Definition at line 832 of file app.c.

References ast_channel_unlock, ast_channel_walk_locked(), ast_strlen_zero(), GROUP_CATEGORY_PREFIX, pbx_builtin_getvar_helper(), s, and S_OR.

00833 {
00834    struct ast_channel *chan;
00835    int count = 0;
00836    const char *test;
00837    char cat[80];
00838    const char *s;
00839 
00840    if (ast_strlen_zero(group))
00841       return 0;
00842 
00843    s = S_OR(category, GROUP_CATEGORY_PREFIX);
00844    ast_copy_string(cat, s, sizeof(cat));
00845 
00846    chan = NULL;
00847    while ((chan = ast_channel_walk_locked(chan)) != NULL) {
00848       test = pbx_builtin_getvar_helper(chan, cat);
00849       if (test && !strcasecmp(test, group))
00850          count++;
00851       ast_channel_unlock(chan);
00852    }
00853 
00854    return count;
00855 }

int ast_app_group_match_get_count const char *  groupmatch,
const char *  category
 

Get the current channel count of all groups that match the specified pattern and category.

Definition at line 857 of file app.c.

References ast_channel_unlock, ast_channel_walk_locked(), ast_strlen_zero(), GROUP_CATEGORY_PREFIX, pbx_builtin_getvar_helper(), s, and S_OR.

00858 {
00859    regex_t regexbuf;
00860    struct ast_channel *chan;
00861    int count = 0;
00862    const char *test;
00863    char cat[80];
00864    const char *s;
00865 
00866    if (ast_strlen_zero(groupmatch))
00867       return 0;
00868 
00869    /* if regex compilation fails, return zero matches */
00870    if (regcomp(&regexbuf, groupmatch, REG_EXTENDED | REG_NOSUB))
00871       return 0;
00872 
00873    s = S_OR(category, GROUP_CATEGORY_PREFIX);
00874    ast_copy_string(cat, s, sizeof(cat));
00875 
00876    chan = NULL;
00877    while ((chan = ast_channel_walk_locked(chan)) != NULL) {
00878       test = pbx_builtin_getvar_helper(chan, cat);
00879       if (test && !regexec(&regexbuf, test, 0, NULL, 0))
00880          count++;
00881       ast_channel_unlock(chan);
00882    }
00883 
00884    regfree(&regexbuf);
00885 
00886    return count;
00887 }

int ast_app_group_set_channel struct ast_channel chan,
const char *  data
 

Set the group for a channel, splitting the provided data into group and category, if specified.

Definition at line 818 of file app.c.

References ast_app_group_split_group(), group, and pbx_builtin_setvar_helper().

00819 {
00820    int res=0;
00821    char group[80] = "";
00822    char category[80] = "";
00823 
00824    if (!ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category))) {
00825       pbx_builtin_setvar_helper(chan, category, group);
00826    } else
00827       res = -1;
00828 
00829    return res;
00830 }

int ast_app_group_split_group const char *  data,
char *  group,
int  group_max,
char *  category,
int  category_max
 

Split a group string into group and category, returning a default category if none is provided.

Definition at line 789 of file app.c.

References ast_strlen_zero(), and GROUP_CATEGORY_PREFIX.

Referenced by ast_app_group_set_channel().

00790 {
00791    int res=0;
00792    char tmp[256];
00793    char *grp=NULL, *cat=NULL;
00794 
00795    if (!ast_strlen_zero(data)) {
00796       ast_copy_string(tmp, data, sizeof(tmp));
00797       grp = tmp;
00798       cat = strchr(tmp, '@');
00799       if (cat) {
00800          *cat = '\0';
00801          cat++;
00802       }
00803    }
00804 
00805    if (!ast_strlen_zero(grp))
00806       ast_copy_string(group, grp, group_max);
00807    else
00808       res = -1;
00809 
00810    if (cat)
00811       snprintf(category, category_max, "%s_%s", GROUP_CATEGORY_PREFIX, cat);
00812    else
00813       ast_copy_string(category, GROUP_CATEGORY_PREFIX, category_max);
00814 
00815    return res;
00816 }

int ast_app_has_voicemail const char *  mailbox,
const char *  folder
 

Determine if a given mailbox has any voicemail

Definition at line 191 of file app.c.

References ast_has_voicemail_func, ast_verbose(), option_verbose, and VERBOSE_PREFIX_3.

Referenced by action_mailboxstatus(), and has_voicemail().

00192 {
00193    static int warned = 0;
00194    if (ast_has_voicemail_func)
00195       return ast_has_voicemail_func(mailbox, folder);
00196 
00197    if ((option_verbose > 2) && !warned) {
00198       ast_verbose(VERBOSE_PREFIX_3 "Message check requested for mailbox %s/folder %s but voicemail not loaded.\n", mailbox, folder ? folder : "INBOX");
00199       warned++;
00200    }
00201    return 0;
00202 }

int ast_app_inboxcount const char *  mailbox,
int *  newmsgs,
int *  oldmsgs
 

Determine number of new/old messages in a mailbox

Definition at line 205 of file app.c.

References ast_inboxcount_func, ast_verbose(), option_verbose, and VERBOSE_PREFIX_3.

Referenced by action_mailboxcount(), sip_send_mwi_to_peer(), and update_registry().

00206 {
00207    static int warned = 0;
00208    if (newmsgs)
00209       *newmsgs = 0;
00210    if (oldmsgs)
00211       *oldmsgs = 0;
00212    if (ast_inboxcount_func)
00213       return ast_inboxcount_func(mailbox, newmsgs, oldmsgs);
00214 
00215    if (!warned && (option_verbose > 2)) {
00216       warned++;
00217       ast_verbose(VERBOSE_PREFIX_3 "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox);
00218    }
00219 
00220    return 0;
00221 }

int ast_app_messagecount const char *  context,
const char *  mailbox,
const char *  folder
 

Determine number of messages in a given mailbox and folder

Definition at line 223 of file app.c.

References ast_messagecount_func, ast_verbose(), option_verbose, and VERBOSE_PREFIX_3.

00224 {
00225    static int warned = 0;
00226    if (ast_messagecount_func)
00227       return ast_messagecount_func(context, mailbox, folder);
00228 
00229    if (!warned && (option_verbose > 2)) {
00230       warned++;
00231       ast_verbose(VERBOSE_PREFIX_3 "Message count requested for mailbox %s@%s/%s but voicemail not loaded.\n", mailbox, context, folder);
00232    }
00233 
00234    return 0;
00235 }

int ast_app_parse_options const struct ast_app_option options,
struct ast_flags flags,
char **  args,
char *  optstr
 

Parses a string containing application options and sets flags/arguments.

Parameters:
options The array of possible options declared with AST_APP_OPTIONS
flags The flag structure to have option flags set
args The array of argument pointers to hold arguments found
optstr The string containing the options to be parsed
Returns:
zero for success, non-zero if an error occurs
See also:
AST_APP_OPTIONS

Definition at line 1324 of file app.c.

References ast_app_option::arg_index, ast_clear_flag, AST_FLAGS_ALL, ast_log(), ast_set_flag, LOG_WARNING, and s.

Referenced by pbx_builtin_background(), pbx_builtin_resetcdr(), and pbx_builtin_waitexten().

01325 {
01326    char *s;
01327    int curarg;
01328    unsigned int argloc;
01329    char *arg;
01330    int res = 0;
01331 
01332    ast_clear_flag(flags, AST_FLAGS_ALL);
01333 
01334    if (!optstr)
01335       return 0;
01336 
01337    s = optstr;
01338    while (*s) {
01339       curarg = *s++ & 0x7f;   /* the array (in app.h) has 128 entries */
01340       ast_set_flag(flags, options[curarg].flag);
01341       argloc = options[curarg].arg_index;
01342       if (*s == '(') {
01343          /* Has argument */
01344          arg = ++s;
01345          if ((s = strchr(s, ')'))) {
01346             if (argloc)
01347                args[argloc - 1] = arg;
01348             *s++ = '\0';
01349          } else {
01350             ast_log(LOG_WARNING, "Missing closing parenthesis for argument '%c' in string '%s'\n", curarg, arg);
01351             res = -1;
01352             break;
01353          }
01354       } else if (argloc) {
01355          args[argloc - 1] = NULL;
01356       }
01357    }
01358 
01359    return res;
01360 }

unsigned int ast_app_separate_args char *  buf,
char  delim,
char **  array,
int  arraylen
 

Separate a string into arguments in an array.

Parameters:
buf The string to be parsed (this must be a writable copy, as it will be modified)
delim The character to be used to delimit arguments
array An array of 'char *' to be filled in with pointers to the found arguments
arraylen The number of elements in the array (i.e. the number of arguments you will accept)
Note: if there are more arguments in the string than the array will hold, the last element of the array will contain the remaining arguments, not separated.

The array will be completely zeroed by this function before it populates any entries.

Returns:
The number of arguments found, or zero if the function arguments are not valid.

Definition at line 889 of file app.c.

Referenced by pbx_builtin_setvar().

00890 {
00891    int argc;
00892    char *scan;
00893    int paren = 0, quote = 0;
00894 
00895    if (!buf || !array || !arraylen)
00896       return 0;
00897 
00898    memset(array, 0, arraylen * sizeof(*array));
00899 
00900    scan = buf;
00901 
00902    for (argc = 0; *scan && (argc < arraylen - 1); argc++) {
00903       array[argc] = scan;
00904       for (; *scan; scan++) {
00905          if (*scan == '(')
00906             paren++;
00907          else if (*scan == ')') {
00908             if (paren)
00909                paren--;
00910          } else if (*scan == '"' && delim != '"') {
00911             quote = quote ? 0 : 1;
00912             /* Remove quote character from argument */
00913             memmove(scan, scan + 1, strlen(scan));
00914             scan--;
00915          } else if (*scan == '\\') {
00916             /* Literal character, don't parse */
00917             memmove(scan, scan + 1, strlen(scan));
00918          } else if ((*scan == delim) && !paren && !quote) {
00919             *scan++ = '\0';
00920             break;
00921          }
00922       }
00923    }
00924 
00925    if (*scan)
00926       array[argc++] = scan;
00927 
00928    return argc;
00929 }

int ast_control_streamfile struct ast_channel chan,
const char *  file,
const char *  fwd,
const char *  rev,
const char *  stop,
const char *  pause,
const char *  restart,
int  skipms
 

Stream a file with fast forward, pause, reverse, restart.

Definition at line 385 of file app.c.

References ast_channel::_state, ast_answer(), ast_log(), ast_seekstream(), AST_STATE_UP, ast_stopstream(), ast_streamfile(), ast_tellstream(), ast_waitfordigit(), ast_waitstream_fr(), LOG_DEBUG, option_debug, and ast_channel::stream.

Referenced by handle_controlstreamfile().

00389 {
00390    char *breaks = NULL;
00391    char *end = NULL;
00392    int blen = 2;
00393    int res;
00394    long pause_restart_point = 0;
00395 
00396    if (stop)
00397       blen += strlen(stop);
00398    if (pause)
00399       blen += strlen(pause);
00400    if (restart)
00401       blen += strlen(restart);
00402 
00403    if (blen > 2) {
00404       breaks = alloca(blen + 1);
00405       breaks[0] = '\0';
00406       if (stop)
00407          strcat(breaks, stop);
00408       if (pause)
00409          strcat(breaks, pause);
00410       if (restart)
00411          strcat(breaks, restart);
00412    }
00413    if (chan->_state != AST_STATE_UP)
00414       res = ast_answer(chan);
00415 
00416    if (file) {
00417       if ((end = strchr(file,':'))) {
00418          if (!strcasecmp(end, ":end")) {
00419             *end = '\0';
00420             end++;
00421          }
00422       }
00423    }
00424 
00425    for (;;) {