Fri Jun 19 12:09:55 2009

Asterisk developer's documentation


app.c File Reference

Convenient Application Routines. More...

#include "asterisk.h"
#include <sys/stat.h>
#include <regex.h>
#include <sys/file.h>
#include <signal.h>
#include <sys/capability.h>
#include "asterisk/paths.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/file.h"
#include "asterisk/app.h"
#include "asterisk/dsp.h"
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/indications.h"
#include "asterisk/linkedlists.h"

Go to the source code of this file.

Data Structures

struct  groups
struct  linear_state
struct  path_lock
struct  path_lock_list

Defines

#define MAX_OTHER_FORMATS   10
#define RES_EXIT   (1 << 17)
#define RES_REPEAT   (1 << 18)
#define RES_RESTART   ((1 << 19) | RES_REPEAT)
#define RES_UPONE   (1 << 16)

Functions

static int __ast_play_and_record (struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int beep, int silencethreshold, int maxsilence, const char *path, int prepend, const char *acceptdtmf, const char *canceldtmf)
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.
enum ast_getdata_result 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_discard (struct ast_channel *chan)
 Discard all group counting for a channel.
int ast_app_group_get_count (const char *group, const char *category)
 Get the current channel count of the specified group and category.
ast_group_infoast_app_group_list_head (void)
 Get the head of the group count list.
int ast_app_group_list_rdlock (void)
 Read Lock the group count list.
int ast_app_group_list_unlock (void)
 Unlock the group count list.
int ast_app_group_list_wrlock (void)
 Write Lock the group count list.
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.
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.
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.
int ast_app_group_update (struct ast_channel *old, struct ast_channel *new)
 Update all group counting for a channel to a new one.
int ast_app_has_voicemail (const char *mailbox, const char *folder)
 Determine if a given mailbox has any voicemail.
int ast_app_inboxcount (const char *mailbox, int *newmsgs, int *oldmsgs)
 Determine number of new/old messages in a mailbox.
int ast_app_inboxcount2 (const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
 Determine number of urgent/new/old messages in a mailbox.
int ast_app_messagecount (const char *context, const char *mailbox, const char *folder)
 Determine number of messages in a given mailbox and folder.
void ast_app_options2str64 (const struct ast_app_option *options, struct ast_flags64 *flags, char *buf, size_t len)
 Given a list of options array, return an option string based on passed flags.
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.
int ast_app_parse_options64 (const struct ast_app_option *options, struct ast_flags64 *flags, char **args, char *optstr)
 Parses a string containing application options and sets flags/arguments.
int ast_app_sayname (struct ast_channel *chan, const char *mailbox, const char *context)
 Given a mailbox and context, play that mailbox owner's name to the channel specified.
unsigned int ast_app_separate_args (char *buf, char delim, char **array, int arraylen)
 Separate a string into arguments in an array.
void ast_close_fds_above_n (int n)
 Common routine for child processes, to close all fds prior to exec(2).
int ast_control_streamfile (struct ast_channel *chan, const char *file, const char *fwd, const char *rev, const char *stop, const char *suspend, const char *restart, int skipms, long *offsetms)
 Stream a file with fast forward, pause, reverse, restart.
int ast_dtmf_stream (struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between, unsigned int duration)
 Send DTMF to a channel.
int ast_get_encoded_char (const char *stream, char *result, size_t *consumed)
 Decode an encoded control or extended ASCII character.
int ast_get_encoded_str (const char *stream, char *result, size_t result_size)
 Decode a string which may contain multiple encoded control or extended ASCII characters.
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(*inboxcount2_func)(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs), int(*messagecount_func)(const char *context, const char *mailbox, const char *folder), int(*sayname_func)(struct ast_channel *chan, const char *mailbox, const char *context))
 Set voicemail function callbacks.
int ast_ivr_menu_run (struct ast_channel *chan, struct ast_ivr_menu *menu, void *cbdata)
 Runs an IVR menu.
static int ast_ivr_menu_run_internal (struct ast_channel *chan, struct ast_ivr_menu *menu, void *cbdata)
int ast_linear_stream (struct ast_channel *chan, const char *filename, int fd, int allowoverride)
 Stream a filename (or file descriptor) as a generator.
enum AST_LOCK_RESULT ast_lock_path (const char *path)
 Lock a filesystem path.
static enum AST_LOCK_RESULT ast_lock_path_flock (const char *path)
static enum AST_LOCK_RESULT ast_lock_path_lockfile (const char *path)
int ast_play_and_prepend (struct ast_channel *chan, char *playfile, char *recordfile, int maxtime, char *fmt, int *duration, int beep, int silencethreshold, int maxsilence)
 Record a message and prepend the message to the given record file after playing the optional playfile (or a beep), storing the duration in 'duration' and with a maximum permitted silence time in milliseconds of 'maxsilence' under 'silencethreshold' or use '-1' for either or both parameters for defaults.
int ast_play_and_record (struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int silencethreshold, int maxsilence, const char *path)
 Record a file for a max amount of time (in seconds), in a given list of formats separated by '|', outputting the duration of the recording, and with a maximum
permitted silence time in milliseconds of 'maxsilence' under 'silencethreshold' or use '-1' for either or both parameters for defaults. calls ast_unlock_path() on 'path' if passed.
int ast_play_and_record_full (struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int silencethreshold, int maxsilence, const char *path, const char *acceptdtmf, const char *canceldtmf)
int ast_play_and_wait (struct ast_channel *chan, const char *fn)
 Play a stream and wait for a digit, returning the digit that was pressed.
char * ast_read_textfile (const char *filename)
 Read a file into asterisk.
int ast_record_review (struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, const char *path)
 Allow to record message and have a review option.
int ast_safe_fork (int stop_reaper)
 Common routine to safely fork without a chance of a signal handler firing badly in the child.
void ast_safe_fork_cleanup (void)
 Common routine to cleanup after fork'ed process is complete (if reaping was stopped).
void ast_set_lock_type (enum AST_LOCK_TYPE type)
 Set the type of locks used by ast_lock_path().
int ast_str_get_encoded_str (struct ast_str **str, int maxlen, const char *stream)
 Decode a stream of encoded control or extended ASCII characters.
void ast_uninstall_vm_functions (void)
int ast_unlock_path (const char *path)
 Unlock a path.
static int ast_unlock_path_flock (const char *path)
static int ast_unlock_path_lockfile (const char *path)
static int ivr_dispatch (struct ast_channel *chan, struct ast_ivr_option *option, char *exten, void *cbdata)
static void * linear_alloc (struct ast_channel *chan, void *params)
static int linear_generator (struct ast_channel *chan, void *data, int len, int samples)
static void linear_release (struct ast_channel *chan, void *params)
static int option_exists (struct ast_ivr_menu *menu, char *option)
static int option_matchmore (struct ast_ivr_menu *menu, char *option)
static void path_lock_destroy (struct path_lock *obj)
static int read_newoption (struct ast_channel *chan, struct ast_ivr_menu *menu, char *exten, int maxexten)

Variables

static int(*) ast_has_voicemail_func (const char *mailbox, const char *folder) = NULL
static int(*) ast_inboxcount2_func (const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs) = NULL
static int(*) ast_inboxcount_func (const char *mailbox, int *newmsgs, int *oldmsgs) = NULL
static enum AST_LOCK_TYPE ast_lock_type = AST_LOCK_TYPE_LOCKFILE
static int(*) ast_messagecount_func (const char *context, const char *mailbox, const char *folder) = NULL
static int(*) ast_sayname_func (struct ast_channel *chan, const char *mailbox, const char *context) = NULL
static char default_acceptdtmf [] = "#"
static char default_canceldtmf [] = ""
static int global_maxsilence = 0
static int global_silence_threshold = 128
static struct ast_generator linearstream


Detailed Description

Convenient Application Routines.

Author:
Mark Spencer <markster@digium.com>

Definition in file app.c.


Define Documentation

#define MAX_OTHER_FORMATS   10

Definition at line 51 of file app.c.

Referenced by __ast_play_and_record().

#define RES_EXIT   (1 << 17)

Definition at line 1448 of file app.c.

Referenced by ast_ivr_menu_run_internal(), and ivr_dispatch().

#define RES_REPEAT   (1 << 18)

Definition at line 1449 of file app.c.

Referenced by ast_ivr_menu_run_internal(), and ivr_dispatch().

#define RES_RESTART   ((1 << 19) | RES_REPEAT)

Definition at line 1450 of file app.c.

Referenced by ast_ivr_menu_run_internal(), and ivr_dispatch().

#define RES_UPONE   (1 << 16)

Definition at line 1447 of file app.c.

Referenced by ast_ivr_menu_run_internal(), and ivr_dispatch().


Function Documentation

static int __ast_play_and_record ( struct ast_channel chan,
const char *  playfile,
const char *  recordfile,
int  maxtime,
const char *  fmt,
int *  duration,
int  beep,
int  silencethreshold,
int  maxsilence,
const char *  path,
int  prepend,
const char *  acceptdtmf,
const char *  canceldtmf 
) [static]

Optionally play a sound file or a beep, then record audio and video from the channel.

Parameters:
chan Channel to playback to/record from.
playfile Filename of sound to play before recording begins.
recordfile Filename to record to.
maxtime Maximum length of recording (in milliseconds).
fmt Format(s) to record message in. Multiple formats may be specified by separating them with a '|'.
duration Where to store actual length of the recorded message (in milliseconds).
beep Whether to play a beep before starting to record.
silencethreshold 
maxsilence Length of silence that will end a recording (in milliseconds).
path Optional filesystem path to unlock.
prepend If true, prepend the recorded audio to an existing file.
acceptdtmf DTMF digits that will end the recording.
canceldtmf DTMF digits that will cancel the recording.

Note:
Instead of asking how much time passed (end - start), calculate the number of seconds of audio which actually went into the file. This fixes a problem where audio is stopped up on the network and never gets to us.
Note that we still want to use the number of seconds passed for the max message, otherwise we could get a situation where this stream is never closed (which would create a resource leak).

Note:
If we ended with silence, trim all but the first 200ms of silence off the recording. However, if we ended with '#', we don't want to trim ANY part of the recording.

Same logic as above.

Definition at line 617 of file app.c.

References ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), ast_closestream(), AST_CONTROL_VIDUPDATE, ast_copy_string(), ast_debug, ast_dsp_free(), ast_dsp_new(), ast_dsp_set_threshold(), ast_dsp_silence(), AST_FILE_MODE, ast_filedelete(), ast_filerename(), AST_FORMAT_SLINEAR, AST_FRAME_DTMF, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_frfree, ast_getformatname(), ast_indicate(), ast_log(), ast_opt_transmit_silence, ast_play_and_wait(), ast_read(), ast_readfile(), ast_readframe(), ast_set_read_format(), ast_strdupa, ast_stream_and_wait(), ast_stream_rewind(), ast_tellstream(), ast_truncstream(), ast_unlock_path(), ast_verb, ast_waitfor(), ast_writefile(), ast_writestream(), chan, f, LOG_WARNING, MAX_OTHER_FORMATS, ast_channel::name, ast_channel::readformat, strsep(), and ast_dsp::totalsilence.

Referenced by ast_play_and_prepend(), ast_play_and_record(), and ast_play_and_record_full().

00618 {
00619    int d = 0;
00620    char *fmts;
00621    char comment[256];
00622    int x, fmtcnt = 1, res = -1, outmsg = 0;
00623    struct ast_filestream *others[MAX_OTHER_FORMATS];
00624    char *sfmt[MAX_OTHER_FORMATS];
00625    char *stringp = NULL;
00626    time_t start, end;
00627    struct ast_dsp *sildet = NULL;   /* silence detector dsp */
00628    int totalsilence = 0;
00629    int rfmt = 0;
00630    struct ast_silence_generator *silgen = NULL;
00631    char prependfile[80];
00632 
00633    if (silencethreshold < 0)
00634       silencethreshold = global_silence_threshold;
00635 
00636    if (maxsilence < 0)
00637       maxsilence = global_maxsilence;
00638 
00639    /* barf if no pointer passed to store duration in */
00640    if (!duration) {
00641       ast_log(LOG_WARNING, "Error play_and_record called without duration pointer\n");
00642       return -1;
00643    }
00644 
00645    ast_debug(1, "play_and_record: %s, %s, '%s'\n", playfile ? playfile : "<None>", recordfile, fmt);
00646    snprintf(comment, sizeof(comment), "Playing %s, Recording to: %s on %s\n", playfile ? playfile : "<None>", recordfile, chan->name);
00647 
00648    if (playfile || beep) {
00649       if (!beep)
00650          d = ast_play_and_wait(chan, playfile);
00651       if (d > -1)
00652          d = ast_stream_and_wait(chan, "beep", "");
00653       if (d < 0)
00654          return -1;
00655    }
00656 
00657    if (prepend) {
00658       ast_copy_string(prependfile, recordfile, sizeof(prependfile)); 
00659       strncat(prependfile, "-prepend", sizeof(prependfile) - strlen(prependfile) - 1);
00660    }
00661 
00662    fmts = ast_strdupa(fmt);
00663 
00664    stringp = fmts;
00665    strsep(&stringp, "|");
00666    ast_debug(1, "Recording Formats: sfmts=%s\n", fmts);
00667    sfmt[0] = ast_strdupa(fmts);
00668 
00669    while ((fmt = strsep(&stringp, "|"))) {
00670       if (fmtcnt > MAX_OTHER_FORMATS - 1) {
00671          ast_log(LOG_WARNING, "Please increase MAX_OTHER_FORMATS in app.c\n");
00672          break;
00673       }
00674       sfmt[fmtcnt++] = ast_strdupa(fmt);
00675    }
00676 
00677    end = start = time(NULL);  /* pre-initialize end to be same as start in case we never get into loop */
00678    for (x = 0; x < fmtcnt; x++) {
00679       others[x] = ast_writefile(prepend ? prependfile : recordfile, sfmt[x], comment, O_TRUNC, 0, AST_FILE_MODE);
00680       ast_verb(3, "x=%d, open writing:  %s format: %s, %p\n", x, prepend ? prependfile : recordfile, sfmt[x], others[x]);
00681 
00682       if (!others[x])
00683          break;
00684    }
00685 
00686    if (path)
00687       ast_unlock_path(path);
00688 
00689    if (maxsilence > 0) {
00690       sildet = ast_dsp_new(); /* Create the silence detector */
00691       if (!sildet) {
00692          ast_log(LOG_WARNING, "Unable to create silence detector :(\n");
00693          return -1;
00694       }
00695       ast_dsp_set_threshold(sildet, silencethreshold);
00696       rfmt = chan->readformat;
00697       res = ast_set_read_format(chan, AST_FORMAT_SLINEAR);
00698       if (res < 0) {
00699          ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
00700          ast_dsp_free(sildet);
00701          return -1;
00702       }
00703    }
00704 
00705    if (!prepend) {
00706       /* Request a video update */
00707       ast_indicate(chan, AST_CONTROL_VIDUPDATE);
00708 
00709       if (ast_opt_transmit_silence)
00710          silgen = ast_channel_start_silence_generator(chan);
00711    }
00712 
00713    if (x == fmtcnt) {
00714       /* Loop forever, writing the packets we read to the writer(s), until
00715          we read a digit or get a hangup */
00716       struct ast_frame *f;
00717       for (;;) {
00718          res = ast_waitfor(chan, 2000);
00719          if (!res) {
00720             ast_debug(1, "One waitfor failed, trying another\n");
00721             /* Try one more time in case of masq */
00722             res = ast_waitfor(chan, 2000);
00723             if (!res) {
00724                ast_log(LOG_WARNING, "No audio available on %s??\n", chan->name);
00725                res = -1;
00726             }
00727          }
00728 
00729          if (res < 0) {
00730             f = NULL;
00731             break;
00732          }
00733          f = ast_read(chan);
00734          if (!f)
00735             break;
00736          if (f->frametype == AST_FRAME_VOICE) {
00737             /* write each format */
00738             for (x = 0; x < fmtcnt; x++) {
00739                if (prepend && !others[x])
00740                   break;
00741                res = ast_writestream(others[x], f);
00742             }
00743 
00744             /* Silence Detection */
00745             if (maxsilence > 0) {
00746                int dspsilence = 0;
00747                ast_dsp_silence(sildet, f, &dspsilence);
00748                if (dspsilence)
00749                   totalsilence = dspsilence;
00750                else
00751                   totalsilence = 0;
00752 
00753                if (totalsilence > maxsilence) {
00754                   /* Ended happily with silence */
00755                   ast_verb(3, "Recording automatically stopped after a silence of %d seconds\n", totalsilence/1000);
00756                   res = 'S';
00757                   outmsg = 2;
00758                   break;
00759                }
00760             }
00761             /* Exit on any error */
00762             if (res) {
00763                ast_log(LOG_WARNING, "Error writing frame\n");
00764                break;
00765             }
00766          } else if (f->frametype == AST_FRAME_VIDEO) {
00767             /* Write only once */
00768             ast_writestream(others[0], f);
00769          } else if (f->frametype == AST_FRAME_DTMF) {
00770             if (prepend) {
00771             /* stop recording with any digit */
00772                ast_verb(3, "User ended message by pressing %c\n", f->subclass);
00773                res = 't';
00774                outmsg = 2;
00775                break;
00776             }
00777             if (strchr(acceptdtmf, f->subclass)) {
00778                ast_verb(3, "User ended message by pressing %c\n", f->subclass);
00779                res = f->subclass;
00780                outmsg = 2;
00781                break;
00782             }
00783             if (strchr(canceldtmf, f->subclass)) {
00784                ast_verb(3, "User cancelled message by pressing %c\n", f->subclass);
00785                res = f->subclass;
00786                outmsg = 0;
00787                break;
00788             }
00789          }
00790          if (maxtime) {
00791             end = time(NULL);
00792             if (maxtime < (end - start)) {
00793                ast_verb(3, "Took too long, cutting it short...\n");
00794                res = 't';
00795                outmsg = 2;
00796                break;
00797             }
00798          }
00799          ast_frfree(f);
00800       }
00801       if (!f) {
00802          ast_verb(3, "User hung up\n");
00803          res = -1;
00804          outmsg = 1;
00805       } else {
00806          ast_frfree(f);
00807       }
00808    } else {
00809       ast_log(LOG_WARNING, "Error creating writestream '%s', format '%s'\n", recordfile, sfmt[x]);
00810    }
00811 
00812    if (!prepend) {
00813       if (silgen)
00814          ast_channel_stop_silence_generator(chan, silgen);
00815    }
00816 
00817    /*!\note
00818     * Instead of asking how much time passed (end - start), calculate the number
00819     * of seconds of audio which actually went into the file.  This fixes a
00820     * problem where audio is stopped up on the network and never gets to us.
00821     *
00822     * Note that we still want to use the number of seconds passed for the max
00823     * message, otherwise we could get a situation where this stream is never
00824     * closed (which would create a resource leak).
00825     */
00826    *duration = others[0] ? ast_tellstream(others[0]) / 8000 : 0;
00827 
00828    if (!prepend) {
00829       for (x = 0; x < fmtcnt; x++) {
00830          if (!others[x])
00831             break;
00832          /*!\note
00833           * If we ended with silence, trim all but the first 200ms of silence
00834           * off the recording.  However, if we ended with '#', we don't want
00835           * to trim ANY part of the recording.
00836           */
00837          if (res > 0 && totalsilence) {
00838             ast_stream_rewind(others[x], totalsilence - 200);
00839             /* Reduce duration by a corresponding amount */
00840             if (x == 0 && *duration) {
00841                *duration -= (totalsilence - 200) / 1000;
00842                if (*duration < 0) {
00843                   *duration = 0;
00844                }
00845             }
00846          }
00847          ast_truncstream(others[x]);
00848          ast_closestream(others[x]);
00849       }
00850    }
00851 
00852    if (prepend && outmsg) {
00853       struct ast_filestream *realfiles[MAX_OTHER_FORMATS];
00854       struct ast_frame *fr;
00855 
00856       for (x = 0; x < fmtcnt; x++) {
00857          snprintf(comment, sizeof(comment), "Opening the real file %s.%s\n", recordfile, sfmt[x]);
00858          realfiles[x] = ast_readfile(recordfile, sfmt[x], comment, O_RDONLY, 0, 0);
00859          if (!others[x] || !realfiles[x])
00860             break;
00861          /*!\note Same logic as above. */
00862          if (totalsilence)
00863             ast_stream_rewind(others[x], totalsilence - 200);
00864          ast_truncstream(others[x]);
00865          /* add the original file too */
00866          while ((fr = ast_readframe(realfiles[x]))) {
00867             ast_writestream(others[x], fr);
00868             ast_frfree(fr);
00869          }
00870          ast_closestream(others[x]);
00871          ast_closestream(realfiles[x]);
00872          ast_filerename(prependfile, recordfile, sfmt[x]);
00873          ast_verb(4, "Recording Format: sfmts=%s, prependfile %s, recordfile %s\n", sfmt[x], prependfile, recordfile);
00874          ast_filedelete(prependfile, sfmt[x]);
00875       }
00876    }
00877    if (rfmt && ast_set_read_format(chan, rfmt)) {
00878       ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(rfmt), chan->name);
00879    }
00880    if (outmsg == 2) {
00881       ast_stream_and_wait(chan, "auth-thankyou", "");
00882    }
00883    if (sildet)
00884       ast_dsp_free(sildet);
00885    return res;
00886 }

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.

Parameters:
chan struct.
context 
collect 
size 
maxlen 
timeout timeout in seconds
Returns:
0 if extension does not exist, 1 if extension exists

Definition at line 69 of file app.c.

References ast_exists_extension(), ast_get_indication_tone(), ast_ignore_pattern(), ast_log(), ast_matchmore_extension(), ast_playtones_start(), ast_playtones_stop(), ast_waitfordigit(), chan, ast_channel::cid, ast_callerid::cid_num, tone_zone_sound::data, ast_pbx::dtimeoutms, LOG_NOTICE, ast_channel::pbx, and ast_channel::zone.

Referenced by builtin_atxfer(), and builtin_blindtransfer().

00070 {
00071    struct tone_zone_sound *ts;
00072    int res = 0, x = 0;
00073 
00074    if (maxlen > size)
00075       maxlen = size;
00076    
00077    if (!timeout && chan->pbx)
00078       timeout = chan->pbx->dtimeoutms / 1000.0;
00079    else if (!timeout)
00080       timeout = 5;
00081 
00082    if ((ts = ast_get_indication_tone(chan->zone, "dial")) && ts->data[0])
00083       res = ast_playtones_start(chan, 0, ts->data, 0);
00084    else 
00085       ast_log(LOG_NOTICE, "Huh....? no dial for indications?\n");
00086    
00087    for (x = strlen(collect); x < maxlen; ) {
00088       res = ast_waitfordigit(chan, timeout);
00089       if (!ast_ignore_pattern(context, collect))
00090          ast_playtones_stop(chan);
00091       if (res < 1)
00092          break;
00093       if (res == '#')
00094          break;
00095       collect[x++] = res;
00096       if (!ast_matchmore_extension(chan, context, collect, 1, chan->cid.cid_num))
00097          break;
00098    }
00099 
00100    if (res >= 0)
00101       res = ast_exists_extension(chan, context, collect, 1, chan->cid.cid_num) ? 1 : 0;
00102 
00103    return res;
00104 }

enum ast_getdata_result 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 114 of file app.c.

References AST_GETDATA_EMPTY_END_TERMINATED, ast_readstring(), ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_pbx::dtimeoutms, ast_channel::language, ast_channel::pbx, ast_pbx::rtimeoutms, and strsep().

Referenced by auth_exec(), conf_exec(), dictate_exec(), find_conf(), login_exec(), read_exec(), testclient_exec(), testserver_exec(), and vm_exec().

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

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 165 of file app.c.

References ast_readstring_full(), ast_streamfile(), ast_strlen_zero(), and ast_channel::language.

Referenced by handle_getdata().

00166 {
00167    int res, to = 2000, fto = 6000;
00168 
00169    if (!ast_strlen_zero(prompt)) {
00170       res = ast_streamfile(c, prompt, c->language);
00171       if (res < 0)
00172          return res;
00173    }
00174    
00175    if (timeout > 0) 
00176       fto = to = timeout;
00177    if (timeout < 0) 
00178       fto = to = 1000000000;
00179 
00180    res = ast_readstring_full(c, s, maxlen, to, fto, "#", audiofd, ctrlfd);
00181 
00182    return res;
00183 }

int ast_app_group_discard ( struct ast_channel chan  ) 

Discard all group counting for a channel.

Definition at line 1042 of file app.c.

References ast_free, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_group_info::chan, chan, and ast_group_info::list.

Referenced by ast_channel_free().

01043 {
01044    struct ast_group_info *gi = NULL;
01045    
01046    AST_RWLIST_WRLOCK(&groups);
01047    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) {
01048       if (gi->chan == chan) {
01049          AST_RWLIST_REMOVE_CURRENT(list);
01050          ast_free(gi);
01051       }
01052    }
01053    AST_RWLIST_TRAVERSE_SAFE_END;
01054    AST_RWLIST_UNLOCK(&groups);
01055    
01056    return 0;
01057 }

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 980 of file app.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strlen_zero(), ast_group_info::category, ast_group_info::group, and ast_group_info::list.

Referenced by group_count_function_read().

00981 {
00982    struct ast_group_info *gi = NULL;
00983    int count = 0;
00984 
00985    if (ast_strlen_zero(group))
00986       return 0;
00987    
00988    AST_RWLIST_RDLOCK(&groups);
00989    AST_RWLIST_TRAVERSE(&groups, gi, list) {
00990       if (!strcasecmp(gi->group, group) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category))))
00991          count++;
00992    }
00993    AST_RWLIST_UNLOCK(&groups);
00994 
00995    return count;
00996 }

struct ast_group_info* ast_app_group_list_head ( void   ) 

Get the head of the group count list.

Definition at line 1069 of file app.c.

References AST_RWLIST_FIRST.

Referenced by group_count_function_read(), group_function_read(), group_list_function_read(), and group_show_channels().

01070 {
01071    return AST_RWLIST_FIRST(&groups);
01072 }

int ast_app_group_list_rdlock ( void   ) 

Read Lock the group count list.

Definition at line 1064 of file app.c.

References AST_RWLIST_RDLOCK.

Referenced by group_count_function_read(), group_function_read(), group_list_function_read(), and group_show_channels().

01065 {
01066    return AST_RWLIST_RDLOCK(&groups);
01067 }

int ast_app_group_list_unlock ( void   ) 

Unlock the group count list.

Definition at line 1074 of file app.c.

References AST_RWLIST_UNLOCK.

Referenced by group_count_function_read(), group_function_read(), group_list_function_read(), and group_show_channels().

01075 {
01076    return AST_RWLIST_UNLOCK(&groups);
01077 }

int ast_app_group_list_wrlock ( void   ) 

Write Lock the group count list.

Definition at line 1059 of file app.c.

References AST_RWLIST_WRLOCK.

01060 {
01061    return AST_RWLIST_WRLOCK(&groups);
01062 }

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 998 of file app.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strlen_zero(), ast_group_info::category, ast_group_info::group, and ast_group_info::list.

Referenced by group_match_count_function_read().

00999 {
01000    struct ast_group_info *gi = NULL;
01001    regex_t regexbuf;
01002    int count = 0;
01003 
01004    if (ast_strlen_zero(groupmatch))
01005       return 0;
01006 
01007    /* if regex compilation fails, return zero matches */
01008    if (regcomp(&regexbuf, groupmatch, REG_EXTENDED | REG_NOSUB))
01009       return 0;
01010 
01011    AST_RWLIST_RDLOCK(&groups);
01012    AST_RWLIST_TRAVERSE(&groups, gi, list) {
01013       if (!regexec(&regexbuf, gi->group, 0, NULL, 0) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category))))
01014          count++;
01015    }
01016    AST_RWLIST_UNLOCK(&groups);
01017 
01018    regfree(&regexbuf);
01019 
01020    return count;
01021 }

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 935 of file app.c.

References ast_app_group_split_group(), AST_RWLIST_INSERT_TAIL, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strlen_zero(), calloc, ast_group_info::category, ast_group_info::chan, chan, free, ast_group_info::group, len(), and ast_group_info::list.

Referenced by dial_exec_full(), and group_function_write().

00936 {
00937    int res = 0;
00938    char group[80] = "", category[80] = "";
00939    struct ast_group_info *gi = NULL;
00940    size_t len = 0;
00941    
00942    if (ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category)))
00943       return -1;
00944    
00945    /* Calculate memory we will need if this is new */
00946    len = sizeof(*gi) + strlen(group) + 1;
00947    if (!ast_strlen_zero(category))
00948       len += strlen(category) + 1;
00949    
00950    AST_RWLIST_WRLOCK(&groups);
00951    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) {
00952       if ((gi->chan == chan) && ((ast_strlen_zero(category) && ast_strlen_zero(gi->category)) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) {
00953          AST_RWLIST_REMOVE_CURRENT(list);
00954          free(gi);
00955          break;
00956       }
00957    }
00958    AST_RWLIST_TRAVERSE_SAFE_END;
00959 
00960    if (ast_strlen_zero(group)) {
00961       /* Enable unsetting the group */
00962    } else if ((gi = calloc(1, len))) {
00963       gi->chan = chan;
00964       gi->group = (char *) gi + sizeof(*gi);
00965       strcpy(gi->group, group);
00966       if (!ast_strlen_zero(category)) {
00967          gi->category = (char *) gi + sizeof(*gi) + strlen(group) + 1;
00968          strcpy(gi->category, category);
00969       }
00970       AST_RWLIST_INSERT_TAIL(&groups, gi, list);
00971    } else {
00972       res = -1;
00973    }
00974    
00975    AST_RWLIST_UNLOCK(&groups);
00976    
00977    return res;
00978 }

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 908 of file app.c.

References ast_copy_string(), and ast_strlen_zero().

Referenced by ast_app_group_set_channel(), group_count_function_read(), and group_match_count_function_read().

00909 {
00910    int res = 0;
00911    char tmp[256];
00912    char *grp = NULL, *cat = NULL;
00913 
00914    if (!ast_strlen_zero(data)) {
00915       ast_copy_string(tmp, data, sizeof(tmp));
00916       grp = tmp;
00917       cat = strchr(tmp, '@');
00918       if (cat) {
00919          *cat = '\0';
00920          cat++;
00921       }
00922    }
00923 
00924    if (!ast_strlen_zero(grp))
00925       ast_copy_string(group, grp, group_max);
00926    else
00927       *group = '\0';
00928 
00929    if (!ast_strlen_zero(cat))
00930       ast_copy_string(category, cat, category_max);
00931 
00932    return res;
00933 }

int ast_app_group_update ( struct ast_channel old,
struct ast_channel new 
)

Update all group counting for a channel to a new one.

Definition at line 1023 of file app.c.

References ast_free, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_group_info::chan, and ast_group_info::list.

Referenced by ast_do_masquerade(), and check_bridge().

01024 {
01025    struct ast_group_info *gi = NULL;
01026 
01027    AST_RWLIST_WRLOCK(&groups);
01028    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) {
01029       if (gi->chan == old) {
01030          gi->chan = new;
01031       } else if (gi->chan == new) {
01032          AST_RWLIST_REMOVE_CURRENT(list);
01033          ast_free(gi);
01034       }
01035    }
01036    AST_RWLIST_TRAVERSE_SAFE_END;
01037    AST_RWLIST_UNLOCK(&groups);
01038 
01039    return 0;
01040 }

int ast_app_has_voicemail ( const char *  mailbox,
const char *  folder 
)

Determine if a given mailbox has any voicemail.

Definition at line 213 of file app.c.

References ast_has_voicemail_func, and ast_verb.

Referenced by action_mailboxstatus(), has_voicemail(), notify_new_message(), play_dialtone(), poll_mailbox(), run_externnotify(), and unistim_send_mwi_to_peer().

00214 {
00215    static int warned = 0;
00216    if (ast_has_voicemail_func)
00217       return ast_has_voicemail_func(mailbox, folder);
00218 
00219    if (!warned) {
00220       ast_verb(3, "Message check requested for mailbox %s/folder %s but voicemail not loaded.\n", mailbox, folder ? folder : "INBOX");
00221       warned++;
00222    }
00223    return 0;
00224 }

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

Determine number of new/old messages in a mailbox.

Definition at line 227 of file app.c.

References ast_inboxcount_func, and ast_verb.

Referenced by sip_send_mwi_to_peer(), and update_registry().

00228 {
00229    static int warned = 0;
00230    if (newmsgs) {
00231       *newmsgs = 0;
00232    }
00233    if (oldmsgs) {
00234       *oldmsgs = 0;
00235    }
00236    if (ast_inboxcount_func) {
00237       return ast_inboxcount_func(mailbox, newmsgs, oldmsgs);
00238    }
00239 
00240    if (!warned) {
00241       warned++;
00242       ast_verb(3, "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox);
00243    }
00244 
00245    return 0;
00246 }

int ast_app_inboxcount2 ( const char *  mailbox,
int *  urgentmsgs,
int *  newmsgs,
int *  oldmsgs 
)

Determine number of urgent/new/old messages in a mailbox.

Parameters:
[in] mailbox the mailbox context to use
[out] urgentmsgs the urgent message count
[out] newmsgs the new message count
[out] oldmsgs the old message count
Returns:
Returns 0 for success, negative upon error
Since:
1.6.1

Definition at line 248 of file app.c.

References ast_inboxcount2_func, ast_inboxcount_func, and ast_verb.

Referenced by action_mailboxcount(), notify_new_message(), and vm_execmain().

00249 {
00250    static int warned = 0;
00251    if (newmsgs) {
00252       *newmsgs = 0;
00253    }
00254    if (oldmsgs) {
00255       *oldmsgs = 0;
00256    }
00257    if (urgentmsgs) {
00258       *urgentmsgs = 0;
00259    }
00260    if (ast_inboxcount_func) {
00261       return ast_inboxcount2_func(mailbox, urgentmsgs, newmsgs, oldmsgs);
00262    }
00263 
00264    if (!warned) {
00265       warned++;
00266       ast_verb(3, "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox);
00267    }
00268 
00269    return 0;
00270 }

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 279 of file app.c.

References ast_messagecount_func, and ast_verb.

Referenced by acf_vmcount_exec().

00280 {
00281    static int warned = 0;
00282    if (ast_messagecount_func)
00283       return ast_messagecount_func(context, mailbox, folder);
00284 
00285    if (!warned) {
00286       warned++;
00287       ast_verb(3, "Message count requested for mailbox %s@%s/%s but voicemail not loaded.\n", mailbox, context, folder);
00288    }
00289 
00290    return 0;
00291 }

void ast_app_options2str64 ( const struct ast_app_option options,
struct ast_flags64 flags,
char *  buf,
size_t  len 
)

Given a list of options array, return an option string based on passed flags.

Parameters:
options The array of possible options declared with AST_APP_OPTIONS
flags The flags of the options that you wish to populate the buffer with
buf The buffer to fill with the string of options
len The maximum length of buf

Definition at line 1755 of file app.c.

References ast_test_flag64.

01756 {
01757    unsigned int i, found = 0;
01758    for (i = 32; i < 128 && found < len; i++) {
01759       if (ast_test_flag64(flags, options[i].flag)) {
01760          buf[found++] = i;
01761       }
01762    }
01763    buf[found] = '\0';
01764 }

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 1679 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 app_exec(), auth_exec(), bridge_exec(), cdr_read(), cdr_write(), chanspy_exec(), conf_exec(), controlplayback_exec(), directory_exec(), disa_exec(), dundi_query_read(), extenspy_exec(), handle_options(), hint_read(), minivm_accmess_exec(), minivm_greet_exec(), minivm_record_exec(), mixmonitor_exec(), page_exec(), park_call_exec(), pbx_builtin_background(), pbx_builtin_resetcdr(), pbx_builtin_waitexten(), read_exec(), readexten_exec(), record_exec(), sendurl_exec(), sla_trunk_exec(), smdi_msg_retrieve_read(), sms_exec(), softhangup_exec(), speech_background(), vm_exec(), and vm_execmain().

01680 {
01681    char *s, *arg;
01682    int curarg, res = 0;
01683    unsigned int argloc;
01684 
01685    ast_clear_flag(flags, AST_FLAGS_ALL);
01686 
01687    if (!optstr)
01688       return 0;
01689 
01690    s = optstr;
01691    while (*s) {
01692       curarg = *s++ & 0x7f;   /* the array (in app.h) has 128 entries */
01693       argloc = options[curarg].arg_index;
01694       if (*s == '(') {
01695          /* Has argument */
01696          arg = ++s;
01697          if ((s = strchr(s, ')'))) {
01698             if (argloc)
01699                args[argloc - 1] = arg;
01700             *s++ = '\0';
01701          } else {
01702             ast_log(LOG_WARNING, "Missing closing parenthesis for argument '%c' in string '%s'\n", curarg, arg);
01703             res = -1;
01704             break;
01705          }
01706       } else if (argloc) {
01707          args[argloc - 1] = "";
01708       }
01709       ast_set_flag(flags, options[curarg].flag);
01710    }
01711 
01712    return res;
01713 }

int ast_app_parse_options64 ( const struct ast_app_option options,
struct ast_flags64 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 64-bit 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 1719 of file app.c.

References ast_app_option::arg_index, ast_log(), ast_set_flag64, ast_flags64::flags, LOG_WARNING, and s.

Referenced by dial_exec_full().

01720 {
01721    char *s, *arg;
01722    int curarg, res = 0;
01723    unsigned int argloc;
01724 
01725    flags->flags = 0;
01726    
01727    if (!optstr)
01728       return 0;
01729 
01730    s = optstr;
01731    while (*s) {
01732       curarg = *s++ & 0x7f;   /* the array (in app.h) has 128 entries */
01733       ast_set_flag64(flags, options[curarg].flag);
01734       argloc = options[curarg].arg_index;
01735       if (*s == '(') {
01736          /* Has argument */
01737          arg = ++s;
01738          if ((s = strchr(s, ')'))) {
01739             if (argloc)
01740                args[argloc - 1] = arg;
01741             *s++ = '\0';
01742          } else {
01743             ast_log(LOG_WARNING, "Missing closing parenthesis for argument '%c' in string '%s'\n", curarg, arg);
01744             res = -1;
01745             break;
01746          }
01747       } else if (argloc) {
01748          args[argloc - 1] = NULL;
01749       }
01750    }
01751 
01752    return res;
01753 }

int ast_app_sayname ( struct ast_channel chan,
const char *  mailbox,
const char *  context 
)

Given a mailbox and context, play that mailbox owner's name to the channel specified.

Parameters:
[in] chan channel to announce name to
[in] mailbox mailbox to retrieve name for
[in] context context to retrieve name for
Returns:
Returns 0 for success, negative upon error
Since:
1.6.1

Definition at line 272 of file app.c.

References ast_sayname_func, and chan.

Referenced by common_exec(), and play_mailbox_owner().

00273 {
00274    if (ast_sayname_func)
00275       return ast_sayname_func(chan, mailbox, context);
00276    return -1;
00277 }

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 1079 of file app.c.

References quote().

Referenced by common_exec(), minivm_accmess_exec(), minivm_greet_exec(), minivm_notify_exec(), minivm_record_exec(), and process_echocancel().

01080 {
01081    int argc;
01082    char *scan, *wasdelim = NULL;
01083    int paren = 0, quote = 0;
01084 
01085    if (!buf || !array || !arraylen)
01086       return 0;
01087 
01088    memset(array, 0, arraylen * sizeof(*array));
01089 
01090    scan = buf;
01091 
01092    for (argc = 0; *scan && (argc < arraylen - 1); argc++) {
01093       array[argc] = scan;
01094       for (; *scan; scan++) {
01095          if (*scan == '(')
01096             paren++;
01097          else if (*scan == ')') {
01098             if (paren)
01099                paren--;
01100          } else if (*scan == '"' && delim != '"') {
01101             quote = quote ? 0 : 1;
01102             /* Remove quote character from argument */
01103             memmove(scan, scan + 1, strlen(scan));
01104             scan--;
01105          } else if (*scan == '\\') {
01106             /* Literal character, don't parse */
01107             memmove(scan, scan + 1, strlen(scan));
01108          } else if ((*scan == delim) && !paren && !quote) {
01109             wasdelim = scan;
01110             *scan++ = '\0';
01111             break;
01112          }
01113       }
01114    }
01115 
01116    /* If the last character in the original string was the delimiter, then
01117     * there is one additional argument. */
01118    if (*scan || (scan > buf && (scan - 1) == wasdelim)) {
01119       array[argc++] = scan;
01120    }
01121 
01122    return argc;
01123 }

void ast_close_fds_above_n ( int  n  ) 

Common routine for child processes, to close all fds prior to exec(2).

Parameters:
[in] n starting file descriptor number for closing all higher file descriptors
Since:
1.6.1

Definition at line 1878 of file app.c.

Referenced by ast_safe_system(), icesencode(), launch_script(), mp3play(), NBScatplay(), send_waveform_to_fd(), spawn_mp3(), spawn_ras(), and vm_check_password_shell().

01879 {
01880    int x, null;
01881    null = open("/dev/null", O_RDONLY);
01882    for (x = n + 1; x <= (null >= 8192 ? null : 8192); x++) {
01883       if (x != null) {
01884          /* Side effect of dup2 is that it closes any existing fd without error.
01885           * This prevents valgrind and other debugging tools from sending up
01886           * false error reports. */
01887          dup2(null, x);
01888          close(x);
01889       }
01890    }
01891    close(null);
01892 }

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,
long *  offsetms 
)

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

Parameters:
chan 
file filename
fwd,rev,stop,pause,restart,skipms,offsetms Before calling this function, set this to be the number of ms to start from the beginning of the file. When the function returns, it will be the number of ms from the beginning where the playback stopped. Pass NULL if you don't care.

Definition at line 460 of file app.c.

References ast_channel::_state, ast_answer(), ast_debug, ast_seekstream(), AST_STATE_UP, ast_stopstream(), ast_streamfile(), ast_tellstream(), ast_verb, ast_waitfordigit(), ast_waitstream_fr(), chan, ast_channel::language, and ast_channel::stream.

Referenced by controlplayback_exec(), handle_controlstreamfile(), and wait_file().

00464 {
00465    char *breaks = NULL;
00466    char *end = NULL;
00467    int blen = 2;
00468    int res;
00469    long pause_restart_point = 0;
00470    long offset = 0;
00471 
00472    if (offsetms) 
00473       offset = *offsetms * 8; /* XXX Assumes 8kHz */
00474 
00475    if (stop)
00476       blen += strlen(stop);
00477    if (suspend)
00478       blen += strlen(suspend);
00479    if (restart)
00480       blen += strlen(restart);
00481 
00482    if (blen > 2) {
00483       breaks = alloca(blen + 1);
00484       breaks[0] = '\0';
00485       if (stop)
00486          strcat(breaks, stop);
00487       if (suspend)
00488          strcat(breaks, suspend);
00489       if (restart)
00490          strcat(breaks, restart);
00491    }
00492    if (chan->_state != AST_STATE_UP)
00493       res = ast_answer(chan);
00494 
00495    if (file) {
00496       if ((end = strchr(file, ':'))) {
00497          if (!strcasecmp(end, ":end")) {
00498             *end = '\0';
00499             end++;
00500          }
00501       }
00502    }
00503 
00504    for (;;) {
00505       ast_stopstream(chan);
00506       res = ast_streamfile(chan, file, chan->language);
00507       if (!res) {
00508          if (pause_restart_point) {
00509             ast_seekstream(chan->stream, pause_restart_point, SEEK_SET);
00510             pause_restart_point = 0;
00511          }
00512          else if (end || offset < 0) {
00513             if (offset == -8) 
00514                offset = 0;
00515             ast_verb(3, "ControlPlayback seek to offset %ld from end\n", offset);
00516 
00517             ast_seekstream(chan->stream, offset, SEEK_END);
00518             end = NULL;
00519             offset = 0;
00520          } else if (offset) {
00521             ast_verb(3, "ControlPlayback seek to offset %ld\n", offset);
00522             ast_seekstream(chan->stream, offset, SEEK_SET);
00523             offset = 0;
00524          };
00525          res = ast_waitstream_fr(chan, breaks, fwd, rev, skipms);
00526       }
00527 
00528       if (res < 1)
00529          break;
00530 
00531       /* We go at next loop if we got the restart char */
00532       if (restart && strchr(restart, res)) {
00533          ast_debug(1, "we'll restart the stream here at next loop\n");
00534          pause_restart_point = 0;
00535          continue;
00536       }
00537 
00538       if (suspend && strchr(suspend, res)) {
00539          pause_restart_point = ast_tellstream(chan->stream);
00540          for (;;) {
00541             ast_stopstream(chan);
00542             res = ast_waitfordigit(chan, 1000);
00543             if (!res)
00544                continue;
00545             else if (res == -1 || strchr(suspend, res) || (stop && strchr(stop, res)))
00546                break;
00547          }
00548          if (res == *suspend) {
00549             res = 0;
00550             continue;
00551          }
00552       }
00553 
00554       if (res == -1)
00555          break;
00556 
00557       /* if we get one of our stop chars, return it to the calling function */
00558       if (stop && strchr(stop, res))
00559          break;
00560    }
00561 
00562    if (pause_restart_point) {
00563       offset = pause_restart_point;
00564    } else {
00565       if (chan->stream) {
00566          offset = ast_tellstream(chan->stream);
00567       } else {
00568          offset = -8;  /* indicate end of file */
00569       }
00570    }
00571 
00572    if (offsetms) 
00573       *offsetms = offset / 8; /* samples --> ms ... XXX Assumes 8 kHz */
00574 
00575    /* If we are returning a digit cast it as char */
00576    if (res > 0 || chan->stream)
00577       res = (char)res;
00578 
00579    ast_stopstream(chan);
00580 
00581    return res;
00582 }

int ast_dtmf_stream ( struct ast_channel chan,
struct ast_channel peer,
const char *  digits,
int  between,
unsigned int  duration 
)

Send DTMF to a channel.

Parameters:
chan The channel that will receive the DTMF frames
peer (optional) Peer channel that will be autoserviced while the primary channel is receiving DTMF
digits This is a string of characters representing the DTMF digits to be sent to the channel. Valid characters are "0123456789*#abcdABCD". Note: You can pass arguments 'f' or 'F', if you want to Flash the channel (if supported by the channel), or 'w' to add a 500 millisecond pause to the DTMF sequence.
between This is the number of milliseconds to wait in between each DTMF digit. If zero milliseconds is specified, then the default value of 100 will be used.
duration This is the duration that each DTMF digit should have.

Definition at line 293 of file app.c.

References ast_autoservice_start(), ast_autoservice_stop(), ast_channel_start_silence_generator(), ast_channel_stop_silence_generator(), AST_CONTROL_FLASH, ast_indicate(), ast_log(), ast_opt_transmit_silence, ast_safe_sleep(), ast_senddigit(), ast_waitfor(), chan, and LOG_WARNING.

Referenced by ast_bridge_call(), dial_exec_full(), handle_cli_misdn_send_digit(), senddtmf_exec(), testclient_exec(), and testserver_exec().

00294 {
00295    const char *ptr;
00296    int res = 0;
00297    struct ast_silence_generator *silgen = NULL;
00298 
00299    if (!between)
00300       between = 100;
00301 
00302    if (peer)
00303       res = ast_autoservice_start(peer);
00304 
00305    if (!res)
00306       res = ast_waitfor(chan, 100);
00307 
00308    /* ast_waitfor will return the number of remaining ms on success */
00309    if (res < 0) {
00310       if (peer) {
00311          ast_autoservice_stop(peer);
00312       }
00313       return res;
00314    }
00315 
00316    if (ast_opt_transmit_silence) {
00317       silgen = ast_channel_start_silence_generator(chan);
00318    }
00319 
00320    for (ptr = digits; *ptr; ptr++) {
00321       if (*ptr == 'w') {
00322          /* 'w' -- wait half a second */
00323          if ((res = ast_safe_sleep(chan, 500)))
00324             break;
00325       } else if (strchr("0123456789*#abcdfABCDF", *ptr)) {
00326          /* Character represents valid DTMF */
00327          if (*ptr == 'f' || *ptr == 'F') {
00328             /* ignore return values if not supported by channel */
00329             ast_indicate(chan, AST_CONTROL_FLASH);
00330          } else
00331             ast_senddigit(chan, *ptr, duration);
00332          /* pause between digits */
00333          if ((res = ast_safe_sleep(chan, between)))
00334             break;
00335       } else
00336          ast_log(LOG_WARNING, "Illegal DTMF character '%c' in string. (0-9*#aAbBcCdD allowed)\n", *ptr);
00337    }
00338 
00339    if (peer) {
00340       /* Stop autoservice on the peer channel, but don't overwrite any error condition 
00341          that has occurred previously while acting on the primary channel */
00342       if (ast_autoservice_stop(peer) && !res)
00343          res = -1;
00344    }
00345 
00346    if (silgen) {
00347       ast_channel_stop_silence_generator(chan, silgen);
00348    }
00349 
00350    return res;
00351 }

int ast_get_encoded_char ( const char *  stream,
char *  result,
size_t *  consumed 
)

Decode an encoded control or extended ASCII character.

Definition at line 1766 of file app.c.

References ast_debug, ast_log(), ast_strlen_zero(), and LOG_ERROR.

Referenced by ast_get_encoded_str(), ast_str_get_encoded_str(), cut_internal(), filter(), and function_fieldqty().

01767 {
01768    int i;
01769    *consumed = 1;
01770    *result = 0;
01771    if (ast_strlen_zero(stream)) {
01772       *consumed = 0;
01773       return -1;
01774    }
01775 
01776    if (*stream == '\\') {
01777       *consumed = 2;
01778       switch (*(stream + 1)) {
01779       case 'n':
01780          *result = '\n';
01781          break;
01782       case 'r':
01783          *result = '\r';
01784          break;
01785       case 't':
01786          *result = '\t';
01787          break;
01788       case 'x':
01789          /* Hexadecimal */
01790          if (strchr("0123456789ABCDEFabcdef", *(stream + 2)) && *(stream + 2) != '\0') {
01791             *consumed = 3;
01792             if (*(stream + 2) <= '9')
01793                *result = *(stream + 2) - '0';
01794             else if (*(stream + 2) <= 'F')
01795                *result = *(stream + 2) - 'A' + 10;
01796             else
01797                *result = *(stream + 2) - 'a' + 10;
01798          } else {
01799             ast_log(LOG_ERROR, "Illegal character '%c' in hexadecimal string\n", *(stream + 2));
01800             return -1;
01801          }
01802 
01803          if (strchr("0123456789ABCDEFabcdef", *(stream + 3)) && *(stream + 3) != '\0') {
01804             *consumed = 4;
01805             *result <<= 4;
01806             if (*(stream + 3) <= '9')
01807                *result += *(stream + 3) - '0';
01808             else if (*(stream + 3) <= 'F')
01809                *result += *(stream + 3) - 'A' + 10;
01810             else
01811                *result += *(stream + 3) - 'a' + 10;
01812          }
01813          break;
01814       case '0':
01815          /* Octal */
01816          *consumed = 2;
01817          for (i = 2; ; i++) {
01818             if (strchr("01234567", *(stream + i)) && *(stream + i) != '\0') {
01819                (*consumed)++;
01820                ast_debug(5, "result was %d, ", *result);
01821                *result <<= 3;
01822                *result += *(stream + i) - '0';
01823                ast_debug(5, "is now %d\n", *result);
01824             } else
01825                break;
01826          }
01827          break;
01828       default:
01829          *result = *(stream + 1);
01830       }
01831    } else {
01832       *result = *stream;
01833       *consumed = 1;
01834    }
01835    return 0;
01836 }

int ast_get_encoded_str ( const char *  stream,
char *  result,
size_t  result_size 
)

Decode a string which may contain multiple encoded control or extended ASCII characters.

Definition at line 1838 of file app.c.

References ast_get_encoded_char().

Referenced by sip_addheader().

01839 {
01840    char *cur = result;
01841    size_t consumed;
01842 
01843    while (cur < result + result_size - 1 && !ast_get_encoded_char(stream, cur, &consumed)) {
01844       cur++;
01845       stream += consumed;
01846    }
01847    *cur = '\0';
01848    return 0;
01849 }

void ast_install_vm_functions ( int(*)(const char *mailbox, const char *folder)  has_voicemail_func,
int(*)(const char *mailbox, int *newmsgs, int *oldmsgs)  inboxcount_func,
int(*)(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)  inboxcount2_func,
int(*)(const char *context, const char *mailbox, const char *folder)  messagecount_func,
int(*)(struct ast_channel *chan, const char *mailbox, const char *context sayname_func 
)

Set voicemail function callbacks.

Parameters:
[in] inboxcount2_func set function pointer
[in] sayname_func set function pointer
[in] inboxcount_func set function pointer
[in] messagecount_func set function pointer
Version:
1.6.1 Added inboxcount2_func, sayname_func

Definition at line 191 of file app.c.

References ast_has_voicemail_func, ast_inboxcount2_func, ast_inboxcount_func, ast_messagecount_func, and ast_sayname_func.

Referenced by load_module().

00196 {
00197    ast_has_voicemail_func = has_voicemail_func;
00198    ast_inboxcount_func = inboxcount_func;
00199    ast_inboxcount2_func = inboxcount2_func;
00200    ast_messagecount_func = messagecount_func;
00201    ast_sayname_func = sayname_func;
00202 }

int ast_ivr_menu_run ( struct ast_channel c,
struct ast_ivr_menu menu,
void *  cbdata 
)

Runs an IVR menu.

Returns:
returns 0 on successful completion, -1 on hangup, or -2 on user error in menu

Definition at line 1638 of file app.c.

References ast_ivr_menu_run_internal(), and chan.

Referenced by skel_exec().

01639 {
01640    int res = ast_ivr_menu_run_internal(chan, menu, cbdata);
01641    /* Hide internal coding */
01642    return res > 0 ? 0 : res;
01643 }

static int ast_ivr_menu_run_internal ( struct ast_channel chan,
struct ast_ivr_menu menu,
void *  cbdata 
) [static]

Definition at line 1558 of file app.c.

References ast_debug, AST_DIGIT_ANY, ast_log(), AST_MAX_EXTENSION, chan, exten, ivr_dispatch(), LOG_WARNING, maxretries, ast_ivr_option::option, option_exists(), ast_ivr_menu::options, read_newoption(), RES_EXIT, RES_REPEAT, RES_RESTART, RES_UPONE, and ast_ivr_menu::title.

Referenced by ast_ivr_menu_run(), and ivr_dispatch().

01559 {
01560    /* Execute an IVR menu structure */
01561    int res = 0;
01562    int pos = 0;
01563    int retries = 0;
01564    char exten[AST_MAX_EXTENSION] = "s";
01565    if (option_exists(menu, "s") < 0) {
01566       strcpy(exten, "g");
01567       if (option_exists(menu, "g") < 0) {
01568          ast_log(LOG_WARNING, "No 's' nor 'g' extension in menu '%s'!\n", menu->title);
01569          return -1;
01570       }
01571    }
01572    while (!res) {
01573       while (menu->options[pos].option) {
01574          if (!strcasecmp(menu->options[pos].option, exten)) {
01575             res = ivr_dispatch(chan, menu->options + pos, exten, cbdata);
01576             ast_debug(1, "IVR Dispatch of '%s' (pos %d) yields %d\n", exten, pos, res);
01577             if (res < 0)
01578                break;
01579             else if (res & RES_UPONE)
01580                return 0;
01581             else if (res & RES_EXIT)
01582                return res;
01583             else if (res & RES_REPEAT) {
01584                int maxretries = res & 0xffff;
01585                if ((res & RES_RESTART) == RES_RESTART) {
01586                   retries = 0;
01587                } else
01588                   retries++;
01589                if (!maxretries)
01590                   maxretries = 3;
01591                if ((maxretries > 0) && (retries >= maxretries)) {
01592                   ast_debug(1, "Max retries %d exceeded\n", maxretries);
01593                   return -2;
01594                } else {
01595                   if (option_exists(menu, "g") > -1) 
01596                      strcpy(exten, "g");
01597                   else if (option_exists(menu, "s") > -1)
01598                      strcpy(exten, "s");
01599                }
01600                pos = 0;
01601                continue;
01602             } else if (res && strchr(AST_DIGIT_ANY, res)) {
01603                ast_debug(1, "Got start of extension, %c\n", res);
01604                exten[1] = '\0';
01605                exten[0] = res;
01606                if ((res = read_newoption(chan, menu, exten, sizeof(exten))))
01607                   break;
01608                if (option_exists(menu, exten) < 0) {
01609                   if (option_exists(menu, "i")) {
01610                      ast_debug(1, "Invalid extension entered, going to 'i'!\n");
01611                      strcpy(exten, "i");
01612                      pos = 0;
01613                      continue;
01614                   } else {
01615                      ast_debug(1, "Aborting on invalid entry, with no 'i' option!\n");
01616                      res = -2;
01617                      break;
01618                   }
01619                } else {
01620                   ast_debug(1, "New existing extension: %s\n", exten);
01621                   pos = 0;
01622                   continue;
01623                }
01624             }
01625          }
01626          pos++;
01627       }
01628       ast_debug(1, "Stopping option '%s', res is %d\n", exten, res);
01629       pos = 0;
01630       if (!strcasecmp(exten, "s"))
01631          strcpy(exten, "g");
01632       else
01633          break;
01634    }
01635    return res;
01636 }

int ast_linear_stream ( struct ast_channel chan,
const char *  filename,
int  fd,
int  allowoverride 
)

Stream a filename (or file descriptor) as a generator.

Definition at line 432 of file app.c.

References ast_activate_generator(), ast_calloc, ast_config_AST_DATA_DIR, ast_copy_string(), ast_log(), ast_strlen_zero(), linear_state::autoclose, chan, errno, linearstream, and LOG_WARNING.

00433 {
00434    struct linear_state *lin;
00435    char tmpf[256];
00436    int res = -1;
00437    int autoclose = 0;
00438    if (fd < 0) {
00439       if (ast_strlen_zero(filename))
00440          return -1;
00441       autoclose = 1;
00442       if (filename[0] == '/') 
00443          ast_copy_string(tmpf, filename, sizeof(tmpf));
00444       else
00445          snprintf(tmpf, sizeof(tmpf), "%s/%s/%s", ast_config_AST_DATA_DIR, "sounds", filename);
00446       if ((fd = open(tmpf, O_RDONLY)) < 0) {
00447          ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", tmpf, strerror(errno));
00448          return -1;
00449       }
00450    }
00451    if ((lin = ast_calloc(1, sizeof(*lin)))) {
00452       lin->fd = fd;
00453       lin->allowoverride = allowoverride;
00454       lin->autoclose = autoclose;
00455       res = ast_activate_generator(chan, &linearstream, lin);
00456    }
00457    return res;
00458 }

enum AST_LOCK_RESULT ast_lock_path ( const char *  path  ) 

Lock a filesystem path.

Parameters:
path the path to be locked
Returns:
one of AST_LOCK_RESULT values

Definition at line 1317 of file app.c.

References AST_LOCK_FAILURE, ast_lock_path_flock(), ast_lock_path_lockfile(), AST_LOCK_TYPE_FLOCK, and AST_LOCK_TYPE_LOCKFILE.

Referenced by vm_lock_path().

01318 {
01319    enum AST_LOCK_RESULT r = AST_LOCK_FAILURE;
01320 
01321    switch (ast_lock_type) {
01322    case AST_LOCK_TYPE_LOCKFILE:
01323       r = ast_lock_path_lockfile(path);
01324       break;
01325    case AST_LOCK_TYPE_FLOCK:
01326       r = ast_lock_path_flock(path);
01327       break;
01328    }
01329 
01330    return r;
01331 }

static enum AST_LOCK_RESULT ast_lock_path_flock ( const char *  path  )  [static]

Definition at line 1196 of file app.c.

References ast_calloc, ast_debug, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, AST_LOCK_FAILURE, AST_LOCK_PATH_NOT_FOUND, AST_LOCK_SUCCESS, AST_LOCK_TIMEOUT, ast_log(), errno, path_lock::fd, path_lock::le, LOG_WARNING, path_lock_destroy(), and strdup.

Referenced by ast_lock_path().

01197 {
01198    char *fs;
01199    int res;
01200    int fd;
01201    time_t start;
01202    struct path_lock *pl;
01203    struct stat st, ost;
01204 
01205    fs = alloca(strlen(path) + 20);
01206 
01207    snprintf(fs, strlen(path) + 19, "%s/lock", path);
01208    if (lstat(fs, &st) == 0) {
01209       if ((st.st_mode & S_IFMT) == S_IFLNK) {
01210          ast_log(LOG_WARNING, "Unable to create lock file "
01211                "'%s': it's already a symbolic link\n",
01212                fs);
01213          return AST_LOCK_FAILURE;
01214       }
01215       if (st.st_nlink > 1) {
01216          ast_log(LOG_WARNING, "Unable to create lock file "
01217                "'%s': %u hard links exist\n",
01218                fs, (unsigned int) st.st_nlink);
01219          return AST_LOCK_FAILURE;
01220       }
01221    }
01222    fd = open(fs, O_WRONLY | O_CREAT, 0600);
01223    if (fd < 0) {
01224       ast_log(LOG_WARNING, "Unable to create lock file '%s': %s\n",
01225             fs, strerror(errno));
01226       return AST_LOCK_PATH_NOT_FOUND;
01227    }
01228    pl = ast_calloc(1, sizeof(*pl));
01229    if (!pl) {
01230       /* We don't unlink the lock file here, on the possibility that
01231        * someone else created it - better to leave a little mess
01232        * than create a big one by destroying someone else's lock
01233        * and causing something to be corrupted.
01234        */
01235       close(fd);
01236       return AST_LOCK_FAILURE;
01237    }
01238    pl->fd = fd;
01239    pl->path = strdup(path);
01240 
01241    time(&start);
01242    while ((
01243       #ifdef SOLARIS
01244       (res = fcntl(pl->fd, F_SETLK, fcntl(pl->fd, F_GETFL) | O_NONBLOCK)) < 0) &&
01245       #else
01246       (res = flock(pl->fd, LOCK_EX | LOCK_NB)) < 0) &&
01247       #endif
01248          (errno == EWOULDBLOCK) && 
01249          (time(NULL) - start < 5))
01250       usleep(1000);
01251    if (res) {
01252       ast_log(LOG_WARNING, "Failed to lock path '%s': %s\n",
01253             path, strerror(errno));
01254       /* No unlinking of lock done, since we tried and failed to
01255        * flock() it.
01256        */
01257       path_lock_destroy(pl);
01258       return AST_LOCK_TIMEOUT;
01259    }
01260 
01261    /* Check for the race where the file is recreated or deleted out from
01262     * underneath us.
01263     */
01264    if (lstat(fs, &st) != 0 && fstat(pl->fd, &ost) != 0 &&
01265          st.st_dev != ost.st_dev &&
01266          st.st_ino != ost.st_ino) {
01267       ast_log(LOG_WARNING, "Unable to create lock file '%s': "
01268             "file changed underneath us\n", fs);
01269       path_lock_destroy(pl);
01270       return AST_LOCK_FAILURE;
01271    }
01272 
01273    /* Success: file created, flocked, and is the one we started with */
01274    AST_LIST_LOCK(&path_lock_list);
01275    AST_LIST_INSERT_TAIL(&path_lock_list, pl, le);
01276    AST_LIST_UNLOCK(&path_lock_list);
01277 
01278    ast_debug(1, "Locked path '%s'\n", path);
01279 
01280    return AST_LOCK_SUCCESS;
01281 }

static enum AST_LOCK_RESULT ast_lock_path_lockfile ( const char *  path  )  [static]

Definition at line 1125 of file app.c.

References ast_debug, AST_FILE_MODE, AST_LOCK_PATH_NOT_FOUND, AST_LOCK_SUCCESS, AST_LOCK_TIMEOUT, ast_log(), ast_random(), errno, LOG_ERROR, LOG_WARNING, and s.

Referenced by ast_lock_path().

01126 {
01127    char *s;
01128    char *fs;
01129    int res;
01130    int fd;
01131    int lp = strlen(path);
01132    time_t start;
01133 
01134    s = alloca(lp + 10); 
01135    fs = alloca(lp + 20);
01136 
01137    snprintf(fs, strlen(path) + 19, "%s/.lock-%08lx", path, ast_random());
01138    fd = open(fs, O_WRONLY | O_CREAT | O_EXCL, AST_FILE_MODE);
01139    if (fd < 0) {
01140       ast_log(LOG_ERROR, "Unable to create lock file '%s': %s\n", path, strerror(errno));
01141       return AST_LOCK_PATH_NOT_FOUND;
01142    }
01143    close(fd);
01144 
01145    snprintf(s, strlen(path) + 9, "%s/.lock", path);
01146    start = time(NULL);
01147    while (((res = link(fs, s)) < 0) && (errno == EEXIST) && (time(NULL) - start < 5))
01148       usleep(1);
01149 
01150    unlink(fs);
01151 
01152    if (res) {
01153       ast_log(LOG_WARNING, "Failed to lock path '%s': %s\n", path, strerror(errno));
01154       return AST_LOCK_TIMEOUT;
01155    } else {
01156       ast_debug(1, "Locked path '%s'\n", path);
01157       return AST_LOCK_SUCCESS;
01158    }
01159 }

int ast_play_and_prepend ( struct ast_channel chan,
char *  playfile,
char *  recordfile,
int  maxtime,
char *  fmt,
int *  duration,
int  beep,
int  silencethreshold,
int  maxsilence 
)

Record a message and prepend the message to the given record file after playing the optional playfile (or a beep), storing the duration in 'duration' and with a maximum permitted silence time in milliseconds of 'maxsilence' under 'silencethreshold' or use '-1' for either or both parameters for defaults.

Definition at line 901 of file app.c.

References __ast_play_and_record(), and chan.

Referenced by vm_forwardoptions().

00902 {
00903    return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, beep, silencethreshold, maxsilence, NULL, 1, default_acceptdtmf, default_canceldtmf);
00904 }

int ast_play_and_record ( struct ast_channel chan,
const char *  playfile,
const char *  recordfile,
int  maxtime,
const char *  fmt,
int *  duration,
int  silencethreshold,
int  maxsilence,
const char *  path 
)

Record a file for a max amount of time (in seconds), in a given list of formats separated by '|', outputting the duration of the recording, and with a maximum
permitted silence time in milliseconds of 'maxsilence' under 'silencethreshold' or use '-1' for either or both parameters for defaults. calls ast_unlock_path() on 'path' if passed.

Definition at line 896 of file app.c.

References __ast_play_and_record(), and chan.

Referenced by app_exec(), ast_record_review(), conf_run(), and setup_privacy_args().

00897 {
00898    return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, 0, silencethreshold, maxsilence, path, 0, default_acceptdtmf, default_canceldtmf);
00899 }

int ast_play_and_record_full ( struct ast_channel chan,
const char *  playfile,
const char *  recordfile,
int  maxtime,
const char *  fmt,
int *  duration,
int  silencethreshold,
int  maxsilence,
const char *  path,
const char *  acceptdtmf,
const char *  canceldtmf 
)

Definition at line 891 of file app.c.

References __ast_play_and_record(), chan, and S_OR.

Referenced by play_record_review().

00892 {
00893    return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, 0, silencethreshold, maxsilence, path, 0, S_OR(acceptdtmf, default_acceptdtmf), S_OR(canceldtmf, default_canceldtmf));
00894 }

int ast_play_and_wait ( struct ast_channel chan,
const char *  fn 
)

Play a stream and wait for a digit, returning the digit that was pressed.

Definition at line 584 of file app.c.

References AST_DIGIT_ANY, ast_stopstream(), ast_streamfile(), ast_waitstream(), chan, and ast_channel::language.

Referenced by __ast_play_and_record(), advanced_options(), ast_record_review(), ast_say_counted_adjective(), ast_say_counted_noun(), dialout(), forward_message(), get_folder(), get_folder2(), leave_voicemail(), minivm_greet_exec(), play_message_category(), play_message_duration(), play_record_review(), vm_authenticate(), vm_browse_messages_en(), vm_browse_messages_es(), vm_browse_messages_gr(), vm_browse_messages_he(), vm_browse_messages_it(), vm_browse_messages_pt(), vm_browse_messages_tw(), vm_execmain(), vm_forwardoptions(), vm_instructions_en(), vm_instructions_tw(), vm_intro(), vm_intro_cz(), vm_intro_de(), vm_intro_en(), vm_intro_es(), vm_intro_fr(), vm_intro_gr(), vm_intro_he(), vm_intro_it(), vm_intro_multilang(), vm_intro_nl(), vm_intro_no(), vm_intro_pl(), vm_intro_pt(), vm_intro_pt_BR(), vm_intro_se(), vm_intro_tw(), vm_newuser(), vm_options(), vm_play_folder_name(), vm_play_folder_name_gr(), vm_play_folder_name_pl(), vm_play_folder_name_ua(), vm_tempgreeting(), and vmauthenticate().

00585 {
00586    int d = 0;
00587 
00588    if ((d = ast_streamfile(chan, fn, chan->language)))
00589       return d;
00590 
00591    d = ast_waitstream(chan, AST_DIGIT_ANY);
00592 
00593    ast_stopstream(chan);
00594 
00595    return d;
00596 }

char* ast_read_textfile ( const char *  filename  ) 

Read a file into asterisk.

Definition at line 1645 of file app.c.

References ast_free, ast_log(), ast_malloc, errno, path_lock::fd, and LOG_WARNING.

Referenced by file_read(), and readfile_exec().

01646 {
01647    int fd, count = 0, res;
01648    char *output = NULL;
01649    struct stat filesize;
01650 
01651    if (stat(filename, &filesize) == -1) {
01652       ast_log(LOG_WARNING, "Error can't stat %s\n", filename);
01653       return NULL;
01654    }
01655 
01656    count = filesize.st_size + 1;
01657 
01658    if ((fd = open(filename, O_RDONLY)) < 0) {
01659       ast_log(LOG_WARNING, "Cannot open file '%s' for reading: %s\n", filename, strerror(errno));
01660       return NULL;
01661    }
01662 
01663    if ((output = ast_malloc(count))) {
01664       res = read(fd, output, count - 1);
01665       if (res == count - 1) {
01666          output[res] = '\0';
01667       } else {
01668          ast_log(LOG_WARNING, "Short read of %s (%d of %d): %s\n", filename, res, count - 1, strerror(errno));
01669          ast_free(output);
01670          output = NULL;
01671       }
01672    }
01673 
01674    close(fd);
01675 
01676    return output;
01677 }

int ast_record_review ( struct ast_channel chan,
const char *  playfile,
const char *  recordfile,
int  maxtime,
const char *  fmt,
int *  duration,
const char *  path 
)

Allow to record message and have a review option.

Definition at line 1349 of file app.c.

References AST_DIGIT_ANY, ast_dsp_get_threshold_from_settings(), ast_log(), ast_play_and_record(), ast_play_and_wait(), ast_stream_and_wait(), ast_verb, ast_waitfordigit(), chan, LOG_WARNING, maxsilence, silencethreshold, and THRESHOLD_SILENCE.

Referenced by conf_run().

01350 {
01351    int silencethreshold; 
01352    int maxsilence = 0;
01353    int res = 0;
01354    int cmd = 0;
01355    int max_attempts = 3;
01356    int attempts = 0;
01357    int recorded = 0;
01358    int message_exists = 0;
01359    /* Note that urgent and private are for flagging messages as such in the future */
01360 
01361    /* barf if no pointer passed to store duration in */
01362    if (!duration) {
01363       ast_log(LOG_WARNING, "Error ast_record_review called without duration pointer\n");
01364       return -1;
01365    }
01366 
01367    cmd = '3';   /* Want to start by recording */
01368 
01369    silencethreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE);
01370 
01371    while ((cmd >= 0) && (cmd != 't')) {
01372       switch (cmd) {
01373       case '1':
01374          if (!message_exists) {
01375             /* In this case, 1 is to record a message */
01376             cmd = '3';
01377             break;
01378          } else {
01379             ast_stream_and_wait(chan, "vm-msgsaved", "");
01380             cmd = 't';
01381             return res;
01382          }
01383       case '2':
01384          /* Review */
01385          ast_verb(3, "Reviewing the recording\n");
01386          cmd = ast_stream_and_wait(chan, recordfile, AST_DIGIT_ANY);
01387          break;
01388       case '3':
01389          message_exists = 0;
01390          /* Record */
01391          if (recorded == 1)
01392             ast_verb(3, "Re-recording\n");
01393          else  
01394             ast_verb(3, "Recording\n");
01395          recorded = 1;
01396          cmd = ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, silencethreshold, maxsilence, path);
01397          if (cmd == -1) {
01398          /* User has hung up, no options to give */
01399             return cmd;
01400          }
01401          if (cmd == '0') {
01402             break;
01403          } else if (cmd == '*') {
01404             break;
01405          } 
01406          else {
01407             /* If all is well, a message exists */
01408             message_exists = 1;
01409             cmd = 0;
01410          }
01411          break;
01412       case '4':
01413       case '5':
01414       case '6':
01415       case '7':
01416       case '8':
01417       case '9':
01418       case '*':
01419       case '#':
01420          cmd = ast_play_and_wait(chan, "vm-sorry");
01421          break;
01422       default:
01423          if (message_exists) {
01424             cmd = ast_play_and_wait(chan, "vm-review");
01425          }
01426          else {
01427             cmd = ast_play_and_wait(chan, "vm-torerecord");
01428             if (!cmd)
01429                cmd = ast_waitfordigit(chan, 600);
01430          }
01431          
01432          if (!cmd)
01433             cmd = ast_waitfordigit(chan, 6000);
01434          if (!cmd) {
01435             attempts++;
01436          }
01437          if (attempts > max_attempts) {
01438             cmd = 't';
01439          }
01440       }
01441    }
01442    if (cmd == 't')
01443       cmd = 0;
01444    return cmd;
01445 }

int ast_safe_fork ( int  stop_reaper  ) 

Common routine to safely fork without a chance of a signal handler firing badly in the child.

Parameters:
[in] stop_reaper flag to determine if sigchld handler is replaced or not
Since:
1.6.1

Definition at line 1894 of file app.c.

References ast_log(), ast_replace_sigchld(), errno, and LOG_WARNING.

Referenced by icesencode(), launch_script(), mp3play(), NBScatplay(), send_waveform_to_fd(), spawn_mp3(), spawn_ras(), statpost(), and vm_check_password_shell().

01895 {
01896    sigset_t signal_set, old_set;
01897    int pid;
01898 
01899    /* Don't let the default signal handler for children reap our status */
01900    if (stop_reaper) {
01901       ast_replace_sigchld();
01902    }
01903 
01904    sigfillset(&signal_set);
01905    pthread_sigmask(SIG_BLOCK, &signal_set, &old_set);
01906 
01907    pid = fork();
01908 
01909    if (pid != 0) {
01910       /* Fork failed or parent */
01911       pthread_sigmask(SIG_SETMASK, &old_set, NULL);
01912       return pid;
01913    } else {
01914       /* Child */
01915 #ifdef HAVE_CAP
01916       cap_t cap = cap_from_text("cap_net_admin-eip");
01917 
01918       if (cap_set_proc(cap)) {
01919          ast_log(LOG_WARNING, "Unable to remove capabilities.\n");
01920       }
01921       cap_free(cap);
01922 #endif
01923 
01924       /* Before we unblock our signals, return our trapped signals back to the defaults */
01925       signal(SIGHUP, SIG_DFL);
01926       signal(SIGCHLD, SIG_DFL);
01927       signal(SIGINT, SIG_DFL);
01928       signal(SIGURG, SIG_DFL);
01929       signal(SIGTERM, SIG_DFL);
01930       signal(SIGPIPE, SIG_DFL);
01931       signal(SIGXFSZ, SIG_DFL);
01932 
01933       /* unblock important signal handlers */
01934       if (pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL)) {
01935          ast_log(LOG_WARNING, "unable to unblock signals: %s\n", strerror(errno));
01936          _exit(1);
01937       }
01938 
01939       return pid;
01940    }
01941 }

void ast_safe_fork_cleanup ( void   ) 

Common routine to cleanup after fork'ed process is complete (if reaping was stopped).

Since:
1.6.1

Definition at line 1943 of file app.c.

References ast_unreplace_sigchld().

Referenced by agi_exec_full(), and run_ras().

01944 {
01945    ast_unreplace_sigchld();
01946 }

void ast_set_lock_type ( enum AST_LOCK_TYPE  type  ) 

Set the type of locks used by ast_lock_path().

Parameters:
type the locking type to use

Definition at line 1312 of file app.c.

01313 {
01314    ast_lock_type = type;
01315 }

int ast_str_get_encoded_str ( struct ast_str **  str,
int  maxlen,
const char *  stream 
)

Decode a stream of encoded control or extended ASCII characters.

Definition at line 1851 of file app.c.

References ast_get_encoded_char(), ast_str_buffer, ast_str_make_space(), ast_str_set(), ast_str_size, ast_str_update, buf, path_lock::next, and str.

Referenced by system_exec_helper().

01852 {
01853    char next, *buf;
01854    size_t offset = 0;
01855    size_t consumed;
01856 
01857    if (strchr(stream, '\\')) {
01858       while (!ast_get_encoded_char(stream, &next, &consumed)) {
01859          if (offset + 2 > ast_str_size(*str) && maxlen > -1) {
01860             ast_str_make_space(str, maxlen > 0 ? maxlen : (ast_str_size(*str) + 48) * 2 - 48);
01861          }
01862          if (offset + 2 > ast_str_size(*str)) {
01863             break;
01864          }
01865          buf = ast_str_buffer(*str);
01866          buf[offset++] = next;
01867          stream += consumed;
01868       }
01869       buf = ast_str_buffer(*str);
01870       buf[offset++] = '\0';
01871       ast_str_update(*str);
01872    } else {
01873       ast_str_set(str, maxlen, "%s", stream);
01874    }
01875    return 0;
01876 }

void ast_uninstall_vm_functions ( void   ) 

Definition at line 204 of file app.c.

References ast_has_voicemail_func, ast_inboxcount2_func, ast_inboxcount_func, ast_messagecount_func, and ast_sayname_func.

Referenced by unload_module().

00205 {
00206    ast_has_voicemail_func = NULL;
00207    ast_inboxcount_func = NULL;
00208    ast_inboxcount2_func = NULL;
00209    ast_messagecount_func = NULL;
00210    ast_sayname_func = NULL;
00211 }

int ast_unlock_path ( const char *  path  ) 

Unlock a path.

Definition at line 1333 of file app.c.

References AST_LOCK_TYPE_FLOCK, AST_LOCK_TYPE_LOCKFILE, ast_unlock_path_flock(), and ast_unlock_path_lockfile().

Referenced by __ast_play_and_record(), access_counter_file(), copy_message(), count_messages(), leave_voicemail(), open_mailbox(), and save_to_folder().

01334 {
01335    int r = 0;
01336 
01337    switch (ast_lock_type) {
01338    case AST_LOCK_TYPE_LOCKFILE:
01339       r = ast_unlock_path_lockfile(path);
01340       break;
01341    case AST_LOCK_TYPE_FLOCK:
01342       r = ast_unlock_path_flock(path);
01343       break;
01344    }
01345 
01346    return r;
01347 }

static int ast_unlock_path_flock ( const char *  path  )  [static]

Definition at line 1283 of file app.c.

References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log(), path_lock::le, LOG_DEBUG, path_lock::path, path_lock_destroy(), and s.

Referenced by ast_unlock_path().

01284 {
01285    char *s;
01286    struct path_lock *p;
01287 
01288    s = alloca(strlen(path) + 20);
01289 
01290    AST_LIST_LOCK(&path_lock_list);
01291    AST_LIST_TRAVERSE_SAFE_BEGIN(&path_lock_list, p, le) {
01292       if (!strcmp(p->path, path)) {
01293          AST_LIST_REMOVE_CURRENT(le);
01294          break;
01295       }
01296    }
01297    AST_LIST_TRAVERSE_SAFE_END;
01298    AST_LIST_UNLOCK(&path_lock_list);
01299 
01300    if (p) {
01301       snprintf(s, strlen(path) + 19, "%s/lock", path);
01302       unlink(s);
01303       path_lock_destroy(p);
01304       ast_log(LOG_DEBUG, "Unlocked path '%s'\n", path);
01305    } else
01306       ast_log(LOG_DEBUG, "Failed to unlock path '%s': "
01307             "lock not found\n", path);
01308 
01309    return 0;
01310 }

static int ast_unlock_path_lockfile ( const char *  path  )  [static]

Definition at line 1161 of file app.c.

References ast_debug, ast_log(), errno, LOG_ERROR, and s.

Referenced by ast_unlock_path().

01162 {
01163    char *s;
01164    int res;
01165 
01166    s = alloca(strlen(path) + 10);
01167 
01168    snprintf(s, strlen(path) + 9, "%s/%s", path, ".lock");
01169 
01170    if ((res = unlink(s)))
01171       ast_log(LOG_ERROR, "Could not unlock path '%s': %s\n", path, strerror(errno));
01172    else {
01173       ast_debug(1, "Unlocked path '%s'\n", path);
01174    }
01175 
01176    return res;
01177 }

static int ivr_dispatch ( struct ast_channel chan,
struct ast_ivr_option option,
char *  exten,
void *  cbdata 
) [static]

Definition at line 1454 of file app.c.

References ast_ivr_option::action, ast_ivr_option::adata, AST_ACTION_BACKGROUND, AST_ACTION_BACKLIST, AST_ACTION_CALLBACK, AST_ACTION_EXIT, AST_ACTION_MENU, AST_ACTION_NOOP, AST_ACTION_PLAYBACK, AST_ACTION_PLAYLIST, AST_ACTION_REPEAT, AST_ACTION_RESTART, AST_ACTION_TRANSFER, AST_ACTION_UPONE, AST_ACTION_WAITOPTION, AST_DIGIT_ANY, ast_ivr_menu_run_internal(), ast_log(), ast_parseable_goto(), ast_stopstream(), ast_strdupa, ast_stream_and_wait(), ast_waitfordigit(), chan, LOG_NOTICE, ast_channel::pbx, RES_EXIT, RES_REPEAT, RES_RESTART, RES_UPONE, ast_pbx::rtimeoutms, and strsep().

Referenced by ast_ivr_menu_run_internal().

01455 {
01456    int res;
01457    int (*ivr_func)(struct ast_channel *, void *);
01458    char *c;
01459    char *n;
01460    
01461    switch (option->action) {
01462    case AST_ACTION_UPONE:
01463       return RES_UPONE;
01464    case AST_ACTION_EXIT:
01465       return RES_EXIT | (((unsigned long)(option->adata)) & 0xffff);
01466    case AST_ACTION_REPEAT:
01467       return RES_REPEAT | (((unsigned long)(option->adata)) & 0xffff);
01468    case AST_ACTION_RESTART:
01469       return RES_RESTART ;
01470    case AST_ACTION_NOOP:
01471       return 0;
01472    case AST_ACTION_BACKGROUND:
01473       res = ast_stream_and_wait(chan, (char *)option->adata, AST_DIGIT_ANY);
01474       if (res < 0) {
01475          ast_log(LOG_NOTICE, "Unable to find file '%s'!\n", (char *)option->adata);
01476          res = 0;
01477       }
01478       return res;
01479    case AST_ACTION_PLAYBACK:
01480       res = ast_stream_and_wait(chan, (char *)option->adata, "");
01481       if (res < 0) {
01482          ast_log(LOG_NOTICE, "Unable to find file '%s'!\n", (char *)option->adata);
01483          res = 0;
01484       }
01485       return res;
01486    case AST_ACTION_MENU:
01487       res = ast_ivr_menu_run_internal(chan, (struct ast_ivr_menu *)option->adata, cbdata);
01488       /* Do not pass entry errors back up, treat as though it was an "UPONE" */
01489       if (res == -2)
01490          res = 0;
01491       return res;
01492    case AST_ACTION_WAITOPTION:
01493       res = ast_waitfordigit(chan, chan->pbx ? chan->pbx->rtimeoutms : 10000);
01494       if (!res)
01495          return 't';
01496       return res;
01497    case AST_ACTION_CALLBACK:
01498       ivr_func = option->adata;
01499       res = ivr_func(chan, cbdata);
01500       return res;
01501    case AST_ACTION_TRANSFER:
01502       res = ast_parseable_goto(chan, option->adata);
01503       return 0;
01504    case AST_ACTION_PLAYLIST:
01505    case AST_ACTION_BACKLIST:
01506       res = 0;
01507       c = ast_strdupa(option->adata);
01508       while ((n = strsep(&c, ";"))) {
01509          if ((res = ast_stream_and_wait(chan, n,
01510                (option->action == AST_ACTION_BACKLIST) ? AST_DIGIT_ANY : "")))
01511             break;
01512       }
01513       ast_stopstream(chan);
01514       return res;
01515    default:
01516       ast_log(LOG_NOTICE, "Unknown dispatch function %d, ignoring!\n", option->action);
01517       return 0;
01518    };
01519    return -1;
01520 }

static void* linear_alloc ( struct ast_channel chan,
void *  params 
) [static]

Definition at line 401 of file app.c.

References linear_state::allowoverride, ast_clear_flag, AST_FLAG_WRITE_INT, AST_FORMAT_SLINEAR, ast_free, ast_log(), ast_set_flag, ast_set_write_format(), chan, LOG_WARNING, ast_channel::name, linear_state::origwfmt, and ast_channel::writeformat.

00402 {
00403    struct linear_state *ls = params;
00404 
00405    if (!params)
00406       return NULL;
00407 
00408    /* In this case, params is already malloc'd */
00409    if (ls->allowoverride)
00410       ast_set_flag(chan, AST_FLAG_WRITE_INT);
00411    else
00412       ast_clear_flag(chan, AST_FLAG_WRITE_INT);
00413 
00414    ls->origwfmt = chan->writeformat;
00415 
00416    if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) {
00417       ast_log(LOG_WARNING, "Unable to set '%s' to linear format (write)\n", chan->name);
00418       ast_free(ls);
00419       ls = params = NULL;
00420    }
00421 
00422    return params;
00423 }

static int linear_generator ( struct ast_channel chan,
void *  data,
int  len,
int  samples 
) [static]

Definition at line 373 of file app.c.

References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_write(), buf, chan, f, linear_state::fd, and LOG_WARNING.

00374 {
00375    short buf[2048 + AST_FRIENDLY_OFFSET / 2];
00376    struct linear_state *ls = data;
00377    struct ast_frame f = {
00378       .frametype = AST_FRAME_VOICE,
00379       .subclass = AST_FORMAT_SLINEAR,
00380       .data.ptr = buf + AST_FRIENDLY_OFFSET / 2,
00381       .offset = AST_FRIENDLY_OFFSET,
00382    };
00383    int res;
00384 
00385    len = samples * 2;
00386    if (len > sizeof(buf) - AST_FRIENDLY_OFFSET) {
00387       ast_log(LOG_WARNING, "Can't generate %d bytes of data!\n" , len);
00388       len = sizeof(buf) - AST_FRIENDLY_OFFSET;
00389    }
00390    res = read(ls->fd, buf + AST_FRIENDLY_OFFSET/2, len);
00391    if (res > 0) {
00392       f.datalen = res;
00393       f.samples = res / 2;
00394       ast_write(chan, &f);
00395       if (res == len)
00396          return 0;
00397    }
00398    return -1;
00399 }

static void linear_release ( struct ast_channel chan,
void *  params 
) [static]

Definition at line 360 of file app.c.

References ast_free, ast_log(), ast_set_write_format(), linear_state::autoclose, chan, linear_state::fd, LOG_WARNING, ast_channel::name, and linear_state::origwfmt.

00361 {
00362    struct linear_state *ls = params;
00363    
00364    if (ls->origwfmt && ast_set_write_format(chan, ls->origwfmt))
00365       ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%d'\n", chan->name, ls->origwfmt);
00366 
00367    if (ls->autoclose)
00368       close(ls->fd);
00369 
00370    ast_free(params);
00371 }

static int option_exists ( struct ast_ivr_menu menu,
char *  option 
) [static]

Definition at line 1522 of file app.c.

References ast_ivr_option::option, and ast_ivr_menu::options.

Referenced by ast_ivr_menu_run_internal().

01523 {
01524    int x;
01525    for (x = 0; menu->options[x].option; x++)
01526       if (!strcasecmp(menu->options[x].option, option))
01527          return x;
01528    return -1;
01529 }

static int option_matchmore ( struct ast_ivr_menu menu,
char *  option 
) [static]

Definition at line 1531 of file app.c.

References ast_ivr_option::option, and ast_ivr_menu::options.

Referenced by read_newoption().

01532 {
01533    int x;
01534    for (x = 0; menu->options[x].option; x++)
01535       if ((!strncasecmp(menu->options[x].option, option, strlen(option))) && 
01536             (menu->options[x].option[strlen(option)]))
01537          return x;
01538    return -1;
01539 }

static void path_lock_destroy ( struct path_lock obj  )  [static]

Definition at line 1187 of file app.c.

References free.

Referenced by ast_lock_path_flock(), and ast_unlock_path_flock().

01188 {
01189    if (obj->fd >= 0)
01190       close(obj->fd);
01191    if (obj->path)
01192       free(obj->path);
01193    free(obj);
01194 }

static int read_newoption ( struct ast_channel chan,
struct ast_ivr_menu menu,
char *  exten,
int  maxexten 
) [static]

Definition at line 1541 of file app.c.

References ast_waitfordigit(), chan, ast_pbx::dtimeoutms, option_matchmore(), and ast_channel::pbx.

Referenced by ast_ivr_menu_run_internal().

01542 {
01543    int res = 0;
01544    int ms;
01545    while (option_matchmore(menu, exten)) {
01546       ms = chan->pbx ? chan->pbx->dtimeoutms : 5000;
01547       if (strlen(exten) >= maxexten - 1) 
01548          break;
01549       res = ast_waitfordigit(chan, ms);
01550       if (res < 1)
01551          break;
01552       exten[strlen(exten) + 1] = '\0';
01553       exten[strlen(exten)] = res;
01554    }
01555    return res > 0 ? 0 : res;
01556 }


Variable Documentation

int(*) ast_has_voicemail_func(const char *mailbox, const char *folder) = NULL [static]

Definition at line 185 of file app.c.

Referenced by ast_app_has_voicemail(), ast_install_vm_functions(), and ast_uninstall_vm_functions().

int(*) ast_inboxcount2_func(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs) = NULL [static]

Definition at line 187 of file app.c.

Referenced by ast_app_inboxcount2(), ast_install_vm_functions(), and ast_uninstall_vm_functions().

int(*) ast_inboxcount_func(const char *mailbox, int *newmsgs, int *oldmsgs) = NULL [static]

Definition at line 186 of file app.c.

Referenced by ast_app_inboxcount(), ast_app_inboxcount2(), ast_install_vm_functions(), and ast_uninstall_vm_functions().

enum AST_LOCK_TYPE ast_lock_type = AST_LOCK_TYPE_LOCKFILE [static]

Definition at line 163 of file app.c.

int(*) ast_messagecount_func(const char *context, const char *mailbox, const char *folder) = NULL [static]

Definition at line 189 of file app.c.

Referenced by ast_app_messagecount(), ast_install_vm_functions(), and ast_uninstall_vm_functions().

int(*) ast_sayname_func(struct ast_channel *chan, const char *mailbox, const char *context) = NULL [static]

Definition at line 188 of file app.c.

Referenced by ast_app_sayname(), ast_install_vm_functions(), and ast_uninstall_vm_functions().

char default_acceptdtmf[] = "#" [static]

Definition at line 888 of file app.c.

char default_canceldtmf[] = "" [static]

Definition at line 889 of file app.c.

int global_maxsilence = 0 [static]

Definition at line 599 of file app.c.

Referenced by apply_general_options(), handle_minivm_show_settings(), load_config(), and play_record_review().

int global_silence_threshold = 128 [static]

Definition at line 598 of file app.c.

struct ast_generator linearstream [static]

Definition at line 425 of file app.c.

Referenced by ast_linear_stream().


Generated on Fri Jun 19 12:09:55 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7