pbx.h File Reference

Core PBX routines and definitions. More...

#include "asterisk/channel.h"
#include "asterisk/sched.h"
#include "asterisk/devicestate.h"
#include "asterisk/presencestate.h"
#include "asterisk/chanvars.h"
#include "asterisk/hashtab.h"
#include "asterisk/stringfields.h"
#include "asterisk/xmldoc.h"
#include "asterisk/format.h"

Include dependency graph for pbx.h:

Go to the source code of this file.

Data Structures

struct  ast_custom_function
 Data structure associated with a custom dialplan function. More...
struct  ast_device_state_info
struct  ast_pbx
struct  ast_pbx_args
 Options for ast_pbx_run(). More...
struct  ast_state_cb_info
struct  ast_switch
struct  ast_timing
struct  pbx_find_info

Defines

#define ast_custom_function_register(acf)   __ast_custom_function_register(acf, ast_module_info->self)
 Register a custom function.
#define ast_custom_function_register_escalating(acf, escalation)   __ast_custom_function_register_escalating(acf, escalation, ast_module_info->self)
 Register a custom function which requires escalated privileges.
#define AST_MAX_APP   32
#define AST_PBX_GOTO_FAILED   -3
#define AST_PBX_KEEP   0
#define AST_PBX_MAX_STACK   128
#define AST_PBX_REPLACE   1
#define PRIORITY_HINT   -1
#define STATUS_NO_CONTEXT   1
#define STATUS_NO_EXTENSION   2
#define STATUS_NO_LABEL   4
#define STATUS_NO_PRIORITY   3
#define STATUS_SUCCESS   5
#define AST_PBX_ERROR   1
#define AST_PBX_HANGUP   -1
 Special return values from applications to the PBX.
#define AST_PBX_INCOMPLETE   12
#define AST_PBX_OK   0

Typedefs

typedef void(* ast_state_cb_destroy_type )(int id, void *data)
 Typedef for devicestate and hint callback removal indication callback.
typedef int(* ast_state_cb_type )(char *context, char *id, struct ast_state_cb_info *info, void *data)
 Typedef for devicestate and hint callbacks.
typedef int( ast_switch_f )(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
 All switch functions have the same interface, so define a type for them.

Enumerations

enum  ast_custom_function_escalation { AST_CFE_NONE, AST_CFE_READ, AST_CFE_WRITE, AST_CFE_BOTH }
 Description of the ways in which a function may escalate privileges. More...
enum  ast_ext_matchcid_types { AST_EXT_MATCHCID_OFF = 0, AST_EXT_MATCHCID_ON = 1, AST_EXT_MATCHCID_ANY = 2 }
 extension matchcid types More...
enum  ast_extension_states {
  AST_EXTENSION_REMOVED = -2, AST_EXTENSION_DEACTIVATED = -1, AST_EXTENSION_NOT_INUSE = 0, AST_EXTENSION_INUSE = 1 << 0,
  AST_EXTENSION_BUSY = 1 << 1, AST_EXTENSION_UNAVAILABLE = 1 << 2, AST_EXTENSION_RINGING = 1 << 3, AST_EXTENSION_ONHOLD = 1 << 4,
  AST_EXTENSION_REMOVED = -2, AST_EXTENSION_DEACTIVATED = -1, AST_EXTENSION_NOT_INUSE = 0, AST_EXTENSION_INUSE = 1 << 0,
  AST_EXTENSION_BUSY = 1 << 1, AST_EXTENSION_UNAVAILABLE = 1 << 2, AST_EXTENSION_RINGING = 1 << 3, AST_EXTENSION_ONHOLD = 1 << 4
}
 Extension states. More...
enum  ast_pbx_result { AST_PBX_SUCCESS = 0, AST_PBX_FAILED = -1, AST_PBX_CALL_LIMIT = -2 }
 The result codes when starting the PBX on a channel with ast_pbx_start. More...
enum  ast_state_cb_update_reason { AST_HINT_UPDATE_DEVICE = 1, AST_HINT_UPDATE_PRESENCE = 2 }
enum  ext_match_t {
  E_MATCHMORE = 0x00, E_CANMATCH = 0x01, E_MATCH = 0x02, E_MATCH_MASK = 0x03,
  E_SPAWN = 0x12, E_FINDLABEL = 0x22, E_MATCHMORE = 0x00, E_CANMATCH = 0x01,
  E_MATCH = 0x02, E_MATCH_MASK = 0x03, E_SPAWN = 0x12, E_FINDLABEL = 0x22
}

Functions

int __ast_custom_function_register (struct ast_custom_function *acf, struct ast_module *mod)
 Register a custom function.
int __ast_custom_function_register_escalating (struct ast_custom_function *acf, enum ast_custom_function_escalation escalation, struct ast_module *mod)
 Register a custom function which requires escalated privileges.
int ast_active_calls (void)
 Retrieve the number of active calls.
int ast_add_extension (const char *context, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar)
 Add and extension to an extension context.
int ast_add_extension2 (struct ast_context *con, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar)
 Add an extension to an extension context, this time with an ast_context *.
int ast_add_extension2_nolock (struct ast_context *con, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar)
 Same as ast_add_extension2, but assumes you have already locked context.
int ast_async_goto (struct ast_channel *chan, const char *context, const char *exten, int priority)
 Set the channel to next execute the specified dialplan location.
int ast_async_goto_by_name (const char *chan, const char *context, const char *exten, int priority)
 Set the channel to next execute the specified dialplan location.
int ast_async_goto_if_exists (struct ast_channel *chan, const char *context, const char *exten, int priority)
int ast_async_parseable_goto (struct ast_channel *chan, const char *goto_string)
int ast_build_timing (struct ast_timing *i, const char *info)
 Construct a timing bitmap, for use in time-based conditionals.
int ast_canmatch_extension (struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
 Looks for a valid matching extension.
int ast_check_timing (const struct ast_timing *i)
 Evaluate a pre-constructed bitmap as to whether the current time falls within the range specified.
int ast_check_timing2 (const struct ast_timing *i, const struct timeval tv)
 Evaluate a pre-constructed bitmap as to whether a particular time falls within the range specified.
char * ast_complete_applications (const char *line, const char *word, int state)
 Command completion for the list of installed applications.
int ast_context_add_ignorepat (const char *context, const char *ignorepat, const char *registrar)
 Add an ignorepat.
int ast_context_add_ignorepat2 (struct ast_context *con, const char *ignorepat, const char *registrar)
int ast_context_add_include (const char *context, const char *include, const char *registrar)
 Add a context include.
int ast_context_add_include2 (struct ast_context *con, const char *include, const char *registrar)
 Add a context include.
int ast_context_add_switch (const char *context, const char *sw, const char *data, int eval, const char *registrar)
 Add a switch.
int ast_context_add_switch2 (struct ast_context *con, const char *sw, const char *data, int eval, const char *registrar)
 Adds a switch (first param is a ast_context).
void ast_context_destroy (struct ast_context *con, const char *registrar)
 Destroy a context (matches the specified context (or ANY context if NULL).
struct ast_contextast_context_find (const char *name)
 Find a context.
struct ast_contextast_context_find_or_create (struct ast_context **extcontexts, struct ast_hashtab *exttable, const char *name, const char *registrar)
 Register a new context or find an existing one.
int ast_context_lockmacro (const char *macrocontext)
 locks the macrolock in the given given context
int ast_context_remove_ignorepat (const char *context, const char *ignorepat, const char *registrar)
int ast_context_remove_ignorepat2 (struct ast_context *con, const char *ignorepat, const char *registrar)
int ast_context_remove_include (const char *context, const char *include, const char *registrar)
 Remove a context include.
int ast_context_remove_include2 (struct ast_context *con, const char *include, const char *registrar)
 Removes an include by an ast_context structure.
int ast_context_remove_switch (const char *context, const char *sw, const char *data, const char *registrar)
 Remove a switch.
int ast_context_remove_switch2 (struct ast_context *con, const char *sw, const char *data, const char *registrar)
 This function locks given context, removes switch, unlock context and return.
int ast_context_unlockmacro (const char *macrocontext)
 Unlocks the macrolock in the given context.
int ast_context_verify_includes (struct ast_context *con)
 Verifies includes in an ast_contect structure.
struct ast_custom_functionast_custom_function_find (const char *name)
int ast_custom_function_unregister (struct ast_custom_function *acf)
 Unregister a custom function.
int ast_destroy_timing (struct ast_timing *i)
 Deallocates memory structures associated with a timing bitmap.
enum ast_extension_states ast_devstate_to_extenstate (enum ast_device_state devstate)
 Map devstate to an extension state.
int ast_exists_extension (struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
 Determine whether an extension exists.
int ast_explicit_goto (struct ast_channel *chan, const char *context, const char *exten, int priority)
int ast_extension_close (const char *pattern, const char *data, int needmore)
int ast_extension_cmp (const char *a, const char *b)
 Determine if one extension should match before another.
int ast_extension_match (const char *pattern, const char *extension)
 Determine if a given extension matches a given pattern (in NXX format).
int ast_extension_patmatch (const char *pattern, const char *data)
int ast_extension_state (struct ast_channel *c, const char *context, const char *exten)
 Uses hint and devicestate callback to get the state of an extension.
const char * ast_extension_state2str (int extension_state)
 Return string representation of the state of an extension.
int ast_extension_state_add (const char *context, const char *exten, ast_state_cb_type change_cb, void *data)
 Registers a state change callback.
int ast_extension_state_add_destroy (const char *context, const char *exten, ast_state_cb_type change_cb, ast_state_cb_destroy_type destroy_cb, void *data)
 Registers a state change callback with destructor.
int ast_extension_state_add_destroy_extended (const char *context, const char *exten, ast_state_cb_type change_cb, ast_state_cb_destroy_type destroy_cb, void *data)
 Registers an extended state change callback with destructor.
int ast_extension_state_add_extended (const char *context, const char *exten, ast_state_cb_type change_cb, void *data)
 Registers an extended state change callback.
int ast_extension_state_del (int id, ast_state_cb_type change_cb)
 Deletes a registered state change callback by ID.
int ast_extension_state_extended (struct ast_channel *c, const char *context, const char *exten, struct ao2_container **device_state_info)
 Uses hint and devicestate callback to get the extended state of an extension.
int ast_findlabel_extension (struct ast_channel *c, const char *context, const char *exten, const char *label, const char *callerid)
 Find the priority of an extension that has the specified label.
int ast_findlabel_extension2 (struct ast_channel *c, struct ast_context *con, const char *exten, const char *label, const char *callerid)
 Find the priority of an extension that has the specified label.
int ast_func_read (struct ast_channel *chan, const char *function, char *workspace, size_t len)
 executes a read operation on a function
int ast_func_read2 (struct ast_channel *chan, const char *function, struct ast_str **str, ssize_t maxlen)
 executes a read operation on a function
int ast_func_write (struct ast_channel *chan, const char *function, const char *value)
 executes a write operation on a function
int ast_get_hint (char *hint, int hintsize, char *name, int namesize, struct ast_channel *c, const char *context, const char *exten)
 If an extension hint exists, return non-zero.
int ast_goto_if_exists (struct ast_channel *chan, const char *context, const char *exten, int priority)
int ast_hint_presence_state (struct ast_channel *c, const char *context, const char *exten, char **subtype, char **message)
 Uses hint and presence state callback to get the presence state of an extension.
int ast_ignore_pattern (const char *context, const char *pattern)
 Checks to see if a number should be ignored.
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).
void ast_merge_contexts_and_delete (struct ast_context **extcontexts, struct ast_hashtab *exttable, const char *registrar)
 Merge the temporary contexts into a global contexts list and delete from the global list the ones that are being added.
int ast_parseable_goto (struct ast_channel *chan, const char *goto_string)
void ast_pbx_h_exten_run (struct ast_channel *chan, const char *context)
 Run the h exten from the given context.
void ast_pbx_hangup_handler_destroy (struct ast_channel *chan)
 Destroy the hangup handler container on a channel.
void ast_pbx_hangup_handler_init (struct ast_channel *chan)
 Init the hangup handler container on a channel.
int ast_pbx_hangup_handler_pop (struct ast_channel *chan)
 Pop the top of the channel hangup handler stack.
void ast_pbx_hangup_handler_push (struct ast_channel *chan, const char *handler)
 Push the given hangup handler onto the channel hangup handler stack.
int ast_pbx_hangup_handler_run (struct ast_channel *chan)
 Run all hangup handlers on the channel.
int ast_pbx_outgoing_app (const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *app, const char *appdata, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel, const struct ast_assigned_ids *assignedids)
 Synchronously or asynchronously make an outbound call and execute an application on the channel.
int ast_pbx_outgoing_exten (const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *context, const char *exten, int priority, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel, int early_media, const struct ast_assigned_ids *assignedids)
 Synchronously or asynchronously make an outbound call and send it to a particular extension.
enum ast_pbx_result ast_pbx_run (struct ast_channel *c)
 Execute the PBX in the current thread.
enum ast_pbx_result ast_pbx_run_args (struct ast_channel *c, struct ast_pbx_args *args)
 Execute the PBX in the current thread.
enum ast_pbx_result ast_pbx_start (struct ast_channel *c)
 Create a new thread and start the PBX.
int ast_processed_calls (void)
 Retrieve the total number of calls processed through the PBX since last restart.
int ast_rdlock_context (struct ast_context *con)
 Read locks a given context.
int ast_rdlock_contexts (void)
 Read locks the context list.
int ast_register_switch (struct ast_switch *sw)
 Register an alternative dialplan switch.
int ast_spawn_extension (struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid, int *found, int combined_find_spawn)
 Launch a new extension (i.e. new stack).
int ast_str_get_hint (struct ast_str **hint, ssize_t hintsize, struct ast_str **name, ssize_t namesize, struct ast_channel *c, const char *context, const char *exten)
 If an extension hint exists, return non-zero.
int ast_thread_inhibit_escalations (void)
 Inhibit (in the current thread) the execution of dialplan functions which cause privilege escalations. If pbx_live_dangerously() has been called, this function has no effect.
int ast_unlock_context (struct ast_context *con)
int ast_unlock_contexts (void)
 Unlocks contexts.
void ast_unregister_switch (struct ast_switch *sw)
 Unregister an alternative switch.
int ast_wrlock_context (struct ast_context *con)
 Write locks a given context.
int ast_wrlock_contexts (void)
 Write locks the context list.
void pbx_builtin_clear_globals (void)
const char * pbx_builtin_getvar_helper (struct ast_channel *chan, const char *name)
 Return a pointer to the value of the corresponding channel variable.
void pbx_builtin_pushvar_helper (struct ast_channel *chan, const char *name, const char *value)
 Add a variable to the channel variable stack, without removing any previously set value.
int pbx_builtin_raise_exception (struct ast_channel *chan, const char *data)
int pbx_builtin_serialize_variables (struct ast_channel *chan, struct ast_str **buf)
 Create a human-readable string, specifying all variables and their corresponding values.
int pbx_builtin_setvar (struct ast_channel *chan, const char *data)
 Parse and set a single channel variable, where the name and value are separated with an '=' character.
int pbx_builtin_setvar_helper (struct ast_channel *chan, const char *name, const char *value)
 Add a variable to the channel variable stack, removing the most recently set value for the same name.
int pbx_builtin_setvar_multiple (struct ast_channel *chan, const char *data)
 Parse and set multiple channel variables, where the pairs are separated by the ',' character, and name and value are separated with an '=' character.
int pbx_checkcondition (const char *condition)
 Evaluate a condition.
int pbx_exec (struct ast_channel *c, struct ast_app *app, const char *data)
 Execute an application.
struct ast_extenpbx_find_extension (struct ast_channel *chan, struct ast_context *bypass, struct pbx_find_info *q, const char *context, const char *exten, int priority, const char *label, const char *callerid, enum ext_match_t action)
struct ast_apppbx_findapp (const char *app)
 Look up an application.
void pbx_live_dangerously (int new_live_dangerously)
 Enable/disable the execution of 'dangerous' functions from external protocols (AMI, etc.).
void pbx_retrieve_variable (struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp)
 Retrieve the value of a builtin variable or variable from the channel variable stack.
int pbx_set_autofallthrough (int newval)
int pbx_set_extenpatternmatchnew (int newval)
void pbx_set_overrideswitch (const char *newval)
int ast_context_remove_extension (const char *context, const char *extension, int priority, const char *registrar)
 Simply remove extension from context.
int ast_context_remove_extension2 (struct ast_context *con, const char *extension, int priority, const char *registrar, int already_locked)
 This functionc locks given context, search for the right extension and fires out all peer in this extensions with given priority. If priority is set to 0, all peers are removed. After that, unlock context and return.
int ast_context_remove_extension_callerid (const char *context, const char *extension, int priority, const char *callerid, int matchcid, const char *registrar)
int ast_context_remove_extension_callerid2 (struct ast_context *con, const char *extension, int priority, const char *callerid, int matchcid, const char *registrar, int already_locked)
Functions for returning values from structures

const char * ast_get_context_name (struct ast_context *con)
struct ast_contextast_get_extension_context (struct ast_exten *exten)
const char * ast_get_extension_name (struct ast_exten *exten)
const char * ast_get_ignorepat_name (struct ast_ignorepat *ip)
const char * ast_get_include_name (struct ast_include *include)
const char * ast_get_switch_data (struct ast_sw *sw)
int ast_get_switch_eval (struct ast_sw *sw)
const char * ast_get_switch_name (struct ast_sw *sw)
Registrar info functions ...


const char * ast_get_context_registrar (struct ast_context *c)
const char * ast_get_extension_registrar (struct ast_exten *e)
const char * ast_get_ignorepat_registrar (struct ast_ignorepat *ip)
const char * ast_get_include_registrar (struct ast_include *i)
const char * ast_get_switch_registrar (struct ast_sw *sw)
Other Extension stuff


const char * ast_get_extension_app (struct ast_exten *e)
void * ast_get_extension_app_data (struct ast_exten *e)
const char * ast_get_extension_cidmatch (struct ast_exten *e)
const char * ast_get_extension_label (struct ast_exten *e)
int ast_get_extension_matchcid (struct ast_exten *e)
int ast_get_extension_priority (struct ast_exten *exten)
int ast_hashtab_compare_contexts (const void *ah_a, const void *ah_b)
 hashtable functions for contexts
unsigned int ast_hashtab_hash_contexts (const void *obj)
Substitution routines, using dynamic string buffers


const char * ast_str_retrieve_variable (struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, struct varshead *headp, const char *var)
void ast_str_substitute_variables (struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
void ast_str_substitute_variables_full (struct ast_str **buf, ssize_t maxlen, struct ast_channel *c, struct varshead *headp, const char *templ, size_t *used)
void ast_str_substitute_variables_varshead (struct ast_str **buf, ssize_t maxlen, struct varshead *headp, const char *templ)
Walking functions ...


struct ast_extenast_walk_context_extensions (struct ast_context *con, struct ast_exten *priority)
struct ast_ignorepatast_walk_context_ignorepats (struct ast_context *con, struct ast_ignorepat *ip)
struct ast_includeast_walk_context_includes (struct ast_context *con, struct ast_include *inc)
struct ast_swast_walk_context_switches (struct ast_context *con, struct ast_sw *sw)
struct ast_contextast_walk_contexts (struct ast_context *con)
struct ast_extenast_walk_extension_priorities (struct ast_exten *exten, struct ast_exten *priority)
Substitution routines, using static string buffers
void pbx_substitute_variables_helper (struct ast_channel *c, const char *cp1, char *cp2, int count)
void pbx_substitute_variables_helper_full (struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int cp2_size, size_t *used)
void pbx_substitute_variables_varshead (struct varshead *headp, const char *cp1, char *cp2, int count)


Detailed Description

Core PBX routines and definitions.

Definition in file pbx.h.


Define Documentation

#define ast_custom_function_register ( acf   )     __ast_custom_function_register(acf, ast_module_info->self)

Register a custom function.

Definition at line 1409 of file pbx.h.

Referenced by load_module(), and reload().

#define ast_custom_function_register_escalating ( acf,
escalation   )     __ast_custom_function_register_escalating(acf, escalation, ast_module_info->self)

Register a custom function which requires escalated privileges.

Examples would be SHELL() (for which a read needs permission to execute arbitrary code) or FILE() (for which write needs permission to change files on the filesystem).

Definition at line 1418 of file pbx.h.

Referenced by load_module().

#define AST_MAX_APP   32

Max length of an application

Definition at line 40 of file pbx.h.

Referenced by handle_show_function(), sla_build_station(), and sla_station_destructor().

#define AST_PBX_ERROR   1

Jump to the 'e' exten

Definition at line 50 of file pbx.h.

Referenced by __ast_pbx_run().

#define AST_PBX_GOTO_FAILED   -3

Definition at line 42 of file pbx.h.

Referenced by __ast_goto_if_exists().

#define AST_PBX_HANGUP   -1

Special return values from applications to the PBX.

Jump to the 'h' exten

Definition at line 48 of file pbx.h.

#define AST_PBX_INCOMPLETE   12

Return to PBX matching, allowing more digits for the extension

Definition at line 51 of file pbx.h.

Referenced by __ast_pbx_run(), dial_exec_full(), pbx_builtin_incomplete(), and retrydial_exec().

#define AST_PBX_KEEP   0

Definition at line 43 of file pbx.h.

#define AST_PBX_MAX_STACK   128

Definition at line 1510 of file pbx.h.

#define AST_PBX_OK   0

No errors

Definition at line 49 of file pbx.h.

#define AST_PBX_REPLACE   1

Definition at line 44 of file pbx.h.

#define PRIORITY_HINT   -1

#define STATUS_NO_CONTEXT   1

Definition at line 1505 of file pbx.h.

#define STATUS_NO_EXTENSION   2

Definition at line 1506 of file pbx.h.

#define STATUS_NO_LABEL   4

Definition at line 1508 of file pbx.h.

#define STATUS_NO_PRIORITY   3

Definition at line 1507 of file pbx.h.

#define STATUS_SUCCESS   5

Definition at line 1509 of file pbx.h.


Typedef Documentation

typedef void(* ast_state_cb_destroy_type)(int id, void *data)

Typedef for devicestate and hint callback removal indication callback.

Definition at line 115 of file pbx.h.

typedef int(* ast_state_cb_type)(char *context, char *id, struct ast_state_cb_info *info, void *data)

Typedef for devicestate and hint callbacks.

Definition at line 112 of file pbx.h.

typedef int( ast_switch_f)(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)

All switch functions have the same interface, so define a type for them.

Data structure associated with an Asterisk switch

Definition at line 156 of file pbx.h.


Enumeration Type Documentation

Description of the ways in which a function may escalate privileges.

Enumerator:
AST_CFE_NONE 
AST_CFE_READ 
AST_CFE_WRITE 
AST_CFE_BOTH 

Definition at line 1399 of file pbx.h.

01399                                     {
01400    AST_CFE_NONE,
01401    AST_CFE_READ,
01402    AST_CFE_WRITE,
01403    AST_CFE_BOTH,
01404 };

extension matchcid types

Note:
matchcid in ast_exten retains 0/1, this adds 3rd state for functions to specify all
See also:
ast_context_remove_extension_callerid
Enumerator:
AST_EXT_MATCHCID_OFF  Match only extensions with matchcid=0
AST_EXT_MATCHCID_ON  Match only extensions with matchcid=1 AND cidmatch matches
AST_EXT_MATCHCID_ANY  Match both - used only in functions manipulating ast_exten's

Definition at line 77 of file pbx.h.

00077                             {
00078    AST_EXT_MATCHCID_OFF = 0,  /*!< Match only extensions with matchcid=0 */
00079    AST_EXT_MATCHCID_ON = 1,   /*!< Match only extensions with matchcid=1 AND cidmatch matches */
00080    AST_EXT_MATCHCID_ANY = 2,  /*!< Match both - used only in functions manipulating ast_exten's */
00081 };

Extension states.

Note:
States can be combined Extension and device states in Asterisk
Enumerator:
AST_EXTENSION_REMOVED  Extension removed
AST_EXTENSION_DEACTIVATED  Extension hint removed
AST_EXTENSION_NOT_INUSE  No device INUSE or BUSY
AST_EXTENSION_INUSE  One or more devices INUSE
AST_EXTENSION_BUSY  All devices BUSY
AST_EXTENSION_UNAVAILABLE  All devices UNAVAILABLE/UNREGISTERED
AST_EXTENSION_RINGING  All devices RINGING
AST_EXTENSION_ONHOLD  All devices ONHOLD
AST_EXTENSION_REMOVED  Extension removed
AST_EXTENSION_DEACTIVATED  Extension hint removed
AST_EXTENSION_NOT_INUSE  No device INUSE or BUSY
AST_EXTENSION_INUSE  One or more devices INUSE
AST_EXTENSION_BUSY  All devices BUSY
AST_EXTENSION_UNAVAILABLE  All devices UNAVAILABLE/UNREGISTERED
AST_EXTENSION_RINGING  All devices RINGING
AST_EXTENSION_ONHOLD  All devices ONHOLD

Definition at line 61 of file pbx.h.

00061                           {
00062    AST_EXTENSION_REMOVED = -2,   /*!< Extension removed */
00063    AST_EXTENSION_DEACTIVATED = -1,  /*!< Extension hint removed */
00064    AST_EXTENSION_NOT_INUSE = 0,  /*!< No device INUSE or BUSY  */
00065    AST_EXTENSION_INUSE = 1 << 0, /*!< One or more devices INUSE */
00066    AST_EXTENSION_BUSY = 1 << 1,  /*!< All devices BUSY */
00067    AST_EXTENSION_UNAVAILABLE = 1 << 2, /*!< All devices UNAVAILABLE/UNREGISTERED */
00068    AST_EXTENSION_RINGING = 1 << 3,  /*!< All devices RINGING */
00069    AST_EXTENSION_ONHOLD = 1 << 4,   /*!< All devices ONHOLD */
00070 };

The result codes when starting the PBX on a channel with ast_pbx_start.

Note:
AST_PBX_CALL_LIMIT refers to the maxcalls call limit in asterisk.conf
See also:
ast_pbx_start
Enumerator:
AST_PBX_SUCCESS 
AST_PBX_FAILED 
AST_PBX_CALL_LIMIT 

Definition at line 331 of file pbx.h.

00331                     {
00332    AST_PBX_SUCCESS = 0,
00333    AST_PBX_FAILED = -1,
00334    AST_PBX_CALL_LIMIT = -2,
00335 };

Enumerator:
AST_HINT_UPDATE_DEVICE  The extension state update is a result of a device state changing on the extension.
AST_HINT_UPDATE_PRESENCE  The extension state update is a result of presence state changing on the extension.

Definition at line 89 of file pbx.h.

00089                                 {
00090    /*! The extension state update is a result of a device state changing on the extension. */
00091    AST_HINT_UPDATE_DEVICE = 1,
00092    /*! The extension state update is a result of presence state changing on the extension. */
00093    AST_HINT_UPDATE_PRESENCE = 2,
00094 };

When looking up extensions, we can have different requests identified by the 'action' argument, as follows.

Note:
that the coding is such that the low 4 bits are the third argument to extension_match_core.
Enumerator:
E_MATCHMORE 
E_CANMATCH 
E_MATCH 
E_MATCH_MASK 
E_SPAWN 
E_FINDLABEL 
E_MATCHMORE 
E_CANMATCH 
E_MATCH 
E_MATCH_MASK 
E_SPAWN 
E_FINDLABEL 

Definition at line 1496 of file pbx.h.

01496                  {
01497    E_MATCHMORE =  0x00, /* extension can match but only with more 'digits' */
01498    E_CANMATCH =   0x01, /* extension can match with or without more 'digits' */
01499    E_MATCH =   0x02, /* extension is an exact match */
01500    E_MATCH_MASK = 0x03, /* mask for the argument to extension_match_core() */
01501    E_SPAWN =   0x12, /* want to spawn an extension. Requires exact match */
01502    E_FINDLABEL =  0x22  /* returns the priority for a given label. Requires exact match */
01503 };


Function Documentation

int __ast_custom_function_register ( struct ast_custom_function acf,
struct ast_module mod 
)

Register a custom function.

Definition at line 4127 of file pbx.c.

References acf_retrieve_docs(), ast_custom_function::acflist, ast_custom_function_find_nolock(), ast_log, AST_RWLIST_INSERT_BEFORE_CURRENT, AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, AST_STATIC_DOC, ast_verb, COLOR_BRCYAN, COLORIZE, COLORIZE_FMT, ast_custom_function::docsrc, LOG_ERROR, ast_custom_function::mod, and ast_custom_function::name.

Referenced by __ast_custom_function_register_escalating(), __init_manager(), ast_features_config_init(), ast_msg_init(), and load_pbx().

04128 {
04129    struct ast_custom_function *cur;
04130 
04131    if (!acf) {
04132       return -1;
04133    }
04134 
04135    acf->mod = mod;
04136 #ifdef AST_XML_DOCS
04137    acf->docsrc = AST_STATIC_DOC;
04138 #endif
04139 
04140    if (acf_retrieve_docs(acf)) {
04141       return -1;
04142    }
04143 
04144    AST_RWLIST_WRLOCK(&acf_root);
04145 
04146    cur = ast_custom_function_find_nolock(acf->name);
04147    if (cur) {
04148       ast_log(LOG_ERROR, "Function %s already registered.\n", acf->name);
04149       AST_RWLIST_UNLOCK(&acf_root);
04150       return -1;
04151    }
04152 
04153    /* Store in alphabetical order */
04154    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&acf_root, cur, acflist) {
04155       if (strcmp(acf->name, cur->name) < 0) {
04156          AST_RWLIST_INSERT_BEFORE_CURRENT(acf, acflist);
04157          break;
04158       }
04159    }
04160    AST_RWLIST_TRAVERSE_SAFE_END;
04161    if (!cur) {
04162       AST_RWLIST_INSERT_TAIL(&acf_root, acf, acflist);
04163    }
04164 
04165    AST_RWLIST_UNLOCK(&acf_root);
04166 
04167    ast_verb(2, "Registered custom function '" COLORIZE_FMT "'\n", COLORIZE(COLOR_BRCYAN, 0, acf->name));
04168 
04169    return 0;
04170 }

int __ast_custom_function_register_escalating ( struct ast_custom_function acf,
enum ast_custom_function_escalation  escalation,
struct ast_module mod 
)

Register a custom function which requires escalated privileges.

Examples would be SHELL() (for which a read needs permission to execute arbitrary code) or FILE() (for which write needs permission to change files on the filesystem).

Definition at line 4172 of file pbx.c.

References __ast_custom_function_register(), AST_CFE_BOTH, AST_CFE_NONE, AST_CFE_READ, AST_CFE_WRITE, ast_custom_function::read_escalates, and ast_custom_function::write_escalates.

04173 {
04174    int res;
04175 
04176    res = __ast_custom_function_register(acf, mod);
04177    if (res != 0) {
04178       return -1;
04179    }
04180 
04181    switch (escalation) {
04182    case AST_CFE_NONE:
04183       break;
04184    case AST_CFE_READ:
04185       acf->read_escalates = 1;
04186       break;
04187    case AST_CFE_WRITE:
04188       acf->write_escalates = 1;
04189       break;
04190    case AST_CFE_BOTH:
04191       acf->read_escalates = 1;
04192       acf->write_escalates = 1;
04193       break;
04194    }
04195 
04196    return 0;
04197 }

int ast_active_calls ( void   ) 

Retrieve the number of active calls.

Definition at line 6761 of file pbx.c.

Referenced by ast_var_Config(), handle_chanlist(), handle_showcalls(), and sysinfo_helper().

06762 {
06763    return countcalls;
06764 }

int ast_add_extension ( const char *  context,
int  replace,
const char *  extension,
int  priority,
const char *  label,
const char *  callerid,
const char *  application,
void *  data,
void(*)(void *)  datad,
const char *  registrar 
)

Add and extension to an extension context.

Parameters:
context context to add the extension to
replace 
extension extension to add
priority priority level of extension addition
label extension label
callerid pattern to match CallerID, or NULL to match any CallerID
application application to run on the extension with that priority level
data data to pass to the application
datad 
registrar who registered the extension
Return values:
0 success
-1 failure

Definition at line 9644 of file pbx.c.

References ast_add_extension2(), ast_unlock_contexts(), c, and find_context_locked().

Referenced by ast_hint_presence_state(), AST_TEST_DEFINE(), create_test_dialplan(), extension_state_add_destroy(), handle_cli_dialplan_add_extension(), internal_extension_state_extended(), load_module(), register_exten(), register_extension(), and register_peer_exten().

09647 {
09648    int ret = -1;
09649    struct ast_context *c;
09650 
09651    c = find_context_locked(context);
09652    if (c) {
09653       ret = ast_add_extension2(c, replace, extension, priority, label, callerid,
09654          application, data, datad, registrar);
09655       ast_unlock_contexts();
09656    }
09657 
09658    return ret;
09659 }

int ast_add_extension2 ( struct ast_context con,
int  replace,
const char *  extension,
int  priority,
const char *  label,
const char *  callerid,
const char *  application,
void *  data,
void(*)(void *)  datad,
const char *  registrar 
)

Add an extension to an extension context, this time with an ast_context *.

Note:
For details about the arguments, check ast_add_extension()
Add an extension to an extension context, this time with an ast_context *.

We sort extensions in order of matching preference, so that we can stop the search as soon as we find a suitable match. This ordering also takes care of wildcards such as '.' (meaning "one or more of any character") and '!' (which is 'earlymatch', meaning "zero or more of any character" but also impacts the return value from CANMATCH and EARLYMATCH.

The extension match rules defined in the devmeeting 2006.05.05 are quite simple: WE SELECT THE LONGEST MATCH. In detail, "longest" means the number of matched characters in the extension. In case of ties (e.g. _XXX and 333) in the length of a pattern, we give priority to entries with the smallest cardinality (e.g, [5-9] comes before [2-8] before the former has only 5 elements, while the latter has 7, etc. In case of same cardinality, the first element in the range counts. If we still have a tie, any final '!' will make this as a possibly less specific pattern.

EBUSY - can't lock EEXIST - extension with the same priority exist and no replace is set

Definition at line 228 of file ael_main.c.

References ast_context::eswitches, extens, ast_context::extension_count, filter_leading_space_from_exprs(), filter_newlines(), free, ast_context::ignorepats, ast_context::includes, namelist::name, ast_context::name, namelist::name2, namelist::next, priors, and ast_context::switches.

Referenced by add_extensions(), ast_add_extension(), AST_TEST_DEFINE(), context_merge(), localized_add_extension2(), lua_register_hints(), manager_dialplan_extension_add(), pbx_load_config(), pbx_load_users(), sla_build_station(), and sla_build_trunk().

00232 {
00233    priors++;
00234    con->extension_count++;
00235    if (strcmp(extension,last_exten) != 0) {
00236       extens++;
00237       strcpy(last_exten, extension);
00238    }
00239    if (!label) {
00240       label = "(null)";
00241    }
00242    if (!callerid) {
00243       callerid = "(null)";
00244    }
00245    if (!application) {
00246       application = "(null)";
00247    }
00248 
00249    if(!no_comp)
00250       printf("Executed ast_add_extension2(context=%s, rep=%d, exten=%s, priority=%d, label=%s, callerid=%s, appl=%s, data=%s, FREE, registrar=%s);\n",
00251             con->name, replace, extension, priority, label, callerid, application, (data?(char*)data:"(null)"), registrar);
00252 
00253    if( dump_extensions && dumpfile ) {
00254       struct namelist *n;
00255 
00256       if( FIRST_TIME ) {
00257          FIRST_TIME = 0;
00258          
00259          if( globalvars )
00260             fprintf(dumpfile,"[globals]\n");
00261          
00262          for(n=globalvars;n;n=n->next) {
00263             fprintf(dumpfile, "%s\n", n->name);
00264          }
00265       }
00266       
00267       /* print out each extension , possibly the context header also */
00268       if( con != last_context ) {
00269          fprintf(dumpfile,"\n\n[%s]\n", con->name);
00270          last_context = con;
00271          for(n=con->ignorepats;n;n=n->next) {
00272             fprintf(dumpfile, "ignorepat => %s\n", n->name);
00273          }
00274          for(n=con->includes;n;n=n->next) {
00275             fprintf(dumpfile, "include => %s\n", n->name);
00276          }
00277          for(n=con->switches;n;n=n->next) {
00278             fprintf(dumpfile, "switch => %s/%s\n", n->name, n->name2);
00279          }
00280          for(n=con->eswitches;n;n=n->next) {
00281             fprintf(dumpfile, "eswitch => %s/%s\n", n->name, n->name2);
00282          }
00283          
00284       }
00285       if( data ) {
00286          filter_newlines((char*)data);
00287          filter_leading_space_from_exprs((char*)data);
00288          /* in previous versions, commas were converted to '|' to separate
00289             args in app calls, but now, commas are used. There used to be
00290             code here to insert backslashes (escapes) before any commas
00291             that may have been embedded in the app args. This code is no more. */
00292 
00293          if( strcmp(label,"(null)") != 0  )
00294             fprintf(dumpfile,"exten => %s,%d(%s),%s(%s)\n", extension, priority, label, application, (char*)data);
00295          else
00296             fprintf(dumpfile,"exten => %s,%d,%s(%s)\n", extension, priority, application, (char*)data);
00297 
00298       } else {
00299 
00300          if( strcmp(label,"(null)") != 0  )
00301             fprintf(dumpfile,"exten => %s,%d(%s),%s\n", extension, priority, label, application);
00302          else
00303             fprintf(dumpfile,"exten => %s,%d,%s\n", extension, priority, application);
00304       }
00305    }
00306    
00307    /* since add_extension2 is responsible for the malloc'd data stuff */
00308    free(data);
00309    return 0;
00310 }

int ast_add_extension2_nolock ( struct ast_context con,
int  replace,
const char *  extension,
int  priority,
const char *  label,
const char *  callerid,
const char *  application,
void *  data,
void(*)(void *)  datad,
const char *  registrar 
)

Same as ast_add_extension2, but assumes you have already locked context.

Since:
12.0.0
Note:
con must be write locked prior to calling. For details about the arguments, check ast_add_extension2()

Definition at line 9960 of file pbx.c.

References ast_add_extension2_lockopt().

Referenced by add_extension(), parking_add_extension(), and parking_duration_callback().

09964 {
09965    return ast_add_extension2_lockopt(con, replace, extension, priority, label, callerid,
09966       application, data, datad, registrar, 0);
09967 }

int ast_async_goto ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority 
)

Set the channel to next execute the specified dialplan location.

See also:
ast_async_parseable_goto, ast_async_goto_if_exists
Note:
Do _NOT_ hold any channel locks when calling this function.

Definition at line 9685 of file pbx.c.

References ast_channel_flags(), ast_channel_is_bridged(), ast_channel_lock, ast_channel_name(), ast_channel_pbx(), ast_channel_unlock, ast_channel_yank(), ast_explicit_goto(), AST_FLAG_IN_AUTOLOOP, ast_hangup(), ast_log, ast_pbx_start(), AST_SOFTHANGUP_ASYNCGOTO, ast_softhangup_nolock(), ast_test_flag, and LOG_WARNING.

Referenced by __ast_goto_if_exists(), action_redirect(), ast_async_goto_by_name(), bridge_channel_blind_transfer(), chan_pjsip_cng_tone_detected(), comeback_goto(), dahdi_handle_dtmf(), fax_detect_framehook(), handle_request_bye(), my_handle_dtmf(), onModeChanged(), ooh323_rtp_read(), pbx_parseable_goto(), process_ast_dsp(), process_sdp(), and sip_read().

09686 {
09687    struct ast_channel *newchan;
09688 
09689    ast_channel_lock(chan);
09690    /* Channels in a bridge or running a PBX can be sent directly to the specified destination */
09691    if (ast_channel_is_bridged(chan) || ast_channel_pbx(chan)) {
09692       if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_AUTOLOOP)) {
09693          priority += 1;
09694       }
09695       ast_explicit_goto(chan, context, exten, priority);
09696       ast_softhangup_nolock(chan, AST_SOFTHANGUP_ASYNCGOTO);
09697       ast_channel_unlock(chan);
09698       return 0;
09699    }
09700    ast_channel_unlock(chan);
09701 
09702    /* Otherwise, we need to gain control of the channel first */
09703    newchan = ast_channel_yank(chan);
09704    if (!newchan) {
09705       ast_log(LOG_WARNING, "Unable to gain control of channel %s\n", ast_channel_name(chan));
09706       return -1;
09707    }
09708    ast_explicit_goto(newchan, context, exten, priority);
09709    if (ast_pbx_start(newchan)) {
09710       ast_hangup(newchan);
09711       ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(newchan));
09712       return -1;
09713    }
09714 
09715    return 0;
09716 }

int ast_async_goto_by_name ( const char *  chan,
const char *  context,
const char *  exten,
int  priority 
)

Set the channel to next execute the specified dialplan location.

Definition at line 9718 of file pbx.c.

References ast_async_goto(), ast_channel_get_by_name(), and ast_channel_unref.

09719 {
09720    struct ast_channel *chan;
09721    int res = -1;
09722 
09723    if ((chan = ast_channel_get_by_name(channame))) {
09724       res = ast_async_goto(chan, context, exten, priority);
09725       chan = ast_channel_unref(chan);
09726    }
09727 
09728    return res;
09729 }

int ast_async_goto_if_exists ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority 
)

Note:
This function will handle locking the channel as needed.

Definition at line 12375 of file pbx.c.

References __ast_goto_if_exists().

12376 {
12377    return __ast_goto_if_exists(chan, context, exten, priority, 1);
12378 }

int ast_async_parseable_goto ( struct ast_channel chan,
const char *  goto_string 
)

Note:
This function will handle locking the channel as needed.

Definition at line 12440 of file pbx.c.

References pbx_parseable_goto().

Referenced by asyncgoto_exec(), handle_redirect(), and parking_duration_callback().

12441 {
12442    return pbx_parseable_goto(chan, goto_string, 1);
12443 }

int ast_build_timing ( struct ast_timing i,
const char *  info_in 
)

Construct a timing bitmap, for use in time-based conditionals.

Parameters:
i Pointer to an ast_timing structure.
info Standard string containing a timerange, weekday range, monthday range, and month range, as well as an optional timezone.
Return values:
Returns 1 on success or 0 on failure.
/brief Build timing

/param i info /param info_in

Definition at line 4104 of file extconf.c.

References ast_strdup, ast_strdupa, ast_strlen_zero, ast_timing::daymask, ast_timing::dowmask, get_range(), get_timerange(), ast_timing::monthmask, NULL, strsep(), and ast_timing::timezone.

Referenced by ast_context_add_include2(), iftime(), pbx_builtin_execiftime(), and pbx_builtin_gotoiftime().

04105 {
04106    char *info;
04107    int j, num_fields, last_sep = -1;
04108 
04109    i->timezone = NULL;
04110 
04111    /* Check for empty just in case */
04112    if (ast_strlen_zero(info_in)) {
04113       return 0;
04114    }
04115 
04116    /* make a copy just in case we were passed a static string */
04117    info = ast_strdupa(info_in);
04118 
04119    /* count the number of fields in the timespec */
04120    for (j = 0, num_fields = 1; info[j] != '\0'; j++) {
04121       if (info[j] == ',') {
04122          last_sep = j;
04123          num_fields++;
04124       }
04125    }
04126 
04127    /* save the timezone, if it is specified */
04128    if (num_fields == 5) {
04129       i->timezone = ast_strdup(info + last_sep + 1);
04130    }
04131 
04132    /* Assume everything except time */
04133    i->monthmask = 0xfff;   /* 12 bits */
04134    i->daymask = 0x7fffffffU; /* 31 bits */
04135    i->dowmask = 0x7f; /* 7 bits */
04136    /* on each call, use strsep() to move info to the next argument */
04137    get_timerange(i, strsep(&info, "|,"));
04138    if (info)
04139       i->dowmask = get_range(strsep(&info, "|,"), 7, days, "day of week");
04140    if (info)
04141       i->daymask = get_range(strsep(&info, "|,"), 31, NULL, "day");
04142    if (info)
04143       i->monthmask = get_range(strsep(&info, "|,"), 12, months, "month");
04144    return 1;
04145 }

int ast_canmatch_extension ( struct ast_channel c,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid 
)

Looks for a valid matching extension.

Parameters:
c not really important
context context to serach within
exten extension to check
priority priority of extension path
callerid callerid of extension being searched for
Note:
It is possible for autoservice to be started and stopped on c during this function call, it is important that c is not locked prior to calling this. Otherwise a deadlock may occur
Returns:
If "exten" *could be* a valid extension in this context with or without some more digits, return non-zero. Basically, when this returns 0, no matter what you add to exten, it's not going to be a valid extension anymore

Definition at line 5955 of file pbx.c.

References E_CANMATCH, NULL, and pbx_extension_helper().

Referenced by __analog_ss_thread(), analog_ss_thread(), background_detect_exec(), cb_events(), do_immediate_setup(), dp_lookup(), dundi_lookup_local(), get_also_info(), get_destination(), leave_voicemail(), loopback_canmatch(), mgcp_ss(), pbx_builtin_background(), phone_check_exception(), test_exten(), and valid_exit().

05956 {
05957    return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_CANMATCH, 0, 0);
05958 }

int ast_check_timing ( const struct ast_timing i  ) 

Evaluate a pre-constructed bitmap as to whether the current time falls within the range specified.

Parameters:
i Pointer to an ast_timing structure.
Return values:
Returns 1, if the time matches or 0, if the current time falls outside of the specified range.

Definition at line 4298 of file extconf.c.

Referenced by iftime(), include_valid(), and pbx_builtin_execiftime().

04299 {
04300    /* sorry, but this feature will NOT be available
04301       in the standalone version */
04302    return 0;
04303 }

int ast_check_timing2 ( const struct ast_timing i,
const struct timeval  tv 
)

Evaluate a pre-constructed bitmap as to whether a particular time falls within the range specified.

Parameters:
i Pointer to an ast_timing structure.
tv Specified time
Return values:
Returns 1, if the time matches or 0, if the time falls outside of the specified range.

Definition at line 9315 of file pbx.c.

References ast_localtime(), ast_log, ast_timing::daymask, ast_timing::dowmask, LOG_WARNING, ast_timing::minmask, ast_timing::monthmask, ast_timing::timezone, ast_tm::tm_hour, ast_tm::tm_mday, ast_tm::tm_min, ast_tm::tm_mon, and ast_tm::tm_wday.

Referenced by ast_check_timing(), and pbx_builtin_gotoiftime().

09316 {
09317    struct ast_tm tm;
09318 
09319    ast_localtime(&tv, &tm, i->timezone);
09320 
09321    /* If it's not the right month, return */
09322    if (!(i->monthmask & (1 << tm.tm_mon)))
09323       return 0;
09324 
09325    /* If it's not that time of the month.... */
09326    /* Warning, tm_mday has range 1..31! */
09327    if (!(i->daymask & (1 << (tm.tm_mday-1))))
09328       return 0;
09329 
09330    /* If it's not the right day of the week */
09331    if (!(i->dowmask & (1 << tm.tm_wday)))
09332       return 0;
09333 
09334    /* Sanity check the hour just to be safe */
09335    if ((tm.tm_hour < 0) || (tm.tm_hour > 23)) {
09336       ast_log(LOG_WARNING, "Insane time...\n");
09337       return 0;
09338    }
09339 
09340    /* Now the tough part, we calculate if it fits
09341       in the right time based on min/hour */
09342    if (!(i->minmask[tm.tm_hour * 2 + (tm.tm_min >= 30 ? 1 : 0)] & (1 << (tm.tm_min >= 30 ? tm.tm_min - 30 : tm.tm_min))))
09343       return 0;
09344 
09345    /* If we got this far, then we're good */
09346    return 1;
09347 }

char* ast_complete_applications ( const char *  line,
const char *  word,
int  state 
)

Command completion for the list of installed applications.

This can be called from a CLI command completion function that wants to complete from the list of available applications.

Definition at line 12445 of file pbx.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, ast_app::name, and NULL.

Referenced by handle_orig(), and handle_show_application().

12446 {
12447    struct ast_app *app;
12448    int which = 0;
12449    int cmp;
12450    char *ret = NULL;
12451    size_t wordlen = strlen(word);
12452 
12453    AST_RWLIST_RDLOCK(&apps);
12454    AST_RWLIST_TRAVERSE(&apps, app, list) {
12455       cmp = strncasecmp(word, app->name, wordlen);
12456       if (cmp > 0) {
12457          continue;
12458       }
12459       if (!cmp) {
12460          /* Found match. */
12461          if (++which <= state) {
12462             /* Not enough matches. */
12463             continue;
12464          }
12465          ret = ast_strdup(app->name);
12466          break;
12467       }
12468       /* Not in container. */
12469       break;
12470    }
12471    AST_RWLIST_UNLOCK(&apps);
12472 
12473    return ret;
12474 }

int ast_context_add_ignorepat ( const char *  context,
const char *  ignorepat,
const char *  registrar 
)

Add an ignorepat.

Parameters:
context which context to add the ignorpattern to
ignorepat ignorepattern to set up for the extension
registrar registrar of the ignore pattern
Adds an ignore pattern to a particular context.

Return values:
0 on success
-1 on failure

Definition at line 9551 of file pbx.c.

References ast_context_add_ignorepat2(), ast_unlock_contexts(), c, and find_context_locked().

Referenced by handle_cli_dialplan_add_ignorepat().

09552 {
09553    int ret = -1;
09554    struct ast_context *c;
09555 
09556    c = find_context_locked(context);
09557    if (c) {
09558       ret = ast_context_add_ignorepat2(c, value, registrar);
09559       ast_unlock_contexts();
09560    }
09561    return ret;
09562 }

static int ast_context_add_ignorepat2 ( struct ast_context con,
const char *  ignorepat,
const char *  registrar 
)

Definition at line 355 of file ael_main.c.

References ADD_LAST, create_name(), and ast_context::ignorepats.

Referenced by ast_compile_ael2(), ast_context_add_ignorepat(), context_merge_incls_swits_igps_other_registrars(), localized_context_add_ignorepat2(), and pbx_load_config().

00356 {
00357    if(!no_comp)
00358       printf("Executed ast_context_add_ignorepat2(con, value=%s, registrar=%s);\n", value, registrar);
00359    if( dump_extensions ) {
00360       struct namelist *x;
00361       x = create_name(value);
00362       ADD_LAST(con->ignorepats,x);
00363    }
00364 }

int ast_context_add_include ( const char *  context,
const char *  include,
const char *  registrar 
)

Add a context include.

Parameters:
context context to add include to
include new include to add
registrar who's registering it
Adds an include taking a char * string as the context parameter

Return values:
0 on success
-1 on error

Definition at line 9090 of file pbx.c.

References ast_context_add_include2(), ast_unlock_contexts(), c, and find_context_locked().

Referenced by AST_TEST_DEFINE(), and handle_cli_dialplan_add_include().

09091 {
09092    int ret = -1;
09093    struct ast_context *c;
09094 
09095    c = find_context_locked(context);
09096    if (c) {
09097       ret = ast_context_add_include2(c, include, registrar);
09098       ast_unlock_contexts();
09099    }
09100    return ret;
09101 }

static int ast_context_add_include2 ( struct ast_context con,
const char *  include,
const char *  registrar 
)

Add a context include.

Parameters:
con context to add the include to
value include value to add
registrar who registered the context
Adds an include taking a struct ast_context as the first parameter

Return values:
0 on success
-1 on failure

Definition at line 366 of file ael_main.c.

References ADD_LAST, create_name(), and ast_context::includes.

Referenced by ast_compile_ael2(), ast_context_add_include(), context_merge_incls_swits_igps_other_registrars(), localized_context_add_include2(), and pbx_load_config().

00367 {
00368    if(!no_comp)
00369       printf("Executed ast_context_add_include2(con, value=%s, registrar=%s);\n", value, registrar);
00370    if( dump_extensions ) {
00371       struct namelist *x;
00372       x = create_name((char*)value);
00373       ADD_LAST(con->includes,x);
00374    }
00375 }

int ast_context_add_switch ( const char *  context,
const char *  sw,
const char *  data,
int  eval,
const char *  registrar 
)

Add a switch.

Parameters:
context context to which to add the switch
sw switch to add
data data to pass to switch
eval whether to evaluate variables when running switch
registrar whoever registered the switch
This function registers a switch with the asterisk switch architecture

Return values:
0 on success
-1 on failure

Definition at line 9427 of file pbx.c.

References ast_context_add_switch2(), ast_unlock_contexts(), c, and find_context_locked().

09428 {
09429    int ret = -1;
09430    struct ast_context *c;
09431 
09432    c = find_context_locked(context);
09433    if (c) { /* found, add switch to this context */
09434       ret = ast_context_add_switch2(c, sw, data, eval, registrar);
09435       ast_unlock_contexts();
09436    }
09437    return ret;
09438 }

static int ast_context_add_switch2 ( struct ast_context con,
const char *  sw,
const char *  data,
int  eval,
const char *  registrar 
)

Adds a switch (first param is a ast_context).

Note:
See ast_context_add_switch() for argument information, with the exception of the first argument. In this case, it's a pointer to an ast_context structure as opposed to the name.

Definition at line 377 of file ael_main.c.

References ADD_LAST, create_name(), ast_context::eswitches, namelist::name2, and ast_context::switches.

Referenced by ast_compile_ael2(), ast_context_add_switch(), context_merge_incls_swits_igps_other_registrars(), localized_context_add_switch2(), lua_register_switches(), and pbx_load_config().

00378 {
00379    if(!no_comp)
00380       printf("Executed ast_context_add_switch2(con, value=%s, data=%s, eval=%d, registrar=%s);\n", value, data, eval, registrar);
00381    if( dump_extensions ) {
00382       struct namelist *x;
00383       x = create_name((char*)value);
00384       strncpy(x->name2,data,100);
00385       if( eval ) {
00386 
00387          ADD_LAST(con->switches,x);
00388 
00389       } else {
00390 
00391          ADD_LAST(con->eswitches,x);
00392       }
00393    }
00394 }

void ast_context_destroy ( struct ast_context con,
const char *  registrar 
)

Destroy a context (matches the specified context (or ANY context if NULL).

Parameters:
con context to destroy
registrar who registered it
You can optionally leave out either parameter. It will find it based on either the ast_context or the registrar name.

Returns:
nothing

Definition at line 636 of file conf2ael.c.

References localized_context_destroy().

Referenced by __unload_module(), AST_TEST_DEFINE(), cleanup_stale_contexts(), handle_cli_dialplan_remove_context(), parking_lot_cfg_remove_extensions(), remove_all_configured_parking_lot_extensions(), remove_pending_parking_lot_extensions(), sla_destroy(), and unload_module().

00637 {
00638    return localized_context_destroy(con, registrar);
00639 }

static struct ast_context * ast_context_find ( const char *  name  )  [read]

Find a context.

Parameters:
name name of the context to find
Will search for the context with the given name.

Returns:
the ast_context on success, NULL on failure.

Definition at line 4419 of file extconf.c.

References ast_walk_contexts(), ast_context::name, NULL, and tmp().

Referenced by __unload_module(), _macro_exec(), ast_context_verify_includes(), ast_ignore_pattern(), cleanup_stale_contexts(), handle_cli_dialplan_add_extension(), handle_cli_dialplan_add_include(), handle_cli_dialplan_remove_context(), isexten_function_read(), register_exten(), register_peer_exten(), unload_module(), and unregister_exten().

04420 {
04421    struct ast_context *tmp = NULL;
04422    while ( (tmp = ast_walk_contexts(tmp)) ) {
04423       if (!name || !strcasecmp(name, tmp->name))
04424          break;
04425    }
04426    return tmp;
04427 }

struct ast_context* ast_context_find_or_create ( struct ast_context **  extcontexts,
struct ast_hashtab exttable,
const char *  name,
const char *  registrar 
) [read]

Register a new context or find an existing one.

Parameters:
extcontexts pointer to the ast_context structure pointer
exttable pointer to the hashtable that contains all the elements in extcontexts
name name of the new context
registrar registrar of the context
This function allows you to play in two environments: the global contexts (active dialplan) or an external context set of your choosing. To act on the external set, make sure extcontexts and exttable are set; for the globals, make sure both extcontexts and exttable are NULL.

This will first search for a context with your name. If it exists already, it will not create a new one. If it does not exist, it will create a new one with the given name and registrar.

Returns:
NULL on failure, and an ast_context structure on success

Definition at line 8651 of file pbx.c.

References ast_calloc, ast_copy_string(), ast_hashtab_compare_contexts(), ast_hashtab_create(), ast_hashtab_hash_contexts(), ast_hashtab_insert_immediate(), ast_hashtab_insert_safe(), ast_hashtab_lookup(), ast_hashtab_newsize_java(), ast_hashtab_resize_java(), ast_log, ast_mutex_init, ast_rdlock_contexts(), ast_rwlock_init, ast_strdup, ast_unlock_contexts(), ast_verb, ast_wrlock_contexts(), ast_context::ignorepats, ast_context::includes, local_contexts, localized_context_find_or_create(), ast_context::lock, LOG_ERROR, ast_context::macrolock, ast_context::name, fake_context::name, ast_context::next, NULL, ast_context::refcount, ast_context::registrar, ast_context::root, ast_context::root_table, and tmp().

Referenced by add_hints(), ast_compile_ael2(), AST_TEST_DEFINE(), config_parse_variables(), context_merge(), create_test_dialplan(), handle_cli_dialplan_add_extension(), handle_cli_dialplan_add_include(), load_module(), lua_register_hints(), lua_register_switches(), manager_dialplan_extension_add(), parking_duration_callback(), parking_lot_cfg_create_extensions(), pbx_load_config(), pbx_load_users(), reload_config(), set_config(), sla_build_station(), and sla_build_trunk().

08652 {
08653    struct ast_context *tmp, **local_contexts;
08654    struct fake_context search;
08655    int length = sizeof(struct ast_context) + strlen(name) + 1;
08656 
08657    if (!contexts_table) {
08658       /* Protect creation of contexts_table from reentrancy. */
08659       ast_wrlock_contexts();
08660       if (!contexts_table) {
08661          contexts_table = ast_hashtab_create(17,
08662             ast_hashtab_compare_contexts,
08663             ast_hashtab_resize_java,
08664             ast_hashtab_newsize_java,
08665             ast_hashtab_hash_contexts,
08666             0);
08667       }
08668       ast_unlock_contexts();
08669    }
08670 
08671    ast_copy_string(search.name, name, sizeof(search.name));
08672    if (!extcontexts) {
08673       ast_rdlock_contexts();
08674       local_contexts = &contexts;
08675       tmp = ast_hashtab_lookup(contexts_table, &search);
08676       ast_unlock_contexts();
08677       if (tmp) {
08678          tmp->refcount++;
08679          return tmp;
08680       }
08681    } else { /* local contexts just in a linked list; search there for the new context; slow, linear search, but not frequent */
08682       local_contexts = extcontexts;
08683       tmp = ast_hashtab_lookup(exttable, &search);
08684       if (tmp) {
08685          tmp->refcount++;
08686          return tmp;
08687       }
08688    }
08689 
08690    if ((tmp = ast_calloc(1, length))) {
08691       ast_rwlock_init(&tmp->lock);
08692       ast_mutex_init(&tmp->macrolock);
08693       strcpy(tmp->name, name);
08694       tmp->root = NULL;
08695       tmp->root_table = NULL;
08696       tmp->registrar = ast_strdup(registrar);
08697       tmp->includes = NULL;
08698       tmp->ignorepats = NULL;
08699       tmp->refcount = 1;
08700    } else {
08701       ast_log(LOG_ERROR, "Danger! We failed to allocate a context for %s!\n", name);
08702       return NULL;
08703    }
08704 
08705    if (!extcontexts) {
08706       ast_wrlock_contexts();
08707       tmp->next = *local_contexts;
08708       *local_contexts = tmp;
08709       ast_hashtab_insert_safe(contexts_table, tmp); /*put this context into the tree */
08710       ast_unlock_contexts();
08711       ast_verb(3, "Registered extension context '%s'; registrar: %s\n", tmp->name, registrar);
08712    } else {
08713       tmp->next = *local_contexts;
08714       if (exttable)
08715          ast_hashtab_insert_immediate(exttable, tmp); /*put this context into the tree */
08716 
08717       *local_contexts = tmp;
08718       ast_verb(3, "Registered extension context '%s'; registrar: %s\n", tmp->name, registrar);
08719    }
08720    return tmp;
08721 }

int ast_context_lockmacro ( const char *  context  ) 

locks the macrolock in the given given context

Parameters:
macrocontext name of the macro-context to lock
Locks the given macro-context to ensure only one thread (call) can execute it at a time

Return values:
0 on success
-1 on failure
Note:
This function locks contexts list by &conlist, searches for the right context structure, and locks the macrolock mutex in that context. macrolock is used to limit a macro to be executed by one call at a time.
Parameters:
context The context

Definition at line 7137 of file pbx.c.

References ast_mutex_lock, ast_unlock_contexts(), c, find_context_locked(), and ast_context::macrolock.

Referenced by _macro_exec().

07138 {
07139    struct ast_context *c;
07140    int ret = -1;
07141 
07142    c = find_context_locked(context);
07143    if (c) {
07144       ast_unlock_contexts();
07145 
07146       /* if we found context, lock macrolock */
07147       ret = ast_mutex_lock(&c->macrolock);
07148    }
07149 
07150    return ret;
07151 }

int ast_context_remove_extension ( const char *  context,
const char *  extension,
int  priority,
const char *  registrar 
)

Simply remove extension from context.

Parameters:
context context to remove extension from
extension which extension to remove
priority priority of extension to remove (0 to remove all)
registrar registrar of the extension
This function removes an extension from a given context.

Return values:
0 on success
-1 on failure
Note:
This function will lock conlock.

Definition at line 6944 of file pbx.c.

References ast_context_remove_extension_callerid(), AST_EXT_MATCHCID_ANY, and NULL.

Referenced by delete_extens(), register_peer_exten(), sla_station_destructor(), sla_trunk_destructor(), unregister_exten(), and unregister_extension().

int ast_context_remove_extension2 ( struct ast_context con,
const char *  extension,
int  priority,
const char *  registrar,
int  already_locked 
)

This functionc locks given context, search for the right extension and fires out all peer in this extensions with given priority. If priority is set to 0, all peers are removed. After that, unlock context and return.

Note:
When do you want to call this function, make sure that &conlock is locked, because some process can handle with your *con context before you lock it.

Definition at line 6974 of file pbx.c.

References ast_context_remove_extension_callerid2(), AST_EXT_MATCHCID_ANY, and NULL.

Referenced by add_extension(), add_hints(), and AST_TEST_DEFINE().

06975 {
06976    return ast_context_remove_extension_callerid2(con, extension, priority, NULL, AST_EXT_MATCHCID_ANY, registrar, already_locked);
06977 }

int ast_context_remove_extension_callerid ( const char *  context,
const char *  extension,
int  priority,
const char *  callerid,
int  matchcid,
const char *  registrar 
)

Definition at line 6949 of file pbx.c.

References ast_context_remove_extension_callerid2(), ast_unlock_contexts(), c, and find_context_locked().

Referenced by ast_context_remove_extension(), handle_cli_dialplan_remove_extension(), and manager_dialplan_extension_remove().

06950 {
06951    int ret = -1; /* default error return */
06952    struct ast_context *c;
06953 
06954    c = find_context_locked(context);
06955    if (c) { /* ... remove extension ... */
06956       ret = ast_context_remove_extension_callerid2(c, extension, priority, callerid,
06957          matchcallerid, registrar, 0);
06958       ast_unlock_contexts();
06959    }
06960 
06961    return ret;
06962 }

int ast_context_remove_extension_callerid2 ( struct ast_context con,
const char *  extension,
int  priority,
const char *  callerid,
int  matchcid,
const char *  registrar,
int  already_locked 
)

Definition at line 6979 of file pbx.c.

References add_exten_to_pattern_tree(), ast_copy_string(), ast_hashtab_insert_immediate(), ast_hashtab_lookup(), ast_hashtab_remove_this_object(), ast_hashtab_size(), ast_log, ast_strlen_zero, ast_unlock_context(), ast_verb, ast_wrlock_context(), ast_exten::cidmatch, match_char::deleted, destroy_exten(), match_char::exten, ast_exten::exten, exten, ast_exten::label, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_exten::matchcid, ast_context::name, ast_exten::next, NULL, ast_context::pattern_tree, ast_exten::peer, ast_exten::peer_label_table, ast_exten::peer_table, ast_exten::priority, ast_exten::registrar, ast_context::root, ast_context::root_table, and match_char::x.

Referenced by __ast_context_destroy(), ast_context_remove_extension2(), and ast_context_remove_extension_callerid().

06980 {
06981    struct ast_exten *exten, *prev_exten = NULL;
06982    struct ast_exten *peer;
06983    struct ast_exten ex, *exten2, *exten3;
06984    char dummy_name[1024];
06985    struct ast_exten *previous_peer = NULL;
06986    struct ast_exten *next_peer = NULL;
06987    int found = 0;
06988 
06989    if (!already_locked)
06990       ast_wrlock_context(con);
06991 
06992 #ifdef NEED_DEBUG
06993    ast_verb(3,"Removing %s/%s/%d%s%s from trees, registrar=%s\n", con->name, extension, priority, matchcallerid ? "/" : "", matchcallerid ? callerid : "", registrar);
06994 #endif
06995 #ifdef CONTEXT_DEBUG
06996    check_contexts(__FILE__, __LINE__);
06997 #endif
06998    /* find this particular extension */
06999    ex.exten = dummy_name;
07000    ex.matchcid = matchcallerid;
07001    ex.cidmatch = callerid;
07002    ast_copy_string(dummy_name, extension, sizeof(dummy_name));
07003    exten = ast_hashtab_lookup(con->root_table, &ex);
07004    if (exten) {
07005       if (priority == 0) {
07006          exten2 = ast_hashtab_remove_this_object(con->root_table, exten);
07007          if (!exten2)
07008             ast_log(LOG_ERROR,"Trying to delete the exten %s from context %s, but could not remove from the root_table\n", extension, con->name);
07009          if (con->pattern_tree) {
07010             struct match_char *x = add_exten_to_pattern_tree(con, exten, 1);
07011 
07012             if (x->exten) { /* this test for safety purposes */
07013                x->deleted = 1; /* with this marked as deleted, it will never show up in the scoreboard, and therefore never be found */
07014                x->exten = 0; /* get rid of what will become a bad pointer */
07015             } else {
07016                ast_log(LOG_WARNING,"Trying to delete an exten from a context, but the pattern tree node returned isn't a full extension\n");
07017             }
07018          }
07019       } else {
07020          ex.priority = priority;
07021          exten2 = ast_hashtab_lookup(exten->peer_table, &ex);
07022          if (exten2) {
07023             if (exten2->label) { /* if this exten has a label, remove that, too */
07024                exten3 = ast_hashtab_remove_this_object(exten->peer_label_table,exten2);
07025                if (!exten3)
07026                   ast_log(LOG_ERROR,"Did not remove this priority label (%d/%s) from the peer_label_table of context %s, extension %s!\n", priority, exten2->label, con->name, exten2->exten);
07027             }
07028 
07029             exten3 = ast_hashtab_remove_this_object(exten->peer_table, exten2);
07030             if (!exten3)
07031                ast_log(LOG_ERROR,"Did not remove this priority (%d) from the peer_table of context %s, extension %s!\n", priority, con->name, exten2->exten);
07032             if (exten2 == exten && exten2->peer) {
07033                exten2 = ast_hashtab_remove_this_object(con->root_table, exten);
07034                ast_hashtab_insert_immediate(con->root_table, exten2->peer);
07035             }
07036             if (ast_hashtab_size(exten->peer_table) == 0) {
07037                /* well, if the last priority of an exten is to be removed,
07038                   then, the extension is removed, too! */
07039                exten3 = ast_hashtab_remove_this_object(con->root_table, exten);
07040                if (!exten3)
07041                   ast_log(LOG_ERROR,"Did not remove this exten (%s) from the context root_table (%s) (priority %d)\n", exten->exten, con->name, priority);
07042                if (con->pattern_tree) {
07043                   struct match_char *x = add_exten_to_pattern_tree(con, exten, 1);
07044                   if (x->exten) { /* this test for safety purposes */
07045                      x->deleted = 1; /* with this marked as deleted, it will never show up in the scoreboard, and therefore never be found */
07046                      x->exten = 0; /* get rid of what will become a bad pointer */
07047                   }
07048                }
07049             }
07050          } else {
07051             ast_log(LOG_ERROR,"Could not find priority %d of exten %s in context %s!\n",
07052                   priority, exten->exten, con->name);
07053          }
07054       }
07055    } else {
07056       /* hmmm? this exten is not in this pattern tree? */
07057       ast_log(LOG_WARNING,"Cannot find extension %s in root_table in context %s\n",
07058             extension, con->name);
07059    }
07060 #ifdef NEED_DEBUG
07061    if (con->pattern_tree) {
07062       ast_log(LOG_NOTICE,"match char tree after exten removal:\n");
07063       log_match_char_tree(con->pattern_tree, " ");
07064    }
07065 #endif
07066 
07067    /* scan the extension list to find first matching extension-registrar */
07068    for (exten = con->root; exten; prev_exten = exten, exten = exten->next) {
07069       if (!strcmp(exten->exten, extension) &&
07070          (!registrar || !strcmp(exten->registrar, registrar)) &&
07071          (!matchcallerid || (!ast_strlen_zero(callerid) && !ast_strlen_zero(exten->cidmatch) && !strcmp(exten->cidmatch, callerid)) || (ast_strlen_zero(callerid) && ast_strlen_zero(exten->cidmatch))))
07072          break;
07073    }
07074    if (!exten) {
07075       /* we can't find right extension */
07076       if (!already_locked)
07077          ast_unlock_context(con);
07078       return -1;
07079    }
07080 
07081    /* scan the priority list to remove extension with exten->priority == priority */
07082    for (peer = exten, next_peer = exten->peer ? exten->peer : exten->next;
07083        peer && !strcmp(peer->exten, extension) &&
07084          (!callerid || (!matchcallerid && !peer->matchcid) || (matchcallerid && peer->matchcid && !strcmp(peer->cidmatch, callerid))) ;
07085          peer = next_peer, next_peer = next_peer ? (next_peer->peer ? next_peer->peer : next_peer->next) : NULL) {
07086 
07087       if ((priority == 0 || peer->priority == priority) &&
07088             (!registrar || !strcmp(peer->registrar, registrar) )) {
07089          found = 1;
07090 
07091          /* we are first priority extension? */
07092          if (!previous_peer) {
07093             /*
07094              * We are first in the priority chain, so must update the extension chain.
07095              * The next node is either the next priority or the next extension
07096              */
07097             struct ast_exten *next_node = peer->peer ? peer->peer : peer->next;
07098             if (peer->peer) {
07099                /* move the peer_table and peer_label_table down to the next peer, if
07100                   it is there */
07101                peer->peer->peer_table = peer->peer_table;
07102                peer->peer->peer_label_table = peer->peer_label_table;
07103                peer->peer_table = NULL;
07104                peer->peer_label_table = NULL;
07105             }
07106             if (!prev_exten) {   /* change the root... */
07107                con->root = next_node;
07108             } else {
07109                prev_exten->next = next_node; /* unlink */
07110             }
07111             if (peer->peer)   { /* update the new head of the pri list */
07112                peer->peer->next = peer->next;
07113             }
07114          } else { /* easy, we are not first priority in extension */
07115             previous_peer->peer = peer->peer;
07116          }
07117 
07118 
07119          /* now, free whole priority extension */
07120          destroy_exten(peer);
07121       } else {
07122          previous_peer = peer;
07123       }
07124    }
07125    if (!already_locked)
07126       ast_unlock_context(con);
07127    return found ? 0 : -1;
07128 }

int ast_context_remove_ignorepat ( const char *  context,
const char *  ignorepat,
const char *  registrar 
)

Definition at line 9507 of file pbx.c.

References ast_context_remove_ignorepat2(), ast_unlock_contexts(), c, and find_context_locked().

Referenced by handle_cli_dialplan_remove_ignorepat().

09508 {
09509    int ret = -1;
09510    struct ast_context *c;
09511 
09512    c = find_context_locked(context);
09513    if (c) {
09514       ret = ast_context_remove_ignorepat2(c, ignorepat, registrar);
09515       ast_unlock_contexts();
09516    }
09517    return ret;
09518 }

int ast_context_remove_ignorepat2 ( struct ast_context con,
const char *  ignorepat,
const char *  registrar 
)

Definition at line 9520 of file pbx.c.

References ast_free, ast_unlock_context(), ast_wrlock_context(), errno, ast_context::ignorepats, ast_ignorepat::next, NULL, ast_ignorepat::pattern, and ast_ignorepat::registrar.

Referenced by ast_context_remove_ignorepat().

09521 {
09522    struct ast_ignorepat *ip, *ipl = NULL;
09523 
09524    ast_wrlock_context(con);
09525 
09526    for (ip = con->ignorepats; ip; ip = ip->next) {
09527       if (!strcmp(ip->pattern, ignorepat) &&
09528          (!registrar || (registrar == ip->registrar))) {
09529          if (ipl) {
09530             ipl->next = ip->next;
09531             ast_free(ip);
09532          } else {
09533             con->ignorepats = ip->next;
09534             ast_free(ip);
09535          }
09536          ast_unlock_context(con);
09537          return 0;
09538       }
09539       ipl = ip;
09540    }
09541 
09542    ast_unlock_context(con);
09543    errno = EINVAL;
09544    return -1;
09545 }

int ast_context_remove_include ( const char *  context,
const char *  include,
const char *  registrar 
)

Remove a context include.

Note:
See ast_context_add_include for information on arguments
Return values:
0 on success
-1 on failure

Definition at line 6837 of file pbx.c.

References ast_context_remove_include2(), ast_unlock_contexts(), c, and find_context_locked().

Referenced by handle_cli_dialplan_remove_include().

06838 {
06839    int ret = -1;
06840    struct ast_context *c;
06841 
06842    c = find_context_locked(context);
06843    if (c) {
06844       /* found, remove include from this context ... */
06845       ret = ast_context_remove_include2(c, include, registrar);
06846       ast_unlock_contexts();
06847    }
06848    return ret;
06849 }

int ast_context_remove_include2 ( struct ast_context con,
const char *  include,
const char *  registrar 
)

Removes an include by an ast_context structure.

Note:
See ast_context_add_include2 for information on arguments
Return values:
0 on success
-1 on success
Removes an include by an ast_context structure.

Return values:
0 on success.
-1 on failure.

Definition at line 6860 of file pbx.c.

References ast_destroy_timing(), ast_free, ast_get_context_name(), ast_unlock_context(), ast_verb, ast_wrlock_context(), ast_context::includes, ast_include::name, ast_include::next, NULL, ast_include::registrar, and ast_include::timing.

Referenced by ast_context_remove_include().

06861 {
06862    struct ast_include *i, *pi = NULL;
06863    int ret = -1;
06864 
06865    ast_wrlock_context(con);
06866 
06867    /* find our include */
06868    for (i = con->includes; i; pi = i, i = i->next) {
06869       if (!strcmp(i->name, include) &&
06870             (!registrar || !strcmp(i->registrar, registrar))) {
06871          /* remove from list */
06872          ast_verb(3, "Removing inclusion of context '%s' in context '%s; registrar=%s'\n", include, ast_get_context_name(con), registrar);
06873          if (pi)
06874             pi->next = i->next;
06875          else
06876             con->includes = i->next;
06877          /* free include and return */
06878          ast_destroy_timing(&(i->timing));
06879          ast_free(i);
06880          ret = 0;
06881          break;
06882       }
06883    }
06884 
06885    ast_unlock_context(con);
06886 
06887    return ret;
06888 }

int ast_context_remove_switch ( const char *  context,
const char *  sw,
const char *  data,
const char *  registrar 
)

Remove a switch.

Removes a switch with the given parameters

Return values:
0 on success
-1 on failure
Note:
This function locks contexts list by &conlist, search for the rigt context structure, leave context list locked and call ast_context_remove_switch2 which removes switch, unlock contexts list and return ...

Definition at line 6895 of file pbx.c.

References ast_context_remove_switch2(), ast_unlock_contexts(), c, and find_context_locked().

06896 {
06897    int ret = -1; /* default error return */
06898    struct ast_context *c;
06899 
06900    c = find_context_locked(context);
06901    if (c) {
06902       /* remove switch from this context ... */
06903       ret = ast_context_remove_switch2(c, sw, data, registrar);
06904       ast_unlock_contexts();
06905    }
06906    return ret;
06907 }

int ast_context_remove_switch2 ( struct ast_context con,
const char *  sw,
const char *  data,
const char *  registrar 
)

This function locks given context, removes switch, unlock context and return.

Note:
When we call this function, &conlock lock must be locked, because when we giving *con argument, some process can remove/change this context and after that there can be segfault.

Definition at line 6917 of file pbx.c.

References ast_context::alts, ast_free, ast_get_context_name(), AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_unlock_context(), ast_verb, ast_wrlock_context(), ast_sw::data, ast_sw::name, and ast_sw::registrar.

Referenced by ast_context_remove_switch().

06918 {
06919    struct ast_sw *i;
06920    int ret = -1;
06921 
06922    ast_wrlock_context(con);
06923 
06924    /* walk switches */
06925    AST_LIST_TRAVERSE_SAFE_BEGIN(&con->alts, i, list) {
06926       if (!strcmp(i->name, sw) && !strcmp(i->data, data) &&
06927          (!registrar || !strcmp(i->registrar, registrar))) {
06928          /* found, remove from list */
06929          ast_verb(3, "Removing switch '%s' from context '%s; registrar=%s'\n", sw, ast_get_context_name(con), registrar);
06930          AST_LIST_REMOVE_CURRENT(list);
06931          ast_free(i); /* free switch and return */
06932          ret = 0;
06933          break;
06934       }
06935    }
06936    AST_LIST_TRAVERSE_SAFE_END;
06937 
06938    ast_unlock_context(con);
06939 
06940    return ret;
06941 }

int ast_context_unlockmacro ( const char *  context  ) 

Unlocks the macrolock in the given context.

Parameters:
macrocontext name of the macro-context to unlock
Unlocks the given macro-context so that another thread (call) can execute it

Return values:
0 on success
-1 on failure
Note:
This function locks contexts list by &conlist, searches for the right context structure, and unlocks the macrolock mutex in that context. macrolock is used to limit a macro to be executed by one call at a time.
Parameters:
context The context

Definition at line 7159 of file pbx.c.

References ast_mutex_unlock, ast_unlock_contexts(), c, find_context_locked(), and ast_context::macrolock.

Referenced by _macro_exec().

07160 {
07161    struct ast_context *c;
07162    int ret = -1;
07163 
07164    c = find_context_locked(context);
07165    if (c) {
07166       ast_unlock_contexts();
07167 
07168       /* if we found context, unlock macrolock */
07169       ret = ast_mutex_unlock(&c->macrolock);
07170    }
07171 
07172    return ret;
07173 }

int ast_context_verify_includes ( struct ast_context con  ) 

Verifies includes in an ast_contect structure.

Parameters:
con context in which to verify the includes
Return values:
0 if no problems found
-1 if there were any missing context

Definition at line 643 of file conf2ael.c.

References localized_context_verify_includes().

Referenced by localized_context_verify_includes(), localized_pbx_load_module(), and pbx_load_module().

00644 {
00645    return  localized_context_verify_includes(con);
00646 }

struct ast_custom_function * ast_custom_function_find ( const char *  name  )  [read]

Definition at line 178 of file ael_main.c.

Referenced by ast_compile_ael2(), ast_func_read(), ast_func_read2(), ast_func_write(), AST_TEST_DEFINE(), config_curl(), destroy_curl(), handle_show_function(), op_func(), realtime_curl(), realtime_multi_curl(), require_curl(), store_curl(), update2_curl(), and update_curl().

00179 {
00180    return 0; /* in "standalone" mode, functions are just not avail */
00181 }

int ast_custom_function_unregister ( struct ast_custom_function acf  ) 

Unregister a custom function.

Definition at line 4030 of file pbx.c.

References ast_custom_function::acflist, AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_string_field_free_memory, ast_verb, AST_XML_DOC, ast_custom_function::docsrc, and ast_custom_function::name.

Referenced by _unload_module(), ast_features_config_shutdown(), load_module(), manager_shutdown(), message_shutdown(), reload(), unload_module(), and unload_pbx().

04031 {
04032    struct ast_custom_function *cur;
04033 
04034    if (!acf) {
04035       return -1;
04036    }
04037 
04038    AST_RWLIST_WRLOCK(&acf_root);
04039    if ((cur = AST_RWLIST_REMOVE(&acf_root, acf, acflist))) {
04040 #ifdef AST_XML_DOCS
04041       if (cur->docsrc == AST_XML_DOC) {
04042          ast_string_field_free_memory(acf);
04043       }
04044 #endif
04045       ast_verb(2, "Unregistered custom function %s\n", cur->name);
04046    }
04047    AST_RWLIST_UNLOCK(&acf_root);
04048 
04049    return cur ? 0 : -1;
04050 }

int ast_destroy_timing ( struct ast_timing i  ) 

Deallocates memory structures associated with a timing bitmap.

Parameters:
i Pointer to an ast_timing structure.
Return values:
0 success
non-zero failure (number suitable to pass to
See also:
strerror)

Definition at line 9349 of file pbx.c.

References ast_free, NULL, and ast_timing::timezone.

Referenced by ast_context_add_include2(), ast_context_remove_include2(), iftime(), pbx_builtin_execiftime(), and pbx_builtin_gotoiftime().

09350 {
09351    if (i->timezone) {
09352       ast_free(i->timezone);
09353       i->timezone = NULL;
09354    }
09355    return 0;
09356 }

enum ast_extension_states ast_devstate_to_extenstate ( enum ast_device_state  devstate  ) 

Map devstate to an extension state.

Parameters:
[in] devstate device state
Returns:
the extension state mapping.

Definition at line 4993 of file pbx.c.

References AST_DEVICE_BUSY, AST_DEVICE_INUSE, AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, AST_DEVICE_ONHOLD, AST_DEVICE_RINGING, AST_DEVICE_RINGINUSE, AST_DEVICE_TOTAL, AST_DEVICE_UNAVAILABLE, AST_DEVICE_UNKNOWN, AST_EXTENSION_BUSY, AST_EXTENSION_INUSE, AST_EXTENSION_NOT_INUSE, AST_EXTENSION_ONHOLD, AST_EXTENSION_RINGING, and AST_EXTENSION_UNAVAILABLE.

Referenced by ast_extension_state3(), and AST_TEST_DEFINE().

04994 {
04995    switch (devstate) {
04996    case AST_DEVICE_ONHOLD:
04997       return AST_EXTENSION_ONHOLD;
04998    case AST_DEVICE_BUSY:
04999       return AST_EXTENSION_BUSY;
05000    case AST_DEVICE_UNKNOWN:
05001       return AST_EXTENSION_NOT_INUSE;
05002    case AST_DEVICE_UNAVAILABLE:
05003    case AST_DEVICE_INVALID:
05004       return AST_EXTENSION_UNAVAILABLE;
05005    case AST_DEVICE_RINGINUSE:
05006       return (AST_EXTENSION_INUSE | AST_EXTENSION_RINGING);
05007    case AST_DEVICE_RINGING:
05008       return AST_EXTENSION_RINGING;
05009    case AST_DEVICE_INUSE:
05010       return AST_EXTENSION_INUSE;
05011    case AST_DEVICE_NOT_INUSE:
05012       return AST_EXTENSION_NOT_INUSE;
05013    case AST_DEVICE_TOTAL: /* not a device state, included for completeness */
05014       break;
05015    }
05016 
05017    return AST_EXTENSION_NOT_INUSE;
05018 }

int ast_exists_extension ( struct ast_channel c,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid 
)

Determine whether an extension exists.

Parameters:
c this is not important
context which context to look in
exten which extension to search for
priority priority of the action within the extension
callerid callerid to search for
Note:
It is possible for autoservice to be started and stopped on c during this function call, it is important that c is not locked prior to calling this. Otherwise a deadlock may occur
Returns:
If an extension within the given context(or callerid) with the given priority is found a non zero value will be returned. Otherwise, 0 is returned.
Examples:
/tmp/asterisk-trunk/trunk/main/app.c.

Definition at line 5940 of file pbx.c.

References E_MATCH, NULL, and pbx_extension_helper().

Referenced by __analog_ss_thread(), __ast_goto_if_exists(), __ast_pbx_run(), _macro_exec(), acf_isexten_exec(), action_originate(), analog_ss_thread(), ast_app_dtget(), ast_bridge_setup_after_goto(), ast_pbx_outgoing_exten(), cb_events(), chan_pjsip_cng_tone_detected(), cli_console_dial(), comeback_goto(), conf_run(), console_dial(), dahdi_handle_dtmf(), dial_exec_full(), dialplan_has_destination_cb(), disa_exec(), dp_lookup(), dundi_lookup_local(), fax_detect_framehook(), findmeexec(), get_also_info(), get_destination(), get_refer_info(), gosub_exec(), handle_gosub(), isexten_function_read(), jingle_new(), key_dial_page(), leave_voicemail(), local_call(), local_devicestate(), loopback_exists(), mgcp_ss(), minivm_greet_exec(), misdn_overlap_dial_task(), my_handle_dtmf(), new_subscribe(), onModeChanged(), ooh323_rtp_read(), options_on_rx_request(), pbx_builtin_waitexten(), phone_check_exception(), privacy_exec(), process_ast_dsp(), process_sdp(), readexten_exec(), refer_incoming_attended_request(), refer_incoming_blind_request(), register_peer_exten(), setsubstate(), show_debug_helper(), sip_new(), sip_read(), skinny_dialer(), socket_process_helper(), try_calling(), vm_authenticate(), and waitstream_core().

05941 {
05942    return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCH, 0, 0);
05943 }

int ast_explicit_goto ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority 
)

Note:
This function will handle locking the channel as needed.

Definition at line 9661 of file pbx.c.

References ast_channel_context_set(), ast_channel_exten_set(), ast_channel_flags(), ast_channel_lock, ast_channel_priority_set(), ast_channel_unlock, AST_FLAG_IN_AUTOLOOP, ast_strlen_zero, and ast_test_flag.

Referenced by __ast_goto_if_exists(), app_control_continue(), ast_async_goto(), ast_bridge_setup_after_goto(), disa_exec(), handle_setpriority(), msg_route(), and pbx_parseable_goto().

09662 {
09663    if (!chan)
09664       return -1;
09665 
09666    ast_channel_lock(chan);
09667 
09668    if (!ast_strlen_zero(context))
09669       ast_channel_context_set(chan, context);
09670    if (!ast_strlen_zero(exten))
09671       ast_channel_exten_set(chan, exten);
09672    if (priority > -1) {
09673       /* see flag description in channel.h for explanation */
09674       if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_AUTOLOOP)) {
09675          --priority;
09676       }
09677       ast_channel_priority_set(chan, priority);
09678    }
09679 
09680    ast_channel_unlock(chan);
09681 
09682    return 0;
09683 }

int ast_extension_close ( const char *  pattern,
const char *  data,
int  needmore 
)

Definition at line 3101 of file pbx.c.

References ast_log, E_CANMATCH, E_MATCHMORE, extension_match_core(), and LOG_WARNING.

Referenced by lua_find_extension(), and realtime_switch_common().

03102 {
03103    if (needmore != E_MATCHMORE && needmore != E_CANMATCH)
03104       ast_log(LOG_WARNING, "invalid argument %d\n", needmore);
03105    return extension_match_core(pattern, data, needmore);
03106 }

int ast_extension_cmp ( const char *  a,
const char *  b 
)

Determine if one extension should match before another.

Parameters:
a extension to compare with b
b extension to compare with a
Checks whether or extension a should match before extension b

Return values:
0 if the two extensions have equal matching priority
1 on a > b
-1 on a < b

Definition at line 2866 of file pbx.c.

References ext_cmp().

Referenced by lua_extension_cmp().

02867 {
02868    int cmp;
02869 
02870    cmp = ext_cmp(a, b);
02871    if (cmp < 0) {
02872       return -1;
02873    }
02874    if (cmp > 0) {
02875       return 1;
02876    }
02877    return 0;
02878 }

static int ast_extension_match ( const char *  pattern,
const char *  extension 
)

Determine if a given extension matches a given pattern (in NXX format).

Parameters:
pattern pattern to match
extension extension to check against the pattern.
Checks whether or not the given extension matches the given pattern.

Return values:
1 on match
0 on failure

Definition at line 4542 of file extconf.c.

References E_MATCH, and extension_match_core().

Referenced by ast_ignore_pattern(), do_say(), find_matching_priority(), load_module(), loopback_canmatch(), loopback_exists(), loopback_matchmore(), lua_find_extension(), manager_show_dialplan_helper(), matchcid(), misdn_cfg_is_msn_valid(), realtime_switch_common(), reload(), and show_dialplan_helper().

04543 {
04544    return extension_match_core(pattern, data, E_MATCH);
04545 }

int ast_extension_patmatch ( const char *  pattern,
const char *  data 
)

int ast_extension_state ( struct ast_channel c,
const char *  context,
const char *  exten 
)

Uses hint and devicestate callback to get the state of an extension.

Parameters:
c this is not important
context which context to look in
exten which extension to get state
Returns:
extension state as defined in the ast_extension_states enum

Definition at line 5152 of file pbx.c.

References internal_extension_state_extended(), and NULL.

Referenced by action_extensionstate(), extstate_read(), and get_queue_member_status().

05153 {
05154    return internal_extension_state_extended(c, context, exten, NULL);
05155 }

const char* ast_extension_state2str ( int  extension_state  ) 

Return string representation of the state of an extension.

Parameters:
extension_state is the numerical state delivered by ast_extension_state
Returns:
the state of an extension as string

Definition at line 5113 of file pbx.c.

References ARRAY_LEN, extension_states, and cfextension_states::text.

Referenced by action_extensionstate(), action_extensionstatelist(), AST_TEST_DEFINE(), extensionstate_update(), handle_request_subscribe(), handle_show_hint(), handle_show_hints(), hints_data_provider_get(), manager_state_cb(), show_channels_cb(), skinny_extensionstate_cb(), and to_ami().

05114 {
05115    int i;
05116 
05117    for (i = 0; (i < ARRAY_LEN(extension_states)); i++) {
05118       if (extension_states[i].extension_state == extension_state)
05119          return extension_states[i].text;
05120    }
05121    return "Unknown";
05122 }

int ast_extension_state_add ( const char *  context,
const char *  exten,
ast_state_cb_type  change_cb,
void *  data 
)

Registers a state change callback.

Parameters:
context which context to look in
exten which extension to get state
change_cb callback to call if state changed
data to pass to callback
Note:
The change_cb is called if the state of an extension is changed.
Return values:
-1 on failure
ID on success

Definition at line 5612 of file pbx.c.

References extension_state_add_destroy(), and NULL.

Referenced by __init_manager(), load_module(), and skinny_register().

05614 {
05615    return extension_state_add_destroy(context, exten, change_cb, NULL, data, 0);
05616 }

int ast_extension_state_add_destroy ( const char *  context,
const char *  exten,
ast_state_cb_type  change_cb,
ast_state_cb_destroy_type  destroy_cb,
void *  data 
)

Registers a state change callback with destructor.

Since:
1.8.9

10.1.0

Parameters:
context which context to look in
exten which extension to get state
change_cb callback to call if state changed
destroy_cb callback to call when registration destroyed.
data to pass to callback
Note:
The change_cb is called if the state of an extension is changed.

The destroy_cb is called when the registration is deleted so the registerer can release any associated resources.

Return values:
-1 on failure
ID on success

Definition at line 5605 of file pbx.c.

References extension_state_add_destroy().

05607 {
05608    return extension_state_add_destroy(context, exten, change_cb, destroy_cb, data, 0);
05609 }

int ast_extension_state_add_destroy_extended ( const char *  context,
const char *  exten,
ast_state_cb_type  change_cb,
ast_state_cb_destroy_type  destroy_cb,
void *  data 
)

Registers an extended state change callback with destructor.

Since:
11
Parameters:
context which context to look in
exten which extension to get state
change_cb callback to call if state changed
destroy_cb callback to call when registration destroyed.
data to pass to callback
Note:
The change_cb is called if the state of an extension is changed. The extended state is passed to the callback in the device_state_info member of ast_state_cb_info.

The destroy_cb is called when the registration is deleted so the registerer can release any associated resources.

Return values:
-1 on failure
ID on success

Definition at line 5619 of file pbx.c.

References extension_state_add_destroy().

Referenced by handle_request_subscribe(), and subscription_established().

05621 {
05622    return extension_state_add_destroy(context, exten, change_cb, destroy_cb, data, 1);
05623 }

int ast_extension_state_add_extended ( const char *  context,
const char *  exten,
ast_state_cb_type  change_cb,
void *  data 
)

Registers an extended state change callback.

Since:
11
Parameters:
context which context to look in
exten which extension to get state
change_cb callback to call if state changed
data to pass to callback
Note:
The change_cb is called if the state of an extension is changed. The extended state is passed to the callback in the device_state_info member of ast_state_cb_info.
Return values:
-1 on failure
ID on success

Definition at line 5626 of file pbx.c.

References extension_state_add_destroy(), and NULL.

05628 {
05629    return extension_state_add_destroy(context, exten, change_cb, NULL, data, 1);
05630 }

int ast_extension_state_del ( int  id,
ast_state_cb_type  change_cb 
)

Deletes a registered state change callback by ID.

Parameters:
id of the registered state callback to delete
change_cb callback to call if state changed (Used if id == 0 (global))
Return values:
0 success
-1 failure

Definition at line 5648 of file pbx.c.

References ao2_callback, ao2_find, ao2_lock, ao2_ref, ao2_unlock, ast_hint::callbacks, find_hint_by_cb_id(), and OBJ_UNLINK.

Referenced by dialog_unlink_all(), handle_request_subscribe(), skinny_session_cleanup(), subscription_shutdown(), and unload_module().

05649 {
05650    struct ast_state_cb *p_cur;
05651    int ret = -1;
05652 
05653    if (!id) {  /* id == 0 is a callback without extension */
05654       if (!change_cb) {
05655          return ret;
05656       }
05657       p_cur = ao2_find(statecbs, change_cb, OBJ_UNLINK);
05658       if (p_cur) {
05659          ret = 0;
05660          ao2_ref(p_cur, -1);
05661       }
05662    } else { /* callback with extension, find the callback based on ID */
05663       struct ast_hint *hint;
05664 
05665       ao2_lock(hints);/* Locked to hold off ast_merge_contexts_and_delete */
05666       hint = ao2_callback(hints, 0, find_hint_by_cb_id, &id);
05667       if (hint) {
05668          p_cur = ao2_find(hint->callbacks, &id, OBJ_UNLINK);
05669          if (p_cur) {
05670             ret = 0;
05671             ao2_ref(p_cur, -1);
05672          }
05673          ao2_ref(hint, -1);
05674       }
05675       ao2_unlock(hints);
05676    }
05677 
05678    return ret;
05679 }

int ast_extension_state_extended ( struct ast_channel c,
const char *  context,
const char *  exten,
struct ao2_container **  device_state_info 
)

Uses hint and devicestate callback to get the extended state of an extension.

Since:
11
Parameters:
c this is not important
context which context to look in
exten which extension to get state
[out] device_state_info ptr to an ao2_container with extended state info, must be unref'd after use.
Returns:
extension state as defined in the ast_extension_states enum

Definition at line 5158 of file pbx.c.

References alloc_device_state_info(), ao2_ref, container, get_device_state_causing_channels(), internal_extension_state_extended(), and NULL.

Referenced by exten_state_data_alloc(), and handle_request_subscribe().

05160 {
05161    struct ao2_container *container = NULL;
05162    int ret;
05163 
05164    if (device_state_info) {
05165       container = alloc_device_state_info();
05166    }
05167 
05168    ret = internal_extension_state_extended(c, context, exten, container);
05169    if (ret < 0 && container) {
05170       ao2_ref(container, -1);
05171       container = NULL;
05172    }
05173 
05174    if (device_state_info) {
05175       get_device_state_causing_channels(container);
05176       *device_state_info = container;
05177    }
05178 
05179    return ret;
05180 }

int ast_findlabel_extension ( struct ast_channel c,
const char *  context,
const char *  exten,
const char *  label,
const char *  callerid 
)

Find the priority of an extension that has the specified label.

Parameters:
c this is not important
context which context to look in
exten which extension to search for
label label of the action within the extension to match to priority
callerid callerid to search for
Note:
It is possible for autoservice to be started and stopped on c during this function call, it is important that c is not locked prior to calling this. Otherwise a deadlock may occur
Return values:
the priority which matches the given label in the extension
-1 if not found.

Definition at line 5945 of file pbx.c.

References E_FINDLABEL, NULL, and pbx_extension_helper().

Referenced by action_originate(), action_redirect(), ari_channels_handle_originate_with_id(), ast_ari_channels_continue_in_dialplan(), handle_gosub(), handle_setpriority(), isexten_function_read(), and pbx_parseable_goto().

05946 {
05947    return pbx_extension_helper(c, NULL, context, exten, 0, label, callerid, E_FINDLABEL, 0, 0);
05948 }

static int ast_findlabel_extension2 ( struct ast_channel c,
struct ast_context con,
const char *  exten,
const char *  label,
const char *  callerid 
)

Find the priority of an extension that has the specified label.

Note:
It is possible for autoservice to be started and stopped on c during this function call, it is important that c is not locked prior to calling this. Otherwise a deadlock may occur

This function is the same as ast_findlabel_extension, except that it accepts a pointer to an ast_context structure to specify the context instead of the name of the context. Otherwise, the functions behave the same.

Definition at line 5219 of file extconf.c.

References E_FINDLABEL, NULL, and pbx_extension_helper().

Referenced by pbx_load_config().

05220 {
05221    return pbx_extension_helper(c, con, NULL, exten, 0, label, callerid, E_FINDLABEL);
05222 }

int ast_func_read ( struct ast_channel chan,
const char *  function,
char *  workspace,
size_t  len 
)

executes a read operation on a function

Parameters:
chan Channel to execute on
function Data containing the function call string (will be modified)
workspace A pointer to safe memory to use for a return value
len the number of bytes in workspace
This application executes a function in read mode on a given channel.

Return values:
0 success
non-zero failure

Definition at line 4338 of file pbx.c.

References __ast_module_user_add(), __ast_module_user_remove(), args, ast_copy_string(), ast_custom_function_find(), ast_free, ast_log, ast_str_buffer(), ast_str_create(), ast_str_size(), ast_strdupa, copy(), func_args(), is_read_allowed(), LOG_ERROR, ast_custom_function::mod, NULL, ast_custom_function::read, ast_custom_function::read2, and str.

Referenced by action_getvar(), generate_status(), handle_getvariable(), lua_get_variable_value(), and pbx_substitute_variables_helper_full().

04339 {
04340    char *copy = ast_strdupa(function);
04341    char *args = func_args(copy);
04342    struct ast_custom_function *acfptr = ast_custom_function_find(copy);
04343    int res;
04344    struct ast_module_user *u = NULL;
04345 
04346    if (acfptr == NULL) {
04347       ast_log(LOG_ERROR, "Function %s not registered\n", copy);
04348    } else if (!acfptr->read && !acfptr->read2) {
04349       ast_log(LOG_ERROR, "Function %s cannot be read\n", copy);
04350    } else if (!is_read_allowed(acfptr)) {
04351       ast_log(LOG_ERROR, "Dangerous function %s read blocked\n", copy);
04352    } else if (acfptr->read) {
04353       if (acfptr->mod) {
04354          u = __ast_module_user_add(acfptr->mod, chan);
04355       }
04356       res = acfptr->read(chan, copy, args, workspace, len);
04357       if (acfptr->mod && u) {
04358          __ast_module_user_remove(acfptr->mod, u);
04359       }
04360       return res;
04361    } else {
04362       struct ast_str *str = ast_str_create(16);
04363       if (acfptr->mod) {
04364          u = __ast_module_user_add(acfptr->mod, chan);
04365       }
04366       res = acfptr->read2(chan, copy, args, &str, 0);
04367       if (acfptr->mod && u) {
04368          __ast_module_user_remove(acfptr->mod, u);
04369       }
04370       ast_copy_string(workspace, ast_str_buffer(str), len > ast_str_size(str) ? ast_str_size(str) : len);
04371       ast_free(str);
04372       return res;
04373    }
04374    return -1;
04375 }

int ast_func_read2 ( struct ast_channel chan,
const char *  function,
struct ast_str **  str,
ssize_t  maxlen 
)

executes a read operation on a function

Parameters:
chan Channel to execute on
function Data containing the function call string (will be modified)
str A dynamic string buffer into which to place the result.
maxlen <0 if the dynamic buffer should not grow; >0 if the dynamic buffer should be limited to that number of bytes; 0 if the dynamic buffer has no upper limit
This application executes a function in read mode on a given channel.

Return values:
0 success
non-zero failure

Definition at line 4377 of file pbx.c.

References __ast_module_user_add(), __ast_module_user_remove(), args, ast_custom_function_find(), ast_log, ast_str_buffer(), ast_str_make_space(), ast_str_reset(), ast_str_size(), ast_strdupa, copy(), func_args(), is_read_allowed(), LOG_ERROR, maxsize, ast_custom_function::mod, NULL, ast_custom_function::read, ast_custom_function::read2, ast_custom_function::read_max, and VAR_BUF_SIZE.

Referenced by ast_ari_channels_get_channel_var(), ast_channel_get_manager_vars(), ast_str_substitute_variables_full(), and AST_TEST_DEFINE().

04378 {
04379    char *copy = ast_strdupa(function);
04380    char *args = func_args(copy);
04381    struct ast_custom_function *acfptr = ast_custom_function_find(copy);
04382    int res;
04383    struct ast_module_user *u = NULL;
04384 
04385    if (acfptr == NULL) {
04386       ast_log(LOG_ERROR, "Function %s not registered\n", copy);
04387    } else if (!acfptr->read && !acfptr->read2) {
04388       ast_log(LOG_ERROR, "Function %s cannot be read\n", copy);
04389    } else if (!is_read_allowed(acfptr)) {
04390       ast_log(LOG_ERROR, "Dangerous function %s read blocked\n", copy);
04391    } else {
04392       if (acfptr->mod) {
04393          u = __ast_module_user_add(acfptr->mod, chan);
04394       }
04395       ast_str_reset(*str);
04396       if (acfptr->read2) {
04397          /* ast_str enabled */
04398          res = acfptr->read2(chan, copy, args, str, maxlen);
04399       } else {
04400          /* Legacy function pointer, allocate buffer for result */
04401          int maxsize = ast_str_size(*str);
04402          if (maxlen > -1) {
04403             if (maxlen == 0) {
04404                if (acfptr->read_max) {
04405                   maxsize = acfptr->read_max;
04406                } else {
04407                   maxsize = VAR_BUF_SIZE;
04408                }
04409             } else {
04410                maxsize = maxlen;
04411             }
04412             ast_str_make_space(str, maxsize);
04413          }
04414          res = acfptr->read(chan, copy, args, ast_str_buffer(*str), maxsize);
04415       }
04416       if (acfptr->mod && u) {
04417          __ast_module_user_remove(acfptr->mod, u);
04418       }
04419       return res;
04420    }
04421    return -1;
04422 }

int ast_func_write ( struct ast_channel chan,
const char *  function,
const char *  value 
)

executes a write operation on a function

Parameters:
chan Channel to execute on
function Data containing the function call string (will be modified)
value A value parameter to pass for writing
This application executes a function in write mode on a given channel.

Return values:
0 success
non-zero failure

Definition at line 4424 of file pbx.c.

References __ast_module_user_add(), __ast_module_user_remove(), args, ast_custom_function_find(), ast_log, ast_strdupa, copy(), func_args(), is_write_allowed(), LOG_ERROR, ast_custom_function::mod, NULL, and ast_custom_function::write.

Referenced by ast_channel_hangupcause_hash_set(), AST_TEST_DEFINE(), conf_run(), confbridge_exec(), pbx_builtin_pushvar_helper(), pbx_builtin_setvar_helper(), setup_profile_bridge(), setup_profile_caller(), and setup_profile_paged().

04425 {
04426    char *copy = ast_strdupa(function);
04427    char *args = func_args(copy);
04428    struct ast_custom_function *acfptr = ast_custom_function_find(copy);
04429 
04430    if (acfptr == NULL) {
04431       ast_log(LOG_ERROR, "Function %s not registered\n", copy);
04432    } else if (!acfptr->write) {
04433       ast_log(LOG_ERROR, "Function %s cannot be written to\n", copy);
04434    } else if (!is_write_allowed(acfptr)) {
04435       ast_log(LOG_ERROR, "Dangerous function %s write blocked\n", copy);
04436    } else {
04437       int res;
04438       struct ast_module_user *u = NULL;
04439       if (acfptr->mod)
04440          u = __ast_module_user_add(acfptr->mod, chan);
04441       res = acfptr->write(chan, copy, args, value);
04442       if (acfptr->mod && u)
04443          __ast_module_user_remove(acfptr->mod, u);
04444       return res;
04445    }
04446 
04447    return -1;
04448 }

static const char * ast_get_context_name ( struct ast_context con  ) 

const char* ast_get_context_registrar ( struct ast_context c  ) 

Definition at line 12220 of file pbx.c.

References NULL, and ast_context::registrar.

Referenced by handle_cli_dialplan_save(), show_debug_helper(), and show_dialplan_helper().

12221 {
12222    return c ? c->registrar : NULL;
12223 }

const char* ast_get_extension_app ( struct ast_exten e  ) 

void* ast_get_extension_app_data ( struct ast_exten e  ) 

const char* ast_get_extension_cidmatch ( struct ast_exten e  ) 

Definition at line 12245 of file pbx.c.

References ast_exten::cidmatch, and NULL.

Referenced by complete_dialplan_remove_extension(), find_matching_priority(), handle_cli_dialplan_save(), and test_exten().

12246 {
12247    return e ? e->cidmatch : NULL;
12248 }

struct ast_context* ast_get_extension_context ( struct ast_exten exten  )  [read]

const char* ast_get_extension_label ( struct ast_exten e  ) 

Definition at line 12197 of file pbx.c.

References ast_exten::label, and NULL.

Referenced by handle_cli_dialplan_save(), manager_show_dialplan_helper(), and show_dialplan_helper().

12198 {
12199    return exten ? exten->label : NULL;
12200 }

int ast_get_extension_matchcid ( struct ast_exten e  ) 

Definition at line 12240 of file pbx.c.

References ast_exten::matchcid.

Referenced by complete_dialplan_remove_extension(), find_matching_priority(), and handle_cli_dialplan_save().

12241 {
12242    return e ? e->matchcid : 0;
12243 }

const char* ast_get_extension_name ( struct ast_exten exten  ) 

int ast_get_extension_priority ( struct ast_exten exten  ) 

Definition at line 12212 of file pbx.c.

References ast_exten::priority.

Referenced by complete_dialplan_remove_extension(), find_matching_priority(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), and print_ext().

12213 {
12214    return exten ? exten->priority : -1;
12215 }

const char* ast_get_extension_registrar ( struct ast_exten e  ) 

int ast_get_hint ( char *  hint,
int  hintsize,
char *  name,
int  namesize,
struct ast_channel c,
const char *  context,
const char *  exten 
)

If an extension hint exists, return non-zero.

Parameters:
hint buffer for hint
hintsize size of hint buffer, in bytes
name buffer for name portion of hint
namesize size of name buffer
c Channel from which to return the hint. This is only important when the hint or name contains an expression to be expanded.
context which context to look in
exten which extension to search for
Returns:
If an extension within the given context with the priority PRIORITY_HINT is found, a non zero value will be returned. Otherwise, 0 is returned.

Definition at line 5902 of file pbx.c.

References ast_copy_string(), ast_get_extension_app(), ast_get_extension_app_data(), ast_hint_extension(), e, and tmp().

Referenced by action_extensionstate(), get_cid_name(), get_destination(), hint_read(), manager_state_cb(), skinny_extensionstate_cb(), and state_notify_build_xml().

05903 {
05904    struct ast_exten *e = ast_hint_extension(c, context, exten);
05905 
05906    if (e) {
05907       if (hint)
05908          ast_copy_string(hint, ast_get_extension_app(e), hintsize);
05909       if (name) {
05910          const char *tmp = ast_get_extension_app_data(e);
05911          if (tmp)
05912             ast_copy_string(name, tmp, namesize);
05913       }
05914       return -1;
05915    }
05916    return 0;
05917 }

const char* ast_get_ignorepat_name ( struct ast_ignorepat ip  ) 

const char* ast_get_ignorepat_registrar ( struct ast_ignorepat ip  ) 

Definition at line 12235 of file pbx.c.

References NULL, and ast_ignorepat::registrar.

Referenced by context_merge_incls_swits_igps_other_registrars(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), and show_dialplan_helper().

12236 {
12237    return ip ? ip->registrar : NULL;
12238 }

const char* ast_get_include_name ( struct ast_include include  ) 

const char* ast_get_include_registrar ( struct ast_include i  ) 

const char* ast_get_switch_data ( struct ast_sw sw  ) 

Definition at line 12265 of file pbx.c.

References ast_sw::data, and NULL.

Referenced by context_merge_incls_swits_igps_other_registrars(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), and show_dialplan_helper().

12266 {
12267    return sw ? sw->data : NULL;
12268 }

int ast_get_switch_eval ( struct ast_sw sw  ) 

Definition at line 12270 of file pbx.c.

References ast_sw::eval.

Referenced by context_merge_incls_swits_igps_other_registrars().

12271 {
12272    return sw->eval;
12273 }

const char* ast_get_switch_name ( struct ast_sw sw  ) 

Definition at line 12260 of file pbx.c.

References ast_sw::name, and NULL.

Referenced by context_merge_incls_swits_igps_other_registrars(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), and show_dialplan_helper().

12261 {
12262    return sw ? sw->name : NULL;
12263 }

const char* ast_get_switch_registrar ( struct ast_sw sw  ) 

Definition at line 12275 of file pbx.c.

References NULL, and ast_sw::registrar.

Referenced by context_merge_incls_swits_igps_other_registrars(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), and show_dialplan_helper().

12276 {
12277    return sw ? sw->registrar : NULL;
12278 }

int ast_goto_if_exists ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority 
)

Note:
This function will handle locking the channel as needed.

Definition at line 12370 of file pbx.c.

References __ast_goto_if_exists().

Referenced by ast_bridge_setup_after_goto(), background_detect_exec(), channel_spy(), common_exec(), conf_run(), goto_exten(), onedigit_goto(), select_entry(), valid_exit(), vm_execmain(), and vmauthenticate().

12371 {
12372    return __ast_goto_if_exists(chan, context, exten, priority, 0);
12373 }

int ast_hashtab_compare_contexts ( const void *  ah_a,
const void *  ah_b 
)

hashtable functions for contexts

Definition at line 596 of file ael_main.c.

Referenced by ast_context_find_or_create(), lua_register_hints(), lua_register_switches(), and pbx_load_module().

00597 {
00598    return 0;
00599 }

unsigned int ast_hashtab_hash_contexts ( const void *  obj  ) 

Definition at line 603 of file ael_main.c.

Referenced by ast_context_find_or_create(), lua_register_hints(), lua_register_switches(), and pbx_load_module().

00604 {
00605    return 0;
00606 }

int ast_hint_presence_state ( struct ast_channel c,
const char *  context,
const char *  exten,
char **  subtype,
char **  message 
)

Uses hint and presence state callback to get the presence state of an extension.

Parameters:
c this is not important
context which context to look in
exten which extension to get state
[out] subtype Further information regarding the presence returned
[out] message Custom message further describing current presence
Note:
The subtype and message are dynamically allocated and must be freed by the caller of this function.
Returns:
returns the presence state value.

Definition at line 5208 of file pbx.c.

References ast_exten::app, ast_add_extension(), ast_free_ptr, ast_hint_extension(), ast_strdup, ast_exten::cidmatch, ast_exten::data, e, ast_exten::exten, extension_presence_state_helper(), ast_exten::label, ast_exten::matchcid, ast_context::name, NULL, ast_exten::parent, ast_exten::priority, and ast_exten::registrar.

Referenced by exten_state_data_alloc(), and handle_request_subscribe().

05209 {
05210    struct ast_exten *e;
05211 
05212    if (!(e = ast_hint_extension(c, context, exten))) {  /* Do we have a hint for this extension ? */
05213       return -1;                   /* No hint, return -1 */
05214    }
05215 
05216    if (e->exten[0] == '_') {
05217       /* Create this hint on-the-fly */
05218       ast_add_extension(e->parent->name, 0, exten, e->priority, e->label,
05219          e->matchcid ? e->cidmatch : NULL, e->app, ast_strdup(e->data), ast_free_ptr,
05220          e->registrar);
05221       if (!(e = ast_hint_extension(c, context, exten))) {
05222          /* Improbable, but not impossible */
05223          return -1;
05224       }
05225    }
05226 
05227    return extension_presence_state_helper(e, subtype, message);
05228 }

int ast_ignore_pattern ( const char *  context,
const char *  pattern 
)

Checks to see if a number should be ignored.

Parameters:
context context to search within
pattern to check whether it should be ignored or not
Check if a number should be ignored with respect to dialtone cancellation.

Return values:
0 if the pattern should not be ignored
non-zero if the pattern should be ignored
Examples:
/tmp/asterisk-trunk/trunk/main/app.c.

Definition at line 9603 of file pbx.c.

References ast_context_find(), ast_extension_match(), ast_context::ignorepats, ast_ignorepat::next, and ast_ignorepat::pattern.

Referenced by __analog_ss_thread(), analog_ss_thread(), ast_app_dtget(), disa_exec(), dp_lookup(), dundi_lookup_local(), and mgcp_ss().

09604 {
09605    struct ast_context *con = ast_context_find(context);
09606 
09607    if (con) {
09608       struct ast_ignorepat *pat;
09609 
09610       for (pat = con->ignorepats; pat; pat = pat->next) {
09611          if (ast_extension_match(pat->pattern, pattern))
09612             return 1;
09613       }
09614    }
09615 
09616    return 0;
09617 }

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

Parameters:
c not really important XXX
context context to serach within
exten extension to check
priority priority of extension path
callerid callerid of extension being searched for
Note:
It is possible for autoservice to be started and stopped on c during this function call, it is important that c is not locked prior to calling this. Otherwise a deadlock may occur
Returns:
If "exten" *could match* a valid extension in this context with some more digits, return non-zero. Does NOT return non-zero if this is an exact-match only. Basically, when this returns 0, no matter what you add to exten, it's not going to be a valid extension anymore
Examples:
/tmp/asterisk-trunk/trunk/main/app.c.

Definition at line 5960 of file pbx.c.

References E_MATCHMORE, NULL, and pbx_extension_helper().

Referenced by __analog_ss_thread(), __ast_pbx_run(), analog_ss_thread(), ast_app_dtget(), collect_digits(), disa_exec(), dp_lookup(), dundi_lookup_local(), key_dial_page(), loopback_matchmore(), mgcp_ss(), pbx_builtin_background(), readexten_exec(), and skinny_dialer().

05961 {
05962    return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCHMORE, 0, 0);
05963 }

void ast_merge_contexts_and_delete ( struct ast_context **  extcontexts,
struct ast_hashtab exttable,
const char *  registrar 
)

Merge the temporary contexts into a global contexts list and delete from the global list the ones that are being added.

Parameters:
extcontexts pointer to the ast_context structure
exttable pointer to the ast_hashtab structure that contains all the elements in extcontexts
registrar of the context; if it's set the routine will delete all contexts that belong to that registrar; if NULL only the contexts that are specified in extcontexts

Definition at line 650 of file conf2ael.c.

References localized_merge_contexts_and_delete().

Referenced by localized_merge_contexts_and_delete(), localized_pbx_load_module(), lua_reload_extensions(), and pbx_load_module().

00651 {
00652    localized_merge_contexts_and_delete(extcontexts, exttable, registrar);
00653 }

int ast_parseable_goto ( struct ast_channel chan,
const char *  goto_string 
)

Note:
This function will handle locking the channel as needed.
Examples:
/tmp/asterisk-trunk/trunk/main/app.c.

Definition at line 12435 of file pbx.c.

References pbx_parseable_goto().

Referenced by _while_exec(), ast_bridge_setup_after_goto(), dial_exec_full(), gosub_exec(), ivr_dispatch(), pbx_builtin_goto(), and while_continue_exec().

12436 {
12437    return pbx_parseable_goto(chan, goto_string, 0);
12438 }

void ast_pbx_h_exten_run ( struct ast_channel chan,
const char *  context 
)

Run the h exten from the given context.

Since:
11.0
Parameters:
chan Channel to run the h exten on.
context Context the h exten is in.
Returns:
Nothing

Definition at line 5970 of file pbx.c.

References ast_channel_caller(), ast_channel_context(), ast_channel_context_set(), ast_channel_exten(), ast_channel_exten_set(), ast_channel_flags(), ast_channel_lock, ast_channel_name(), ast_channel_priority(), ast_channel_priority_set(), ast_channel_unlock, ast_debug, AST_FLAG_BRIDGE_HANGUP_RUN, AST_FLAG_IN_AUTOLOOP, ast_set2_flag, ast_set_flag, AST_SOFTHANGUP_HANGUP_EXEC, ast_softhangup_nolock(), ast_spawn_extension(), ast_test_flag, ast_verb, NULL, and S_COR.

Referenced by __ast_pbx_run(), and ast_bridge_setup_after_goto().

05971 {
05972    int autoloopflag;
05973    int found;
05974    int spawn_error;
05975 
05976    ast_channel_lock(chan);
05977 
05978    /*
05979     * Make sure that the channel is marked as hungup since we are
05980     * going to run the h exten on it.
05981     */
05982    ast_softhangup_nolock(chan, AST_SOFTHANGUP_HANGUP_EXEC);
05983 
05984    /* Set h exten location */
05985    if (context != ast_channel_context(chan)) {
05986       ast_channel_context_set(chan, context);
05987    }
05988    ast_channel_exten_set(chan, "h");
05989    ast_channel_priority_set(chan, 1);
05990 
05991    /* Save autoloop flag */
05992    autoloopflag = ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_AUTOLOOP);
05993    ast_set_flag(ast_channel_flags(chan), AST_FLAG_IN_AUTOLOOP);
05994    ast_channel_unlock(chan);
05995 
05996    for (;;) {
05997       spawn_error = ast_spawn_extension(chan, ast_channel_context(chan),
05998          ast_channel_exten(chan), ast_channel_priority(chan),
05999          S_COR(ast_channel_caller(chan)->id.number.valid,
06000             ast_channel_caller(chan)->id.number.str, NULL), &found, 1);
06001 
06002       ast_channel_lock(chan);
06003       if (spawn_error) {
06004          /* The code after the loop needs the channel locked. */
06005          break;
06006       }
06007       ast_channel_priority_set(chan, ast_channel_priority(chan) + 1);
06008       ast_channel_unlock(chan);
06009    }
06010    if (found && spawn_error) {
06011       /* Something bad happened, or a hangup has been requested. */
06012       ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n",
06013          ast_channel_context(chan), ast_channel_exten(chan),
06014          ast_channel_priority(chan), ast_channel_name(chan));
06015       ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n",
06016          ast_channel_context(chan), ast_channel_exten(chan),
06017          ast_channel_priority(chan), ast_channel_name(chan));
06018    }
06019 
06020    /* An "h" exten has been run, so indicate that one has been run. */
06021    ast_set_flag(ast_channel_flags(chan), AST_FLAG_BRIDGE_HANGUP_RUN);
06022 
06023    /* Restore autoloop flag */
06024    ast_set2_flag(ast_channel_flags(chan), autoloopflag, AST_FLAG_IN_AUTOLOOP);
06025    ast_channel_unlock(chan);
06026 }

void ast_pbx_hangup_handler_destroy ( struct ast_channel chan  ) 

Destroy the hangup handler container on a channel.

Since:
11.0
Parameters:
chan Channel to destroy the hangup handler container on.
Returns:
Nothing

Definition at line 6091 of file pbx.c.

References ast_channel_hangup_handlers(), ast_channel_lock, ast_channel_unlock, ast_free, and AST_LIST_REMOVE_HEAD.

Referenced by ast_channel_destructor(), and ast_dummy_channel_destructor().

06092 {
06093    struct ast_hangup_handler_list *handlers;
06094    struct ast_hangup_handler *h_handler;
06095 
06096    ast_channel_lock(chan);
06097 
06098    /* Get rid of each of the hangup handlers on the channel */
06099    handlers = ast_channel_hangup_handlers(chan);
06100    while ((h_handler = AST_LIST_REMOVE_HEAD(handlers, node))) {
06101       ast_free(h_handler);
06102    }
06103 
06104    ast_channel_unlock(chan);
06105 }

void ast_pbx_hangup_handler_init ( struct ast_channel chan  ) 

Init the hangup handler container on a channel.

Since:
11.0
Parameters:
chan Channel to init the hangup handler container on.
Returns:
Nothing

Definition at line 6083 of file pbx.c.

References ast_channel_hangup_handlers(), and AST_LIST_HEAD_INIT_NOLOCK.

Referenced by __ast_channel_alloc_ap(), and ast_dummy_channel_alloc().

06084 {
06085    struct ast_hangup_handler_list *handlers;
06086 
06087    handlers = ast_channel_hangup_handlers(chan);
06088    AST_LIST_HEAD_INIT_NOLOCK(handlers);
06089 }

int ast_pbx_hangup_handler_pop ( struct ast_channel chan  ) 

Pop the top of the channel hangup handler stack.

Since:
11.0
Parameters:
chan Channel to push the hangup handler onto.
Return values:
TRUE if a handler was popped off of the stack.

Definition at line 6107 of file pbx.c.

References ast_hangup_handler::args, ast_channel_hangup_handlers(), ast_channel_lock, ast_channel_unlock, ast_free, AST_LIST_REMOVE_HEAD, and publish_hangup_handler_message().

Referenced by func_channel_write_real().

06108 {
06109    struct ast_hangup_handler_list *handlers;
06110    struct ast_hangup_handler *h_handler;
06111 
06112    ast_channel_lock(chan);
06113    handlers = ast_channel_hangup_handlers(chan);
06114    h_handler = AST_LIST_REMOVE_HEAD(handlers, node);
06115    if (h_handler) {
06116       publish_hangup_handler_message("pop", chan, h_handler->args);
06117    }
06118    ast_channel_unlock(chan);
06119    if (h_handler) {
06120       ast_free(h_handler);
06121       return 1;
06122    }
06123    return 0;
06124 }

void ast_pbx_hangup_handler_push ( struct ast_channel chan,
const char *  handler 
)

Push the given hangup handler onto the channel hangup handler stack.

Since:
11.0
Parameters:
chan Channel to push the hangup handler onto.
handler Gosub application parameter string.
Returns:
Nothing

Definition at line 6126 of file pbx.c.

References ast_hangup_handler::args, ast_app_expand_sub_args(), ast_channel_hangup_handlers(), ast_channel_lock, ast_channel_unlock, ast_free, AST_LIST_INSERT_HEAD, ast_malloc, ast_strlen_zero, and publish_hangup_handler_message().

Referenced by func_channel_write_real().

06127 {
06128    struct ast_hangup_handler_list *handlers;
06129    struct ast_hangup_handler *h_handler;
06130    const char *expanded_handler;
06131 
06132    if (ast_strlen_zero(handler)) {
06133       return;
06134    }
06135 
06136    expanded_handler = ast_app_expand_sub_args(chan, handler);
06137    if (!expanded_handler) {
06138       return;
06139    }
06140    h_handler = ast_malloc(sizeof(*h_handler) + 1 + strlen(expanded_handler));
06141    if (!h_handler) {
06142       ast_free((char *) expanded_handler);
06143       return;
06144    }
06145    strcpy(h_handler->args, expanded_handler);/* Safe */
06146    ast_free((char *) expanded_handler);
06147 
06148    ast_channel_lock(chan);
06149 
06150    handlers = ast_channel_hangup_handlers(chan);
06151    AST_LIST_INSERT_HEAD(handlers, h_handler, node);
06152    publish_hangup_handler_message("push", chan, h_handler->args);
06153    ast_channel_unlock(chan);
06154 }

int ast_pbx_hangup_handler_run ( struct ast_channel chan  ) 

Run all hangup handlers on the channel.

Since:
11.0
Parameters:
chan Channel to run the hangup handlers on.
Note:
Absolutely _NO_ channel locks should be held before calling this function.
Return values:
Zero if no hangup handlers run.
non-zero if hangup handlers were run.

Definition at line 6046 of file pbx.c.

References ast_hangup_handler::args, ast_app_exec_sub(), ast_channel_hangup_handlers(), ast_channel_lock, ast_channel_unlock, ast_free, AST_LIST_EMPTY, AST_LIST_REMOVE_HEAD, AST_SOFTHANGUP_HANGUP_EXEC, ast_softhangup_nolock(), NULL, and publish_hangup_handler_message().

Referenced by __ast_pbx_run(), and ast_hangup().

06047 {
06048    struct ast_hangup_handler_list *handlers;
06049    struct ast_hangup_handler *h_handler;
06050 
06051    ast_channel_lock(chan);
06052    handlers = ast_channel_hangup_handlers(chan);
06053    if (AST_LIST_EMPTY(handlers)) {
06054       ast_channel_unlock(chan);
06055       return 0;
06056    }
06057 
06058    /*
06059     * Make sure that the channel is marked as hungup since we are
06060     * going to run the hangup handlers on it.
06061     */
06062    ast_softhangup_nolock(chan, AST_SOFTHANGUP_HANGUP_EXEC);
06063 
06064    for (;;) {
06065       handlers = ast_channel_hangup_handlers(chan);
06066       h_handler = AST_LIST_REMOVE_HEAD(handlers, node);
06067       if (!h_handler) {
06068          break;
06069       }
06070 
06071       publish_hangup_handler_message("run", chan, h_handler->args);
06072       ast_channel_unlock(chan);
06073 
06074       ast_app_exec_sub(NULL, chan, h_handler->args, 1);
06075       ast_free(h_handler);
06076 
06077       ast_channel_lock(chan);
06078    }
06079    ast_channel_unlock(chan);
06080    return 1;
06081 }

int ast_pbx_outgoing_app ( const char *  type,
struct ast_format_cap cap,
const char *  addr,
int  timeout,
const char *  app,
const char *  appdata,
int *  reason,
int  synchronous,
const char *  cid_num,
const char *  cid_name,
struct ast_variable vars,
const char *  account,
struct ast_channel **  locked_channel,
const struct ast_assigned_ids assignedids 
)

Synchronously or asynchronously make an outbound call and execute an application on the channel.

Note that when the application stops executing, the channel is hungup.

Parameters:
type The channel technology to create
cap The format capabilities for the channel
addr Address data to pass to the channel technology driver
timeout How long we should attempt to dial the outbound channel
app The name of the application to execute
appdata Data to pass to the application
reason Optional. If provided, the dialed status of the outgoing channel. Codes are AST_CONTROL_xxx values. Valid only if synchronous is non-zero.
synchronous If zero then don't wait for anything. If one then block until the outbound channel answers or the call fails. If greater than one then wait for the call to complete.
cid_num The caller ID number to set on the outbound channel
cid_name The caller ID name to set on the outbound channel
vars Variables to set on the outbound channel
account The accountcode for the outbound channel
locked_channel Optional. The outbound channel that was created if success is returned. Otherwise it is set to NULL. This is returned both locked and reference bumped.
assignedids Optional. The uniqueid(s) to assign the channel(s) that are created.
Return values:
0 on success
-1 on failure

Definition at line 10584 of file pbx.c.

References ast_strlen_zero, NULL, and pbx_outgoing_attempt().

Referenced by action_originate(), attempt_thread(), fast_originate(), orig_app(), and originate_exec().

10589 {
10590    if (reason) {
10591       *reason = 0;
10592    }
10593    if (locked_channel) {
10594       *locked_channel = NULL;
10595    }
10596    if (ast_strlen_zero(app)) {
10597       return -1;
10598    }
10599 
10600    return pbx_outgoing_attempt(type, cap, addr, timeout, NULL, NULL, 0, app, appdata,
10601       reason, synchronous, cid_num, cid_name, vars, account, locked_channel, 0,
10602       assignedids);
10603 }

int ast_pbx_outgoing_exten ( const char *  type,
struct ast_format_cap cap,
const char *  addr,
int  timeout,
const char *  context,
const char *  exten,
int  priority,
int *  reason,
int  synchronous,
const char *  cid_num,
const char *  cid_name,
struct ast_variable vars,
const char *  account,
struct ast_channel **  locked_channel,
int  early_media,
const struct ast_assigned_ids assignedids 
)

Synchronously or asynchronously make an outbound call and send it to a particular extension.

Parameters:
type The channel technology to create
cap The format capabilities for the channel
addr Address data to pass to the channel technology driver
timeout How long we should attempt to dial the outbound channel
context The destination context for the outbound channel
exten The destination extension for the outbound channel
priority The destination priority for the outbound channel
reason Optional. If provided, the dialed status of the outgoing channel. Codes are AST_CONTROL_xxx values. Valid only if synchronous is non-zero.
synchronous If zero then don't wait for anything. If one then block until the outbound channel answers or the call fails. If greater than one then wait for the call to complete or if the call doesn't answer and failed exists then run a channel named OutgoingSpoolFailed at failed.
cid_num The caller ID number to set on the outbound channel
cid_name The caller ID name to set on the outbound channel
vars Variables to set on the outbound channel
account The accountcode for the outbound channel
locked_channel Optional. The outbound channel that was created if success is returned. Otherwise it is set to NULL. This is returned both locked and reference bumped.
early_media If non-zero the channel "answers" when progress is indicated.
assignedids Optional. The uniqueid(s) to assign the channel(s) that are created.
Return values:
0 on success
-1 on failure

Todo:
XXX Not good. The channel name is not unique if more than one originate fails at a time.

Definition at line 10530 of file pbx.c.

References ast_assert, ast_channel_alloc, ast_channel_name(), ast_channel_unlock, ast_exists_extension(), ast_hangup(), ast_log, ast_pbx_run(), ast_set_variables(), AST_STATE_DOWN, LOG_ERROR, NULL, pbx_builtin_setvar_helper(), and pbx_outgoing_attempt().

Referenced by action_originate(), attempt_thread(), fast_originate(), hook_launch_thread(), orig_exten(), and originate_exec().

10535 {
10536    int res;
10537    int my_reason;
10538 
10539    if (!reason) {
10540       reason = &my_reason;
10541    }
10542    *reason = 0;
10543    if (locked_channel) {
10544       *locked_channel = NULL;
10545    }
10546 
10547    res = pbx_outgoing_attempt(type, cap, addr, timeout, context, exten, priority,
10548       NULL, NULL, reason, synchronous, cid_num, cid_name, vars, account, locked_channel,
10549       early_media, assignedids);
10550 
10551    if (res < 0 /* Call failed to get connected for some reason. */
10552       && 1 < synchronous
10553       && ast_exists_extension(NULL, context, "failed", 1, NULL)) {
10554       struct ast_channel *failed;
10555 
10556       /* We do not have to worry about a locked_channel if dialing failed. */
10557       ast_assert(!locked_channel || !*locked_channel);
10558 
10559       /*!
10560        * \todo XXX Not good.  The channel name is not unique if more than
10561        * one originate fails at a time.
10562        */
10563       failed = ast_channel_alloc(0, AST_STATE_DOWN, cid_num, cid_name, account,
10564          "failed", context, NULL, NULL, 0, "OutgoingSpoolFailed");
10565       if (failed) {
10566          char failed_reason[12];
10567 
10568          ast_set_variables(failed, vars);
10569          snprintf(failed_reason, sizeof(failed_reason), "%d", *reason);
10570          pbx_builtin_setvar_helper(failed, "REASON", failed_reason);
10571          ast_channel_unlock(failed);
10572 
10573          if (ast_pbx_run(failed)) {
10574             ast_log(LOG_ERROR, "Unable to run PBX on '%s'\n",
10575                ast_channel_name(failed));
10576             ast_hangup(failed);
10577          }
10578       }
10579    }
10580 
10581    return res;
10582 }

enum ast_pbx_result ast_pbx_run ( struct ast_channel c  ) 

Execute the PBX in the current thread.

Parameters:
c channel to run the pbx on
This executes the PBX on a given channel. It allocates a new PBX structure for the channel, and provides all PBX functionality. See ast_pbx_start for an asynchronous function to run the PBX in a new thread as opposed to the current one.

Return values:
Zero on success
non-zero on failure

Definition at line 6756 of file pbx.c.

References ast_pbx_run_args(), and NULL.

Referenced by __analog_ss_thread(), analog_ss_thread(), ari_originate_dial(), ast_bridge_run_after_goto(), ast_pbx_outgoing_exten(), do_notify(), mgcp_ss(), pbx_outgoing_exec(), skinny_newcall(), and unistim_ss().

06757 {
06758    return ast_pbx_run_args(c, NULL);
06759 }

enum ast_pbx_result ast_pbx_run_args ( struct ast_channel c,
struct ast_pbx_args args 
)

Execute the PBX in the current thread.

Parameters:
c channel to run the pbx on
args options for the pbx
This executes the PBX on a given channel. It allocates a new PBX structure for the channel, and provides all PBX functionality. See ast_pbx_start for an asynchronous function to run the PBX in a new thread as opposed to the current one.

Return values:
Zero on success
non-zero on failure

Definition at line 6736 of file pbx.c.

References __ast_pbx_run(), ast_log, AST_OPT_FLAG_FULLY_BOOTED, ast_options, AST_PBX_CALL_LIMIT, AST_PBX_FAILED, AST_PBX_SUCCESS, ast_test_flag, decrease_call_count(), increase_call_count(), and LOG_WARNING.

Referenced by action_dialplan_exec(), ast_pbx_run(), handle_gosub(), msg_route(), and stasis_app_exec().

06737 {
06738    enum ast_pbx_result res = AST_PBX_SUCCESS;
06739 
06740    if (!ast_test_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED)) {
06741       ast_log(LOG_WARNING, "PBX requires Asterisk to be fully booted\n");
06742       return AST_PBX_FAILED;
06743    }
06744 
06745    if (increase_call_count(c)) {
06746       return AST_PBX_CALL_LIMIT;
06747    }
06748 
06749    res = __ast_pbx_run(c, args);
06750 
06751    decrease_call_count();
06752 
06753    return res;
06754 }

enum ast_pbx_result ast_pbx_start ( struct ast_channel c  ) 

Create a new thread and start the PBX.

Parameters:
c channel to start the pbx on
See also:
ast_pbx_run for a synchronous function to run the PBX in the current thread, as opposed to starting a new one.
Return values:
Zero on success
non-zero on failure

Definition at line 6709 of file pbx.c.

References ast_log, AST_OPT_FLAG_FULLY_BOOTED, ast_options, AST_PBX_CALL_LIMIT, AST_PBX_FAILED, AST_PBX_SUCCESS, ast_pthread_create_detached, ast_test_flag, decrease_call_count(), increase_call_count(), LOG_WARNING, NULL, and pbx_thread().

Referenced by alsa_new(), ast_async_goto(), ast_iax2_new(), bridge_failed_peer_goto(), console_new(), dahdi_new(), dial_exec_full(), do_monitor_headset(), generic_recall(), handle_request_invite(), handle_response_clip(), handle_response_cmgr(), jingle_action_session_initiate(), local_call(), mgcp_new(), nbs_new(), ooh323_new(), oss_new(), pbx_start_chan(), pbx_start_incoming_request(), phone_new(), skinny_new(), and unistim_new().

06710 {
06711    pthread_t t;
06712 
06713    if (!c) {
06714       ast_log(LOG_WARNING, "Asked to start thread on NULL channel?\n");
06715       return AST_PBX_FAILED;
06716    }
06717 
06718    if (!ast_test_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED)) {
06719       ast_log(LOG_WARNING, "PBX requires Asterisk to be fully booted\n");
06720       return AST_PBX_FAILED;
06721    }
06722 
06723    if (increase_call_count(c))
06724       return AST_PBX_CALL_LIMIT;
06725 
06726    /* Start a new thread, and get something handling this channel. */
06727    if (ast_pthread_create_detached(&t, NULL, pbx_thread, c)) {
06728       ast_log(LOG_WARNING, "Failed to create new channel thread\n");
06729       decrease_call_count();
06730       return AST_PBX_FAILED;
06731    }
06732 
06733    return AST_PBX_SUCCESS;
06734 }

int ast_processed_calls ( void   ) 

Retrieve the total number of calls processed through the PBX since last restart.

Definition at line 6766 of file pbx.c.

Referenced by ast_var_Config(), handle_chanlist(), and handle_showcalls().

06767 {
06768    return totalcalls;
06769 }

int ast_rdlock_context ( struct ast_context con  ) 

Read locks a given context.

Parameters:
con context to lock
Return values:
0 on success
-1 on failure

Definition at line 12169 of file pbx.c.

References ast_rwlock_rdlock, and ast_context::lock.

Referenced by _macro_exec(), complete_dialplan_remove_ignorepat(), complete_dialplan_remove_include(), dundi_precache_full(), find_matching_endwhile(), handle_cli_dialplan_save(), lookup_c_ip(), lookup_ci(), manager_show_dialplan_helper(), show_debug_helper(), and show_dialplan_helper().

12170 {
12171    return ast_rwlock_rdlock(&con->lock);
12172 }

int ast_rdlock_contexts ( void   ) 

int ast_register_switch ( struct ast_switch sw  ) 

Register an alternative dialplan switch.

Parameters:
sw switch to register
This function registers a populated ast_switch structure with the asterisk switching architecture.

Return values:
0 success
non-zero failure

Definition at line 7269 of file pbx.c.

References ast_log, AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, LOG_WARNING, ast_switch::name, and tmp().

Referenced by load_module().

07270 {
07271    struct ast_switch *tmp;
07272 
07273    AST_RWLIST_WRLOCK(&switches);
07274    AST_RWLIST_TRAVERSE(&switches, tmp, list) {
07275       if (!strcasecmp(tmp->name, sw->name)) {
07276          AST_RWLIST_UNLOCK(&switches);
07277          ast_log(LOG_WARNING, "Switch '%s' already found\n", sw->name);
07278          return -1;
07279       }
07280    }
07281    AST_RWLIST_INSERT_TAIL(&switches, sw, list);
07282    AST_RWLIST_UNLOCK(&switches);
07283 
07284    return 0;
07285 }

int ast_spawn_extension ( struct ast_channel c,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid,
int *  found,
int  combined_find_spawn 
)

Launch a new extension (i.e. new stack).

Parameters:
c not important
context which context to generate the extension within
exten new extension to add
priority priority of new extension
callerid callerid of extension
found 
combined_find_spawn This adds a new extension to the asterisk extension list.
Note:
It is possible for autoservice to be started and stopped on c during this function call, it is important that c is not locked prior to calling this. Otherwise a deadlock may occur
Return values:
0 on success
-1 on failure.

Definition at line 5965 of file pbx.c.

References E_SPAWN, NULL, and pbx_extension_helper().

Referenced by __ast_pbx_run(), _macro_exec(), ast_pbx_h_exten_run(), gosub_run(), and loopback_exec().

05966 {
05967    return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_SPAWN, found, combined_find_spawn);
05968 }

int ast_str_get_hint ( struct ast_str **  hint,
ssize_t  hintsize,
struct ast_str **  name,
ssize_t  namesize,
struct ast_channel c,
const char *  context,
const char *  exten 
)

If an extension hint exists, return non-zero.

Parameters:
hint buffer for hint
hintsize Maximum size of hint buffer (<0 to prevent growth, >0 to limit growth to that number of bytes, or 0 for unlimited growth)
name buffer for name portion of hint
namesize Maximum size of name buffer (<0 to prevent growth, >0 to limit growth to that number of bytes, or 0 for unlimited growth)
c Channel from which to return the hint. This is only important when the hint or name contains an expression to be expanded.
context which context to look in
exten which extension to search for
Returns:
If an extension within the given context with the priority PRIORITY_HINT is found, a non zero value will be returned. Otherwise, 0 is returned.

Definition at line 5920 of file pbx.c.

References ast_get_extension_app(), ast_get_extension_app_data(), ast_hint_extension(), ast_str_set(), e, and tmp().

Referenced by ast_str_retrieve_variable().

05921 {
05922    struct ast_exten *e = ast_hint_extension(c, context, exten);
05923 
05924    if (!e) {
05925       return 0;
05926    }
05927 
05928    if (hint) {
05929       ast_str_set(hint, hintsize, "%s", ast_get_extension_app(e));
05930    }
05931    if (name) {
05932       const char *tmp = ast_get_extension_app_data(e);
05933       if (tmp) {
05934          ast_str_set(name, namesize, "%s", tmp);
05935       }
05936    }
05937    return -1;
05938 }

const char* ast_str_retrieve_variable ( struct ast_str **  buf,
ssize_t  maxlen,
struct ast_channel chan,
struct varshead headp,
const char *  var 
)

Parameters:
buf Result will be placed in this buffer.
maxlen -1 if the buffer should not grow, 0 if the buffer may grow to any size, and >0 if the buffer should grow only to that number of bytes.
chan Channel variables from which to extract values, and channel to pass to any dialplan functions.
headp If no channel is specified, a channel list from which to extract variable values
var Variable name to retrieve.

Definition at line 3598 of file pbx.c.

References ARRAY_LEN, ast_channel_caller(), ast_channel_context(), ast_channel_dialed(), ast_channel_exten(), ast_channel_hangupcause(), ast_channel_lock, ast_channel_name(), ast_channel_priority(), ast_channel_uniqueid(), ast_channel_unlock, ast_channel_varshead(), ast_config_AST_AGI_DIR, ast_config_AST_CONFIG_DIR, ast_config_AST_DATA_DIR, ast_config_AST_DB, ast_config_AST_KEY_DIR, ast_config_AST_LOG_DIR, ast_config_AST_MODULE_DIR, ast_config_AST_RUN_DIR, ast_config_AST_SPOOL_DIR, ast_config_AST_SYSTEM_NAME, ast_config_AST_VAR_DIR, ast_debug, ast_eid_default, ast_eid_to_str(), AST_LIST_TRAVERSE, ast_party_id_presentation(), ast_rwlock_rdlock, ast_rwlock_unlock, ast_str_buffer(), ast_str_get_hint(), ast_str_set(), ast_str_substring(), ast_strdupa, ast_var_name(), ast_var_value(), ast_var_t::entries, globalslock, NULL, and parse_variable_name().

Referenced by ast_ari_asterisk_get_global_var(), ast_ari_channels_get_channel_var(), ast_str_substitute_variables_full(), and pbx_retrieve_variable().

03599 {
03600    const char not_found = '\0';
03601    char *tmpvar;
03602    const char *ret;
03603    const char *s; /* the result */
03604    int offset, length;
03605    int i, need_substring;
03606    struct varshead *places[2] = { headp, &globals };  /* list of places where we may look */
03607    char workspace[20];
03608 
03609    if (c) {
03610       ast_channel_lock(c);
03611       places[0] = ast_channel_varshead(c);
03612    }
03613    /*
03614     * Make a copy of var because parse_variable_name() modifies the string.
03615     * Then if called directly, we might need to run substring() on the result;
03616     * remember this for later in 'need_substring', 'offset' and 'length'
03617     */
03618    tmpvar = ast_strdupa(var); /* parse_variable_name modifies the string */
03619    need_substring = parse_variable_name(tmpvar, &offset, &length, &i /* ignored */);
03620 
03621    /*
03622     * Look first into predefined variables, then into variable lists.
03623     * Variable 's' points to the result, according to the following rules:
03624     * s == &not_found (set at the beginning) means that we did not find a
03625     * matching variable and need to look into more places.
03626     * If s != &not_found, s is a valid result string as follows:
03627     * s = NULL if the variable does not have a value;
03628     * you typically do this when looking for an unset predefined variable.
03629     * s = workspace if the result has been assembled there;
03630     * typically done when the result is built e.g. with an snprintf(),
03631     * so we don't need to do an additional copy.
03632     * s != workspace in case we have a string, that needs to be copied
03633     * (the ast_copy_string is done once for all at the end).
03634     * Typically done when the result is already available in some string.
03635     */
03636    s = &not_found;   /* default value */
03637    if (c) { /* This group requires a valid channel */
03638       /* Names with common parts are looked up a piece at a time using strncmp. */
03639       if (!strncmp(var, "CALL", 4)) {
03640          if (!strncmp(var + 4, "ING", 3)) {
03641             if (!strcmp(var + 7, "PRES")) {        /* CALLINGPRES */
03642                ast_str_set(str, maxlen, "%d",
03643                   ast_party_id_presentation(&ast_channel_caller(c)->id));
03644                s = ast_str_buffer(*str);
03645             } else if (!strcmp(var + 7, "ANI2")) {    /* CALLINGANI2 */
03646                ast_str_set(str, maxlen, "%d", ast_channel_caller(c)->ani2);
03647                s = ast_str_buffer(*str);
03648             } else if (!strcmp(var + 7, "TON")) {     /* CALLINGTON */
03649                ast_str_set(str, maxlen, "%d", ast_channel_caller(c)->id.number.plan);
03650                s = ast_str_buffer(*str);
03651             } else if (!strcmp(var + 7, "TNS")) {     /* CALLINGTNS */
03652                ast_str_set(str, maxlen, "%d", ast_channel_dialed(c)->transit_network_select);
03653                s = ast_str_buffer(*str);
03654             }
03655          }
03656       } else if (!strcmp(var, "HINT")) {
03657          s = ast_str_get_hint(str, maxlen, NULL, 0, c, ast_channel_context(c), ast_channel_exten(c)) ? ast_str_buffer(*str) : NULL;
03658       } else if (!strcmp(var, "HINTNAME")) {
03659          s = ast_str_get_hint(NULL, 0, str, maxlen, c, ast_channel_context(c), ast_channel_exten(c)) ? ast_str_buffer(*str) : NULL;
03660       } else if (!strcmp(var, "EXTEN")) {
03661          s = ast_channel_exten(c);
03662       } else if (!strcmp(var, "CONTEXT")) {
03663          s = ast_channel_context(c);
03664       } else if (!strcmp(var, "PRIORITY")) {
03665          ast_str_set(str, maxlen, "%d", ast_channel_priority(c));
03666          s = ast_str_buffer(*str);
03667       } else if (!strcmp(var, "CHANNEL")) {
03668          s = ast_channel_name(c);
03669       } else if (!strcmp(var, "UNIQUEID")) {
03670          s = ast_channel_uniqueid(c);
03671       } else if (!strcmp(var, "HANGUPCAUSE")) {
03672          ast_str_set(str, maxlen, "%d", ast_channel_hangupcause(c));
03673          s = ast_str_buffer(*str);
03674       }
03675    }
03676    if (s == &not_found) { /* look for more */
03677       if (!strcmp(var, "EPOCH")) {
03678          ast_str_set(str, maxlen, "%d", (int) time(NULL));
03679          s = ast_str_buffer(*str);
03680       } else if (!strcmp(var, "SYSTEMNAME")) {
03681          s = ast_config_AST_SYSTEM_NAME;
03682       } else if (!strcmp(var, "ASTETCDIR")) {
03683          s = ast_config_AST_CONFIG_DIR;
03684       } else if (!strcmp(var, "ASTMODDIR")) {
03685          s = ast_config_AST_MODULE_DIR;
03686       } else if (!strcmp(var, "ASTVARLIBDIR")) {
03687          s = ast_config_AST_VAR_DIR;
03688       } else if (!strcmp(var, "ASTDBDIR")) {
03689          s = ast_config_AST_DB;
03690       } else if (!strcmp(var, "ASTKEYDIR")) {
03691          s = ast_config_AST_KEY_DIR;
03692       } else if (!strcmp(var, "ASTDATADIR")) {
03693          s = ast_config_AST_DATA_DIR;
03694       } else if (!strcmp(var, "ASTAGIDIR")) {
03695          s = ast_config_AST_AGI_DIR;
03696       } else if (!strcmp(var, "ASTSPOOLDIR")) {
03697          s = ast_config_AST_SPOOL_DIR;
03698       } else if (!strcmp(var, "ASTRUNDIR")) {
03699          s = ast_config_AST_RUN_DIR;
03700       } else if (!strcmp(var, "ASTLOGDIR")) {
03701          s = ast_config_AST_LOG_DIR;
03702       } else if (!strcmp(var, "ENTITYID")) {
03703          ast_eid_to_str(workspace, sizeof(workspace), &ast_eid_default);
03704          s = workspace;
03705       }
03706    }
03707    /* if not found, look into chanvars or global vars */
03708    for (i = 0; s == &not_found && i < ARRAY_LEN(places); i++) {
03709       struct ast_var_t *variables;
03710       if (!places[i])
03711          continue;
03712       if (places[i] == &globals)
03713          ast_rwlock_rdlock(&globalslock);
03714       AST_LIST_TRAVERSE(places[i], variables, entries) {
03715          if (!strcmp(ast_var_name(variables), var)) {
03716             s = ast_var_value(variables);
03717             break;
03718          }
03719       }
03720       if (places[i] == &globals)
03721          ast_rwlock_unlock(&globalslock);
03722    }
03723    if (s == &not_found || s == NULL) {
03724       ast_debug(5, "Result of '%s' is NULL\n", var);
03725       ret = NULL;
03726    } else {
03727       ast_debug(5, "Result of '%s' is '%s'\n", var, s);
03728       if (s != ast_str_buffer(*str)) {
03729          ast_str_set(str, maxlen, "%s", s);
03730       }
03731       ret = ast_str_buffer(*str);
03732       if (need_substring) {
03733          ret = ast_str_substring(*str, offset, length);
03734          ast_debug(2, "Final result of '%s' is '%s'\n", var, ret);
03735       }
03736    }
03737 
03738    if (c) {
03739       ast_channel_unlock(c);
03740    }
03741    return ret;
03742 }

void ast_str_substitute_variables ( struct ast_str **  buf,
ssize_t  maxlen,
struct ast_channel chan,
const char *  templ 
)

Parameters:
buf Result will be placed in this buffer.
maxlen -1 if the buffer should not grow, 0 if the buffer may grow to any size, and >0 if the buffer should grow only to that number of bytes.
chan Channel variables from which to extract values, and channel to pass to any dialplan functions.
templ Variable template to expand.

Definition at line 4629 of file pbx.c.

References ast_str_substitute_variables_full(), and NULL.

Referenced by _macro_exec(), acf_odbc_read(), acf_odbc_write(), AST_TEST_DEFINE(), cli_odbc_read(), cli_odbc_write(), config_curl(), custom_log(), cut_internal(), destroy_curl(), do_notify(), exec_exec(), func_mchan_read(), function_eval2(), function_fieldnum_helper(), function_fieldqty_helper(), handle_getvariablefull(), import_helper(), listfilter(), make_email_file(), realtime_curl(), realtime_multi_curl(), replace(), require_curl(), run_app_helper(), sendmail(), sendpage(), shift_pop(), store_curl(), strreplace(), syslog_log(), test_2way_function(), test_chan_function(), test_chan_integer(), test_chan_integer_accessor(), test_chan_string(), test_chan_variable(), test_expected_result(), tryexec_exec(), unshift_push(), update2_curl(), and update_curl().

04630 {
04631    size_t used;
04632    ast_str_substitute_variables_full(buf, maxlen, chan, NULL, templ, &used);
04633 }

void ast_str_substitute_variables_full ( struct ast_str **  buf,
ssize_t  maxlen,
struct ast_channel c,
struct varshead headp,
const char *  templ,
size_t *  used 
)

Parameters:
buf Result will be placed in this buffer.
maxlen -1 if the buffer should not grow, 0 if the buffer may grow to any size, and >0 if the buffer should grow only to that number of bytes.
c Channel variables from which to extract values, and channel to pass to any dialplan functions.
headp If no channel is specified, a channel list from which to extract variable values
templ Variable template to expand.
used Number of bytes read from the template.

Definition at line 4450 of file pbx.c.

References ast_channel_unref, ast_channel_varshead(), ast_debug, ast_dummy_channel_alloc(), ast_free, ast_func_read2(), ast_log, ast_str_append(), ast_str_append_substr(), ast_str_buffer(), ast_str_create(), ast_str_expr(), ast_str_reset(), ast_str_retrieve_variable(), ast_str_set_substr(), ast_str_strlen(), ast_str_substitute_variables_full(), ast_str_substring(), ast_strlen_zero, len(), LOG_ERROR, LOG_WARNING, NULL, and parse_variable_name().

Referenced by ast_str_substitute_variables(), ast_str_substitute_variables_full(), and ast_str_substitute_variables_varshead().

04451 {
04452    /* Substitutes variables into buf, based on string templ */
04453    char *cp4 = NULL;
04454    const char *whereweare;
04455    int orig_size = 0;
04456    int offset, offset2, isfunction;
04457    const char *nextvar, *nextexp, *nextthing;
04458    const char *vars, *vare;
04459    char *finalvars;
04460    int pos, brackets, needsub, len;
04461    struct ast_str *substr1 = ast_str_create(16), *substr2 = NULL, *substr3 = ast_str_create(16);
04462 
04463    ast_str_reset(*buf);
04464    whereweare = templ;
04465    while (!ast_strlen_zero(whereweare)) {
04466       /* reset our buffer */
04467       ast_str_reset(substr3);
04468 
04469       /* Assume we're copying the whole remaining string */
04470       pos = strlen(whereweare);
04471       nextvar = NULL;
04472       nextexp = NULL;
04473       nextthing = strchr(whereweare, '$');
04474       if (nextthing) {
04475          switch (nextthing[1]) {
04476          case '{':
04477             nextvar = nextthing;
04478             pos = nextvar - whereweare;
04479             break;
04480          case '[':
04481             nextexp = nextthing;
04482             pos = nextexp - whereweare;
04483             break;
04484          default:
04485             pos = 1;
04486          }
04487       }
04488 
04489       if (pos) {
04490          /* Copy that many bytes */
04491          ast_str_append_substr(buf, maxlen, whereweare, pos);
04492 
04493          templ += pos;
04494          whereweare += pos;
04495       }
04496 
04497       if (nextvar) {
04498          /* We have a variable.  Find the start and end, and determine
04499             if we are going to have to recursively call ourselves on the
04500             contents */
04501          vars = vare = nextvar + 2;
04502          brackets = 1;
04503          needsub = 0;
04504 
04505          /* Find the end of it */
04506          while (brackets && *vare) {
04507             if ((vare[0] == '$') && (vare[1] == '{')) {
04508                needsub++;
04509             } else if (vare[0] == '{') {
04510                brackets++;
04511             } else if (vare[0] == '}') {
04512                brackets--;
04513             } else if ((vare[0] == '$') && (vare[1] == '['))
04514                needsub++;
04515             vare++;
04516          }
04517          if (brackets)
04518             ast_log(LOG_WARNING, "Error in extension logic (missing '}')\n");
04519          len = vare - vars - 1;
04520 
04521          /* Skip totally over variable string */
04522          whereweare += (len + 3);
04523 
04524          /* Store variable name (and truncate) */
04525          ast_str_set_substr(&substr1, 0, vars, len);
04526          ast_debug(5, "Evaluating '%s' (from '%s' len %d)\n", ast_str_buffer(substr1), vars, len);
04527 
04528          /* Substitute if necessary */
04529          if (needsub) {
04530             size_t my_used;
04531 
04532             if (!substr2) {
04533                substr2 = ast_str_create(16);
04534             }
04535             ast_str_substitute_variables_full(&substr2, 0, c, headp, ast_str_buffer(substr1), &my_used);
04536             finalvars = ast_str_buffer(substr2);
04537          } else {
04538             finalvars = ast_str_buffer(substr1);
04539          }
04540 
04541          parse_variable_name(finalvars, &offset, &offset2, &isfunction);
04542          if (isfunction) {
04543             /* Evaluate function */
04544             if (c || !headp) {
04545                cp4 = ast_func_read2(c, finalvars, &substr3, 0) ? NULL : ast_str_buffer(substr3);
04546             } else {
04547                struct varshead old;
04548                struct ast_channel *bogus = ast_dummy_channel_alloc();
04549                if (bogus) {
04550                   memcpy(&old, ast_channel_varshead(bogus), sizeof(old));
04551                   memcpy(ast_channel_varshead(bogus), headp, sizeof(*ast_channel_varshead(bogus)));
04552                   cp4 = ast_func_read2(c, finalvars, &substr3, 0) ? NULL : ast_str_buffer(substr3);
04553                   /* Don't deallocate the varshead that was passed in */
04554                   memcpy(ast_channel_varshead(bogus), &old, sizeof(*ast_channel_varshead(bogus)));
04555                   ast_channel_unref(bogus);
04556                } else {
04557                   ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution.  Function results may be blank.\n");
04558                }
04559             }
04560             ast_debug(2, "Function %s result is '%s'\n", finalvars, cp4 ? cp4 : "(null)");
04561          } else {
04562             /* Retrieve variable value */
04563             ast_str_retrieve_variable(&substr3, 0, c, headp, finalvars);
04564             cp4 = ast_str_buffer(substr3);
04565          }
04566          if (cp4) {
04567             ast_str_substring(substr3, offset, offset2);
04568             ast_str_append(buf, maxlen, "%s", ast_str_buffer(substr3));
04569          }
04570       } else if (nextexp) {
04571          /* We have an expression.  Find the start and end, and determine
04572             if we are going to have to recursively call ourselves on the
04573             contents */
04574          vars = vare = nextexp + 2;
04575          brackets = 1;
04576          needsub = 0;
04577 
04578          /* Find the end of it */
04579          while (brackets && *vare) {
04580             if ((vare[0] == '$') && (vare[1] == '[')) {
04581                needsub++;
04582                brackets++;
04583                vare++;
04584             } else if (vare[0] == '[') {
04585                brackets++;
04586             } else if (vare[0] == ']') {
04587                brackets--;
04588             } else if ((vare[0] == '$') && (vare[1] == '{')) {
04589                needsub++;
04590                vare++;
04591             }
04592             vare++;
04593          }
04594          if (brackets)
04595             ast_log(LOG_WARNING, "Error in extension logic (missing ']')\n");
04596          len = vare - vars - 1;
04597 
04598          /* Skip totally over expression */
04599          whereweare += (len + 3);
04600 
04601          /* Store variable name (and truncate) */
04602          ast_str_set_substr(&substr1, 0, vars, len);
04603 
04604          /* Substitute if necessary */
04605          if (needsub) {
04606             size_t my_used;
04607 
04608             if (!substr2) {
04609                substr2 = ast_str_create(16);
04610             }
04611             ast_str_substitute_variables_full(&substr2, 0, c, headp, ast_str_buffer(substr1), &my_used);
04612             finalvars = ast_str_buffer(substr2);
04613          } else {
04614             finalvars = ast_str_buffer(substr1);
04615          }
04616 
04617          if (ast_str_expr(&substr3, 0, c, finalvars)) {
04618             ast_debug(2, "Expression result is '%s'\n", ast_str_buffer(substr3));
04619          }
04620          ast_str_append(buf, maxlen, "%s", ast_str_buffer(substr3));
04621       }
04622    }
04623    *used = ast_str_strlen(*buf) - orig_size;
04624    ast_free(substr1);
04625    ast_free(substr2);
04626    ast_free(substr3);
04627 }

void ast_str_substitute_variables_varshead ( struct ast_str **  buf,
ssize_t  maxlen,
struct varshead headp,
const char *  templ 
)

Parameters:
buf Result will be placed in this buffer.
maxlen -1 if the buffer should not grow, 0 if the buffer may grow to any size, and >0 if the buffer should grow only to that number of bytes.
headp If no channel is specified, a channel list from which to extract variable values
templ Variable template to expand.

Definition at line 4635 of file pbx.c.

References ast_str_substitute_variables_full(), and NULL.

Referenced by add_user_extension(), build_user_routes(), handle_aor(), handle_registrations(), phoneprov_callback(), pp_each_extension_helper(), and pp_each_user_helper().

04636 {
04637    size_t used;
04638    ast_str_substitute_variables_full(buf, maxlen, NULL, headp, templ, &used);
04639 }

int ast_thread_inhibit_escalations ( void   ) 

Inhibit (in the current thread) the execution of dialplan functions which cause privilege escalations. If pbx_live_dangerously() has been called, this function has no effect.

Returns:
0 if successfuly marked current thread.

Non-zero if marking current thread failed.

Definition at line 4233 of file pbx.c.

References ast_log, ast_threadstorage_get(), LOG_ERROR, NULL, and thread_inhibit_escalations_tl.

Referenced by handle_tcptls_connection().

04234 {
04235    int *thread_inhibit_escalations;
04236 
04237    thread_inhibit_escalations = ast_threadstorage_get(
04238       &thread_inhibit_escalations_tl, sizeof(*thread_inhibit_escalations));
04239 
04240    if (thread_inhibit_escalations == NULL) {
04241       ast_log(LOG_ERROR, "Error inhibiting privilege escalations for current thread\n");
04242       return -1;
04243    }
04244 
04245    *thread_inhibit_escalations = 1;
04246    return 0;
04247 }

int ast_unlock_context ( struct ast_context con  ) 

int ast_unlock_contexts ( void   ) 

void ast_unregister_switch ( struct ast_switch sw  ) 

Unregister an alternative switch.

Parameters:
sw switch to unregister
Unregisters a switch from asterisk.

Returns:
nothing

Definition at line 7287 of file pbx.c.

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

Referenced by __unload_module(), and unload_module().

07288 {
07289    AST_RWLIST_WRLOCK(&switches);
07290    AST_RWLIST_REMOVE(&switches, sw, list);
07291    AST_RWLIST_UNLOCK(&switches);
07292 }

static struct ast_exten * ast_walk_context_extensions ( struct ast_context con,
struct ast_exten priority 
) [read]

struct ast_ignorepat * ast_walk_context_ignorepats ( struct ast_context con,
struct ast_ignorepat ip 
) [read]

static struct ast_include * ast_walk_context_includes ( struct ast_context con,
struct ast_include inc 
) [read]

static struct ast_sw * ast_walk_context_switches ( struct ast_context con,
struct ast_sw sw 
) [read]

static struct ast_context * ast_walk_contexts ( struct ast_context con  )  [read]

static struct ast_exten * ast_walk_extension_priorities ( struct ast_exten exten,
struct ast_exten priority 
) [read]

int ast_wrlock_context ( struct ast_context con  ) 

int ast_wrlock_contexts ( void   ) 

void pbx_builtin_clear_globals ( void   ) 

Definition at line 11640 of file pbx.c.

References AST_LIST_REMOVE_HEAD, ast_rwlock_unlock, ast_rwlock_wrlock, ast_var_delete(), ast_var_t::entries, and globalslock.

Referenced by handle_cli_dialplan_reload(), pbx_shutdown(), and reload().

11641 {
11642    struct ast_var_t *vardata;
11643 
11644    ast_rwlock_wrlock(&globalslock);
11645    while ((vardata = AST_LIST_REMOVE_HEAD(&globals, entries)))
11646       ast_var_delete(vardata);
11647    ast_rwlock_unlock(&globalslock);
11648 }

const char* pbx_builtin_getvar_helper ( struct ast_channel chan,
const char *  name 
)

Return a pointer to the value of the corresponding channel variable.

Note:
Will lock the channel.

This function will return a pointer to the buffer inside the channel variable. This value should only be accessed with the channel locked. If the value needs to be kept around, it should be done by using the following thread-safe code:

      const char *var;

      ast_channel_lock(chan);
      if ((var = pbx_builtin_getvar_helper(chan, "MYVAR"))) {
         var = ast_strdupa(var);
      }
      ast_channel_unlock(chan);

Definition at line 11415 of file pbx.c.

References ast_channel_lock, ast_channel_unlock, ast_channel_varshead(), AST_LIST_TRAVERSE, ast_rwlock_rdlock, ast_rwlock_unlock, ast_var_name(), ast_var_value(), globalslock, and NULL.

Referenced by __ast_pbx_run(), _macro_exec(), _while_exec(), action_agents(), agent_handle_show_specific(), agent_login_channel_config(), agent_request_exec(), agent_show_requested(), aMYSQL_connect(), analog_call(), array(), ast_bridge_timelimit(), ast_bridge_transfer_attended(), ast_call_forward(), ast_channel_connected_line_macro(), ast_channel_connected_line_sub(), ast_channel_get_manager_vars(), ast_channel_redirecting_macro(), ast_channel_redirecting_sub(), ast_eivr_getvariable(), ast_get_chan_applicationmap(), ast_monitor_stop(), ast_unreal_hangup(), bridge_check_monitor(), bridge_parking_push(), check_bridge_play_sound(), common_exec(), conf_run(), create_dynamic_lot_full(), crement_function_read(), dahdi_hangup(), dial_exec_full(), do_forward(), dundi_exec(), dundi_helper(), feature_automixmonitor(), feature_automonitor(), feature_blind_transfer(), find_by_mark(), find_channel_parking_lot_name(), find_conf_realtime(), func_channel_read(), generate_parked_user(), generic_fax_exec(), get_also_info(), get_index(), get_refer_info(), get_transfer_context(), global_read(), gosub_run(), handle_call_forward(), handle_gosub(), hash_read(), iax2_call(), iax2_exec(), import_ch(), leave_voicemail(), local_read(), macro_fixup(), manager_mixmonitor(), meetme_menu_admin_extended(), mgcp_call(), minivm_delete_exec(), minivm_notify_exec(), misdn_answer(), misdn_hangup(), morsecode_exec(), notify_new_message(), ooh323_call(), ooh323_hangup(), park_app_exec(), pbx_builtin_background(), pbx_builtin_gotoiftime(), pbx_builtin_saycharacters(), pbx_builtin_saycharacters_case(), pbx_builtin_saydigits(), pbx_builtin_saynumber(), pbx_builtin_sayphonetic(), pre_bridge_setup(), queue_exec(), receive_ademco_event(), refer_outgoing_request(), report_receive_fax_status(), report_send_fax_status(), retrydial_exec(), ring_entry(), run_agi(), sayunixtime_exec(), set_local_info(), set_touch_variable(), set_transfer_variables_all(), setsubstate(), setup_mixmonitor(), setup_park_common_datastore(), sip_addheader(), sla_trunk_exec(), speech_background(), try_calling(), try_suggested_sip_codec(), and wait_for_answer().

11416 {
11417    struct ast_var_t *variables;
11418    const char *ret = NULL;
11419    int i;
11420    struct varshead *places[2] = { NULL, &globals };
11421 
11422    if (!name)
11423       return NULL;
11424 
11425    if (chan) {
11426       ast_channel_lock(chan);
11427       places[0] = ast_channel_varshead(chan);
11428    }
11429 
11430    for (i = 0; i < 2; i++) {
11431       if (!places[i])
11432          continue;
11433       if (places[i] == &globals)
11434          ast_rwlock_rdlock(&globalslock);
11435       AST_LIST_TRAVERSE(places[i], variables, entries) {
11436          if (!strcmp(name, ast_var_name(variables))) {
11437             ret = ast_var_value(variables);
11438             break;
11439          }
11440       }
11441       if (places[i] == &globals)
11442          ast_rwlock_unlock(&globalslock);
11443       if (ret)
11444          break;
11445    }
11446 
11447    if (chan)
11448       ast_channel_unlock(chan);
11449 
11450    return ret;
11451 }

void pbx_builtin_pushvar_helper ( struct ast_channel chan,
const char *  name,
const char *  value 
)

Add a variable to the channel variable stack, without removing any previously set value.

Note:
Will lock the channel.

Definition at line 11453 of file pbx.c.

References ast_channel_lock, ast_channel_unlock, ast_channel_varshead(), ast_func_write(), AST_LIST_INSERT_HEAD, ast_log, ast_rwlock_unlock, ast_rwlock_wrlock, ast_strdupa, ast_var_assign(), ast_verb, globalslock, and LOG_WARNING.

Referenced by acf_odbc_read(), acf_odbc_write(), cli_odbc_read(), cli_odbc_write(), and frame_set_var().

11454 {
11455    struct ast_var_t *newvariable;
11456    struct varshead *headp;
11457 
11458    if (name[strlen(name)-1] == ')') {
11459       char *function = ast_strdupa(name);
11460 
11461       ast_log(LOG_WARNING, "Cannot push a value onto a function\n");
11462       ast_func_write(chan, function, value);
11463       return;
11464    }
11465 
11466    if (chan) {
11467       ast_channel_lock(chan);
11468       headp = ast_channel_varshead(chan);
11469    } else {
11470       ast_rwlock_wrlock(&globalslock);
11471       headp = &globals;
11472    }
11473 
11474    if (value && (newvariable = ast_var_assign(name, value))) {
11475       if (headp == &globals)
11476          ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
11477       AST_LIST_INSERT_HEAD(headp, newvariable, entries);
11478    }
11479 
11480    if (chan)
11481       ast_channel_unlock(chan);
11482    else
11483       ast_rwlock_unlock(&globalslock);
11484 }

int pbx_builtin_raise_exception ( struct ast_channel chan,
const char *  data 
)

Definition at line 3793 of file pbx.c.

References raise_exception().

03794 {
03795    /* Priority will become 1, next time through the AUTOLOOP */
03796    return raise_exception(chan, reason, 0);
03797 }

int pbx_builtin_serialize_variables ( struct ast_channel chan,
struct ast_str **  buf 
)

Create a human-readable string, specifying all variables and their corresponding values.

Parameters:
chan Channel from which to read variables
buf Dynamic string in which to place the result (should be allocated with ast_str_create).
See also:
ast_str_create
Note:
Will lock the channel.

Definition at line 11384 of file pbx.c.

References ast_channel_lock, ast_channel_unlock, ast_channel_varshead(), AST_LIST_TRAVERSE, ast_log, ast_str_append(), ast_str_reset(), ast_var_name(), ast_var_value(), ast_var_t::entries, LOG_ERROR, total, and var.

Referenced by ast_var_channels_table(), and dumpchan_exec().

11385 {
11386    struct ast_var_t *variables;
11387    const char *var, *val;
11388    int total = 0;
11389 
11390    if (!chan)
11391       return 0;
11392 
11393    ast_str_reset(*buf);
11394 
11395    ast_channel_lock(chan);
11396 
11397    AST_LIST_TRAVERSE(ast_channel_varshead(chan), variables, entries) {
11398       if ((var = ast_var_name(variables)) && (val = ast_var_value(variables))
11399          /* && !ast_strlen_zero(var) && !ast_strlen_zero(val) */
11400          ) {
11401          if (ast_str_append(buf, 0, "%s=%s\n", var, val) < 0) {
11402             ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n");
11403             break;
11404          } else
11405             total++;
11406       } else
11407          break;
11408    }
11409 
11410    ast_channel_unlock(chan);
11411 
11412    return total;
11413 }

int pbx_builtin_setvar ( struct ast_channel chan,
const char *  data 
)

Parse and set a single channel variable, where the name and value are separated with an '=' character.

Note:
Will lock the channel.

Definition at line 11538 of file pbx.c.

References ast_log, ast_strdupa, ast_strlen_zero, localized_pbx_builtin_setvar(), LOG_WARNING, pbx_builtin_setvar_helper(), strsep(), and value.

Referenced by ast_compile_ael2(), and localized_pbx_builtin_setvar().

11539 {
11540    char *name, *value, *mydata;
11541 
11542    if (ast_strlen_zero(data)) {
11543       ast_log(LOG_WARNING, "Set requires one variable name/value pair.\n");
11544       return 0;
11545    }
11546 
11547    mydata = ast_strdupa(data);
11548    name = strsep(&mydata, "=");
11549    value = mydata;
11550    if (!value) {
11551       ast_log(LOG_WARNING, "Set requires an '=' to be a valid assignment.\n");
11552       return 0;
11553    }
11554 
11555    if (strchr(name, ' ')) {
11556       ast_log(LOG_WARNING, "Please avoid unnecessary spaces on variables as it may lead to unexpected results ('%s' set to '%s').\n", name, mydata);
11557    }
11558 
11559    pbx_builtin_setvar_helper(chan, name, value);
11560 
11561    return 0;
11562 }

int pbx_builtin_setvar_helper ( struct ast_channel chan,
const char *  name,
const char *  value 
)

Add a variable to the channel variable stack, removing the most recently set value for the same name.

Note:
Will lock the channel. May also be used to set a channel dialplan function to a particular value.
See also:
ast_func_write
Returns:
-1 if the dialplan function fails to be set
Version:
1.8 changed the function to return an error code

Definition at line 11486 of file pbx.c.

References ast_channel_lock, ast_channel_publish_varset(), ast_channel_unlock, ast_channel_varshead(), ast_func_write(), AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_rwlock_unlock, ast_rwlock_wrlock, ast_strdupa, ast_var_assign(), ast_var_delete(), ast_var_name(), ast_verb, and globalslock.

Referenced by __analog_ss_thread(), __ast_pbx_run(), _macro_exec(), _while_exec(), acf_curl_helper(), acf_fetch(), acf_odbc_read(), acf_odbc_write(), acf_transaction_write(), action_atxfer(), action_kick_last(), action_setvar(), admin_exec(), agent_login_exec(), agent_request_exec(), agi_exec_full(), aMYSQL_fetch(), aMYSQL_set(), analog_ss_thread(), app_exec(), aqm_exec(), array(), ast_ari_asterisk_set_global_var(), ast_bridge_set_transfer_variables(), ast_cc_agent_set_interfaces_chanvar(), ast_eivr_setvariable(), ast_iax2_new(), ast_monitor_start(), ast_monitor_stop(), ast_pbx_outgoing_exten(), ast_pickup_call(), ast_rtp_instance_set_stats_vars(), ast_set_cc_interfaces_chanvar(), ast_set_variables(), AST_TEST_DEFINE(), ast_unreal_hangup(), asyncgoto_exec(), attended_transfer_bridge(), background_detect_exec(), blind_transfer_bridge(), blind_transfer_cb(), bridge_channel_internal_push(), bridge_exec(), calendar_write_exec(), caller_joined_bridge(), caller_safety_timeout(), cb_events(), cccancel_exec(), ccreq_exec(), chan_pjsip_cng_tone_detected(), chan_pjsip_new(), chanavail_exec(), channel_spy(), check_bridge_play_sound(), clear_agent_status(), commit_exec(), conf_run(), confbridge_exec(), controlplayback_exec(), count_exec(), crement_function_read(), dahdi_handle_dtmf(), dahdi_new(), dial_exec_full(), dial_transfer(), directory_exec(), disa_exec(), do_directory(), do_notify(), do_waiting(), dynamic_dtmf_hook_callback(), end_bridge_callback(), execute_menu_entry(), export_aoc_vars(), export_ch(), fax_detect_framehook(), frame_set_var(), func_mchan_write(), function_db_delete(), function_db_exists(), function_db_read(), function_realtime_store(), generic_recall(), get_rdnis(), get_refer_info(), global_write(), gosub_release_frame(), gosub_run(), handle_controlstreamfile(), handle_gosub(), handle_incoming_request(), handle_outgoing_response(), handle_request_bye(), handle_response_cmgr(), handle_set_chanvar(), handle_set_global(), handle_setvariable(), handle_streamfile(), hash_read(), hash_write(), isAnsweringMachine(), kick_conference_participant(), launch_monitor_thread(), leave_marked(), leave_queue(), leave_voicemail(), lua_set_variable(), lua_set_variable_value(), macro_fixup(), mbl_status_exec(), mgcp_new(), minivm_accmess_exec(), minivm_delete_exec(), minivm_greet_exec(), minivm_notify_exec(), minivm_record_exec(), misdn_call(), mixmonitor_exec(), msg_send_exec(), my_handle_dtmf(), MYSQL_exec(), onModeChanged(), ooh323_new(), ooh323_rtp_read(), originate_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), parking_duration_callback(), parking_timeout_set_caller_features(), parse_moved_contact(), pbx_builtin_background(), pbx_builtin_gotoiftime(), pbx_builtin_importvar(), pbx_builtin_setvar(), pbx_builtin_setvar_multiple(), pbx_load_config(), phase_e_handler(), play_message_datetime(), playback_exec(), pqm_exec(), prep_email_sub_vars(), privacy_exec(), process_ast_dsp(), process_sdp(), read_exec(), readexten_exec(), realtimefield_read(), receivefax_exec(), record_dtmf_response(), record_exec(), refer_blind_callback(), reload_module(), return_exec(), rollback_exec(), rotate_file(), rqm_exec(), select_entry(), select_item_menu(), select_item_seq(), sendfax_exec(), sendimage_exec(), sendtext_exec(), sendurl_exec(), set(), set_asterisk_int(), set_channel_variables(), set_queue_result(), setsubstate(), shift_pop(), sip_addheader(), sip_hangup(), sip_new(), sip_read(), skinny_new(), sla_calc_trunk_timeouts(), sla_station_exec(), sla_trunk_exec(), speech_create(), start_automixmonitor(), start_automonitor(), start_monitor_exec(), stasis_app_control_set_channel_var(), system_exec_helper(), test_chan_variable(), testtime_write(), transfer_exec(), transmit(), tryexec_exec(), unicast_rtp_request(), unshift_push(), update_bridge_vars_set(), update_qe_rule(), upqm_exec(), vm_box_exists(), vm_exec(), vm_playmsgexec(), vmauthenticate(), waituntil_exec(), xmpp_status_exec(), and zapateller_exec().

11487 {
11488    struct ast_var_t *newvariable;
11489    struct varshead *headp;
11490    const char *nametail = name;
11491 
11492    if (name[strlen(name) - 1] == ')') {
11493       char *function = ast_strdupa(name);
11494 
11495       return ast_func_write(chan, function, value);
11496    }
11497 
11498    if (chan) {
11499       ast_channel_lock(chan);
11500       headp = ast_channel_varshead(chan);
11501    } else {
11502       ast_rwlock_wrlock(&globalslock);
11503       headp = &globals;
11504    }
11505 
11506    /* For comparison purposes, we have to strip leading underscores */
11507    if (*nametail == '_') {
11508       nametail++;
11509       if (*nametail == '_')
11510          nametail++;
11511    }
11512 
11513    AST_LIST_TRAVERSE_SAFE_BEGIN(headp, newvariable, entries) {
11514       if (strcmp(ast_var_name(newvariable), nametail) == 0) {
11515          /* there is already such a variable, delete it */
11516          AST_LIST_REMOVE_CURRENT(entries);
11517          ast_var_delete(newvariable);
11518          break;
11519       }
11520    }
11521    AST_LIST_TRAVERSE_SAFE_END;
11522 
11523    if (value && (newvariable = ast_var_assign(name, value))) {
11524       if (headp == &globals) {
11525          ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
11526       }
11527       AST_LIST_INSERT_HEAD(headp, newvariable, entries);
11528       ast_channel_publish_varset(chan, name, value);
11529    }
11530 
11531    if (chan)
11532       ast_channel_unlock(chan);
11533    else
11534       ast_rwlock_unlock(&globalslock);
11535    return 0;
11536 }

int pbx_builtin_setvar_multiple ( struct ast_channel chan,
const char *  data 
)

Parse and set multiple channel variables, where the pairs are separated by the ',' character, and name and value are separated with an '=' character.

Note:
Will lock the channel.

Definition at line 11564 of file pbx.c.

References args, AST_APP_ARG, ast_channel_context(), ast_channel_exten(), ast_channel_priority(), AST_DECLARE_APP_ARGS, ast_log, AST_NONSTANDARD_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero, LOG_WARNING, ast_channel::name, pbx_builtin_setvar_helper(), and value.

Referenced by queue_function_var(), set_queue_variables(), and try_calling().

11565 {
11566    char *data;
11567    int x;
11568    AST_DECLARE_APP_ARGS(args,
11569       AST_APP_ARG(pair)[24];
11570    );
11571    AST_DECLARE_APP_ARGS(pair,
11572       AST_APP_ARG(name);
11573       AST_APP_ARG(value);
11574    );
11575 
11576    if (ast_strlen_zero(vdata)) {
11577       ast_log(LOG_WARNING, "MSet requires at least one variable name/value pair.\n");
11578       return 0;
11579    }
11580 
11581    data = ast_strdupa(vdata);
11582    AST_STANDARD_APP_ARGS(args, data);
11583 
11584    for (x = 0; x < args.argc; x++) {
11585       AST_NONSTANDARD_APP_ARGS(pair, args.pair[x], '=');
11586       if (pair.argc == 2) {
11587          pbx_builtin_setvar_helper(chan, pair.name, pair.value);
11588          if (strchr(pair.name, ' '))
11589             ast_log(LOG_WARNING, "Please avoid unnecessary spaces on variables as it may lead to unexpected results ('%s' set to '%s').\n", pair.name, pair.value);
11590       } else if (!chan) {
11591          ast_log(LOG_WARNING, "MSet: ignoring entry '%s' with no '='\n", pair.name);
11592       } else {
11593          ast_log(LOG_WARNING, "MSet: ignoring entry '%s' with no '=' (in %s@%s:%d\n", pair.name, ast_channel_exten(chan), ast_channel_context(chan), ast_channel_priority(chan));
11594       }
11595    }
11596 
11597    return 0;
11598 }

int pbx_checkcondition ( const char *  condition  ) 

Evaluate a condition.

Return values:
0 if the condition is NULL or of zero length
int If the string is an integer, the integer representation of the integer is returned
1 Any other non-empty string

Definition at line 11650 of file pbx.c.

References ast_strlen_zero.

Referenced by _macro_exec(), _while_exec(), acf_if(), execif_exec(), gosubif_exec(), macroif_exec(), pbx_builtin_gotoif(), and testtime_write().

11651 {
11652    int res;
11653    if (ast_strlen_zero(condition)) {                /* NULL or empty strings are false */
11654       return 0;
11655    } else if (sscanf(condition, "%30d", &res) == 1) { /* Numbers are evaluated for truth */
11656       return res;
11657    } else {                                         /* Strings are true */
11658       return 1;
11659    }
11660 }

int pbx_exec ( struct ast_channel c,
struct ast_app app,
const char *  data 
)

Execute an application.

Parameters:
c channel to execute on
app which app to execute
data the data passed into the app
This application executes an application on a given channel. It saves the stack and executes the given application passing in the given data.

Return values:
0 success
-1 failure
Parameters:
c  Channel
app  Application
data  Data for execution
Examples:
/tmp/asterisk-trunk/trunk/main/app.c.

Definition at line 1641 of file pbx.c.

References __ast_module_user_add(), __ast_module_user_remove(), ast_channel_appl(), ast_channel_appl_set(), ast_channel_data(), ast_channel_data_set(), ast_channel_lock, ast_channel_publish_snapshot(), ast_channel_unlock, ast_app::execute, ast_app::module, ast_app::name, NULL, and S_OR.

Referenced by aelsub_exec(), answer_exec_run(), ari_originate_dial(), ast_app_exec_macro(), AST_TEST_DEFINE(), bridge_check_monitor(), bridge_stasis_run_cb(), conf_run(), conf_start_record(), disa_exec(), do_magic_pickup(), dundi_exec(), exec_exec(), execif_exec(), forward_message(), handle_exec(), iax2_exec(), lua_pbx_exec(), page_exec(), pbx_builtin_execiftime(), pbx_extension_helper(), pbx_outgoing_exec(), realtime_exec(), run_app_helper(), snoop_stasis_thread(), try_calling(), and tryexec_exec().

01644 {
01645    int res;
01646    struct ast_module_user *u = NULL;
01647    const char *saved_c_appl;
01648    const char *saved_c_data;
01649 
01650    /* save channel values */
01651    saved_c_appl= ast_channel_appl(c);
01652    saved_c_data= ast_channel_data(c);
01653 
01654    ast_channel_lock(c);
01655    ast_channel_appl_set(c, app->name);
01656    ast_channel_data_set(c, data);
01657    ast_channel_publish_snapshot(c);
01658    ast_channel_unlock(c);
01659 
01660    if (app->module)
01661       u = __ast_module_user_add(app->module, c);
01662    res = app->execute(c, S_OR(data, ""));
01663    if (app->module && u)
01664       __ast_module_user_remove(app->module, u);
01665    /* restore channel values */
01666    ast_channel_appl_set(c, saved_c_appl);
01667    ast_channel_data_set(c, saved_c_data);
01668    return res;
01669 }

static struct ast_exten * pbx_find_extension ( struct ast_channel chan,
struct ast_context bypass,
struct pbx_find_info q,
const char *  context,
const char *  exten,
int  priority,
const char *  label,
const char *  callerid,
enum ext_match_t  action 
) [read]

struct ast_app * pbx_findapp ( const char *  app  )  [read]

Look up an application.

Parameters:
app name of the app
This function searches for the ast_app structure within the apps that are registered for the one with the name you passed in.

Returns:
the ast_app structure that matches on success, or NULL on failure
Examples:
/tmp/asterisk-trunk/trunk/main/app.c.

Definition at line 170 of file ael_main.c.

Referenced by aelsub_exec(), answer_exec_run(), ari_originate_dial(), ast_app_exec_macro(), AST_TEST_DEFINE(), bridge_check_monitor(), bridge_stasis_run_cb(), conf_run(), conf_start_record(), disa_exec(), do_magic_pickup(), dundi_exec(), exec_exec(), execif_exec(), forward_message(), handle_exec(), iax2_exec(), lua_pbx_exec(), page_exec(), pbx_builtin_execiftime(), pbx_extension_helper(), pbx_outgoing_exec(), realtime_exec(), run_app_helper(), snoop_stasis_thread(), try_calling(), and tryexec_exec().

00171 {
00172    return (struct ast_app*)1; /* so as not to trigger an error */
00173 }

void pbx_live_dangerously ( int  new_live_dangerously  ) 

Enable/disable the execution of 'dangerous' functions from external protocols (AMI, etc.).

These dialplan functions (such as SHELL) provide an opportunity for privilege escalation. They are okay to invoke from the dialplan, but external protocols with permission controls should not normally invoke them.

This function can globally enable/disable the execution of dangerous functions from external protocols.

Parameters:
new_live_dangerously If true, enable the execution of escalating functions from external protocols.

Definition at line 4220 of file pbx.c.

References ast_log, LOG_NOTICE, and LOG_WARNING.

Referenced by ast_readconfig().

04221 {
04222    if (new_live_dangerously && !live_dangerously) {
04223       ast_log(LOG_WARNING, "Privilege escalation protection disabled!\n"
04224          "See https://wiki.asterisk.org/wiki/x/1gKfAQ for more details.\n");
04225    }
04226 
04227    if (!new_live_dangerously && live_dangerously) {
04228       ast_log(LOG_NOTICE, "Privilege escalation protection enabled.\n");
04229    }
04230    live_dangerously = new_live_dangerously;
04231 }

void pbx_retrieve_variable ( struct ast_channel c,
const char *  var,
char **  ret,
char *  workspace,
int  workspacelen,
struct varshead headp 
)

Retrieve the value of a builtin variable or variable from the channel variable stack.

Note:
Will lock the channel.
Retrieve the value of a builtin variable or variable from the channel variable stack.

Note:
See also

Definition at line 3587 of file pbx.c.

References ast_copy_string(), ast_free, ast_str_buffer(), ast_str_create(), ast_str_retrieve_variable(), NULL, and str.

Referenced by action_getvar(), generate_status(), handle_getvariable(), lua_get_variable(), lua_get_variable_value(), and pbx_substitute_variables_helper_full().

03588 {
03589    struct ast_str *str = ast_str_create(16);
03590    const char *cret;
03591 
03592    cret = ast_str_retrieve_variable(&str, 0, c, headp, var);
03593    ast_copy_string(workspace, ast_str_buffer(str), workspacelen);
03594    *ret = cret ? workspace : NULL;
03595    ast_free(str);
03596 }

int pbx_set_autofallthrough ( int  newval  ) 

Set "autofallthrough" flag, if newval is <0, does not actually set. If set to 1, sets to auto fall through. If newval set to 0, sets to no auto fall through (reads extension instead). Returns previous value.

Definition at line 6771 of file pbx.c.

Referenced by pbx_load_module().

06772 {
06773    int oldval = autofallthrough;
06774    autofallthrough = newval;
06775    return oldval;
06776 }

int pbx_set_extenpatternmatchnew ( int  newval  ) 

Set "extenpatternmatchnew" flag, if newval is <0, does not actually set. If set to 1, sets to use the new Trie-based pattern matcher. If newval set to 0, sets to use the old linear-search algorithm. Returns previous value.

Definition at line 6778 of file pbx.c.

Referenced by AST_TEST_DEFINE(), handle_set_extenpatternmatchnew(), handle_unset_extenpatternmatchnew(), and pbx_load_module().

06779 {
06780    int oldval = extenpatternmatchnew;
06781    extenpatternmatchnew = newval;
06782    return oldval;
06783 }

void pbx_set_overrideswitch ( const char *  newval  ) 

Set "overrideswitch" field. If set and of nonzero length, all contexts will be tried directly through the named switch prior to any other matching within that context.

Since:
1.6.1

Definition at line 6785 of file pbx.c.

References ast_free, ast_strdup, ast_strlen_zero, and NULL.

Referenced by pbx_load_module().

06786 {
06787    if (overrideswitch) {
06788       ast_free(overrideswitch);
06789    }
06790    if (!ast_strlen_zero(newval)) {
06791       overrideswitch = ast_strdup(newval);
06792    } else {
06793       overrideswitch = NULL;
06794    }
06795 }

static void pbx_substitute_variables_helper ( struct ast_channel c,
const char *  cp1,
char *  cp2,
int  count 
)

Definition at line 218 of file ael_main.c.

References AST_MAX_EXTENSION.

Referenced by add_extensions(), ast_add_extension2_lockopt(), escape_and_substitute(), function_eval(), get_mapping_weight(), import_helper(), launch_monitor_thread(), manager_log(), pbx_builtin_importvar(), pbx_extension_helper(), pbx_find_extension(), pbx_load_config(), realtime_exec(), rotate_file(), substituted(), test_chan_function(), test_chan_integer(), test_chan_integer_accessor(), test_chan_string(), test_chan_variable(), write_cdr(), and write_cel().

00219 {
00220    if (cp1 && *cp1)
00221       strncpy(cp2,cp1,AST_MAX_EXTENSION); /* Right now, this routine is ONLY being called for 
00222                                     a possible var substitution on extension names,
00223                                     so....! */
00224    else
00225       *cp2 = 0;
00226 }

void pbx_substitute_variables_helper_full ( struct ast_channel c,
struct varshead headp,
const char *  cp1,
char *  cp2,
int  cp2_size,
size_t *  used 
)

Definition at line 4641 of file pbx.c.

References ast_alloca, ast_channel_unref, ast_channel_varshead(), ast_copy_string(), ast_debug, ast_dummy_channel_alloc(), ast_expr(), ast_func_read(), ast_log, ast_strlen_zero, len(), LOG_ERROR, LOG_WARNING, NULL, parse_variable_name(), pbx_retrieve_variable(), pbx_substitute_variables_helper_full(), substring(), var, and VAR_BUF_SIZE.

Referenced by pbx_substitute_variables_helper(), pbx_substitute_variables_helper_full(), and pbx_substitute_variables_varshead().

04642 {
04643    /* Substitutes variables into cp2, based on string cp1, cp2 NO LONGER NEEDS TO BE ZEROED OUT!!!!  */
04644    char *cp4 = NULL;
04645    const char *whereweare, *orig_cp2 = cp2;
04646    int length, offset, offset2, isfunction;
04647    char *workspace = NULL;
04648    char *ltmp = NULL, *var = NULL;
04649    char *nextvar, *nextexp, *nextthing;
04650    char *vars, *vare;
04651    int pos, brackets, needsub, len;
04652 
04653    *cp2 = 0; /* just in case nothing ends up there */
04654    whereweare = cp1;
04655    while (!ast_strlen_zero(whereweare) && count) {
04656       /* Assume we're copying the whole remaining string */
04657       pos = strlen(whereweare);
04658       nextvar = NULL;
04659       nextexp = NULL;
04660       nextthing = strchr(whereweare, '$');
04661       if (nextthing) {
04662          switch (nextthing[1]) {
04663          case '{':
04664             nextvar = nextthing;
04665             pos = nextvar - whereweare;
04666             break;
04667          case '[':
04668             nextexp = nextthing;
04669             pos = nextexp - whereweare;
04670             break;
04671          default:
04672             pos = 1;
04673          }
04674       }
04675 
04676       if (pos) {
04677          /* Can't copy more than 'count' bytes */
04678          if (pos > count)
04679             pos = count;
04680 
04681          /* Copy that many bytes */
04682          memcpy(cp2, whereweare, pos);
04683 
04684          count -= pos;
04685          cp2 += pos;
04686          whereweare += pos;
04687          *cp2 = 0;
04688       }
04689 
04690       if (nextvar) {
04691          /* We have a variable.  Find the start and end, and determine
04692             if we are going to have to recursively call ourselves on the
04693             contents */
04694          vars = vare = nextvar + 2;
04695          brackets = 1;
04696          needsub = 0;
04697 
04698          /* Find the end of it */
04699          while (brackets && *vare) {
04700             if ((vare[0] == '$') && (vare[1] == '{')) {
04701                needsub++;
04702             } else if (vare[0] == '{') {
04703                brackets++;
04704             } else if (vare[0] == '}') {
04705                brackets--;
04706             } else if ((vare[0] == '$') && (vare[1] == '['))
04707                needsub++;
04708             vare++;
04709          }
04710          if (brackets)
04711             ast_log(LOG_WARNING, "Error in extension logic (missing '}')\n");
04712          len = vare - vars - 1;
04713 
04714          /* Skip totally over variable string */
04715          whereweare += (len + 3);
04716 
04717          if (!var)
04718             var = ast_alloca(VAR_BUF_SIZE);
04719 
04720          /* Store variable name (and truncate) */
04721          ast_copy_string(var, vars, len + 1);
04722 
04723          /* Substitute if necessary */
04724          if (needsub) {
04725             size_t my_used;
04726 
04727             if (!ltmp) {
04728                ltmp = ast_alloca(VAR_BUF_SIZE);
04729             }
04730             pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, &my_used);
04731             vars = ltmp;
04732          } else {
04733             vars = var;
04734          }
04735 
04736          if (!workspace)
04737             workspace = ast_alloca(VAR_BUF_SIZE);
04738 
04739          workspace[0] = '\0';
04740 
04741          parse_variable_name(vars, &offset, &offset2, &isfunction);
04742          if (isfunction) {
04743             /* Evaluate function */
04744             if (c || !headp)
04745                cp4 = ast_func_read(c, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace;
04746             else {
04747                struct varshead old;
04748                struct ast_channel *c = ast_dummy_channel_alloc();
04749                if (c) {
04750                   memcpy(&old, ast_channel_varshead(c), sizeof(old));
04751                   memcpy(ast_channel_varshead(c), headp, sizeof(*ast_channel_varshead(c)));
04752                   cp4 = ast_func_read(c, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace;
04753                   /* Don't deallocate the varshead that was passed in */
04754                   memcpy(ast_channel_varshead(c), &old, sizeof(*ast_channel_varshead(c)));
04755                   c = ast_channel_unref(c);
04756                } else {
04757                   ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution.  Function results may be blank.\n");
04758                }
04759             }
04760             ast_debug(2, "Function %s result is '%s'\n", vars, cp4 ? cp4 : "(null)");
04761          } else {
04762             /* Retrieve variable value */
04763             pbx_retrieve_variable(c, vars, &cp4, workspace, VAR_BUF_SIZE, headp);
04764          }
04765          if (cp4) {
04766             cp4 = substring(cp4, offset, offset2, workspace, VAR_BUF_SIZE);
04767 
04768             length = strlen(cp4);
04769             if (length > count)
04770                length = count;
04771             memcpy(cp2, cp4, length);
04772             count -= length;
04773             cp2 += length;
04774             *cp2 = 0;
04775          }
04776       } else if (nextexp) {
04777          /* We have an expression.  Find the start and end, and determine
04778             if we are going to have to recursively call ourselves on the
04779             contents */
04780          vars = vare = nextexp + 2;
04781          brackets = 1;
04782          needsub = 0;
04783 
04784          /* Find the end of it */
04785          while (brackets && *vare) {
04786             if ((vare[0] == '$') && (vare[1] == '[')) {
04787                needsub++;
04788                brackets++;
04789                vare++;
04790             } else if (vare[0] == '[') {
04791                brackets++;
04792             } else if (vare[0] == ']') {
04793                brackets--;
04794             } else if ((vare[0] == '$') && (vare[1] == '{')) {
04795                needsub++;
04796                vare++;
04797             }
04798             vare++;
04799          }
04800          if (brackets)
04801             ast_log(LOG_WARNING, "Error in extension logic (missing ']')\n");
04802          len = vare - vars - 1;
04803 
04804          /* Skip totally over expression */
04805          whereweare += (len + 3);
04806 
04807          if (!var)
04808             var = ast_alloca(VAR_BUF_SIZE);
04809 
04810          /* Store variable name (and truncate) */
04811          ast_copy_string(var, vars, len + 1);
04812 
04813          /* Substitute if necessary */
04814          if (needsub) {
04815             size_t my_used;
04816 
04817             if (!ltmp) {
04818                ltmp = ast_alloca(VAR_BUF_SIZE);
04819             }
04820             pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, &my_used);
04821             vars = ltmp;
04822          } else {
04823             vars = var;
04824          }
04825 
04826          length = ast_expr(vars, cp2, count, c);
04827 
04828          if (length) {
04829             ast_debug(1, "Expression result is '%s'\n", cp2);
04830             count -= length;
04831             cp2 += length;
04832             *cp2 = 0;
04833          }
04834       }
04835    }
04836    *used = cp2 - orig_cp2;
04837 }

void pbx_substitute_variables_varshead ( struct varshead headp,
const char *  cp1,
char *  cp2,
int  count 
)

Definition at line 4845 of file pbx.c.

References NULL, and pbx_substitute_variables_helper_full().

Referenced by do_say(), dundi_lookup_local(), get_mapping_weight(), and loopback_subst().

04846 {
04847    size_t used;
04848    pbx_substitute_variables_helper_full(NULL, headp, cp1, cp2, count, &used);
04849 }


Generated on Thu Apr 16 06:32:16 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6