Wed Jan 8 2020 09:49:52

Asterisk developer's documentation


app.h File Reference

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

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_app_stack_funcs
 Stack applications callback functions. More...
 
struct  ast_ivr_menu
 
struct  ast_ivr_option
 

Macros

#define AST_APP_ARG(name)   char *name
 Define an application argument. More...
 
#define AST_APP_OPTION(option, flagno)   [option] = { .flag = flagno }
 Declares an application option that does not accept an argument. More...
 
#define AST_APP_OPTION_ARG(option, flagno, argno)   [option] = { .flag = flagno, .arg_index = argno + 1 }
 Declares an application option that accepts an argument. More...
 
#define AST_APP_OPTIONS(holder, options...)   static const struct ast_app_option holder[128] = options
 Declares an array of options for an application. More...
 
#define ast_app_separate_args(a, b, c, d)   __ast_app_separate_args(a,b,1,c,d)
 
#define AST_DECLARE_APP_ARGS(name, arglist)   AST_DEFINE_APP_ARGS_TYPE(, arglist) name = { 0, }
 Declare a structure to hold an application's arguments. More...
 
#define AST_DEFINE_APP_ARGS_TYPE(type, arglist)
 Define a structure type to hold an application's arguments. More...
 
#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, 1, args.argv, ((sizeof(args) - offsetof(typeof(args), argv)) / sizeof(args.argv[0])))
 Performs the 'nonstandard' argument separation process for an application. More...
 
#define AST_NONSTANDARD_RAW_ARGS(args, parse, sep)   args.argc = __ast_app_separate_args(parse, sep, 0, args.argv, ((sizeof(args) - offsetof(typeof(args), argv)) / sizeof(args.argv[0])))
 
#define AST_STANDARD_APP_ARGS(args, parse)   args.argc = __ast_app_separate_args(parse, ',', 1, args.argv, ((sizeof(args) - offsetof(typeof(args), argv)) / sizeof(args.argv[0])))
 Performs the 'standard' argument separation process for an application. More...
 
#define AST_STANDARD_RAW_ARGS(args, parse)   args.argc = __ast_app_separate_args(parse, ',', 0, args.argv, ((sizeof(args) - offsetof(typeof(args), argv)) / sizeof(args.argv[0])))
 
#define BEGIN_OPTIONS   {
 
#define END_OPTIONS   }
 

Typedefs

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

Enumerations

enum  ast_getdata_result {
  AST_GETDATA_FAILED = -1, AST_GETDATA_COMPLETE = 0, AST_GETDATA_TIMEOUT = 1, AST_GETDATA_INTERRUPTED = 2,
  AST_GETDATA_EMPTY_END_TERMINATED = 3
}
 
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 }
 
enum  AST_LOCK_TYPE { AST_LOCK_TYPE_LOCKFILE = 0, AST_LOCK_TYPE_FLOCK = 1 }
 Type of locking to use in ast_lock_path / ast_unlock_path. More...
 
enum  ast_timelen { TIMELEN_HOURS, TIMELEN_MINUTES, TIMELEN_SECONDS, TIMELEN_MILLISECONDS }
 

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. More...
 
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. More...
 
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. More...
 
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. More...
 
const char * ast_app_expand_sub_args (struct ast_channel *chan, const char *args)
 Add missing context/exten to subroutine argument string. More...
 
int ast_app_getdata (struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout)
 Plays a stream and gets DTMF data from a channel. More...
 
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. More...
 
int ast_app_group_discard (struct ast_channel *chan)
 Discard all group counting for a channel. More...
 
int ast_app_group_get_count (const char *group, const char *category)
 Get the current channel count of the specified group and category. More...
 
struct ast_group_infoast_app_group_list_head (void)
 Get the head of the group count list. More...
 
int ast_app_group_list_rdlock (void)
 Read Lock the group count list. More...
 
int ast_app_group_list_unlock (void)
 Unlock the group count list. More...
 
int ast_app_group_list_wrlock (void)
 Write Lock the group count list. More...
 
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. More...
 
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. More...
 
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. More...
 
int ast_app_group_update (struct ast_channel *oldchan, struct ast_channel *newchan)
 Update all group counting for a channel to a new one. More...
 
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. More...
 
int ast_app_inboxcount (const char *mailbox, int *newmsgs, int *oldmsgs)
 Determine number of new/old messages in a mailbox. More...
 
int ast_app_inboxcount2 (const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
 Determine number of urgent/new/old messages in a mailbox. More...
 
int ast_app_messagecount (const char *context, const char *mailbox, const char *folder)
 Check number of messages in a given context, mailbox, and folder. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
void ast_close_fds_above_n (int n)
 Common routine for child processes, to close all fds prior to exec(2) More...
 
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. More...
 
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. More...
 
int ast_get_encoded_char (const char *stream, char *result, size_t *consumed)
 Decode an encoded control or extended ASCII character. More...
 
char * ast_get_encoded_str (const char *stream, char *result, size_t result_len)
 Decode a stream of encoded control or extended ASCII characters. More...
 
void ast_install_stack_functions (const struct ast_app_stack_funcs *funcs)
 Set stack application function callbacks. More...
 
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. More...
 
int ast_ivr_menu_run (struct ast_channel *c, struct ast_ivr_menu *menu, void *cbdata)
 Runs an IVR menu. More...
 
int ast_linear_stream (struct ast_channel *chan, const char *filename, int fd, int allowoverride)
 Stream a filename (or file descriptor) as a generator. More...
 
enum AST_LOCK_RESULT ast_lock_path (const char *path)
 Lock a filesystem path. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
char * ast_read_textfile (const char *file)
 Read a file into asterisk. More...
 
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. More...
 
void ast_replace_sigchld (void)
 Replace the SIGCHLD handler. More...
 
int ast_safe_fork (int stop_reaper)
 Common routine to safely fork without a chance of a signal handler firing badly in the child. More...
 
void ast_safe_fork_cleanup (void)
 Common routine to cleanup after fork'ed process is complete (if reaping was stopped) More...
 
int ast_safe_system (const char *s)
 Safely spawn an external program while closing file descriptors. More...
 
void ast_set_lock_type (enum AST_LOCK_TYPE type)
 Set the type of locks used by ast_lock_path() More...
 
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. More...
 
 AST_THREADSTORAGE_EXTERNAL (ast_str_thread_global_buf)
 
void ast_uninstall_vm_functions (void)
 
int ast_unlock_path (const char *path)
 Unlock a path. More...
 
void ast_unreplace_sigchld (void)
 Restore the SIGCHLD handler. More...
 

Detailed Description

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

Definition in file app.h.

Macro Definition Documentation

#define AST_APP_ARG (   name)    char *name

Define an application argument.

Parameters
nameThe name of the argument

Definition at line 555 of file app.h.

Referenced by acf_curl_helper(), acf_if(), acf_isexten_exec(), acf_jabberreceive_read(), acf_jabberstatus_read(), acf_mailbox_exists(), acf_meetme_info(), acf_odbc_read(), acf_odbc_write(), acf_rand_exec(), acf_sprintf(), acf_strftime(), acf_strptime(), acf_transaction_read(), acf_transaction_write(), acf_version_exec(), acf_vmcount_exec(), action_status(), add_agent(), admin_exec(), aelsub_exec(), aes_helper(), agi_exec_full(), aji_join_exec(), aji_leave_exec(), aji_send_exec(), aji_sendgroup_exec(), aji_status_exec(), app_exec(), aqm_exec(), array(), ast_eivr_senddtmf(), ast_queue_log(), asyncgoto_exec(), auth_exec(), background_detect_exec(), bridge_exec(), calendar_query_exec(), calendar_query_result_exec(), calendar_write_exec(), callerid_read(), cdr_read(), cdr_write(), celgenuserevent_exec(), chanavail_exec(), channel_admin_exec(), chanspy_exec(), cli_odbc_read(), cli_odbc_write(), conf_exec(), confbridge_exec(), config_function_read(), controlplayback_exec(), count_exec(), create_addr(), cut_internal(), dahdi_accept_r2_call_exec(), dahdi_send_callrerouting_facility_exec(), determine_starting_point(), dial_exec_full(), dialgroup_write(), dictate_exec(), directory_exec(), disa_exec(), dundi_query_read(), dundi_result_read(), dundifunc_read(), enable_jack_hook(), enum_query_read(), enum_result_read(), execif_exec(), extenspy_exec(), festival_exec(), file_count_line(), file_read(), file_write(), filter(), find_conf(), find_realtime_gw(), find_table_cb(), forkcdr_exec(), func_header_read(), function_agent(), function_db_delete(), function_db_exists(), function_db_read(), function_db_write(), function_enum(), function_fieldnum_helper(), function_fieldqty_helper(), function_realtime_read(), function_realtime_readdestroy(), function_realtime_store(), function_realtime_write(), function_txtcidname(), gosub_exec(), gosubif_exec(), hash_read(), hash_write(), hint_read(), iconv_read(), import_helper(), init_acf_query(), isAnsweringMachine(), isexten_function_read(), listfilter(), load_values_config(), log_exec(), login_exec(), man_do_variable_value(), math(), misdn_call(), misdn_check_l2l1(), misdn_facility_exec(), misdn_request(), mixmonitor_exec(), my_pri_make_cc_dialstring(), originate_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), oss_call(), oss_request(), page_exec(), parkandannounce_exec(), parked_call_exec(), pbx_builtin_answer(), pbx_builtin_background(), pbx_builtin_saydate(), pbx_builtin_saytime(), pbx_builtin_setvar_multiple(), pbx_builtin_waitexten(), peek_read(), pickupchan_exec(), play_moh_exec(), playback_exec(), pqm_exec(), privacy_exec(), process_applicationmap_line(), ql_exec(), queue_exec(), queue_function_memberpenalty_read(), queue_function_memberpenalty_write(), queue_function_queuememberpaused(), queue_function_queuememberstatus(), rcvfax_exec(), read_exec(), readexten_exec(), realtimefield_read(), receivefax_exec(), record_exec(), reg_source_db(), regex(), reload_single_member(), replace(), retrydial_exec(), rqm_exec(), saycountedadj_exec(), saycountednoun_exec(), sayunixtime_exec(), senddtmf_exec(), sendfax_exec(), sendurl_exec(), shared_read(), shared_write(), shift_pop(), sig_pri_call(), sig_pri_extract_called_num_subaddr(), sip_acf_channel_read(), sip_parse_register_line(), sip_request_call(), sla_trunk_exec(), smdi_msg_read(), smdi_msg_retrieve_read(), sms_exec(), sndfax_exec(), softhangup_exec(), speech_background(), speech_load(), srv_result_read(), stackpeek_read(), start_moh_exec(), start_monitor_exec(), transfer_exec(), unshift_push(), upqm_exec(), userevent_exec(), verbose_exec(), vm_box_exists(), vm_check_password_shell(), vm_exec(), vm_execmain(), volume_write(), and zapateller_exec().

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

Declares an application option that does not accept an argument.

Parameters
optionThe single character representing the option
flagnoThe flag index to be set if this option is present
See Also
AST_APP_OPTIONS, ast_app_parse_options

Definition at line 721 of file app.h.

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

Declares an application option that accepts an argument.

Parameters
optionThe single character representing the option
flagnoThe flag index to be set if this option is present
argnoThe index into the argument array where the argument should be placed
See Also
AST_APP_OPTIONS, ast_app_parse_options

Definition at line 732 of file app.h.

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

Declares an array of options for an application.

Parameters
holderThe name of the array to be created
optionsThe actual options to be placed into the array
See Also
ast_app_parse_options

This macro declares a 'static const' array of struct ast_option elements to hold the list of available options for an application. Each option must be declared using either the AST_APP_OPTION() or AST_APP_OPTION_ARG() macros.

Example usage:

enum my_app_option_flags {
OPT_JUMP = (1 << 0),
OPT_BLAH = (1 << 1),
OPT_BLORT = (1 << 2),
};
enum my_app_option_args {
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
};
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_app_parse_options(my_app_options, &opts, opt_args, options)) {
return -1;
}
}

Definition at line 712 of file app.h.

#define ast_app_separate_args (   a,
  b,
  c,
 
)    __ast_app_separate_args(a,b,1,c,d)

Definition at line 640 of file app.h.

#define AST_DECLARE_APP_ARGS (   name,
  arglist 
)    AST_DEFINE_APP_ARGS_TYPE(, arglist) name = { 0, }

Declare a structure to hold an application's arguments.

Parameters
nameThe name of the structure
arglistThe list of arguments, defined using AST_APP_ARG

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

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

Definition at line 572 of file app.h.

Referenced by acf_curl_helper(), acf_if(), acf_isexten_exec(), acf_jabberreceive_read(), acf_jabberstatus_read(), acf_mailbox_exists(), acf_meetme_info(), acf_odbc_read(), acf_odbc_write(), acf_rand_exec(), acf_sprintf(), acf_strftime(), acf_strptime(), acf_transaction_read(), acf_transaction_write(), acf_version_exec(), acf_vmcount_exec(), action_status(), add_agent(), admin_exec(), aelsub_exec(), aes_helper(), agi_exec_full(), aji_join_exec(), aji_leave_exec(), aji_send_exec(), aji_sendgroup_exec(), aji_status_exec(), app_exec(), aqm_exec(), array(), ast_eivr_senddtmf(), ast_queue_log(), asyncgoto_exec(), auth_exec(), background_detect_exec(), bridge_exec(), calendar_query_exec(), calendar_query_result_exec(), calendar_write_exec(), callerid_read(), cdr_read(), cdr_write(), celgenuserevent_exec(), chanavail_exec(), channel_admin_exec(), chanspy_exec(), cli_odbc_read(), cli_odbc_write(), conf_exec(), confbridge_exec(), config_function_read(), controlplayback_exec(), count_exec(), create_addr(), cut_internal(), dahdi_accept_r2_call_exec(), dahdi_send_callrerouting_facility_exec(), determine_starting_point(), dial_exec_full(), dialgroup_write(), dictate_exec(), directory_exec(), disa_exec(), dundi_query_read(), dundi_result_read(), dundifunc_read(), enable_jack_hook(), enum_query_read(), enum_result_read(), execif_exec(), extenspy_exec(), festival_exec(), file_count_line(), file_read(), file_write(), filter(), find_conf(), find_realtime_gw(), find_table_cb(), forkcdr_exec(), func_header_read(), function_agent(), function_db_delete(), function_db_exists(), function_db_read(), function_db_write(), function_enum(), function_fieldnum_helper(), function_fieldqty_helper(), function_realtime_read(), function_realtime_readdestroy(), function_realtime_store(), function_realtime_write(), function_txtcidname(), gosub_exec(), gosubif_exec(), hash_read(), hash_write(), hint_read(), iconv_read(), import_helper(), init_acf_query(), isAnsweringMachine(), isexten_function_read(), listfilter(), load_values_config(), log_exec(), login_exec(), man_do_variable_value(), math(), misdn_call(), misdn_check_l2l1(), misdn_facility_exec(), misdn_request(), mixmonitor_exec(), my_pri_make_cc_dialstring(), originate_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), oss_call(), oss_request(), page_exec(), parkandannounce_exec(), parked_call_exec(), pbx_builtin_answer(), pbx_builtin_background(), pbx_builtin_saydate(), pbx_builtin_saytime(), pbx_builtin_setvar_multiple(), pbx_builtin_waitexten(), peek_read(), pickupchan_exec(), play_moh_exec(), playback_exec(), pqm_exec(), privacy_exec(), process_applicationmap_line(), ql_exec(), queue_exec(), queue_function_memberpenalty_read(), queue_function_memberpenalty_write(), queue_function_queuememberpaused(), queue_function_queuememberstatus(), rcvfax_exec(), read_exec(), readexten_exec(), realtimefield_read(), receivefax_exec(), record_exec(), reg_source_db(), regex(), reload_single_member(), replace(), retrydial_exec(), rqm_exec(), saycountedadj_exec(), saycountednoun_exec(), sayunixtime_exec(), senddtmf_exec(), sendfax_exec(), sendurl_exec(), shared_read(), shared_write(), shift_pop(), sig_pri_call(), sig_pri_extract_called_num_subaddr(), sip_acf_channel_read(), sip_parse_register_line(), sip_request_call(), sla_trunk_exec(), smdi_msg_read(), smdi_msg_retrieve_read(), sms_exec(), sndfax_exec(), softhangup_exec(), speech_background(), speech_load(), srv_result_read(), stackpeek_read(), start_moh_exec(), start_monitor_exec(), transfer_exec(), unshift_push(), upqm_exec(), userevent_exec(), verbose_exec(), vm_box_exists(), vm_check_password_shell(), vm_exec(), vm_execmain(), volume_write(), and zapateller_exec().

#define AST_DEFINE_APP_ARGS_TYPE (   type,
  arglist 
)
Value:
struct type { \
unsigned int argc; \
char *argv[0]; \
arglist \
}
static const char type[]
Definition: chan_nbs.c:57

Define a structure type to hold an application's arguments.

Parameters
typeThe name of the structure type
arglistThe list of arguments, defined using AST_APP_ARG

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

Note
This defines a structure type, but does not declare an instance of the structure. That must be done separately.

Definition at line 588 of file app.h.

#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 }
unsigned int flags
Definition: app.h:77
char * title
Definition: app.h:76

Definition at line 83 of file app.h.

#define AST_IVR_FLAG_AUTORESTART   (1 << 0)

Definition at line 81 of file app.h.

#define AST_NONSTANDARD_APP_ARGS (   args,
  parse,
  sep 
)    args.argc = __ast_app_separate_args(parse, sep, 1, args.argv, ((sizeof(args) - offsetof(typeof(args), argv)) / sizeof(args.argv[0])))

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

Parameters
argsAn argument structure defined using AST_DECLARE_APP_ARGS
parseA modifiable buffer containing the input to be parsed
sepA nonstandard separator character

This function will separate the input string using the nonstandard argument separator character and fill in the provided structure, including the argc argument counter field.

Definition at line 619 of file app.h.

Referenced by acf_if(), acf_jabberreceive_read(), acf_jabberstatus_read(), acf_mailbox_exists(), aji_status_exec(), ast_queue_log(), callerid_read(), callerid_write(), connectedline_read(), connectedline_write(), determine_starting_point(), dialgroup_write(), function_agent(), function_db_delete(), function_db_exists(), function_db_read(), function_db_write(), misdn_call(), misdn_request(), my_pri_make_cc_dialstring(), oss_call(), oss_request(), pbx_builtin_setvar_multiple(), record_exec(), redirecting_read(), redirecting_write(), regex(), sig_pri_call(), sig_pri_extract_called_num_subaddr(), sip_request_call(), and vm_check_password_shell().

#define AST_NONSTANDARD_RAW_ARGS (   args,
  parse,
  sep 
)    args.argc = __ast_app_separate_args(parse, sep, 0, args.argv, ((sizeof(args) - offsetof(typeof(args), argv)) / sizeof(args.argv[0])))

Definition at line 621 of file app.h.

Referenced by create_addr(), execif_exec(), gosubif_exec(), reg_source_db(), and sip_parse_register_line().

#define AST_STANDARD_APP_ARGS (   args,
  parse 
)    args.argc = __ast_app_separate_args(parse, ',', 1, args.argv, ((sizeof(args) - offsetof(typeof(args), argv)) / sizeof(args.argv[0])))

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

Parameters
argsAn argument structure defined using AST_DECLARE_APP_ARGS
parseA modifiable buffer containing the input to be parsed

This function will separate the input string using the standard argument separator character ',' and fill in the provided structure, including the argc argument counter field.

Definition at line 604 of file app.h.

Referenced by acf_curl_helper(), acf_isexten_exec(), acf_jabberreceive_read(), acf_jabberstatus_read(), acf_meetme_info(), acf_odbc_read(), acf_odbc_write(), acf_rand_exec(), acf_sprintf(), acf_strftime(), acf_strptime(), acf_transaction_read(), acf_transaction_write(), acf_version_exec(), acf_vmcount_exec(), action_status(), add_agent(), admin_exec(), aes_helper(), agi_exec_full(), aji_join_exec(), aji_leave_exec(), aji_send_exec(), aji_sendgroup_exec(), aji_status_exec(), app_exec(), aqm_exec(), array(), ast_eivr_senddtmf(), ast_masq_park_call_exten(), ast_park_call_exten(), asyncgoto_exec(), auth_exec(), background_detect_exec(), bridge_exec(), calendar_query_exec(), calendar_query_result_exec(), calendar_write_exec(), callerid_read(), callerid_write(), cdr_read(), cdr_write(), celgenuserevent_exec(), chanavail_exec(), channel_admin_exec(), chanspy_exec(), cli_odbc_read(), cli_odbc_write(), conf_exec(), confbridge_exec(), config_function_read(), connectedline_write(), controlplayback_exec(), count_exec(), cut_internal(), dahdi_accept_r2_call_exec(), dahdi_send_callrerouting_facility_exec(), dial_exec_full(), dialgroup_write(), dictate_exec(), directory_exec(), disa_exec(), dundi_query_read(), dundi_result_read(), dundifunc_read(), enable_jack_hook(), enum_query_read(), enum_result_read(), execif_exec(), extenspy_exec(), festival_exec(), file_count_line(), file_read(), file_write(), find_conf(), find_realtime_gw(), find_table_cb(), forkcdr_exec(), func_header_read(), function_enum(), function_fieldnum_helper(), function_fieldqty_helper(), function_realtime_read(), function_realtime_readdestroy(), function_realtime_store(), function_realtime_write(), function_txtcidname(), hash_read(), hash_write(), hint_read(), iconv_read(), import_helper(), init_acf_query(), isAnsweringMachine(), isexten_function_read(), listfilter(), log_exec(), login_exec(), man_do_variable_value(), math(), misdn_check_l2l1(), misdn_facility_exec(), mixmonitor_exec(), originate_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), page_exec(), park_call_exec(), parkandannounce_exec(), parked_call_exec(), pbx_builtin_answer(), pbx_builtin_background(), pbx_builtin_saydate(), pbx_builtin_saytime(), pbx_builtin_setvar_multiple(), pbx_builtin_waitexten(), pickupchan_exec(), play_moh_exec(), playback_exec(), pqm_exec(), privacy_exec(), process_applicationmap_line(), ql_exec(), queue_exec(), queue_function_memberpenalty_read(), queue_function_memberpenalty_write(), queue_function_queuememberpaused(), queue_function_queuememberstatus(), rcvfax_exec(), read_exec(), readexten_exec(), realtimefield_read(), receivefax_exec(), record_exec(), redirecting_write(), reload_single_member(), replace(), retrydial_exec(), rqm_exec(), saycountedadj_exec(), saycountednoun_exec(), sayunixtime_exec(), senddtmf_exec(), sendfax_exec(), sendurl_exec(), shared_read(), shared_write(), shift_pop(), sip_acf_channel_read(), sla_trunk_exec(), smdi_msg_read(), smdi_msg_retrieve_read(), sms_exec(), sndfax_exec(), softhangup_exec(), speech_background(), speech_load(), srv_result_read(), stackpeek_read(), start_moh_exec(), start_monitor_exec(), transfer_exec(), unshift_push(), upqm_exec(), userevent_exec(), verbose_exec(), vm_box_exists(), vm_exec(), vm_execmain(), volume_write(), xfer_park_call_helper(), and zapateller_exec().

#define AST_STANDARD_RAW_ARGS (   args,
  parse 
)    args.argc = __ast_app_separate_args(parse, ',', 0, args.argv, ((sizeof(args) - offsetof(typeof(args), argv)) / sizeof(args.argv[0])))

Definition at line 606 of file app.h.

Referenced by aelsub_exec(), filter(), gosub_exec(), load_values_config(), and peek_read().

#define BEGIN_OPTIONS   {

Definition at line 662 of file app.h.

#define END_OPTIONS   }

Definition at line 663 of file app.h.

Typedef Documentation

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

Callback function for IVR.

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

Definition at line 42 of file app.h.

Enumeration Type Documentation

Enumerator
AST_GETDATA_FAILED 
AST_GETDATA_COMPLETE 
AST_GETDATA_TIMEOUT 
AST_GETDATA_INTERRUPTED 
AST_GETDATA_EMPTY_END_TERMINATED 

indicates a user terminated empty string rather than an empty string resulting from a timeout or other factors

Definition at line 477 of file app.h.

477  {
478  AST_GETDATA_FAILED = -1,
482  /*! indicates a user terminated empty string rather than an empty string resulting
483  * from a timeout or other factors */
485 };
Enumerator
AST_ACTION_UPONE 

adata is unused

AST_ACTION_EXIT 

adata is the return value for ast_ivr_menu_run if channel was not hungup

AST_ACTION_CALLBACK 

adata is an ast_ivr_callback

AST_ACTION_PLAYBACK 

adata is file to play

AST_ACTION_BACKGROUND 

adata is file to play

AST_ACTION_PLAYLIST 

adata is list of files, separated by ; to play

AST_ACTION_MENU 

adata is a pointer to an ast_ivr_menu

AST_ACTION_REPEAT 

adata is max # of repeats, cast to a pointer

AST_ACTION_RESTART 

adata is like repeat, but resets repeats to 0

AST_ACTION_TRANSFER 

adata is a string with exten

[@context]
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 44 of file app.h.

44  {
45  AST_ACTION_UPONE, /*!< adata is unused */
46  AST_ACTION_EXIT, /*!< adata is the return value for ast_ivr_menu_run if channel was not hungup */
47  AST_ACTION_CALLBACK, /*!< adata is an ast_ivr_callback */
48  AST_ACTION_PLAYBACK, /*!< adata is file to play */
49  AST_ACTION_BACKGROUND, /*!< adata is file to play */
50  AST_ACTION_PLAYLIST, /*!< adata is list of files, separated by ; to play */
51  AST_ACTION_MENU, /*!< adata is a pointer to an ast_ivr_menu */
52  AST_ACTION_REPEAT, /*!< adata is max # of repeats, cast to a pointer */
53  AST_ACTION_RESTART, /*!< adata is like repeat, but resets repeats to 0 */
54  AST_ACTION_TRANSFER, /*!< adata is a string with exten\verbatim[@context]\endverbatim */
55  AST_ACTION_WAITOPTION, /*!< adata is a timeout, or 0 for defaults */
56  AST_ACTION_NOOP, /*!< adata is unused */
57  AST_ACTION_BACKLIST, /*!< adata is list of files separated by ; allows interruption */
ast_ivr_action
Definition: app.h:44
Enumerator
AST_LOCK_SUCCESS 
AST_LOCK_TIMEOUT 
AST_LOCK_PATH_NOT_FOUND 
AST_LOCK_FAILURE 

Definition at line 487 of file app.h.

487  {
488  AST_LOCK_SUCCESS = 0,
489  AST_LOCK_TIMEOUT = -1,
491  AST_LOCK_FAILURE = -3,
492 };

Type of locking to use in ast_lock_path / ast_unlock_path.

Enumerator
AST_LOCK_TYPE_LOCKFILE 
AST_LOCK_TYPE_FLOCK 

Definition at line 495 of file app.h.

495  {
498 };
Enumerator
TIMELEN_HOURS 
TIMELEN_MINUTES 
TIMELEN_SECONDS 
TIMELEN_MILLISECONDS 

Definition at line 87 of file app.h.

Function Documentation

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.

Parameters
bufThe string to be parsed (this must be a writable copy, as it will be modified)
delimThe character to be used to delimit arguments
remove_charsRemove backslashes and quote characters, while parsing
arrayAn array of 'char *' to be filled in with pointers to the found arguments
arraylenThe number of elements in the array (i.e. the number of arguments you will accept)

Note: if there are more arguments in the string than the array will hold, the last element of the array will contain the remaining arguments, not separated.

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

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

Definition at line 1388 of file app.c.

References paren, and quote().

Referenced by ast_app_separate_args().

1389 {
1390  int argc;
1391  char *scan, *wasdelim = NULL;
1392  int paren = 0, quote = 0, bracket = 0;
1393 
1394  if (!array || !arraylen) {
1395  return 0;
1396  }
1397 
1398  memset(array, 0, arraylen * sizeof(*array));
1399 
1400  if (!buf) {
1401  return 0;
1402  }
1403 
1404  scan = buf;
1405 
1406  for (argc = 0; *scan && (argc < arraylen - 1); argc++) {
1407  array[argc] = scan;
1408  for (; *scan; scan++) {
1409  if (*scan == '(') {
1410  paren++;
1411  } else if (*scan == ')') {
1412  if (paren) {
1413  paren--;
1414  }
1415  } else if (*scan == '[') {
1416  bracket++;
1417  } else if (*scan == ']') {
1418  if (bracket) {
1419  bracket--;
1420  }
1421  } else if (*scan == '"' && delim != '"') {
1422  quote = quote ? 0 : 1;
1423  if (remove_chars) {
1424  /* Remove quote character from argument */
1425  memmove(scan, scan + 1, strlen(scan));
1426  scan--;
1427  }
1428  } else if (*scan == '\\') {
1429  if (remove_chars) {
1430  /* Literal character, don't parse */
1431  memmove(scan, scan + 1, strlen(scan));
1432  } else {
1433  scan++;
1434  }
1435  } else if ((*scan == delim) && !paren && !quote && !bracket) {
1436  wasdelim = scan;
1437  *scan++ = '\0';
1438  break;
1439  }
1440  }
1441  }
1442 
1443  /* If the last character in the original string was the delimiter, then
1444  * there is one additional argument. */
1445  if (*scan || (scan > buf && (scan - 1) == wasdelim)) {
1446  array[argc++] = scan;
1447  }
1448 
1449  return argc;
1450 }
static int quote(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int array(struct ast_channel *chan, const char *cmd, char *var, const char *value)
Definition: func_strings.c:913
#define paren
Definition: ael_lex.c:958
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.

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

Present a dialtone and collect a certain length extension.

Parameters
chanstruct.
context
collect
size
maxlen
timeouttimeout in milliseconds
Returns
0 if extension does not exist, 1 if extension exists

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().

121 {
122  struct ast_tone_zone_sound *ts;
123  int res = 0, x = 0;
124 
125  if (maxlen > size) {
126  maxlen = size;
127  }
128 
129  if (!timeout) {
130  if (chan->pbx && chan->pbx->dtimeoutms) {
131  timeout = chan->pbx->dtimeoutms;
132  } else {
133  timeout = 5000;
134  }
135  }
136 
137  if ((ts = ast_get_indication_tone(chan->zone, "dial"))) {
138  res = ast_playtones_start(chan, 0, ts->data, 0);
139  ts = ast_tone_zone_sound_unref(ts);
140  } else {
141  ast_log(LOG_NOTICE, "Huh....? no dial for indications?\n");
142  }
143 
144  for (x = strlen(collect); x < maxlen; ) {
145  res = ast_waitfordigit(chan, timeout);
146  if (!ast_ignore_pattern(context, collect)) {
147  ast_playtones_stop(chan);
148  }
149  if (res < 1) {
150  break;
151  }
152  if (res == '#') {
153  break;
154  }
155  collect[x++] = res;
156  if (!ast_matchmore_extension(chan, context, collect, 1,
157  S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL))) {
158  break;
159  }
160  }
161 
162  if (res >= 0) {
163  res = ast_exists_extension(chan, context, collect, 1,
164  S_COR(chan->caller.id.number.valid, chan->caller.id.number.str, NULL)) ? 1 : 0;
165  }
166 
167  return res;
168 }
int ast_matchmore_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks to see if adding anything to this extension might match something. (exists ^ canmatch) ...
Definition: pbx.c:5420
char * str
Subscriber phone number (Malloced)
Definition: channel.h:241
struct ast_party_caller caller
Channel Caller ID information.
Definition: channel.h:804
struct ast_tone_zone * zone
Definition: channel.h:767
int ast_ignore_pattern(const char *context, const char *pattern)
Checks to see if a number should be ignored.
Definition: pbx.c:8650
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
Definition: indications.c:411
struct ast_party_id id
Caller party ID.
Definition: channel.h:370
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:83
static struct ast_tone_zone_sound * ast_tone_zone_sound_unref(struct ast_tone_zone_sound *ts)
Release a reference to an ast_tone_zone_sound.
Definition: indications.h:226
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition: pbx.c:5400
Description of a tone.
Definition: indications.h:36
struct ast_tone_zone_sound * ast_get_indication_tone(const struct ast_tone_zone *zone, const char *indication)
Locate a tone zone sound.
Definition: indications.c:473
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition: channel.c:3552
int dtimeoutms
Definition: pbx.h:180
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
Definition: indications.c:319
const char * data
Description of a tone.
Definition: indications.h:53
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
unsigned char valid
TRUE if the number information is valid/present.
Definition: channel.h:247
struct ast_pbx * pbx
Definition: channel.h:761
struct ast_party_number number
Subscriber phone number.
Definition: channel.h:292
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.

Since
1.8.30.0
11.0

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.

Note
Absolutely NO channel locks should be held before calling this function.
Parameters
autoservice_chanA channel to place into autoservice while the macro is run
macro_chanChannel to execute macro on.
macro_argsMacro application argument string.
Return values
0success
-1on 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, ast_channel::name, pbx_exec(), pbx_findapp(), and ast_channel::priority.

Referenced by ast_app_run_macro(), and feature_exec_app().

255 {
256  struct ast_app *macro_app;
257  int res;
258 
259  macro_app = pbx_findapp("Macro");
260  if (!macro_app) {
262  "Cannot run 'Macro(%s)'. The application is not available.\n", macro_args);
263  return -1;
264  }
265  if (autoservice_chan) {
266  ast_autoservice_start(autoservice_chan);
267  }
268 
269  ast_debug(4, "%s Original location: %s,%s,%d\n", macro_chan->name,
270  macro_chan->context, macro_chan->exten, macro_chan->priority);
271 
272  res = pbx_exec(macro_chan, macro_app, macro_args);
273  ast_debug(4, "Macro exited with status %d\n", res);
274 
275  /*
276  * Assume anything negative from Macro is an error.
277  * Anything else is success.
278  */
279  if (res < 0) {
280  res = -1;
281  } else {
282  res = 0;
283  }
284 
285  ast_debug(4, "%s Ending location: %s,%s,%d\n", macro_chan->name,
286  macro_chan->context, macro_chan->exten, macro_chan->priority);
287 
288  if (autoservice_chan) {
289  ast_autoservice_stop(autoservice_chan);
290  }
291  return res;
292 }
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
Definition: autoservice.c:179
struct ast_app * pbx_findapp(const char *app)
Look up an application.
Definition: pbx.c:1537
int priority
Definition: channel.h:841
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
Definition: pbx.c:1497
char context[AST_MAX_CONTEXT]
Definition: channel.h:868
#define LOG_WARNING
Definition: logger.h:144
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
Definition: autoservice.c:238
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
ast_app: A registered application
Definition: pbx.c:971
char exten[AST_MAX_EXTENSION]
Definition: channel.h:869
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.

Since
1.8.30.0
11

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.

Note
Absolutely NO channel locks should be held before calling this function.
Parameters
autoservice_chanA channel to place into autoservice while the subroutine is run
sub_chanChannel to execute subroutine on.
sub_argsGosub application argument string.
ignore_hangupTRUE if a hangup does not stop execution of the routine.
Return values
0success
-1on 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().

344 {
345  const struct ast_app_stack_funcs *funcs;
346  int res;
347 
348  funcs = app_stack_callbacks;
349  if (!funcs || !funcs->run_sub) {
351  "Cannot run 'Gosub(%s)'. The app_stack module is not available.\n",
352  sub_args);
353  return -1;
354  }
355  ast_module_ref(funcs->module);
356 
357  if (autoservice_chan) {
358  ast_autoservice_start(autoservice_chan);
359  }
360 
361  res = funcs->run_sub(sub_chan, sub_args, ignore_hangup);
362  ast_module_unref(funcs->module);
363 
364  if (autoservice_chan) {
365  ast_autoservice_stop(autoservice_chan);
366  }
367  return res;
368 }
void ast_module_unref(struct ast_module *)
Definition: loader.c:1312
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
Definition: autoservice.c:179
#define LOG_WARNING
Definition: logger.h:144
static struct ast_app_stack_funcs * app_stack_callbacks
Definition: app.c:317
int(* run_sub)(struct ast_channel *chan, const char *args, int ignore_hangup)
Callback for the routine to run a subroutine on a channel.
Definition: app.h:184
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
Definition: autoservice.c:238
void * module
Definition: app.h:170
Stack applications callback functions.
Definition: app.h:165
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
struct ast_module * ast_module_ref(struct ast_module *)
Definition: loader.c:1300
const char* ast_app_expand_sub_args ( struct ast_channel chan,
const char *  args 
)

Add missing context/exten to subroutine argument string.

Since
1.8.30.0
Parameters
chanChannel to obtain context/exten.
argsGosub application argument string.

Fills in the optional context and exten from the given channel.

Return values
New-argsGosub argument string on success. Must be freed.
NULLon 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.

325 {
326  const struct ast_app_stack_funcs *funcs;
327  const char *new_args;
328 
329  funcs = app_stack_callbacks;
330  if (!funcs || !funcs->expand_sub_args) {
332  "Cannot expand 'Gosub(%s)' arguments. The app_stack module is not available.\n",
333  args);
334  return NULL;
335  }
336  ast_module_ref(funcs->module);
337 
338  new_args = funcs->expand_sub_args(chan, args);
339  ast_module_unref(funcs->module);
340  return new_args;
341 }
void ast_module_unref(struct ast_module *)
Definition: loader.c:1312
const char *(* expand_sub_args)(struct ast_channel *chan, const char *args)
Add missing context/exten to Gosub application argument string.
Definition: app.h:198
#define LOG_WARNING
Definition: logger.h:144
static struct ast_app_stack_funcs * app_stack_callbacks
Definition: app.c:317
void * module
Definition: app.h:170
static struct @350 args
Stack applications callback functions.
Definition: app.h:165
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
struct ast_module * ast_module_ref(struct ast_module *)
Definition: loader.c:1300
int ast_app_getdata ( struct ast_channel c,
const char *  prompt,
char *  s,
int  maxlen,
int  timeout 
)

Plays a stream and gets DTMF data from a channel.

Parameters
cWhich channel one is interacting with
promptFile to pass to ast_streamfile (the one that you wish to play). It is also valid for this to be multiple files concatenated by "&". For example, "file1&file2&file3".
sThe location where the DTMF data will be stored
maxlenMax Length of the data
timeoutTimeout length waiting for data(in milliseconds). Set to 0 for standard timeout(six seconds), or -1 for no time out.

This function was designed for application programmers for situations where they need to play a message and then get some DTMF data in response to the message. If a digit is pressed during playback, it will immediately break out of the message and continue execution of your code.

Plays a stream and gets DTMF data from a channel.

Parameters
cThe channel to read from
promptThe file to stream to the channel
sThe string to read in to. Must be at least the size of your length
maxlenHow many digits to read (maximum)
timeoutset 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::language, ast_channel::pbx, ast_pbx::rtimeoutms, and strsep().

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

179 {
180  int res = 0, to, fto;
181  char *front, *filename;
182 
183  /* XXX Merge with full version? XXX */
184 
185  if (maxlen)
186  s[0] = '\0';
187 
188  if (!prompt)
189  prompt = "";
190 
191  filename = ast_strdupa(prompt);
192  while ((front = strsep(&filename, "&"))) {
193  if (!ast_strlen_zero(front)) {
194  res = ast_streamfile(c, front, c->language);
195  if (res)
196  continue;
197  }
198  if (ast_strlen_zero(filename)) {
199  /* set timeouts for the last prompt */
200  fto = c->pbx ? c->pbx->rtimeoutms : 6000;
201  to = c->pbx ? c->pbx->dtimeoutms : 2000;
202 
203  if (timeout > 0) {
204  fto = to = timeout;
205  }
206  if (timeout < 0) {
207  fto = to = 1000000000;
208  }
209  } else {
210  /* there is more than one prompt, so
211  * get rid of the long timeout between
212  * prompts, and make it 50ms */
213  fto = 50;
214  to = c->pbx ? c->pbx->dtimeoutms : 2000;
215  }
216  res = ast_readstring(c, s, maxlen, to, fto, "#");
218  return res;
219  }
220  if (!ast_strlen_zero(s)) {
221  return res;
222  }
223  }
224 
225  return res;
226 }
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:946
char * strsep(char **str, const char *delims)
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
int dtimeoutms
Definition: pbx.h:180
static struct ast_str * prompt
Definition: asterisk.c:2395
int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders)
Reads multiple digits.
Definition: channel.c:5837
const ast_string_field language
Definition: channel.h:787
struct ast_pbx * pbx
Definition: channel.h:761
int rtimeoutms
Definition: pbx.h:181
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(), ast_strlen_zero(), and ast_channel::language.

Referenced by handle_getdata().

232 {
233  int res, to = 2000, fto = 6000;
234 
235  if (!ast_strlen_zero(prompt)) {
236  res = ast_streamfile(c, prompt, c->language);
237  if (res < 0) {
238  return res;
239  }
240  }
241 
242  if (timeout > 0) {
243  fto = to = timeout;
244  }
245  if (timeout < 0) {
246  fto = to = 1000000000;
247  }
248 
249  res = ast_readstring_full(c, s, maxlen, to, fto, "#", audiofd, ctrlfd);
250 
251  return res;
252 }
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:946
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd)
Definition: channel.c:5842
static struct ast_str * prompt
Definition: asterisk.c:2395
const ast_string_field language
Definition: channel.h:787
int ast_app_group_discard ( struct ast_channel chan)

Discard all group counting for a channel.

Definition at line 1348 of file app.c.

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

Referenced by ast_channel_destructor().

1349 {
1350  struct ast_group_info *gi = NULL;
1351 
1354  if (gi->chan == chan) {
1356  ast_free(gi);
1357  }
1358  }
1361 
1362  return 0;
1363 }
channel group info
Definition: channel.h:2459
Definition: app.c:104
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:565
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:542
struct ast_channel * chan
Definition: channel.h:2460
#define ast_free(a)
Definition: astmm.h:97
struct ast_group_info::@157 group_list
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:602
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 1269 of file app.c.

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

Referenced by group_count_function_read().

1270 {
1271  struct ast_group_info *gi = NULL;
1272  int count = 0;
1273 
1274  if (ast_strlen_zero(group)) {
1275  return 0;
1276  }
1277 
1280  if (!strcasecmp(gi->group, group) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) {
1281  count++;
1282  }
1283  }
1285 
1286  return count;
1287 }
channel group info
Definition: channel.h:2459
Definition: app.c:104
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
char * group
Definition: channel.h:2462
char * category
Definition: channel.h:2461
struct ast_group_info::@157 group_list
struct ast_group_info* ast_app_group_list_head ( void  )

Get the head of the group count list.

Definition at line 1375 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().

1376 {
1377  return AST_RWLIST_FIRST(&groups);
1378 }
Definition: app.c:104
#define AST_RWLIST_FIRST
Definition: linkedlists.h:422
int ast_app_group_list_rdlock ( void  )

Read Lock the group count list.

Definition at line 1370 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().

1371 {
1372  return AST_RWLIST_RDLOCK(&groups);
1373 }
Definition: app.c:104
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
int ast_app_group_list_unlock ( void  )

Unlock the group count list.

Definition at line 1380 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().

1381 {
1382  return AST_RWLIST_UNLOCK(&groups);
1383 }
Definition: app.c:104
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
int ast_app_group_list_wrlock ( void  )

Write Lock the group count list.

Definition at line 1365 of file app.c.

References AST_RWLIST_WRLOCK.

1366 {
1367  return AST_RWLIST_WRLOCK(&groups);
1368 }
Definition: app.c:104
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
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 1289 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, ast_group_info::group_list, LOG_ERROR, and LOG_NOTICE.

Referenced by group_match_count_function_read().

1290 {
1291  struct ast_group_info *gi = NULL;
1292  regex_t regexbuf_group;
1293  regex_t regexbuf_category;
1294  int count = 0;
1295 
1296  if (ast_strlen_zero(groupmatch)) {
1297  ast_log(LOG_NOTICE, "groupmatch empty\n");
1298  return 0;
1299  }
1300 
1301  /* if regex compilation fails, return zero matches */
1302  if (regcomp(&regexbuf_group, groupmatch, REG_EXTENDED | REG_NOSUB)) {
1303  ast_log(LOG_ERROR, "Regex compile failed on: %s\n", groupmatch);
1304  return 0;
1305  }
1306 
1307  if (!ast_strlen_zero(category) && regcomp(&regexbuf_category, category, REG_EXTENDED | REG_NOSUB)) {
1308  ast_log(LOG_ERROR, "Regex compile failed on: %s\n", category);
1309  regfree(&regexbuf_group);
1310  return 0;
1311  }
1312 
1315  if (!regexec(&regexbuf_group, gi->group, 0, NULL, 0) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !regexec(&regexbuf_category, gi->category, 0, NULL, 0)))) {
1316  count++;
1317  }
1318  }
1320 
1321  regfree(&regexbuf_group);
1322  if (!ast_strlen_zero(category)) {
1323  regfree(&regexbuf_category);
1324  }
1325 
1326  return count;
1327 }
channel group info
Definition: channel.h:2459
Definition: app.c:104
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
char * group
Definition: channel.h:2462
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
char * category
Definition: channel.h:2461
struct ast_group_info::@157 group_list
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 1222 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, ast_group_info::group_list, and len().

Referenced by dial_exec_full(), and group_function_write().

1223 {
1224  int res = 0;
1225  char group[80] = "", category[80] = "";
1226  struct ast_group_info *gi = NULL;
1227  size_t len = 0;
1228 
1229  if (ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category))) {
1230  return -1;
1231  }
1232 
1233  /* Calculate memory we will need if this is new */
1234  len = sizeof(*gi) + strlen(group) + 1;
1235  if (!ast_strlen_zero(category)) {
1236  len += strlen(category) + 1;
1237  }
1238 
1241  if ((gi->chan == chan) && ((ast_strlen_zero(category) && ast_strlen_zero(gi->category)) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) {
1243  free(gi);
1244  break;
1245  }
1246  }
1248 
1249  if (ast_strlen_zero(group)) {
1250  /* Enable unsetting the group */
1251  } else if ((gi = calloc(1, len))) {
1252  gi->chan = chan;
1253  gi->group = (char *) gi + sizeof(*gi);
1254  strcpy(gi->group, group);
1255  if (!ast_strlen_zero(category)) {
1256  gi->category = (char *) gi + sizeof(*gi) + strlen(group) + 1;
1257  strcpy(gi->category, category);
1258  }
1260  } else {
1261  res = -1;
1262  }
1263 
1265 
1266  return res;
1267 }
channel group info
Definition: channel.h:2459
Definition: app.c:104
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define calloc(a, b)
Definition: astmm.h:79
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: app.c:1195
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:565
char * group
Definition: channel.h:2462
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:542
struct ast_channel * chan
Definition: channel.h:2460
#define free(a)
Definition: astmm.h:94
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char * category
Definition: channel.h:2461
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:726
struct ast_group_info::@157 group_list
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:602
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 1195 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().

1196 {
1197  int res = 0;
1198  char tmp[256];
1199  char *grp = NULL, *cat = NULL;
1200 
1201  if (!ast_strlen_zero(data)) {
1202  ast_copy_string(tmp, data, sizeof(tmp));
1203  grp = tmp;
1204  if ((cat = strchr(tmp, '@'))) {
1205  *cat++ = '\0';
1206  }
1207  }
1208 
1209  if (!ast_strlen_zero(grp)) {
1210  ast_copy_string(group, grp, group_max);
1211  } else {
1212  *group = '\0';
1213  }
1214 
1215  if (!ast_strlen_zero(cat)) {
1216  ast_copy_string(category, cat, category_max);
1217  }
1218 
1219  return res;
1220 }
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
char * category
Definition: channel.h:2461
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
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 1329 of file app.c.

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

Referenced by ast_do_masquerade(), and check_bridge().

1330 {
1331  struct ast_group_info *gi = NULL;
1332 
1335  if (gi->chan == old) {
1336  gi->chan = new;
1337  } else if (gi->chan == new) {
1339  ast_free(gi);
1340  }
1341  }
1344 
1345  return 0;
1346 }
channel group info
Definition: channel.h:2459
Definition: app.c:104
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:565
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:542
struct ast_channel * chan
Definition: channel.h:2460
#define ast_free(a)
Definition: astmm.h:97
struct ast_group_info::@157 group_list
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:602
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.

Return values
1Mailbox has voicemail
0No new voicemail in specified mailbox
-1Failure
Since
1.0

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().

422 {
423  static int warned = 0;
425  return ast_has_voicemail_func(mailbox, folder);
426  }
427 
428  if (warned++ % 10 == 0) {
429  ast_verb(3, "Message check requested for mailbox %s/folder %s but voicemail not loaded.\n", mailbox, folder ? folder : "INBOX");
430  }
431  return 0;
432 }
static int(* ast_has_voicemail_func)(const char *mailbox, const char *folder)
Definition: app.c:393
#define ast_verb(level,...)
Definition: logger.h:243
static char mailbox[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:197
int ast_app_inboxcount ( const char *  mailbox,
int *  newmsgs,
int *  oldmsgs 
)

Determine number of new/old messages in a mailbox.

Since
1.0
Parameters
[in]mailboxMailbox specification in the format mbox[][&mbox2[]][...]
[out]newmsgsNumber of messages in the "INBOX" folder. Includes number of messages in the "Urgent" folder, if any.
[out]oldmsgsNumber of messages in the "Old" folder.
Return values
0Success
-1Failure

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().

436 {
437  static int warned = 0;
438  if (newmsgs) {
439  *newmsgs = 0;
440  }
441  if (oldmsgs) {
442  *oldmsgs = 0;
443  }
444  if (ast_inboxcount_func) {
445  return ast_inboxcount_func(mailbox, newmsgs, oldmsgs);
446  }
447 
448  if (warned++ % 10 == 0) {
449  ast_verb(3, "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox);
450  }
451 
452  return 0;
453 }
static int(* ast_inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs)
Definition: app.c:394
#define ast_verb(level,...)
Definition: logger.h:243
static char mailbox[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:197
int ast_app_inboxcount2 ( const char *  mailbox,
int *  urgentmsgs,
int *  newmsgs,
int *  oldmsgs 
)

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

Parameters
[in]mailboxthe mailbox context to use
[out]urgentmsgsthe urgent message count
[out]newmsgsthe new message count
[out]oldmsgsthe old message count
Returns
Returns 0 for success, negative upon error
Since
1.6.1

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().

456 {
457  static int warned = 0;
458  if (newmsgs) {
459  *newmsgs = 0;
460  }
461  if (oldmsgs) {
462  *oldmsgs = 0;
463  }
464  if (urgentmsgs) {
465  *urgentmsgs = 0;
466  }
467  if (ast_inboxcount2_func) {
468  return ast_inboxcount2_func(mailbox, urgentmsgs, newmsgs, oldmsgs);
469  }
470 
471  if (warned++ % 10 == 0) {
472  ast_verb(3, "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox);
473  }
474 
475  return 0;
476 }
#define ast_verb(level,...)
Definition: logger.h:243
static int(* ast_inboxcount2_func)(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
Definition: app.c:395
static char mailbox[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:197
int ast_app_messagecount ( const char *  context,
const char *  mailbox,
const char *  folder 
)

Check number of messages in a given context, mailbox, and folder.

Since
1.4
Parameters
[in]contextMailbox context
[in]mailboxMailbox number
[in]folderMailbox folder
Returns
Number of messages in the given context, mailbox, and folder. If folder is NULL, folder "INBOX" is assumed. If folder is "INBOX", includes number of messages in the "Urgent" folder.

Definition at line 486 of file app.c.

References ast_messagecount_func, and ast_verb.

Referenced by acf_vmcount_exec().

487 {
488  static int warned = 0;
489  if (ast_messagecount_func) {
490  return ast_messagecount_func(context, mailbox, folder);
491  }
492 
493  if (!warned) {
494  warned++;
495  ast_verb(3, "Message count requested for mailbox %s@%s/%s but voicemail not loaded.\n", mailbox, context, folder);
496  }
497 
498  return 0;
499 }
static int(* ast_messagecount_func)(const char *context, const char *mailbox, const char *folder)
Definition: app.c:397
#define ast_verb(level,...)
Definition: logger.h:243
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
static char mailbox[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:197
void ast_app_options2str64 ( const struct ast_app_option options,
struct ast_flags64 flags,
char *  buf,
size_t  len 
)

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

Parameters
optionsThe array of possible options declared with AST_APP_OPTIONS
flagsThe flags of the options that you wish to populate the buffer with
bufThe buffer to fill with the string of options
lenThe maximum length of buf

Definition at line 2111 of file app.c.

References ast_test_flag64, and len().

2112 {
2113  unsigned int i, found = 0;
2114  for (i = 32; i < 128 && found < len; i++) {
2115  if (ast_test_flag64(flags, options[i].flag)) {
2116  buf[found++] = i;
2117  }
2118  }
2119  buf[found] = '\0';
2120 }
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_test_flag64(p, flag)
Definition: utils.h:120
int ast_app_parse_options ( const struct ast_app_option options,
struct ast_flags flags,
char **  args,
char *  optstr 
)

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

Parameters
optionsThe array of possible options declared with AST_APP_OPTIONS
flagsThe flag structure to have option flags set
argsThe array of argument pointers to hold arguments found
optstrThe string containing the options to be parsed
Returns
zero for success, non-zero if an error occurs
See Also
AST_APP_OPTIONS

Definition at line 2101 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(), sig_pri_call(), sla_trunk_exec(), smdi_msg_retrieve_read(), sms_exec(), softhangup_exec(), speech_background(), vm_exec(), vm_execmain(), and volume_write().

2102 {
2103  return parse_options(options, flags, args, optstr, 32);
2104 }
static int parse_options(const struct ast_app_option *options, void *_flags, char **args, char *optstr, int flaglen)
Definition: app.c:2021
static struct @350 args
int ast_app_parse_options64 ( const struct ast_app_option options,
struct ast_flags64 flags,
char **  args,
char *  optstr 
)

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

Parameters
optionsThe array of possible options declared with AST_APP_OPTIONS
flagsThe 64-bit flag structure to have option flags set
argsThe array of argument pointers to hold arguments found
optstrThe string containing the options to be parsed
Returns
zero for success, non-zero if an error occurs
See Also
AST_APP_OPTIONS

Definition at line 2106 of file app.c.

References parse_options().

Referenced by conf_exec(), dial_exec_full(), and find_conf_realtime().

2107 {
2108  return parse_options(options, flags, args, optstr, 64);
2109 }
static int parse_options(const struct ast_app_option *options, void *_flags, char **args, char *optstr, int flaglen)
Definition: app.c:2021
static struct @350 args
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.

Parameters
[in]timestrString to parse
[in]defunitDefault unit type
[out]resultResulting value, specified in milliseconds
Return values
0Success
-1Failure
Since
1.8

Definition at line 2311 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().

2312 {
2313  int res;
2314  char u[10];
2315 #ifdef HAVE_LONG_DOUBLE_WIDER
2316  long double amount;
2317  #define FMT "%30Lf%9s"
2318 #else
2319  double amount;
2320  #define FMT "%30lf%9s"
2321 #endif
2322  if (!timestr) {
2323  return -1;
2324  }
2325 
2326  res = sscanf(timestr, FMT, &amount, u);
2327 
2328  if (res == 0 || res == EOF) {
2329 #undef FMT
2330  return -1;
2331  } else if (res == 2) {
2332  switch (u[0]) {
2333  case 'h':
2334  case 'H':
2335  unit = TIMELEN_HOURS;
2336  break;
2337  case 's':
2338  case 'S':
2339  unit = TIMELEN_SECONDS;
2340  break;
2341  case 'm':
2342  case 'M':
2343  if (toupper(u[1]) == 'S') {
2344  unit = TIMELEN_MILLISECONDS;
2345  } else if (u[1] == '\0') {
2346  unit = TIMELEN_MINUTES;
2347  }
2348  break;
2349  }
2350  }
2351 
2352  switch (unit) {
2353  case TIMELEN_HOURS:
2354  amount *= 60;
2355  /* fall-through */
2356  case TIMELEN_MINUTES:
2357  amount *= 60;
2358  /* fall-through */
2359  case TIMELEN_SECONDS:
2360  amount *= 1000;
2361  /* fall-through */
2362  case TIMELEN_MILLISECONDS:
2363  ;
2364  }
2365  *result = amount > INT_MAX ? INT_MAX : (int) amount;
2366  return 0;
2367 }
#define FMT
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.

Since
1.8

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.

Note
Absolutely NO channel locks should be held before calling this function.
Parameters
autoservice_chanA channel to place into autoservice while the macro is run
macro_chanChannel to execute macro on.
macro_nameThe name of the macro to run.
macro_argsThe arguments to pass to the macro.
Return values
0success
-1on 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().

295 {
296  int res;
297  char *args_str;
298  size_t args_len;
299 
300  if (ast_strlen_zero(macro_args)) {
301  return ast_app_exec_macro(autoservice_chan, macro_chan, macro_name);
302  }
303 
304  /* Create the Macro application argument string. */
305  args_len = strlen(macro_name) + strlen(macro_args) + 2;
306  args_str = ast_malloc(args_len);
307  if (!args_str) {
308  return -1;
309  }
310  snprintf(args_str, args_len, "%s,%s", macro_name, macro_args);
311 
312  res = ast_app_exec_macro(autoservice_chan, macro_chan, args_str);
313  ast_free(args_str);
314  return res;
315 }
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_free(a)
Definition: astmm.h:97
#define ast_malloc(a)
Definition: astmm.h:91
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.
Definition: app.c:254
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.

Since
1.8.30.0
11

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.

Note
Absolutely NO channel locks should be held before calling this function.
Parameters
autoservice_chanA channel to place into autoservice while the subroutine is run
sub_chanChannel to execute subroutine on.
sub_locationThe location of the subroutine to run.
sub_argsThe arguments to pass to the subroutine.
ignore_hangupTRUE if a hangup does not stop execution of the routine.
Return values
0success
-1on error

Definition at line 370 of file app.c.

References ast_app_exec_sub(), ast_free, ast_malloc, and ast_strlen_zero().

371 {
372  int res;
373  char *args_str;
374  size_t args_len;
375 
376  if (ast_strlen_zero(sub_args)) {
377  return ast_app_exec_sub(autoservice_chan, sub_chan, sub_location, ignore_hangup);
378  }
379 
380  /* Create the Gosub application argument string. */
381  args_len = strlen(sub_location) + strlen(sub_args) + 3;
382  args_str = ast_malloc(args_len);
383  if (!args_str) {
384  return -1;
385  }
386  snprintf(args_str, args_len, "%s(%s)", sub_location, sub_args);
387 
388  res = ast_app_exec_sub(autoservice_chan, sub_chan, args_str, ignore_hangup);
389  ast_free(args_str);
390  return res;
391 }
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.
Definition: app.c:343
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_free(a)
Definition: astmm.h:97
#define ast_malloc(a)
Definition: astmm.h:91
int ast_app_sayname ( struct ast_channel chan,
const char *  mailbox,
const char *  context 
)

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

Parameters
[in]chanChannel on which to play the name
[in]mailboxMailbox number from which to retrieve the recording
[in]contextMailbox context from which to locate the mailbox number
Return values
0Name played without interruption
dtmfASCII value of the DTMF which interrupted playback.
-1Unable to locate mailbox or hangup occurred.
Since
1.6.1

Definition at line 478 of file app.c.

References ast_sayname_func.

Referenced by common_exec(), and play_mailbox_owner().

479 {
480  if (ast_sayname_func) {
481  return ast_sayname_func(chan, mailbox, context);
482  }
483  return -1;
484 }
static int(* ast_sayname_func)(struct ast_channel *chan, const char *mailbox, const char *context)
Definition: app.c:396
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
static char mailbox[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:197
void ast_close_fds_above_n ( int  n)

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

Parameters
[in]nstarting file descriptor number for closing all higher file descriptors
Since
1.6.1

Definition at line 2237 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().

2238 {
2239  closefrom(n + 1);
2240 }
void closefrom(int lowfd)
Definition: strcompat.c:426
int ast_control_streamfile ( struct ast_channel chan,
const char *  file,
const char *  fwd,
const char *  rev,
const char *  stop,
const char *  pause,
const char *  restart,
int  skipms,
long *  offsetms 
)

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

Parameters
chan
filefilename
fwd,rev,stop,pause,restart,skipms,offsetmsBefore 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(), ast_channel::language, and ast_channel::stream.

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

687 {
688  char *breaks = NULL;
689  char *end = NULL;
690  int blen = 2;
691  int res;
692  long pause_restart_point = 0;
693  long offset = 0;
694 
695  if (!file) {
696  return -1;
697  }
698  if (offsetms) {
699  offset = *offsetms * 8; /* XXX Assumes 8kHz */
700  }
701 
702  if (stop) {
703  blen += strlen(stop);
704  }
705  if (suspend) {
706  blen += strlen(suspend);
707  }
708  if (restart) {
709  blen += strlen(restart);
710  }
711 
712  if (blen > 2) {
713  breaks = ast_alloca(blen + 1);
714  breaks[0] = '\0';
715  if (stop) {
716  strcat(breaks, stop);
717  }
718  if (suspend) {
719  strcat(breaks, suspend);
720  }
721  if (restart) {
722  strcat(breaks, restart);
723  }
724  }
725  if (chan->_state != AST_STATE_UP) {
726  res = ast_answer(chan);
727  }
728 
729  if ((end = strchr(file, ':'))) {
730  if (!strcasecmp(end, ":end")) {
731  *end = '\0';
732  end++;
733  }
734  }
735 
736  for (;;) {
737  ast_stopstream(chan);
738  res = ast_streamfile(chan, file, chan->language);
739  if (!res) {
740  if (pause_restart_point) {
741  ast_seekstream(chan->stream, pause_restart_point, SEEK_SET);
742  pause_restart_point = 0;
743  }
744  else if (end || offset < 0) {
745  if (offset == -8) {
746  offset = 0;
747  }
748  ast_verb(3, "ControlPlayback seek to offset %ld from end\n", offset);
749 
750  ast_seekstream(chan->stream, offset, SEEK_END);
751  end = NULL;
752  offset = 0;
753  } else if (offset) {
754  ast_verb(3, "ControlPlayback seek to offset %ld\n", offset);
755  ast_seekstream(chan->stream, offset, SEEK_SET);
756  offset = 0;
757  }
758  res = ast_waitstream_fr(chan, breaks, fwd, rev, skipms);
759  }
760 
761  if (res < 1) {
762  break;
763  }
764 
765  /* We go at next loop if we got the restart char */
766  if (restart && strchr(restart, res)) {
767  ast_debug(1, "we'll restart the stream here at next loop\n");
768  pause_restart_point = 0;
769  continue;
770  }
771 
772  if (suspend && strchr(suspend, res)) {
773  pause_restart_point = ast_tellstream(chan->stream);
774  for (;;) {
775  ast_stopstream(chan);
776  if (!(res = ast_waitfordigit(chan, 1000))) {
777  continue;
778  } else if (res == -1 || strchr(suspend, res) || (stop && strchr(stop, res))) {
779  break;
780  }
781  }
782  if (res == *suspend) {
783  res = 0;
784  continue;
785  }
786  }
787 
788  if (res == -1) {
789  break;
790  }
791 
792  /* if we get one of our stop chars, return it to the calling function */
793  if (stop && strchr(stop, res)) {
794  break;
795  }
796  }
797 
798  if (pause_restart_point) {
799  offset = pause_restart_point;
800  } else {
801  if (chan->stream) {
802  offset = ast_tellstream(chan->stream);
803  } else {
804  offset = -8; /* indicate end of file */
805  }
806  }
807 
808  if (offsetms) {
809  *offsetms = offset / 8; /* samples --> ms ... XXX Assumes 8 kHz */
810  }
811 
812  /* If we are returning a digit cast it as char */
813  if (res > 0 || chan->stream) {
814  res = (char)res;
815  }
816 
817  ast_stopstream(chan);
818 
819  return res;
820 }
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:946
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: utils.h:653
unsigned int stop
Definition: app_meetme.c:969
#define ast_verb(level,...)
Definition: logger.h:243
off_t ast_tellstream(struct ast_filestream *fs)
Tell where we are in a stream.
Definition: file.c:889
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
int ast_waitstream_fr(struct ast_channel *c, const char *breakon, const char *forward, const char *rewind, int ms)
Same as waitstream but allows stream to be forwarded or rewound.
Definition: file.c:1337
static int skipms
enum ast_channel_state _state
Definition: channel.h:839
int ast_seekstream(struct ast_filestream *fs, off_t sample_offset, int whence)
Seeks into stream.
Definition: file.c:879
static void suspend(struct cc_core_instance *core_instance)
Definition: ccss.c:2919
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition: channel.c:3552
int ast_answer(struct ast_channel *chan)
Answer a channel.
Definition: channel.c:3086
struct ast_filestream * stream
Definition: channel.h:757
const ast_string_field language
Definition: channel.h:787
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:128
int ast_dtmf_stream ( struct ast_channel chan,
struct ast_channel peer,
const char *  digits,
int  between,
unsigned int  duration 
)

Send DTMF to a channel.

Parameters
chanThe channel that will receive the DTMF frames
peer(optional) Peer channel that will be autoserviced while the primary channel is receiving DTMF
digitsThis 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.
betweenThis 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.
durationThis 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().

502 {
503  const char *ptr;
504  int res = 0;
505  struct ast_silence_generator *silgen = NULL;
506 
507  if (!between) {
508  between = 100;
509  }
510 
511  if (peer) {
512  res = ast_autoservice_start(peer);
513  }
514 
515  if (!res) {
516  res = ast_waitfor(chan, 100);
517  }
518 
519  /* ast_waitfor will return the number of remaining ms on success */
520  if (res < 0) {
521  if (peer) {
522  ast_autoservice_stop(peer);
523  }
524  return res;
525  }
526 
529  }
530 
531  for (ptr = digits; *ptr; ptr++) {
532  if (*ptr == 'w') {
533  /* 'w' -- wait half a second */
534  if ((res = ast_safe_sleep(chan, 500))) {
535  break;
536  }
537  } else if (strchr("0123456789*#abcdfABCDF", *ptr)) {
538  /* Character represents valid DTMF */
539  if (*ptr == 'f' || *ptr == 'F') {
540  /* ignore return values if not supported by channel */
542  } else {
543  ast_senddigit(chan, *ptr, duration);
544  }
545  /* pause between digits */
546  if ((res = ast_safe_sleep(chan, between))) {
547  break;
548  }
549  } else {
550  ast_log(LOG_WARNING, "Illegal DTMF character '%c' in string. (0-9*#aAbBcCdD allowed)\n", *ptr);
551  }
552  }
553 
554  if (peer) {
555  /* Stop autoservice on the peer channel, but don't overwrite any error condition
556  that has occurred previously while acting on the primary channel */
557  if (ast_autoservice_stop(peer) && !res) {
558  res = -1;
559  }
560  }
561 
562  if (silgen) {
564  }
565 
566  return res;
567 }
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1916
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
Definition: autoservice.c:179
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4393
#define LOG_WARNING
Definition: logger.h:144
#define ast_opt_transmit_silence
Definition: options.h:120
int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration)
Send a DTMF digit to a channel.
Definition: channel.c:4774
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
Definition: autoservice.c:238
struct ast_silence_generator * ast_channel_start_silence_generator(struct ast_channel *chan)
Starts a silence generator on the given channel.
Definition: channel.c:8309
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state)
Stops a previously-started silence generator on the given channel.
Definition: channel.c:8355
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3539
int ast_get_encoded_char ( const char *  stream,
char *  result,
size_t *  consumed 
)

Decode an encoded control or extended ASCII character.

Parameters
[in]streamString to decode
[out]resultDecoded character
[out]consumedNumber of characters used in stream to encode the character
Return values
-1Stream is of zero length
0Success

Definition at line 2122 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().

2123 {
2124  int i;
2125  *consumed = 1;
2126  *result = 0;
2127  if (ast_strlen_zero(stream)) {
2128  *consumed = 0;
2129  return -1;
2130  }
2131 
2132  if (*stream == '\\') {
2133  *consumed = 2;
2134  switch (*(stream + 1)) {
2135  case 'n':
2136  *result = '\n';
2137  break;
2138  case 'r':
2139  *result = '\r';
2140  break;
2141  case 't':
2142  *result = '\t';
2143  break;
2144  case 'x':
2145  /* Hexadecimal */
2146  if (strchr("0123456789ABCDEFabcdef", *(stream + 2)) && *(stream + 2) != '\0') {
2147  *consumed = 3;
2148  if (*(stream + 2) <= '9') {
2149  *result = *(stream + 2) - '0';
2150  } else if (*(stream + 2) <= 'F') {
2151  *result = *(stream + 2) - 'A' + 10;
2152  } else {
2153  *result = *(stream + 2) - 'a' + 10;
2154  }
2155  } else {
2156  ast_log(LOG_ERROR, "Illegal character '%c' in hexadecimal string\n", *(stream + 2));
2157  return -1;
2158  }
2159 
2160  if (strchr("0123456789ABCDEFabcdef", *(stream + 3)) && *(stream + 3) != '\0') {
2161  *consumed = 4;
2162  *result <<= 4;
2163  if (*(stream + 3) <= '9') {
2164  *result += *(stream + 3) - '0';
2165  } else if (*(stream + 3) <= 'F') {
2166  *result += *(stream + 3) - 'A' + 10;
2167  } else {
2168  *result += *(stream + 3) - 'a' + 10;
2169  }
2170  }
2171  break;
2172  case '0':
2173  /* Octal */
2174  *consumed = 2;
2175  for (i = 2; ; i++) {
2176  if (strchr("01234567", *(stream + i)) && *(stream + i) != '\0') {
2177  (*consumed)++;
2178  ast_debug(5, "result was %d, ", *result);
2179  *result <<= 3;
2180  *result += *(stream + i) - '0';
2181  ast_debug(5, "is now %d\n", *result);
2182  } else {
2183  break;
2184  }
2185  }
2186  break;
2187  default:
2188  *result = *(stream + 1);
2189  }
2190  } else {
2191  *result = *stream;
2192  *consumed = 1;
2193  }
2194  return 0;
2195 }
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
char* ast_get_encoded_str ( const char *  stream,
char *  result,
size_t  result_len 
)

Decode a stream of encoded control or extended ASCII characters.

Parameters
[in]streamEncoded string
[out]resultDecoded string
[in]result_lenMaximum size of the result buffer
Returns
A pointer to the result string

Definition at line 2197 of file app.c.

References ast_get_encoded_char().

Referenced by listfilter(), mgcp_new(), replace(), sip_addheader(), and sip_new().

2198 {
2199  char *cur = result;
2200  size_t consumed;
2201 
2202  while (cur < result + result_size - 1 && !ast_get_encoded_char(stream, cur, &consumed)) {
2203  cur++;
2204  stream += consumed;
2205  }
2206  *cur = '\0';
2207  return result;
2208 }
int ast_get_encoded_char(const char *stream, char *result, size_t *consumed)
Decode an encoded control or extended ASCII character.
Definition: app.c:2122
void ast_install_stack_functions ( const struct ast_app_stack_funcs funcs)

Set stack application function callbacks.

Since
1.8.30.0
11
Parameters
funcsStack applications callback functions.

Definition at line 319 of file app.c.

References app_stack_callbacks.

Referenced by load_module(), and unload_module().

320 {
321  app_stack_callbacks = funcs;
322 }
static struct ast_app_stack_funcs * app_stack_callbacks
Definition: app.c:317
void ast_install_vm_functions ( int(*)(const char *mailbox, const char *folder)  has_voicemail_func,
int(*)(const char *mailbox, int *newmsgs, int *oldmsgs)  inboxcount_func,
int(*)(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)  inboxcount2_func,
int(*)(const char *context, const char *mailbox, const char *folder)  messagecount_func,
int(*)(struct ast_channel *chan, const char *mailbox, const char *context sayname_func 
)

Set voicemail function callbacks.

Parameters
[in]has_voicemail_funcset function pointer
[in]inboxcount2_funcset function pointer
[in]sayname_funcset function pointer
[in]inboxcount_funcset function pointer
[in]messagecount_funcset function pointer
Version
1.6.1 Added inboxcount2_func, sayname_func

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().

404 {
405  ast_has_voicemail_func = has_voicemail_func;
406  ast_inboxcount_func = inboxcount_func;
407  ast_inboxcount2_func = inboxcount2_func;
408  ast_messagecount_func = messagecount_func;
409  ast_sayname_func = sayname_func;
410 }
static int(* ast_messagecount_func)(const char *context, const char *mailbox, const char *folder)
Definition: app.c:397
static int(* ast_sayname_func)(struct ast_channel *chan, const char *mailbox, const char *context)
Definition: app.c:396
static int(* ast_inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs)
Definition: app.c:394
static int(* ast_has_voicemail_func)(const char *mailbox, const char *folder)
Definition: app.c:393
static int(* ast_inboxcount2_func)(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
Definition: app.c:395
int ast_ivr_menu_run ( struct ast_channel c,
struct ast_ivr_menu menu,
void *  cbdata 
)

Runs an IVR menu.

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

Definition at line 1980 of file app.c.

References ast_ivr_menu_run_internal().

Referenced by skel_exec().

1981 {
1982  int res = ast_ivr_menu_run_internal(chan, menu, cbdata);
1983  /* Hide internal coding */
1984  return res > 0 ? 0 : res;
1985 }
static int ast_ivr_menu_run_internal(struct ast_channel *chan, struct ast_ivr_menu *menu, void *cbdata)
Definition: app.c:1895
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.

654 {
655  struct linear_state *lin;
656  char tmpf[256];
657  int res = -1;
658  int autoclose = 0;
659  if (fd < 0) {
660  if (ast_strlen_zero(filename)) {
661  return -1;
662  }
663  autoclose = 1;
664  if (filename[0] == '/') {
665  ast_copy_string(tmpf, filename, sizeof(tmpf));
666  } else {
667  snprintf(tmpf, sizeof(tmpf), "%s/%s/%s", ast_config_AST_DATA_DIR, "sounds", filename);
668  }
669  if ((fd = open(tmpf, O_RDONLY)) < 0) {
670  ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", tmpf, strerror(errno));
671  return -1;
672  }
673  }
674  if ((lin = ast_calloc(1, sizeof(*lin)))) {
675  lin->fd = fd;
677  lin->autoclose = autoclose;
678  res = ast_activate_generator(chan, &linearstream, lin);
679  }
680  return res;
681 }
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
Definition: channel.c:3148
#define LOG_WARNING
Definition: logger.h:144
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
int autoclose
Definition: app.c:571
const char * ast_config_AST_DATA_DIR
Definition: asterisk.c:262
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
int allowoverride
Definition: app.c:572
#define ast_calloc(a, b)
Definition: astmm.h:82
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
static struct ast_generator linearstream
Definition: app.c:646
int fd
Definition: app.c:570
enum AST_LOCK_RESULT ast_lock_path ( const char *  path)

Lock a filesystem path.

Parameters
paththe path to be locked
Returns
one of AST_LOCK_RESULT values

Definition at line 1652 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().

1653 {
1655 
1656  switch (ast_lock_type) {
1658  r = ast_lock_path_lockfile(path);
1659  break;
1660  case AST_LOCK_TYPE_FLOCK:
1661  r = ast_lock_path_flock(path);
1662  break;
1663  }
1664 
1665  return r;
1666 }
AST_LOCK_RESULT
Definition: app.h:487
static enum AST_LOCK_RESULT ast_lock_path_flock(const char *path)
Definition: app.c:1532
static enum AST_LOCK_RESULT ast_lock_path_lockfile(const char *path)
Definition: app.c:1458
static enum AST_LOCK_TYPE ast_lock_type
Definition: app.c:229
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.

Parameters
chanthe channel being recorded
playfileFilename of sound to play before recording begins
recordfileFilename to save the recording
maxtime_secLongest possible message length in seconds
fmtstring containing all formats to be recorded delimited by '|'
durationpointer to integer for storing length of the recording
sound_durationpointer to integer for storing length of the recording minus all silence
beepwhether to play a beep to prompt the recording
silencethresholdtolerance of noise levels that can be considered silence for the purpose of silence timeout, -1 for default
maxsilence_mslength of time in milliseconds which will trigger a timeout from silence, -1 for default.
Return values
-1failure or hangup
'S'Recording ended from silence timeout
't'Recording either exceeded maximum duration or the call was ended via DTMF

Definition at line 1188 of file app.c.

References __ast_play_and_record(), default_acceptdtmf, and default_canceldtmf.

Referenced by vm_forwardoptions().

1189 {
1190  return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, sound_duration, beep, silencethreshold, maxsilence, NULL, 1, default_acceptdtmf, default_canceldtmf, 1);
1191 }
static const char default_acceptdtmf[]
Definition: app.c:1175
static int maxsilence
static char beep[AST_MAX_BUF]
Definition: chan_agent.c:239
static int silencethreshold
static const char default_canceldtmf[]
Definition: app.c:1176
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)
Definition: app.c:862
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.

Parameters
chanthe channel being recorded
playfileFilename of sound to play before recording begins
recordfileFilename to save the recording
maxtime_secLongest possible message length in seconds
fmtstring containing all formats to be recorded delimited by '|'
durationpointer to integer for storing length of the recording
sound_durationpointer to integer for storing length of the recording minus all silence
silencethresholdtolerance of noise levels that can be considered silence for the purpose of silence timeout, -1 for default
maxsilence_mslength of time in milliseconds which will trigger a timeout from silence, -1 for default
pathOptional filesystem path to unlock
Return values
-1failure or hangup
'S'Recording ended from silence timeout
't'Recording ended from the message exceeding the maximum duration
dtmfcharRecording ended via the return value's DTMF character for either cancel or accept.

Definition at line 1183 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().

1184 {
1185  return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, sound_duration, 0, silencethreshold, maxsilence, path, 0, default_acceptdtmf, default_canceldtmf, 0);
1186 }
static const char default_acceptdtmf[]
Definition: app.c:1175
static int maxsilence
static int silencethreshold
static const char default_canceldtmf[]
Definition: app.c:1176
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)
Definition: app.c:862
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.

Parameters
chanthe channel being recorded
playfileFilename of sound to play before recording begins
recordfileFilename to save the recording
maxtime_secLongest possible message length in seconds
fmtstring containing all formats to be recorded delimited by '|'
durationpointer to integer for storing length of the recording
sound_durationpointer to integer for storing length of the recording minus all silence
silencethresholdtolerance of noise levels that can be considered silence for the purpose of silence timeout, -1 for default
maxsilence_msLength of time in milliseconds which will trigger a timeout from silence, -1 for default
pathOptional filesystem path to unlock
acceptdtmfCharacter of DTMF to end and accept the recording
canceldtmfCharacter of DTMF to end and cancel the recording
Return values
-1failure or hangup
'S'Recording ended from silence timeout
't'Recording ended from the message exceeding the maximum duration
dtmfcharRecording ended via the return value's DTMF character for either cancel or accept.

Definition at line 1178 of file app.c.

References __ast_play_and_record(), default_acceptdtmf, default_canceldtmf, and S_OR.

Referenced by play_record_review().

1179 {
1180  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);
1181 }
static const char default_acceptdtmf[]
Definition: app.c:1175
static int maxsilence
static int silencethreshold
static const char default_canceldtmf[]
Definition: app.c:1176
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)
Definition: app.c:862
static char acceptdtmf
Definition: chan_agent.c:227
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
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(), ast_waitstream(), and ast_channel::language.

Referenced by __ast_play_and_record(), advanced_options(), ast_record_review(), ast_say_counted_adjective(), ast_say_counted_noun(), dialout(), forward_message(), get_folder(), get_folder2(), leave_voicemail(), minivm_greet_exec(), play_message_category(), play_message_duration(), play_record_review(), vm_authenticate(), vm_browse_messages_en(), vm_browse_messages_he(), vm_browse_messages_latin(), 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().

823 {
824  int d = 0;
825 
826  if ((d = ast_streamfile(chan, fn, chan->language))) {
827  return d;
828  }
829 
830  d = ast_waitstream(chan, AST_DIGIT_ANY);
831 
832  ast_stopstream(chan);
833 
834  return d;
835 }
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:946
#define AST_DIGIT_ANY
Definition: file.h:47
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1343
const ast_string_field language
Definition: channel.h:787
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:128
char* ast_read_textfile ( const char *  file)

Read a file into asterisk.

Definition at line 1987 of file app.c.

References ast_free, ast_log(), ast_malloc, errno, and LOG_WARNING.

Referenced by readfile_exec().

1988 {
1989  int fd, count = 0, res;
1990  char *output = NULL;
1991  struct stat filesize;
1992 
1993  if (stat(filename, &filesize) == -1) {
1994  ast_log(LOG_WARNING, "Error can't stat %s\n", filename);
1995  return NULL;
1996  }
1997 
1998  count = filesize.st_size + 1;
1999 
2000  if ((fd = open(filename, O_RDONLY)) < 0) {
2001  ast_log(LOG_WARNING, "Cannot open file '%s' for reading: %s\n", filename, strerror(errno));
2002  return NULL;
2003  }
2004 
2005  if ((output = ast_malloc(count))) {
2006  res = read(fd, output, count - 1);
2007  if (res == count - 1) {
2008  output[res] = '\0';
2009  } else {
2010  ast_log(LOG_WARNING, "Short read of %s (%d of %d): %s\n", filename, res, count - 1, strerror(errno));
2011  ast_free(output);
2012  output = NULL;
2013  }
2014  }
2015 
2016  close(fd);
2017 
2018  return output;
2019 }
#define LOG_WARNING
Definition: logger.h:144
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
#define ast_free(a)
Definition: astmm.h:97
#define ast_malloc(a)
Definition: astmm.h:91
int fd
Definition: app.c:570
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 1684 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().

1685 {
1686  int silencethreshold;
1687  int maxsilence = 0;
1688  int res = 0;
1689  int cmd = 0;
1690  int max_attempts = 3;
1691  int attempts = 0;
1692  int recorded = 0;
1693  int message_exists = 0;
1694  /* Note that urgent and private are for flagging messages as such in the future */
1695 
1696  /* barf if no pointer passed to store duration in */
1697  if (!duration) {
1698  ast_log(LOG_WARNING, "Error ast_record_review called without duration pointer\n");
1699  return -1;
1700  }
1701 
1702  cmd = '3'; /* Want to start by recording */
1703 
1705 
1706  while ((cmd >= 0) && (cmd != 't')) {
1707  switch (cmd) {
1708  case '1':
1709  if (!message_exists) {
1710  /* In this case, 1 is to record a message */
1711  cmd = '3';
1712  break;
1713  } else {
1714  ast_stream_and_wait(chan, "vm-msgsaved", "");
1715  cmd = 't';
1716  return res;
1717  }
1718  case '2':
1719  /* Review */
1720  ast_verb(3, "Reviewing the recording\n");
1721  cmd = ast_stream_and_wait(chan, recordfile, AST_DIGIT_ANY);
1722  break;
1723  case '3':
1724  message_exists = 0;
1725  /* Record */
1726  ast_verb(3, "R%secording\n", recorded == 1 ? "e-r" : "");
1727  recorded = 1;
1728  if ((cmd = ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, NULL, silencethreshold, maxsilence, path)) == -1) {
1729  /* User has hung up, no options to give */
1730  return cmd;
1731  }
1732  if (cmd == '0') {
1733  break;
1734  } else if (cmd == '*') {
1735  break;
1736  } else {
1737  /* If all is well, a message exists */
1738  message_exists = 1;
1739  cmd = 0;
1740  }
1741  break;
1742  case '4':
1743  case '5':
1744  case '6':
1745  case '7':
1746  case '8':
1747  case '9':
1748  case '*':
1749  case '#':
1750  cmd = ast_play_and_wait(chan, "vm-sorry");
1751  break;
1752  default:
1753  if (message_exists) {
1754  cmd = ast_play_and_wait(chan, "vm-review");
1755  } else {
1756  if (!(cmd = ast_play_and_wait(chan, "vm-torerecord"))) {
1757  cmd = ast_waitfordigit(chan, 600);
1758  }
1759  }
1760 
1761  if (!cmd) {
1762  cmd = ast_waitfordigit(chan, 6000);
1763  }
1764  if (!cmd) {
1765  attempts++;
1766  }
1767  if (attempts > max_attempts) {
1768  cmd = 't';
1769  }
1770  }
1771  }
1772  if (cmd == 't') {
1773  cmd = 0;
1774  }
1775  return cmd;
1776 }
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 p...
Definition: app.c:1183
#define AST_DIGIT_ANY
Definition: file.h:47
#define LOG_WARNING
Definition: logger.h:144
static int maxsilence
#define ast_verb(level,...)
Definition: logger.h:243
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: app.c:822
static int silencethreshold
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int ast_stream_and_wait(struct ast_channel *chan, const char *file, const char *digits)
stream file until digit If the file name is non-empty, try to play it.
Definition: file.c:1370
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition: channel.c:3552
int ast_dsp_get_threshold_from_settings(enum threshold which)
Get silence threshold from dsp.conf.
Definition: dsp.c:1880
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 temporarily replaced.

Code that executes this function must call ast_unreplace_sigchld() after it is finished doing the wait*().

Definition at line 1047 of file asterisk.c.

References ast_mutex_lock, ast_mutex_unlock, null_sig_handler, safe_system_level, safe_system_lock, and safe_system_prev_handler.

Referenced by ast_safe_fork(), and ast_safe_system().

1048 {
1049  unsigned int level;
1050 
1052  level = safe_system_level++;
1053 
1054  /* only replace the handler if it has not already been done */
1055  if (level == 0) {
1056  sigaction(SIGCHLD, &null_sig_handler, &safe_system_prev_handler);
1057  }
1058 
1060 }
static ast_mutex_t safe_system_lock
Definition: asterisk.c:1041
static struct sigaction safe_system_prev_handler
Definition: asterisk.c:1045
#define ast_mutex_lock(a)
Definition: lock.h:155
static unsigned int safe_system_level
Keep track of how many threads are currently trying to wait*() on a child process.
Definition: asterisk.c:1044
static struct sigaction null_sig_handler
Definition: asterisk.c:1032
#define ast_mutex_unlock(a)
Definition: lock.h:156
int ast_safe_fork ( int  stop_reaper)

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

Parameters
[in]stop_reaperflag to determine if sigchld handler is replaced or not
Since
1.6.1

Definition at line 2242 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().

2243 {
2244  sigset_t signal_set, old_set;
2245  int pid;
2246 
2247  /* Don't let the default signal handler for children reap our status */
2248  if (stop_reaper) {
2250  }
2251 
2252  sigfillset(&signal_set);
2253  pthread_sigmask(SIG_BLOCK, &signal_set, &old_set);
2254 
2255  pid = fork();
2256 
2257  if (pid != 0) {
2258  /* Fork failed or parent */
2259  pthread_sigmask(SIG_SETMASK, &old_set, NULL);
2260  if (!stop_reaper && pid > 0) {
2261  struct zombie *cur = ast_calloc(1, sizeof(*cur));
2262  if (cur) {
2263  cur->pid = pid;
2269  ast_log(LOG_ERROR, "Shaun of the Dead wants to kill zombies, but can't?!!\n");
2271  }
2272  }
2273  }
2274  }
2275  return pid;
2276  } else {
2277  /* Child */
2278 #ifdef HAVE_CAP
2279  cap_t cap = cap_from_text("cap_net_admin-eip");
2280 
2281  if (cap_set_proc(cap)) {
2282  ast_log(LOG_WARNING, "Unable to remove capabilities.\n");
2283  }
2284  cap_free(cap);
2285 #endif
2286 
2287  /* Before we unblock our signals, return our trapped signals back to the defaults */
2288  signal(SIGHUP, SIG_DFL);
2289  signal(SIGCHLD, SIG_DFL);
2290  signal(SIGINT, SIG_DFL);
2291  signal(SIGURG, SIG_DFL);
2292  signal(SIGTERM, SIG_DFL);
2293  signal(SIGPIPE, SIG_DFL);
2294  signal(SIGXFSZ, SIG_DFL);
2295 
2296  /* unblock important signal handlers */
2297  if (pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL)) {
2298  ast_log(LOG_WARNING, "unable to unblock signals: %s\n", strerror(errno));
2299  _exit(1);
2300  }
2301 
2302  return pid;
2303  }
2304 }
pid_t pid
Definition: app.c:69
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:39
#define LOG_WARNING
Definition: logger.h:144
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:139
struct zombie::@216 list
#define ast_pthread_create_background(a, b, c, d)
Definition: utils.h:426
#define AST_PTHREADT_NULL
Definition: lock.h:65
Definition: app.c:73
#define LOG_ERROR
Definition: logger.h:155
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:716
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
static pthread_t shaun_of_the_dead_thread
Definition: app.c:66
Definition: app.c:68
static void * shaun_of_the_dead(void *data)
Definition: app.c:75
#define ast_calloc(a, b)
Definition: astmm.h:82
void ast_replace_sigchld(void)
Replace the SIGCHLD handler.
Definition: asterisk.c:1047
void ast_safe_fork_cleanup ( void  )

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

Since
1.6.1

Definition at line 2306 of file app.c.

References ast_unreplace_sigchld().

Referenced by agi_exec_full(), and run_ras().

2307 {
2309 }
void ast_unreplace_sigchld(void)
Restore the SIGCHLD handler.
Definition: asterisk.c:1062
int ast_safe_system ( const char *  s)

Safely spawn an external program while closing file descriptors.

Note
This replaces the system call in all Asterisk modules

Definition at line 1077 of file asterisk.c.

References ast_close_fds_above_n(), ast_log(), ast_opt_high_priority, ast_replace_sigchld(), ast_set_priority(), ast_unreplace_sigchld(), errno, LOG_WARNING, status, WEXITSTATUS, and WIFEXITED.

Referenced by add_email_attachment(), alarmreceiver_exec(), ast_monitor_stop(), consolehandler(), mixmonitor_thread(), notify_message(), process_text_line(), remoteconsolehandler(), rotate_file(), run_externnotify(), sendmail(), sendpage(), system_exec_helper(), and vm_change_password_shell().

1078 {
1079  pid_t pid;
1080  int res;
1081  struct rusage rusage;
1082  int status;
1083 
1084 #if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK)
1086 
1087 #ifdef HAVE_WORKING_FORK
1088  pid = fork();
1089 #else
1090  pid = vfork();
1091 #endif
1092 
1093  if (pid == 0) {
1094 #ifdef HAVE_CAP
1095  cap_t cap = cap_from_text("cap_net_admin-eip");
1096 
1097  if (cap_set_proc(cap)) {
1098  /* Careful with order! Logging cannot happen after we close FDs */
1099  ast_log(LOG_WARNING, "Unable to remove capabilities.\n");
1100  }
1101  cap_free(cap);
1102 #endif
1103 #ifdef HAVE_WORKING_FORK
1105  ast_set_priority(0);
1106  /* Close file descriptors and launch system command */
1107  ast_close_fds_above_n(STDERR_FILENO);
1108 #endif
1109  execl("/bin/sh", "/bin/sh", "-c", s, (char *) NULL);
1110  _exit(1);
1111  } else if (pid > 0) {
1112  for (;;) {
1113  res = wait4(pid, &status, 0, &rusage);
1114  if (res > -1) {
1115  res = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
1116  break;
1117  } else if (errno != EINTR)
1118  break;
1119  }
1120  } else {
1121  ast_log(LOG_WARNING, "Fork failed: %s\n", strerror(errno));
1122  res = -1;
1123  }
1124 
1126 #else /* !defined(HAVE_WORKING_FORK) && !defined(HAVE_WORKING_VFORK) */
1127  res = -1;
1128 #endif
1129 
1130  return res;
1131 }
pid_t pid
Definition: app.c:69
#define LOG_WARNING
Definition: logger.h:144
#define WIFEXITED(status)
Definition: private.h:105
void ast_unreplace_sigchld(void)
Restore the SIGCHLD handler.
Definition: asterisk.c:1062
#define WEXITSTATUS(status)
Definition: private.h:108
int ast_set_priority(int)
We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy ac...
Definition: asterisk.c:1650
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int errno
void ast_close_fds_above_n(int n)
Common routine for child processes, to close all fds prior to exec(2)
Definition: app.c:2237
void ast_replace_sigchld(void)
Replace the SIGCHLD handler.
Definition: asterisk.c:1047
jack_status_t status
Definition: app_jack.c:143
#define ast_opt_high_priority
Definition: options.h:108
void ast_set_lock_type ( enum AST_LOCK_TYPE  type)

Set the type of locks used by ast_lock_path()

Parameters
typethe locking type to use

Definition at line 1647 of file app.c.

References ast_lock_type, and type.

Referenced by ast_readconfig().

1648 {
1649  ast_lock_type = type;
1650 }
static const char type[]
Definition: chan_nbs.c:57
static enum AST_LOCK_TYPE ast_lock_type
Definition: app.c:229
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 2210 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().

2211 {
2212  char next, *buf;
2213  size_t offset = 0;
2214  size_t consumed;
2215 
2216  if (strchr(stream, '\\')) {
2217  while (!ast_get_encoded_char(stream, &next, &consumed)) {
2218  if (offset + 2 > ast_str_size(*str) && maxlen > -1) {
2219  ast_str_make_space(str, maxlen > 0 ? maxlen : (ast_str_size(*str) + 48) * 2 - 48);
2220  }
2221  if (offset + 2 > ast_str_size(*str)) {
2222  break;
2223  }
2224  buf = ast_str_buffer(*str);
2225  buf[offset++] = next;
2226  stream += consumed;
2227  }
2228  buf = ast_str_buffer(*str);
2229  buf[offset++] = '\0';
2230  ast_str_update(*str);
2231  } else {
2232  ast_str_set(str, maxlen, "%s", stream);
2233  }
2234  return 0;
2235 }
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition: strings.h:482
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:874
int ast_str_make_space(struct ast_str **buf, size_t new_len)
Definition: strings.h:588
int ast_get_encoded_char(const char *stream, char *result, size_t *consumed)
Decode an encoded control or extended ASCII character.
Definition: app.c:2122
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
Definition: strings.h:446
AST_THREADSTORAGE_EXTERNAL ( 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().

413 {
414  ast_has_voicemail_func = NULL;
415  ast_inboxcount_func = NULL;
416  ast_inboxcount2_func = NULL;
417  ast_messagecount_func = NULL;
418  ast_sayname_func = NULL;
419 }
static int(* ast_messagecount_func)(const char *context, const char *mailbox, const char *folder)
Definition: app.c:397
static int(* ast_sayname_func)(struct ast_channel *chan, const char *mailbox, const char *context)
Definition: app.c:396
static int(* ast_inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs)
Definition: app.c:394
static int(* ast_has_voicemail_func)(const char *mailbox, const char *folder)
Definition: app.c:393
static int(* ast_inboxcount2_func)(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
Definition: app.c:395
int ast_unlock_path ( const char *  path)

Unlock a path.

Definition at line 1668 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().

1669 {
1670  int r = 0;
1671 
1672  switch (ast_lock_type) {
1674  r = ast_unlock_path_lockfile(path);
1675  break;
1676  case AST_LOCK_TYPE_FLOCK:
1677  r = ast_unlock_path_flock(path);
1678  break;
1679  }
1680 
1681  return r;
1682 }
static int ast_unlock_path_lockfile(const char *path)
Definition: app.c:1495
static int ast_unlock_path_flock(const char *path)
Definition: app.c:1617
static enum AST_LOCK_TYPE ast_lock_type
Definition: app.c:229
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 1062 of file asterisk.c.

References ast_mutex_lock, ast_mutex_unlock, safe_system_level, safe_system_lock, and safe_system_prev_handler.

Referenced by ast_safe_fork_cleanup(), and ast_safe_system().

1063 {
1064  unsigned int level;
1065 
1067  level = --safe_system_level;
1068 
1069  /* only restore the handler if we are the last one */
1070  if (level == 0) {
1071  sigaction(SIGCHLD, &safe_system_prev_handler, NULL);
1072  }
1073 
1075 }
static ast_mutex_t safe_system_lock
Definition: asterisk.c:1041
static struct sigaction safe_system_prev_handler
Definition: asterisk.c:1045
#define ast_mutex_lock(a)
Definition: lock.h:155
static unsigned int safe_system_level
Keep track of how many threads are currently trying to wait*() on a child process.
Definition: asterisk.c:1044
#define ast_mutex_unlock(a)
Definition: lock.h:156