Convenient Application Routines. More...
#include "asterisk.h"
#include <sys/stat.h>
#include <regex.h>
#include <sys/file.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <dirent.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"
#include "asterisk/threadstorage.h"
#include "asterisk/test.h"
Go to the source code of this file.
Data Structures | |
struct | groups |
struct | linear_state |
struct | path_lock |
struct | path_lock_list |
struct | zombie |
struct | zombies |
Defines | |
#define | AST_MAX_FORMATS 10 |
#define | FMT "%30Lf%9s" |
#define | RES_EXIT (1 << 17) |
#define | RES_REPEAT (1 << 18) |
#define | RES_RESTART ((1 << 19) | RES_REPEAT) |
#define | RES_UPONE (1 << 16) |
Functions | |
unsigned int | __ast_app_separate_args (char *buf, char delim, int remove_chars, char **array, int arraylen) |
Separate a string into arguments in an array. | |
static int | __ast_play_and_record (struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int *sound_duration, int beep, int silencethreshold, int maxsilence, const char *path, int prepend, const char *acceptdtmf, const char *canceldtmf, int skip_confirmation_sound) |
int | ast_app_dtget (struct ast_channel *chan, const char *context, char *collect, size_t size, int maxlen, int timeout) |
This function presents a dialtone and reads an extension into 'collect' which must be a pointer to a **pre-initialized** array of char having a size of 'size' suitable for writing to. It will collect no more than the smaller of 'maxlen' or 'size' minus the original strlen() of collect digits. | |
enum ast_getdata_result | ast_app_getdata (struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout) |
ast_app_getdata | |
int | ast_app_getdata_full (struct ast_channel *c, const 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. | |
struct ast_group_info * | ast_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 If folder is NULL, defaults to "INBOX". If folder is "INBOX", includes the number of messages in the "Urgent" folder. | |
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) |
Check number of messages in a given context, 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_parse_timelen (const char *timestr, int *result, enum ast_timelen unit) |
Common routine to parse time lengths, with optional time unit specifier. | |
int | ast_app_run_macro (struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const char *const macro_name, const char *const macro_args) |
Run a macro on a channel, placing a second channel into autoservice. | |
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) |
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. | |
char * | ast_get_encoded_str (const char *stream, char *result, size_t result_size) |
Decode a stream of 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 *sound_duration, int beep, int silencethreshold, int maxsilence) |
Record a file based on input frm a channel. Recording is performed in 'prepend' mode which works a little differently from normal recordings This function will not play a success message due to post-recording control in the application this was added for. | |
int | ast_play_and_record (struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int *sound_duration, int silencethreshold, int maxsilence, const char *path) |
Record a file based on input from a channel. Use default accept and cancel DTMF. This function will play "auth-thankyou" upon successful recording. | |
int | ast_play_and_record_full (struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int *sound_duration, int silencethreshold, int maxsilence, const char *path, const char *acceptdtmf, const char *canceldtmf) |
Record a file based on input from a channel This function will play "auth-thankyou" upon successful recording. | |
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. | |
AST_THREADSTORAGE_PUBLIC (ast_str_thread_global_buf) | |
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 int | parse_options (const struct ast_app_option *options, void *_flags, char **args, char *optstr, int flaglen) |
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) |
static void * | shaun_of_the_dead (void *data) |
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 const char | default_acceptdtmf [] = "#" |
static const char | default_canceldtmf [] = "" |
static int | global_maxsilence = 0 |
static int | global_silence_threshold = 128 |
static struct ast_generator | linearstream |
static pthread_t | shaun_of_the_dead_thread = AST_PTHREADT_NULL |
Convenient Application Routines.
Definition in file app.c.
#define FMT "%30Lf%9s" |
Referenced by ast_app_parse_timelen().
#define RES_EXIT (1 << 17) |
Definition at line 1652 of file app.c.
Referenced by ast_ivr_menu_run_internal(), and ivr_dispatch().
#define RES_REPEAT (1 << 18) |
Definition at line 1653 of file app.c.
Referenced by ast_ivr_menu_run_internal(), and ivr_dispatch().
#define RES_RESTART ((1 << 19) | RES_REPEAT) |
Definition at line 1654 of file app.c.
Referenced by ast_ivr_menu_run_internal(), and ivr_dispatch().
#define RES_UPONE (1 << 16) |
Definition at line 1651 of file app.c.
Referenced by ast_ivr_menu_run_internal(), and ivr_dispatch().
unsigned int __ast_app_separate_args | ( | char * | buf, | |
char | delim, | |||
int | remove_chars, | |||
char ** | array, | |||
int | arraylen | |||
) |
Separate a string into arguments in an array.
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 | |
remove_chars | Remove backslashes and quote characters, while parsing | |
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.
Definition at line 1261 of file app.c.
References paren, and quote().
Referenced by ast_app_separate_args().
01262 { 01263 int argc; 01264 char *scan, *wasdelim = NULL; 01265 int paren = 0, quote = 0, bracket = 0; 01266 01267 if (!array || !arraylen) { 01268 return 0; 01269 } 01270 01271 memset(array, 0, arraylen * sizeof(*array)); 01272 01273 if (!buf) { 01274 return 0; 01275 } 01276 01277 scan = buf; 01278 01279 for (argc = 0; *scan && (argc < arraylen - 1); argc++) { 01280 array[argc] = scan; 01281 for (; *scan; scan++) { 01282 if (*scan == '(') { 01283 paren++; 01284 } else if (*scan == ')') { 01285 if (paren) { 01286 paren--; 01287 } 01288 } else if (*scan == '[') { 01289 bracket++; 01290 } else if (*scan == ']') { 01291 if (bracket) { 01292 bracket--; 01293 } 01294 } else if (*scan == '"' && delim != '"') { 01295 quote = quote ? 0 : 1; 01296 if (remove_chars) { 01297 /* Remove quote character from argument */ 01298 memmove(scan, scan + 1, strlen(scan)); 01299 scan--; 01300 } 01301 } else if (*scan == '\\') { 01302 if (remove_chars) { 01303 /* Literal character, don't parse */ 01304 memmove(scan, scan + 1, strlen(scan)); 01305 } else { 01306 scan++; 01307 } 01308 } else if ((*scan == delim) && !paren && !quote && !bracket) { 01309 wasdelim = scan; 01310 *scan++ = '\0'; 01311 break; 01312 } 01313 } 01314 } 01315 01316 /* If the last character in the original string was the delimiter, then 01317 * there is one additional argument. */ 01318 if (*scan || (scan > buf && (scan - 1) == wasdelim)) { 01319 array[argc++] = scan; 01320 } 01321 01322 return argc; 01323 }
static int __ast_play_and_record | ( | struct ast_channel * | chan, | |
const char * | playfile, | |||
const char * | recordfile, | |||
int | maxtime, | |||
const char * | fmt, | |||
int * | duration, | |||
int * | sound_duration, | |||
int | beep, | |||
int | silencethreshold, | |||
int | maxsilence, | |||
const char * | path, | |||
int | prepend, | |||
const char * | acceptdtmf, | |||
const char * | canceldtmf, | |||
int | skip_confirmation_sound | |||
) | [static] |
Optionally play a sound file or a beep, then record audio and video from the channel.
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 seconds). | |
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). | |
sound_duration | Where to store the length of the recorded message (in milliseconds), minus any silence | |
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 and follow prepend mode recording rules | |
acceptdtmf | DTMF digits that will end the recording. | |
canceldtmf | DTMF digits that will cancel the recording. | |
skip_confirmation_sound | If true, don't play auth-thankyou at end. Nice for custom recording prompts in apps. |
-1 | failure or hangup | |
'S' | Recording ended from silence timeout | |
't' | Recording ended from the message exceeding the maximum duration, or via DTMF in prepend mode | |
dtmfchar | Recording ended via the return value's DTMF character for either cancel or accept. |
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).
Definition at line 745 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_MAX_FORMATS, 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(), comment, f, ast_frame::frametype, global_maxsilence, global_silence_threshold, ast_frame_subclass::integer, LOG_WARNING, ast_channel::readformat, ast_frame::subclass, and ast_dsp::totalsilence.
Referenced by ast_play_and_prepend(), ast_play_and_record(), and ast_play_and_record_full().
00746 { 00747 int d = 0; 00748 char *fmts; 00749 char comment[256]; 00750 int x, fmtcnt = 1, res = -1, outmsg = 0; 00751 struct ast_filestream *others[AST_MAX_FORMATS]; 00752 char *sfmt[AST_MAX_FORMATS]; 00753 char *stringp = NULL; 00754 time_t start, end; 00755 struct ast_dsp *sildet = NULL; /* silence detector dsp */ 00756 int totalsilence = 0; 00757 int dspsilence = 0; 00758 int olddspsilence = 0; 00759 int rfmt = 0; 00760 struct ast_silence_generator *silgen = NULL; 00761 char prependfile[80]; 00762 00763 if (silencethreshold < 0) { 00764 silencethreshold = global_silence_threshold; 00765 } 00766 00767 if (maxsilence < 0) { 00768 maxsilence = global_maxsilence; 00769 } 00770 00771 /* barf if no pointer passed to store duration in */ 00772 if (!duration) { 00773 ast_log(LOG_WARNING, "Error play_and_record called without duration pointer\n"); 00774 return -1; 00775 } 00776 00777 ast_debug(1, "play_and_record: %s, %s, '%s'\n", playfile ? playfile : "<None>", recordfile, fmt); 00778 snprintf(comment, sizeof(comment), "Playing %s, Recording to: %s on %s\n", playfile ? playfile : "<None>", recordfile, chan->name); 00779 00780 if (playfile || beep) { 00781 if (!beep) { 00782 d = ast_play_and_wait(chan, playfile); 00783 } 00784 if (d > -1) { 00785 d = ast_stream_and_wait(chan, "beep", ""); 00786 } 00787 if (d < 0) { 00788 return -1; 00789 } 00790 } 00791 00792 if (prepend) { 00793 ast_copy_string(prependfile, recordfile, sizeof(prependfile)); 00794 strncat(prependfile, "-prepend", sizeof(prependfile) - strlen(prependfile) - 1); 00795 } 00796 00797 fmts = ast_strdupa(fmt); 00798 00799 stringp = fmts; 00800 strsep(&stringp, "|"); 00801 ast_debug(1, "Recording Formats: sfmts=%s\n", fmts); 00802 sfmt[0] = ast_strdupa(fmts); 00803 00804 while ((fmt = strsep(&stringp, "|"))) { 00805 if (fmtcnt > AST_MAX_FORMATS - 1) { 00806 ast_log(LOG_WARNING, "Please increase AST_MAX_FORMATS in file.h\n"); 00807 break; 00808 } 00809 sfmt[fmtcnt++] = ast_strdupa(fmt); 00810 } 00811 00812 end = start = time(NULL); /* pre-initialize end to be same as start in case we never get into loop */ 00813 for (x = 0; x < fmtcnt; x++) { 00814 others[x] = ast_writefile(prepend ? prependfile : recordfile, sfmt[x], comment, O_TRUNC, 0, AST_FILE_MODE); 00815 ast_verb(3, "x=%d, open writing: %s format: %s, %p\n", x, prepend ? prependfile : recordfile, sfmt[x], others[x]); 00816 00817 if (!others[x]) { 00818 break; 00819 } 00820 } 00821 00822 if (path) { 00823 ast_unlock_path(path); 00824 } 00825 00826 if (maxsilence > 0) { 00827 sildet = ast_dsp_new(); /* Create the silence detector */ 00828 if (!sildet) { 00829 ast_log(LOG_WARNING, "Unable to create silence detector :(\n"); 00830 return -1; 00831 } 00832 ast_dsp_set_threshold(sildet, silencethreshold); 00833 rfmt = chan->readformat; 00834 res = ast_set_read_format(chan, AST_FORMAT_SLINEAR); 00835 if (res < 0) { 00836 ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n"); 00837 ast_dsp_free(sildet); 00838 return -1; 00839 } 00840 } 00841 00842 if (!prepend) { 00843 /* Request a video update */ 00844 ast_indicate(chan, AST_CONTROL_VIDUPDATE); 00845 00846 if (ast_opt_transmit_silence) { 00847 silgen = ast_channel_start_silence_generator(chan); 00848 } 00849 } 00850 00851 if (x == fmtcnt) { 00852 /* Loop forever, writing the packets we read to the writer(s), until 00853 we read a digit or get a hangup */ 00854 struct ast_frame *f; 00855 for (;;) { 00856 if (!(res = ast_waitfor(chan, 2000))) { 00857 ast_debug(1, "One waitfor failed, trying another\n"); 00858 /* Try one more time in case of masq */ 00859 if (!(res = ast_waitfor(chan, 2000))) { 00860 ast_log(LOG_WARNING, "No audio available on %s??\n", chan->name); 00861 res = -1; 00862 } 00863 } 00864 00865 if (res < 0) { 00866 f = NULL; 00867 break; 00868 } 00869 if (!(f = ast_read(chan))) { 00870 break; 00871 } 00872 if (f->frametype == AST_FRAME_VOICE) { 00873 /* write each format */ 00874 for (x = 0; x < fmtcnt; x++) { 00875 if (prepend && !others[x]) { 00876 break; 00877 } 00878 res = ast_writestream(others[x], f); 00879 } 00880 00881 /* Silence Detection */ 00882 if (maxsilence > 0) { 00883 dspsilence = 0; 00884 ast_dsp_silence(sildet, f, &dspsilence); 00885 if (olddspsilence > dspsilence) { 00886 totalsilence += olddspsilence; 00887 } 00888 olddspsilence = dspsilence; 00889 00890 if (dspsilence > maxsilence) { 00891 /* Ended happily with silence */ 00892 ast_verb(3, "Recording automatically stopped after a silence of %d seconds\n", dspsilence/1000); 00893 res = 'S'; 00894 outmsg = 2; 00895 break; 00896 } 00897 } 00898 /* Exit on any error */ 00899 if (res) { 00900 ast_log(LOG_WARNING, "Error writing frame\n"); 00901 break; 00902 } 00903 } else if (f->frametype == AST_FRAME_VIDEO) { 00904 /* Write only once */ 00905 ast_writestream(others[0], f); 00906 } else if (f->frametype == AST_FRAME_DTMF) { 00907 if (prepend) { 00908 /* stop recording with any digit */ 00909 ast_verb(3, "User ended message by pressing %c\n", f->subclass.integer); 00910 res = 't'; 00911 outmsg = 2; 00912 break; 00913 } 00914 if (strchr(acceptdtmf, f->subclass.integer)) { 00915 ast_verb(3, "User ended message by pressing %c\n", f->subclass.integer); 00916 res = f->subclass.integer; 00917 outmsg = 2; 00918 break; 00919 } 00920 if (strchr(canceldtmf, f->subclass.integer)) { 00921 ast_verb(3, "User cancelled message by pressing %c\n", f->subclass.integer); 00922 res = f->subclass.integer; 00923 outmsg = 0; 00924 break; 00925 } 00926 } 00927 if (maxtime) { 00928 end = time(NULL); 00929 if (maxtime < (end - start)) { 00930 ast_verb(3, "Took too long, cutting it short...\n"); 00931 res = 't'; 00932 outmsg = 2; 00933 break; 00934 } 00935 } 00936 ast_frfree(f); 00937 } 00938 if (!f) { 00939 ast_verb(3, "User hung up\n"); 00940 res = -1; 00941 outmsg = 1; 00942 } else { 00943 ast_frfree(f); 00944 } 00945 } else { 00946 ast_log(LOG_WARNING, "Error creating writestream '%s', format '%s'\n", recordfile, sfmt[x]); 00947 } 00948 00949 if (!prepend) { 00950 if (silgen) { 00951 ast_channel_stop_silence_generator(chan, silgen); 00952 } 00953 } 00954 00955 /*!\note 00956 * Instead of asking how much time passed (end - start), calculate the number 00957 * of seconds of audio which actually went into the file. This fixes a 00958 * problem where audio is stopped up on the network and never gets to us. 00959 * 00960 * Note that we still want to use the number of seconds passed for the max 00961 * message, otherwise we could get a situation where this stream is never 00962 * closed (which would create a resource leak). 00963 */ 00964 *duration = others[0] ? ast_tellstream(others[0]) / 8000 : 0; 00965 if (sound_duration) { 00966 *sound_duration = *duration; 00967 } 00968 00969 if (!prepend) { 00970 /* Reduce duration by a total silence amount */ 00971 if (olddspsilence <= dspsilence) { 00972 totalsilence += dspsilence; 00973 } 00974 00975 if (sound_duration) { 00976 if (totalsilence > 0) { 00977 *sound_duration -= (totalsilence - 200) / 1000; 00978 } 00979 if (*sound_duration < 0) { 00980 *sound_duration = 0; 00981 } 00982 } 00983 00984 if (dspsilence > 0) { 00985 *duration -= (dspsilence - 200) / 1000; 00986 } 00987 if (*duration < 0) { 00988 *duration = 0; 00989 } 00990 00991 for (x = 0; x < fmtcnt; x++) { 00992 if (!others[x]) { 00993 break; 00994 } 00995 /*!\note 00996 * If we ended with silence, trim all but the first 200ms of silence 00997 * off the recording. However, if we ended with '#', we don't want 00998 * to trim ANY part of the recording. 00999 */ 01000 if (res > 0 && dspsilence) { 01001 /* rewind only the trailing silence */ 01002 ast_stream_rewind(others[x], dspsilence - 200); 01003 } 01004 ast_truncstream(others[x]); 01005 ast_closestream(others[x]); 01006 } 01007 } 01008 01009 if (prepend && outmsg) { 01010 struct ast_filestream *realfiles[AST_MAX_FORMATS]; 01011 struct ast_frame *fr; 01012 01013 for (x = 0; x < fmtcnt; x++) { 01014 snprintf(comment, sizeof(comment), "Opening the real file %s.%s\n", recordfile, sfmt[x]); 01015 realfiles[x] = ast_readfile(recordfile, sfmt[x], comment, O_RDONLY, 0, 0); 01016 if (!others[x] || !realfiles[x]) { 01017 break; 01018 } 01019 /*!\note Same logic as above. */ 01020 if (dspsilence) { 01021 ast_stream_rewind(others[x], dspsilence - 200); 01022 } 01023 ast_truncstream(others[x]); 01024 /* add the original file too */ 01025 while ((fr = ast_readframe(realfiles[x]))) { 01026 ast_writestream(others[x], fr); 01027 ast_frfree(fr); 01028 } 01029 ast_closestream(others[x]); 01030 ast_closestream(realfiles[x]); 01031 ast_filerename(prependfile, recordfile, sfmt[x]); 01032 ast_verb(4, "Recording Format: sfmts=%s, prependfile %s, recordfile %s\n", sfmt[x], prependfile, recordfile); 01033 ast_filedelete(prependfile, sfmt[x]); 01034 } 01035 } 01036 if (rfmt && ast_set_read_format(chan, rfmt)) { 01037 ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(rfmt), chan->name); 01038 } 01039 if ((outmsg == 2) && (!skip_confirmation_sound)) { 01040 ast_stream_and_wait(chan, "auth-thankyou", ""); 01041 } 01042 if (sildet) { 01043 ast_dsp_free(sildet); 01044 } 01045 return res; 01046 }
int ast_app_dtget | ( | struct ast_channel * | chan, | |
const char * | context, | |||
char * | collect, | |||
size_t | size, | |||
int | maxlen, | |||
int | timeout | |||
) |
This function presents a dialtone and reads an extension into 'collect' which must be a pointer to a **pre-initialized** array of char having a size of 'size' suitable for writing to. It will collect no more than the smaller of 'maxlen' or 'size' minus the original strlen() of collect digits.
Present a dialtone and collect a certain length extension.
chan | struct. | |
context | ||
collect | ||
size | ||
maxlen | ||
timeout | timeout in milliseconds |
Definition at line 119 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_tone_zone_sound_unref(), ast_waitfordigit(), ast_channel::caller, ast_tone_zone_sound::data, ast_pbx::dtimeoutms, ast_party_caller::id, LOG_NOTICE, ast_party_id::number, ast_channel::pbx, S_COR, ast_party_number::str, ast_party_number::valid, and ast_channel::zone.
Referenced by builtin_atxfer(), builtin_blindtransfer(), and grab_transfer().
00120 { 00121 struct ast_tone_zone_sound *ts; 00122 int res = 0, x = 0; 00123 00124 if (maxlen > size) { 00125 maxlen = size; 00126 } 00127 00128 if (!timeout) { 00129 if (chan->pbx && chan->pbx->dtimeoutms) { 00130 timeout = chan->pbx->dtimeoutms; 00131 } else { 00132 timeout = 5000; 00133 } 00134 } 00135 00136 if ((ts = ast_get_indication_tone(chan->zone, "dial"))) { 00137 res = ast_playtones_start(chan, 0, ts->data, 0); 00138 ts = ast_tone_zone_sound_unref(ts); 00139 } else { 00140 ast_log(LOG_NOTICE, "Huh....? no dial for indications?\n"); 00141 } 00142 00143 for (x = strlen(collect); x < maxlen; ) { 00144 res = ast_waitfordigit(chan, timeout); 00145 if (!ast_ignore_pattern(context, collect)) { 00146 ast_playtones_stop(chan); 00147 } 00148 if (res < 1) { 00149 break; 00150 } 00151 if (res == '#') { 00152 break; 00153 } 00154 collect[x++] = res; 00155 if (!ast_matchmore_extension(chan, context, collect, 1, 00156 S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) { 00157 break; 00158 } 00159 } 00160 00161 if (res >= 0) { 00162 res = ast_exists_extension(chan, context, collect, 1, 00163 S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL)) ? 1 : 0; 00164 } 00165 00166 return res; 00167 }
enum ast_getdata_result ast_app_getdata | ( | struct ast_channel * | c, | |
const char * | prompt, | |||
char * | s, | |||
int | maxlen, | |||
int | timeout | |||
) |
ast_app_getdata
Plays a stream and gets DTMF data from a channel.
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 177 of file app.c.
References AST_GETDATA_EMPTY_END_TERMINATED, ast_readstring(), ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_pbx::dtimeoutms, ast_channel::pbx, and ast_pbx::rtimeoutms.
Referenced by auth_exec(), conf_exec(), dictate_exec(), find_conf(), login_exec(), read_exec(), testclient_exec(), testserver_exec(), and vm_exec().
00178 { 00179 int res = 0, to, fto; 00180 char *front, *filename; 00181 00182 /* XXX Merge with full version? XXX */ 00183 00184 if (maxlen) 00185 s[0] = '\0'; 00186 00187 if (!prompt) 00188 prompt = ""; 00189 00190 filename = ast_strdupa(prompt); 00191 while ((front = strsep(&filename, "&"))) { 00192 if (!ast_strlen_zero(front)) { 00193 res = ast_streamfile(c, front, c->language); 00194 if (res) 00195 continue; 00196 } 00197 if (ast_strlen_zero(filename)) { 00198 /* set timeouts for the last prompt */ 00199 fto = c->pbx ? c->pbx->rtimeoutms : 6000; 00200 to = c->pbx ? c->pbx->dtimeoutms : 2000; 00201 00202 if (timeout > 0) { 00203 fto = to = timeout; 00204 } 00205 if (timeout < 0) { 00206 fto = to = 1000000000; 00207 } 00208 } else { 00209 /* there is more than one prompt, so 00210 * get rid of the long timeout between 00211 * prompts, and make it 50ms */ 00212 fto = 50; 00213 to = c->pbx ? c->pbx->dtimeoutms : 2000; 00214 } 00215 res = ast_readstring(c, s, maxlen, to, fto, "#"); 00216 if (res == AST_GETDATA_EMPTY_END_TERMINATED) { 00217 return res; 00218 } 00219 if (!ast_strlen_zero(s)) { 00220 return res; 00221 } 00222 } 00223 00224 return res; 00225 }
int ast_app_getdata_full | ( | struct ast_channel * | c, | |
const 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 230 of file app.c.
References ast_readstring_full(), ast_streamfile(), and ast_strlen_zero().
Referenced by handle_getdata().
00231 { 00232 int res, to = 2000, fto = 6000; 00233 00234 if (!ast_strlen_zero(prompt)) { 00235 res = ast_streamfile(c, prompt, c->language); 00236 if (res < 0) { 00237 return res; 00238 } 00239 } 00240 00241 if (timeout > 0) { 00242 fto = to = timeout; 00243 } 00244 if (timeout < 0) { 00245 fto = to = 1000000000; 00246 } 00247 00248 res = ast_readstring_full(c, s, maxlen, to, fto, "#", audiofd, ctrlfd); 00249 00250 return res; 00251 }
int ast_app_group_discard | ( | struct ast_channel * | chan | ) |
Discard all group counting for a channel.
Definition at line 1221 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, and ast_group_info::chan.
Referenced by ast_channel_destructor().
01222 { 01223 struct ast_group_info *gi = NULL; 01224 01225 AST_RWLIST_WRLOCK(&groups); 01226 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, group_list) { 01227 if (gi->chan == chan) { 01228 AST_RWLIST_REMOVE_CURRENT(group_list); 01229 ast_free(gi); 01230 } 01231 } 01232 AST_RWLIST_TRAVERSE_SAFE_END; 01233 AST_RWLIST_UNLOCK(&groups); 01234 01235 return 0; 01236 }
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 1142 of file app.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strlen_zero(), ast_group_info::category, and ast_group_info::group.
Referenced by group_count_function_read().
01143 { 01144 struct ast_group_info *gi = NULL; 01145 int count = 0; 01146 01147 if (ast_strlen_zero(group)) { 01148 return 0; 01149 } 01150 01151 AST_RWLIST_RDLOCK(&groups); 01152 AST_RWLIST_TRAVERSE(&groups, gi, group_list) { 01153 if (!strcasecmp(gi->group, group) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) { 01154 count++; 01155 } 01156 } 01157 AST_RWLIST_UNLOCK(&groups); 01158 01159 return count; 01160 }
struct ast_group_info* ast_app_group_list_head | ( | void | ) | [read] |
Get the head of the group count list.
Definition at line 1248 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().
01249 { 01250 return AST_RWLIST_FIRST(&groups); 01251 }
int ast_app_group_list_rdlock | ( | void | ) |
Read Lock the group count list.
Definition at line 1243 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().
01244 { 01245 return AST_RWLIST_RDLOCK(&groups); 01246 }
int ast_app_group_list_unlock | ( | void | ) |
Unlock the group count list.
Definition at line 1253 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().
01254 { 01255 return AST_RWLIST_UNLOCK(&groups); 01256 }
int ast_app_group_list_wrlock | ( | void | ) |
Write Lock the group count list.
Definition at line 1238 of file app.c.
References AST_RWLIST_WRLOCK.
01239 { 01240 return AST_RWLIST_WRLOCK(&groups); 01241 }
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 1162 of file app.c.
References ast_log(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strlen_zero(), ast_group_info::category, ast_group_info::group, LOG_ERROR, and LOG_NOTICE.
Referenced by group_match_count_function_read().
01163 { 01164 struct ast_group_info *gi = NULL; 01165 regex_t regexbuf_group; 01166 regex_t regexbuf_category; 01167 int count = 0; 01168 01169 if (ast_strlen_zero(groupmatch)) { 01170 ast_log(LOG_NOTICE, "groupmatch empty\n"); 01171 return 0; 01172 } 01173 01174 /* if regex compilation fails, return zero matches */ 01175 if (regcomp(®exbuf_group, groupmatch, REG_EXTENDED | REG_NOSUB)) { 01176 ast_log(LOG_ERROR, "Regex compile failed on: %s\n", groupmatch); 01177 return 0; 01178 } 01179 01180 if (!ast_strlen_zero(category) && regcomp(®exbuf_category, category, REG_EXTENDED | REG_NOSUB)) { 01181 ast_log(LOG_ERROR, "Regex compile failed on: %s\n", category); 01182 regfree(®exbuf_group); 01183 return 0; 01184 } 01185 01186 AST_RWLIST_RDLOCK(&groups); 01187 AST_RWLIST_TRAVERSE(&groups, gi, group_list) { 01188 if (!regexec(®exbuf_group, gi->group, 0, NULL, 0) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !regexec(®exbuf_category, gi->category, 0, NULL, 0)))) { 01189 count++; 01190 } 01191 } 01192 AST_RWLIST_UNLOCK(&groups); 01193 01194 regfree(®exbuf_group); 01195 if (!ast_strlen_zero(category)) { 01196 regfree(®exbuf_category); 01197 } 01198 01199 return count; 01200 }
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 1095 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, free, ast_group_info::group, and len().
Referenced by dial_exec_full(), and group_function_write().
01096 { 01097 int res = 0; 01098 char group[80] = "", category[80] = ""; 01099 struct ast_group_info *gi = NULL; 01100 size_t len = 0; 01101 01102 if (ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category))) { 01103 return -1; 01104 } 01105 01106 /* Calculate memory we will need if this is new */ 01107 len = sizeof(*gi) + strlen(group) + 1; 01108 if (!ast_strlen_zero(category)) { 01109 len += strlen(category) + 1; 01110 } 01111 01112 AST_RWLIST_WRLOCK(&groups); 01113 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, group_list) { 01114 if ((gi->chan == chan) && ((ast_strlen_zero(category) && ast_strlen_zero(gi->category)) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) { 01115 AST_RWLIST_REMOVE_CURRENT(group_list); 01116 free(gi); 01117 break; 01118 } 01119 } 01120 AST_RWLIST_TRAVERSE_SAFE_END; 01121 01122 if (ast_strlen_zero(group)) { 01123 /* Enable unsetting the group */ 01124 } else if ((gi = calloc(1, len))) { 01125 gi->chan = chan; 01126 gi->group = (char *) gi + sizeof(*gi); 01127 strcpy(gi->group, group); 01128 if (!ast_strlen_zero(category)) { 01129 gi->category = (char *) gi + sizeof(*gi) + strlen(group) + 1; 01130 strcpy(gi->category, category); 01131 } 01132 AST_RWLIST_INSERT_TAIL(&groups, gi, group_list); 01133 } else { 01134 res = -1; 01135 } 01136 01137 AST_RWLIST_UNLOCK(&groups); 01138 01139 return res; 01140 }
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 1068 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().
01069 { 01070 int res = 0; 01071 char tmp[256]; 01072 char *grp = NULL, *cat = NULL; 01073 01074 if (!ast_strlen_zero(data)) { 01075 ast_copy_string(tmp, data, sizeof(tmp)); 01076 grp = tmp; 01077 if ((cat = strchr(tmp, '@'))) { 01078 *cat++ = '\0'; 01079 } 01080 } 01081 01082 if (!ast_strlen_zero(grp)) { 01083 ast_copy_string(group, grp, group_max); 01084 } else { 01085 *group = '\0'; 01086 } 01087 01088 if (!ast_strlen_zero(cat)) { 01089 ast_copy_string(category, cat, category_max); 01090 } 01091 01092 return res; 01093 }
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 1202 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, and ast_group_info::chan.
Referenced by ast_do_masquerade(), and check_bridge().
01203 { 01204 struct ast_group_info *gi = NULL; 01205 01206 AST_RWLIST_WRLOCK(&groups); 01207 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, group_list) { 01208 if (gi->chan == old) { 01209 gi->chan = new; 01210 } else if (gi->chan == new) { 01211 AST_RWLIST_REMOVE_CURRENT(group_list); 01212 ast_free(gi); 01213 } 01214 } 01215 AST_RWLIST_TRAVERSE_SAFE_END; 01216 AST_RWLIST_UNLOCK(&groups); 01217 01218 return 0; 01219 }
int ast_app_has_voicemail | ( | const char * | mailbox, | |
const char * | folder | |||
) |
Determine if a given mailbox has any voicemail If folder is NULL, defaults to "INBOX". If folder is "INBOX", includes the number of messages in the "Urgent" folder.
1 | Mailbox has voicemail | |
0 | No new voicemail in specified mailbox | |
-1 | Failure |
Definition at line 303 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(), skinny_register(), and unistim_send_mwi_to_peer().
00304 { 00305 static int warned = 0; 00306 if (ast_has_voicemail_func) { 00307 return ast_has_voicemail_func(mailbox, folder); 00308 } 00309 00310 if (warned++ % 10 == 0) { 00311 ast_verb(3, "Message check requested for mailbox %s/folder %s but voicemail not loaded.\n", mailbox, folder ? folder : "INBOX"); 00312 } 00313 return 0; 00314 }
int ast_app_inboxcount | ( | const char * | mailbox, | |
int * | newmsgs, | |||
int * | oldmsgs | |||
) |
Determine number of new/old messages in a mailbox.
[in] | mailbox | Mailbox specification in the format mbox[][&mbox2[]][...] |
[out] | newmsgs | Number of messages in the "INBOX" folder. Includes number of messages in the "Urgent" folder, if any. |
[out] | oldmsgs | Number of messages in the "Old" folder. |
0 | Success | |
-1 | Failure |
Definition at line 317 of file app.c.
References ast_inboxcount_func, and ast_verb.
Referenced by sip_send_mwi_to_peer(), and update_registry().
00318 { 00319 static int warned = 0; 00320 if (newmsgs) { 00321 *newmsgs = 0; 00322 } 00323 if (oldmsgs) { 00324 *oldmsgs = 0; 00325 } 00326 if (ast_inboxcount_func) { 00327 return ast_inboxcount_func(mailbox, newmsgs, oldmsgs); 00328 } 00329 00330 if (warned++ % 10 == 0) { 00331 ast_verb(3, "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox); 00332 } 00333 00334 return 0; 00335 }
int ast_app_inboxcount2 | ( | const char * | mailbox, | |
int * | urgentmsgs, | |||
int * | newmsgs, | |||
int * | oldmsgs | |||
) |
Determine number of urgent/new/old messages in a mailbox.
[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 |
Definition at line 337 of file app.c.
References ast_inboxcount2_func, and ast_verb.
Referenced by action_mailboxcount(), notify_new_message(), and vm_execmain().
00338 { 00339 static int warned = 0; 00340 if (newmsgs) { 00341 *newmsgs = 0; 00342 } 00343 if (oldmsgs) { 00344 *oldmsgs = 0; 00345 } 00346 if (urgentmsgs) { 00347 *urgentmsgs = 0; 00348 } 00349 if (ast_inboxcount2_func) { 00350 return ast_inboxcount2_func(mailbox, urgentmsgs, newmsgs, oldmsgs); 00351 } 00352 00353 if (warned++ % 10 == 0) { 00354 ast_verb(3, "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox); 00355 } 00356 00357 return 0; 00358 }
int ast_app_messagecount | ( | const char * | context, | |
const char * | mailbox, | |||
const char * | folder | |||
) |
Check number of messages in a given context, mailbox, and folder.
[in] | context | Mailbox context |
[in] | mailbox | Mailbox number |
[in] | folder | Mailbox folder |
Definition at line 368 of file app.c.
References ast_messagecount_func, and ast_verb.
Referenced by acf_vmcount_exec().
00369 { 00370 static int warned = 0; 00371 if (ast_messagecount_func) { 00372 return ast_messagecount_func(context, mailbox, folder); 00373 } 00374 00375 if (!warned) { 00376 warned++; 00377 ast_verb(3, "Message count requested for mailbox %s@%s/%s but voicemail not loaded.\n", mailbox, context, folder); 00378 } 00379 00380 return 0; 00381 }
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.
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 1984 of file app.c.
References ast_test_flag64.
01985 { 01986 unsigned int i, found = 0; 01987 for (i = 32; i < 128 && found < len; i++) { 01988 if (ast_test_flag64(flags, options[i].flag)) { 01989 buf[found++] = i; 01990 } 01991 } 01992 buf[found] = '\0'; 01993 }
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.
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 |
Definition at line 1974 of file app.c.
References parse_options().
Referenced by app_exec(), auth_exec(), bridge_exec(), cdr_read(), cdr_write(), chanspy_exec(), confbridge_exec(), connectedline_write(), controlplayback_exec(), directory_exec(), disa_exec(), dundi_query_read(), dundifunc_read(), extenspy_exec(), forkcdr_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(), realtime_common(), receivefax_exec(), record_exec(), redirecting_write(), sendfax_exec(), sendurl_exec(), sla_trunk_exec(), smdi_msg_retrieve_read(), sms_exec(), softhangup_exec(), speech_background(), vm_exec(), vm_execmain(), and volume_write().
01975 { 01976 return parse_options(options, flags, args, optstr, 32); 01977 }
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.
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 |
Definition at line 1979 of file app.c.
References parse_options().
Referenced by conf_exec(), dial_exec_full(), and find_conf_realtime().
01980 { 01981 return parse_options(options, flags, args, optstr, 64); 01982 }
int ast_app_parse_timelen | ( | const char * | timestr, | |
int * | result, | |||
enum ast_timelen | defunit | |||
) |
Common routine to parse time lengths, with optional time unit specifier.
[in] | timestr | String to parse |
[in] | defunit | Default unit type |
[out] | result | Resulting value, specified in milliseconds |
0 | Success | |
-1 | Failure |
Definition at line 2184 of file app.c.
References FMT, TIMELEN_HOURS, TIMELEN_MILLISECONDS, TIMELEN_MINUTES, and TIMELEN_SECONDS.
Referenced by ast_eivr_senddtmf(), pbx_builtin_wait(), pbx_builtin_waitexten(), and senddtmf_exec().
02185 { 02186 int res; 02187 char u[10]; 02188 #ifdef HAVE_LONG_DOUBLE_WIDER 02189 long double amount; 02190 #define FMT "%30Lf%9s" 02191 #else 02192 double amount; 02193 #define FMT "%30lf%9s" 02194 #endif 02195 if (!timestr) { 02196 return -1; 02197 } 02198 02199 if ((res = sscanf(timestr, FMT, &amount, u)) == 0) { 02200 #undef FMT 02201 return -1; 02202 } else if (res == 2) { 02203 switch (u[0]) { 02204 case 'h': 02205 case 'H': 02206 unit = TIMELEN_HOURS; 02207 break; 02208 case 's': 02209 case 'S': 02210 unit = TIMELEN_SECONDS; 02211 break; 02212 case 'm': 02213 case 'M': 02214 if (toupper(u[1]) == 'S') { 02215 unit = TIMELEN_MILLISECONDS; 02216 } else if (u[1] == '\0') { 02217 unit = TIMELEN_MINUTES; 02218 } 02219 break; 02220 } 02221 } 02222 02223 switch (unit) { 02224 case TIMELEN_HOURS: 02225 amount *= 60; 02226 /* fall-through */ 02227 case TIMELEN_MINUTES: 02228 amount *= 60; 02229 /* fall-through */ 02230 case TIMELEN_SECONDS: 02231 amount *= 1000; 02232 /* fall-through */ 02233 case TIMELEN_MILLISECONDS: 02234 ; 02235 } 02236 *result = amount > INT_MAX ? INT_MAX : (int) amount; 02237 return 0; 02238 }
int ast_app_run_macro | ( | struct ast_channel * | autoservice_chan, | |
struct ast_channel * | macro_chan, | |||
const char *const | macro_name, | |||
const char *const | macro_args | |||
) |
Run a macro on a channel, placing a second channel into autoservice.
autoservice_chan | A channel to place into autoservice while the macro is run | |
macro_chan | The channel to run the macro on | |
macro_name | The name of the macro to run | |
macro_args | The arguments to pass to the macro |
0 | success | |
-1 | failure |
Definition at line 253 of file app.c.
References ast_autoservice_start(), ast_autoservice_stop(), ast_log(), ast_strlen_zero(), LOG_WARNING, pbx_exec(), pbx_findapp(), and S_OR.
Referenced by ast_channel_connected_line_macro(), ast_channel_redirecting_macro(), and generic_recall().
00254 { 00255 struct ast_app *macro_app; 00256 int res; 00257 char buf[1024]; 00258 00259 macro_app = pbx_findapp("Macro"); 00260 if (!macro_app) { 00261 ast_log(LOG_WARNING, "Cannot run macro '%s' because the 'Macro' application in not available\n", macro_name); 00262 return -1; 00263 } 00264 snprintf(buf, sizeof(buf), "%s%s%s", macro_name, ast_strlen_zero(macro_args) ? "" : ",", S_OR(macro_args, "")); 00265 if (autoservice_chan) { 00266 ast_autoservice_start(autoservice_chan); 00267 } 00268 res = pbx_exec(macro_chan, macro_app, buf); 00269 if (autoservice_chan) { 00270 ast_autoservice_stop(autoservice_chan); 00271 } 00272 return res; 00273 }
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.
[in] | chan | Channel on which to play the name |
[in] | mailbox | Mailbox number from which to retrieve the recording |
[in] | context | Mailbox context from which to locate the mailbox number |
0 | Name played without interruption | |
dtmf | ASCII value of the DTMF which interrupted playback. | |
-1 | Unable to locate mailbox or hangup occurred. |
Definition at line 360 of file app.c.
References ast_sayname_func.
Referenced by common_exec(), and play_mailbox_owner().
00361 { 00362 if (ast_sayname_func) { 00363 return ast_sayname_func(chan, mailbox, context); 00364 } 00365 return -1; 00366 }
unsigned int ast_app_separate_args | ( | char * | buf, | |
char | delim, | |||
char ** | array, | |||
int | arraylen | |||
) |
Definition at line 1326 of file app.c.
References __ast_app_separate_args().
01327 { 01328 return __ast_app_separate_args(buf, delim, 1, array, arraylen); 01329 }
void ast_close_fds_above_n | ( | int | n | ) |
Common routine for child processes, to close all fds prior to exec(2).
[in] | n | starting file descriptor number for closing all higher file descriptors |
Definition at line 2110 of file app.c.
References closefrom().
Referenced by app_exec(), ast_safe_system(), icesencode(), launch_script(), main(), mp3play(), NBScatplay(), send_waveform_to_fd(), spawn_mp3(), spawn_ras(), and vm_check_password_shell().
02111 { 02112 closefrom(n + 1); 02113 }
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.
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 565 of file app.c.
References ast_channel::_state, ast_alloca, ast_answer(), ast_debug, ast_seekstream(), AST_STATE_UP, ast_stopstream(), ast_streamfile(), ast_tellstream(), ast_verb, ast_waitfordigit(), ast_waitstream_fr(), and ast_channel::stream.
Referenced by controlplayback_exec(), handle_controlstreamfile(), and wait_file().
00569 { 00570 char *breaks = NULL; 00571 char *end = NULL; 00572 int blen = 2; 00573 int res; 00574 long pause_restart_point = 0; 00575 long offset = 0; 00576 00577 if (!file) { 00578 return -1; 00579 } 00580 if (offsetms) { 00581 offset = *offsetms * 8; /* XXX Assumes 8kHz */ 00582 } 00583 00584 if (stop) { 00585 blen += strlen(stop); 00586 } 00587 if (suspend) { 00588 blen += strlen(suspend); 00589 } 00590 if (restart) { 00591 blen += strlen(restart); 00592 } 00593 00594 if (blen > 2) { 00595 breaks = ast_alloca(blen + 1); 00596 breaks[0] = '\0'; 00597 if (stop) { 00598 strcat(breaks, stop); 00599 } 00600 if (suspend) { 00601 strcat(breaks, suspend); 00602 } 00603 if (restart) { 00604 strcat(breaks, restart); 00605 } 00606 } 00607 if (chan->_state != AST_STATE_UP) { 00608 res = ast_answer(chan); 00609 } 00610 00611 if ((end = strchr(file, ':'))) { 00612 if (!strcasecmp(end, ":end")) { 00613 *end = '\0'; 00614 end++; 00615 } 00616 } 00617 00618 for (;;) { 00619 ast_stopstream(chan); 00620 res = ast_streamfile(chan, file, chan->language); 00621 if (!res) { 00622 if (pause_restart_point) { 00623 ast_seekstream(chan->stream, pause_restart_point, SEEK_SET); 00624 pause_restart_point = 0; 00625 } 00626 else if (end || offset < 0) { 00627 if (offset == -8) { 00628 offset = 0; 00629 } 00630 ast_verb(3, "ControlPlayback seek to offset %ld from end\n", offset); 00631 00632 ast_seekstream(chan->stream, offset, SEEK_END); 00633 end = NULL; 00634 offset = 0; 00635 } else if (offset) { 00636 ast_verb(3, "ControlPlayback seek to offset %ld\n", offset); 00637 ast_seekstream(chan->stream, offset, SEEK_SET); 00638 offset = 0; 00639 } 00640 res = ast_waitstream_fr(chan, breaks, fwd, rev, skipms); 00641 } 00642 00643 if (res < 1) { 00644 break; 00645 } 00646 00647 /* We go at next loop if we got the restart char */ 00648 if (restart && strchr(restart, res)) { 00649 ast_debug(1, "we'll restart the stream here at next loop\n"); 00650 pause_restart_point = 0; 00651 continue; 00652 } 00653 00654 if (suspend && strchr(suspend, res)) { 00655 pause_restart_point = ast_tellstream(chan->stream); 00656 for (;;) { 00657 ast_stopstream(chan); 00658 if (!(res = ast_waitfordigit(chan, 1000))) { 00659 continue; 00660 } else if (res == -1 || strchr(suspend, res) || (stop && strchr(stop, res))) { 00661 break; 00662 } 00663 } 00664 if (res == *suspend) { 00665 res = 0; 00666 continue; 00667 } 00668 } 00669 00670 if (res == -1) { 00671 break; 00672 } 00673 00674 /* if we get one of our stop chars, return it to the calling function */ 00675 if (stop && strchr(stop, res)) { 00676 break; 00677 } 00678 } 00679 00680 if (pause_restart_point) { 00681 offset = pause_restart_point; 00682 } else { 00683 if (chan->stream) { 00684 offset = ast_tellstream(chan->stream); 00685 } else { 00686 offset = -8; /* indicate end of file */ 00687 } 00688 } 00689 00690 if (offsetms) { 00691 *offsetms = offset / 8; /* samples --> ms ... XXX Assumes 8 kHz */ 00692 } 00693 00694 /* If we are returning a digit cast it as char */ 00695 if (res > 0 || chan->stream) { 00696 res = (char)res; 00697 } 00698 00699 ast_stopstream(chan); 00700 00701 return res; 00702 }
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.
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 383 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(), and LOG_WARNING.
Referenced by ast_bridge_call(), ast_eivr_senddtmf(), bridge_channel_dtmf_stream(), dial_exec_full(), handle_cli_misdn_send_digit(), senddtmf_exec(), testclient_exec(), testserver_exec(), and wait_for_answer().
00384 { 00385 const char *ptr; 00386 int res = 0; 00387 struct ast_silence_generator *silgen = NULL; 00388 00389 if (!between) { 00390 between = 100; 00391 } 00392 00393 if (peer) { 00394 res = ast_autoservice_start(peer); 00395 } 00396 00397 if (!res) { 00398 res = ast_waitfor(chan, 100); 00399 } 00400 00401 /* ast_waitfor will return the number of remaining ms on success */ 00402 if (res < 0) { 00403 if (peer) { 00404 ast_autoservice_stop(peer); 00405 } 00406 return res; 00407 } 00408 00409 if (ast_opt_transmit_silence) { 00410 silgen = ast_channel_start_silence_generator(chan); 00411 } 00412 00413 for (ptr = digits; *ptr; ptr++) { 00414 if (*ptr == 'w') { 00415 /* 'w' -- wait half a second */ 00416 if ((res = ast_safe_sleep(chan, 500))) { 00417 break; 00418 } 00419 } else if (strchr("0123456789*#abcdfABCDF", *ptr)) { 00420 /* Character represents valid DTMF */ 00421 if (*ptr == 'f' || *ptr == 'F') { 00422 /* ignore return values if not supported by channel */ 00423 ast_indicate(chan, AST_CONTROL_FLASH); 00424 } else { 00425 ast_senddigit(chan, *ptr, duration); 00426 } 00427 /* pause between digits */ 00428 if ((res = ast_safe_sleep(chan, between))) { 00429 break; 00430 } 00431 } else { 00432 ast_log(LOG_WARNING, "Illegal DTMF character '%c' in string. (0-9*#aAbBcCdD allowed)\n", *ptr); 00433 } 00434 } 00435 00436 if (peer) { 00437 /* Stop autoservice on the peer channel, but don't overwrite any error condition 00438 that has occurred previously while acting on the primary channel */ 00439 if (ast_autoservice_stop(peer) && !res) { 00440 res = -1; 00441 } 00442 } 00443 00444 if (silgen) { 00445 ast_channel_stop_silence_generator(chan, silgen); 00446 } 00447 00448 return res; 00449 }
int ast_get_encoded_char | ( | const char * | stream, | |
char * | result, | |||
size_t * | consumed | |||
) |
Decode an encoded control or extended ASCII character.
[in] | stream | String to decode |
[out] | result | Decoded character |
[out] | consumed | Number of characters used in stream to encode the character |
-1 | Stream is of zero length | |
0 | Success |
Definition at line 1995 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(), function_fieldnum_helper(), function_fieldqty_helper(), replace(), shift_pop(), and unshift_push().
01996 { 01997 int i; 01998 *consumed = 1; 01999 *result = 0; 02000 if (ast_strlen_zero(stream)) { 02001 *consumed = 0; 02002 return -1; 02003 } 02004 02005 if (*stream == '\\') { 02006 *consumed = 2; 02007 switch (*(stream + 1)) { 02008 case 'n': 02009 *result = '\n'; 02010 break; 02011 case 'r': 02012 *result = '\r'; 02013 break; 02014 case 't': 02015 *result = '\t'; 02016 break; 02017 case 'x': 02018 /* Hexadecimal */ 02019 if (strchr("0123456789ABCDEFabcdef", *(stream + 2)) && *(stream + 2) != '\0') { 02020 *consumed = 3; 02021 if (*(stream + 2) <= '9') { 02022 *result = *(stream + 2) - '0'; 02023 } else if (*(stream + 2) <= 'F') { 02024 *result = *(stream + 2) - 'A' + 10; 02025 } else { 02026 *result = *(stream + 2) - 'a' + 10; 02027 } 02028 } else { 02029 ast_log(LOG_ERROR, "Illegal character '%c' in hexadecimal string\n", *(stream + 2)); 02030 return -1; 02031 } 02032 02033 if (strchr("0123456789ABCDEFabcdef", *(stream + 3)) && *(stream + 3) != '\0') { 02034 *consumed = 4; 02035 *result <<= 4; 02036 if (*(stream + 3) <= '9') { 02037 *result += *(stream + 3) - '0'; 02038 } else if (*(stream + 3) <= 'F') { 02039 *result += *(stream + 3) - 'A' + 10; 02040 } else { 02041 *result += *(stream + 3) - 'a' + 10; 02042 } 02043 } 02044 break; 02045 case '0': 02046 /* Octal */ 02047 *consumed = 2; 02048 for (i = 2; ; i++) { 02049 if (strchr("01234567", *(stream + i)) && *(stream + i) != '\0') { 02050 (*consumed)++; 02051 ast_debug(5, "result was %d, ", *result); 02052 *result <<= 3; 02053 *result += *(stream + i) - '0'; 02054 ast_debug(5, "is now %d\n", *result); 02055 } else { 02056 break; 02057 } 02058 } 02059 break; 02060 default: 02061 *result = *(stream + 1); 02062 } 02063 } else { 02064 *result = *stream; 02065 *consumed = 1; 02066 } 02067 return 0; 02068 }
char* ast_get_encoded_str | ( | const char * | stream, | |
char * | result, | |||
size_t | result_len | |||
) |
Decode a stream of encoded control or extended ASCII characters.
[in] | stream | Encoded string |
[out] | result | Decoded string |
[in] | result_len | Maximum size of the result buffer |
Definition at line 2070 of file app.c.
References ast_get_encoded_char().
Referenced by listfilter(), mgcp_new(), replace(), sip_addheader(), and sip_new().
02071 { 02072 char *cur = result; 02073 size_t consumed; 02074 02075 while (cur < result + result_size - 1 && !ast_get_encoded_char(stream, cur, &consumed)) { 02076 cur++; 02077 stream += consumed; 02078 } 02079 *cur = '\0'; 02080 return result; 02081 }
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.
[in] | has_voicemail_func | set function pointer |
[in] | inboxcount2_func | set function pointer |
[in] | sayname_func | set function pointer |
[in] | inboxcount_func | set function pointer |
[in] | messagecount_func | set function pointer |
Definition at line 281 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().
00286 { 00287 ast_has_voicemail_func = has_voicemail_func; 00288 ast_inboxcount_func = inboxcount_func; 00289 ast_inboxcount2_func = inboxcount2_func; 00290 ast_messagecount_func = messagecount_func; 00291 ast_sayname_func = sayname_func; 00292 }
int ast_ivr_menu_run | ( | struct ast_channel * | c, | |
struct ast_ivr_menu * | menu, | |||
void * | cbdata | |||
) |
Runs an IVR menu.
Definition at line 1853 of file app.c.
References ast_ivr_menu_run_internal().
Referenced by skel_exec().
01854 { 01855 int res = ast_ivr_menu_run_internal(chan, menu, cbdata); 01856 /* Hide internal coding */ 01857 return res > 0 ? 0 : res; 01858 }
static int ast_ivr_menu_run_internal | ( | struct ast_channel * | chan, | |
struct ast_ivr_menu * | menu, | |||
void * | cbdata | |||
) | [static] |
Definition at line 1768 of file app.c.
References ast_debug, AST_DIGIT_ANY, ast_log(), AST_MAX_EXTENSION, 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().
01769 { 01770 /* Execute an IVR menu structure */ 01771 int res = 0; 01772 int pos = 0; 01773 int retries = 0; 01774 char exten[AST_MAX_EXTENSION] = "s"; 01775 if (option_exists(menu, "s") < 0) { 01776 strcpy(exten, "g"); 01777 if (option_exists(menu, "g") < 0) { 01778 ast_log(LOG_WARNING, "No 's' nor 'g' extension in menu '%s'!\n", menu->title); 01779 return -1; 01780 } 01781 } 01782 while (!res) { 01783 while (menu->options[pos].option) { 01784 if (!strcasecmp(menu->options[pos].option, exten)) { 01785 res = ivr_dispatch(chan, menu->options + pos, exten, cbdata); 01786 ast_debug(1, "IVR Dispatch of '%s' (pos %d) yields %d\n", exten, pos, res); 01787 if (res < 0) { 01788 break; 01789 } else if (res & RES_UPONE) { 01790 return 0; 01791 } else if (res & RES_EXIT) { 01792 return res; 01793 } else if (res & RES_REPEAT) { 01794 int maxretries = res & 0xffff; 01795 if ((res & RES_RESTART) == RES_RESTART) { 01796 retries = 0; 01797 } else { 01798 retries++; 01799 } 01800 if (!maxretries) { 01801 maxretries = 3; 01802 } 01803 if ((maxretries > 0) && (retries >= maxretries)) { 01804 ast_debug(1, "Max retries %d exceeded\n", maxretries); 01805 return -2; 01806 } else { 01807 if (option_exists(menu, "g") > -1) { 01808 strcpy(exten, "g"); 01809 } else if (option_exists(menu, "s") > -1) { 01810 strcpy(exten, "s"); 01811 } 01812 } 01813 pos = 0; 01814 continue; 01815 } else if (res && strchr(AST_DIGIT_ANY, res)) { 01816 ast_debug(1, "Got start of extension, %c\n", res); 01817 exten[1] = '\0'; 01818 exten[0] = res; 01819 if ((res = read_newoption(chan, menu, exten, sizeof(exten)))) { 01820 break; 01821 } 01822 if (option_exists(menu, exten) < 0) { 01823 if (option_exists(menu, "i")) { 01824 ast_debug(1, "Invalid extension entered, going to 'i'!\n"); 01825 strcpy(exten, "i"); 01826 pos = 0; 01827 continue; 01828 } else { 01829 ast_debug(1, "Aborting on invalid entry, with no 'i' option!\n"); 01830 res = -2; 01831 break; 01832 } 01833 } else { 01834 ast_debug(1, "New existing extension: %s\n", exten); 01835 pos = 0; 01836 continue; 01837 } 01838 } 01839 } 01840 pos++; 01841 } 01842 ast_debug(1, "Stopping option '%s', res is %d\n", exten, res); 01843 pos = 0; 01844 if (!strcasecmp(exten, "s")) { 01845 strcpy(exten, "g"); 01846 } else { 01847 break; 01848 } 01849 } 01850 return res; 01851 }
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 535 of file app.c.
References linear_state::allowoverride, ast_activate_generator(), ast_calloc, ast_config_AST_DATA_DIR, ast_copy_string(), ast_log(), ast_strlen_zero(), linear_state::autoclose, errno, linear_state::fd, linearstream, and LOG_WARNING.
00536 { 00537 struct linear_state *lin; 00538 char tmpf[256]; 00539 int res = -1; 00540 int autoclose = 0; 00541 if (fd < 0) { 00542 if (ast_strlen_zero(filename)) { 00543 return -1; 00544 } 00545 autoclose = 1; 00546 if (filename[0] == '/') { 00547 ast_copy_string(tmpf, filename, sizeof(tmpf)); 00548 } else { 00549 snprintf(tmpf, sizeof(tmpf), "%s/%s/%s", ast_config_AST_DATA_DIR, "sounds", filename); 00550 } 00551 if ((fd = open(tmpf, O_RDONLY)) < 0) { 00552 ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", tmpf, strerror(errno)); 00553 return -1; 00554 } 00555 } 00556 if ((lin = ast_calloc(1, sizeof(*lin)))) { 00557 lin->fd = fd; 00558 lin->allowoverride = allowoverride; 00559 lin->autoclose = autoclose; 00560 res = ast_activate_generator(chan, &linearstream, lin); 00561 } 00562 return res; 00563 }
enum AST_LOCK_RESULT ast_lock_path | ( | const char * | path | ) |
Lock a filesystem path.
path | the path to be locked |
Definition at line 1525 of file app.c.
References AST_LOCK_FAILURE, ast_lock_path_flock(), ast_lock_path_lockfile(), ast_lock_type, AST_LOCK_TYPE_FLOCK, and AST_LOCK_TYPE_LOCKFILE.
Referenced by ast_module_reload(), and vm_lock_path().
01526 { 01527 enum AST_LOCK_RESULT r = AST_LOCK_FAILURE; 01528 01529 switch (ast_lock_type) { 01530 case AST_LOCK_TYPE_LOCKFILE: 01531 r = ast_lock_path_lockfile(path); 01532 break; 01533 case AST_LOCK_TYPE_FLOCK: 01534 r = ast_lock_path_flock(path); 01535 break; 01536 } 01537 01538 return r; 01539 }
static enum AST_LOCK_RESULT ast_lock_path_flock | ( | const char * | path | ) | [static] |
Definition at line 1405 of file app.c.
References ast_alloca, 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, LOG_WARNING, path_lock::path, path_lock_destroy(), and strdup.
Referenced by ast_lock_path().
01406 { 01407 char *fs; 01408 int res; 01409 int fd; 01410 time_t start; 01411 struct path_lock *pl; 01412 struct stat st, ost; 01413 01414 fs = ast_alloca(strlen(path) + 20); 01415 01416 snprintf(fs, strlen(path) + 19, "%s/lock", path); 01417 if (lstat(fs, &st) == 0) { 01418 if ((st.st_mode & S_IFMT) == S_IFLNK) { 01419 ast_log(LOG_WARNING, "Unable to create lock file " 01420 "'%s': it's already a symbolic link\n", 01421 fs); 01422 return AST_LOCK_FAILURE; 01423 } 01424 if (st.st_nlink > 1) { 01425 ast_log(LOG_WARNING, "Unable to create lock file " 01426 "'%s': %u hard links exist\n", 01427 fs, (unsigned int) st.st_nlink); 01428 return AST_LOCK_FAILURE; 01429 } 01430 } 01431 if ((fd = open(fs, O_WRONLY | O_CREAT, 0600)) < 0) { 01432 ast_log(LOG_WARNING, "Unable to create lock file '%s': %s\n", 01433 fs, strerror(errno)); 01434 return AST_LOCK_PATH_NOT_FOUND; 01435 } 01436 if (!(pl = ast_calloc(1, sizeof(*pl)))) { 01437 /* We don't unlink the lock file here, on the possibility that 01438 * someone else created it - better to leave a little mess 01439 * than create a big one by destroying someone else's lock 01440 * and causing something to be corrupted. 01441 */ 01442 close(fd); 01443 return AST_LOCK_FAILURE; 01444 } 01445 pl->fd = fd; 01446 pl->path = strdup(path); 01447 01448 time(&start); 01449 while ( 01450 #ifdef SOLARIS 01451 ((res = fcntl(pl->fd, F_SETLK, fcntl(pl->fd, F_GETFL) | O_NONBLOCK)) < 0) && 01452 #else 01453 ((res = flock(pl->fd, LOCK_EX | LOCK_NB)) < 0) && 01454 #endif 01455 (errno == EWOULDBLOCK) && 01456 (time(NULL) - start < 5)) 01457 usleep(1000); 01458 if (res) { 01459 ast_log(LOG_WARNING, "Failed to lock path '%s': %s\n", 01460 path, strerror(errno)); 01461 /* No unlinking of lock done, since we tried and failed to 01462 * flock() it. 01463 */ 01464 path_lock_destroy(pl); 01465 return AST_LOCK_TIMEOUT; 01466 } 01467 01468 /* Check for the race where the file is recreated or deleted out from 01469 * underneath us. 01470 */ 01471 if (lstat(fs, &st) != 0 && fstat(pl->fd, &ost) != 0 && 01472 st.st_dev != ost.st_dev && 01473 st.st_ino != ost.st_ino) { 01474 ast_log(LOG_WARNING, "Unable to create lock file '%s': " 01475 "file changed underneath us\n", fs); 01476 path_lock_destroy(pl); 01477 return AST_LOCK_FAILURE; 01478 } 01479 01480 /* Success: file created, flocked, and is the one we started with */ 01481 AST_LIST_LOCK(&path_lock_list); 01482 AST_LIST_INSERT_TAIL(&path_lock_list, pl, le); 01483 AST_LIST_UNLOCK(&path_lock_list); 01484 01485 ast_debug(1, "Locked path '%s'\n", path); 01486 01487 return AST_LOCK_SUCCESS; 01488 }
static enum AST_LOCK_RESULT ast_lock_path_lockfile | ( | const char * | path | ) | [static] |
Definition at line 1331 of file app.c.
References ast_alloca, ast_debug, AST_FILE_MODE, AST_LOCK_PATH_NOT_FOUND, AST_LOCK_SUCCESS, AST_LOCK_TIMEOUT, ast_log(), ast_random(), errno, LOG_ERROR, and LOG_WARNING.
Referenced by ast_lock_path().
01332 { 01333 char *s; 01334 char *fs; 01335 int res; 01336 int fd; 01337 int lp = strlen(path); 01338 time_t start; 01339 01340 s = ast_alloca(lp + 10); 01341 fs = ast_alloca(lp + 20); 01342 01343 snprintf(fs, strlen(path) + 19, "%s/.lock-%08lx", path, ast_random()); 01344 fd = open(fs, O_WRONLY | O_CREAT | O_EXCL, AST_FILE_MODE); 01345 if (fd < 0) { 01346 ast_log(LOG_ERROR, "Unable to create lock file '%s': %s\n", path, strerror(errno)); 01347 return AST_LOCK_PATH_NOT_FOUND; 01348 } 01349 close(fd); 01350 01351 snprintf(s, strlen(path) + 9, "%s/.lock", path); 01352 start = time(NULL); 01353 while (((res = link(fs, s)) < 0) && (errno == EEXIST) && (time(NULL) - start < 5)) { 01354 sched_yield(); 01355 } 01356 01357 unlink(fs); 01358 01359 if (res) { 01360 ast_log(LOG_WARNING, "Failed to lock path '%s': %s\n", path, strerror(errno)); 01361 return AST_LOCK_TIMEOUT; 01362 } else { 01363 ast_debug(1, "Locked path '%s'\n", path); 01364 return AST_LOCK_SUCCESS; 01365 } 01366 }
int ast_play_and_prepend | ( | struct ast_channel * | chan, | |
char * | playfile, | |||
char * | recordfile, | |||
int | maxtime_sec, | |||
char * | fmt, | |||
int * | duration, | |||
int * | sound_duration, | |||
int | beep, | |||
int | silencethreshold, | |||
int | maxsilence_ms | |||
) |
Record a file based on input frm a channel. Recording is performed in 'prepend' mode which works a little differently from normal recordings This function will not play a success message due to post-recording control in the application this was added for.
chan | the channel being recorded | |
playfile | Filename of sound to play before recording begins | |
recordfile | Filename to save the recording | |
maxtime_sec | Longest possible message length in seconds | |
fmt | string containing all formats to be recorded delimited by '|' | |
duration | pointer to integer for storing length of the recording | |
sound_duration | pointer to integer for storing length of the recording minus all silence | |
beep | whether to play a beep to prompt the recording | |
silencethreshold | tolerance of noise levels that can be considered silence for the purpose of silence timeout, -1 for default | |
maxsilence_ms | length of time in milliseconds which will trigger a timeout from silence, -1 for default. |
-1 | failure or hangup | |
'S' | Recording ended from silence timeout | |
't' | Recording either exceeded maximum duration or the call was ended via DTMF |
Definition at line 1061 of file app.c.
References __ast_play_and_record(), default_acceptdtmf, and default_canceldtmf.
Referenced by vm_forwardoptions().
01062 { 01063 return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, sound_duration, beep, silencethreshold, maxsilence, NULL, 1, default_acceptdtmf, default_canceldtmf, 1); 01064 }
int ast_play_and_record | ( | struct ast_channel * | chan, | |
const char * | playfile, | |||
const char * | recordfile, | |||
int | maxtime_sec, | |||
const char * | fmt, | |||
int * | duration, | |||
int * | sound_duration, | |||
int | silencethreshold, | |||
int | maxsilence_ms, | |||
const char * | path | |||
) |
Record a file based on input from a channel. Use default accept and cancel DTMF. This function will play "auth-thankyou" upon successful recording.
chan | the channel being recorded | |
playfile | Filename of sound to play before recording begins | |
recordfile | Filename to save the recording | |
maxtime_sec | Longest possible message length in seconds | |
fmt | string containing all formats to be recorded delimited by '|' | |
duration | pointer to integer for storing length of the recording | |
sound_duration | pointer to integer for storing length of the recording minus all silence | |
silencethreshold | tolerance of noise levels that can be considered silence for the purpose of silence timeout, -1 for default | |
maxsilence_ms | length of time in milliseconds which will trigger a timeout from silence, -1 for default | |
path | Optional filesystem path to unlock |
-1 | failure or hangup | |
'S' | Recording ended from silence timeout | |
't' | Recording ended from the message exceeding the maximum duration | |
dtmfchar | Recording ended via the return value's DTMF character for either cancel or accept. |
Definition at line 1056 of file app.c.
References __ast_play_and_record(), default_acceptdtmf, and default_canceldtmf.
Referenced by app_exec(), ast_record_review(), conf_run(), and setup_privacy_args().
01057 { 01058 return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, sound_duration, 0, silencethreshold, maxsilence, path, 0, default_acceptdtmf, default_canceldtmf, 0); 01059 }
int ast_play_and_record_full | ( | struct ast_channel * | chan, | |
const char * | playfile, | |||
const char * | recordfile, | |||
int | maxtime_sec, | |||
const char * | fmt, | |||
int * | duration, | |||
int * | sound_duration, | |||
int | silencethreshold, | |||
int | maxsilence_ms, | |||
const char * | path, | |||
const char * | acceptdtmf, | |||
const char * | canceldtmf | |||
) |
Record a file based on input from a channel This function will play "auth-thankyou" upon successful recording.
chan | the channel being recorded | |
playfile | Filename of sound to play before recording begins | |
recordfile | Filename to save the recording | |
maxtime_sec | Longest possible message length in seconds | |
fmt | string containing all formats to be recorded delimited by '|' | |
duration | pointer to integer for storing length of the recording | |
sound_duration | pointer to integer for storing length of the recording minus all silence | |
silencethreshold | tolerance of noise levels that can be considered silence for the purpose of silence timeout, -1 for default | |
maxsilence_ms | Length of time in milliseconds which will trigger a timeout from silence, -1 for default | |
path | Optional filesystem path to unlock | |
acceptdtmf | Character of DTMF to end and accept the recording | |
canceldtmf | Character of DTMF to end and cancel the recording |
-1 | failure or hangup | |
'S' | Recording ended from silence timeout | |
't' | Recording ended from the message exceeding the maximum duration | |
dtmfchar | Recording ended via the return value's DTMF character for either cancel or accept. |
Definition at line 1051 of file app.c.
References __ast_play_and_record(), default_acceptdtmf, default_canceldtmf, and S_OR.
Referenced by play_record_review().
01052 { 01053 return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, sound_duration, 0, silencethreshold, maxsilence, path, 0, S_OR(acceptdtmf, default_acceptdtmf), S_OR(canceldtmf, default_canceldtmf), 0); 01054 }
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 704 of file app.c.
References AST_DIGIT_ANY, ast_stopstream(), ast_streamfile(), ast_test_suite_event_notify, and ast_waitstream().
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_vi(), vm_browse_messages_zh(), vm_exec(), vm_execmain(), vm_forwardoptions(), vm_instructions_en(), vm_instructions_zh(), vm_intro(), vm_intro_cs(), 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_vi(), vm_intro_zh(), 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().
00705 { 00706 int d = 0; 00707 00708 ast_test_suite_event_notify("PLAYBACK", "Message: %s", fn); 00709 if ((d = ast_streamfile(chan, fn, chan->language))) { 00710 return d; 00711 } 00712 00713 d = ast_waitstream(chan, AST_DIGIT_ANY); 00714 00715 ast_stopstream(chan); 00716 00717 return d; 00718 }
char* ast_read_textfile | ( | const char * | filename | ) |
Read a file into asterisk.
Definition at line 1860 of file app.c.
References ast_free, ast_log(), ast_malloc, errno, and LOG_WARNING.
Referenced by readfile_exec().
01861 { 01862 int fd, count = 0, res; 01863 char *output = NULL; 01864 struct stat filesize; 01865 01866 if (stat(filename, &filesize) == -1) { 01867 ast_log(LOG_WARNING, "Error can't stat %s\n", filename); 01868 return NULL; 01869 } 01870 01871 count = filesize.st_size + 1; 01872 01873 if ((fd = open(filename, O_RDONLY)) < 0) { 01874 ast_log(LOG_WARNING, "Cannot open file '%s' for reading: %s\n", filename, strerror(errno)); 01875 return NULL; 01876 } 01877 01878 if ((output = ast_malloc(count))) { 01879 res = read(fd, output, count - 1); 01880 if (res == count - 1) { 01881 output[res] = '\0'; 01882 } else { 01883 ast_log(LOG_WARNING, "Short read of %s (%d of %d): %s\n", filename, res, count - 1, strerror(errno)); 01884 ast_free(output); 01885 output = NULL; 01886 } 01887 } 01888 01889 close(fd); 01890 01891 return output; 01892 }
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 1557 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(), LOG_WARNING, maxsilence, silencethreshold, and THRESHOLD_SILENCE.
Referenced by conf_run().
01558 { 01559 int silencethreshold; 01560 int maxsilence = 0; 01561 int res = 0; 01562 int cmd = 0; 01563 int max_attempts = 3; 01564 int attempts = 0; 01565 int recorded = 0; 01566 int message_exists = 0; 01567 /* Note that urgent and private are for flagging messages as such in the future */ 01568 01569 /* barf if no pointer passed to store duration in */ 01570 if (!duration) { 01571 ast_log(LOG_WARNING, "Error ast_record_review called without duration pointer\n"); 01572 return -1; 01573 } 01574 01575 cmd = '3'; /* Want to start by recording */ 01576 01577 silencethreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE); 01578 01579 while ((cmd >= 0) && (cmd != 't')) { 01580 switch (cmd) { 01581 case '1': 01582 if (!message_exists) { 01583 /* In this case, 1 is to record a message */ 01584 cmd = '3'; 01585 break; 01586 } else { 01587 ast_stream_and_wait(chan, "vm-msgsaved", ""); 01588 cmd = 't'; 01589 return res; 01590 } 01591 case '2': 01592 /* Review */ 01593 ast_verb(3, "Reviewing the recording\n"); 01594 cmd = ast_stream_and_wait(chan, recordfile, AST_DIGIT_ANY); 01595 break; 01596 case '3': 01597 message_exists = 0; 01598 /* Record */ 01599 ast_verb(3, "R%secording\n", recorded == 1 ? "e-r" : ""); 01600 recorded = 1; 01601 if ((cmd = ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, NULL, silencethreshold, maxsilence, path)) == -1) { 01602 /* User has hung up, no options to give */ 01603 return cmd; 01604 } 01605 if (cmd == '0') { 01606 break; 01607 } else if (cmd == '*') { 01608 break; 01609 } else { 01610 /* If all is well, a message exists */ 01611 message_exists = 1; 01612 cmd = 0; 01613 } 01614 break; 01615 case '4': 01616 case '5': 01617 case '6': 01618 case '7': 01619 case '8': 01620 case '9': 01621 case '*': 01622 case '#': 01623 cmd = ast_play_and_wait(chan, "vm-sorry"); 01624 break; 01625 default: 01626 if (message_exists) { 01627 cmd = ast_play_and_wait(chan, "vm-review"); 01628 } else { 01629 if (!(cmd = ast_play_and_wait(chan, "vm-torerecord"))) { 01630 cmd = ast_waitfordigit(chan, 600); 01631 } 01632 } 01633 01634 if (!cmd) { 01635 cmd = ast_waitfordigit(chan, 6000); 01636 } 01637 if (!cmd) { 01638 attempts++; 01639 } 01640 if (attempts > max_attempts) { 01641 cmd = 't'; 01642 } 01643 } 01644 } 01645 if (cmd == 't') { 01646 cmd = 0; 01647 } 01648 return cmd; 01649 }
int ast_safe_fork | ( | int | stop_reaper | ) |
Common routine to safely fork without a chance of a signal handler firing badly in the child.
[in] | stop_reaper | flag to determine if sigchld handler is replaced or not |
Definition at line 2115 of file app.c.
References ast_calloc, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_log(), ast_pthread_create_background, AST_PTHREADT_NULL, ast_replace_sigchld(), errno, zombie::list, LOG_ERROR, LOG_WARNING, zombie::pid, and shaun_of_the_dead().
Referenced by app_exec(), filestream_destructor(), icesencode(), launch_script(), mp3play(), NBScatplay(), send_waveform_to_fd(), spawn_mp3(), spawn_ras(), and vm_check_password_shell().
02116 { 02117 sigset_t signal_set, old_set; 02118 int pid; 02119 02120 /* Don't let the default signal handler for children reap our status */ 02121 if (stop_reaper) { 02122 ast_replace_sigchld(); 02123 } 02124 02125 sigfillset(&signal_set); 02126 pthread_sigmask(SIG_BLOCK, &signal_set, &old_set); 02127 02128 pid = fork(); 02129 02130 if (pid != 0) { 02131 /* Fork failed or parent */ 02132 pthread_sigmask(SIG_SETMASK, &old_set, NULL); 02133 if (!stop_reaper && pid > 0) { 02134 struct zombie *cur = ast_calloc(1, sizeof(*cur)); 02135 if (cur) { 02136 cur->pid = pid; 02137 AST_LIST_LOCK(&zombies); 02138 AST_LIST_INSERT_TAIL(&zombies, cur, list); 02139 AST_LIST_UNLOCK(&zombies); 02140 if (shaun_of_the_dead_thread == AST_PTHREADT_NULL) { 02141 if (ast_pthread_create_background(&shaun_of_the_dead_thread, NULL, shaun_of_the_dead, NULL)) { 02142 ast_log(LOG_ERROR, "Shaun of the Dead wants to kill zombies, but can't?!!\n"); 02143 shaun_of_the_dead_thread = AST_PTHREADT_NULL; 02144 } 02145 } 02146 } 02147 } 02148 return pid; 02149 } else { 02150 /* Child */ 02151 #ifdef HAVE_CAP 02152 cap_t cap = cap_from_text("cap_net_admin-eip"); 02153 02154 if (cap_set_proc(cap)) { 02155 ast_log(LOG_WARNING, "Unable to remove capabilities.\n"); 02156 } 02157 cap_free(cap); 02158 #endif 02159 02160 /* Before we unblock our signals, return our trapped signals back to the defaults */ 02161 signal(SIGHUP, SIG_DFL); 02162 signal(SIGCHLD, SIG_DFL); 02163 signal(SIGINT, SIG_DFL); 02164 signal(SIGURG, SIG_DFL); 02165 signal(SIGTERM, SIG_DFL); 02166 signal(SIGPIPE, SIG_DFL); 02167 signal(SIGXFSZ, SIG_DFL); 02168 02169 /* unblock important signal handlers */ 02170 if (pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL)) { 02171 ast_log(LOG_WARNING, "unable to unblock signals: %s\n", strerror(errno)); 02172 _exit(1); 02173 } 02174 02175 return pid; 02176 } 02177 }
void ast_safe_fork_cleanup | ( | void | ) |
Common routine to cleanup after fork'ed process is complete (if reaping was stopped).
Definition at line 2179 of file app.c.
References ast_unreplace_sigchld().
Referenced by agi_exec_full(), and run_ras().
02180 { 02181 ast_unreplace_sigchld(); 02182 }
void ast_set_lock_type | ( | enum AST_LOCK_TYPE | type | ) |
Set the type of locks used by ast_lock_path().
type | the locking type to use |
Definition at line 1520 of file app.c.
References ast_lock_type.
Referenced by ast_readconfig().
01521 { 01522 ast_lock_type = type; 01523 }
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 2083 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(), and zombie::next.
Referenced by sendtext_exec(), and system_exec_helper().
02084 { 02085 char next, *buf; 02086 size_t offset = 0; 02087 size_t consumed; 02088 02089 if (strchr(stream, '\\')) { 02090 while (!ast_get_encoded_char(stream, &next, &consumed)) { 02091 if (offset + 2 > ast_str_size(*str) && maxlen > -1) { 02092 ast_str_make_space(str, maxlen > 0 ? maxlen : (ast_str_size(*str) + 48) * 2 - 48); 02093 } 02094 if (offset + 2 > ast_str_size(*str)) { 02095 break; 02096 } 02097 buf = ast_str_buffer(*str); 02098 buf[offset++] = next; 02099 stream += consumed; 02100 } 02101 buf = ast_str_buffer(*str); 02102 buf[offset++] = '\0'; 02103 ast_str_update(*str); 02104 } else { 02105 ast_str_set(str, maxlen, "%s", stream); 02106 } 02107 return 0; 02108 }
AST_THREADSTORAGE_PUBLIC | ( | ast_str_thread_global_buf | ) |
void ast_uninstall_vm_functions | ( | void | ) |
Definition at line 294 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().
00295 { 00296 ast_has_voicemail_func = NULL; 00297 ast_inboxcount_func = NULL; 00298 ast_inboxcount2_func = NULL; 00299 ast_messagecount_func = NULL; 00300 ast_sayname_func = NULL; 00301 }
int ast_unlock_path | ( | const char * | path | ) |
Unlock a path.
Definition at line 1541 of file app.c.
References ast_lock_type, 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(), ast_module_reload(), close_mailbox(), copy_message(), count_messages(), leave_voicemail(), open_mailbox(), resequence_mailbox(), and save_to_folder().
01542 { 01543 int r = 0; 01544 01545 switch (ast_lock_type) { 01546 case AST_LOCK_TYPE_LOCKFILE: 01547 r = ast_unlock_path_lockfile(path); 01548 break; 01549 case AST_LOCK_TYPE_FLOCK: 01550 r = ast_unlock_path_flock(path); 01551 break; 01552 } 01553 01554 return r; 01555 }
static int ast_unlock_path_flock | ( | const char * | path | ) | [static] |
Definition at line 1490 of file app.c.
References ast_alloca, 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, and path_lock_destroy().
Referenced by ast_unlock_path().
01491 { 01492 char *s; 01493 struct path_lock *p; 01494 01495 s = ast_alloca(strlen(path) + 20); 01496 01497 AST_LIST_LOCK(&path_lock_list); 01498 AST_LIST_TRAVERSE_SAFE_BEGIN(&path_lock_list, p, le) { 01499 if (!strcmp(p->path, path)) { 01500 AST_LIST_REMOVE_CURRENT(le); 01501 break; 01502 } 01503 } 01504 AST_LIST_TRAVERSE_SAFE_END; 01505 AST_LIST_UNLOCK(&path_lock_list); 01506 01507 if (p) { 01508 snprintf(s, strlen(path) + 19, "%s/lock", path); 01509 unlink(s); 01510 path_lock_destroy(p); 01511 ast_log(LOG_DEBUG, "Unlocked path '%s'\n", path); 01512 } else { 01513 ast_log(LOG_DEBUG, "Failed to unlock path '%s': " 01514 "lock not found\n", path); 01515 } 01516 01517 return 0; 01518 }
static int ast_unlock_path_lockfile | ( | const char * | path | ) | [static] |
Definition at line 1368 of file app.c.
References ast_alloca, ast_debug, ast_log(), errno, and LOG_ERROR.
Referenced by ast_unlock_path().
01369 { 01370 char *s; 01371 int res; 01372 01373 s = ast_alloca(strlen(path) + 10); 01374 01375 snprintf(s, strlen(path) + 9, "%s/%s", path, ".lock"); 01376 01377 if ((res = unlink(s))) { 01378 ast_log(LOG_ERROR, "Could not unlock path '%s': %s\n", path, strerror(errno)); 01379 } else { 01380 ast_debug(1, "Unlocked path '%s'\n", path); 01381 } 01382 01383 return res; 01384 }
static int ivr_dispatch | ( | struct ast_channel * | chan, | |
struct ast_ivr_option * | option, | |||
char * | exten, | |||
void * | cbdata | |||
) | [static] |
Definition at line 1658 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(), LOG_NOTICE, ast_channel::pbx, RES_EXIT, RES_REPEAT, RES_RESTART, RES_UPONE, and ast_pbx::rtimeoutms.
Referenced by ast_ivr_menu_run_internal().
01659 { 01660 int res; 01661 int (*ivr_func)(struct ast_channel *, void *); 01662 char *c; 01663 char *n; 01664 01665 switch (option->action) { 01666 case AST_ACTION_UPONE: 01667 return RES_UPONE; 01668 case AST_ACTION_EXIT: 01669 return RES_EXIT | (((unsigned long)(option->adata)) & 0xffff); 01670 case AST_ACTION_REPEAT: 01671 return RES_REPEAT | (((unsigned long)(option->adata)) & 0xffff); 01672 case AST_ACTION_RESTART: 01673 return RES_RESTART ; 01674 case AST_ACTION_NOOP: 01675 return 0; 01676 case AST_ACTION_BACKGROUND: 01677 res = ast_stream_and_wait(chan, (char *)option->adata, AST_DIGIT_ANY); 01678 if (res < 0) { 01679 ast_log(LOG_NOTICE, "Unable to find file '%s'!\n", (char *)option->adata); 01680 res = 0; 01681 } 01682 return res; 01683 case AST_ACTION_PLAYBACK: 01684 res = ast_stream_and_wait(chan, (char *)option->adata, ""); 01685 if (res < 0) { 01686 ast_log(LOG_NOTICE, "Unable to find file '%s'!\n", (char *)option->adata); 01687 res = 0; 01688 } 01689 return res; 01690 case AST_ACTION_MENU: 01691 if ((res = ast_ivr_menu_run_internal(chan, (struct ast_ivr_menu *)option->adata, cbdata)) == -2) { 01692 /* Do not pass entry errors back up, treat as though it was an "UPONE" */ 01693 res = 0; 01694 } 01695 return res; 01696 case AST_ACTION_WAITOPTION: 01697 if (!(res = ast_waitfordigit(chan, chan->pbx ? chan->pbx->rtimeoutms : 10000))) { 01698 return 't'; 01699 } 01700 return res; 01701 case AST_ACTION_CALLBACK: 01702 ivr_func = option->adata; 01703 res = ivr_func(chan, cbdata); 01704 return res; 01705 case AST_ACTION_TRANSFER: 01706 res = ast_parseable_goto(chan, option->adata); 01707 return 0; 01708 case AST_ACTION_PLAYLIST: 01709 case AST_ACTION_BACKLIST: 01710 res = 0; 01711 c = ast_strdupa(option->adata); 01712 while ((n = strsep(&c, ";"))) { 01713 if ((res = ast_stream_and_wait(chan, n, 01714 (option->action == AST_ACTION_BACKLIST) ? AST_DIGIT_ANY : ""))) { 01715 break; 01716 } 01717 } 01718 ast_stopstream(chan); 01719 return res; 01720 default: 01721 ast_log(LOG_NOTICE, "Unknown dispatch function %d, ignoring!\n", option->action); 01722 return 0; 01723 } 01724 return -1; 01725 }
static void* linear_alloc | ( | struct ast_channel * | chan, | |
void * | params | |||
) | [static] |
Definition at line 502 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(), LOG_WARNING, linear_state::origwfmt, and ast_channel::writeformat.
00503 { 00504 struct linear_state *ls = params; 00505 00506 if (!params) { 00507 return NULL; 00508 } 00509 00510 /* In this case, params is already malloc'd */ 00511 if (ls->allowoverride) { 00512 ast_set_flag(chan, AST_FLAG_WRITE_INT); 00513 } else { 00514 ast_clear_flag(chan, AST_FLAG_WRITE_INT); 00515 } 00516 00517 ls->origwfmt = chan->writeformat; 00518 00519 if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) { 00520 ast_log(LOG_WARNING, "Unable to set '%s' to linear format (write)\n", chan->name); 00521 ast_free(ls); 00522 ls = params = NULL; 00523 } 00524 00525 return params; 00526 }
static int linear_generator | ( | struct ast_channel * | chan, | |
void * | data, | |||
int | len, | |||
int | samples | |||
) | [static] |
Definition at line 473 of file app.c.
References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_write(), ast_frame::datalen, linear_state::fd, ast_frame::frametype, LOG_WARNING, and ast_frame::samples.
00474 { 00475 short buf[2048 + AST_FRIENDLY_OFFSET / 2]; 00476 struct linear_state *ls = data; 00477 struct ast_frame f = { 00478 .frametype = AST_FRAME_VOICE, 00479 .subclass.codec = AST_FORMAT_SLINEAR, 00480 .data.ptr = buf + AST_FRIENDLY_OFFSET / 2, 00481 .offset = AST_FRIENDLY_OFFSET, 00482 }; 00483 int res; 00484 00485 len = samples * 2; 00486 if (len > sizeof(buf) - AST_FRIENDLY_OFFSET) { 00487 ast_log(LOG_WARNING, "Can't generate %d bytes of data!\n" , len); 00488 len = sizeof(buf) - AST_FRIENDLY_OFFSET; 00489 } 00490 res = read(ls->fd, buf + AST_FRIENDLY_OFFSET/2, len); 00491 if (res > 0) { 00492 f.datalen = res; 00493 f.samples = res / 2; 00494 ast_write(chan, &f); 00495 if (res == len) { 00496 return 0; 00497 } 00498 } 00499 return -1; 00500 }
static void linear_release | ( | struct ast_channel * | chan, | |
void * | params | |||
) | [static] |
Definition at line 458 of file app.c.
References ast_free, ast_log(), ast_set_write_format(), linear_state::autoclose, linear_state::fd, LOG_WARNING, and linear_state::origwfmt.
00459 { 00460 struct linear_state *ls = params; 00461 00462 if (ls->origwfmt && ast_set_write_format(chan, ls->origwfmt)) { 00463 ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%d'\n", chan->name, ls->origwfmt); 00464 } 00465 00466 if (ls->autoclose) { 00467 close(ls->fd); 00468 } 00469 00470 ast_free(params); 00471 }
static int option_exists | ( | struct ast_ivr_menu * | menu, | |
char * | option | |||
) | [static] |
Definition at line 1727 of file app.c.
References ast_ivr_option::option, and ast_ivr_menu::options.
Referenced by ast_ivr_menu_run_internal().
static int option_matchmore | ( | struct ast_ivr_menu * | menu, | |
char * | option | |||
) | [static] |
Definition at line 1738 of file app.c.
References ast_ivr_option::option, and ast_ivr_menu::options.
Referenced by read_newoption().
static int parse_options | ( | const struct ast_app_option * | options, | |
void * | _flags, | |||
char ** | args, | |||
char * | optstr, | |||
int | flaglen | |||
) | [static] |
Definition at line 1894 of file app.c.
References ast_app_option::arg_index, ast_clear_flag, ast_copy_string(), AST_FLAGS_ALL, ast_log(), ast_set_flag, ast_set_flag64, ast_flags64::flags, ast_flags::flags, LOG_WARNING, paren, and quote().
Referenced by ast_app_parse_options(), and ast_app_parse_options64().
01895 { 01896 char *s, *arg; 01897 int curarg, res = 0; 01898 unsigned int argloc; 01899 struct ast_flags *flags = _flags; 01900 struct ast_flags64 *flags64 = _flags; 01901 01902 if (flaglen == 32) { 01903 ast_clear_flag(flags, AST_FLAGS_ALL); 01904 } else { 01905 flags64->flags = 0; 01906 } 01907 01908 if (!optstr) { 01909 return 0; 01910 } 01911 01912 s = optstr; 01913 while (*s) { 01914 curarg = *s++ & 0x7f; /* the array (in app.h) has 128 entries */ 01915 argloc = options[curarg].arg_index; 01916 if (*s == '(') { 01917 int paren = 1, quote = 0; 01918 int parsequotes = (s[1] == '"') ? 1 : 0; 01919 01920 /* Has argument */ 01921 arg = ++s; 01922 for (; *s; s++) { 01923 if (*s == '(' && !quote) { 01924 paren++; 01925 } else if (*s == ')' && !quote) { 01926 /* Count parentheses, unless they're within quotes (or backslashed, below) */ 01927 paren--; 01928 } else if (*s == '"' && parsequotes) { 01929 /* Leave embedded quotes alone, unless they are the first character */ 01930 quote = quote ? 0 : 1; 01931 ast_copy_string(s, s + 1, INT_MAX); 01932 s--; 01933 } else if (*s == '\\') { 01934 if (!quote) { 01935 /* If a backslash is found outside of quotes, remove it */ 01936 ast_copy_string(s, s + 1, INT_MAX); 01937 } else if (quote && s[1] == '"') { 01938 /* Backslash for a quote character within quotes, remove the backslash */ 01939 ast_copy_string(s, s + 1, INT_MAX); 01940 } else { 01941 /* Backslash within quotes, keep both characters */ 01942 s++; 01943 } 01944 } 01945 01946 if (paren == 0) { 01947 break; 01948 } 01949 } 01950 /* This will find the closing paren we found above, or none, if the string ended before we found one. */ 01951 if ((s = strchr(s, ')'))) { 01952 if (argloc) { 01953 args[argloc - 1] = arg; 01954 } 01955 *s++ = '\0'; 01956 } else { 01957 ast_log(LOG_WARNING, "Missing closing parenthesis for argument '%c' in string '%s'\n", curarg, arg); 01958 res = -1; 01959 break; 01960 } 01961 } else if (argloc) { 01962 args[argloc - 1] = ""; 01963 } 01964 if (flaglen == 32) { 01965 ast_set_flag(flags, options[curarg].flag); 01966 } else { 01967 ast_set_flag64(flags64, options[curarg].flag); 01968 } 01969 } 01970 01971 return res; 01972 }
static void path_lock_destroy | ( | struct path_lock * | obj | ) | [static] |
static int read_newoption | ( | struct ast_channel * | chan, | |
struct ast_ivr_menu * | menu, | |||
char * | exten, | |||
int | maxexten | |||
) | [static] |
Definition at line 1750 of file app.c.
References ast_waitfordigit(), ast_pbx::dtimeoutms, option_matchmore(), and ast_channel::pbx.
Referenced by ast_ivr_menu_run_internal().
01751 { 01752 int res = 0; 01753 int ms; 01754 while (option_matchmore(menu, exten)) { 01755 ms = chan->pbx ? chan->pbx->dtimeoutms : 5000; 01756 if (strlen(exten) >= maxexten - 1) { 01757 break; 01758 } 01759 if ((res = ast_waitfordigit(chan, ms)) < 1) { 01760 break; 01761 } 01762 exten[strlen(exten) + 1] = '\0'; 01763 exten[strlen(exten)] = res; 01764 } 01765 return res > 0 ? 0 : res; 01766 }
static void* shaun_of_the_dead | ( | void * | data | ) | [static] |
Definition at line 74 of file app.c.
References ast_free, AST_LIST_EMPTY, AST_LIST_FIRST, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_poll, zombie::pid, and status.
Referenced by ast_safe_fork().
00075 { 00076 struct zombie *cur; 00077 int status; 00078 for (;;) { 00079 if (!AST_LIST_EMPTY(&zombies)) { 00080 /* Don't allow cancellation while we have a lock. */ 00081 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); 00082 AST_LIST_LOCK(&zombies); 00083 AST_LIST_TRAVERSE_SAFE_BEGIN(&zombies, cur, list) { 00084 if (waitpid(cur->pid, &status, WNOHANG) != 0) { 00085 AST_LIST_REMOVE_CURRENT(list); 00086 ast_free(cur); 00087 } 00088 } 00089 AST_LIST_TRAVERSE_SAFE_END 00090 AST_LIST_UNLOCK(&zombies); 00091 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); 00092 } 00093 pthread_testcancel(); 00094 /* Wait for 60 seconds, without engaging in a busy loop. */ 00095 ast_poll(NULL, 0, AST_LIST_FIRST(&zombies) ? 5000 : 60000); 00096 } 00097 return NULL; 00098 }
int(* ast_has_voicemail_func)(const char *mailbox, const char *folder) = NULL [static] |
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] |
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] |
Referenced by ast_app_inboxcount(), ast_install_vm_functions(), and ast_uninstall_vm_functions().
enum AST_LOCK_TYPE ast_lock_type = AST_LOCK_TYPE_LOCKFILE [static] |
Definition at line 228 of file app.c.
Referenced by ast_lock_path(), ast_set_lock_type(), and ast_unlock_path().
int(* ast_messagecount_func)(const char *context, const char *mailbox, const char *folder) = NULL [static] |
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] |
Referenced by ast_app_sayname(), ast_install_vm_functions(), and ast_uninstall_vm_functions().
const char default_acceptdtmf[] = "#" [static] |
Definition at line 1048 of file app.c.
Referenced by ast_play_and_prepend(), ast_play_and_record(), and ast_play_and_record_full().
const char default_canceldtmf[] = "" [static] |
Definition at line 1049 of file app.c.
Referenced by ast_play_and_prepend(), ast_play_and_record(), and ast_play_and_record_full().
int global_maxsilence = 0 [static] |
Definition at line 721 of file app.c.
Referenced by __ast_play_and_record().
int global_silence_threshold = 128 [static] |
Definition at line 720 of file app.c.
Referenced by __ast_play_and_record().
struct ast_generator linearstream [static] |
Definition at line 528 of file app.c.
Referenced by ast_linear_stream().
pthread_t shaun_of_the_dead_thread = AST_PTHREADT_NULL [static] |