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"#include "asterisk/module.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. | |
| int | ast_app_exec_macro (struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const char *macro_args) |
| Run a macro on a channel, placing an optional second channel into autoservice. | |
| int | ast_app_exec_sub (struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int ignore_hangup) |
| Run a subroutine on a channel, placing an optional second channel into autoservice. | |
| const char * | ast_app_expand_sub_args (struct ast_channel *chan, const char *args) |
| Add missing context/exten to subroutine argument string. | |
| 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 *macro_name, const char *macro_args) |
| Run a macro on a channel, placing an optional second channel into autoservice. | |
| int | ast_app_run_sub (struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_location, const char *sub_args, int ignore_hangup) |
| Run a subroutine on a channel, placing an optional 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_stack_functions (const struct ast_app_stack_funcs *funcs) |
| Set stack application function callbacks. | |
| 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 struct ast_app_stack_funcs * | app_stack_callbacks |
| 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 1769 of file app.c.
Referenced by ast_ivr_menu_run_internal(), and ivr_dispatch().
| #define RES_REPEAT (1 << 18) |
Definition at line 1770 of file app.c.
Referenced by ast_ivr_menu_run_internal(), and ivr_dispatch().
| #define RES_RESTART ((1 << 19) | RES_REPEAT) |
Definition at line 1771 of file app.c.
Referenced by ast_ivr_menu_run_internal(), and ivr_dispatch().
| #define RES_UPONE (1 << 16) |
Definition at line 1768 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 1378 of file app.c.
References paren, and quote().
Referenced by ast_app_separate_args().
01379 { 01380 int argc; 01381 char *scan, *wasdelim = NULL; 01382 int paren = 0, quote = 0, bracket = 0; 01383 01384 if (!array || !arraylen) { 01385 return 0; 01386 } 01387 01388 memset(array, 0, arraylen * sizeof(*array)); 01389 01390 if (!buf) { 01391 return 0; 01392 } 01393 01394 scan = buf; 01395 01396 for (argc = 0; *scan && (argc < arraylen - 1); argc++) { 01397 array[argc] = scan; 01398 for (; *scan; scan++) { 01399 if (*scan == '(') { 01400 paren++; 01401 } else if (*scan == ')') { 01402 if (paren) { 01403 paren--; 01404 } 01405 } else if (*scan == '[') { 01406 bracket++; 01407 } else if (*scan == ']') { 01408 if (bracket) { 01409 bracket--; 01410 } 01411 } else if (*scan == '"' && delim != '"') { 01412 quote = quote ? 0 : 1; 01413 if (remove_chars) { 01414 /* Remove quote character from argument */ 01415 memmove(scan, scan + 1, strlen(scan)); 01416 scan--; 01417 } 01418 } else if (*scan == '\\') { 01419 if (remove_chars) { 01420 /* Literal character, don't parse */ 01421 memmove(scan, scan + 1, strlen(scan)); 01422 } else { 01423 scan++; 01424 } 01425 } else if ((*scan == delim) && !paren && !quote && !bracket) { 01426 wasdelim = scan; 01427 *scan++ = '\0'; 01428 break; 01429 } 01430 } 01431 } 01432 01433 /* If the last character in the original string was the delimiter, then 01434 * there is one additional argument. */ 01435 if (*scan || (scan > buf && (scan - 1) == wasdelim)) { 01436 array[argc++] = scan; 01437 } 01438 01439 return argc; 01440 }
| 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 862 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().
00863 { 00864 int d = 0; 00865 char *fmts; 00866 char comment[256]; 00867 int x, fmtcnt = 1, res = -1, outmsg = 0; 00868 struct ast_filestream *others[AST_MAX_FORMATS]; 00869 char *sfmt[AST_MAX_FORMATS]; 00870 char *stringp = NULL; 00871 time_t start, end; 00872 struct ast_dsp *sildet = NULL; /* silence detector dsp */ 00873 int totalsilence = 0; 00874 int dspsilence = 0; 00875 int olddspsilence = 0; 00876 int rfmt = 0; 00877 struct ast_silence_generator *silgen = NULL; 00878 char prependfile[80]; 00879 00880 if (silencethreshold < 0) { 00881 silencethreshold = global_silence_threshold; 00882 } 00883 00884 if (maxsilence < 0) { 00885 maxsilence = global_maxsilence; 00886 } 00887 00888 /* barf if no pointer passed to store duration in */ 00889 if (!duration) { 00890 ast_log(LOG_WARNING, "Error play_and_record called without duration pointer\n"); 00891 return -1; 00892 } 00893 00894 ast_debug(1, "play_and_record: %s, %s, '%s'\n", playfile ? playfile : "<None>", recordfile, fmt); 00895 snprintf(comment, sizeof(comment), "Playing %s, Recording to: %s on %s\n", playfile ? playfile : "<None>", recordfile, chan->name); 00896 00897 if (playfile || beep) { 00898 if (!beep) { 00899 d = ast_play_and_wait(chan, playfile); 00900 } 00901 if (d > -1) { 00902 d = ast_stream_and_wait(chan, "beep", ""); 00903 } 00904 if (d < 0) { 00905 return -1; 00906 } 00907 } 00908 00909 if (prepend) { 00910 ast_copy_string(prependfile, recordfile, sizeof(prependfile)); 00911 strncat(prependfile, "-prepend", sizeof(prependfile) - strlen(prependfile) - 1); 00912 } 00913 00914 fmts = ast_strdupa(fmt); 00915 00916 stringp = fmts; 00917 strsep(&stringp, "|"); 00918 ast_debug(1, "Recording Formats: sfmts=%s\n", fmts); 00919 sfmt[0] = ast_strdupa(fmts); 00920 00921 while ((fmt = strsep(&stringp, "|"))) { 00922 if (fmtcnt > AST_MAX_FORMATS - 1) { 00923 ast_log(LOG_WARNING, "Please increase AST_MAX_FORMATS in file.h\n"); 00924 break; 00925 } 00926 sfmt[fmtcnt++] = ast_strdupa(fmt); 00927 } 00928 00929 end = start = time(NULL); /* pre-initialize end to be same as start in case we never get into loop */ 00930 for (x = 0; x < fmtcnt; x++) { 00931 others[x] = ast_writefile(prepend ? prependfile : recordfile, sfmt[x], comment, O_TRUNC, 0, AST_FILE_MODE); 00932 ast_verb(3, "x=%d, open writing: %s format: %s, %p\n", x, prepend ? prependfile : recordfile, sfmt[x], others[x]); 00933 00934 if (!others[x]) { 00935 break; 00936 } 00937 } 00938 00939 if (path) { 00940 ast_unlock_path(path); 00941 } 00942 00943 if (maxsilence > 0) { 00944 sildet = ast_dsp_new(); /* Create the silence detector */ 00945 if (!sildet) { 00946 ast_log(LOG_WARNING, "Unable to create silence detector :(\n"); 00947 return -1; 00948 } 00949 ast_dsp_set_threshold(sildet, silencethreshold); 00950 rfmt = chan->readformat; 00951 res = ast_set_read_format(chan, AST_FORMAT_SLINEAR); 00952 if (res < 0) { 00953 ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n"); 00954 ast_dsp_free(sildet); 00955 return -1; 00956 } 00957 } 00958 00959 if (!prepend) { 00960 /* Request a video update */ 00961 ast_indicate(chan, AST_CONTROL_VIDUPDATE); 00962 00963 if (ast_opt_transmit_silence) { 00964 silgen = ast_channel_start_silence_generator(chan); 00965 } 00966 } 00967 00968 if (x == fmtcnt) { 00969 /* Loop forever, writing the packets we read to the writer(s), until 00970 we read a digit or get a hangup */ 00971 struct ast_frame *f; 00972 for (;;) { 00973 if (!(res = ast_waitfor(chan, 2000))) { 00974 ast_debug(1, "One waitfor failed, trying another\n"); 00975 /* Try one more time in case of masq */ 00976 if (!(res = ast_waitfor(chan, 2000))) { 00977 ast_log(LOG_WARNING, "No audio available on %s??\n", chan->name); 00978 res = -1; 00979 } 00980 } 00981 00982 if (res < 0) { 00983 f = NULL; 00984 break; 00985 } 00986 if (!(f = ast_read(chan))) { 00987 break; 00988 } 00989 if (f->frametype == AST_FRAME_VOICE) { 00990 /* write each format */ 00991 for (x = 0; x < fmtcnt; x++) { 00992 if (prepend && !others[x]) { 00993 break; 00994 } 00995 res = ast_writestream(others[x], f); 00996 } 00997 00998 /* Silence Detection */ 00999 if (maxsilence > 0) { 01000 dspsilence = 0; 01001 ast_dsp_silence(sildet, f, &dspsilence); 01002 if (olddspsilence > dspsilence) { 01003 totalsilence += olddspsilence; 01004 } 01005 olddspsilence = dspsilence; 01006 01007 if (dspsilence > maxsilence) { 01008 /* Ended happily with silence */ 01009 ast_verb(3, "Recording automatically stopped after a silence of %d seconds\n", dspsilence/1000); 01010 res = 'S'; 01011 outmsg = 2; 01012 break; 01013 } 01014 } 01015 /* Exit on any error */ 01016 if (res) { 01017 ast_log(LOG_WARNING, "Error writing frame\n"); 01018 break; 01019 } 01020 } else if (f->frametype == AST_FRAME_VIDEO) { 01021 /* Write only once */ 01022 ast_writestream(others[0], f); 01023 } else if (f->frametype == AST_FRAME_DTMF) { 01024 if (prepend) { 01025 /* stop recording with any digit */ 01026 ast_verb(3, "User ended message by pressing %c\n", f->subclass.integer); 01027 res = 't'; 01028 outmsg = 2; 01029 break; 01030 } 01031 if (strchr(acceptdtmf, f->subclass.integer)) { 01032 ast_verb(3, "User ended message by pressing %c\n", f->subclass.integer); 01033 res = f->subclass.integer; 01034 outmsg = 2; 01035 break; 01036 } 01037 if (strchr(canceldtmf, f->subclass.integer)) { 01038 ast_verb(3, "User cancelled message by pressing %c\n", f->subclass.integer); 01039 res = f->subclass.integer; 01040 outmsg = 0; 01041 break; 01042 } 01043 } 01044 if (maxtime) { 01045 end = time(NULL); 01046 if (maxtime < (end - start)) { 01047 ast_verb(3, "Took too long, cutting it short...\n"); 01048 res = 't'; 01049 outmsg = 2; 01050 break; 01051 } 01052 } 01053 ast_frfree(f); 01054 } 01055 if (!f) { 01056 ast_verb(3, "User hung up\n"); 01057 res = -1; 01058 outmsg = 1; 01059 } else { 01060 ast_frfree(f); 01061 } 01062 } else { 01063 ast_log(LOG_WARNING, "Error creating writestream '%s', format '%s'\n", recordfile, sfmt[x]); 01064 } 01065 01066 if (!prepend) { 01067 if (silgen) { 01068 ast_channel_stop_silence_generator(chan, silgen); 01069 } 01070 } 01071 01072 /*!\note 01073 * Instead of asking how much time passed (end - start), calculate the number 01074 * of seconds of audio which actually went into the file. This fixes a 01075 * problem where audio is stopped up on the network and never gets to us. 01076 * 01077 * Note that we still want to use the number of seconds passed for the max 01078 * message, otherwise we could get a situation where this stream is never 01079 * closed (which would create a resource leak). 01080 */ 01081 *duration = others[0] ? ast_tellstream(others[0]) / 8000 : 0; 01082 if (sound_duration) { 01083 *sound_duration = *duration; 01084 } 01085 01086 if (!prepend) { 01087 /* Reduce duration by a total silence amount */ 01088 if (olddspsilence <= dspsilence) { 01089 totalsilence += dspsilence; 01090 } 01091 01092 if (sound_duration) { 01093 if (totalsilence > 0) { 01094 *sound_duration -= (totalsilence - 200) / 1000; 01095 } 01096 if (*sound_duration < 0) { 01097 *sound_duration = 0; 01098 } 01099 } 01100 01101 if (dspsilence > 0) { 01102 *duration -= (dspsilence - 200) / 1000; 01103 } 01104 if (*duration < 0) { 01105 *duration = 0; 01106 } 01107 01108 for (x = 0; x < fmtcnt; x++) { 01109 if (!others[x]) { 01110 break; 01111 } 01112 /*!\note 01113 * If we ended with silence, trim all but the first 200ms of silence 01114 * off the recording. However, if we ended with '#', we don't want 01115 * to trim ANY part of the recording. 01116 */ 01117 if (res > 0 && dspsilence) { 01118 /* rewind only the trailing silence */ 01119 ast_stream_rewind(others[x], dspsilence - 200); 01120 } 01121 ast_truncstream(others[x]); 01122 ast_closestream(others[x]); 01123 } 01124 } 01125 01126 if (prepend && outmsg) { 01127 struct ast_filestream *realfiles[AST_MAX_FORMATS]; 01128 struct ast_frame *fr; 01129 01130 for (x = 0; x < fmtcnt; x++) { 01131 snprintf(comment, sizeof(comment), "Opening the real file %s.%s\n", recordfile, sfmt[x]); 01132 realfiles[x] = ast_readfile(recordfile, sfmt[x], comment, O_RDONLY, 0, 0); 01133 if (!others[x] || !realfiles[x]) { 01134 break; 01135 } 01136 /*!\note Same logic as above. */ 01137 if (dspsilence) { 01138 ast_stream_rewind(others[x], dspsilence - 200); 01139 } 01140 ast_truncstream(others[x]); 01141 /* add the original file too */ 01142 while ((fr = ast_readframe(realfiles[x]))) { 01143 ast_writestream(others[x], fr); 01144 ast_frfree(fr); 01145 } 01146 ast_closestream(others[x]); 01147 ast_closestream(realfiles[x]); 01148 ast_filerename(prependfile, recordfile, sfmt[x]); 01149 ast_verb(4, "Recording Format: sfmts=%s, prependfile %s, recordfile %s\n", sfmt[x], prependfile, recordfile); 01150 ast_filedelete(prependfile, sfmt[x]); 01151 } 01152 } 01153 if (rfmt && ast_set_read_format(chan, rfmt)) { 01154 ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_getformatname(rfmt), chan->name); 01155 } 01156 if ((outmsg == 2) && (!skip_confirmation_sound)) { 01157 ast_stream_and_wait(chan, "auth-thankyou", ""); 01158 } 01159 if (sildet) { 01160 ast_dsp_free(sildet); 01161 } 01162 return res; 01163 }
| 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 120 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().
00121 { 00122 struct ast_tone_zone_sound *ts; 00123 int res = 0, x = 0; 00124 00125 if (maxlen > size) { 00126 maxlen = size; 00127 } 00128 00129 if (!timeout) { 00130 if (chan->pbx && chan->pbx->dtimeoutms) { 00131 timeout = chan->pbx->dtimeoutms; 00132 } else { 00133 timeout = 5000; 00134 } 00135 } 00136 00137 if ((ts = ast_get_indication_tone(chan->zone, "dial"))) { 00138 res = ast_playtones_start(chan, 0, ts->data, 0); 00139 ts = ast_tone_zone_sound_unref(ts); 00140 } else { 00141 ast_log(LOG_NOTICE, "Huh....? no dial for indications?\n"); 00142 } 00143 00144 for (x = strlen(collect); x < maxlen; ) { 00145 res = ast_waitfordigit(chan, timeout); 00146 if (!ast_ignore_pattern(context, collect)) { 00147 ast_playtones_stop(chan); 00148 } 00149 if (res < 1) { 00150 break; 00151 } 00152 if (res == '#') { 00153 break; 00154 } 00155 collect[x++] = res; 00156 if (!ast_matchmore_extension(chan, context, collect, 1, 00157 S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) { 00158 break; 00159 } 00160 } 00161 00162 if (res >= 0) { 00163 res = ast_exists_extension(chan, context, collect, 1, 00164 S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL)) ? 1 : 0; 00165 } 00166 00167 return res; 00168 }
| int ast_app_exec_macro | ( | struct ast_channel * | autoservice_chan, | |
| struct ast_channel * | macro_chan, | |||
| const char * | macro_args | |||
| ) |
Run a macro on a channel, placing an optional second channel into autoservice.
This is a shorthand method that makes it very easy to run a macro on any given channel. It is perfectly reasonable to supply a NULL autoservice_chan here in case there is no channel to place into autoservice.
| autoservice_chan | A channel to place into autoservice while the macro is run | |
| macro_chan | Channel to execute macro on. | |
| macro_args | Macro application argument string. |
| 0 | success | |
| -1 | on error |
Definition at line 254 of file app.c.
References ast_autoservice_start(), ast_autoservice_stop(), ast_debug, ast_log(), ast_channel::context, ast_channel::exten, LOG_WARNING, pbx_exec(), pbx_findapp(), and ast_channel::priority.
Referenced by ast_app_run_macro(), and feature_exec_app().
00255 { 00256 struct ast_app *macro_app; 00257 int res; 00258 00259 macro_app = pbx_findapp("Macro"); 00260 if (!macro_app) { 00261 ast_log(LOG_WARNING, 00262 "Cannot run 'Macro(%s)'. The application is not available.\n", macro_args); 00263 return -1; 00264 } 00265 if (autoservice_chan) { 00266 ast_autoservice_start(autoservice_chan); 00267 } 00268 00269 ast_debug(4, "%s Original location: %s,%s,%d\n", macro_chan->name, 00270 macro_chan->context, macro_chan->exten, macro_chan->priority); 00271 00272 res = pbx_exec(macro_chan, macro_app, macro_args); 00273 ast_debug(4, "Macro exited with status %d\n", res); 00274 00275 /* 00276 * Assume anything negative from Macro is an error. 00277 * Anything else is success. 00278 */ 00279 if (res < 0) { 00280 res = -1; 00281 } else { 00282 res = 0; 00283 } 00284 00285 ast_debug(4, "%s Ending location: %s,%s,%d\n", macro_chan->name, 00286 macro_chan->context, macro_chan->exten, macro_chan->priority); 00287 00288 if (autoservice_chan) { 00289 ast_autoservice_stop(autoservice_chan); 00290 } 00291 return res; 00292 }
| int ast_app_exec_sub | ( | struct ast_channel * | autoservice_chan, | |
| struct ast_channel * | sub_chan, | |||
| const char * | sub_args, | |||
| int | ignore_hangup | |||
| ) |
Run a subroutine on a channel, placing an optional second channel into autoservice.
This is a shorthand method that makes it very easy to run a subroutine on any given channel. It is perfectly reasonable to supply a NULL autoservice_chan here in case there is no channel to place into autoservice.
| autoservice_chan | A channel to place into autoservice while the subroutine is run | |
| sub_chan | Channel to execute subroutine on. | |
| sub_args | Gosub application argument string. | |
| ignore_hangup | TRUE if a hangup does not stop execution of the routine. |
| 0 | success | |
| -1 | on error |
Definition at line 343 of file app.c.
References app_stack_callbacks, ast_autoservice_start(), ast_autoservice_stop(), ast_log(), ast_module_ref(), ast_module_unref(), LOG_WARNING, ast_app_stack_funcs::module, and ast_app_stack_funcs::run_sub.
Referenced by ast_app_run_sub(), and feature_exec_app().
00344 { 00345 const struct ast_app_stack_funcs *funcs; 00346 int res; 00347 00348 funcs = app_stack_callbacks; 00349 if (!funcs || !funcs->run_sub) { 00350 ast_log(LOG_WARNING, 00351 "Cannot run 'Gosub(%s)'. The app_stack module is not available.\n", 00352 sub_args); 00353 return -1; 00354 } 00355 ast_module_ref(funcs->module); 00356 00357 if (autoservice_chan) { 00358 ast_autoservice_start(autoservice_chan); 00359 } 00360 00361 res = funcs->run_sub(sub_chan, sub_args, ignore_hangup); 00362 ast_module_unref(funcs->module); 00363 00364 if (autoservice_chan) { 00365 ast_autoservice_stop(autoservice_chan); 00366 } 00367 return res; 00368 }
| const char* ast_app_expand_sub_args | ( | struct ast_channel * | chan, | |
| const char * | args | |||
| ) |
Add missing context/exten to subroutine argument string.
| chan | Channel to obtain context/exten. | |
| args | Gosub application argument string. |
Fills in the optional context and exten from the given channel.
| New-args | Gosub argument string on success. Must be freed. | |
| NULL | on error. |
Definition at line 324 of file app.c.
References app_stack_callbacks, ast_log(), ast_module_ref(), ast_module_unref(), ast_app_stack_funcs::expand_sub_args, LOG_WARNING, and ast_app_stack_funcs::module.
00325 { 00326 const struct ast_app_stack_funcs *funcs; 00327 const char *new_args; 00328 00329 funcs = app_stack_callbacks; 00330 if (!funcs || !funcs->expand_sub_args) { 00331 ast_log(LOG_WARNING, 00332 "Cannot expand 'Gosub(%s)' arguments. The app_stack module is not available.\n", 00333 args); 00334 return NULL; 00335 } 00336 ast_module_ref(funcs->module); 00337 00338 new_args = funcs->expand_sub_args(chan, args); 00339 ast_module_unref(funcs->module); 00340 return new_args; 00341 }
| 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 178 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().
00179 { 00180 int res = 0, to, fto; 00181 char *front, *filename; 00182 00183 /* XXX Merge with full version? XXX */ 00184 00185 if (maxlen) 00186 s[0] = '\0'; 00187 00188 if (!prompt) 00189 prompt = ""; 00190 00191 filename = ast_strdupa(prompt); 00192 while ((front = strsep(&filename, "&"))) { 00193 if (!ast_strlen_zero(front)) { 00194 res = ast_streamfile(c, front, c->language); 00195 if (res) 00196 continue; 00197 } 00198 if (ast_strlen_zero(filename)) { 00199 /* set timeouts for the last prompt */ 00200 fto = c->pbx ? c->pbx->rtimeoutms : 6000; 00201 to = c->pbx ? c->pbx->dtimeoutms : 2000; 00202 00203 if (timeout > 0) { 00204 fto = to = timeout; 00205 } 00206 if (timeout < 0) { 00207 fto = to = 1000000000; 00208 } 00209 } else { 00210 /* there is more than one prompt, so 00211 * get rid of the long timeout between 00212 * prompts, and make it 50ms */ 00213 fto = 50; 00214 to = c->pbx ? c->pbx->dtimeoutms : 2000; 00215 } 00216 res = ast_readstring(c, s, maxlen, to, fto, "#"); 00217 if (res == AST_GETDATA_EMPTY_END_TERMINATED) { 00218 return res; 00219 } 00220 if (!ast_strlen_zero(s)) { 00221 return res; 00222 } 00223 } 00224 00225 return res; 00226 }
| 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 231 of file app.c.
References ast_readstring_full(), ast_streamfile(), and ast_strlen_zero().
Referenced by handle_getdata().
00232 { 00233 int res, to = 2000, fto = 6000; 00234 00235 if (!ast_strlen_zero(prompt)) { 00236 res = ast_streamfile(c, prompt, c->language); 00237 if (res < 0) { 00238 return res; 00239 } 00240 } 00241 00242 if (timeout > 0) { 00243 fto = to = timeout; 00244 } 00245 if (timeout < 0) { 00246 fto = to = 1000000000; 00247 } 00248 00249 res = ast_readstring_full(c, s, maxlen, to, fto, "#", audiofd, ctrlfd); 00250 00251 return res; 00252 }
| int ast_app_group_discard | ( | struct ast_channel * | chan | ) |
Discard all group counting for a channel.
Definition at line 1338 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().
01339 { 01340 struct ast_group_info *gi = NULL; 01341 01342 AST_RWLIST_WRLOCK(&groups); 01343 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, group_list) { 01344 if (gi->chan == chan) { 01345 AST_RWLIST_REMOVE_CURRENT(group_list); 01346 ast_free(gi); 01347 } 01348 } 01349 AST_RWLIST_TRAVERSE_SAFE_END; 01350 AST_RWLIST_UNLOCK(&groups); 01351 01352 return 0; 01353 }
| 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 1259 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().
01260 { 01261 struct ast_group_info *gi = NULL; 01262 int count = 0; 01263 01264 if (ast_strlen_zero(group)) { 01265 return 0; 01266 } 01267 01268 AST_RWLIST_RDLOCK(&groups); 01269 AST_RWLIST_TRAVERSE(&groups, gi, group_list) { 01270 if (!strcasecmp(gi->group, group) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) { 01271 count++; 01272 } 01273 } 01274 AST_RWLIST_UNLOCK(&groups); 01275 01276 return count; 01277 }
| struct ast_group_info* ast_app_group_list_head | ( | void | ) | [read] |
Get the head of the group count list.
Definition at line 1365 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().
01366 { 01367 return AST_RWLIST_FIRST(&groups); 01368 }
| int ast_app_group_list_rdlock | ( | void | ) |
Read Lock the group count list.
Definition at line 1360 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().
01361 { 01362 return AST_RWLIST_RDLOCK(&groups); 01363 }
| int ast_app_group_list_unlock | ( | void | ) |
Unlock the group count list.
Definition at line 1370 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().
01371 { 01372 return AST_RWLIST_UNLOCK(&groups); 01373 }
| int ast_app_group_list_wrlock | ( | void | ) |
Write Lock the group count list.
Definition at line 1355 of file app.c.
References AST_RWLIST_WRLOCK.
01356 { 01357 return AST_RWLIST_WRLOCK(&groups); 01358 }
| 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 1279 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().
01280 { 01281 struct ast_group_info *gi = NULL; 01282 regex_t regexbuf_group; 01283 regex_t regexbuf_category; 01284 int count = 0; 01285 01286 if (ast_strlen_zero(groupmatch)) { 01287 ast_log(LOG_NOTICE, "groupmatch empty\n"); 01288 return 0; 01289 } 01290 01291 /* if regex compilation fails, return zero matches */ 01292 if (regcomp(®exbuf_group, groupmatch, REG_EXTENDED | REG_NOSUB)) { 01293 ast_log(LOG_ERROR, "Regex compile failed on: %s\n", groupmatch); 01294 return 0; 01295 } 01296 01297 if (!ast_strlen_zero(category) && regcomp(®exbuf_category, category, REG_EXTENDED | REG_NOSUB)) { 01298 ast_log(LOG_ERROR, "Regex compile failed on: %s\n", category); 01299 regfree(®exbuf_group); 01300 return 0; 01301 } 01302 01303 AST_RWLIST_RDLOCK(&groups); 01304 AST_RWLIST_TRAVERSE(&groups, gi, group_list) { 01305 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)))) { 01306 count++; 01307 } 01308 } 01309 AST_RWLIST_UNLOCK(&groups); 01310 01311 regfree(®exbuf_group); 01312 if (!ast_strlen_zero(category)) { 01313 regfree(®exbuf_category); 01314 } 01315 01316 return count; 01317 }
| 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 1212 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().
01213 { 01214 int res = 0; 01215 char group[80] = "", category[80] = ""; 01216 struct ast_group_info *gi = NULL; 01217 size_t len = 0; 01218 01219 if (ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category))) { 01220 return -1; 01221 } 01222 01223 /* Calculate memory we will need if this is new */ 01224 len = sizeof(*gi) + strlen(group) + 1; 01225 if (!ast_strlen_zero(category)) { 01226 len += strlen(category) + 1; 01227 } 01228 01229 AST_RWLIST_WRLOCK(&groups); 01230 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, group_list) { 01231 if ((gi->chan == chan) && ((ast_strlen_zero(category) && ast_strlen_zero(gi->category)) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) { 01232 AST_RWLIST_REMOVE_CURRENT(group_list); 01233 free(gi); 01234 break; 01235 } 01236 } 01237 AST_RWLIST_TRAVERSE_SAFE_END; 01238 01239 if (ast_strlen_zero(group)) { 01240 /* Enable unsetting the group */ 01241 } else if ((gi = calloc(1, len))) { 01242 gi->chan = chan; 01243 gi->group = (char *) gi + sizeof(*gi); 01244 strcpy(gi->group, group); 01245 if (!ast_strlen_zero(category)) { 01246 gi->category = (char *) gi + sizeof(*gi) + strlen(group) + 1; 01247 strcpy(gi->category, category); 01248 } 01249 AST_RWLIST_INSERT_TAIL(&groups, gi, group_list); 01250 } else { 01251 res = -1; 01252 } 01253 01254 AST_RWLIST_UNLOCK(&groups); 01255 01256 return res; 01257 }
| 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 1185 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().
01186 { 01187 int res = 0; 01188 char tmp[256]; 01189 char *grp = NULL, *cat = NULL; 01190 01191 if (!ast_strlen_zero(data)) { 01192 ast_copy_string(tmp, data, sizeof(tmp)); 01193 grp = tmp; 01194 if ((cat = strchr(tmp, '@'))) { 01195 *cat++ = '\0'; 01196 } 01197 } 01198 01199 if (!ast_strlen_zero(grp)) { 01200 ast_copy_string(group, grp, group_max); 01201 } else { 01202 *group = '\0'; 01203 } 01204 01205 if (!ast_strlen_zero(cat)) { 01206 ast_copy_string(category, cat, category_max); 01207 } 01208 01209 return res; 01210 }
| 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 1319 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().
01320 { 01321 struct ast_group_info *gi = NULL; 01322 01323 AST_RWLIST_WRLOCK(&groups); 01324 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, group_list) { 01325 if (gi->chan == old) { 01326 gi->chan = new; 01327 } else if (gi->chan == new) { 01328 AST_RWLIST_REMOVE_CURRENT(group_list); 01329 ast_free(gi); 01330 } 01331 } 01332 AST_RWLIST_TRAVERSE_SAFE_END; 01333 AST_RWLIST_UNLOCK(&groups); 01334 01335 return 0; 01336 }
| 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 421 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().
00422 { 00423 static int warned = 0; 00424 if (ast_has_voicemail_func) { 00425 return ast_has_voicemail_func(mailbox, folder); 00426 } 00427 00428 if (warned++ % 10 == 0) { 00429 ast_verb(3, "Message check requested for mailbox %s/folder %s but voicemail not loaded.\n", mailbox, folder ? folder : "INBOX"); 00430 } 00431 return 0; 00432 }
| 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 435 of file app.c.
References ast_inboxcount_func, and ast_verb.
Referenced by sip_send_mwi_to_peer(), and update_registry().
00436 { 00437 static int warned = 0; 00438 if (newmsgs) { 00439 *newmsgs = 0; 00440 } 00441 if (oldmsgs) { 00442 *oldmsgs = 0; 00443 } 00444 if (ast_inboxcount_func) { 00445 return ast_inboxcount_func(mailbox, newmsgs, oldmsgs); 00446 } 00447 00448 if (warned++ % 10 == 0) { 00449 ast_verb(3, "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox); 00450 } 00451 00452 return 0; 00453 }
| 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 455 of file app.c.
References ast_inboxcount2_func, and ast_verb.
Referenced by action_mailboxcount(), notify_new_message(), and vm_execmain().
00456 { 00457 static int warned = 0; 00458 if (newmsgs) { 00459 *newmsgs = 0; 00460 } 00461 if (oldmsgs) { 00462 *oldmsgs = 0; 00463 } 00464 if (urgentmsgs) { 00465 *urgentmsgs = 0; 00466 } 00467 if (ast_inboxcount2_func) { 00468 return ast_inboxcount2_func(mailbox, urgentmsgs, newmsgs, oldmsgs); 00469 } 00470 00471 if (warned++ % 10 == 0) { 00472 ast_verb(3, "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox); 00473 } 00474 00475 return 0; 00476 }
| 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 486 of file app.c.
References ast_messagecount_func, and ast_verb.
Referenced by acf_vmcount_exec().
00487 { 00488 static int warned = 0; 00489 if (ast_messagecount_func) { 00490 return ast_messagecount_func(context, mailbox, folder); 00491 } 00492 00493 if (!warned) { 00494 warned++; 00495 ast_verb(3, "Message count requested for mailbox %s@%s/%s but voicemail not loaded.\n", mailbox, context, folder); 00496 } 00497 00498 return 0; 00499 }
| 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 2101 of file app.c.
References ast_test_flag64.
02102 { 02103 unsigned int i, found = 0; 02104 for (i = 32; i < 128 && found < len; i++) { 02105 if (ast_test_flag64(flags, options[i].flag)) { 02106 buf[found++] = i; 02107 } 02108 } 02109 buf[found] = '\0'; 02110 }
| 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 2091 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().
02092 { 02093 return parse_options(options, flags, args, optstr, 32); 02094 }
| 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 2096 of file app.c.
References parse_options().
Referenced by conf_exec(), dial_exec_full(), and find_conf_realtime().
02097 { 02098 return parse_options(options, flags, args, optstr, 64); 02099 }
| 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 2301 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().
02302 { 02303 int res; 02304 char u[10]; 02305 #ifdef HAVE_LONG_DOUBLE_WIDER 02306 long double amount; 02307 #define FMT "%30Lf%9s" 02308 #else 02309 double amount; 02310 #define FMT "%30lf%9s" 02311 #endif 02312 if (!timestr) { 02313 return -1; 02314 } 02315 02316 res = sscanf(timestr, FMT, &amount, u); 02317 02318 if (res == 0 || res == EOF) { 02319 #undef FMT 02320 return -1; 02321 } else if (res == 2) { 02322 switch (u[0]) { 02323 case 'h': 02324 case 'H': 02325 unit = TIMELEN_HOURS; 02326 break; 02327 case 's': 02328 case 'S': 02329 unit = TIMELEN_SECONDS; 02330 break; 02331 case 'm': 02332 case 'M': 02333 if (toupper(u[1]) == 'S') { 02334 unit = TIMELEN_MILLISECONDS; 02335 } else if (u[1] == '\0') { 02336 unit = TIMELEN_MINUTES; 02337 } 02338 break; 02339 } 02340 } 02341 02342 switch (unit) { 02343 case TIMELEN_HOURS: 02344 amount *= 60; 02345 /* fall-through */ 02346 case TIMELEN_MINUTES: 02347 amount *= 60; 02348 /* fall-through */ 02349 case TIMELEN_SECONDS: 02350 amount *= 1000; 02351 /* fall-through */ 02352 case TIMELEN_MILLISECONDS: 02353 ; 02354 } 02355 *result = amount > INT_MAX ? INT_MAX : (int) amount; 02356 return 0; 02357 }
| int ast_app_run_macro | ( | struct ast_channel * | autoservice_chan, | |
| struct ast_channel * | macro_chan, | |||
| const char * | macro_name, | |||
| const char * | macro_args | |||
| ) |
Run a macro on a channel, placing an optional second channel into autoservice.
This is a shorthand method that makes it very easy to run a macro on any given channel. It is perfectly reasonable to supply a NULL autoservice_chan here in case there is no channel to place into autoservice.
| autoservice_chan | A channel to place into autoservice while the macro is run | |
| macro_chan | Channel to execute macro on. | |
| macro_name | The name of the macro to run. | |
| macro_args | The arguments to pass to the macro. |
| 0 | success | |
| -1 | on error |
Definition at line 294 of file app.c.
References ast_app_exec_macro(), ast_free, ast_malloc, and ast_strlen_zero().
Referenced by ast_channel_connected_line_macro(), ast_channel_redirecting_macro(), and generic_recall().
00295 { 00296 int res; 00297 char *args_str; 00298 size_t args_len; 00299 00300 if (ast_strlen_zero(macro_args)) { 00301 return ast_app_exec_macro(autoservice_chan, macro_chan, macro_name); 00302 } 00303 00304 /* Create the Macro application argument string. */ 00305 args_len = strlen(macro_name) + strlen(macro_args) + 2; 00306 args_str = ast_malloc(args_len); 00307 if (!args_str) { 00308 return -1; 00309 } 00310 snprintf(args_str, args_len, "%s,%s", macro_name, macro_args); 00311 00312 res = ast_app_exec_macro(autoservice_chan, macro_chan, args_str); 00313 ast_free(args_str); 00314 return res; 00315 }
| int ast_app_run_sub | ( | struct ast_channel * | autoservice_chan, | |
| struct ast_channel * | sub_chan, | |||
| const char * | sub_location, | |||
| const char * | sub_args, | |||
| int | ignore_hangup | |||
| ) |
Run a subroutine on a channel, placing an optional second channel into autoservice.
This is a shorthand method that makes it very easy to run a subroutine on any given channel. It is perfectly reasonable to supply a NULL autoservice_chan here in case there is no channel to place into autoservice.
| autoservice_chan | A channel to place into autoservice while the subroutine is run | |
| sub_chan | Channel to execute subroutine on. | |
| sub_location | The location of the subroutine to run. | |
| sub_args | The arguments to pass to the subroutine. | |
| ignore_hangup | TRUE if a hangup does not stop execution of the routine. |
| 0 | success | |
| -1 | on error |
Definition at line 370 of file app.c.
References ast_app_exec_sub(), ast_free, ast_malloc, and ast_strlen_zero().
00371 { 00372 int res; 00373 char *args_str; 00374 size_t args_len; 00375 00376 if (ast_strlen_zero(sub_args)) { 00377 return ast_app_exec_sub(autoservice_chan, sub_chan, sub_location, ignore_hangup); 00378 } 00379 00380 /* Create the Gosub application argument string. */ 00381 args_len = strlen(sub_location) + strlen(sub_args) + 3; 00382 args_str = ast_malloc(args_len); 00383 if (!args_str) { 00384 return -1; 00385 } 00386 snprintf(args_str, args_len, "%s(%s)", sub_location, sub_args); 00387 00388 res = ast_app_exec_sub(autoservice_chan, sub_chan, args_str, ignore_hangup); 00389 ast_free(args_str); 00390 return res; 00391 }
| 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 478 of file app.c.
References ast_sayname_func.
Referenced by common_exec(), and play_mailbox_owner().
00479 { 00480 if (ast_sayname_func) { 00481 return ast_sayname_func(chan, mailbox, context); 00482 } 00483 return -1; 00484 }
| unsigned int ast_app_separate_args | ( | char * | buf, | |
| char | delim, | |||
| char ** | array, | |||
| int | arraylen | |||
| ) |
Definition at line 1443 of file app.c.
References __ast_app_separate_args().
01444 { 01445 return __ast_app_separate_args(buf, delim, 1, array, arraylen); 01446 }
| 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 2227 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().
02228 { 02229 closefrom(n + 1); 02230 }
| 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 683 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().
00687 { 00688 char *breaks = NULL; 00689 char *end = NULL; 00690 int blen = 2; 00691 int res; 00692 long pause_restart_point = 0; 00693 long offset = 0; 00694 00695 if (!file) { 00696 return -1; 00697 } 00698 if (offsetms) { 00699 offset = *offsetms * 8; /* XXX Assumes 8kHz */ 00700 } 00701 00702 if (stop) { 00703 blen += strlen(stop); 00704 } 00705 if (suspend) { 00706 blen += strlen(suspend); 00707 } 00708 if (restart) { 00709 blen += strlen(restart); 00710 } 00711 00712 if (blen > 2) { 00713 breaks = ast_alloca(blen + 1); 00714 breaks[0] = '\0'; 00715 if (stop) { 00716 strcat(breaks, stop); 00717 } 00718 if (suspend) { 00719 strcat(breaks, suspend); 00720 } 00721 if (restart) { 00722 strcat(breaks, restart); 00723 } 00724 } 00725 if (chan->_state != AST_STATE_UP) { 00726 res = ast_answer(chan); 00727 } 00728 00729 if ((end = strchr(file, ':'))) { 00730 if (!strcasecmp(end, ":end")) { 00731 *end = '\0'; 00732 end++; 00733 } 00734 } 00735 00736 for (;;) { 00737 ast_stopstream(chan); 00738 res = ast_streamfile(chan, file, chan->language); 00739 if (!res) { 00740 if (pause_restart_point) { 00741 ast_seekstream(chan->stream, pause_restart_point, SEEK_SET); 00742 pause_restart_point = 0; 00743 } 00744 else if (end || offset < 0) { 00745 if (offset == -8) { 00746 offset = 0; 00747 } 00748 ast_verb(3, "ControlPlayback seek to offset %ld from end\n", offset); 00749 00750 ast_seekstream(chan->stream, offset, SEEK_END); 00751 end = NULL; 00752 offset = 0; 00753 } else if (offset) { 00754 ast_verb(3, "ControlPlayback seek to offset %ld\n", offset); 00755 ast_seekstream(chan->stream, offset, SEEK_SET); 00756 offset = 0; 00757 } 00758 res = ast_waitstream_fr(chan, breaks, fwd, rev, skipms); 00759 } 00760 00761 if (res < 1) { 00762 break; 00763 } 00764 00765 /* We go at next loop if we got the restart char */ 00766 if (restart && strchr(restart, res)) { 00767 ast_debug(1, "we'll restart the stream here at next loop\n"); 00768 pause_restart_point = 0; 00769 continue; 00770 } 00771 00772 if (suspend && strchr(suspend, res)) { 00773 pause_restart_point = ast_tellstream(chan->stream); 00774 for (;;) { 00775 ast_stopstream(chan); 00776 if (!(res = ast_waitfordigit(chan, 1000))) { 00777 continue; 00778 } else if (res == -1 || strchr(suspend, res) || (stop && strchr(stop, res))) { 00779 break; 00780 } 00781 } 00782 if (res == *suspend) { 00783 res = 0; 00784 continue; 00785 } 00786 } 00787 00788 if (res == -1) { 00789 break; 00790 } 00791 00792 /* if we get one of our stop chars, return it to the calling function */ 00793 if (stop && strchr(stop, res)) { 00794 break; 00795 } 00796 } 00797 00798 if (pause_restart_point) { 00799 offset = pause_restart_point; 00800 } else { 00801 if (chan->stream) { 00802 offset = ast_tellstream(chan->stream); 00803 } else { 00804 offset = -8; /* indicate end of file */ 00805 } 00806 } 00807 00808 if (offsetms) { 00809 *offsetms = offset / 8; /* samples --> ms ... XXX Assumes 8 kHz */ 00810 } 00811 00812 /* If we are returning a digit cast it as char */ 00813 if (res > 0 || chan->stream) { 00814 res = (char)res; 00815 } 00816 00817 ast_stopstream(chan); 00818 00819 return res; 00820 }
| 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 501 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().
00502 { 00503 const char *ptr; 00504 int res = 0; 00505 struct ast_silence_generator *silgen = NULL; 00506 00507 if (!between) { 00508 between = 100; 00509 } 00510 00511 if (peer) { 00512 res = ast_autoservice_start(peer); 00513 } 00514 00515 if (!res) { 00516 res = ast_waitfor(chan, 100); 00517 } 00518 00519 /* ast_waitfor will return the number of remaining ms on success */ 00520 if (res < 0) { 00521 if (peer) { 00522 ast_autoservice_stop(peer); 00523 } 00524 return res; 00525 } 00526 00527 if (ast_opt_transmit_silence) { 00528 silgen = ast_channel_start_silence_generator(chan); 00529 } 00530 00531 for (ptr = digits; *ptr; ptr++) { 00532 if (*ptr == 'w') { 00533 /* 'w' -- wait half a second */ 00534 if ((res = ast_safe_sleep(chan, 500))) { 00535 break; 00536 } 00537 } else if (strchr("0123456789*#abcdfABCDF", *ptr)) { 00538 /* Character represents valid DTMF */ 00539 if (*ptr == 'f' || *ptr == 'F') { 00540 /* ignore return values if not supported by channel */ 00541 ast_indicate(chan, AST_CONTROL_FLASH); 00542 } else { 00543 ast_senddigit(chan, *ptr, duration); 00544 } 00545 /* pause between digits */ 00546 if ((res = ast_safe_sleep(chan, between))) { 00547 break; 00548 } 00549 } else { 00550 ast_log(LOG_WARNING, "Illegal DTMF character '%c' in string. (0-9*#aAbBcCdD allowed)\n", *ptr); 00551 } 00552 } 00553 00554 if (peer) { 00555 /* Stop autoservice on the peer channel, but don't overwrite any error condition 00556 that has occurred previously while acting on the primary channel */ 00557 if (ast_autoservice_stop(peer) && !res) { 00558 res = -1; 00559 } 00560 } 00561 00562 if (silgen) { 00563 ast_channel_stop_silence_generator(chan, silgen); 00564 } 00565 00566 return res; 00567 }
| 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 2112 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().
02113 { 02114 int i; 02115 *consumed = 1; 02116 *result = 0; 02117 if (ast_strlen_zero(stream)) { 02118 *consumed = 0; 02119 return -1; 02120 } 02121 02122 if (*stream == '\\') { 02123 *consumed = 2; 02124 switch (*(stream + 1)) { 02125 case 'n': 02126 *result = '\n'; 02127 break; 02128 case 'r': 02129 *result = '\r'; 02130 break; 02131 case 't': 02132 *result = '\t'; 02133 break; 02134 case 'x': 02135 /* Hexadecimal */ 02136 if (strchr("0123456789ABCDEFabcdef", *(stream + 2)) && *(stream + 2) != '\0') { 02137 *consumed = 3; 02138 if (*(stream + 2) <= '9') { 02139 *result = *(stream + 2) - '0'; 02140 } else if (*(stream + 2) <= 'F') { 02141 *result = *(stream + 2) - 'A' + 10; 02142 } else { 02143 *result = *(stream + 2) - 'a' + 10; 02144 } 02145 } else { 02146 ast_log(LOG_ERROR, "Illegal character '%c' in hexadecimal string\n", *(stream + 2)); 02147 return -1; 02148 } 02149 02150 if (strchr("0123456789ABCDEFabcdef", *(stream + 3)) && *(stream + 3) != '\0') { 02151 *consumed = 4; 02152 *result <<= 4; 02153 if (*(stream + 3) <= '9') { 02154 *result += *(stream + 3) - '0'; 02155 } else if (*(stream + 3) <= 'F') { 02156 *result += *(stream + 3) - 'A' + 10; 02157 } else { 02158 *result += *(stream + 3) - 'a' + 10; 02159 } 02160 } 02161 break; 02162 case '0': 02163 /* Octal */ 02164 *consumed = 2; 02165 for (i = 2; ; i++) { 02166 if (strchr("01234567", *(stream + i)) && *(stream + i) != '\0') { 02167 (*consumed)++; 02168 ast_debug(5, "result was %d, ", *result); 02169 *result <<= 3; 02170 *result += *(stream + i) - '0'; 02171 ast_debug(5, "is now %d\n", *result); 02172 } else { 02173 break; 02174 } 02175 } 02176 break; 02177 default: 02178 *result = *(stream + 1); 02179 } 02180 } else { 02181 *result = *stream; 02182 *consumed = 1; 02183 } 02184 return 0; 02185 }
| 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 2187 of file app.c.
References ast_get_encoded_char().
Referenced by listfilter(), mgcp_new(), replace(), sip_addheader(), and sip_new().
02188 { 02189 char *cur = result; 02190 size_t consumed; 02191 02192 while (cur < result + result_size - 1 && !ast_get_encoded_char(stream, cur, &consumed)) { 02193 cur++; 02194 stream += consumed; 02195 } 02196 *cur = '\0'; 02197 return result; 02198 }
| void ast_install_stack_functions | ( | const struct ast_app_stack_funcs * | funcs | ) |
Set stack application function callbacks.
| funcs | Stack applications callback functions. |
Definition at line 319 of file app.c.
References app_stack_callbacks.
Referenced by load_module(), and unload_module().
00320 { 00321 app_stack_callbacks = funcs; 00322 }
| 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 399 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().
00404 { 00405 ast_has_voicemail_func = has_voicemail_func; 00406 ast_inboxcount_func = inboxcount_func; 00407 ast_inboxcount2_func = inboxcount2_func; 00408 ast_messagecount_func = messagecount_func; 00409 ast_sayname_func = sayname_func; 00410 }
| int ast_ivr_menu_run | ( | struct ast_channel * | c, | |
| struct ast_ivr_menu * | menu, | |||
| void * | cbdata | |||
| ) |
Runs an IVR menu.
Definition at line 1970 of file app.c.
References ast_ivr_menu_run_internal().
Referenced by skel_exec().
01971 { 01972 int res = ast_ivr_menu_run_internal(chan, menu, cbdata); 01973 /* Hide internal coding */ 01974 return res > 0 ? 0 : res; 01975 }
| static int ast_ivr_menu_run_internal | ( | struct ast_channel * | chan, | |
| struct ast_ivr_menu * | menu, | |||
| void * | cbdata | |||
| ) | [static] |
Definition at line 1885 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().
01886 { 01887 /* Execute an IVR menu structure */ 01888 int res = 0; 01889 int pos = 0; 01890 int retries = 0; 01891 char exten[AST_MAX_EXTENSION] = "s"; 01892 if (option_exists(menu, "s") < 0) { 01893 strcpy(exten, "g"); 01894 if (option_exists(menu, "g") < 0) { 01895 ast_log(LOG_WARNING, "No 's' nor 'g' extension in menu '%s'!\n", menu->title); 01896 return -1; 01897 } 01898 } 01899 while (!res) { 01900 while (menu->options[pos].option) { 01901 if (!strcasecmp(menu->options[pos].option, exten)) { 01902 res = ivr_dispatch(chan, menu->options + pos, exten, cbdata); 01903 ast_debug(1, "IVR Dispatch of '%s' (pos %d) yields %d\n", exten, pos, res); 01904 if (res < 0) { 01905 break; 01906 } else if (res & RES_UPONE) { 01907 return 0; 01908 } else if (res & RES_EXIT) { 01909 return res; 01910 } else if (res & RES_REPEAT) { 01911 int maxretries = res & 0xffff; 01912 if ((res & RES_RESTART) == RES_RESTART) { 01913 retries = 0; 01914 } else { 01915 retries++; 01916 } 01917 if (!maxretries) { 01918 maxretries = 3; 01919 } 01920 if ((maxretries > 0) && (retries >= maxretries)) { 01921 ast_debug(1, "Max retries %d exceeded\n", maxretries); 01922 return -2; 01923 } else { 01924 if (option_exists(menu, "g") > -1) { 01925 strcpy(exten, "g"); 01926 } else if (option_exists(menu, "s") > -1) { 01927 strcpy(exten, "s"); 01928 } 01929 } 01930 pos = 0; 01931 continue; 01932 } else if (res && strchr(AST_DIGIT_ANY, res)) { 01933 ast_debug(1, "Got start of extension, %c\n", res); 01934 exten[1] = '\0'; 01935 exten[0] = res; 01936 if ((res = read_newoption(chan, menu, exten, sizeof(exten)))) { 01937 break; 01938 } 01939 if (option_exists(menu, exten) < 0) { 01940 if (option_exists(menu, "i")) { 01941 ast_debug(1, "Invalid extension entered, going to 'i'!\n"); 01942 strcpy(exten, "i"); 01943 pos = 0; 01944 continue; 01945 } else { 01946 ast_debug(1, "Aborting on invalid entry, with no 'i' option!\n"); 01947 res = -2; 01948 break; 01949 } 01950 } else { 01951 ast_debug(1, "New existing extension: %s\n", exten); 01952 pos = 0; 01953 continue; 01954 } 01955 } 01956 } 01957 pos++; 01958 } 01959 ast_debug(1, "Stopping option '%s', res is %d\n", exten, res); 01960 pos = 0; 01961 if (!strcasecmp(exten, "s")) { 01962 strcpy(exten, "g"); 01963 } else { 01964 break; 01965 } 01966 } 01967 return res; 01968 }
| 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 653 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.
00654 { 00655 struct linear_state *lin; 00656 char tmpf[256]; 00657 int res = -1; 00658 int autoclose = 0; 00659 if (fd < 0) { 00660 if (ast_strlen_zero(filename)) { 00661 return -1; 00662 } 00663 autoclose = 1; 00664 if (filename[0] == '/') { 00665 ast_copy_string(tmpf, filename, sizeof(tmpf)); 00666 } else { 00667 snprintf(tmpf, sizeof(tmpf), "%s/%s/%s", ast_config_AST_DATA_DIR, "sounds", filename); 00668 } 00669 if ((fd = open(tmpf, O_RDONLY)) < 0) { 00670 ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", tmpf, strerror(errno)); 00671 return -1; 00672 } 00673 } 00674 if ((lin = ast_calloc(1, sizeof(*lin)))) { 00675 lin->fd = fd; 00676 lin->allowoverride = allowoverride; 00677 lin->autoclose = autoclose; 00678 res = ast_activate_generator(chan, &linearstream, lin); 00679 } 00680 return res; 00681 }
| enum AST_LOCK_RESULT ast_lock_path | ( | const char * | path | ) |
Lock a filesystem path.
| path | the path to be locked |
Definition at line 1642 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().
01643 { 01644 enum AST_LOCK_RESULT r = AST_LOCK_FAILURE; 01645 01646 switch (ast_lock_type) { 01647 case AST_LOCK_TYPE_LOCKFILE: 01648 r = ast_lock_path_lockfile(path); 01649 break; 01650 case AST_LOCK_TYPE_FLOCK: 01651 r = ast_lock_path_flock(path); 01652 break; 01653 } 01654 01655 return r; 01656 }
| static enum AST_LOCK_RESULT ast_lock_path_flock | ( | const char * | path | ) | [static] |
Definition at line 1522 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().
01523 { 01524 char *fs; 01525 int res; 01526 int fd; 01527 time_t start; 01528 struct path_lock *pl; 01529 struct stat st, ost; 01530 01531 fs = ast_alloca(strlen(path) + 20); 01532 01533 snprintf(fs, strlen(path) + 19, "%s/lock", path); 01534 if (lstat(fs, &st) == 0) { 01535 if ((st.st_mode & S_IFMT) == S_IFLNK) { 01536 ast_log(LOG_WARNING, "Unable to create lock file " 01537 "'%s': it's already a symbolic link\n", 01538 fs); 01539 return AST_LOCK_FAILURE; 01540 } 01541 if (st.st_nlink > 1) { 01542 ast_log(LOG_WARNING, "Unable to create lock file " 01543 "'%s': %u hard links exist\n", 01544 fs, (unsigned int) st.st_nlink); 01545 return AST_LOCK_FAILURE; 01546 } 01547 } 01548 if ((fd = open(fs, O_WRONLY | O_CREAT, 0600)) < 0) { 01549 ast_log(LOG_WARNING, "Unable to create lock file '%s': %s\n", 01550 fs, strerror(errno)); 01551 return AST_LOCK_PATH_NOT_FOUND; 01552 } 01553 if (!(pl = ast_calloc(1, sizeof(*pl)))) { 01554 /* We don't unlink the lock file here, on the possibility that 01555 * someone else created it - better to leave a little mess 01556 * than create a big one by destroying someone else's lock 01557 * and causing something to be corrupted. 01558 */ 01559 close(fd); 01560 return AST_LOCK_FAILURE; 01561 } 01562 pl->fd = fd; 01563 pl->path = strdup(path); 01564 01565 time(&start); 01566 while ( 01567 #ifdef SOLARIS 01568 ((res = fcntl(pl->fd, F_SETLK, fcntl(pl->fd, F_GETFL) | O_NONBLOCK)) < 0) && 01569 #else 01570 ((res = flock(pl->fd, LOCK_EX | LOCK_NB)) < 0) && 01571 #endif 01572 (errno == EWOULDBLOCK) && 01573 (time(NULL) - start < 5)) 01574 usleep(1000); 01575 if (res) { 01576 ast_log(LOG_WARNING, "Failed to lock path '%s': %s\n", 01577 path, strerror(errno)); 01578 /* No unlinking of lock done, since we tried and failed to 01579 * flock() it. 01580 */ 01581 path_lock_destroy(pl); 01582 return AST_LOCK_TIMEOUT; 01583 } 01584 01585 /* Check for the race where the file is recreated or deleted out from 01586 * underneath us. 01587 */ 01588 if (lstat(fs, &st) != 0 && fstat(pl->fd, &ost) != 0 && 01589 st.st_dev != ost.st_dev && 01590 st.st_ino != ost.st_ino) { 01591 ast_log(LOG_WARNING, "Unable to create lock file '%s': " 01592 "file changed underneath us\n", fs); 01593 path_lock_destroy(pl); 01594 return AST_LOCK_FAILURE; 01595 } 01596 01597 /* Success: file created, flocked, and is the one we started with */ 01598 AST_LIST_LOCK(&path_lock_list); 01599 AST_LIST_INSERT_TAIL(&path_lock_list, pl, le); 01600 AST_LIST_UNLOCK(&path_lock_list); 01601 01602 ast_debug(1, "Locked path '%s'\n", path); 01603 01604 return AST_LOCK_SUCCESS; 01605 }
| static enum AST_LOCK_RESULT ast_lock_path_lockfile | ( | const char * | path | ) | [static] |
Definition at line 1448 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().
01449 { 01450 char *s; 01451 char *fs; 01452 int res; 01453 int fd; 01454 int lp = strlen(path); 01455 time_t start; 01456 01457 s = ast_alloca(lp + 10); 01458 fs = ast_alloca(lp + 20); 01459 01460 snprintf(fs, strlen(path) + 19, "%s/.lock-%08lx", path, (unsigned long)ast_random()); 01461 fd = open(fs, O_WRONLY | O_CREAT | O_EXCL, AST_FILE_MODE); 01462 if (fd < 0) { 01463 ast_log(LOG_ERROR, "Unable to create lock file '%s': %s\n", path, strerror(errno)); 01464 return AST_LOCK_PATH_NOT_FOUND; 01465 } 01466 close(fd); 01467 01468 snprintf(s, strlen(path) + 9, "%s/.lock", path); 01469 start = time(NULL); 01470 while (((res = link(fs, s)) < 0) && (errno == EEXIST) && (time(NULL) - start < 5)) { 01471 sched_yield(); 01472 } 01473 01474 unlink(fs); 01475 01476 if (res) { 01477 ast_log(LOG_WARNING, "Failed to lock path '%s': %s\n", path, strerror(errno)); 01478 return AST_LOCK_TIMEOUT; 01479 } else { 01480 ast_debug(1, "Locked path '%s'\n", path); 01481 return AST_LOCK_SUCCESS; 01482 } 01483 }
| 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 1178 of file app.c.
References __ast_play_and_record(), default_acceptdtmf, and default_canceldtmf.
Referenced by vm_forwardoptions().
01179 { 01180 return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, sound_duration, beep, silencethreshold, maxsilence, NULL, 1, default_acceptdtmf, default_canceldtmf, 1); 01181 }
| 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 1173 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().
01174 { 01175 return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, sound_duration, 0, silencethreshold, maxsilence, path, 0, default_acceptdtmf, default_canceldtmf, 0); 01176 }
| 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 1168 of file app.c.
References __ast_play_and_record(), default_acceptdtmf, default_canceldtmf, and S_OR.
Referenced by play_record_review().
01169 { 01170 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); 01171 }
| 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 822 of file app.c.
References AST_DIGIT_ANY, ast_stopstream(), ast_streamfile(), 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().
00823 { 00824 int d = 0; 00825 00826 if ((d = ast_streamfile(chan, fn, chan->language))) { 00827 return d; 00828 } 00829 00830 d = ast_waitstream(chan, AST_DIGIT_ANY); 00831 00832 ast_stopstream(chan); 00833 00834 return d; 00835 }
| char* ast_read_textfile | ( | const char * | filename | ) |
Read a file into asterisk.
Definition at line 1977 of file app.c.
References ast_free, ast_log(), ast_malloc, errno, and LOG_WARNING.
Referenced by readfile_exec().
01978 { 01979 int fd, count = 0, res; 01980 char *output = NULL; 01981 struct stat filesize; 01982 01983 if (stat(filename, &filesize) == -1) { 01984 ast_log(LOG_WARNING, "Error can't stat %s\n", filename); 01985 return NULL; 01986 } 01987 01988 count = filesize.st_size + 1; 01989 01990 if ((fd = open(filename, O_RDONLY)) < 0) { 01991 ast_log(LOG_WARNING, "Cannot open file '%s' for reading: %s\n", filename, strerror(errno)); 01992 return NULL; 01993 } 01994 01995 if ((output = ast_malloc(count))) { 01996 res = read(fd, output, count - 1); 01997 if (res == count - 1) { 01998 output[res] = '\0'; 01999 } else { 02000 ast_log(LOG_WARNING, "Short read of %s (%d of %d): %s\n", filename, res, count - 1, strerror(errno)); 02001 ast_free(output); 02002 output = NULL; 02003 } 02004 } 02005 02006 close(fd); 02007 02008 return output; 02009 }
| 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 1674 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().
01675 { 01676 int silencethreshold; 01677 int maxsilence = 0; 01678 int res = 0; 01679 int cmd = 0; 01680 int max_attempts = 3; 01681 int attempts = 0; 01682 int recorded = 0; 01683 int message_exists = 0; 01684 /* Note that urgent and private are for flagging messages as such in the future */ 01685 01686 /* barf if no pointer passed to store duration in */ 01687 if (!duration) { 01688 ast_log(LOG_WARNING, "Error ast_record_review called without duration pointer\n"); 01689 return -1; 01690 } 01691 01692 cmd = '3'; /* Want to start by recording */ 01693 01694 silencethreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE); 01695 01696 while ((cmd >= 0) && (cmd != 't')) { 01697 switch (cmd) { 01698 case '1': 01699 if (!message_exists) { 01700 /* In this case, 1 is to record a message */ 01701 cmd = '3'; 01702 break; 01703 } else { 01704 ast_stream_and_wait(chan, "vm-msgsaved", ""); 01705 cmd = 't'; 01706 return res; 01707 } 01708 case '2': 01709 /* Review */ 01710 ast_verb(3, "Reviewing the recording\n"); 01711 cmd = ast_stream_and_wait(chan, recordfile, AST_DIGIT_ANY); 01712 break; 01713 case '3': 01714 message_exists = 0; 01715 /* Record */ 01716 ast_verb(3, "R%secording\n", recorded == 1 ? "e-r" : ""); 01717 recorded = 1; 01718 if ((cmd = ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, NULL, silencethreshold, maxsilence, path)) == -1) { 01719 /* User has hung up, no options to give */ 01720 return cmd; 01721 } 01722 if (cmd == '0') { 01723 break; 01724 } else if (cmd == '*') { 01725 break; 01726 } else { 01727 /* If all is well, a message exists */ 01728 message_exists = 1; 01729 cmd = 0; 01730 } 01731 break; 01732 case '4': 01733 case '5': 01734 case '6': 01735 case '7': 01736 case '8': 01737 case '9': 01738 case '*': 01739 case '#': 01740 cmd = ast_play_and_wait(chan, "vm-sorry"); 01741 break; 01742 default: 01743 if (message_exists) { 01744 cmd = ast_play_and_wait(chan, "vm-review"); 01745 } else { 01746 if (!(cmd = ast_play_and_wait(chan, "vm-torerecord"))) { 01747 cmd = ast_waitfordigit(chan, 600); 01748 } 01749 } 01750 01751 if (!cmd) { 01752 cmd = ast_waitfordigit(chan, 6000); 01753 } 01754 if (!cmd) { 01755 attempts++; 01756 } 01757 if (attempts > max_attempts) { 01758 cmd = 't'; 01759 } 01760 } 01761 } 01762 if (cmd == 't') { 01763 cmd = 0; 01764 } 01765 return cmd; 01766 }
| 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 2232 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().
02233 { 02234 sigset_t signal_set, old_set; 02235 int pid; 02236 02237 /* Don't let the default signal handler for children reap our status */ 02238 if (stop_reaper) { 02239 ast_replace_sigchld(); 02240 } 02241 02242 sigfillset(&signal_set); 02243 pthread_sigmask(SIG_BLOCK, &signal_set, &old_set); 02244 02245 pid = fork(); 02246 02247 if (pid != 0) { 02248 /* Fork failed or parent */ 02249 pthread_sigmask(SIG_SETMASK, &old_set, NULL); 02250 if (!stop_reaper && pid > 0) { 02251 struct zombie *cur = ast_calloc(1, sizeof(*cur)); 02252 if (cur) { 02253 cur->pid = pid; 02254 AST_LIST_LOCK(&zombies); 02255 AST_LIST_INSERT_TAIL(&zombies, cur, list); 02256 AST_LIST_UNLOCK(&zombies); 02257 if (shaun_of_the_dead_thread == AST_PTHREADT_NULL) { 02258 if (ast_pthread_create_background(&shaun_of_the_dead_thread, NULL, shaun_of_the_dead, NULL)) { 02259 ast_log(LOG_ERROR, "Shaun of the Dead wants to kill zombies, but can't?!!\n"); 02260 shaun_of_the_dead_thread = AST_PTHREADT_NULL; 02261 } 02262 } 02263 } 02264 } 02265 return pid; 02266 } else { 02267 /* Child */ 02268 #ifdef HAVE_CAP 02269 cap_t cap = cap_from_text("cap_net_admin-eip"); 02270 02271 if (cap_set_proc(cap)) { 02272 ast_log(LOG_WARNING, "Unable to remove capabilities.\n"); 02273 } 02274 cap_free(cap); 02275 #endif 02276 02277 /* Before we unblock our signals, return our trapped signals back to the defaults */ 02278 signal(SIGHUP, SIG_DFL); 02279 signal(SIGCHLD, SIG_DFL); 02280 signal(SIGINT, SIG_DFL); 02281 signal(SIGURG, SIG_DFL); 02282 signal(SIGTERM, SIG_DFL); 02283 signal(SIGPIPE, SIG_DFL); 02284 signal(SIGXFSZ, SIG_DFL); 02285 02286 /* unblock important signal handlers */ 02287 if (pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL)) { 02288 ast_log(LOG_WARNING, "unable to unblock signals: %s\n", strerror(errno)); 02289 _exit(1); 02290 } 02291 02292 return pid; 02293 } 02294 }
| void ast_safe_fork_cleanup | ( | void | ) |
Common routine to cleanup after fork'ed process is complete (if reaping was stopped).
Definition at line 2296 of file app.c.
References ast_unreplace_sigchld().
Referenced by agi_exec_full(), and run_ras().
02297 { 02298 ast_unreplace_sigchld(); 02299 }
| 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 1637 of file app.c.
References ast_lock_type.
Referenced by ast_readconfig().
01638 { 01639 ast_lock_type = type; 01640 }
| 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 2200 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().
02201 { 02202 char next, *buf; 02203 size_t offset = 0; 02204 size_t consumed; 02205 02206 if (strchr(stream, '\\')) { 02207 while (!ast_get_encoded_char(stream, &next, &consumed)) { 02208 if (offset + 2 > ast_str_size(*str) && maxlen > -1) { 02209 ast_str_make_space(str, maxlen > 0 ? maxlen : (ast_str_size(*str) + 48) * 2 - 48); 02210 } 02211 if (offset + 2 > ast_str_size(*str)) { 02212 break; 02213 } 02214 buf = ast_str_buffer(*str); 02215 buf[offset++] = next; 02216 stream += consumed; 02217 } 02218 buf = ast_str_buffer(*str); 02219 buf[offset++] = '\0'; 02220 ast_str_update(*str); 02221 } else { 02222 ast_str_set(str, maxlen, "%s", stream); 02223 } 02224 return 0; 02225 }
| AST_THREADSTORAGE_PUBLIC | ( | ast_str_thread_global_buf | ) |
| void ast_uninstall_vm_functions | ( | void | ) |
Definition at line 412 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().
00413 { 00414 ast_has_voicemail_func = NULL; 00415 ast_inboxcount_func = NULL; 00416 ast_inboxcount2_func = NULL; 00417 ast_messagecount_func = NULL; 00418 ast_sayname_func = NULL; 00419 }
| int ast_unlock_path | ( | const char * | path | ) |
Unlock a path.
Definition at line 1658 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().
01659 { 01660 int r = 0; 01661 01662 switch (ast_lock_type) { 01663 case AST_LOCK_TYPE_LOCKFILE: 01664 r = ast_unlock_path_lockfile(path); 01665 break; 01666 case AST_LOCK_TYPE_FLOCK: 01667 r = ast_unlock_path_flock(path); 01668 break; 01669 } 01670 01671 return r; 01672 }
| static int ast_unlock_path_flock | ( | const char * | path | ) | [static] |
Definition at line 1607 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().
01608 { 01609 char *s; 01610 struct path_lock *p; 01611 01612 s = ast_alloca(strlen(path) + 20); 01613 01614 AST_LIST_LOCK(&path_lock_list); 01615 AST_LIST_TRAVERSE_SAFE_BEGIN(&path_lock_list, p, le) { 01616 if (!strcmp(p->path, path)) { 01617 AST_LIST_REMOVE_CURRENT(le); 01618 break; 01619 } 01620 } 01621 AST_LIST_TRAVERSE_SAFE_END; 01622 AST_LIST_UNLOCK(&path_lock_list); 01623 01624 if (p) { 01625 snprintf(s, strlen(path) + 19, "%s/lock", path); 01626 unlink(s); 01627 path_lock_destroy(p); 01628 ast_log(LOG_DEBUG, "Unlocked path '%s'\n", path); 01629 } else { 01630 ast_log(LOG_DEBUG, "Failed to unlock path '%s': " 01631 "lock not found\n", path); 01632 } 01633 01634 return 0; 01635 }
| static int ast_unlock_path_lockfile | ( | const char * | path | ) | [static] |
Definition at line 1485 of file app.c.
References ast_alloca, ast_debug, ast_log(), errno, and LOG_ERROR.
Referenced by ast_unlock_path().
01486 { 01487 char *s; 01488 int res; 01489 01490 s = ast_alloca(strlen(path) + 10); 01491 01492 snprintf(s, strlen(path) + 9, "%s/%s", path, ".lock"); 01493 01494 if ((res = unlink(s))) { 01495 ast_log(LOG_ERROR, "Could not unlock path '%s': %s\n", path, strerror(errno)); 01496 } else { 01497 ast_debug(1, "Unlocked path '%s'\n", path); 01498 } 01499 01500 return res; 01501 }
| static int ivr_dispatch | ( | struct ast_channel * | chan, | |
| struct ast_ivr_option * | option, | |||
| char * | exten, | |||
| void * | cbdata | |||
| ) | [static] |
Definition at line 1775 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().
01776 { 01777 int res; 01778 int (*ivr_func)(struct ast_channel *, void *); 01779 char *c; 01780 char *n; 01781 01782 switch (option->action) { 01783 case AST_ACTION_UPONE: 01784 return RES_UPONE; 01785 case AST_ACTION_EXIT: 01786 return RES_EXIT | (((unsigned long)(option->adata)) & 0xffff); 01787 case AST_ACTION_REPEAT: 01788 return RES_REPEAT | (((unsigned long)(option->adata)) & 0xffff); 01789 case AST_ACTION_RESTART: 01790 return RES_RESTART ; 01791 case AST_ACTION_NOOP: 01792 return 0; 01793 case AST_ACTION_BACKGROUND: 01794 res = ast_stream_and_wait(chan, (char *)option->adata, AST_DIGIT_ANY); 01795 if (res < 0) { 01796 ast_log(LOG_NOTICE, "Unable to find file '%s'!\n", (char *)option->adata); 01797 res = 0; 01798 } 01799 return res; 01800 case AST_ACTION_PLAYBACK: 01801 res = ast_stream_and_wait(chan, (char *)option->adata, ""); 01802 if (res < 0) { 01803 ast_log(LOG_NOTICE, "Unable to find file '%s'!\n", (char *)option->adata); 01804 res = 0; 01805 } 01806 return res; 01807 case AST_ACTION_MENU: 01808 if ((res = ast_ivr_menu_run_internal(chan, (struct ast_ivr_menu *)option->adata, cbdata)) == -2) { 01809 /* Do not pass entry errors back up, treat as though it was an "UPONE" */ 01810 res = 0; 01811 } 01812 return res; 01813 case AST_ACTION_WAITOPTION: 01814 if (!(res = ast_waitfordigit(chan, chan->pbx ? chan->pbx->rtimeoutms : 10000))) { 01815 return 't'; 01816 } 01817 return res; 01818 case AST_ACTION_CALLBACK: 01819 ivr_func = option->adata; 01820 res = ivr_func(chan, cbdata); 01821 return res; 01822 case AST_ACTION_TRANSFER: 01823 res = ast_parseable_goto(chan, option->adata); 01824 return 0; 01825 case AST_ACTION_PLAYLIST: 01826 case AST_ACTION_BACKLIST: 01827 res = 0; 01828 c = ast_strdupa(option->adata); 01829 while ((n = strsep(&c, ";"))) { 01830 if ((res = ast_stream_and_wait(chan, n, 01831 (option->action == AST_ACTION_BACKLIST) ? AST_DIGIT_ANY : ""))) { 01832 break; 01833 } 01834 } 01835 ast_stopstream(chan); 01836 return res; 01837 default: 01838 ast_log(LOG_NOTICE, "Unknown dispatch function %u, ignoring!\n", option->action); 01839 return 0; 01840 } 01841 return -1; 01842 }
| static void* linear_alloc | ( | struct ast_channel * | chan, | |
| void * | params | |||
| ) | [static] |
Definition at line 620 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.
00621 { 00622 struct linear_state *ls = params; 00623 00624 if (!params) { 00625 return NULL; 00626 } 00627 00628 /* In this case, params is already malloc'd */ 00629 if (ls->allowoverride) { 00630 ast_set_flag(chan, AST_FLAG_WRITE_INT); 00631 } else { 00632 ast_clear_flag(chan, AST_FLAG_WRITE_INT); 00633 } 00634 00635 ls->origwfmt = chan->writeformat; 00636 00637 if (ast_set_write_format(chan, AST_FORMAT_SLINEAR)) { 00638 ast_log(LOG_WARNING, "Unable to set '%s' to linear format (write)\n", chan->name); 00639 ast_free(ls); 00640 ls = params = NULL; 00641 } 00642 00643 return params; 00644 }
| static int linear_generator | ( | struct ast_channel * | chan, | |
| void * | data, | |||
| int | len, | |||
| int | samples | |||
| ) | [static] |
Definition at line 591 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.
00592 { 00593 short buf[2048 + AST_FRIENDLY_OFFSET / 2]; 00594 struct linear_state *ls = data; 00595 struct ast_frame f = { 00596 .frametype = AST_FRAME_VOICE, 00597 .subclass.codec = AST_FORMAT_SLINEAR, 00598 .data.ptr = buf + AST_FRIENDLY_OFFSET / 2, 00599 .offset = AST_FRIENDLY_OFFSET, 00600 }; 00601 int res; 00602 00603 len = samples * 2; 00604 if (len > sizeof(buf) - AST_FRIENDLY_OFFSET) { 00605 ast_log(LOG_WARNING, "Can't generate %d bytes of data!\n" , len); 00606 len = sizeof(buf) - AST_FRIENDLY_OFFSET; 00607 } 00608 res = read(ls->fd, buf + AST_FRIENDLY_OFFSET/2, len); 00609 if (res > 0) { 00610 f.datalen = res; 00611 f.samples = res / 2; 00612 ast_write(chan, &f); 00613 if (res == len) { 00614 return 0; 00615 } 00616 } 00617 return -1; 00618 }
| static void linear_release | ( | struct ast_channel * | chan, | |
| void * | params | |||
| ) | [static] |
Definition at line 576 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.
00577 { 00578 struct linear_state *ls = params; 00579 00580 if (ls->origwfmt && ast_set_write_format(chan, ls->origwfmt)) { 00581 ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%d'\n", chan->name, ls->origwfmt); 00582 } 00583 00584 if (ls->autoclose) { 00585 close(ls->fd); 00586 } 00587 00588 ast_free(params); 00589 }
| static int option_exists | ( | struct ast_ivr_menu * | menu, | |
| char * | option | |||
| ) | [static] |
Definition at line 1844 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 1855 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 2011 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().
02012 { 02013 char *s, *arg; 02014 int curarg, res = 0; 02015 unsigned int argloc; 02016 struct ast_flags *flags = _flags; 02017 struct ast_flags64 *flags64 = _flags; 02018 02019 if (flaglen == 32) { 02020 ast_clear_flag(flags, AST_FLAGS_ALL); 02021 } else { 02022 flags64->flags = 0; 02023 } 02024 02025 if (!optstr) { 02026 return 0; 02027 } 02028 02029 s = optstr; 02030 while (*s) { 02031 curarg = *s++ & 0x7f; /* the array (in app.h) has 128 entries */ 02032 argloc = options[curarg].arg_index; 02033 if (*s == '(') { 02034 int paren = 1, quote = 0; 02035 int parsequotes = (s[1] == '"') ? 1 : 0; 02036 02037 /* Has argument */ 02038 arg = ++s; 02039 for (; *s; s++) { 02040 if (*s == '(' && !quote) { 02041 paren++; 02042 } else if (*s == ')' && !quote) { 02043 /* Count parentheses, unless they're within quotes (or backslashed, below) */ 02044 paren--; 02045 } else if (*s == '"' && parsequotes) { 02046 /* Leave embedded quotes alone, unless they are the first character */ 02047 quote = quote ? 0 : 1; 02048 ast_copy_string(s, s + 1, INT_MAX); 02049 s--; 02050 } else if (*s == '\\') { 02051 if (!quote) { 02052 /* If a backslash is found outside of quotes, remove it */ 02053 ast_copy_string(s, s + 1, INT_MAX); 02054 } else if (quote && s[1] == '"') { 02055 /* Backslash for a quote character within quotes, remove the backslash */ 02056 ast_copy_string(s, s + 1, INT_MAX); 02057 } else { 02058 /* Backslash within quotes, keep both characters */ 02059 s++; 02060 } 02061 } 02062 02063 if (paren == 0) { 02064 break; 02065 } 02066 } 02067 /* This will find the closing paren we found above, or none, if the string ended before we found one. */ 02068 if ((s = strchr(s, ')'))) { 02069 if (argloc) { 02070 args[argloc - 1] = arg; 02071 } 02072 *s++ = '\0'; 02073 } else { 02074 ast_log(LOG_WARNING, "Missing closing parenthesis for argument '%c' in string '%s'\n", curarg, arg); 02075 res = -1; 02076 break; 02077 } 02078 } else if (argloc) { 02079 args[argloc - 1] = ""; 02080 } 02081 if (flaglen == 32) { 02082 ast_set_flag(flags, options[curarg].flag); 02083 } else { 02084 ast_set_flag64(flags64, options[curarg].flag); 02085 } 02086 } 02087 02088 return res; 02089 }
| 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 1867 of file app.c.
References ast_waitfordigit(), ast_pbx::dtimeoutms, option_matchmore(), and ast_channel::pbx.
Referenced by ast_ivr_menu_run_internal().
01868 { 01869 int res = 0; 01870 int ms; 01871 while (option_matchmore(menu, exten)) { 01872 ms = chan->pbx ? chan->pbx->dtimeoutms : 5000; 01873 if (strlen(exten) >= maxexten - 1) { 01874 break; 01875 } 01876 if ((res = ast_waitfordigit(chan, ms)) < 1) { 01877 break; 01878 } 01879 exten[strlen(exten) + 1] = '\0'; 01880 exten[strlen(exten)] = res; 01881 } 01882 return res > 0 ? 0 : res; 01883 }
| static void* shaun_of_the_dead | ( | void * | data | ) | [static] |
Definition at line 75 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().
00076 { 00077 struct zombie *cur; 00078 int status; 00079 for (;;) { 00080 if (!AST_LIST_EMPTY(&zombies)) { 00081 /* Don't allow cancellation while we have a lock. */ 00082 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); 00083 AST_LIST_LOCK(&zombies); 00084 AST_LIST_TRAVERSE_SAFE_BEGIN(&zombies, cur, list) { 00085 if (waitpid(cur->pid, &status, WNOHANG) != 0) { 00086 AST_LIST_REMOVE_CURRENT(list); 00087 ast_free(cur); 00088 } 00089 } 00090 AST_LIST_TRAVERSE_SAFE_END 00091 AST_LIST_UNLOCK(&zombies); 00092 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); 00093 } 00094 pthread_testcancel(); 00095 /* Wait for 60 seconds, without engaging in a busy loop. */ 00096 ast_poll(NULL, 0, AST_LIST_FIRST(&zombies) ? 5000 : 60000); 00097 } 00098 return NULL; 00099 }
struct ast_app_stack_funcs* app_stack_callbacks [static] |
Definition at line 317 of file app.c.
Referenced by ast_app_exec_sub(), ast_app_expand_sub_args(), and ast_install_stack_functions().
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 229 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 1165 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 1166 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 838 of file app.c.
Referenced by __ast_play_and_record().
int global_silence_threshold = 128 [static] |
Definition at line 837 of file app.c.
Referenced by __ast_play_and_record().
struct ast_generator linearstream [static] |
Definition at line 646 of file app.c.
Referenced by ast_linear_stream().
pthread_t shaun_of_the_dead_thread = AST_PTHREADT_NULL [static] |
1.6.1