Go to the source code of this file.
Data Structures | |
struct | ast_app_option |
A structure to hold the description of an application 'option'. More... | |
struct | ast_group_info |
struct | ast_ivr_menu |
struct | ast_ivr_option |
Defines | |
#define | AST_APP_ARG(name) char *name |
Define an application argument. | |
#define | AST_APP_OPTION(option, flagno) [option] = { .flag = flagno } |
Declares an application option that does not accept an argument. | |
#define | AST_APP_OPTION_ARG(option, flagno, argno) [option] = { .flag = flagno, .arg_index = argno + 1 } |
Declares an application option that accepts an argument. | |
#define | AST_APP_OPTIONS(holder, options...) static const struct ast_app_option holder[128] = options |
Declares an array of options for an application. | |
#define | AST_DECLARE_APP_ARGS(name, arglist) |
Declare a structure to hold the application's arguments. | |
#define | AST_IVR_DECLARE_MENU(holder, title, flags, foo...) |
#define | AST_IVR_FLAG_AUTORESTART (1 << 0) |
#define | AST_NONSTANDARD_APP_ARGS(args, parse, sep) args.argc = ast_app_separate_args(parse, sep, args.argv, (sizeof(args) - sizeof(args.argc)) / sizeof(args.argv[0])) |
Performs the 'nonstandard' argument separation process for an application. | |
#define | AST_STANDARD_APP_ARGS(args, parse) args.argc = ast_app_separate_args(parse, '|', args.argv, (sizeof(args) - sizeof(args.argc)) / sizeof(args.argv[0])) |
Performs the 'standard' argument separation process for an application. | |
#define | BEGIN_OPTIONS { |
#define | END_OPTIONS } |
Typedefs | |
typedef int(* | ast_ivr_callback )(struct ast_channel *chan, char *option, void *cbdata) |
Callback function for IVR. | |
Enumerations | |
enum | ast_ivr_action { AST_ACTION_UPONE, AST_ACTION_EXIT, AST_ACTION_CALLBACK, AST_ACTION_PLAYBACK, AST_ACTION_BACKGROUND, AST_ACTION_PLAYLIST, AST_ACTION_MENU, AST_ACTION_REPEAT, AST_ACTION_RESTART, AST_ACTION_TRANSFER, AST_ACTION_WAITOPTION, AST_ACTION_NOOP, AST_ACTION_BACKLIST } |
enum | AST_LOCK_RESULT { AST_LOCK_SUCCESS = 0, AST_LOCK_TIMEOUT = -1, AST_LOCK_PATH_NOT_FOUND = -2, AST_LOCK_FAILURE = -3 } |
Functions | |
int | ast_app_dtget (struct ast_channel *chan, const char *context, char *collect, size_t size, int maxlen, int timeout) |
Present a dialtone and collect a certain length extension. | |
int | ast_app_getdata (struct ast_channel *c, char *prompt, char *s, int maxlen, int timeout) |
Plays a stream and gets DTMF data from a channel. | |
int | ast_app_getdata_full (struct ast_channel *c, char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd) |
Full version with audiofd and controlfd. NOTE: returns '2' on ctrlfd available, not '1' like other full functions. | |
int | ast_app_group_discard (struct ast_channel *chan) |
int | ast_app_group_get_count (const char *group, const char *category) |
struct ast_group_info * | ast_app_group_list_head (void) |
int | ast_app_group_list_lock (void) |
int | ast_app_group_list_unlock (void) |
int | ast_app_group_match_get_count (const char *groupmatch, const char *category) |
int | ast_app_group_set_channel (struct ast_channel *chan, const char *data) |
int | ast_app_group_split_group (const char *data, char *group, int group_max, char *category, int category_max) |
int | ast_app_group_update (struct ast_channel *oldchan, struct ast_channel *newchan) |
int | ast_app_has_voicemail (const char *mailbox, const char *folder) |
int | ast_app_inboxcount (const char *mailbox, int *newmsgs, int *oldmsgs) |
int | ast_app_messagecount (const char *context, const char *mailbox, const char *folder) |
int | ast_app_parse_options (const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr) |
Parses a string containing application options and sets flags/arguments. | |
unsigned int | ast_app_separate_args (char *buf, char delim, char **array, int arraylen) |
Separate a string into arguments in an array. | |
int | ast_control_streamfile (struct ast_channel *chan, const char *file, const char *fwd, const char *rev, const char *stop, const char *pause, const char *restart, int skipms) |
int | ast_dtmf_stream (struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between) |
Send DTMF to a channel. | |
void | ast_install_vm_functions (int(*has_voicemail_func)(const char *mailbox, const char *folder), int(*inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs), int(*messagecount_func)(const char *context, const char *mailbox, const char *folder)) |
int | ast_ivr_menu_run (struct ast_channel *c, struct ast_ivr_menu *menu, void *cbdata) |
Runs an IVR menu. | |
int | ast_linear_stream (struct ast_channel *chan, const char *filename, int fd, int allowoverride) |
enum AST_LOCK_RESULT | ast_lock_path (const char *path) |
Lock a filesystem path. | |
int | ast_play_and_prepend (struct ast_channel *chan, char *playfile, char *recordfile, int maxtime_sec, char *fmt, int *duration, int beep, int silencethreshold, int maxsilence_ms) |
int | ast_play_and_record (struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime_sec, const char *fmt, int *duration, int silencethreshold, int maxsilence_ms, const char *path) |
int | ast_play_and_record_full (struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime_sec, const char *fmt, int *duration, int silencethreshold, int maxsilence_ms, const char *path, const char *acceptdtmf, const char *canceldtmf) |
int | ast_play_and_wait (struct ast_channel *chan, const char *fn) |
char * | ast_read_textfile (const char *file) |
int | ast_record_review (struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, const char *path) |
void | ast_replace_sigchld (void) |
Replace the SIGCHLD handler. | |
int | ast_safe_system (const char *s) |
void | ast_uninstall_vm_functions (void) |
int | ast_unlock_path (const char *path) |
void | ast_unreplace_sigchld (void) |
Restore the SIGCHLD handler. |
Definition in file app.h.
Define an application argument.
name | The name of the argument |
Definition at line 244 of file app.h.
Referenced by __login_exec(), acf_channel_read(), acf_curl_exec(), acf_odbc_read(), acf_odbc_write(), acf_rand_exec(), acf_sprintf(), acf_strftime(), acf_strptime(), acf_vmcount_exec(), add_agent(), admin_exec(), app_exec(), aqm_exec(), array(), astman_get_variables(), asyncgoto_exec(), auth_exec(), cdr_read(), cdr_write(), chanavail_exec(), checkmd5(), conf_exec(), count_exec(), cut_internal(), dictate_exec(), directory_exec(), disa_exec(), filter(), find_conf(), func_header_read(), function_agent(), function_db_delete(), function_db_exists(), function_db_read(), function_db_write(), function_enum(), function_fieldqty(), function_realtime_read(), function_realtime_write(), hasvoicemail_exec(), isAnsweringMachine(), math(), misdn_check_l2l1(), mixmonitor_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), pbx_builtin_background(), pbx_builtin_waitexten(), playback_exec(), pqm_exec(), privacy_exec(), ql_exec(), queue_exec(), read_exec(), record_exec(), regex(), reload_queues(), rqm_exec(), sayunixtime_exec(), sendimage_exec(), sendtext_exec(), transfer_exec(), upqm_exec(), userevent_exec(), vm_box_exists(), vm_exec(), and vm_execmain().
#define AST_APP_OPTION | ( | option, | |||
flagno | ) | [option] = { .flag = flagno } |
Declares an application option that does not accept an argument.
option | The single character representing the option | |
flagno | The flag index to be set if this option is present |
#define AST_APP_OPTION_ARG | ( | option, | |||
flagno, | |||||
argno | ) | [option] = { .flag = flagno, .arg_index = argno + 1 } |
Declares an application option that accepts an argument.
option | The single character representing the option | |
flagno | The flag index to be set if this option is present | |
argno | The index into the argument array where the argument should be placed |
#define AST_APP_OPTIONS | ( | holder, | |||
options... | ) | static const struct ast_app_option holder[128] = options |
Declares an array of options for an application.
holder | The name of the array to be created | |
options | The actual options to be placed into the array |
struct
ast_option
elements to hold the list of available options for an application. Each option must be declared using either the AST_APP_OPTION() or AST_APP_OPTION_ARG() macros.Example usage:
enum { OPT_JUMP = (1 << 0), OPT_BLAH = (1 << 1), OPT_BLORT = (1 << 2), } my_app_option_flags; enum { OPT_ARG_BLAH = 0, OPT_ARG_BLORT, !! this entry tells how many possible arguments there are, and must be the last entry in the list OPT_ARG_ARRAY_SIZE, } my_app_option_args; AST_APP_OPTIONS(my_app_options, { AST_APP_OPTION('j', OPT_JUMP), AST_APP_OPTION_ARG('b', OPT_BLAH, OPT_ARG_BLAH), AST_APP_OPTION_BLORT('B', OPT_BLORT, OPT_ARG_BLORT), }); static int my_app_exec(struct ast_channel *chan, void *data) { char *options; struct ast_flags opts = { 0, }; char *opt_args[OPT_ARG_ARRAY_SIZE]; ... do any argument parsing here ... if (ast_parseoptions(my_app_options, &opts, opt_args, options)) { LOCAL_USER_REMOVE(u); return -1; } }
#define AST_DECLARE_APP_ARGS | ( | name, | |||
arglist | ) |
Value:
struct { \ unsigned int argc; \ char *argv[0]; \ arglist \ } name
name | The name of the structure | |
arglist | The list of arguments, defined using AST_APP_ARG |
Definition at line 261 of file app.h.
Referenced by __login_exec(), acf_channel_read(), acf_curl_exec(), acf_odbc_read(), acf_odbc_write(), acf_rand_exec(), acf_sprintf(), acf_strftime(), acf_strptime(), acf_vmcount_exec(), add_agent(), admin_exec(), app_exec(), aqm_exec(), array(), astman_get_variables(), asyncgoto_exec(), auth_exec(), cdr_read(), cdr_write(), chanavail_exec(), checkmd5(), conf_exec(), count_exec(), cut_internal(), dictate_exec(), directory_exec(), disa_exec(), filter(), find_conf(), func_header_read(), function_agent(), function_db_delete(), function_db_exists(), function_db_read(), function_db_write(), function_enum(), function_fieldqty(), function_realtime_read(), function_realtime_write(), hasvoicemail_exec(), isAnsweringMachine(), math(), misdn_check_l2l1(), mixmonitor_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), pbx_builtin_background(), pbx_builtin_waitexten(), playback_exec(), pqm_exec(), privacy_exec(), ql_exec(), queue_exec(), read_exec(), record_exec(), regex(), reload_queues(), rqm_exec(), sayunixtime_exec(), sendimage_exec(), sendtext_exec(), transfer_exec(), upqm_exec(), userevent_exec(), vm_box_exists(), vm_exec(), and vm_execmain().
#define AST_IVR_DECLARE_MENU | ( | holder, | |||
title, | |||||
flags, | |||||
foo... | ) |
Value:
static struct ast_ivr_option __options_##holder[] = foo;\ static struct ast_ivr_menu holder = { title, flags, __options_##holder }
#define AST_NONSTANDARD_APP_ARGS | ( | args, | |||
parse, | |||||
sep | ) | args.argc = ast_app_separate_args(parse, sep, args.argv, (sizeof(args) - sizeof(args.argc)) / sizeof(args.argv[0])) |
Performs the 'nonstandard' argument separation process for an application.
args | An argument structure defined using AST_DECLARE_APP_ARGS | |
parse | A modifiable buffer containing the input to be parsed | |
sep | A nonstandard separator character |
Definition at line 290 of file app.h.
Referenced by acf_odbc_write(), add_agent(), array(), find_conf(), function_agent(), function_db_delete(), function_db_exists(), function_db_read(), function_db_write(), record_exec(), regex(), and reload_queues().
#define AST_STANDARD_APP_ARGS | ( | args, | |||
parse | ) | args.argc = ast_app_separate_args(parse, '|', args.argv, (sizeof(args) - sizeof(args.argc)) / sizeof(args.argv[0])) |
Performs the 'standard' argument separation process for an application.
args | An argument structure defined using AST_DECLARE_APP_ARGS | |
parse | A modifiable buffer containing the input to be parsed |
Definition at line 277 of file app.h.
Referenced by __login_exec(), acf_channel_read(), acf_curl_exec(), acf_odbc_read(), acf_odbc_write(), acf_rand_exec(), acf_sprintf(), acf_strftime(), acf_strptime(), acf_vmcount_exec(), admin_exec(), app_exec(), aqm_exec(), array(), astman_get_variables(), asyncgoto_exec(), auth_exec(), cdr_read(), cdr_write(), chanavail_exec(), checkmd5(), conf_exec(), count_exec(), cut_internal(), dictate_exec(), directory_exec(), disa_exec(), filter(), func_header_read(), function_enum(), function_fieldqty(), function_realtime_read(), function_realtime_write(), hasvoicemail_exec(), isAnsweringMachine(), math(), misdn_check_l2l1(), mixmonitor_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), pbx_builtin_background(), pbx_builtin_waitexten(), playback_exec(), pqm_exec(), privacy_exec(), ql_exec(), queue_exec(), read_exec(), rqm_exec(), sayunixtime_exec(), sendimage_exec(), sendtext_exec(), transfer_exec(), upqm_exec(), userevent_exec(), vm_box_exists(), vm_exec(), and vm_execmain().
typedef int(* ast_ivr_callback)(struct ast_channel *chan, char *option, void *cbdata) |
enum ast_ivr_action |
AST_ACTION_UPONE | adata is unused |
AST_ACTION_EXIT | adata is the return value for ast_ivr_menu_run if channel was not hungup |
AST_ACTION_CALLBACK | adata is an ast_ivr_callback |
AST_ACTION_PLAYBACK | adata is file to play |
AST_ACTION_BACKGROUND | adata is file to play |
AST_ACTION_PLAYLIST | adata is list of files, separated by ; to play |
AST_ACTION_MENU | adata is a pointer to an ast_ivr_menu |
AST_ACTION_REPEAT | adata is max # of repeats, cast to a pointer |
AST_ACTION_RESTART | adata is like repeat, but resets repeats to 0 |
AST_ACTION_TRANSFER | adata is a string with exten[] |
AST_ACTION_WAITOPTION | adata is a timeout, or 0 for defaults |
AST_ACTION_NOOP | adata is unused |
AST_ACTION_BACKLIST | adata is list of files separated by ; allows interruption |
Definition at line 37 of file app.h.
00037 { 00038 AST_ACTION_UPONE, /*!< adata is unused */ 00039 AST_ACTION_EXIT, /*!< adata is the return value for ast_ivr_menu_run if channel was not hungup */ 00040 AST_ACTION_CALLBACK, /*!< adata is an ast_ivr_callback */ 00041 AST_ACTION_PLAYBACK, /*!< adata is file to play */ 00042 AST_ACTION_BACKGROUND, /*!< adata is file to play */ 00043 AST_ACTION_PLAYLIST, /*!< adata is list of files, separated by ; to play */ 00044 AST_ACTION_MENU, /*!< adata is a pointer to an ast_ivr_menu */ 00045 AST_ACTION_REPEAT, /*!< adata is max # of repeats, cast to a pointer */ 00046 AST_ACTION_RESTART, /*!< adata is like repeat, but resets repeats to 0 */ 00047 AST_ACTION_TRANSFER, /*!< adata is a string with exten[@context] */ 00048 AST_ACTION_WAITOPTION, /*!< adata is a timeout, or 0 for defaults */ 00049 AST_ACTION_NOOP, /*!< adata is unused */ 00050 AST_ACTION_BACKLIST, /*!< adata is list of files separated by ; allows interruption */ 00051 } ast_ivr_action;
enum AST_LOCK_RESULT |
Definition at line 186 of file app.h.
00186 { 00187 AST_LOCK_SUCCESS = 0, 00188 AST_LOCK_TIMEOUT = -1, 00189 AST_LOCK_PATH_NOT_FOUND = -2, 00190 AST_LOCK_FAILURE = -3, 00191 };
int ast_app_dtget | ( | struct ast_channel * | chan, | |
const char * | context, | |||
char * | collect, | |||
size_t | size, | |||
int | maxlen, | |||
int | timeout | |||
) |
Present a dialtone and collect a certain length extension.
Definition at line 65 of file app.c.
References ast_exists_extension(), ast_get_indication_tone(), ast_ignore_pattern(), ast_log(), ast_matchmore_extension(), ast_playtones_start(), ast_playtones_stop(), ast_waitfordigit(), ast_channel::cid, ast_callerid::cid_num, tone_zone_sound::data, ast_pbx::dtimeout, LOG_NOTICE, ast_channel::pbx, and ast_channel::zone.
00066 { 00067 struct tone_zone_sound *ts; 00068 int res=0, x=0; 00069 00070 if (maxlen > size) 00071 maxlen = size; 00072 00073 if (!timeout && chan->pbx) 00074 timeout = chan->pbx->dtimeout; 00075 else if (!timeout) 00076 timeout = 5; 00077 00078 ts = ast_get_indication_tone(chan->zone,"dial"); 00079 if (ts && ts->data[0]) 00080 res = ast_playtones_start(chan, 0, ts->data, 0); 00081 else 00082 ast_log(LOG_NOTICE,"Huh....? no dial for indications?\n"); 00083 00084 for (x = strlen(collect); x < maxlen; ) { 00085 res = ast_waitfordigit(chan, timeout); 00086 if (!ast_ignore_pattern(context, collect)) 00087 ast_playtones_stop(chan); 00088 if (res < 1) 00089 break; 00090 if (res == '#') 00091 break; 00092 collect[x++] = res; 00093 if (!ast_matchmore_extension(chan, context, collect, 1, chan->cid.cid_num)) 00094 break; 00095 } 00096 if (res >= 0) 00097 res = ast_exists_extension(chan, context, collect, 1, chan->cid.cid_num) ? 1 : 0; 00098 return res; 00099 }
int ast_app_getdata | ( | struct ast_channel * | c, | |
char * | prompt, | |||
char * | s, | |||
int | maxlen, | |||
int | timeout | |||
) |
Plays a stream and gets DTMF data from a channel.
c | Which channel one is interacting with | |
prompt | File to pass to ast_streamfile (the one that you wish to play) | |
s | The location where the DTMF data will be stored | |
maxlen | Max Length of the data | |
timeout | Timeout length waiting for data(in milliseconds). Set to 0 for standard timeout(six seconds), or -1 for no time out. |
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 107 of file app.c.
References ast_readstring(), ast_streamfile(), ast_pbx::dtimeout, ast_channel::pbx, and ast_pbx::rtimeout.
00108 { 00109 int res,to,fto; 00110 /* XXX Merge with full version? XXX */ 00111 if (maxlen) 00112 s[0] = '\0'; 00113 if (prompt) { 00114 res = ast_streamfile(c, prompt, c->language); 00115 if (res < 0) 00116 return res; 00117 } 00118 fto = c->pbx ? c->pbx->rtimeout * 1000 : 6000; 00119 to = c->pbx ? c->pbx->dtimeout * 1000 : 2000; 00120 00121 if (timeout > 0) 00122 fto = to = timeout; 00123 if (timeout < 0) 00124 fto = to = 1000000000; 00125 res = ast_readstring(c, s, maxlen, to, fto, "#"); 00126 return res; 00127 }
int ast_app_getdata_full | ( | struct ast_channel * | c, | |
char * | prompt, | |||
char * | s, | |||
int | maxlen, | |||
int | timeout, | |||
int | audiofd, | |||
int | ctrlfd | |||
) |
Full version with audiofd and controlfd. NOTE: returns '2' on ctrlfd available, not '1' like other full functions.
Definition at line 130 of file app.c.
References ast_readstring_full(), and ast_streamfile().
00131 { 00132 int res, to, fto; 00133 if (prompt) { 00134 res = ast_streamfile(c, prompt, c->language); 00135 if (res < 0) 00136 return res; 00137 } 00138 fto = 6000; 00139 to = 2000; 00140 if (timeout > 0) 00141 fto = to = timeout; 00142 if (timeout < 0) 00143 fto = to = 1000000000; 00144 res = ast_readstring_full(c, s, maxlen, to, fto, "#", audiofd, ctrlfd); 00145 return res; 00146 }
int ast_app_group_discard | ( | struct ast_channel * | chan | ) |
Discard all group counting for a channel
Definition at line 893 of file app.c.
References AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_group_info::chan, and free.
00894 { 00895 struct ast_group_info *gi = NULL; 00896 00897 AST_LIST_LOCK(&groups); 00898 AST_LIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) { 00899 if (gi->chan == chan) { 00900 AST_LIST_REMOVE_CURRENT(&groups, list); 00901 free(gi); 00902 } 00903 } 00904 AST_LIST_TRAVERSE_SAFE_END 00905 AST_LIST_UNLOCK(&groups); 00906 00907 return 0; 00908 }
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 836 of file app.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strlen_zero(), ast_group_info::category, and ast_group_info::group.
00837 { 00838 struct ast_group_info *gi = NULL; 00839 int count = 0; 00840 00841 if (ast_strlen_zero(group)) 00842 return 0; 00843 00844 AST_LIST_LOCK(&groups); 00845 AST_LIST_TRAVERSE(&groups, gi, list) { 00846 if (!strcasecmp(gi->group, group) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) 00847 count++; 00848 } 00849 AST_LIST_UNLOCK(&groups); 00850 00851 return count; 00852 }
struct ast_group_info* ast_app_group_list_head | ( | void | ) | [read] |
Get the head of the group count list
Definition at line 915 of file app.c.
References AST_LIST_FIRST.
00916 { 00917 return AST_LIST_FIRST(&groups); 00918 }
int ast_app_group_list_lock | ( | void | ) |
Lock the group count list
Definition at line 910 of file app.c.
References AST_LIST_LOCK.
00911 { 00912 return AST_LIST_LOCK(&groups); 00913 }
int ast_app_group_list_unlock | ( | void | ) |
Unlock the group count list
Definition at line 920 of file app.c.
References AST_LIST_UNLOCK.
00921 { 00922 return AST_LIST_UNLOCK(&groups); 00923 }
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 854 of file app.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strlen_zero(), ast_group_info::category, and ast_group_info::group.
00855 { 00856 struct ast_group_info *gi = NULL; 00857 regex_t regexbuf; 00858 int count = 0; 00859 00860 if (ast_strlen_zero(groupmatch)) 00861 return 0; 00862 00863 /* if regex compilation fails, return zero matches */ 00864 if (regcomp(®exbuf, groupmatch, REG_EXTENDED | REG_NOSUB)) 00865 return 0; 00866 00867 AST_LIST_LOCK(&groups); 00868 AST_LIST_TRAVERSE(&groups, gi, list) { 00869 if (!regexec(®exbuf, gi->group, 0, NULL, 0) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) 00870 count++; 00871 } 00872 AST_LIST_UNLOCK(&groups); 00873 00874 regfree(®exbuf); 00875 00876 return count; 00877 }
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 793 of file app.c.
References ast_app_group_split_group(), AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_strlen_zero(), calloc, ast_group_info::category, ast_group_info::chan, free, ast_group_info::group, group, and len.
00794 { 00795 int res = 0; 00796 char group[80] = "", category[80] = ""; 00797 struct ast_group_info *gi = NULL; 00798 size_t len = 0; 00799 00800 if (ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category))) 00801 return -1; 00802 00803 /* Calculate memory we will need if this is new */ 00804 len = sizeof(*gi) + strlen(group) + 1; 00805 if (!ast_strlen_zero(category)) 00806 len += strlen(category) + 1; 00807 00808 AST_LIST_LOCK(&groups); 00809 AST_LIST_TRAVERSE_SAFE_BEGIN(&groups, gi, list) { 00810 if ((gi->chan == chan) && ((ast_strlen_zero(category) && ast_strlen_zero(gi->category)) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) { 00811 AST_LIST_REMOVE_CURRENT(&groups, list); 00812 free(gi); 00813 break; 00814 } 00815 } 00816 AST_LIST_TRAVERSE_SAFE_END 00817 00818 if ((gi = calloc(1, len))) { 00819 gi->chan = chan; 00820 gi->group = (char *) gi + sizeof(*gi); 00821 strcpy(gi->group, group); 00822 if (!ast_strlen_zero(category)) { 00823 gi->category = (char *) gi + sizeof(*gi) + strlen(group) + 1; 00824 strcpy(gi->category, category); 00825 } 00826 AST_LIST_INSERT_TAIL(&groups, gi, list); 00827 } else { 00828 res = -1; 00829 } 00830 00831 AST_LIST_UNLOCK(&groups); 00832 00833 return res; 00834 }
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 766 of file app.c.
References ast_strlen_zero().
00767 { 00768 int res=0; 00769 char tmp[256]; 00770 char *grp=NULL, *cat=NULL; 00771 00772 if (!ast_strlen_zero(data)) { 00773 ast_copy_string(tmp, data, sizeof(tmp)); 00774 grp = tmp; 00775 cat = strchr(tmp, '@'); 00776 if (cat) { 00777 *cat = '\0'; 00778 cat++; 00779 } 00780 } 00781 00782 if (!ast_strlen_zero(grp)) 00783 ast_copy_string(group, grp, group_max); 00784 else 00785 res = -1; 00786 00787 if (!ast_strlen_zero(cat)) 00788 ast_copy_string(category, cat, category_max); 00789 00790 return res; 00791 }
int ast_app_group_update | ( | struct ast_channel * | oldchan, | |
struct ast_channel * | newchan | |||
) |
Update all group counting for a channel to a new one
Definition at line 879 of file app.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, and ast_group_info::chan.
00880 { 00881 struct ast_group_info *gi = NULL; 00882 00883 AST_LIST_LOCK(&groups); 00884 AST_LIST_TRAVERSE(&groups, gi, list) { 00885 if (gi->chan == old) 00886 gi->chan = new; 00887 } 00888 AST_LIST_UNLOCK(&groups); 00889 00890 return 0; 00891 }
int ast_app_has_voicemail | ( | const char * | mailbox, | |
const char * | folder | |||
) |
Determine if a given mailbox has any voicemail
Definition at line 168 of file app.c.
References ast_has_voicemail_func, ast_verbose(), option_verbose, and VERBOSE_PREFIX_3.
00169 { 00170 static int warned = 0; 00171 if (ast_has_voicemail_func) 00172 return ast_has_voicemail_func(mailbox, folder); 00173 00174 if ((option_verbose > 2) && !warned) { 00175 ast_verbose(VERBOSE_PREFIX_3 "Message check requested for mailbox %s/folder %s but voicemail not loaded.\n", mailbox, folder ? folder : "INBOX"); 00176 warned++; 00177 } 00178 return 0; 00179 }
int ast_app_inboxcount | ( | const char * | mailbox, | |
int * | newmsgs, | |||
int * | oldmsgs | |||
) |
Determine number of new/old messages in a mailbox
Definition at line 182 of file app.c.
References ast_inboxcount_func, ast_verbose(), option_verbose, and VERBOSE_PREFIX_3.
00183 { 00184 static int warned = 0; 00185 if (newmsgs) 00186 *newmsgs = 0; 00187 if (oldmsgs) 00188 *oldmsgs = 0; 00189 if (ast_inboxcount_func) 00190 return ast_inboxcount_func(mailbox, newmsgs, oldmsgs); 00191 00192 if (!warned && (option_verbose > 2)) { 00193 warned++; 00194 ast_verbose(VERBOSE_PREFIX_3 "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox); 00195 } 00196 00197 return 0; 00198 }
int ast_app_messagecount | ( | const char * | context, | |
const char * | mailbox, | |||
const char * | folder | |||
) |
Determine number of messages in a given mailbox and folder
Definition at line 200 of file app.c.
References ast_messagecount_func, ast_verbose(), option_verbose, and VERBOSE_PREFIX_3.
00201 { 00202 static int warned = 0; 00203 if (ast_messagecount_func) 00204 return ast_messagecount_func(context, mailbox, folder); 00205 00206 if (!warned && (option_verbose > 2)) { 00207 warned++; 00208 ast_verbose(VERBOSE_PREFIX_3 "Message count requested for mailbox %s@%s/%s but voicemail not loaded.\n", mailbox, context, folder); 00209 } 00210 00211 return 0; 00212 }
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 1360 of file app.c.
References ast_app_option::arg_index, ast_clear_flag, AST_FLAGS_ALL, ast_log(), ast_set_flag, LOG_WARNING, and s.
01361 { 01362 char *s; 01363 int curarg; 01364 unsigned int argloc; 01365 char *arg; 01366 int res = 0; 01367 01368 ast_clear_flag(flags, AST_FLAGS_ALL); 01369 01370 if (!optstr) 01371 return 0; 01372 01373 s = optstr; 01374 while (*s) { 01375 curarg = *s++ & 0x7f; /* the array (in app.h) has 128 entries */ 01376 ast_set_flag(flags, options[curarg].flag); 01377 argloc = options[curarg].arg_index; 01378 if (*s == '(') { 01379 /* Has argument */ 01380 arg = ++s; 01381 if ((s = strchr(s, ')'))) { 01382 if (argloc) 01383 args[argloc - 1] = arg; 01384 *s++ = '\0'; 01385 } else { 01386 ast_log(LOG_WARNING, "Missing closing parenthesis for argument '%c' in string '%s'\n", curarg, arg); 01387 res = -1; 01388 break; 01389 } 01390 } else if (argloc) { 01391 args[argloc - 1] = NULL; 01392 } 01393 } 01394 01395 return res; 01396 }
unsigned int ast_app_separate_args | ( | char * | buf, | |
char | delim, | |||
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 | |
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) |
The array will be completely zeroed by this function before it populates any entries.
Definition at line 925 of file app.c.
References quote().
00926 { 00927 int argc; 00928 char *scan; 00929 int paren = 0, quote = 0; 00930 00931 if (!buf || !array || !arraylen) 00932 return 0; 00933 00934 memset(array, 0, arraylen * sizeof(*array)); 00935 00936 scan = buf; 00937 00938 for (argc = 0; *scan && (argc < arraylen - 1); argc++) { 00939 array[argc] = scan; 00940 for (; *scan; scan++) { 00941 if (*scan == '(') 00942 paren++; 00943 else if (*scan == ')') { 00944 if (paren) 00945 paren--; 00946 } else if (*scan == '"' && delim != '"') { 00947 quote = quote ? 0 : 1; 00948 /* Remove quote character from argument */ 00949 memmove(scan, scan + 1, strlen(scan)); 00950 scan--; 00951 } else if (*scan == '\\') { 00952 /* Literal character, don't parse */ 00953 memmove(scan, scan + 1, strlen(scan)); 00954 } else if ((*scan == delim) && !paren && !quote) { 00955 *scan++ = '\0'; 00956 break; 00957 } 00958 } 00959 } 00960 00961 if (*scan) 00962 array[argc++] = scan; 00963 00964 return argc; 00965 }
int ast_control_streamfile | ( | struct ast_channel * | chan, | |
const char * | file, | |||
const char * | fwd, | |||
const char * | rev, | |||
const char * | stop, | |||
const char * | pause, | |||
const char * | restart, | |||
int | skipms | |||
) |
Stream a file with fast forward, pause, reverse, restart.
Definition at line 362 of file app.c.
References ast_channel::_state, ast_answer(), ast_log(), ast_seekstream(), AST_STATE_UP, ast_stopstream(), ast_streamfile(), ast_tellstream(), ast_waitfordigit(), ast_waitstream_fr(), LOG_DEBUG, option_debug, and ast_channel::stream.
00366 { 00367 char *breaks = NULL; 00368 char *end = NULL; 00369 int blen = 2; 00370 int res; 00371 long pause_restart_point = 0; 00372 00373 if (stop) 00374 blen += strlen(stop); 00375 if (pause) 00376 blen += strlen(pause); 00377 if (restart) 00378 blen += strlen(restart); 00379 00380 if (blen > 2) { 00381 breaks = alloca(blen + 1); 00382 breaks[0] = '\0'; 00383 if (stop) 00384 strcat(breaks, stop); 00385 if (pause) 00386 strcat(breaks, pause); 00387 if (restart) 00388 strcat(breaks, restart); 00389 } 00390 if (chan->_state != AST_STATE_UP) 00391 res = ast_answer(chan); 00392 00393 if (file) { 00394 if ((end = strchr(file,':'))) { 00395 if (!strcasecmp(end, ":end")) { 00396 *end = '\0'; 00397 end++; 00398 } 00399 } 00400 } 00401 00402 for (;;) { 00403 ast_stopstream(chan); 00404 res = ast_streamfile(chan, file, chan->language); 00405 if (!res) { 00406 if (pause_restart_point) { 00407 ast_seekstream(chan->stream, pause_restart_point, SEEK_SET); 00408 pause_restart_point = 0; 00409 } 00410 else if (end) { 00411 ast_seekstream(chan->stream, 0, SEEK_END); 00412 end = NULL; 00413 }; 00414 res = ast_waitstream_fr(chan, breaks, fwd, rev, skipms); 00415 } 00416 00417 if (res < 1) 00418 break; 00419 00420 /* We go at next loop if we got the restart char */ 00421 if (restart && strchr(restart, res)) { 00422 if (option_debug) 00423 ast_log(LOG_DEBUG, "we'll restart the stream here at next loop\n"); 00424 pause_restart_point = 0; 00425 continue; 00426 } 00427 00428 if (pause && strchr(pause, res)) { 00429 pause_restart_point = ast_tellstream(chan->stream); 00430 for (;;) { 00431 ast_stopstream(chan); 00432 res = ast_waitfordigit(chan, 1000); 00433 if (!res) 00434 continue; 00435 else if (res == -1 || strchr(pause, res) || (stop && strchr(stop, res))) 00436 break; 00437 } 00438 if (res == *pause) { 00439 res = 0; 00440 continue; 00441 } 00442 } 00443 00444 if (res == -1) 00445 break; 00446 00447 /* if we get one of our stop chars, return it to the calling function */ 00448 if (stop && strchr(stop, res)) 00449 break; 00450 } 00451 00452 ast_stopstream(chan); 00453 00454 return res; 00455 }
int ast_dtmf_stream | ( | struct ast_channel * | chan, | |
struct ast_channel * | peer, | |||
const char * | digits, | |||
int | between | |||
) |
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. |
Definition at line 214 of file app.c.
References ast_autoservice_start(), ast_autoservice_stop(), AST_CONTROL_FLASH, ast_indicate(), ast_log(), ast_safe_sleep(), ast_senddigit(), ast_waitfor(), and LOG_WARNING.
00215 { 00216 const char *ptr; 00217 int res = 0; 00218 00219 if (!between) 00220 between = 100; 00221 00222 if (peer) 00223 res = ast_autoservice_start(peer); 00224 00225 if (!res) 00226 res = ast_waitfor(chan, 100); 00227 00228 /* ast_waitfor will return the number of remaining ms on success */ 00229 if (res < 0) 00230 return res; 00231 00232 for (ptr = digits; *ptr; ptr++) { 00233 if (*ptr == 'w') { 00234 /* 'w' -- wait half a second */ 00235 if ((res = ast_safe_sleep(chan, 500))) 00236 break; 00237 } else if (strchr("0123456789*#abcdfABCDF", *ptr)) { 00238 /* Character represents valid DTMF */ 00239 if (*ptr == 'f' || *ptr == 'F') { 00240 /* ignore return values if not supported by channel */ 00241 ast_indicate(chan, AST_CONTROL_FLASH); 00242 } else 00243 ast_senddigit(chan, *ptr); 00244 /* pause between digits */ 00245 if ((res = ast_safe_sleep(chan, between))) 00246 break; 00247 } else 00248 ast_log(LOG_WARNING, "Illegal DTMF character '%c' in string. (0-9*#aAbBcCdD allowed)\n",*ptr); 00249 } 00250 00251 if (peer) { 00252 /* Stop autoservice on the peer channel, but don't overwrite any error condition 00253 that has occurred previously while acting on the primary channel */ 00254 if (ast_autoservice_stop(peer) && !res) 00255 res = -1; 00256 } 00257 00258 return res; 00259 }
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 *context, const char *mailbox, const char *folder) | messagecount_func | |||
) |
Definition at line 152 of file app.c.
References ast_has_voicemail_func, ast_inboxcount_func, and ast_messagecount_func.
00155 { 00156 ast_has_voicemail_func = has_voicemail_func; 00157 ast_inboxcount_func = inboxcount_func; 00158 ast_messagecount_func = messagecount_func; 00159 }
int ast_ivr_menu_run | ( | struct ast_channel * | c, | |
struct ast_ivr_menu * | menu, | |||
void * | cbdata | |||
) |
Runs an IVR menu.
Definition at line 1322 of file app.c.
References ast_ivr_menu_run_internal().
01323 { 01324 int res = ast_ivr_menu_run_internal(chan, menu, cbdata); 01325 /* Hide internal coding */ 01326 return res > 0 ? 0 : res; 01327 }
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 333 of file app.c.
References linear_state::allowoverride, ast_activate_generator(), ast_calloc, ast_config_AST_DATA_DIR, ast_log(), ast_strlen_zero(), linear_state::autoclose, linear_state::fd, and LOG_WARNING.
00334 { 00335 struct linear_state *lin; 00336 char tmpf[256]; 00337 int res = -1; 00338 int autoclose = 0; 00339 if (fd < 0) { 00340 if (ast_strlen_zero(filename)) 00341 return -1; 00342 autoclose = 1; 00343 if (filename[0] == '/') 00344 ast_copy_string(tmpf, filename, sizeof(tmpf)); 00345 else 00346 snprintf(tmpf, sizeof(tmpf), "%s/%s/%s", (char *)ast_config_AST_DATA_DIR, "sounds", filename); 00347 fd = open(tmpf, O_RDONLY); 00348 if (fd < 0){ 00349 ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", tmpf, strerror(errno)); 00350 return -1; 00351 } 00352 } 00353 if ((lin = ast_calloc(1, sizeof(*lin)))) { 00354 lin->fd = fd; 00355 lin->allowoverride = allowoverride; 00356 lin->autoclose = autoclose; 00357 res = ast_activate_generator(chan, &linearstream, lin); 00358 } 00359 return res; 00360 }
enum AST_LOCK_RESULT ast_lock_path | ( | const char * | path | ) |
Lock a filesystem path.
path | the path to be locked |
Definition at line 967 of file app.c.
References AST_LOCK_FAILURE, AST_LOCK_PATH_NOT_FOUND, AST_LOCK_SUCCESS, AST_LOCK_TIMEOUT, ast_log(), ast_random(), LOG_DEBUG, LOG_ERROR, LOG_WARNING, option_debug, and s.
00968 { 00969 char *s; 00970 char *fs; 00971 int res; 00972 int fd; 00973 int lp = strlen(path); 00974 time_t start; 00975 00976 if (!(s = alloca(lp + 10)) || !(fs = alloca(lp + 20))) { 00977 ast_log(LOG_WARNING, "Out of memory!\n"); 00978 return AST_LOCK_FAILURE; 00979 } 00980 00981 snprintf(fs, strlen(path) + 19, "%s/.lock-%08lx", path, ast_random()); 00982 fd = open(fs, O_WRONLY | O_CREAT | O_EXCL, 0600); 00983 if (fd < 0) { 00984 ast_log(LOG_ERROR, "Unable to create lock file '%s': %s\n", path, strerror(errno)); 00985 return AST_LOCK_PATH_NOT_FOUND; 00986 } 00987 close(fd); 00988 00989 snprintf(s, strlen(path) + 9, "%s/.lock", path); 00990 start = time(NULL); 00991 while (((res = link(fs, s)) < 0) && (errno == EEXIST) && (time(NULL) - start < 5)) 00992 usleep(1); 00993 00994 unlink(fs); 00995 00996 if (res) { 00997 ast_log(LOG_WARNING, "Failed to lock path '%s': %s\n", path, strerror(errno)); 00998 return AST_LOCK_TIMEOUT; 00999 } else { 01000 if (option_debug) 01001 ast_log(LOG_DEBUG, "Locked path '%s'\n", path); 01002 return AST_LOCK_SUCCESS; 01003 } 01004 }
int ast_play_and_prepend | ( | struct ast_channel * | chan, | |
char * | playfile, | |||
char * | recordfile, | |||
int | maxtime_sec, | |||
char * | fmt, | |||
int * | duration, | |||
int | beep, | |||
int | silencethreshold, | |||
int | maxsilence_ms | |||
) |
Record a message and prepend the message to the given record file after playing the optional playfile (or a beep), storing the duration in 'duration' and with a maximum
permitted silence time in milliseconds of 'maxsilence' under 'silencethreshold' or use '-1' for either or both parameters for defaults.
Definition at line 759 of file app.c.
References __ast_play_and_record().
00760 { 00761 return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, beep, silencethreshold, maxsilence, NULL, 1, default_acceptdtmf, default_canceldtmf); 00762 }
int ast_play_and_record | ( | struct ast_channel * | chan, | |
const char * | playfile, | |||
const char * | recordfile, | |||
int | maxtime_sec, | |||
const char * | fmt, | |||
int * | duration, | |||
int | silencethreshold, | |||
int | maxsilence_ms, | |||
const char * | path | |||
) |
Record a file for a max amount of time (in seconds), in a given list of formats separated by '|', outputting the duration of the recording, and with a maximum
permitted silence time in milliseconds of 'maxsilence' under 'silencethreshold' or use '-1' for either or both parameters for defaults. calls ast_unlock_path() on 'path' if passed
Definition at line 754 of file app.c.
References __ast_play_and_record().
00755 { 00756 return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, 0, silencethreshold, maxsilence, path, 0, default_acceptdtmf, default_canceldtmf); 00757 }
int ast_play_and_record_full | ( | struct ast_channel * | chan, | |
const char * | playfile, | |||
const char * | recordfile, | |||
int | maxtime_sec, | |||
const char * | fmt, | |||
int * | duration, | |||
int | silencethreshold, | |||
int | maxsilence_ms, | |||
const char * | path, | |||
const char * | acceptdtmf, | |||
const char * | canceldtmf | |||
) |
Definition at line 749 of file app.c.
References __ast_play_and_record(), and S_OR.
00750 { 00751 return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, 0, silencethreshold, maxsilence, path, 0, S_OR(acceptdtmf, default_acceptdtmf), S_OR(canceldtmf, default_canceldtmf)); 00752 }
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 457 of file app.c.
References AST_DIGIT_ANY, ast_stopstream(), ast_streamfile(), and ast_waitstream().
00458 { 00459 int d; 00460 d = ast_streamfile(chan, fn, chan->language); 00461 if (d) 00462 return d; 00463 d = ast_waitstream(chan, AST_DIGIT_ANY); 00464 ast_stopstream(chan); 00465 return d; 00466 }
char* ast_read_textfile | ( | const char * | file | ) |
Read a file into asterisk
Definition at line 1329 of file app.c.
References ast_log(), ast_malloc, free, and LOG_WARNING.
01330 { 01331 int fd; 01332 char *output = NULL; 01333 struct stat filesize; 01334 int count = 0; 01335 int res; 01336 if (stat(filename, &filesize) == -1) { 01337 ast_log(LOG_WARNING, "Error can't stat %s\n", filename); 01338 return NULL; 01339 } 01340 count = filesize.st_size + 1; 01341 fd = open(filename, O_RDONLY); 01342 if (fd < 0) { 01343 ast_log(LOG_WARNING, "Cannot open file '%s' for reading: %s\n", filename, strerror(errno)); 01344 return NULL; 01345 } 01346 if ((output = ast_malloc(count))) { 01347 res = read(fd, output, count - 1); 01348 if (res == count - 1) { 01349 output[res] = '\0'; 01350 } else { 01351 ast_log(LOG_WARNING, "Short read of %s (%d of %d): %s\n", filename, res, count - 1, strerror(errno)); 01352 free(output); 01353 output = NULL; 01354 } 01355 } 01356 close(fd); 01357 return output; 01358 }
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 1028 of file app.c.
References AST_DIGIT_ANY, ast_log(), ast_play_and_record(), ast_play_and_wait(), ast_stream_and_wait(), ast_verbose(), ast_waitfordigit(), LOG_WARNING, maxsilence, silencethreshold, and VERBOSE_PREFIX_3.
01029 { 01030 int silencethreshold = 128; 01031 int maxsilence=0; 01032 int res = 0; 01033 int cmd = 0; 01034 int max_attempts = 3; 01035 int attempts = 0; 01036 int recorded = 0; 01037 int message_exists = 0; 01038 /* Note that urgent and private are for flagging messages as such in the future */ 01039 01040 /* barf if no pointer passed to store duration in */ 01041 if (duration == NULL) { 01042 ast_log(LOG_WARNING, "Error ast_record_review called without duration pointer\n"); 01043 return -1; 01044 } 01045 01046 cmd = '3'; /* Want to start by recording */ 01047 01048 while ((cmd >= 0) && (cmd != 't')) { 01049 switch (cmd) { 01050 case '1': 01051 if (!message_exists) { 01052 /* In this case, 1 is to record a message */ 01053 cmd = '3'; 01054 break; 01055 } else { 01056 ast_stream_and_wait(chan, "vm-msgsaved", chan->language, ""); 01057 cmd = 't'; 01058 return res; 01059 } 01060 case '2': 01061 /* Review */ 01062 ast_verbose(VERBOSE_PREFIX_3 "Reviewing the recording\n"); 01063 cmd = ast_stream_and_wait(chan, recordfile, chan->language, AST_DIGIT_ANY); 01064 break; 01065 case '3': 01066 message_exists = 0; 01067 /* Record */ 01068 if (recorded == 1) 01069 ast_verbose(VERBOSE_PREFIX_3 "Re-recording\n"); 01070 else 01071 ast_verbose(VERBOSE_PREFIX_3 "Recording\n"); 01072 recorded = 1; 01073 cmd = ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, silencethreshold, maxsilence, path); 01074 if (cmd == -1) { 01075 /* User has hung up, no options to give */ 01076 return cmd; 01077 } 01078 if (cmd == '0') { 01079 break; 01080 } else if (cmd == '*') { 01081 break; 01082 } 01083 else { 01084 /* If all is well, a message exists */ 01085 message_exists = 1; 01086 cmd = 0; 01087 } 01088 break; 01089 case '4': 01090 case '5': 01091 case '6': 01092 case '7': 01093 case '8': 01094 case '9': 01095 case '*': 01096 case '#': 01097 cmd = ast_play_and_wait(chan, "vm-sorry"); 01098 break; 01099 default: 01100 if (message_exists) { 01101 cmd = ast_play_and_wait(chan, "vm-review"); 01102 } 01103 else { 01104 cmd = ast_play_and_wait(chan, "vm-torerecord"); 01105 if (!cmd) 01106 cmd = ast_waitfordigit(chan, 600); 01107 } 01108 01109 if (!cmd) 01110 cmd = ast_waitfordigit(chan, 6000); 01111 if (!cmd) { 01112 attempts++; 01113 } 01114 if (attempts > max_attempts) { 01115 cmd = 't'; 01116 } 01117 } 01118 } 01119 if (cmd == 't') 01120 cmd = 0; 01121 return cmd; 01122 }
void ast_replace_sigchld | ( | void | ) |
Replace the SIGCHLD handler.
Normally, Asterisk has a SIGCHLD handler that is cleaning up all zombie processes from forking elsewhere in Asterisk. However, if you want to wait*() on the process to retrieve information about it's exit status, then this signal handler needs to be temporaraly replaced.
Code that executes this function *must* call ast_unreplace_sigchld() after it is finished doing the wait*().
Definition at line 746 of file asterisk.c.
References ast_mutex_lock(), ast_mutex_unlock(), and null_sig_handler().
00747 { 00748 unsigned int level; 00749 00750 ast_mutex_lock(&safe_system_lock); 00751 level = safe_system_level++; 00752 00753 /* only replace the handler if it has not already been done */ 00754 if (level == 0) 00755 safe_system_prev_handler = signal(SIGCHLD, null_sig_handler); 00756 00757 ast_mutex_unlock(&safe_system_lock); 00758 }
int ast_safe_system | ( | const char * | s | ) |
Safely spawn an external program while closing file descriptors
Definition at line 774 of file asterisk.c.
References ast_log(), ast_opt_high_priority, ast_replace_sigchld(), ast_set_priority(), ast_unreplace_sigchld(), and LOG_WARNING.
00775 { 00776 pid_t pid; 00777 #ifdef HAVE_WORKING_FORK 00778 int x; 00779 #endif 00780 int res; 00781 struct rusage rusage; 00782 int status; 00783 00784 #if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK) 00785 ast_replace_sigchld(); 00786 00787 #ifdef HAVE_WORKING_FORK 00788 pid = fork(); 00789 #else 00790 pid = vfork(); 00791 #endif 00792 00793 if (pid == 0) { 00794 #ifdef HAVE_WORKING_FORK 00795 if (ast_opt_high_priority) 00796 ast_set_priority(0); 00797 /* Close file descriptors and launch system command */ 00798 for (x = STDERR_FILENO + 1; x < 4096; x++) 00799 close(x); 00800 #endif 00801 execl("/bin/sh", "/bin/sh", "-c", s, (char *) NULL); 00802 _exit(1); 00803 } else if (pid > 0) { 00804 for(;;) { 00805 res = wait4(pid, &status, 0, &rusage); 00806 if (res > -1) { 00807 res = WIFEXITED(status) ? WEXITSTATUS(status) : -1; 00808 break; 00809 } else if (errno != EINTR) 00810 break; 00811 } 00812 } else { 00813 ast_log(LOG_WARNING, "Fork failed: %s\n", strerror(errno)); 00814 res = -1; 00815 } 00816 00817 ast_unreplace_sigchld(); 00818 #else 00819 res = -1; 00820 #endif 00821 00822 return res; 00823 }
void ast_uninstall_vm_functions | ( | void | ) |
Definition at line 161 of file app.c.
References ast_has_voicemail_func, ast_inboxcount_func, and ast_messagecount_func.
00162 { 00163 ast_has_voicemail_func = NULL; 00164 ast_inboxcount_func = NULL; 00165 ast_messagecount_func = NULL; 00166 }
int ast_unlock_path | ( | const char * | path | ) |
Unlock a path
Definition at line 1006 of file app.c.
References ast_log(), LOG_DEBUG, LOG_ERROR, LOG_WARNING, option_debug, and s.
01007 { 01008 char *s; 01009 int res; 01010 01011 if (!(s = alloca(strlen(path) + 10))) { 01012 ast_log(LOG_WARNING, "Out of memory!\n"); 01013 return -1; 01014 } 01015 01016 snprintf(s, strlen(path) + 9, "%s/%s", path, ".lock"); 01017 01018 if ((res = unlink(s))) 01019 ast_log(LOG_ERROR, "Could not unlock path '%s': %s\n", path, strerror(errno)); 01020 else { 01021 if (option_debug) 01022 ast_log(LOG_DEBUG, "Unlocked path '%s'\n", path); 01023 } 01024 01025 return res; 01026 }
void ast_unreplace_sigchld | ( | void | ) |
Restore the SIGCHLD handler.
This function is called after a call to ast_replace_sigchld. It restores the SIGCHLD handler that cleans up any zombie processes.
Definition at line 760 of file asterisk.c.
References ast_mutex_lock(), and ast_mutex_unlock().
00761 { 00762 unsigned int level; 00763 00764 ast_mutex_lock(&safe_system_lock); 00765 level = --safe_system_level; 00766 00767 /* only restore the handler if we are the last one */ 00768 if (level == 0) 00769 signal(SIGCHLD, safe_system_prev_handler); 00770 00771 ast_mutex_unlock(&safe_system_lock); 00772 }