Wed Oct 28 11:45:43 2009

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_ivr_menu
struct  ast_ivr_option

Defines

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

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

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.
int ast_app_dtget (struct ast_channel *chan, const char *context, char *collect, size_t size, int maxlen, int timeout)
 Present a dialtone and collect a certain length extension.
int ast_app_getdata (struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout)
 Plays a stream and gets DTMF data from a channel.
int ast_app_getdata_full (struct ast_channel *c, char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd)
 Full version with audiofd and controlfd. NOTE: returns '2' on ctrlfd available, not '1' like other full functions.
int ast_app_group_discard (struct ast_channel *chan)
 Discard all group counting for a channel.
int ast_app_group_get_count (const char *group, const char *category)
 Get the current channel count of the specified group and category.
struct ast_group_infoast_app_group_list_head (void)
 Get the head of the group count list.
int ast_app_group_list_rdlock (void)
 Read Lock the group count list.
int ast_app_group_list_unlock (void)
 Unlock the group count list.
int ast_app_group_list_wrlock (void)
 Write Lock the group count list.
int ast_app_group_match_get_count (const char *groupmatch, const char *category)
 Get the current channel count of all groups that match the specified pattern and category.
int ast_app_group_set_channel (struct ast_channel *chan, const char *data)
 Set the group for a channel, splitting the provided data into group and category, if specified.
int ast_app_group_split_group (const char *data, char *group, int group_max, char *category, int category_max)
 Split a group string into group and category, returning a default category if none is provided.
int ast_app_group_update (struct ast_channel *oldchan, struct ast_channel *newchan)
 Update all group counting for a channel to a new one.
int ast_app_has_voicemail (const char *mailbox, const char *folder)
 Determine if a given mailbox has any voicemail.
int ast_app_inboxcount (const char *mailbox, int *newmsgs, int *oldmsgs)
 Determine number of new/old messages in a mailbox.
int ast_app_messagecount (const char *context, const char *mailbox, const char *folder)
 Determine number of messages in a given mailbox and folder.
void ast_app_options2str64 (const struct ast_app_option *options, struct ast_flags64 *flags, char *buf, size_t len)
 Given a list of options array, return an option string based on passed flags.
int ast_app_parse_options (const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
 Parses a string containing application options and sets flags/arguments.
int ast_app_parse_options64 (const struct ast_app_option *options, struct ast_flags64 *flags, char **args, char *optstr)
 Parses a string containing application options and sets flags/arguments.
int ast_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.
int ast_dtmf_stream (struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between, unsigned int duration)
 Send DTMF to a channel.
int ast_get_encoded_char (const char *stream, char *result, size_t *consumed)
 Decode an encoded control or extended ASCII character.
int ast_get_encoded_str (const char *stream, char *result, size_t result_size)
 Decode a string which may contain multiple encoded control or extended ASCII characters.
void ast_install_vm_functions (int(*has_voicemail_func)(const char *mailbox, const char *folder), int(*inboxcount_func)(const char *mailbox, int *newmsgs, int *oldmsgs), int(*messagecount_func)(const char *context, const char *mailbox, const char *folder))
int ast_ivr_menu_run (struct ast_channel *c, struct ast_ivr_menu *menu, void *cbdata)
 Runs an IVR menu.
int ast_linear_stream (struct ast_channel *chan, const char *filename, int fd, int allowoverride)
 Stream a filename (or file descriptor) as a generator.
enum AST_LOCK_RESULT ast_lock_path (const char *path)
 Lock a filesystem path.
int ast_play_and_prepend (struct ast_channel *chan, char *playfile, char *recordfile, int maxtime_sec, char *fmt, int *duration, int beep, int silencethreshold, int maxsilence_ms)
 Record a message and prepend the message to the given record file after playing the optional playfile (or a beep), storing the duration in 'duration' and with a maximum permitted silence time in milliseconds of 'maxsilence' under 'silencethreshold' or use '-1' for either or both parameters for defaults.
int ast_play_and_record (struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime_sec, const char *fmt, int *duration, int silencethreshold, int maxsilence_ms, const char *path)
 Record a file for a max amount of time (in seconds), in a given list of formats separated by '|', outputting the duration of the recording, and with a maximum
permitted silence time in milliseconds of 'maxsilence' under 'silencethreshold' or use '-1' for either or both parameters for defaults. calls ast_unlock_path() on 'path' if passed.
int ast_play_and_record_full (struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime_sec, const char *fmt, int *duration, int silencethreshold, int maxsilence_ms, const char *path, const char *acceptdtmf, const char *canceldtmf)
int ast_play_and_wait (struct ast_channel *chan, const char *fn)
 Play a stream and wait for a digit, returning the digit that was pressed.
char * ast_read_textfile (const char *file)
 Read a file into asterisk.
int ast_record_review (struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, const char *path)
 Allow to record message and have a review option.
void ast_replace_sigchld (void)
 Replace the SIGCHLD handler.
int ast_safe_system (const char *s)
 Safely spawn an external program while closing file descriptors.
void ast_set_lock_type (enum AST_LOCK_TYPE type)
 Set the type of locks used by ast_lock_path().
int ast_str_get_encoded_str (struct ast_str **str, int maxlen, const char *stream)
 Decode a stream of encoded control or extended ASCII characters.
void ast_uninstall_vm_functions (void)
int ast_unlock_path (const char *path)
 Unlock a path.
void ast_unreplace_sigchld (void)
 Restore the SIGCHLD handler.


Detailed Description

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

Definition in file app.h.


Define Documentation

#define AST_APP_ARG ( name   )     char *name

Define an application argument.

Parameters:
name The name of the argument

Definition at line 277 of file app.h.

Referenced by acf_channel_read(), acf_curl_exec(), acf_if(), acf_import(), acf_isexten_exec(), acf_jabberstatus_read(), acf_mailbox_exists(), acf_odbc_read(), acf_odbc_write(), acf_rand_exec(), acf_sprintf(), acf_strftime(), acf_strptime(), acf_version_exec(), acf_vmcount_exec(), add_agent(), admin_exec(), agi_exec_full(), aji_send_exec(), aji_status_exec(), app_exec(), aqm_exec(), array(), astman_get_variables(), asyncgoto_exec(), attempt_reconnect(), auth_exec(), background_detect_exec(), bridge_exec(), build_profile(), cdr_read(), cdr_write(), chanavail_exec(), channel_admin_exec(), chanspy_exec(), collect_function_digits(), conf_exec(), controlplayback_exec(), count_exec(), cut_internal(), 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_read(), filter(), find_conf(), forkcdr_exec(), func_header_read(), function_agent(), function_autopatchup(), function_db_delete(), function_db_exists(), function_db_read(), function_db_write(), function_enum(), function_fieldqty(), function_ilink(), function_realtime_read(), function_realtime_readdestroy(), function_realtime_store(), function_realtime_write(), function_remote(), gosub_exec(), gosubif_exec(), hash_read(), hash_write(), hint_read(), iconv_read(), init_acf_query(), isAnsweringMachine(), isexten_function_read(), jack_exec(), load_rpt_vars(), log_exec(), login_exec(), math(), misdn_check_l2l1(), mixmonitor_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), oss_call(), oss_request(), parkandannounce_exec(), pbx_builtin_background(), pbx_builtin_setvar_multiple(), pbx_builtin_waitexten(), play_moh_exec(), playback_exec(), pp_each_user_exec(), pqm_exec(), privacy_exec(), ql_exec(), queue_exec(), queue_function_memberpenalty_read(), queue_function_memberpenalty_write(), rcvfax_exec(), read_exec(), readexten_exec(), record_exec(), regex(), reload_queues(), retrydial_exec(), rpt_exec(), rqm_exec(), sayunixtime_exec(), senddtmf_exec(), sendtext_exec(), sendurl_exec(), shared_read(), shared_write(), sla_trunk_exec(), smdi_msg_read(), smdi_msg_retrieve_read(), sms_exec(), sndfax_exec(), softhangup_exec(), speech_background(), speech_load(), start_moh_exec(), start_monitor_exec(), transfer_exec(), upqm_exec(), userevent_exec(), verbose_exec(), vm_box_exists(), vm_exec(), vm_execmain(), and zapateller_exec().

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

Declares an application option that does not accept an argument.

Parameters:
option The single character representing the option
flagno The flag index to be set if this option is present
See also:
AST_APP_OPTIONS, ast_app_parse_options

Definition at line 444 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:
option The single character representing the option
flagno The flag index to be set if this option is present
argno The index into the argument array where the argument should be placed
See also:
AST_APP_OPTIONS, ast_app_parse_options

Definition at line 455 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:
holder The name of the array to be created
options The 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 {
        OPT_JUMP = (1 << 0),
        OPT_BLAH = (1 << 1),
        OPT_BLORT = (1 << 2),
  } my_app_option_flags;

  enum {
        OPT_ARG_BLAH = 0,
        OPT_ARG_BLORT,
        !! this entry tells how many possible arguments there are,
           and must be the last entry in the list
        OPT_ARG_ARRAY_SIZE,
  } my_app_option_args;

  AST_APP_OPTIONS(my_app_options, {
        AST_APP_OPTION('j', OPT_JUMP),
        AST_APP_OPTION_ARG('b', OPT_BLAH, OPT_ARG_BLAH),
        AST_APP_OPTION_BLORT('B', OPT_BLORT, OPT_ARG_BLORT),
  });

  static int my_app_exec(struct ast_channel *chan, void *data)
  {
   char *options;
   struct ast_flags opts = { 0, };
   char *opt_args[OPT_ARG_ARRAY_SIZE];

   ... do any argument parsing here ...

   if (ast_parseoptions(my_app_options, &opts, opt_args, options)) {
      ast_module_user_remove(u);
      return -1;
   }
  }

Definition at line 435 of file app.h.

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

#define AST_DECLARE_APP_ARGS ( name,
arglist   )     AST_DEFINE_APP_ARGS_TYPE(, arglist) name

Declare a structure to hold an application's arguments.

Parameters:
name The name of the structure
arglist The 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 294 of file app.h.

Referenced by acf_channel_read(), acf_curl_exec(), acf_if(), acf_import(), acf_isexten_exec(), acf_jabberstatus_read(), acf_mailbox_exists(), acf_odbc_read(), acf_odbc_write(), acf_rand_exec(), acf_sprintf(), acf_strftime(), acf_strptime(), acf_version_exec(), acf_vmcount_exec(), add_agent(), admin_exec(), agi_exec_full(), aji_send_exec(), aji_status_exec(), app_exec(), aqm_exec(), array(), astman_get_variables(), asyncgoto_exec(), attempt_reconnect(), auth_exec(), background_detect_exec(), bridge_exec(), build_profile(), cdr_read(), cdr_write(), chanavail_exec(), channel_admin_exec(), chanspy_exec(), collect_function_digits(), conf_exec(), controlplayback_exec(), count_exec(), cut_internal(), 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_read(), filter(), find_conf(), forkcdr_exec(), func_header_read(), function_agent(), function_autopatchup(), function_db_delete(), function_db_exists(), function_db_read(), function_db_write(), function_enum(), function_fieldqty(), function_ilink(), function_realtime_read(), function_realtime_readdestroy(), function_realtime_store(), function_realtime_write(), function_remote(), gosub_exec(), gosubif_exec(), hash_read(), hash_write(), hint_read(), iconv_read(), init_acf_query(), isAnsweringMachine(), isexten_function_read(), jack_exec(), load_rpt_vars(), log_exec(), login_exec(), math(), misdn_check_l2l1(), mixmonitor_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), oss_call(), oss_request(), parkandannounce_exec(), pbx_builtin_background(), pbx_builtin_setvar_multiple(), pbx_builtin_waitexten(), play_moh_exec(), playback_exec(), pp_each_user_exec(), pqm_exec(), privacy_exec(), ql_exec(), queue_exec(), queue_function_memberpenalty_read(), queue_function_memberpenalty_write(), rcvfax_exec(), read_exec(), readexten_exec(), record_exec(), regex(), reload_queues(), retrydial_exec(), rpt_exec(), rqm_exec(), sayunixtime_exec(), senddtmf_exec(), sendtext_exec(), sendurl_exec(), shared_read(), shared_write(), sla_trunk_exec(), smdi_msg_read(), smdi_msg_retrieve_read(), sms_exec(), sndfax_exec(), softhangup_exec(), speech_background(), speech_load(), start_moh_exec(), start_monitor_exec(), transfer_exec(), upqm_exec(), userevent_exec(), verbose_exec(), vm_box_exists(), vm_exec(), vm_execmain(), and zapateller_exec().

#define AST_DEFINE_APP_ARGS_TYPE ( type,
arglist   ) 

Value:

struct type { \
      unsigned int argc; \
      char *argv[0]; \
      arglist \
   }
Define a structure type to hold an application's arguments.

Parameters:
type The name of the structure type
arglist The 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 310 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 }

Definition at line 78 of file app.h.

#define AST_IVR_FLAG_AUTORESTART   (1 << 0)

Definition at line 76 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:
args An argument structure defined using AST_DECLARE_APP_ARGS
parse A modifiable buffer containing the input to be parsed
sep A nonstandard separator character
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 341 of file app.h.

Referenced by acf_if(), acf_jabberstatus_read(), acf_mailbox_exists(), aji_status_exec(), build_profile(), dialgroup_write(), execif_exec(), function_agent(), function_db_delete(), function_db_exists(), function_db_read(), function_db_write(), function_remote(), oss_call(), oss_request(), pbx_builtin_setvar_multiple(), record_exec(), and regex().

#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 343 of file app.h.

Referenced by gosubif_exec().

#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:
args An argument structure defined using AST_DECLARE_APP_ARGS
parse A 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 326 of file app.h.

Referenced by acf_channel_read(), acf_curl_exec(), acf_import(), acf_isexten_exec(), acf_jabberstatus_read(), acf_odbc_read(), acf_odbc_write(), acf_rand_exec(), acf_sprintf(), acf_strftime(), acf_strptime(), acf_version_exec(), acf_vmcount_exec(), add_agent(), admin_exec(), agi_exec_full(), aji_send_exec(), aji_status_exec(), app_exec(), aqm_exec(), array(), astman_get_variables(), asyncgoto_exec(), attempt_reconnect(), auth_exec(), background_detect_exec(), bridge_exec(), build_profile(), cdr_read(), cdr_write(), chanavail_exec(), channel_admin_exec(), chanspy_exec(), collect_function_digits(), conf_exec(), controlplayback_exec(), count_exec(), cut_internal(), 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_read(), filter(), find_conf(), forkcdr_exec(), func_header_read(), function_autopatchup(), function_enum(), function_fieldqty(), function_ilink(), function_realtime_read(), function_realtime_readdestroy(), function_realtime_store(), function_realtime_write(), function_remote(), hash_read(), hash_write(), hint_read(), iconv_read(), init_acf_query(), isAnsweringMachine(), isexten_function_read(), load_rpt_vars(), log_exec(), login_exec(), math(), misdn_check_l2l1(), mixmonitor_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), parkandannounce_exec(), pbx_builtin_background(), pbx_builtin_setvar_multiple(), pbx_builtin_waitexten(), play_moh_exec(), playback_exec(), pp_each_user_exec(), pqm_exec(), privacy_exec(), ql_exec(), queue_exec(), queue_function_memberpenalty_read(), queue_function_memberpenalty_write(), rcvfax_exec(), read_exec(), readexten_exec(), record_exec(), reload_queues(), retrydial_exec(), rpt_exec(), rqm_exec(), sayunixtime_exec(), senddtmf_exec(), sendtext_exec(), sendurl_exec(), shared_read(), shared_write(), sla_trunk_exec(), smdi_msg_read(), smdi_msg_retrieve_read(), sms_exec(), sndfax_exec(), softhangup_exec(), speech_background(), speech_load(), start_moh_exec(), start_monitor_exec(), transfer_exec(), upqm_exec(), userevent_exec(), verbose_exec(), vm_box_exists(), vm_exec(), vm_execmain(), 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 328 of file app.h.

Referenced by gosub_exec().

#define BEGIN_OPTIONS   {

Definition at line 384 of file app.h.

#define END_OPTIONS   }

Definition at line 385 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 37 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 199 of file app.h.

00199                         {
00200    AST_GETDATA_FAILED = -1,
00201    AST_GETDATA_COMPLETE = 0,
00202    AST_GETDATA_TIMEOUT = 1,
00203    AST_GETDATA_INTERRUPTED = 2,
00204    /*! indicates a user terminated empty string rather than an empty string resulting 
00205     * from a timeout or other factors */
00206    AST_GETDATA_EMPTY_END_TERMINATED = 3,
00207 };

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 39 of file app.h.

00039              {
00040    AST_ACTION_UPONE, /*!< adata is unused */
00041    AST_ACTION_EXIT,  /*!< adata is the return value for ast_ivr_menu_run if channel was not hungup */
00042    AST_ACTION_CALLBACK, /*!< adata is an ast_ivr_callback */
00043    AST_ACTION_PLAYBACK, /*!< adata is file to play */
00044    AST_ACTION_BACKGROUND,  /*!< adata is file to play */
00045    AST_ACTION_PLAYLIST, /*!< adata is list of files, separated by ; to play */
00046    AST_ACTION_MENU,  /*!< adata is a pointer to an ast_ivr_menu */
00047    AST_ACTION_REPEAT,   /*!< adata is max # of repeats, cast to a pointer */
00048    AST_ACTION_RESTART,  /*!< adata is like repeat, but resets repeats to 0 */
00049    AST_ACTION_TRANSFER, /*!< adata is a string with exten\verbatim[@context]\endverbatim */
00050    AST_ACTION_WAITOPTION,  /*!< adata is a timeout, or 0 for defaults */
00051    AST_ACTION_NOOP,  /*!< adata is unused */
00052    AST_ACTION_BACKLIST, /*!< adata is list of files separated by ; allows interruption */
00053 } ast_ivr_action;

Enumerator:
AST_LOCK_SUCCESS 
AST_LOCK_TIMEOUT 
AST_LOCK_PATH_NOT_FOUND 
AST_LOCK_FAILURE 

Definition at line 209 of file app.h.

00209                      {
00210    AST_LOCK_SUCCESS = 0,
00211    AST_LOCK_TIMEOUT = -1,
00212    AST_LOCK_PATH_NOT_FOUND = -2,
00213    AST_LOCK_FAILURE = -3,
00214 };

Type of locking to use in ast_lock_path / ast_unlock_path.

Enumerator:
AST_LOCK_TYPE_LOCKFILE 
AST_LOCK_TYPE_FLOCK 

Definition at line 217 of file app.h.

00217                    {
00218    AST_LOCK_TYPE_LOCKFILE = 0,
00219    AST_LOCK_TYPE_FLOCK = 1,
00220 };


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:
buf The string to be parsed (this must be a writable copy, as it will be modified)
delim The character to be used to delimit arguments
remove_chars Remove backslashes and quote characters, while parsing
array An array of 'char *' to be filled in with pointers to the found arguments
arraylen The number of elements in the array (i.e. the number of arguments you will accept)
Note: if there are more arguments in the string than the array will hold, the last element of the array will contain the remaining arguments, not separated.

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

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

Definition at line 1037 of file app.c.

References quote().

Referenced by ast_app_separate_args().

01038 {
01039    int argc;
01040    char *scan, *wasdelim = NULL;
01041    int paren = 0, quote = 0;
01042 
01043    if (!buf || !array || !arraylen)
01044       return 0;
01045 
01046    memset(array, 0, arraylen * sizeof(*array));
01047 
01048    scan = buf;
01049 
01050    for (argc = 0; *scan && (argc < arraylen - 1); argc++) {
01051       array[argc] = scan;
01052       for (; *scan; scan++) {
01053          if (*scan == '(')
01054             paren++;
01055          else if (*scan == ')') {
01056             if (paren)
01057                paren--;
01058          } else if (*scan == '"' && delim != '"') {
01059             quote = quote ? 0 : 1;
01060             if (remove_chars) {
01061                /* Remove quote character from argument */
01062                memmove(scan, scan + 1, strlen(scan));
01063                scan--;
01064             }
01065          } else if (*scan == '\\') {
01066             if (remove_chars) {
01067                /* Literal character, don't parse */
01068                memmove(scan, scan + 1, strlen(scan));
01069             } else {
01070                scan++;
01071             }
01072          } else if ((*scan == delim) && !paren && !quote) {
01073             wasdelim = scan;
01074             *scan++ = '\0';
01075             break;
01076          }
01077       }
01078    }
01079 
01080    /* If the last character in the original string was the delimiter, then
01081     * there is one additional argument. */
01082    if (*scan || (scan > buf && (scan - 1) == wasdelim)) {
01083       array[argc++] = scan;
01084    }
01085 
01086    return argc;
01087 }

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.

Returns:
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:
chan struct.
context 
collect 
size 
maxlen 
timeout timeout in seconds
Returns:
0 if extension does not exist, 1 if extension exists

Definition at line 66 of file app.c.

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

Referenced by builtin_atxfer(), and builtin_blindtransfer().

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

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:
c Which channel one is interacting with
prompt File 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".
s The location where the DTMF data will be stored
maxlen Max Length of the data
timeout Timeout length waiting for data(in milliseconds). Set to 0 for standard timeout(six seconds), or -1 for no time out.
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:
c The channel to read from
prompt The file to stream to the channel
s The string to read in to. Must be at least the size of your length
maxlen How many digits to read (maximum)
timeout set timeout to 0 for "standard" timeouts. Set timeout to -1 for "ludicrous time" (essentially never times out)

Definition at line 111 of file app.c.

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

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

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

int ast_app_getdata_full ( struct ast_channel c,
char *  prompt,
char *  s,
int  maxlen,
int  timeout,
int  audiofd,
int  ctrlfd 
)

Full version with audiofd and controlfd. NOTE: returns '2' on ctrlfd available, not '1' like other full functions.

Definition at line 162 of file app.c.

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

Referenced by handle_getdata().

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

int ast_app_group_discard ( struct ast_channel chan  ) 

Discard all group counting for a channel.

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

00998 {
00999    struct ast_group_info *gi = NULL;
01000    
01001    AST_RWLIST_WRLOCK(&groups);
01002    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, group_list) {
01003       if (gi->chan == chan) {
01004          AST_RWLIST_REMOVE_CURRENT(group_list);
01005          ast_free(gi);
01006       }
01007    }
01008    AST_RWLIST_TRAVERSE_SAFE_END;
01009    AST_RWLIST_UNLOCK(&groups);
01010    
01011    return 0;
01012 }

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

00936 {
00937    struct ast_group_info *gi = NULL;
00938    int count = 0;
00939 
00940    if (ast_strlen_zero(group))
00941       return 0;
00942    
00943    AST_RWLIST_RDLOCK(&groups);
00944    AST_RWLIST_TRAVERSE(&groups, gi, group_list) {
00945       if (!strcasecmp(gi->group, group) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category))))
00946          count++;
00947    }
00948    AST_RWLIST_UNLOCK(&groups);
00949 
00950    return count;
00951 }

struct ast_group_info* ast_app_group_list_head ( void   )  [read]

Get the head of the group count list.

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

01025 {
01026    return AST_RWLIST_FIRST(&groups);
01027 }

int ast_app_group_list_rdlock ( void   ) 

Read Lock the group count list.

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

01020 {
01021    return AST_RWLIST_RDLOCK(&groups);
01022 }

int ast_app_group_list_unlock ( void   ) 

Unlock the group count list.

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

01030 {
01031    return AST_RWLIST_UNLOCK(&groups);
01032 }

int ast_app_group_list_wrlock ( void   ) 

Write Lock the group count list.

Definition at line 1014 of file app.c.

References AST_RWLIST_WRLOCK.

01015 {
01016    return AST_RWLIST_WRLOCK(&groups);
01017 }

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

00954 {
00955    struct ast_group_info *gi = NULL;
00956    regex_t regexbuf;
00957    int count = 0;
00958 
00959    if (ast_strlen_zero(groupmatch))
00960       return 0;
00961 
00962    /* if regex compilation fails, return zero matches */
00963    if (regcomp(&regexbuf, groupmatch, REG_EXTENDED | REG_NOSUB))
00964       return 0;
00965 
00966    AST_RWLIST_RDLOCK(&groups);
00967    AST_RWLIST_TRAVERSE(&groups, gi, group_list) {
00968       if (!regexec(&regexbuf, gi->group, 0, NULL, 0) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category))))
00969          count++;
00970    }
00971    AST_RWLIST_UNLOCK(&groups);
00972 
00973    regfree(&regexbuf);
00974 
00975    return count;
00976 }

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

00891 {
00892    int res = 0;
00893    char group[80] = "", category[80] = "";
00894    struct ast_group_info *gi = NULL;
00895    size_t len = 0;
00896    
00897    if (ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category)))
00898       return -1;
00899    
00900    /* Calculate memory we will need if this is new */
00901    len = sizeof(*gi) + strlen(group) + 1;
00902    if (!ast_strlen_zero(category))
00903       len += strlen(category) + 1;
00904    
00905    AST_RWLIST_WRLOCK(&groups);
00906    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, group_list) {
00907       if ((gi->chan == chan) && ((ast_strlen_zero(category) && ast_strlen_zero(gi->category)) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) {
00908          AST_RWLIST_REMOVE_CURRENT(group_list);
00909          free(gi);
00910          break;
00911       }
00912    }
00913    AST_RWLIST_TRAVERSE_SAFE_END;
00914 
00915    if (ast_strlen_zero(group)) {
00916       /* Enable unsetting the group */
00917    } else if ((gi = calloc(1, len))) {
00918       gi->chan = chan;
00919       gi->group = (char *) gi + sizeof(*gi);
00920       strcpy(gi->group, group);
00921       if (!ast_strlen_zero(category)) {
00922          gi->category = (char *) gi + sizeof(*gi) + strlen(group) + 1;
00923          strcpy(gi->category, category);
00924       }
00925       AST_RWLIST_INSERT_TAIL(&groups, gi, group_list);
00926    } else {
00927       res = -1;
00928    }
00929    
00930    AST_RWLIST_UNLOCK(&groups);
00931    
00932    return res;
00933 }

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

00864 {
00865    int res = 0;
00866    char tmp[256];
00867    char *grp = NULL, *cat = NULL;
00868 
00869    if (!ast_strlen_zero(data)) {
00870       ast_copy_string(tmp, data, sizeof(tmp));
00871       grp = tmp;
00872       cat = strchr(tmp, '@');
00873       if (cat) {
00874          *cat = '\0';
00875          cat++;
00876       }
00877    }
00878 
00879    if (!ast_strlen_zero(grp))
00880       ast_copy_string(group, grp, group_max);
00881    else
00882       *group = '\0';
00883 
00884    if (!ast_strlen_zero(cat))
00885       ast_copy_string(category, cat, category_max);
00886 
00887    return res;
00888 }

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

00979 {
00980    struct ast_group_info *gi = NULL;
00981 
00982    AST_RWLIST_WRLOCK(&groups);
00983    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&groups, gi, group_list) {
00984       if (gi->chan == old) {
00985          gi->chan = new;
00986       } else if (gi->chan == new) {
00987          AST_RWLIST_REMOVE_CURRENT(group_list);
00988          ast_free(gi);
00989       }
00990    }
00991    AST_RWLIST_TRAVERSE_SAFE_END
00992    AST_RWLIST_UNLOCK(&groups);
00993 
00994    return 0;
00995 }

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

Determine if a given mailbox has any voicemail.

Definition at line 202 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(), and run_externnotify().

00203 {
00204    static int warned = 0;
00205    if (ast_has_voicemail_func)
00206       return ast_has_voicemail_func(mailbox, folder);
00207 
00208    if (!warned) {
00209       ast_verb(3, "Message check requested for mailbox %s/folder %s but voicemail not loaded.\n", mailbox, folder ? folder : "INBOX");
00210       warned++;
00211    }
00212    return 0;
00213 }

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

Determine number of new/old messages in a mailbox.

Definition at line 216 of file app.c.

References ast_inboxcount_func, and ast_verb.

Referenced by action_mailboxcount(), notify_new_message(), sip_send_mwi_to_peer(), unistim_send_mwi_to_peer(), update_registry(), and vm_execmain().

00217 {
00218    static int warned = 0;
00219    if (newmsgs)
00220       *newmsgs = 0;
00221    if (oldmsgs)
00222       *oldmsgs = 0;
00223    if (ast_inboxcount_func)
00224       return ast_inboxcount_func(mailbox, newmsgs, oldmsgs);
00225 
00226    if (!warned) {
00227       warned++;
00228       ast_verb(3, "Message count requested for mailbox %s but voicemail not loaded.\n", mailbox);
00229    }
00230 
00231    return 0;
00232 }

int ast_app_messagecount ( const char *  context,
const char *  mailbox,
const char *  folder 
)

Determine number of messages in a given mailbox and folder.

Definition at line 234 of file app.c.

References ast_messagecount_func, and ast_verb.

Referenced by acf_vmcount_exec().

00235 {
00236    static int warned = 0;
00237    if (ast_messagecount_func)
00238       return ast_messagecount_func(context, mailbox, folder);
00239 
00240    if (!warned) {
00241       warned++;
00242       ast_verb(3, "Message count requested for mailbox %s@%s/%s but voicemail not loaded.\n", mailbox, context, folder);
00243    }
00244 
00245    return 0;
00246 }

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

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

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

Definition at line 1723 of file app.c.

References ast_test_flag64.

01724 {
01725    unsigned int i, found = 0;
01726    for (i = 32; i < 128 && found < len; i++) {
01727       if (ast_test_flag64(flags, options[i].flag)) {
01728          buf[found++] = i;
01729       }
01730    }
01731    buf[found] = '\0';
01732 }

int ast_app_parse_options ( const struct ast_app_option options,
struct ast_flags flags,
char **  args,
char *  optstr 
)

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

Parameters:
options The array of possible options declared with AST_APP_OPTIONS
flags The flag structure to have option flags set
args The array of argument pointers to hold arguments found
optstr The string containing the options to be parsed
Returns:
zero for success, non-zero if an error occurs
See also:
AST_APP_OPTIONS

Definition at line 1647 of file app.c.

References ast_app_option::arg_index, ast_clear_flag, AST_FLAGS_ALL, ast_log(), ast_set_flag, LOG_WARNING, and s.

Referenced by app_exec(), auth_exec(), bridge_exec(), cdr_read(), cdr_write(), chanspy_exec(), conf_exec(), controlplayback_exec(), directory_exec(), disa_exec(), dundi_query_read(), dundifunc_read(), extenspy_exec(), forkcdr_exec(), handle_options(), hint_read(), minivm_accmess_exec(), minivm_greet_exec(), minivm_record_exec(), mixmonitor_exec(), page_exec(), pbx_builtin_background(), pbx_builtin_resetcdr(), pbx_builtin_waitexten(), read_exec(), readexten_exec(), record_exec(), sendurl_exec(), sla_trunk_exec(), sms_exec(), softhangup_exec(), speech_background(), vm_exec(), and vm_execmain().

01648 {
01649    char *s, *arg;
01650    int curarg, res = 0;
01651    unsigned int argloc;
01652 
01653    ast_clear_flag(flags, AST_FLAGS_ALL);
01654 
01655    if (!optstr)
01656       return 0;
01657 
01658    s = optstr;
01659    while (*s) {
01660       curarg = *s++ & 0x7f;   /* the array (in app.h) has 128 entries */
01661       argloc = options[curarg].arg_index;
01662       if (*s == '(') {
01663          /* Has argument */
01664          arg = ++s;
01665          if ((s = strchr(s, ')'))) {
01666             if (argloc)
01667                args[argloc - 1] = arg;
01668             *s++ = '\0';
01669          } else {
01670             ast_log(LOG_WARNING, "Missing closing parenthesis for argument '%c' in string '%s'\n", curarg, arg);
01671             res = -1;
01672             break;
01673          }
01674       } else if (argloc) {
01675          args[argloc - 1] = "";
01676       }
01677       ast_set_flag(flags, options[curarg].flag);
01678    }
01679 
01680    return res;
01681 }

int ast_app_parse_options64 ( const struct ast_app_option options,
struct ast_flags64 flags,
char **  args,
char *  optstr 
)

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

Parameters:
options The array of possible options declared with AST_APP_OPTIONS
flags The 64-bit flag structure to have option flags set
args The array of argument pointers to hold arguments found
optstr The string containing the options to be parsed
Returns:
zero for success, non-zero if an error occurs
See also:
AST_APP_OPTIONS

Definition at line 1687 of file app.c.

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

Referenced by dial_exec_full().

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

int ast_control_streamfile ( struct ast_channel chan,
const char *  file,
const char *  fwd,
const char *  rev,
const char *  stop,
const char *  pause,
const char *  restart,
int  skipms,
long *  offsetms 
)

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

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

Definition at line 415 of file app.c.

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

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

00419 {
00420    char *breaks = NULL;
00421    char *end = NULL;
00422    int blen = 2;
00423    int res;
00424    long pause_restart_point = 0;
00425    long offset = 0;
00426 
00427    if (offsetms) 
00428       offset = *offsetms * 8; /* XXX Assumes 8kHz */
00429 
00430    if (stop)
00431       blen += strlen(stop);
00432    if (pause)
00433       blen += strlen(pause);
00434    if (restart)
00435       blen += strlen(restart);
00436 
00437    if (blen > 2) {
00438       breaks = alloca(blen + 1);
00439       breaks[0] = '\0';
00440       if (stop)
00441          strcat(breaks, stop);
00442       if (pause)
00443          strcat(breaks, pause);
00444       if (restart)
00445          strcat(breaks, restart);
00446    }
00447    if (chan->_state != AST_STATE_UP)
00448       res = ast_answer(chan);
00449 
00450    if (file) {
00451       if ((end = strchr(file, ':'))) {
00452          if (!strcasecmp(end, ":end")) {
00453             *end = '\0';
00454             end++;
00455          }
00456       }
00457    }
00458 
00459    for (;;) {
00460       ast_stopstream(chan);
00461       res = ast_streamfile(chan, file, chan->language);
00462       if (!res) {
00463          if (pause_restart_point) {
00464             ast_seekstream(chan->stream, pause_restart_point, SEEK_SET);
00465             pause_restart_point = 0;
00466          }
00467          else if (end || offset < 0) {
00468             if (offset == -8) 
00469                offset = 0;
00470             ast_verb(3, "ControlPlayback seek to offset %ld from end\n", offset);
00471 
00472             ast_seekstream(chan->stream, offset, SEEK_END);
00473             end = NULL;
00474             offset = 0;
00475          } else if (offset) {
00476             ast_verb(3, "ControlPlayback seek to offset %ld\n", offset);
00477             ast_seekstream(chan->stream, offset, SEEK_SET);
00478             offset = 0;
00479          };
00480          res = ast_waitstream_fr(chan, breaks, fwd, rev, skipms);
00481       }
00482 
00483       if (res < 1)
00484          break;
00485 
00486       /* We go at next loop if we got the restart char */
00487       if (restart && strchr(restart, res)) {
00488          ast_debug(1, "we'll restart the stream here at next loop\n");
00489          pause_restart_point = 0;
00490          continue;
00491       }
00492 
00493       if (pause && strchr(pause, res)) {
00494          pause_restart_point = ast_tellstream(chan->stream);
00495          for (;;) {
00496             ast_stopstream(chan);
00497             res = ast_waitfordigit(chan, 1000);
00498             if (!res)
00499                continue;
00500             else if (res == -1 || strchr(pause, res) || (stop && strchr(stop, res)))
00501                break;
00502          }
00503          if (res == *pause) {
00504             res = 0;
00505             continue;
00506          }
00507       }
00508 
00509       if (res == -1)
00510          break;
00511 
00512       /* if we get one of our stop chars, return it to the calling function */
00513       if (stop && strchr(stop, res))
00514          break;
00515    }
00516 
00517    if (pause_restart_point) {
00518       offset = pause_restart_point;
00519    } else {
00520       if (chan->stream) {
00521          offset = ast_tellstream(chan->stream);
00522       } else {
00523          offset = -8;  /* indicate end of file */
00524       }
00525    }
00526 
00527    if (offsetms) 
00528       *offsetms = offset / 8; /* samples --> ms ... XXX Assumes 8 kHz */
00529 
00530    /* If we are returning a digit cast it as char */
00531    if (res > 0 || chan->stream)
00532       res = (char)res;
00533 
00534    ast_stopstream(chan);
00535 
00536    return res;
00537 }

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

Send DTMF to a channel.

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

Definition at line 248 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(), dial_exec_full(), handle_cli_misdn_send_digit(), senddtmf_exec(), testclient_exec(), and testserver_exec().

00249 {
00250    const char *ptr;
00251    int res = 0;
00252    struct ast_silence_generator *silgen = NULL;
00253 
00254    if (!between)
00255       between = 100;
00256 
00257    if (peer)
00258       res = ast_autoservice_start(peer);
00259 
00260    if (!res)
00261       res = ast_waitfor(chan, 100);
00262 
00263    /* ast_waitfor will return the number of remaining ms on success */
00264    if (res < 0) {
00265       if (peer) {
00266          ast_autoservice_stop(peer);
00267       }
00268       return res;
00269    }
00270 
00271    if (ast_opt_transmit_silence) {
00272       silgen = ast_channel_start_silence_generator(chan);
00273    }
00274 
00275    for (ptr = digits; *ptr; ptr++) {
00276       if (*ptr == 'w') {
00277          /* 'w' -- wait half a second */
00278          if ((res = ast_safe_sleep(chan, 500)))
00279             break;
00280       } else if (strchr("0123456789*#abcdfABCDF", *ptr)) {
00281          /* Character represents valid DTMF */
00282          if (*ptr == 'f' || *ptr == 'F') {
00283             /* ignore return values if not supported by channel */
00284             ast_indicate(chan, AST_CONTROL_FLASH);
00285          } else
00286             ast_senddigit(chan, *ptr, duration);
00287          /* pause between digits */
00288          if ((res = ast_safe_sleep(chan, between)))
00289             break;
00290       } else
00291          ast_log(LOG_WARNING, "Illegal DTMF character '%c' in string. (0-9*#aAbBcCdD allowed)\n", *ptr);
00292    }
00293 
00294    if (peer) {
00295       /* Stop autoservice on the peer channel, but don't overwrite any error condition 
00296          that has occurred previously while acting on the primary channel */
00297       if (ast_autoservice_stop(peer) && !res)
00298          res = -1;
00299    }
00300 
00301    if (silgen) {
00302       ast_channel_stop_silence_generator(chan, silgen);
00303    }
00304 
00305    return res;
00306 }

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

Decode an encoded control or extended ASCII character.

Definition at line 1734 of file app.c.

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

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

01735 {
01736    int i;
01737    *consumed = 1;
01738    *result = 0;
01739    if (ast_strlen_zero(stream)) {
01740       *consumed = 0;
01741       return -1;
01742    }
01743 
01744    if (*stream == '\\') {
01745       *consumed = 2;
01746       switch (*(stream + 1)) {
01747       case 'n':
01748          *result = '\n';
01749          break;
01750       case 'r':
01751          *result = '\r';
01752          break;
01753       case 't':
01754          *result = '\t';
01755          break;
01756       case 'x':
01757          /* Hexadecimal */
01758          if (strchr("0123456789ABCDEFabcdef", *(stream + 2)) && *(stream + 2) != '\0') {
01759             *consumed = 3;
01760             if (*(stream + 2) <= '9')
01761                *result = *(stream + 2) - '0';
01762             else if (*(stream + 2) <= 'F')
01763                *result = *(stream + 2) - 'A' + 10;
01764             else
01765                *result = *(stream + 2) - 'a' + 10;
01766          } else {
01767             ast_log(LOG_ERROR, "Illegal character '%c' in hexadecimal string\n", *(stream + 2));
01768             return -1;
01769          }
01770 
01771          if (strchr("0123456789ABCDEFabcdef", *(stream + 3)) && *(stream + 3) != '\0') {
01772             *consumed = 4;
01773             *result <<= 4;
01774             if (*(stream + 3) <= '9')
01775                *result += *(stream + 3) - '0';
01776             else if (*(stream + 3) <= 'F')
01777                *result += *(stream + 3) - 'A' + 10;
01778             else
01779                *result += *(stream + 3) - 'a' + 10;
01780          }
01781          break;
01782       case '0':
01783          /* Octal */
01784          *consumed = 2;
01785          for (i = 2; ; i++) {
01786             if (strchr("01234567", *(stream + i)) && *(stream + i) != '\0') {
01787                (*consumed)++;
01788                ast_debug(5, "result was %d, ", *result);
01789                *result <<= 3;
01790                *result += *(stream + i) - '0';
01791                ast_debug(5, "is now %d\n", *result);
01792             } else
01793                break;
01794          }
01795          break;
01796       default:
01797          *result = *(stream + 1);
01798       }
01799    } else {
01800       *result = *stream;
01801       *consumed = 1;
01802    }
01803    return 0;
01804 }

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

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

Definition at line 1806 of file app.c.

References ast_get_encoded_char().

Referenced by sip_addheader().

01807 {
01808    char *cur = result;
01809    size_t consumed;
01810 
01811    while (cur < result + result_size - 1 && !ast_get_encoded_char(stream, cur, &consumed)) {
01812       cur++;
01813       stream += consumed;
01814    }
01815    *cur = '\0';
01816    return 0;
01817 }

void ast_install_vm_functions ( int(*)(const char *mailbox, const char *folder)  has_voicemail_func,
int(*)(const char *mailbox, int *newmsgs, int *oldmsgs)  inboxcount_func,
int(*)(const char *context, const char *mailbox, const char *folder)  messagecount_func 
)

Definition at line 186 of file app.c.

References ast_has_voicemail_func, ast_inboxcount_func, and ast_messagecount_func.

Referenced by load_module().

00189 {
00190    ast_has_voicemail_func = has_voicemail_func;
00191    ast_inboxcount_func = inboxcount_func;
00192    ast_messagecount_func = messagecount_func;
00193 }

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

References ast_ivr_menu_run_internal().

Referenced by skel_exec().

01607 {
01608    int res = ast_ivr_menu_run_internal(chan, menu, cbdata);
01609    /* Hide internal coding */
01610    return res > 0 ? 0 : res;
01611 }

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 387 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, and LOG_WARNING.

00388 {
00389    struct linear_state *lin;
00390    char tmpf[256];
00391    int res = -1;
00392    int autoclose = 0;
00393    if (fd < 0) {
00394       if (ast_strlen_zero(filename))
00395          return -1;
00396       autoclose = 1;
00397       if (filename[0] == '/') 
00398          ast_copy_string(tmpf, filename, sizeof(tmpf));
00399       else
00400          snprintf(tmpf, sizeof(tmpf), "%s/%s/%s", ast_config_AST_DATA_DIR, "sounds", filename);
00401       if ((fd = open(tmpf, O_RDONLY)) < 0) {
00402          ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", tmpf, strerror(errno));
00403          return -1;
00404       }
00405    }
00406    if ((lin = ast_calloc(1, sizeof(*lin)))) {
00407       lin->fd = fd;
00408       lin->allowoverride = allowoverride;
00409       lin->autoclose = autoclose;
00410       res = ast_activate_generator(chan, &linearstream, lin);
00411    }
00412    return res;
00413 }

enum AST_LOCK_RESULT ast_lock_path ( const char *  path  ) 

Lock a filesystem path.

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

Definition at line 1287 of file app.c.

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

Referenced by vm_lock_path().

01288 {
01289    enum AST_LOCK_RESULT r = AST_LOCK_FAILURE;
01290 
01291    switch (ast_lock_type) {
01292    case AST_LOCK_TYPE_LOCKFILE:
01293       r = ast_lock_path_lockfile(path);
01294       break;
01295    case AST_LOCK_TYPE_FLOCK:
01296       r = ast_lock_path_flock(path);
01297       break;
01298    }
01299 
01300    return r;
01301 }

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

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

Definition at line 856 of file app.c.

References __ast_play_and_record().

Referenced by vm_forwardoptions().

00857 {
00858    return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, beep, silencethreshold, maxsilence, NULL, 1, default_acceptdtmf, default_canceldtmf);
00859 }

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

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

Definition at line 851 of file app.c.

References __ast_play_and_record().

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

00852 {
00853    return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, 0, silencethreshold, maxsilence, path, 0, default_acceptdtmf, default_canceldtmf);
00854 }

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

Definition at line 846 of file app.c.

References __ast_play_and_record(), and S_OR.

Referenced by play_record_review().

00847 {
00848    return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, 0, silencethreshold, maxsilence, path, 0, S_OR(acceptdtmf, default_acceptdtmf), S_OR(canceldtmf, default_canceldtmf));
00849 }

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

char* ast_read_textfile ( const char *  file  ) 

Read a file into asterisk.

Definition at line 1613 of file app.c.

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

Referenced by file_read(), and readfile_exec().

01614 {
01615    int fd, count = 0, res;
01616    char *output = NULL;
01617    struct stat filesize;
01618 
01619    if (stat(filename, &filesize) == -1) {
01620       ast_log(LOG_WARNING, "Error can't stat %s\n", filename);
01621       return NULL;
01622    }
01623 
01624    count = filesize.st_size + 1;
01625 
01626    if ((fd = open(filename, O_RDONLY)) < 0) {
01627       ast_log(LOG_WARNING, "Cannot open file '%s' for reading: %s\n", filename, strerror(errno));
01628       return NULL;
01629    }
01630 
01631    if ((output = ast_malloc(count))) {
01632       res = read(fd, output, count - 1);
01633       if (res == count - 1) {
01634          output[res] = '\0';
01635       } else {
01636          ast_log(LOG_WARNING, "Short read of %s (%d of %d): %s\n", filename, res, count - 1, strerror(errno));
01637          ast_free(output);
01638          output = NULL;
01639       }
01640    }
01641 
01642    close(fd);
01643 
01644    return output;
01645 }

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

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

Referenced by conf_run().

01320 {
01321    int silencethreshold = 128; 
01322    int maxsilence = 0;
01323    int res = 0;
01324    int cmd = 0;
01325    int max_attempts = 3;
01326    int attempts = 0;
01327    int recorded = 0;
01328    int message_exists = 0;
01329    /* Note that urgent and private are for flagging messages as such in the future */
01330 
01331    /* barf if no pointer passed to store duration in */
01332    if (!duration) {
01333       ast_log(LOG_WARNING, "Error ast_record_review called without duration pointer\n");
01334       return -1;
01335    }
01336 
01337    cmd = '3';   /* Want to start by recording */
01338 
01339    while ((cmd >= 0) && (cmd != 't')) {
01340       switch (cmd) {
01341       case '1':
01342          if (!message_exists) {
01343             /* In this case, 1 is to record a message */
01344             cmd = '3';
01345             break;
01346          } else {
01347             ast_stream_and_wait(chan, "vm-msgsaved", "");
01348             cmd = 't';
01349             return res;
01350          }
01351       case '2':
01352          /* Review */
01353          ast_verb(3, "Reviewing the recording\n");
01354          cmd = ast_stream_and_wait(chan, recordfile, AST_DIGIT_ANY);
01355          break;
01356       case '3':
01357          message_exists = 0;
01358          /* Record */
01359          if (recorded == 1)
01360             ast_verb(3, "Re-recording\n");
01361          else  
01362             ast_verb(3, "Recording\n");
01363          recorded = 1;
01364          cmd = ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, silencethreshold, maxsilence, path);
01365          if (cmd == -1) {
01366          /* User has hung up, no options to give */
01367             return cmd;
01368          }
01369          if (cmd == '0') {
01370             break;
01371          } else if (cmd == '*') {
01372             break;
01373          } 
01374          else {
01375             /* If all is well, a message exists */
01376             message_exists = 1;
01377             cmd = 0;
01378          }
01379          break;
01380       case '4':
01381       case '5':
01382       case '6':
01383       case '7':
01384       case '8':
01385       case '9':
01386       case '*':
01387       case '#':
01388          cmd = ast_play_and_wait(chan, "vm-sorry");
01389          break;
01390       default:
01391          if (message_exists) {
01392             cmd = ast_play_and_wait(chan, "vm-review");
01393          }
01394          else {
01395             cmd = ast_play_and_wait(chan, "vm-torerecord");
01396             if (!cmd)
01397                cmd = ast_waitfordigit(chan, 600);
01398          }
01399          
01400          if (!cmd)
01401             cmd = ast_waitfordigit(chan, 6000);
01402          if (!cmd) {
01403             attempts++;
01404          }
01405          if (attempts > max_attempts) {
01406             cmd = 't';
01407          }
01408       }
01409    }
01410    if (cmd == 't')
01411       cmd = 0;
01412    return cmd;
01413 }

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

00830 {
00831    unsigned int level;
00832 
00833    ast_mutex_lock(&safe_system_lock);
00834    level = safe_system_level++;
00835 
00836    /* only replace the handler if it has not already been done */
00837    if (level == 0)
00838       safe_system_prev_handler = signal(SIGCHLD, null_sig_handler);
00839 
00840    ast_mutex_unlock(&safe_system_lock);
00841 }

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 857 of file asterisk.c.

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

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

00858 {
00859    pid_t pid;
00860 #ifdef HAVE_WORKING_FORK
00861    int x;
00862 #endif
00863    int res;
00864    struct rusage rusage;
00865    int status;
00866 
00867 #if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK)
00868    ast_replace_sigchld();
00869 
00870 #ifdef HAVE_WORKING_FORK
00871    pid = fork();
00872 #else
00873    pid = vfork();
00874 #endif   
00875 
00876    if (pid == 0) {
00877 #ifdef HAVE_CAP
00878       cap_t cap = cap_from_text("cap_net_admin-eip");
00879 
00880       if (cap_set_proc(cap)) {
00881          /* Careful with order! Logging cannot happen after we close FDs */
00882          ast_log(LOG_WARNING, "Unable to remove capabilities.\n");
00883       }
00884       cap_free(cap);
00885 #endif
00886 #ifdef HAVE_WORKING_FORK
00887       if (ast_opt_high_priority)
00888          ast_set_priority(0);
00889       /* Close file descriptors and launch system command */
00890       for (x = STDERR_FILENO + 1; x < 4096; x++)
00891          close(x);
00892 #endif
00893       execl("/bin/sh", "/bin/sh", "-c", s, (char *) NULL);
00894       _exit(1);
00895    } else if (pid > 0) {
00896       for (;;) {
00897          res = wait4(pid, &status, 0, &rusage);
00898          if (res > -1) {
00899             res = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
00900             break;
00901          } else if (errno != EINTR) 
00902             break;
00903       }
00904    } else {
00905       ast_log(LOG_WARNING, "Fork failed: %s\n", strerror(errno));
00906       res = -1;
00907    }
00908 
00909    ast_unreplace_sigchld();
00910 #else /* !defined(HAVE_WORKING_FORK) && !defined(HAVE_WORKING_VFORK) */
00911    res = -1;
00912 #endif
00913 
00914    return res;
00915 }

void ast_set_lock_type ( enum AST_LOCK_TYPE  type  ) 

Set the type of locks used by ast_lock_path().

Parameters:
type the locking type to use

Definition at line 1282 of file app.c.

Referenced by ast_readconfig().

01283 {
01284    ast_lock_type = type;
01285 }

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

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

Referenced by system_exec_helper().

01820 {
01821    char next, *buf;
01822    size_t offset = 0;
01823    size_t consumed;
01824 
01825    if (strchr(stream, '\\')) {
01826       while (!ast_get_encoded_char(stream, &next, &consumed)) {
01827          if (offset + 2 > ast_str_size(*str) && maxlen > -1) {
01828             ast_str_make_space(str, maxlen > 0 ? maxlen : (ast_str_size(*str) + 48) * 2 - 48);
01829          }
01830          if (offset + 2 > ast_str_size(*str)) {
01831             break;
01832          }
01833          buf = ast_str_buffer(*str);
01834          buf[offset++] = next;
01835          stream += consumed;
01836       }
01837       buf = ast_str_buffer(*str);
01838       buf[offset++] = '\0';
01839       ast_str_update(*str);
01840    } else {
01841       ast_str_set(str, maxlen, "%s", stream);
01842    }
01843    return 0;
01844 }

void ast_uninstall_vm_functions ( void   ) 

Definition at line 195 of file app.c.

References ast_has_voicemail_func, ast_inboxcount_func, and ast_messagecount_func.

Referenced by unload_module().

00196 {
00197    ast_has_voicemail_func = NULL;
00198    ast_inboxcount_func = NULL;
00199    ast_messagecount_func = NULL;
00200 }

int ast_unlock_path ( const char *  path  ) 

Unlock a path.

Definition at line 1303 of file app.c.

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

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

01304 {
01305    int r = 0;
01306 
01307    switch (ast_lock_type) {
01308    case AST_LOCK_TYPE_LOCKFILE:
01309       r = ast_unlock_path_lockfile(path);
01310       break;
01311    case AST_LOCK_TYPE_FLOCK:
01312       r = ast_unlock_path_flock(path);
01313       break;
01314    }
01315 
01316    return r;
01317 }

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 843 of file asterisk.c.

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

Referenced by agi_exec_full(), and ast_safe_system().

00844 {
00845    unsigned int level;
00846 
00847    ast_mutex_lock(&safe_system_lock);
00848    level = --safe_system_level;
00849 
00850    /* only restore the handler if we are the last one */
00851    if (level == 0)
00852       signal(SIGCHLD, safe_system_prev_handler);
00853 
00854    ast_mutex_unlock(&safe_system_lock);
00855 }


Generated on Wed Oct 28 11:45:44 2009 for Asterisk - the Open Source PBX by  doxygen 1.5.6