Asterisk - The Open Source Telephony Project GIT-master-6144b6b
Loading...
Searching...
No Matches
Data Structures | Macros | Typedefs | Enumerations | Functions
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
 

Macros

#define ast_custom_function_register(acf)   __ast_custom_function_register(acf, AST_MODULE_SELF)
 Register a custom function.
 
#define ast_custom_function_register_escalating(acf, escalation)   __ast_custom_function_register_escalating(acf, escalation, AST_MODULE_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   512
 
#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) (const char *context, const char *exten, 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
}
 Extension states. More...
 
enum  ast_pbx_outgoing_sync { AST_OUTGOING_NO_WAIT = 0 , AST_OUTGOING_WAIT = 1 , AST_OUTGOING_WAIT_COMPLETE = 2 }
 
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
}
 

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, const char *registrar_file, int registrar_line)
 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, const char *registrar_file, int registrar_line)
 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_in)
 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 *value, 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)
 
int ast_context_destroy_by_name (const char *context, const char *registrar)
 Destroy a context by name.
 
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_remove_ignorepat (const char *context, const char *ignorepat, const char *registrar)
 Remove an ignorepat.
 
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.
 
void ast_context_set_autohints (struct ast_context *con, int enabled)
 Enable or disable autohints support on a 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)
 Add watcher for extension states.
 
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)
 Add watcher for extension states 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)
 Add watcher for extended extension states with destructor.
 
int ast_extension_state_add_extended (const char *context, const char *exten, ast_state_cb_type change_cb, void *data)
 Add watcher for extended extension states.
 
int ast_extension_state_del (int id, ast_state_cb_type change_cb)
 Deletes a state change watcher 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
 
const char * ast_get_extension_registrar_file (struct ast_exten *e)
 Get name of configuration file used by registrar to register this extension.
 
int ast_get_extension_registrar_line (struct ast_exten *e)
 Get line number of configuration file used by registrar to register this extension.
 
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)
 
int ast_pbx_exec_application (struct ast_channel *chan, const char *app_name, const char *app_args)
 Execute an application.
 
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_app_predial (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, const char *predial_callee)
 
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.
 
int ast_pbx_outgoing_exten_predial (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, const char *predial_callee)
 
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_thread_inhibit_escalations_swap (int inhibit)
 Swap the current thread escalation inhibit setting.
 
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.).
 
int pbx_parse_location (struct ast_channel *chan, char **context, char **exten, char **pri, int *ipri, int *mode, char *rest)
 Parses a dialplan location into context, extension, priority.
 
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 (const struct ast_ignorepat *ip)
 
const char * ast_get_include_name (const struct ast_include *include)
 
const char * ast_get_switch_data (const struct ast_sw *sw)
 
int ast_get_switch_eval (const struct ast_sw *sw)
 
const char * ast_get_switch_name (const 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)
 
int ast_get_extension_data (char *buf, int bufsize, struct ast_channel *c, const char *context, const char *exten, int priority)
 Fill a string buffer with the data at a dialplan extension.
 
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)
 
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 (const struct ast_ignorepat *ip)
 
const char * ast_get_include_registrar (const struct ast_include *i)
 
const char * ast_get_switch_registrar (const struct ast_sw *sw)
 
Walking functions ...
struct ast_extenast_walk_context_extensions (struct ast_context *con, struct ast_exten *priority)
 
const struct ast_ignorepatast_walk_context_ignorepats (const struct ast_context *con, const struct ast_ignorepat *ip)
 
const struct ast_includeast_walk_context_includes (const struct ast_context *con, const struct ast_include *inc)
 
const struct ast_swast_walk_context_switches (const struct ast_context *con, const 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)
 
Iterator functions ...
int ast_context_ignorepats_count (const struct ast_context *con)
 
const struct ast_ignorepatast_context_ignorepats_get (const struct ast_context *con, int idx)
 
int ast_context_includes_count (const struct ast_context *con)
 
const struct ast_includeast_context_includes_get (const struct ast_context *con, int idx)
 
int ast_context_switches_count (const struct ast_context *con)
 
const struct ast_swast_context_switches_get (const struct ast_context *con, int idx)
 
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_helper_full_location (struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int cp2_size, size_t *used, const char *context, const char *exten, int pri)
 Substitutes variables, similar to pbx_substitute_variables_helper_full, but allows passing the context, extension, and priority in.
 
void pbx_substitute_variables_varshead (struct varshead *headp, const char *cp1, char *cp2, int count)
 
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_full2 (struct ast_str **buf, ssize_t maxlen, struct ast_channel *c, struct varshead *headp, const char *templ, size_t *used, int use_both)
 Perform variable/function/expression substitution on an ast_str.
 
void ast_str_substitute_variables_varshead (struct ast_str **buf, ssize_t maxlen, struct varshead *headp, const char *templ)
 
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)
 

Detailed Description

Core PBX routines and definitions.

Definition in file pbx.h.

Macro Definition Documentation

◆ ast_custom_function_register

#define ast_custom_function_register (   acf)    __ast_custom_function_register(acf, AST_MODULE_SELF)

Register a custom function.

Definition at line 1563 of file pbx.h.

◆ ast_custom_function_register_escalating

#define ast_custom_function_register_escalating (   acf,
  escalation 
)    __ast_custom_function_register_escalating(acf, escalation, AST_MODULE_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 1572 of file pbx.h.

◆ AST_MAX_APP

#define AST_MAX_APP   32

Max length of an application

Definition at line 40 of file pbx.h.

◆ AST_PBX_ERROR

#define AST_PBX_ERROR   1

Jump to the 'e' exten

Definition at line 50 of file pbx.h.

◆ AST_PBX_GOTO_FAILED

#define AST_PBX_GOTO_FAILED   -3

Definition at line 42 of file pbx.h.

◆ AST_PBX_HANGUP

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

◆ AST_PBX_INCOMPLETE

#define AST_PBX_INCOMPLETE   12

Return to PBX matching, allowing more digits for the extension

Definition at line 51 of file pbx.h.

◆ AST_PBX_KEEP

#define AST_PBX_KEEP   0

Definition at line 43 of file pbx.h.

◆ AST_PBX_MAX_STACK

#define AST_PBX_MAX_STACK   512

Definition at line 1668 of file pbx.h.

◆ AST_PBX_OK

#define AST_PBX_OK   0

No errors

Definition at line 49 of file pbx.h.

◆ AST_PBX_REPLACE

#define AST_PBX_REPLACE   1

Definition at line 44 of file pbx.h.

◆ PRIORITY_HINT

#define PRIORITY_HINT   -1

Special Priority for a hint

Definition at line 54 of file pbx.h.

◆ STATUS_NO_CONTEXT

#define STATUS_NO_CONTEXT   1

Definition at line 1659 of file pbx.h.

◆ STATUS_NO_EXTENSION

#define STATUS_NO_EXTENSION   2

Definition at line 1660 of file pbx.h.

◆ STATUS_NO_LABEL

#define STATUS_NO_LABEL   4

Definition at line 1662 of file pbx.h.

◆ STATUS_NO_PRIORITY

#define STATUS_NO_PRIORITY   3

Definition at line 1661 of file pbx.h.

◆ STATUS_SUCCESS

#define STATUS_SUCCESS   5

Definition at line 1663 of file pbx.h.

Typedef Documentation

◆ ast_state_cb_destroy_type

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.

◆ ast_state_cb_type

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

Typedef for devicestate and hint callbacks.

Definition at line 112 of file pbx.h.

◆ ast_switch_f

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 158 of file pbx.h.

Enumeration Type Documentation

◆ ast_custom_function_escalation

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 1553 of file pbx.h.

1553 {
1558};
@ AST_CFE_NONE
Definition pbx.h:1554
@ AST_CFE_READ
Definition pbx.h:1555
@ AST_CFE_WRITE
Definition pbx.h:1556
@ AST_CFE_BOTH
Definition pbx.h:1557

◆ ast_ext_matchcid_types

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.

77 {
78 AST_EXT_MATCHCID_OFF = 0, /*!< Match only extensions with matchcid=0 */
79 AST_EXT_MATCHCID_ON = 1, /*!< Match only extensions with matchcid=1 AND cidmatch matches */
80 AST_EXT_MATCHCID_ANY = 2, /*!< Match both - used only in functions manipulating ast_exten's */
81};
@ AST_EXT_MATCHCID_ON
Definition pbx.h:79
@ AST_EXT_MATCHCID_OFF
Definition pbx.h:78
@ AST_EXT_MATCHCID_ANY
Definition pbx.h:80

◆ ast_extension_states

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

Definition at line 61 of file pbx.h.

61 {
62 AST_EXTENSION_REMOVED = -2, /*!< Extension removed */
63 AST_EXTENSION_DEACTIVATED = -1, /*!< Extension hint removed */
64 AST_EXTENSION_NOT_INUSE = 0, /*!< No device INUSE or BUSY */
65 AST_EXTENSION_INUSE = 1 << 0, /*!< One or more devices INUSE */
66 AST_EXTENSION_BUSY = 1 << 1, /*!< All devices BUSY */
67 AST_EXTENSION_UNAVAILABLE = 1 << 2, /*!< All devices UNAVAILABLE/UNREGISTERED */
68 AST_EXTENSION_RINGING = 1 << 3, /*!< All devices RINGING */
69 AST_EXTENSION_ONHOLD = 1 << 4, /*!< All devices ONHOLD */
70};
@ AST_EXTENSION_REMOVED
Definition pbx.h:62
@ AST_EXTENSION_RINGING
Definition pbx.h:68
@ AST_EXTENSION_NOT_INUSE
Definition pbx.h:64
@ AST_EXTENSION_INUSE
Definition pbx.h:65
@ AST_EXTENSION_UNAVAILABLE
Definition pbx.h:67
@ AST_EXTENSION_ONHOLD
Definition pbx.h:69
@ AST_EXTENSION_BUSY
Definition pbx.h:66
@ AST_EXTENSION_DEACTIVATED
Definition pbx.h:63

◆ ast_pbx_outgoing_sync

Enumerator
AST_OUTGOING_NO_WAIT 

Don't wait for originated call to answer

AST_OUTGOING_WAIT 

Wait for originated call to answer

AST_OUTGOING_WAIT_COMPLETE 

Wait for originated call to answer and hangup

Definition at line 1143 of file pbx.h.

1143 {
1144 AST_OUTGOING_NO_WAIT = 0, /*!< Don't wait for originated call to answer */
1145 AST_OUTGOING_WAIT = 1, /*!< Wait for originated call to answer */
1146 AST_OUTGOING_WAIT_COMPLETE = 2, /*!< Wait for originated call to answer and hangup */
1147};
@ AST_OUTGOING_NO_WAIT
Definition pbx.h:1144
@ AST_OUTGOING_WAIT
Definition pbx.h:1145
@ AST_OUTGOING_WAIT_COMPLETE
Definition pbx.h:1146

◆ ast_pbx_result

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 372 of file pbx.h.

372 {
373 AST_PBX_SUCCESS = 0,
374 AST_PBX_FAILED = -1,
376};
@ AST_PBX_FAILED
Definition pbx.h:374
@ AST_PBX_CALL_LIMIT
Definition pbx.h:375
@ AST_PBX_SUCCESS
Definition pbx.h:373

◆ ast_state_cb_update_reason

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.

89 {
90 /*! The extension state update is a result of a device state changing on the extension. */
92 /*! The extension state update is a result of presence state changing on the extension. */
94};
@ AST_HINT_UPDATE_DEVICE
Definition pbx.h:91
@ AST_HINT_UPDATE_PRESENCE
Definition pbx.h:93

◆ ext_match_t

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 

Definition at line 1650 of file pbx.h.

1650 {
1651 E_MATCHMORE = 0x00, /* extension can match but only with more 'digits' */
1652 E_CANMATCH = 0x01, /* extension can match with or without more 'digits' */
1653 E_MATCH = 0x02, /* extension is an exact match */
1654 E_MATCH_MASK = 0x03, /* mask for the argument to extension_match_core() */
1655 E_SPAWN = 0x12, /* want to spawn an extension. Requires exact match */
1656 E_FINDLABEL = 0x22 /* returns the priority for a given label. Requires exact match */
1657};
@ E_MATCH_MASK
Definition pbx.h:1654
@ E_MATCH
Definition pbx.h:1653
@ E_CANMATCH
Definition pbx.h:1652
@ E_FINDLABEL
Definition pbx.h:1656
@ E_MATCHMORE
Definition pbx.h:1651
@ E_SPAWN
Definition pbx.h:1655

Function Documentation

◆ __ast_custom_function_register()

int __ast_custom_function_register ( struct ast_custom_function acf,
struct ast_module mod 
)

Register a custom function.

Definition at line 388 of file pbx_functions.c.

389{
390 struct ast_custom_function *cur;
391
392 if (!acf) {
393 return -1;
394 }
395
396 acf->mod = mod;
397#ifdef AST_XML_DOCS
398 acf->docsrc = AST_STATIC_DOC;
399#endif
400
401 if (acf_retrieve_docs(acf)) {
402 return -1;
403 }
404
406
408 if (cur) {
409 ast_log(LOG_ERROR, "Function %s already registered.\n", acf->name);
411 return -1;
412 }
413
414 /* Store in alphabetical order */
416 if (strcmp(acf->name, cur->name) < 0) {
418 break;
419 }
420 }
422 if (!cur) {
424 }
425
427
428 ast_verb(5, "Registered custom function '" COLORIZE_FMT "'\n", COLORIZE(COLOR_BRCYAN, 0, acf->name));
429
430 return 0;
431}
#define ast_log
Definition astobj2.c:42
#define LOG_ERROR
#define ast_verb(level,...)
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
#define AST_RWLIST_TRAVERSE_SAFE_END
#define AST_RWLIST_INSERT_TAIL
#define AST_RWLIST_INSERT_BEFORE_CURRENT
static struct ast_custom_function * ast_custom_function_find_nolock(const char *name)
static int acf_retrieve_docs(struct ast_custom_function *acf)
Registered functions container.
Data structure associated with a custom dialplan function.
Definition pbx.h:118
struct ast_module * mod
Definition pbx.h:142
enum ast_doc_src docsrc
Definition pbx.h:127
struct ast_custom_function::@254 acflist
const char * name
Definition pbx.h:119
#define COLOR_BRCYAN
Definition term.h:63
#define COLORIZE(fg, bg, str)
Definition term.h:72
#define COLORIZE_FMT
Shortcut macros for coloring a set of text.
Definition term.h:71
@ AST_STATIC_DOC
Definition xmldoc.h:32

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_msg_init(), load_features_config(), and load_pbx().

◆ __ast_custom_function_register_escalating()

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 433 of file pbx_functions.c.

434{
435 int res;
436
437 res = __ast_custom_function_register(acf, mod);
438 if (res != 0) {
439 return -1;
440 }
441
442 switch (escalation) {
443 case AST_CFE_NONE:
444 break;
445 case AST_CFE_READ:
446 acf->read_escalates = 1;
447 break;
448 case AST_CFE_WRITE:
449 acf->write_escalates = 1;
450 break;
451 case AST_CFE_BOTH:
452 acf->read_escalates = 1;
453 acf->write_escalates = 1;
454 break;
455 }
456
457 return 0;
458}
int __ast_custom_function_register(struct ast_custom_function *acf, struct ast_module *mod)
Register a custom function.
unsigned int read_escalates
Definition pbx.h:143
unsigned int write_escalates
Definition pbx.h:147

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

◆ ast_active_calls()

int ast_active_calls ( void  )

Retrieve the number of active calls.

Definition at line 3320 of file pbx.c.

3321{
3322 return countcalls;
3323}
static int countcalls
Definition pbx.c:422

References countcalls.

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

◆ ast_add_extension()

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
contextcontext to add the extension to
replace
extensionextension to add
prioritypriority level of extension addition
labelextension label
calleridpattern to match CallerID, or NULL to match any CallerID
applicationapplication to run on the extension with that priority level
datadata to pass to the application
datada pointer to a function that will deallocate data when needed or NULL if data does not need to be freed.
registrarwho registered the extension
Note
On any failure, the function pointed to by datap will be called and passed the data pointer.
Return values
0success
-1failure

Definition at line 5206 of file pbx.c.

5209{
5210 int ret = -1;
5211 struct ast_context *c;
5212
5213 c = find_context_locked(context);
5214 if (c) {
5215 ret = ast_add_extension2(c, replace, extension, priority, label, callerid,
5216 application, data, datad, registrar, NULL, 0);
5218 }
5219
5220 return ret;
5221}
static int priority
static const char registrar[]
The static registrar for the added dialplan hints.
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
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, const char *registrar_file, int registrar_line)
Main interface to add extensions to the list for out context.
Definition pbx.c:5539
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition pbx.c:3374
int ast_unlock_contexts(void)
Unlocks contexts.
Definition pbx.c:6631
#define NULL
Definition resample.c:96
ast_context: An extension context
Definition pbx.c:254
char data[]
Definition pbx.c:275
structure to hold extensions
static struct test_val c

References ast_add_extension2(), ast_unlock_contexts(), c, ast_context::data, find_context_locked(), NULL, priority, registrar, and replace().

Referenced by add_to_regcontext(), app_create(), ast_sip_persistent_endpoint_update_state(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), create_test_dialplan(), extension_state_autohints_device_state_cb(), extension_state_get(), handle_cli_dialplan_add_extension(), join_conference_bridge(), load_module(), register_extension(), register_peer_exten(), session_register_apps(), sla_build_station(), and sla_build_trunk().

◆ ast_add_extension2()

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,
const char *  registrar_file,
int  registrar_line 
)

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

Parameters
concontext to add the extension to
replace
extensionextension to add
prioritypriority level of extension addition
labelextension label
calleridpattern to match CallerID, or NULL to match any CallerID
applicationapplication to run on the extension with that priority level
datadata to pass to the application
datada pointer to a function that will deallocate data when needed or NULL if data does not need to be freed.
registrarwho registered the extension
registrar_fileoptional configuration file that defines this extension
registrar_lineoptional line number of configuration file that defines extension
Note
On any failure, the function pointed to by datap will be called and passed the data pointer.
Return values
0success
-1failure

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 5539 of file pbx.c.

5543{
5544 return ast_add_extension2_lockopt(con, replace, extension, priority, label, callerid,
5545 application, data, datad, registrar, registrar_file, registrar_line, 1);
5546}
static int ast_add_extension2_lockopt(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, const char *registrar_file, int registrar_line, int lock_context)
Same as ast_add_extension2() but controls the context locking.
Definition pbx.c:5565

References ast_add_extension2_lockopt(), priority, registrar, and replace().

Referenced by add_extensions(), ast_add_extension(), context_merge(), lua_register_hints(), manager_dialplan_extension_add(), and pbx_load_config().

◆ ast_add_extension2_nolock()

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,
const char *  registrar_file,
int  registrar_line 
)

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

Definition at line 5548 of file pbx.c.

5552{
5553 return ast_add_extension2_lockopt(con, replace, extension, priority, label, callerid,
5554 application, data, datad, registrar, registrar_file, registrar_line, 0);
5555}

References ast_add_extension2_lockopt(), priority, registrar, and replace().

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

◆ ast_async_goto()

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
If the AST_SOFTHANGUP_ASYNCGOTO flag is set, it can prevent the dialplan location from being overwritten by ast_explicit_goto.
Do NOT hold any channel locks when calling this function.

Definition at line 5251 of file pbx.c.

5252{
5253 struct ast_channel *newchan;
5254
5255 ast_channel_lock(chan);
5256 /* Channels in a bridge or running a PBX can be sent directly to the specified destination */
5257 if (ast_channel_is_bridged(chan) || ast_channel_pbx(chan)) {
5259 priority += 1;
5260 }
5263 ast_channel_unlock(chan);
5264 return 0;
5265 }
5266 ast_channel_unlock(chan);
5267
5268 /* Otherwise, we need to gain control of the channel first */
5269 newchan = ast_channel_yank(chan);
5270 if (!newchan) {
5271 ast_log(LOG_WARNING, "Unable to gain control of channel %s\n", ast_channel_name(chan));
5272 return -1;
5273 }
5275 if (ast_pbx_start(newchan)) {
5276 ast_hangup(newchan);
5277 ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(newchan));
5278 return -1;
5279 }
5280
5281 return 0;
5282}
const char * ast_channel_name(const struct ast_channel *chan)
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition channel.c:2540
#define ast_channel_lock(chan)
Definition channel.h:2983
@ AST_FLAG_IN_AUTOLOOP
Definition channel.h:1017
struct ast_channel * ast_channel_yank(struct ast_channel *yankee)
Gain control of a channel in the system.
Definition channel.c:10773
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
Definition channel.c:10725
@ AST_SOFTHANGUP_ASYNCGOTO
Definition channel.h:1146
int ast_softhangup_nolock(struct ast_channel *chan, int cause)
Softly hangup up a channel (no channel lock)
Definition channel.c:2449
struct ast_pbx * ast_channel_pbx(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition channel.h:2984
#define LOG_WARNING
enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
Create a new thread and start the PBX.
Definition pbx.c:3268
int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority)
Definition pbx.c:5223
Main Channel structure associated with a channel.
char exten[AST_MAX_EXTENSION]
char context[AST_MAX_CONTEXT]
#define ast_test_flag(p, flag)
Definition utils.h:64

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, ast_channel::context, ast_channel::exten, LOG_WARNING, and priority.

Referenced by __ast_goto_if_exists(), ast_async_goto_by_name(), async_goto_with_discard_bridge_after(), bridge_channel_blind_transfer(), chan_pjsip_cng_tone_detected(), comeback_goto(), dahdi_handle_dtmf(), fax_detect_framehook(), my_handle_dtmf(), onModeChanged(), ooh323_rtp_read(), and pbx_parseable_goto().

◆ ast_async_goto_by_name()

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 5284 of file pbx.c.

5285{
5286 struct ast_channel *chan;
5287 int res = -1;
5288
5289 if ((chan = ast_channel_get_by_name(channame))) {
5290 res = ast_async_goto(chan, context, exten, priority);
5291 chan = ast_channel_unref(chan);
5292 }
5293
5294 return res;
5295}
struct ast_channel * ast_channel_get_by_name(const char *search)
Find a channel by name or uniqueid.
Definition channel.c:1417
#define ast_channel_unref(c)
Decrease channel reference count.
Definition channel.h:3019
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.
Definition pbx.c:5251

References ast_async_goto(), ast_channel_get_by_name(), ast_channel_unref, ast_channel::context, ast_channel::exten, and priority.

◆ ast_async_goto_if_exists()

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 6944 of file pbx.c.

6945{
6946 return __ast_goto_if_exists(chan, context, exten, priority, 1);
6947}
static int __ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, int async)
Definition pbx.c:6918

References __ast_goto_if_exists(), ast_channel::context, ast_channel::exten, and priority.

◆ ast_async_parseable_goto()

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 7029 of file pbx.c.

7030{
7031 return pbx_parseable_goto(chan, goto_string, 1);
7032}
static int pbx_parseable_goto(struct ast_channel *chan, const char *goto_string, int async)
Definition pbx.c:6990

References pbx_parseable_goto().

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

◆ ast_build_timing()

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

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

Parameters
iPointer to an ast_timing structure.
info_inStandard string containing a timerange, weekday range, monthday range, and month range, as well as an optional timezone.
Return values
1on success.
0on failure.

Definition at line 3804 of file extconf.c.

3805{
3806 char *info;
3807 int j, num_fields, last_sep = -1;
3808
3809 i->timezone = NULL;
3810
3811 /* Check for empty just in case */
3812 if (ast_strlen_zero(info_in)) {
3813 return 0;
3814 }
3815
3816 /* make a copy just in case we were passed a static string */
3817 info = ast_strdupa(info_in);
3818
3819 /* count the number of fields in the timespec */
3820 for (j = 0, num_fields = 1; info[j] != '\0'; j++) {
3821 if (info[j] == '|' || info[j] == ',') {
3822 last_sep = j;
3823 num_fields++;
3824 }
3825 }
3826
3827 /* save the timezone, if it is specified */
3828 if (num_fields == 5) {
3829 i->timezone = ast_strdup(info + last_sep + 1);
3830 }
3831
3832 /* Assume everything except time */
3833 i->monthmask = 0xfff; /* 12 bits */
3834 i->daymask = 0x7fffffffU; /* 31 bits */
3835 i->dowmask = 0x7f; /* 7 bits */
3836 /* on each call, use strsep() to move info to the next argument */
3837 get_timerange(i, strsep(&info, "|,"));
3838 if (info)
3839 i->dowmask = get_range(strsep(&info, "|,"), 7, days, "day of week");
3840 if (info)
3841 i->daymask = get_range(strsep(&info, "|,"), 31, NULL, "day");
3842 if (info)
3843 i->monthmask = get_range(strsep(&info, "|,"), 12, months, "month");
3844 return 1;
3845}
char * strsep(char **str, const char *delims)
#define ast_strdup(str)
A wrapper for strdup()
Definition astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
char * days[]
Definition extconf.c:3773
static void get_timerange(struct ast_timing *i, char *times)
store a bitmask of valid times, one bit each 2 minute
Definition extconf.c:2680
static unsigned get_range(char *src, int max, char *const names[], const char *msg)
helper function to return a range up to max (7, 12, 31 respectively). names, if supplied,...
Definition extconf.c:2636
char * months[]
Definition extconf.c:3785
static force_inline int ast_strlen_zero(const char *s)
Definition extconf.c:950
unsigned int monthmask
Definition pbx.h:175
unsigned int daymask
Definition pbx.h:176
char * timezone
Definition pbx.h:179
unsigned int dowmask
Definition pbx.h:177

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

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

◆ ast_canmatch_extension()

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
cnot really important
contextcontext to search within
extenextension to check
prioritypriority of extension path
calleridcallerid 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 2750 of file pbx.c.

2751{
2752 return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_CANMATCH, 0, 0);
2753}
@ E_CANMATCH
Definition extconf.h:216
static int pbx_extension_helper(struct ast_channel *c, struct ast_context *con, const char *context, const char *exten, int priority, const char *label, const char *callerid, enum ext_match_t action, int *found, int combined_find_spawn)
The return value depends on the action:
Definition pbx.c:2516

References c, E_CANMATCH, ast_exten::exten, NULL, pbx_extension_helper(), and priority.

Referenced by __analog_ss_thread(), analog_ss_thread(), background_detect_exec(), dp_lookup(), dundi_lookup_local(), get_destination(), leave_voicemail(), loopback_canmatch(), pbx_builtin_background(), test_exten(), and valid_exit().

◆ ast_check_timing()

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
iPointer to an ast_timing structure.
Return values
1if the time matches.
0if the current time falls outside of the specified range.

Definition at line 3998 of file extconf.c.

3999{
4000 /* sorry, but this feature will NOT be available
4001 in the standalone version */
4002 return 0;
4003}

References ast_check_timing2(), and ast_tvnow().

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

◆ ast_check_timing2()

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
iPointer to an ast_timing structure.
tvSpecified time
Return values
1if the time matches.
0if the time falls outside of the specified range.

Definition at line 245 of file pbx_timing.c.

246{
247 struct ast_tm tm;
248
249 ast_localtime(&tv, &tm, i->timezone);
250
251 /* If it's not the right month, return */
252 if (!(i->monthmask & (1 << tm.tm_mon)))
253 return 0;
254
255 /* If it's not that time of the month.... */
256 /* Warning, tm_mday has range 1..31! */
257 if (!(i->daymask & (1 << (tm.tm_mday-1))))
258 return 0;
259
260 /* If it's not the right day of the week */
261 if (!(i->dowmask & (1 << tm.tm_wday)))
262 return 0;
263
264 /* Sanity check the hour just to be safe */
265 if ((tm.tm_hour < 0) || (tm.tm_hour > 23)) {
266 ast_log(LOG_WARNING, "Insane time...\n");
267 return 0;
268 }
269
270 /* Now the tough part, we calculate if it fits
271 in the right time based on min/hour */
272 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))))
273 return 0;
274
275 /* If we got this far, then we're good */
276 return 1;
277}
struct ast_tm * ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone)
Timezone-independent version of localtime_r(3).
Definition localtime.c:1739
unsigned int minmask[48]
Definition pbx.h:178
int tm_min
Definition localtime.h:37

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

◆ ast_complete_applications()

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 441 of file pbx_app.c.

442{
443 struct ast_app *app;
444 int which = 0;
445 int cmp;
446 char *ret = NULL;
447 size_t wordlen = strlen(word);
448
451 cmp = strncasecmp(word, app->name, wordlen);
452 if (cmp < 0) {
453 /* No more matches. */
454 break;
455 } else if (!cmp) {
456 /* Found match. */
457 if (state != -1) {
458 if (++which <= state) {
459 /* Not enough matches. */
460 continue;
461 }
462 ret = ast_strdup(app->name);
463 break;
464 }
466 break;
467 }
468 }
469 }
471
472 return ret;
473}
static const char app[]
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
Definition main/cli.c:2845
short word
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition linkedlists.h:78
#define AST_RWLIST_TRAVERSE
Registered applications container.
Definition pbx_app.c:69
ast_app: A registered application
Definition pbx_app.c:45
struct ast_app::@406 list

References app, ast_cli_completion_add(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, ast_app::list, and NULL.

Referenced by handle_orig(), and handle_show_application().

◆ ast_context_add_ignorepat()

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

Add an ignorepat.

Parameters
contextwhich context to add the ignorepattern to
ignorepatignorepattern to set up for the extension
registrarregistrar of the ignore pattern

Adds an ignore pattern to a particular context.

Return values
0on success
-1on failure

Definition at line 5133 of file pbx.c.

5134{
5135 int ret = -1;
5136 struct ast_context *c;
5137
5138 c = find_context_locked(context);
5139 if (c) {
5142 }
5143 return ret;
5144}
int ast_context_add_ignorepat2(struct ast_context *con, const char *value, const char *registrar)
Definition pbx.c:5146
int value
Definition syslog.c:37

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

Referenced by handle_cli_dialplan_add_ignorepat().

◆ ast_context_add_ignorepat2()

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

Definition at line 348 of file ael_main.c.

349{
350 if(!no_comp)
351 printf("Executed ast_context_add_ignorepat2(con, value=%s, registrar=%s);\n", value, registrar);
352 if( dump_extensions ) {
353 struct namelist *x;
354 x = create_name(value);
355 ADD_LAST(con->ignorepats,x);
356 }
357}
struct namelist * create_name(const char *name)
Definition ael_main.c:79
#define ADD_LAST(headptr, memptr)
Definition ael_main.c:64
static int no_comp
Definition ael_main.c:124
static int dump_extensions
Definition ael_main.c:126
struct ast_ignorepats ignorepats
Definition pbx.c:264

References ADD_LAST, ast_context_ignorepats_count(), ast_context_ignorepats_get(), ast_get_ignorepat_name(), ast_unlock_context(), AST_VECTOR_APPEND, ast_wrlock_context(), create_name(), dump_extensions, errno, ignorepat_alloc(), ignorepat_free(), ast_context::ignorepats, no_comp, registrar, and value.

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

◆ ast_context_add_include()

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

Add a context include.

Parameters
contextcontext to add include to
includenew include to add
registrarwho's registering it

Adds an include taking a char * string as the context parameter

Return values
0on success
-1on error

Definition at line 4962 of file pbx.c.

4963{
4964 int ret = -1;
4965 struct ast_context *c;
4966
4967 c = find_context_locked(context);
4968 if (c) {
4969 ret = ast_context_add_include2(c, include, registrar);
4971 }
4972 return ret;
4973}
int ast_context_add_include2(struct ast_context *con, const char *value, const char *registrar)
Add a context include.
Definition pbx.c:4982

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

Referenced by AST_TEST_DEFINE(), and handle_cli_dialplan_add_include().

◆ ast_context_add_include2()

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

Add a context include.

Adds an include taking a struct ast_context as the first parameter

Note
See ast_context_add_include for information on arguments

Definition at line 359 of file ael_main.c.

360{
361 if(!no_comp)
362 printf("Executed ast_context_add_include2(con, value=%s, registrar=%s);\n", value, registrar);
363 if( dump_extensions ) {
364 struct namelist *x;
365 x = create_name((char*)value);
366 ADD_LAST(con->includes,x);
367 }
368}
struct ast_includes includes
Definition pbx.c:263

References ADD_LAST, ast_context_includes_count(), ast_context_includes_get(), ast_debug, ast_get_context_name(), ast_get_include_name(), ast_unlock_context(), AST_VECTOR_APPEND, ast_wrlock_context(), create_name(), dump_extensions, errno, include_alloc(), include_free(), ast_context::includes, no_comp, registrar, and value.

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

◆ ast_context_add_switch()

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

Add a switch.

Parameters
contextcontext to which to add the switch
swswitch to add
datadata to pass to switch
evalwhether to evaluate variables when running switch
registrarwhoever registered the switch

This function registers a switch with the asterisk switch architecture

Return values
0on success
-1on failure

Definition at line 5027 of file pbx.c.

5028{
5029 int ret = -1;
5030 struct ast_context *c;
5031
5032 c = find_context_locked(context);
5033 if (c) { /* found, add switch to this context */
5034 ret = ast_context_add_switch2(c, sw, data, eval, registrar);
5036 }
5037 return ret;
5038}
int ast_context_add_switch2(struct ast_context *con, const char *value, const char *data, int eval, const char *registrar)
Adds a switch (first param is a ast_context)
Definition pbx.c:5047

References ast_context_add_switch2(), ast_unlock_contexts(), c, ast_context::data, find_context_locked(), and registrar.

◆ ast_context_add_switch2()

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 370 of file ael_main.c.

371{
372 if(!no_comp)
373 printf("Executed ast_context_add_switch2(con, value=%s, data=%s, eval=%d, registrar=%s);\n", value, data, eval, registrar);
374 if( dump_extensions ) {
375 struct namelist *x;
376 x = create_name((char*)value);
377 strncpy(x->name2, data, 99);
378 if( eval ) {
379
380 ADD_LAST(con->switches,x);
381
382 } else {
383
384 ADD_LAST(con->eswitches,x);
385 }
386 }
387}
struct namelist * switches
Definition ael_main.c:53
struct namelist * eswitches
Definition ael_main.c:54
char name2[100]
Definition ael_main.c:42

References ADD_LAST, ast_context::alts, ast_context_switches_count(), ast_context_switches_get(), ast_get_context_name(), ast_get_switch_data(), ast_get_switch_name(), ast_unlock_context(), AST_VECTOR_APPEND, ast_verb, ast_wrlock_context(), create_name(), ast_sw::data, dump_extensions, errno, ast_context::eswitches, ast_sw::eval, namelist::name2, no_comp, registrar, sw_alloc(), sw_free(), ast_context::switches, and value.

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

◆ ast_context_destroy()

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

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

Parameters
concontext to destroy
registrarwho registered it

You can optionally leave out either parameter. It will find it based on either the ast_context or the registrar name.

Definition at line 6507 of file pbx.c.

6508{
6512}
void __ast_context_destroy(struct ast_context *list, struct ast_hashtab *contexttab, struct ast_context *con, const char *registrar)
Definition pbx.c:6342
int ast_wrlock_contexts(void)
Write locks the context list.
Definition pbx.c:6621
static struct ast_hashtab * contexts_table
Definition pbx.c:426
static struct ast_context * contexts
Definition pbx.c:425

References __ast_context_destroy(), ast_unlock_contexts(), ast_wrlock_contexts(), contexts, contexts_table, and registrar.

◆ ast_context_destroy_by_name()

int ast_context_destroy_by_name ( const char *  context,
const char *  registrar 
)

Destroy a context by name.

Parameters
contextName of the context to destroy
registrarwho registered it

You can optionally leave out the registrar parameter. It will find it based on the context name.

Return values
-1context not found
0Success

Definition at line 6491 of file pbx.c.

6492{
6493 struct ast_context *con;
6494 int ret = -1;
6495
6497 con = ast_context_find(context);
6498 if (con) {
6500 ret = 0;
6501 }
6503
6504 return ret;
6505}
void ast_context_destroy(void)
Definition ael_main.c:414
struct ast_context * ast_context_find(const char *name)
Find a context.
Definition pbx.c:2065

References ast_context_destroy(), ast_context_find(), ast_unlock_contexts(), ast_wrlock_contexts(), and registrar.

Referenced by __unload_module(), app_dtor(), ast_sip_destroy_sorcery_global(), check_regcontext(), handle_cli_dialplan_remove_context(), pbx_extension_state_autohint_remove(), and session_unregister_app_cb().

◆ ast_context_find()

static struct ast_context * ast_context_find ( const char *  name)

Find a context.

Parameters
namename 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 4170 of file extconf.c.

4171{
4172 struct ast_context *tmp = NULL;
4173 while ( (tmp = ast_walk_contexts(tmp)) ) {
4174 if (!name || !strcasecmp(name, tmp->name))
4175 break;
4176 }
4177 return tmp;
4178}
struct ast_context * ast_walk_contexts(void)
Definition ael_main.c:401
static const char name[]
Definition format_mp3.c:68
const char * name
Definition pbx.c:255

References ast_hashtab_lookup(), ast_rdlock_contexts(), ast_unlock_contexts(), ast_walk_contexts(), contexts_table, item, name, aco_type::name, ast_context::name, and NULL.

Referenced by app_create(), ast_context_destroy_by_name(), ast_context_verify_includes(), ast_ignore_pattern(), context_included(), handle_cli_dialplan_add_extension(), handle_cli_dialplan_add_include(), isexten_function_read(), and session_register_apps().

◆ ast_context_find_or_create()

struct ast_context * ast_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.

Parameters
extcontextspointer to the ast_context structure pointer
exttablepointer to the hashtable that contains all the elements in extcontexts
namename of the new context
registrarregistrar 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 4542 of file pbx.c.

4543{
4544 struct ast_context *tmp, **local_contexts;
4545 struct ast_context search = {
4546 .name = name,
4547 };
4548 size_t name_bytes = strlen(name);
4549 size_t registrar_bytes = strlen(registrar);
4550 int length = sizeof(struct ast_context) + name_bytes + registrar_bytes + 2;
4551
4552 if (!contexts_table) {
4553 /* Protect creation of contexts_table from reentrancy. */
4555 if (!contexts_table) {
4561 0);
4562 }
4564 }
4565
4566 if (!extcontexts) {
4569 tmp = ast_hashtab_lookup(contexts_table, &search);
4570 if (tmp) {
4571 tmp->refcount++;
4573 return tmp;
4574 }
4575 } else { /* local contexts just in a linked list; search there for the new context; slow, linear search, but not frequent */
4576 local_contexts = extcontexts;
4577 tmp = ast_hashtab_lookup(exttable, &search);
4578 if (tmp) {
4579 tmp->refcount++;
4580 return tmp;
4581 }
4582 }
4583
4584 if ((tmp = ast_calloc(1, length))) {
4585 ast_rwlock_init(&tmp->lock);
4586 tmp->name = memcpy(&tmp->data[0], name, name_bytes);
4587 tmp->registrar = memcpy(&tmp->data[name_bytes + 1], registrar, registrar_bytes);
4588 tmp->root = NULL;
4589 tmp->root_table = NULL;
4590 AST_VECTOR_INIT(&tmp->includes, 0);
4591 AST_VECTOR_INIT(&tmp->ignorepats, 0);
4592 AST_VECTOR_INIT(&tmp->alts, 0);
4593 tmp->refcount = 1;
4594
4595 /* The context 'name' must be stored at the beginning of 'data.' The
4596 * order of subsequent strings (currently only 'registrar') is not
4597 * relevant. */
4598 ast_assert(tmp->name == &tmp->data[0]);
4599 } else {
4600 ast_log(LOG_ERROR, "Danger! We failed to allocate a context for %s!\n", name);
4601 if (!extcontexts) {
4603 }
4604 return NULL;
4605 }
4606
4607 if (!extcontexts) {
4609 tmp->next = *local_contexts;
4610 *local_contexts = tmp;
4611 ast_hashtab_insert_safe(contexts_table, tmp); /*put this context into the tree */
4613 } else {
4615 tmp->next = *local_contexts;
4616 if (exttable)
4617 ast_hashtab_insert_immediate(exttable, tmp); /*put this context into the tree */
4618
4619 *local_contexts = tmp;
4620 }
4621 ast_debug(1, "Registered extension context '%s'; registrar: %s, scope: %s\n", tmp->name, registrar,
4622 tmp->scope == AST_CONTEXT_SCOPE_LOCAL ? "local": "global");
4623 return tmp;
4624}
#define ast_calloc(num, len)
A wrapper for calloc()
Definition astmm.h:202
#define ast_hashtab_insert_safe(tab, obj)
Definition hashtab.h:316
int ast_hashtab_newsize_java(struct ast_hashtab *tab)
Create a prime number roughly 2x the current table size.
Definition hashtab.c:127
#define ast_hashtab_insert_immediate(tab, obj)
Insert without checking.
Definition hashtab.h:290
void * ast_hashtab_lookup(struct ast_hashtab *tab, const void *obj)
Lookup this object in the hash table.
Definition hashtab.c:486
#define ast_hashtab_create(initial_buckets, compare, resize, newsize, hash, do_locking)
Create the hashtable list.
Definition hashtab.h:254
int ast_hashtab_resize_java(struct ast_hashtab *tab)
Determines if a table resize should occur using the Java algorithm (if the table load factor is 75% o...
Definition hashtab.c:84
#define ast_debug(level,...)
Log a DEBUG message.
#define ast_rwlock_init(rwlock)
wrapper for rwlock with tracking enabled
Definition lock.h:231
int ast_hashtab_compare_contexts(const void *ah_a, const void *ah_b)
hashtable functions for contexts
Definition pbx.c:337
unsigned int ast_hashtab_hash_contexts(const void *obj)
Definition pbx.c:389
int ast_rdlock_contexts(void)
Read locks the context list.
Definition pbx.c:6626
@ AST_CONTEXT_SCOPE_GLOBAL
Definition pbx.c:198
@ AST_CONTEXT_SCOPE_LOCAL
Definition pbx.c:197
static struct ast_context * local_contexts
Definition pbx_config.c:117
struct ast_sws alts
Definition pbx.c:265
struct ast_exten * root
Definition pbx.c:259
enum ast_context_scope scope
Definition pbx.c:266
int refcount
Definition pbx.c:267
const char * registrar
Definition pbx.c:256
struct ast_context * next
Definition pbx.c:262
struct ast_hashtab * root_table
Definition pbx.c:260
ast_rwlock_t lock
Definition pbx.c:258
#define ast_assert(a)
Definition utils.h:779
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition vector.h:124

References ast_context::alts, ast_assert, ast_calloc, AST_CONTEXT_SCOPE_GLOBAL, AST_CONTEXT_SCOPE_LOCAL, ast_debug, 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_rdlock_contexts(), ast_rwlock_init, ast_unlock_contexts(), AST_VECTOR_INIT, ast_wrlock_contexts(), contexts, contexts_table, ast_context::data, ast_context::ignorepats, ast_context::includes, local_contexts, ast_context::lock, LOG_ERROR, name, ast_context::name, ast_context::next, NULL, ast_context::refcount, registrar, ast_context::registrar, ast_context::root, ast_context::root_table, and ast_context::scope.

Referenced by add_hints(), app_create(), ast_compile_ael2(), ast_sip_persistent_endpoint_add_to_regcontext(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), 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(), session_register_apps(), set_config(), sla_build_station(), and sla_build_trunk().

◆ ast_context_ignorepats_count()

int ast_context_ignorepats_count ( const struct ast_context con)

◆ ast_context_ignorepats_get()

const struct ast_ignorepat * ast_context_ignorepats_get ( const struct ast_context con,
int  idx 
)

◆ ast_context_includes_count()

int ast_context_includes_count ( const struct ast_context con)

◆ ast_context_includes_get()

const struct ast_include * ast_context_includes_get ( const struct ast_context con,
int  idx 
)

◆ ast_context_remove_extension()

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

Simply remove extension from context.

Parameters
contextcontext to remove extension from
extensionwhich extension to remove
prioritypriority of extension to remove (0 to remove all)
registrarregistrar of the extension

This function removes an extension from a given context.

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

Definition at line 3508 of file pbx.c.

3509{
3511}
int ast_context_remove_extension_callerid(const char *context, const char *extension, int priority, const char *callerid, int matchcallerid, const char *registrar)
Definition pbx.c:3513

References ast_context_remove_extension_callerid(), AST_EXT_MATCHCID_ANY, NULL, priority, and registrar.

Referenced by ast_sip_persistent_endpoint_update_state(), AST_TEST_DEFINE(), conf_ended(), delete_extens(), register_peer_exten(), sla_station_destructor(), sla_trunk_destructor(), and unregister_extension().

◆ ast_context_remove_extension2()

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 3538 of file pbx.c.

3539{
3541}
int ast_context_remove_extension_callerid2(struct ast_context *con, const char *extension, int priority, const char *callerid, int matchcallerid, const char *registrar, int already_locked)
Definition pbx.c:3543

References ast_context_remove_extension_callerid2(), AST_EXT_MATCHCID_ANY, NULL, priority, and registrar.

Referenced by add_extension(), and add_hints().

◆ ast_context_remove_extension_callerid()

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 3513 of file pbx.c.

3514{
3515 int ret = -1; /* default error return */
3516 struct ast_context *c;
3517
3518 c = find_context_locked(context);
3519 if (c) { /* ... remove extension ... */
3521 matchcallerid, registrar, 0);
3523 }
3524
3525 return ret;
3526}

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

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

◆ ast_context_remove_extension_callerid2()

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 3543 of file pbx.c.

3544{
3545 struct ast_exten *exten, *prev_exten = NULL;
3546 struct ast_exten *peer;
3547 struct ast_exten ex, *exten2, *exten3;
3548 char dummy_name[1024];
3549 char dummy_cid[1024];
3550 struct ast_exten *previous_peer = NULL;
3551 struct ast_exten *next_peer = NULL;
3552 int found = 0;
3553
3554 if (!already_locked)
3555 ast_wrlock_context(con);
3556
3557#ifdef NEED_DEBUG
3558 ast_verb(3,"Removing %s/%s/%d%s%s from trees, registrar=%s\n", con->name, extension, priority, matchcallerid ? "/" : "", matchcallerid ? callerid : "", registrar);
3559#endif
3560#ifdef CONTEXT_DEBUG
3561 check_contexts(__FILE__, __LINE__);
3562#endif
3563 /* find this particular extension */
3564 ex.exten = dummy_name;
3565 ext_strncpy(dummy_name, extension, sizeof(dummy_name), 1);
3566 ex.matchcid = matchcallerid;
3567 if (callerid) {
3568 ex.cidmatch = dummy_cid;
3569 ext_strncpy(dummy_cid, callerid, sizeof(dummy_cid), 1);
3570 } else {
3571 ex.cidmatch = NULL;
3572 }
3573 exten = ast_hashtab_lookup(con->root_table, &ex);
3574 if (exten) {
3575 if (priority == 0) {
3577 if (!exten2)
3578 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);
3579 if (con->pattern_tree) {
3580 struct match_char *x = add_exten_to_pattern_tree(con, exten, 1);
3581
3582 if (x->exten) { /* this test for safety purposes */
3583 x->deleted = 1; /* with this marked as deleted, it will never show up in the scoreboard, and therefore never be found */
3584 x->exten = 0; /* get rid of what will become a bad pointer */
3585 } else {
3586 ast_log(LOG_WARNING,"Trying to delete an exten from a context, but the pattern tree node returned isn't a full extension\n");
3587 }
3588 }
3589 } else {
3590 ex.priority = priority;
3591 exten2 = ast_hashtab_lookup(exten->peer_table, &ex);
3592 if (exten2) {
3593 if (exten2->label) { /* if this exten has a label, remove that, too */
3595 if (!exten3) {
3596 ast_log(LOG_ERROR, "Did not remove this priority label (%d/%s) "
3597 "from the peer_label_table of context %s, extension %s!\n",
3598 priority, exten2->label, con->name, exten2->name);
3599 }
3600 }
3601
3603 if (!exten3) {
3604 ast_log(LOG_ERROR, "Did not remove this priority (%d) from the "
3605 "peer_table of context %s, extension %s!\n",
3606 priority, con->name, exten2->name);
3607 }
3608 if (exten2 == exten && exten2->peer) {
3611 }
3612 if (ast_hashtab_size(exten->peer_table) == 0) {
3613 /* well, if the last priority of an exten is to be removed,
3614 then, the extension is removed, too! */
3616 if (!exten3) {
3617 ast_log(LOG_ERROR, "Did not remove this exten (%s) from the "
3618 "context root_table (%s) (priority %d)\n",
3619 exten->name, con->name, priority);
3620 }
3621 if (con->pattern_tree) {
3622 struct match_char *x = add_exten_to_pattern_tree(con, exten, 1);
3623 if (x->exten) { /* this test for safety purposes */
3624 x->deleted = 1; /* with this marked as deleted, it will never show up in the scoreboard, and therefore never be found */
3625 x->exten = 0; /* get rid of what will become a bad pointer */
3626 }
3627 }
3628 }
3629 } else {
3630 ast_debug(3,"Could not find priority %d of exten %s in context %s!\n",
3631 priority, exten->name, con->name);
3632 }
3633 }
3634 } else {
3635 /* hmmm? this exten is not in this pattern tree? */
3636 ast_log(LOG_WARNING,"Cannot find extension %s in root_table in context %s\n",
3637 extension, con->name);
3638 }
3639#ifdef NEED_DEBUG
3640 if (con->pattern_tree) {
3641 ast_log(LOG_NOTICE,"match char tree after exten removal:\n");
3642 log_match_char_tree(con->pattern_tree, " ");
3643 }
3644#endif
3645
3646 /* scan the extension list to find first matching extension-registrar */
3647 for (exten = con->root; exten; prev_exten = exten, exten = exten->next) {
3648 if (!strcmp(exten->exten, ex.exten) &&
3649 (!matchcallerid ||
3650 (!ast_strlen_zero(ex.cidmatch) && !ast_strlen_zero(exten->cidmatch) && !strcmp(exten->cidmatch, ex.cidmatch)) ||
3651 (ast_strlen_zero(ex.cidmatch) && ast_strlen_zero(exten->cidmatch)))) {
3652 break;
3653 }
3654 }
3655 if (!exten) {
3656 /* we can't find right extension */
3657 if (!already_locked)
3658 ast_unlock_context(con);
3659 return -1;
3660 }
3661
3662 /* scan the priority list to remove extension with exten->priority == priority */
3663 for (peer = exten, next_peer = exten->peer ? exten->peer : exten->next;
3664 peer && !strcmp(peer->exten, ex.exten) &&
3665 (!callerid || (!matchcallerid && !peer->matchcid) || (matchcallerid && peer->matchcid && !strcmp(peer->cidmatch, ex.cidmatch))) ;
3666 peer = next_peer, next_peer = next_peer ? (next_peer->peer ? next_peer->peer : next_peer->next) : NULL) {
3667
3668 if ((priority == 0 || peer->priority == priority) &&
3669 (!registrar || !strcmp(peer->registrar, registrar) )) {
3670 found = 1;
3671
3672 /* we are first priority extension? */
3673 if (!previous_peer) {
3674 /*
3675 * We are first in the priority chain, so must update the extension chain.
3676 * The next node is either the next priority or the next extension
3677 */
3678 struct ast_exten *next_node = peer->peer ? peer->peer : peer->next;
3679 if (peer->peer) {
3680 /* move the peer_table and peer_label_table down to the next peer, if
3681 it is there */
3684 peer->peer_table = NULL;
3686 }
3687 if (!prev_exten) { /* change the root... */
3688 con->root = next_node;
3689 } else {
3690 prev_exten->next = next_node; /* unlink */
3691 }
3692 if (peer->peer) { /* update the new head of the pri list */
3693 peer->peer->next = peer->next;
3694 }
3695 } else { /* easy, we are not first priority in extension */
3696 previous_peer->peer = peer->peer;
3697 }
3698
3699
3700 /* now, free whole priority extension */
3702 } else {
3703 previous_peer = peer;
3704 }
3705 }
3706 if (!already_locked)
3707 ast_unlock_context(con);
3708 return found ? 0 : -1;
3709}
void * ast_hashtab_remove_this_object(struct ast_hashtab *tab, void *obj)
Hash the object and then compare ptrs in bucket list instead of calling the compare routine,...
Definition hashtab.c:789
int ast_hashtab_size(struct ast_hashtab *tab)
Returns the number of elements stored in the hashtab.
Definition hashtab.c:577
#define LOG_NOTICE
int ast_wrlock_context(struct ast_context *con)
Write locks a given context.
Definition pbx.c:6639
static unsigned int ext_strncpy(char *dst, const char *src, size_t dst_size, int nofluff)
Definition pbx.c:5308
int ast_unlock_context(struct ast_context *con)
Definition pbx.c:6649
static struct match_char * add_exten_to_pattern_tree(struct ast_context *con, struct ast_exten *e1, int findonly)
Definition pbx.c:1289
static void destroy_exten(struct ast_exten *e)
Definition pbx.c:3234
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
struct match_char * pattern_tree
Definition pbx.c:261
ast_exten: An extension The dialplan is saved as a linked list with each context having it's own link...
Definition pbx.c:207
char * exten
Definition pbx.c:208
struct ast_hashtab * peer_label_table
Definition pbx.c:222
struct ast_hashtab * peer_table
Definition pbx.c:221
char * name
Definition pbx.c:209
const char * registrar
Definition pbx.c:223
const char * cidmatch
Definition pbx.c:211
struct ast_exten * peer
Definition pbx.c:220
struct ast_exten * next
Definition pbx.c:226
int priority
Definition pbx.c:213
const char * label
Definition pbx.c:214
int matchcid
Definition pbx.c:210
match_char: forms a syntax tree for quick matching of extension patterns
Definition pbx.c:232
char x[1]
Definition pbx.c:239
struct ast_exten * exten
Definition pbx.c:238

References add_exten_to_pattern_tree(), ast_debug, 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, destroy_exten(), ext_strncpy(), ast_exten::exten, match_char::exten, ast_exten::label, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_exten::matchcid, ast_exten::name, ast_context::name, ast_exten::next, NULL, ast_context::pattern_tree, ast_exten::peer, ast_exten::peer_label_table, ast_exten::peer_table, priority, ast_exten::priority, registrar, 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().

◆ ast_context_remove_ignorepat()

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

Remove an ignorepat.

Parameters
contextcontext from which to remove the pattern
ignorepatthe pattern to remove
registrarthe registrar of the ignore pattern

This removes the given ignorepattern

Return values
0on success
-1on failure

Definition at line 5093 of file pbx.c.

5094{
5095 int ret = -1;
5096 struct ast_context *c;
5097
5098 c = find_context_locked(context);
5099 if (c) {
5100 ret = ast_context_remove_ignorepat2(c, ignorepat, registrar);
5102 }
5103 return ret;
5104}
int ast_context_remove_ignorepat2(struct ast_context *con, const char *ignorepat, const char *registrar)
Definition pbx.c:5106

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

Referenced by handle_cli_dialplan_remove_ignorepat().

◆ ast_context_remove_ignorepat2()

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

Definition at line 5106 of file pbx.c.

5107{
5108 int idx;
5109
5110 ast_wrlock_context(con);
5111
5112 for (idx = 0; idx < ast_context_ignorepats_count(con); idx++) {
5113 struct ast_ignorepat *ip = AST_VECTOR_GET(&con->ignorepats, idx);
5114
5115 if (!strcmp(ast_get_ignorepat_name(ip), ignorepat) &&
5118 ignorepat_free(ip);
5119 ast_unlock_context(con);
5120 return 0;
5121 }
5122 }
5123
5124 ast_unlock_context(con);
5125 errno = EINVAL;
5126 return -1;
5127}
int errno
int ast_context_ignorepats_count(const struct ast_context *con)
Definition pbx.c:6880
const char * ast_get_ignorepat_registrar(const struct ast_ignorepat *ip)
const char * ast_get_ignorepat_name(const struct ast_ignorepat *ip)
void ignorepat_free(struct ast_ignorepat *ip)
ast_ignorepat: Ignore patterns in dial plan
#define AST_VECTOR_REMOVE_ORDERED(vec, idx)
Remove an element from a vector by index while maintaining order.
Definition vector.h:459

References ast_context_ignorepats_count(), ast_get_ignorepat_name(), ast_get_ignorepat_registrar(), ast_unlock_context(), AST_VECTOR_GET, AST_VECTOR_REMOVE_ORDERED, ast_wrlock_context(), errno, ignorepat_free(), ast_context::ignorepats, and registrar.

Referenced by ast_context_remove_ignorepat().

◆ ast_context_remove_include()

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

Remove a context include.

Definition at line 3396 of file pbx.c.

3397{
3398 int ret = -1;
3399 struct ast_context *c;
3400
3401 c = find_context_locked(context);
3402 if (c) {
3403 /* found, remove include from this context ... */
3404 ret = ast_context_remove_include2(c, include, registrar);
3406 }
3407 return ret;
3408}
int ast_context_remove_include2(struct ast_context *con, const char *include, const char *registrar)
Locks context, remove included contexts, unlocks context. When we call this function,...
Definition pbx.c:3419

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

Referenced by handle_cli_dialplan_remove_include().

◆ ast_context_remove_include2()

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_include for information on arguments

Removes an include by an ast_context structure.

Return values
0on success.
-1on failure.

Definition at line 3419 of file pbx.c.

3420{
3421 int ret = -1;
3422 int idx;
3423
3424 ast_wrlock_context(con);
3425
3426 /* find our include */
3427 for (idx = 0; idx < ast_context_includes_count(con); idx++) {
3428 struct ast_include *i = AST_VECTOR_GET(&con->includes, idx);
3429
3430 if (!strcmp(ast_get_include_name(i), include) &&
3431 (!registrar || !strcmp(ast_get_include_registrar(i), registrar))) {
3432
3433 /* remove from list */
3434 ast_verb(3, "Removing inclusion of context '%s' in context '%s; registrar=%s'\n", include, ast_get_context_name(con), registrar);
3436
3437 /* free include and return */
3438 include_free(i);
3439 ret = 0;
3440 break;
3441 }
3442 }
3443
3444 ast_unlock_context(con);
3445
3446 return ret;
3447}
const char * ast_get_context_name(struct ast_context *con)
Definition pbx.c:6657
int ast_context_includes_count(const struct ast_context *con)
Definition pbx.c:6837
const char * ast_get_include_name(const struct ast_include *include)
Definition pbx_include.c:50
const char * ast_get_include_registrar(const struct ast_include *i)
Definition pbx_include.c:60
void include_free(struct ast_include *inc)
ast_include: include= support in extensions.conf
Definition pbx_include.c:37

References ast_context_includes_count(), ast_get_context_name(), ast_get_include_name(), ast_get_include_registrar(), ast_unlock_context(), AST_VECTOR_GET, AST_VECTOR_REMOVE_ORDERED, ast_verb, ast_wrlock_context(), include_free(), ast_context::includes, and registrar.

Referenced by ast_context_remove_include().

◆ ast_context_remove_switch()

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
0on success
-1on failure
Note
This function locks contexts list by &conlist, search for the right context structure, leave context list locked and call ast_context_remove_switch2 which removes switch, unlock contexts list and return ...

Definition at line 3454 of file pbx.c.

3455{
3456 int ret = -1; /* default error return */
3457 struct ast_context *c;
3458
3459 c = find_context_locked(context);
3460 if (c) {
3461 /* remove switch from this context ... */
3464 }
3465 return ret;
3466}
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.
Definition pbx.c:3476

References ast_context_remove_switch2(), ast_unlock_contexts(), c, ast_context::data, find_context_locked(), and registrar.

◆ ast_context_remove_switch2()

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 3476 of file pbx.c.

3477{
3478 int idx;
3479 int ret = -1;
3480
3481 ast_wrlock_context(con);
3482
3483 /* walk switches */
3484 for (idx = 0; idx < ast_context_switches_count(con); idx++) {
3485 struct ast_sw *i = AST_VECTOR_GET(&con->alts, idx);
3486
3487 if (!strcmp(ast_get_switch_name(i), sw) &&
3488 !strcmp(ast_get_switch_data(i), data) &&
3489 (!registrar || !strcmp(ast_get_switch_registrar(i), registrar))) {
3490
3491 /* found, remove from list */
3492 ast_verb(3, "Removing switch '%s' from context '%s; registrar=%s'\n", sw, ast_get_context_name(con), registrar);
3493 AST_VECTOR_REMOVE_ORDERED(&con->alts, idx);
3494
3495 /* free switch and return */
3496 sw_free(i);
3497 ret = 0;
3498 break;
3499 }
3500 }
3501
3502 ast_unlock_context(con);
3503
3504 return ret;
3505}
int ast_context_switches_count(const struct ast_context *con)
Definition pbx.c:6792
const char * ast_get_switch_name(const struct ast_sw *sw)
Definition pbx_sw.c:48
const char * ast_get_switch_data(const struct ast_sw *sw)
Definition pbx_sw.c:53
const char * ast_get_switch_registrar(const struct ast_sw *sw)
Definition pbx_sw.c:63
void sw_free(struct ast_sw *sw)
Definition pbx_sw.c:101
ast_sw: Switch statement in extensions.conf
Definition pbx_sw.c:37
const char * data
Definition pbx_sw.c:42

References ast_context::alts, ast_context_switches_count(), ast_get_context_name(), ast_get_switch_data(), ast_get_switch_name(), ast_get_switch_registrar(), ast_unlock_context(), AST_VECTOR_GET, AST_VECTOR_REMOVE_ORDERED, ast_verb, ast_wrlock_context(), ast_sw::data, registrar, and sw_free().

Referenced by ast_context_remove_switch().

◆ ast_context_set_autohints()

void ast_context_set_autohints ( struct ast_context con,
int  enabled 
)

Enable or disable autohints support on a context.

Parameters
conpointer to the context
enabledwhether autohints are enabled

Definition at line 4626 of file pbx.c.

4627{
4628 con->autohints = enabled;
4629
4630 if (con->scope == AST_CONTEXT_SCOPE_GLOBAL) {
4631 if (con->autohints) {
4633 } else {
4635 }
4636 }
4637}
static int enabled
Definition dnsmgr.c:91
void pbx_extension_state_autohint_set(struct ast_context *context)
void pbx_extension_state_autohint_remove(struct ast_context *context, unsigned int forced)
int autohints
Definition pbx.c:268

References AST_CONTEXT_SCOPE_GLOBAL, ast_context::autohints, enabled, pbx_extension_state_autohint_remove(), pbx_extension_state_autohint_set(), and ast_context::scope.

Referenced by pbx_load_config().

◆ ast_context_switches_count()

int ast_context_switches_count ( const struct ast_context con)

◆ ast_context_switches_get()

const struct ast_sw * ast_context_switches_get ( const struct ast_context con,
int  idx 
)

◆ ast_context_verify_includes()

int ast_context_verify_includes ( struct ast_context con)

Verifies includes in an ast_contect structure.

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

Definition at line 6890 of file pbx.c.

6891{
6892 int idx;
6893 int res = 0;
6894 int includecount = ast_context_includes_count(con);
6895
6896 if (includecount >= AST_PBX_MAX_STACK) {
6897 ast_log(LOG_WARNING, "Context %s contains too many includes (%d). Maximum is %d.\n",
6898 ast_get_context_name(con), includecount, AST_PBX_MAX_STACK);
6899 }
6900
6901 for (idx = 0; idx < includecount; idx++) {
6902 const struct ast_include *inc = ast_context_includes_get(con, idx);
6903
6904 if (ast_context_find(include_rname(inc))) {
6905 continue;
6906 }
6907
6908 res = -1;
6909 ast_log(LOG_WARNING, "Context '%s' tries to include nonexistent context '%s'\n",
6911 break;
6912 }
6913
6914 return res;
6915}
#define AST_PBX_MAX_STACK
Definition extconf.h:225
const struct ast_include * ast_context_includes_get(const struct ast_context *con, int idx)
Definition pbx.c:6842
const char * include_rname(const struct ast_include *inc)
Definition pbx_include.c:55

References ast_context_find(), ast_context_includes_count(), ast_context_includes_get(), ast_get_context_name(), ast_log, AST_PBX_MAX_STACK, include_rname(), and LOG_WARNING.

◆ ast_custom_function_find()

struct ast_custom_function * ast_custom_function_find ( const char *  name)

◆ ast_custom_function_unregister()

int ast_custom_function_unregister ( struct ast_custom_function acf)

Unregister a custom function.

Definition at line 268 of file pbx_functions.c.

269{
270 struct ast_custom_function *cur;
271
272 if (!acf) {
273 return -1;
274 }
275
277 cur = AST_RWLIST_REMOVE(&acf_root, acf, acflist);
278 if (cur) {
279#ifdef AST_XML_DOCS
280 if (cur->docsrc == AST_XML_DOC) {
282 }
283#endif
284 ast_verb(5, "Unregistered custom function %s\n", cur->name);
285 }
287
288 return cur ? 0 : -1;
289}
#define AST_RWLIST_REMOVE
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
@ AST_XML_DOC
Definition xmldoc.h:31

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(), close_logger(), geoloc_dialplan_unload(), load_module(), load_module(), manager_shutdown(), message_shutdown(), reload(), unload_features_config(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_module(), unload_parking_bridge_features(), and unload_pbx().

◆ ast_destroy_timing()

int ast_destroy_timing ( struct ast_timing i)

Deallocates memory structures associated with a timing bitmap.

Parameters
iPointer to an ast_timing structure.
Return values
0success
non-zerofailure (number suitable to pass to
See also
strerror)

Definition at line 279 of file pbx_timing.c.

280{
281 if (i->timezone) {
282 ast_free(i->timezone);
283 i->timezone = NULL;
284 }
285 return 0;
286}
#define ast_free(a)
Definition astmm.h:180

References ast_free, NULL, and ast_timing::timezone.

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

◆ ast_devstate_to_extenstate()

enum ast_extension_states ast_devstate_to_extenstate ( enum ast_device_state  devstate)

Map devstate to an extension state.

Parameters
[in]devstatedevice state
Returns
the extension state mapping.

Definition at line 1136 of file extension_state.c.

1137{
1138 switch (devstate) {
1139 case AST_DEVICE_ONHOLD:
1140 return AST_EXTENSION_ONHOLD;
1141 case AST_DEVICE_BUSY:
1142 return AST_EXTENSION_BUSY;
1143 case AST_DEVICE_UNKNOWN:
1146 case AST_DEVICE_INVALID:
1150 case AST_DEVICE_RINGING:
1151 return AST_EXTENSION_RINGING;
1152 case AST_DEVICE_INUSE:
1153 return AST_EXTENSION_INUSE;
1156 case AST_DEVICE_TOTAL: /* not a device state, included for completeness */
1157 break;
1158 }
1159
1161}
@ AST_DEVICE_RINGINUSE
Definition devicestate.h:60
@ AST_DEVICE_INUSE
Definition devicestate.h:55
@ AST_DEVICE_UNKNOWN
Definition devicestate.h:53
@ AST_DEVICE_ONHOLD
Definition devicestate.h:61
@ AST_DEVICE_RINGING
Definition devicestate.h:59
@ AST_DEVICE_INVALID
Definition devicestate.h:57
@ AST_DEVICE_BUSY
Definition devicestate.h:56
@ AST_DEVICE_NOT_INUSE
Definition devicestate.h:54
@ AST_DEVICE_TOTAL
Definition devicestate.h:62
@ AST_DEVICE_UNAVAILABLE
Definition devicestate.h:58

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_TEST_DEFINE(), extension_state_device_state_cb(), and extension_state_update_sources().

◆ ast_exists_extension()

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
cthis is not important
contextwhich context to look in
extenwhich extension to search for
prioritypriority of the action within the extension
calleridcallerid 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.

Definition at line 2735 of file pbx.c.

2736{
2737 return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCH, 0, 0);
2738}
@ E_MATCH
Definition extconf.h:217

References c, E_MATCH, ast_exten::exten, NULL, pbx_extension_helper(), and priority.

Referenced by __analog_ss_thread(), __ast_goto_if_exists(), __ast_pbx_run(), action_originate(), add_to_regcontext(), analog_ss_thread(), ast_app_dtget(), ast_bridge_setup_after_goto(), ast_pbx_outgoing_exten_predial(), ast_sip_persistent_endpoint_update_state(), chan_pjsip_cng_tone_detected(), cli_console_dial(), comeback_goto(), conf_run(), dahdi_handle_dtmf(), dial_exec_full(), dialplan_has_destination_cb(), disa_exec(), dp_lookup(), dundi_lookup_local(), fax_detect_framehook(), findmeexec(), get_destination(), gosub_exec(), grab_transfer(), handle_gosub(), isexten_function_read(), jingle_new(), join_conference_bridge(), key_dial_page(), leave_voicemail(), local_call(), local_devicestate(), loopback_exists(), minivm_greet_exec(), my_handle_dtmf(), new_subscribe(), onModeChanged(), ooh323_rtp_read(), options_on_rx_request(), pbx_builtin_waitexten(), privacy_exec(), readexten_exec(), refer_incoming_attended_request(), refer_incoming_blind_request(), register_peer_exten(), show_debug_helper(), socket_process_helper(), try_calling(), vm_authenticate(), and waitstream_core().

◆ ast_explicit_goto()

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.
If the AST_SOFTHANGUP_ASYNCGOTO flag is set on the channel, this function will fail and return -1.

Definition at line 5223 of file pbx.c.

5224{
5225 if (!chan)
5226 return -1;
5227
5228 ast_channel_lock(chan);
5229
5231 ast_channel_unlock(chan);
5232 return -1;
5233 }
5234 if (!ast_strlen_zero(context))
5235 ast_channel_context_set(chan, context);
5236 if (!ast_strlen_zero(exten))
5237 ast_channel_exten_set(chan, exten);
5238 if (priority > -1) {
5239 /* see flag description in channel.h for explanation */
5241 --priority;
5242 }
5244 }
5245
5246 ast_channel_unlock(chan);
5247
5248 return 0;
5249}
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
void ast_channel_context_set(struct ast_channel *chan, const char *value)
int ast_channel_softhangup_internal_flag(struct ast_channel *chan)
void ast_channel_priority_set(struct ast_channel *chan, int value)

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

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

◆ ast_extension_close()

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

Definition at line 2058 of file pbx.c.

2059{
2060 if (needmore != E_MATCHMORE && needmore != E_CANMATCH)
2061 ast_log(LOG_WARNING, "invalid argument %d\n", needmore);
2062 return extension_match_core(pattern, data, needmore);
2063}
@ E_MATCHMORE
Definition extconf.h:215
static int extension_match_core(const char *pattern, const char *data, enum ext_match_t mode)
Definition pbx.c:2040

References ast_log, ast_exten::data, E_CANMATCH, E_MATCHMORE, extension_match_core(), and LOG_WARNING.

Referenced by lua_find_extension(), and realtime_switch_common().

◆ ast_extension_cmp()

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

Determine if one extension should match before another.

Parameters
aextension to compare with b
bextension to compare with a

Checks whether or extension a should match before extension b

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

Definition at line 1823 of file pbx.c.

1824{
1825 int cmp;
1826
1827 cmp = ext_cmp(a, b);
1828 if (cmp < 0) {
1829 return -1;
1830 }
1831 if (cmp > 0) {
1832 return 1;
1833 }
1834 return 0;
1835}
static int ext_cmp(const char *left, const char *right)
Definition pbx.c:1766
static struct test_val b
static struct test_val a

References a, b, and ext_cmp().

Referenced by lua_extension_cmp().

◆ ast_extension_match()

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

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

Parameters
patternpattern to match
extensionextension to check against the pattern.

Checks whether or not the given extension matches the given pattern.

Return values
1on match
0on failure

Definition at line 4293 of file extconf.c.

4294{
4295 return extension_match_core(pattern, data, E_MATCH);
4296}
static int extension_match_core(const char *pattern, const char *data, enum ext_match_t mode)
Definition extconf.c:4284

References ast_context::data, E_MATCH, extension_match_core(), and extension_match_core().

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

◆ ast_extension_patmatch()

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

◆ ast_extension_state()

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
cthis is not important
contextwhich context to look in
extenwhich extension to get state
Returns
extension state as defined in the ast_extension_states enum

Definition at line 55 of file extension_state_legacy.c.

56{
57 struct ast_extension_state_device_snapshot *device_snapshot;
58 enum ast_extension_states device_state;
59
60 device_snapshot = ast_extension_state_get_latest_device_snapshot(c, exten, context);
61 if (!device_snapshot) {
62 return -1;
63 }
64
65 device_state = device_snapshot->state;
66 ao2_ref(device_snapshot, -1);
67
68 return device_state;
69}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition astobj2.h:459
struct ast_extension_state_device_snapshot * ast_extension_state_get_latest_device_snapshot(struct ast_channel *chan, const char *exten, const char *context)
Get the latest device state message for an extension.
ast_extension_states
Extension states.
Definition pbx.h:61
Device snapshot for an extension state.
enum ast_extension_states state
The state of the extension.

References ao2_ref, ast_extension_state_get_latest_device_snapshot(), c, and ast_extension_state_device_snapshot::state.

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

◆ ast_extension_state2str()

const char * ast_extension_state2str ( int  extension_state)

Return string representation of the state of an extension.

Parameters
extension_stateis the numerical state delivered by ast_extension_state
Returns
the state of an extension as string

Definition at line 1163 of file extension_state.c.

1164{
1165 int i;
1166
1167 for (i = 0; (i < ARRAY_LEN(extension_state_mappings)); i++) {
1170 }
1171 return "Unknown";
1172}
static const struct cfextension_states extension_state_mappings[]
const char *const text
Extension state information.
#define ARRAY_LEN(a)
Definition utils.h:706

References ARRAY_LEN, extension_state_mappings, and cfextension_states::text.

Referenced by action_extensionstate(), action_extensionstatelist(), AST_TEST_DEFINE(), exten_state_publisher_state_cb(), handle_show_hint(), handle_show_hints(), manager_state_cb(), and to_ami().

◆ ast_extension_state_add()

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

Add watcher for extension states.

Parameters
contextwhich context to look in
extenwhich extension to get state
change_cbcallback to call if state changed
datato pass to callback
Note
If context and exten are NULL then the added watcher is global. The change_cb is called for every extension's state change.
The change_cb is called if the state of an extension is changed.
Return values
-1on failure
0Global watcher added successfully
IDon success

Definition at line 375 of file extension_state_legacy.c.

377{
378 return extension_state_legacy_add_destroy(context, exten, change_cb, NULL, data, 0);
379}
static int extension_state_legacy_add_destroy(const char *context, const char *exten, ast_state_cb_type change_cb, ast_state_cb_destroy_type destroy_cb, void *data, int extended)

References extension_state_legacy_add_destroy(), and NULL.

Referenced by __init_manager(), create_queue_member(), and publisher_start().

◆ ast_extension_state_add_destroy()

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 
)

Add watcher for extension states with destructor.

Since
1.8.9
10.1.0
Parameters
contextwhich context to look in
extenwhich extension to get state
change_cbcallback to call if state changed
destroy_cbcallback to call when the watcher is destroyed.
datato pass to callbacks
Note
If context and exten are NULL then the added watcher is global. The change_cb is called for every extension's state change.
The change_cb is called if the state of an extension is changed.
The destroy_cb is called when the watcher is deleted so the watcher can release any associated resources.
Return values
-1on failure
0Global watcher added successfully
IDon success

Definition at line 369 of file extension_state_legacy.c.

371{
372 return extension_state_legacy_add_destroy(context, exten, change_cb, destroy_cb, data, 0);
373}

References extension_state_legacy_add_destroy().

◆ ast_extension_state_add_destroy_extended()

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 
)

Add watcher for extended extension states with destructor.

Since
11
Parameters
contextwhich context to look in
extenwhich extension to get state
change_cbcallback to call if state changed
destroy_cbcallback to call when the watcher is destroyed.
datato pass to callbacks
Note
If context and exten are NULL then the added watcher is global. The change_cb is called for every extension's state change.
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 watcher is deleted so the watcher can release any associated resources.
Return values
-1on failure
0Global watcher added successfully
IDon success

Definition at line 381 of file extension_state_legacy.c.

383{
384 return extension_state_legacy_add_destroy(context, exten, change_cb, destroy_cb, data, 1);
385}

References extension_state_legacy_add_destroy().

Referenced by subscription_established().

◆ ast_extension_state_add_extended()

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

Add watcher for extended extension states.

Since
11
Parameters
contextwhich context to look in
extenwhich extension to get state
change_cbcallback to call if state changed
datato pass to callback
Note
If context and exten are NULL then the added watcher is global. The change_cb is called for every extension's state change.
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
-1on failure
0Global watcher added successfully
IDon success

Definition at line 387 of file extension_state_legacy.c.

389{
390 return extension_state_legacy_add_destroy(context, exten, change_cb, NULL, data, 1);
391}

References extension_state_legacy_add_destroy(), and NULL.

◆ ast_extension_state_del()

int ast_extension_state_del ( int  id,
ast_state_cb_type  change_cb 
)

Deletes a state change watcher by ID.

Parameters
idof the state watcher to delete (0 for global watcher)
change_cbcallback to call if state changed (Used if id == 0 (global))
Return values
0success
-1failure

Definition at line 393 of file extension_state_legacy.c.

394{
396
397 /* A negative id is considered invalid */
398 if (id < 0) {
399 return -1;
400 }
401
402 if (!id) { /* id == 0 is a callback without extension */
403 if (!change_cb) {
404 return -1;
405 }
406
407 /*
408 * Global callbacks all have the ID of 0 so we need to find the actual index
409 * for them in the vector for removal based on callback.
410 */
412 for (id = 0; id < AST_VECTOR_SIZE(&extension_state_legacy_callbacks); id++) {
414 if (cb && cb->change_cb == change_cb) {
418 ao2_ref(cb, -1);
419 return 0;
420 }
421 }
423
424 return -1;
425 }
426
430 if (cb) {
434 ao2_ref(cb, -1);
435 return 0;
436 }
437 }
439
440 return -1;
441}
static struct @377 extension_state_legacy_callbacks
Legacy callbacks, the index of it in the vector is the id given to the API user for per-extension.
static ast_mutex_t extension_state_legacy_callbacks_lock
Lock to protect the callbacks vector.
#define ast_mutex_unlock(a)
Definition lock.h:197
#define ast_mutex_lock(a)
Definition lock.h:196
void stasis_message_router_unsubscribe(struct stasis_message_router *router)
Unsubscribe the router from the upstream topic.
struct stasis_message_router * router
#define AST_VECTOR_REPLACE(vec, idx, elem)
Replace an element at a specific position in a vector, growing the vector if needed.
Definition vector.h:295

References ao2_ref, ast_mutex_lock, ast_mutex_unlock, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, extension_state_legacy_state_cb::change_cb, extension_state_legacy_callbacks, extension_state_legacy_callbacks_lock, NULL, extension_state_legacy_state_cb::router, and stasis_message_router_unsubscribe().

Referenced by destroy_queue_member_cb(), subscription_shutdown(), and unload_module().

◆ ast_extension_state_extended()

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
cthis is not important
contextwhich context to look in
extenwhich extension to get state
[out]device_state_infoptr 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 143 of file extension_state_legacy.c.

145{
146 struct ast_extension_state_device_snapshot *device_snapshot;
147 enum ast_extension_states device_state;
148
149 device_snapshot = ast_extension_state_get_latest_device_snapshot(c, exten, context);
150 if (!device_snapshot) {
151 return -1;
152 }
153
154 device_state = device_snapshot->state;
155
156 /* The caller wants device state info, so allocate a container and populate it */
157 if (device_state_info) {
158 *device_state_info = extension_state_legacy_create_device_state_info(device_snapshot);
159 }
160
161 ao2_ref(device_snapshot, -1);
162
163 return device_state;
164}
static struct ao2_container * extension_state_legacy_create_device_state_info(struct ast_extension_state_device_snapshot *device_snapshot)

References ao2_ref, ast_extension_state_get_latest_device_snapshot(), c, extension_state_legacy_create_device_state_info(), and ast_extension_state_device_snapshot::state.

Referenced by exten_state_data_alloc().

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

Parameters
cthis is not important
contextwhich context to look in
extenwhich extension to search for
labellabel of the action within the extension to match to priority
calleridcallerid 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
thepriority which matches the given label in the extension
-1if not found.

Definition at line 2740 of file pbx.c.

2741{
2742 return pbx_extension_helper(c, NULL, context, exten, 0, label, callerid, E_FINDLABEL, 0, 0);
2743}
@ E_FINDLABEL
Definition extconf.h:220

References c, E_FINDLABEL, ast_exten::exten, ast_exten::label, 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_parse_location().

◆ ast_findlabel_extension2()

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 4973 of file extconf.c.

4974{
4975 return pbx_extension_helper(c, con, NULL, exten, 0, label, callerid, E_FINDLABEL);
4976}
static int pbx_extension_helper(struct ast_channel *c, struct ast_context *con, const char *context, const char *exten, int priority, const char *label, const char *callerid, enum ext_match_t action)
The return value depends on the action:
Definition extconf.c:4912

References c, E_FINDLABEL, ast_exten::exten, ast_exten::label, NULL, pbx_extension_helper(), and pbx_extension_helper().

Referenced by pbx_load_config().

◆ ast_func_read()

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

executes a read operation on a function

Parameters
chanChannel to execute on
functionData containing the function call string (will be modified)
workspaceA pointer to safe memory to use for a return value
lenthe number of bytes in workspace

This application executes a function in read mode on a given channel.

Return values
0success
non-zerofailure

Definition at line 614 of file pbx_functions.c.

615{
616 char *copy = ast_strdupa(function);
617 char *args = func_args(copy);
619 int res;
620 struct ast_module_user *u = NULL;
621 /*
622 * The module pointer needs to be saved because some modules, notably func_odbc,
623 * dynamically create and destroy functions so the acfptr might not be valid
624 * when the read callback returns.
625 *
626 * NEVER ASSUME THE acfptr IS STILL VALID AFTER THE CALLBACK RETURNS!
627 */
628 struct ast_module *mod = acfptr ? acfptr->mod : NULL;
629
630 if (acfptr == NULL) {
631 ast_log(LOG_ERROR, "Function %s not registered\n", copy);
632 } else if (!acfptr->read && !acfptr->read2) {
633 ast_log(LOG_ERROR, "Function %s cannot be read\n", copy);
634 } else if (!is_read_allowed(acfptr)) {
635 ast_log(LOG_ERROR, "Dangerous function %s read blocked\n", copy);
636 } else if (acfptr->read) {
637 if (mod) {
638 u = __ast_module_user_add(mod, chan);
639 }
640 res = acfptr->read(chan, copy, args, workspace, len);
641 if (mod && u) {
643 }
644
645 return res;
646 } else {
647 struct ast_str *str = ast_str_create(16);
648
649 if (mod) {
650 u = __ast_module_user_add(mod, chan);
651 }
652 res = acfptr->read2(chan, copy, args, &str, 0);
653 if (mod && u) {
655 }
657 ast_free(str);
658
659 return res;
660 }
661
662 return -1;
663}
const char * str
Definition app_jack.c:150
static int copy(char *infile, char *outfile)
Utility function to copy a file.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
struct ast_module_user * __ast_module_user_add(struct ast_module *, struct ast_channel *)
Definition loader.c:809
void __ast_module_user_remove(struct ast_module *, struct ast_module_user *)
Definition loader.c:835
static int is_read_allowed(struct ast_custom_function *acfptr)
Determines whether execution of a custom function's read function is allowed.
struct ast_custom_function * ast_custom_function_find(const char *name)
static char * func_args(char *function)
return a pointer to the arguments of the function, and terminates the function name with '\0'
static struct @522 args
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition strings.h:659
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition strings.h:425
size_t attribute_pure ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition strings.h:742
ast_acf_read_fn_t read
Definition pbx.h:129
ast_acf_read2_fn_t read2
Definition pbx.h:137
Support for dynamic strings.
Definition strings.h:623

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(), len(), LOG_ERROR, ast_custom_function::mod, NULL, ast_custom_function::read, ast_custom_function::read2, and str.

Referenced by action_getvar(), assign_uuid(), fetch_access_token(), fetch_google_access_token(), generate_status(), handle_eval_function(), handle_getvariable(), lua_get_variable_value(), and pbx_substitute_variables_helper_full_location().

◆ ast_func_read2()

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
chanChannel to execute on
functionData containing the function call string (will be modified)
strA 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
0success
non-zerofailure

Definition at line 665 of file pbx_functions.c.

666{
667 char *copy = ast_strdupa(function);
668 char *args = func_args(copy);
670 int res;
671 struct ast_module_user *u = NULL;
672 /*
673 * The module pointer needs to be saved because some modules, notably func_odbc,
674 * dynamically create and destroy functions so the acfptr might not be valid
675 * when the read callback returns.
676 *
677 * NEVER ASSUME THE acfptr IS STILL VALID AFTER THE CALLBACK RETURNS!
678 */
679 struct ast_module *mod = acfptr ? acfptr->mod : NULL;
680
681 if (acfptr == NULL) {
682 ast_log(LOG_ERROR, "Function %s not registered\n", copy);
683 } else if (!acfptr->read && !acfptr->read2) {
684 ast_log(LOG_ERROR, "Function %s cannot be read\n", copy);
685 } else if (!is_read_allowed(acfptr)) {
686 ast_log(LOG_ERROR, "Dangerous function %s read blocked\n", copy);
687 } else {
688 if (mod) {
689 u = __ast_module_user_add(mod, chan);
690 }
692 if (acfptr->read2) {
693 /* ast_str enabled */
694 res = acfptr->read2(chan, copy, args, str, maxlen);
695 } else {
696 /* Legacy function pointer, allocate buffer for result */
697 int maxsize = ast_str_size(*str);
698
699 if (maxlen > -1) {
700 if (maxlen == 0) {
701 if (acfptr->read_max) {
702 maxsize = acfptr->read_max;
703 } else {
705 }
706 } else {
707 maxsize = maxlen;
708 }
710 }
711 res = acfptr->read(chan, copy, args, ast_str_buffer(*str), maxsize);
712 ast_str_update(*str); /* Manually set the string length */
713 }
714 if (mod && u) {
716 }
717
718 return res;
719 }
720
721 return -1;
722}
static int maxsize
#define VAR_BUF_SIZE
Definition pbx_private.h:76
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
Definition strings.h:693
#define ast_str_make_space(buf, new_len)
Definition strings.h:828
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
Definition strings.h:703
size_t read_max
Definition pbx.h:139

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_str_update(), 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, str, and VAR_BUF_SIZE.

Referenced by ast_ari_bridges_get_bridge_vars(), ast_ari_channels_get_channel_var(), ast_ari_channels_get_channel_vars(), ast_channel_get_ari_vars(), ast_str_substitute_variables_full2(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), and channel_get_external_vars().

◆ ast_func_write()

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

executes a write operation on a function

Parameters
chanChannel to execute on
functionData containing the function call string (will be modified)
valueA value parameter to pass for writing

This application executes a function in write mode on a given channel.

Return values
0success
non-zerofailure

Definition at line 724 of file pbx_functions.c.

725{
726 char *copy = ast_strdupa(function);
727 char *args = func_args(copy);
729 /*
730 * The module pointer needs to be saved because some modules, notably func_odbc,
731 * dynamically create and destroy functions so the acfptr might not be valid
732 * when the write callback returns.
733 *
734 * NEVER ASSUME THE acfptr IS STILL VALID AFTER THE CALLBACK RETURNS!
735 */
736 struct ast_module *mod = acfptr ? acfptr->mod : NULL;
737
738 if (acfptr == NULL) {
739 ast_log(LOG_ERROR, "Function %s not registered\n", copy);
740 } else if (!acfptr->write) {
741 ast_log(LOG_ERROR, "Function %s cannot be written to\n", copy);
742 } else if (!is_write_allowed(acfptr)) {
743 ast_log(LOG_ERROR, "Dangerous function %s write blocked\n", copy);
744 } else {
745 int res;
746 struct ast_module_user *u = NULL;
747
748 if (mod) {
749 u = __ast_module_user_add(mod, chan);
750 }
751 res = acfptr->write(chan, copy, args, value);
752 if (mod && u) {
754 }
755
756 return res;
757 }
758
759 return -1;
760}
static int is_write_allowed(struct ast_custom_function *acfptr)
Determines whether execution of a custom function's write function is allowed.
ast_acf_write_fn_t write
Definition pbx.h:141
struct ast_channel * chan
Definition loader.c:137

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

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

◆ ast_get_context_name()

static const char * ast_get_context_name ( struct ast_context con)

◆ ast_get_context_registrar()

const char * ast_get_context_registrar ( struct ast_context c)

Definition at line 6685 of file pbx.c.

6686{
6687 return c ? c->registrar : NULL;
6688}

References c, and NULL.

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

◆ ast_get_extension_app()

const char * ast_get_extension_app ( struct ast_exten e)

◆ ast_get_extension_app_data()

void * ast_get_extension_app_data ( struct ast_exten e)

◆ ast_get_extension_cidmatch()

const char * ast_get_extension_cidmatch ( struct ast_exten e)

◆ ast_get_extension_context()

struct ast_context * ast_get_extension_context ( struct ast_exten exten)

Definition at line 6662 of file pbx.c.

6663{
6664 return exten ? exten->parent : NULL;
6665}
struct ast_context * parent
Definition pbx.c:215

References NULL, and ast_exten::parent.

Referenced by extension_is_compatible().

◆ ast_get_extension_data()

int ast_get_extension_data ( char *  buf,
int  bufsize,
struct ast_channel c,
const char *  context,
const char *  exten,
int  priority 
)

Fill a string buffer with the data at a dialplan extension.

Parameters
bufString buffer
bufsizeSize of buf
cChannel
contextDialplan context
extenDialplan extension
priorityDialplan priority
Return values
-1Failed to obtain extension data
0Successfully obtained extension data

Definition at line 6725 of file pbx.c.

6727{
6728 struct ast_exten *e;
6729 struct pbx_find_info q = { .stacklen = 0 }; /* the rest is set in pbx_find_context */
6731 e = pbx_find_extension(c, NULL, &q, context, exten, priority, NULL, "", E_MATCH);
6732 if (e) {
6733 if (buf) {
6734 const char *tmp = ast_get_extension_app_data(e);
6735 if (tmp) {
6736 ast_copy_string(buf, tmp, bufsize);
6737 }
6738 }
6740 return 0;
6741 }
6743 return -1;
6744}
char buf[BUFSIZE]
Definition eagi_proxy.c:66
void * ast_get_extension_app_data(struct ast_exten *e)
Definition pbx.c:6720
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)
Definition pbx.c:2108

References ast_copy_string(), ast_get_extension_app_data(), ast_rdlock_contexts(), ast_unlock_contexts(), buf, c, E_MATCH, NULL, pbx_find_extension(), priority, and pbx_find_info::stacklen.

Referenced by eval_exten_read().

◆ ast_get_extension_label()

const char * ast_get_extension_label ( struct ast_exten e)

Definition at line 6672 of file pbx.c.

6673{
6674 return exten ? exten->label : NULL;
6675}

References ast_exten::label, and NULL.

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

◆ ast_get_extension_matchcid()

int ast_get_extension_matchcid ( struct ast_exten e)

◆ ast_get_extension_name()

const char * ast_get_extension_name ( struct ast_exten exten)

◆ ast_get_extension_priority()

int ast_get_extension_priority ( struct ast_exten exten)

◆ ast_get_extension_registrar()

const char * ast_get_extension_registrar ( struct ast_exten e)

◆ ast_get_extension_registrar_file()

const char * ast_get_extension_registrar_file ( struct ast_exten e)

Get name of configuration file used by registrar to register this extension.

Return values
NULLif registrar did not indicate config file when registering the extension
nameof the file used to register the extension

Definition at line 6695 of file pbx.c.

6696{
6697 return e ? e->registrar_file : NULL;
6698}
const char * registrar_file
Definition pbx.c:224

References NULL, and ast_exten::registrar_file.

Referenced by show_dialplan_helper_extension_output().

◆ ast_get_extension_registrar_line()

int ast_get_extension_registrar_line ( struct ast_exten e)

Get line number of configuration file used by registrar to register this extension.

Return values
0if the line wasn't indicated when the extension was registered
positiveinteger indicating what line in the config file was responsible for registering the extension.

Definition at line 6700 of file pbx.c.

6701{
6702 return e ? e->registrar_line : 0;
6703}
int registrar_line
Definition pbx.c:225

References ast_exten::registrar_line.

Referenced by show_dialplan_helper_extension_output().

◆ ast_get_hint()

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
hintbuffer for hint
hintsizesize of hint buffer, in bytes
namebuffer for name portion of hint
namesizesize of name buffer
cChannel from which to return the hint. This is only important when the hint or name contains an expression to be expanded.
contextwhich context to look in
extenwhich 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.

If an extension hint exists, return non-zero.

Definition at line 2697 of file pbx.c.

2698{
2699 struct ast_exten *e = ast_hint_extension(c, context, exten);
2700
2701 if (e) {
2702 if (hint)
2703 ast_copy_string(hint, ast_get_extension_app(e), hintsize);
2704 if (name) {
2705 const char *tmp = ast_get_extension_app_data(e);
2706 if (tmp)
2707 ast_copy_string(name, tmp, namesize);
2708 }
2709 return -1;
2710 }
2711 return 0;
2712}
const char * ast_get_extension_app(struct ast_exten *e)
Definition pbx.c:6715
static struct ast_exten * ast_hint_extension(struct ast_channel *c, const char *context, const char *exten)
Definition pbx.c:2644

References ast_copy_string(), ast_get_extension_app(), ast_get_extension_app_data(), ast_hint_extension(), c, ast_exten::exten, and name.

Referenced by action_extensionstate(), get_cid_name(), get_resource_display_name(), hint_read(), and manager_state_cb().

◆ ast_get_ignorepat_name()

const char * ast_get_ignorepat_name ( const struct ast_ignorepat ip)

◆ ast_get_ignorepat_registrar()

const char * ast_get_ignorepat_registrar ( const struct ast_ignorepat ip)

◆ ast_get_include_name()

const char * ast_get_include_name ( const struct ast_include include)

◆ ast_get_include_registrar()

const char * ast_get_include_registrar ( const struct ast_include i)

◆ ast_get_switch_data()

const char * ast_get_switch_data ( const struct ast_sw sw)

◆ ast_get_switch_eval()

int ast_get_switch_eval ( const struct ast_sw sw)

Definition at line 58 of file pbx_sw.c.

59{
60 return sw->eval;
61}
int eval
Definition pbx_sw.c:43

References ast_sw::eval.

Referenced by context_merge_incls_swits_igps_other_registrars(), and pbx_find_extension().

◆ ast_get_switch_name()

const char * ast_get_switch_name ( const struct ast_sw sw)

◆ ast_get_switch_registrar()

const char * ast_get_switch_registrar ( const struct ast_sw sw)

◆ ast_goto_if_exists()

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 6939 of file pbx.c.

6940{
6941 return __ast_goto_if_exists(chan, context, exten, priority, 0);
6942}

References __ast_goto_if_exists(), ast_channel::context, ast_channel::exten, and priority.

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

◆ ast_hashtab_compare_contexts()

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

hashtable functions for contexts

Definition at line 589 of file ael_main.c.

590{
591 return 0;
592}

References bc, and ast_context::name.

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

◆ ast_hashtab_hash_contexts()

unsigned int ast_hashtab_hash_contexts ( const void *  obj)

◆ ast_hint_presence_state()

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
cthis is not important
contextwhich context to look in
extenwhich extension to get state
[out]subtypeFurther information regarding the presence returned
[out]messageCustom 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 71 of file extension_state_legacy.c.

72{
73 struct ast_extension_state_presence_snapshot *presence_snapshot;
75
76 presence_snapshot = ast_extension_state_get_latest_presence_snapshot(c, exten, context);
77 if (!presence_snapshot) {
78 return -1;
79 }
80
81 presence_state = presence_snapshot->presence_state;
82 if (presence_snapshot->presence_subtype) {
83 *subtype = ast_strdup(presence_snapshot->presence_subtype);
84 }
85 if (presence_snapshot->presence_message) {
86 *message = ast_strdup(presence_snapshot->presence_message);
87 }
88
89 ao2_ref(presence_snapshot, -1);
90
91 return presence_state;
92}
struct ast_extension_state_presence_snapshot * ast_extension_state_get_latest_presence_snapshot(struct ast_channel *chan, const char *exten, const char *context)
Get the latest presence state message for an extension.
ast_presence_state
Presence snapshot for an extension state.
char * presence_subtype
The subtype of the presence state.
char * presence_message
An optional message for the presence.
enum ast_presence_state presence_state
The presence state of the extension.

References ao2_ref, ast_extension_state_get_latest_presence_snapshot(), ast_strdup, c, ast_extension_state_presence_snapshot::presence_message, ast_extension_state_presence_snapshot::presence_state, and ast_extension_state_presence_snapshot::presence_subtype.

Referenced by exten_state_data_alloc().

◆ ast_ignore_pattern()

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

Checks to see if a number should be ignored.

Parameters
contextcontext to search within
patternto check whether it should be ignored or not

Check if a number should be ignored with respect to dialtone cancellation.

Return values
0if the pattern should not be ignored
non-zeroif the pattern should be ignored

Definition at line 5177 of file pbx.c.

5178{
5179 int ret = 0;
5180 struct ast_context *con;
5181
5183 con = ast_context_find(context);
5184 if (con) {
5185 int idx;
5186
5187 for (idx = 0; idx < ast_context_ignorepats_count(con); idx++) {
5188 const struct ast_ignorepat *pat = ast_context_ignorepats_get(con, idx);
5189
5191 ret = 1;
5192 break;
5193 }
5194 }
5195 }
5197
5198 return ret;
5199}
int ast_extension_match(const char *pattern, const char *extension)
Determine if a given extension matches a given pattern (in NXX format)
Definition pbx.c:2053
const struct ast_ignorepat * ast_context_ignorepats_get(const struct ast_context *con, int idx)
Definition pbx.c:6885

References ast_context_find(), ast_context_ignorepats_count(), ast_context_ignorepats_get(), ast_extension_match(), ast_get_ignorepat_name(), ast_rdlock_contexts(), ast_unlock_contexts(), and ast_ignorepat::pattern.

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

◆ ast_matchmore_extension()

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
cnot really important XXX
contextcontext to search within
extenextension to check
prioritypriority of extension path
calleridcallerid 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

Definition at line 2755 of file pbx.c.

2756{
2757 return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCHMORE, 0, 0);
2758}

References c, E_MATCHMORE, ast_exten::exten, NULL, pbx_extension_helper(), and priority.

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(), pbx_builtin_background(), and readexten_exec().

◆ ast_merge_contexts_and_delete()

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
extcontextspointer to the ast_context structure
exttablepointer to the ast_hashtab structure that contains all the elements in extcontexts
registrarof 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 4859 of file pbx.c.

4860{
4861 double ft;
4862 struct ast_context *tmp;
4863 struct ast_context *oldcontextslist;
4864 struct ast_hashtab *oldtable;
4865 struct ast_hashtab_iter *iter;
4866 int ctx_count = 0, promoted_count = 0;
4867 struct timeval begintime;
4868 struct timeval writelocktime;
4869 struct timeval endlocktime;
4870 struct timeval enddeltime;
4871
4872 begintime = ast_tvnow();
4874
4875 if (!contexts_table) {
4876 /* Well, that's odd. There are no contexts. */
4877 contexts_table = exttable;
4878 contexts = *extcontexts;
4879
4881 while ((tmp = ast_hashtab_next(iter))) {
4882 context_promote(tmp);
4883 }
4885
4887 return;
4888 }
4889
4891 while ((tmp = ast_hashtab_next(iter))) {
4892 ++ctx_count;
4893 context_merge(extcontexts, exttable, tmp, registrar);
4894 }
4896
4897 writelocktime = ast_tvnow();
4898
4899 /* save the old table and list */
4900 oldtable = contexts_table;
4901 oldcontextslist = contexts;
4902
4903 /* move in the new table and list */
4904 contexts_table = exttable;
4905 contexts = *extcontexts;
4906
4908 while ((tmp = ast_hashtab_next(iter))) {
4909 promoted_count += context_promote(tmp);
4910 }
4912
4913 /* ctx_count is still the number of old contexts before the merge,
4914 * use the new count when we tell the user how many contexts exist. */
4915 ctx_count = ast_hashtab_size(contexts_table);
4916
4918
4919 endlocktime = ast_tvnow();
4920
4921 /*
4922 * The old list and hashtab no longer are relevant, delete them
4923 * while the rest of asterisk is now freely using the new stuff
4924 * instead.
4925 */
4926
4927 ast_hashtab_destroy(oldtable, NULL);
4928
4929 for (tmp = oldcontextslist; tmp; ) {
4930 struct ast_context *next; /* next starting point */
4931
4932 next = tmp->next;
4934 tmp = next;
4935 }
4936 enddeltime = ast_tvnow();
4937
4938 ft = ast_tvdiff_us(writelocktime, begintime);
4939 ft /= 1000000.0;
4940 ast_verb(5,"Time to scan old dialplan and merge leftovers back into the new: %8.6f sec\n", ft);
4941
4942 ft = ast_tvdiff_us(endlocktime, writelocktime);
4943 ft /= 1000000.0;
4944 ast_verb(5,"Time to promote contexts and swap in new dialplan: %8.6f sec\n", ft);
4945
4946 ft = ast_tvdiff_us(enddeltime, endlocktime);
4947 ft /= 1000000.0;
4948 ast_verb(5,"Time to delete the old dialplan: %8.6f sec\n", ft);
4949
4950 ft = ast_tvdiff_us(enddeltime, begintime);
4951 ft /= 1000000.0;
4952 ast_verb(5,"Total time merge_contexts_delete: %8.6f sec\n", ft);
4953 ast_verb(5, "%s successfully loaded %d contexts after incorporating %d promoted contexts (enable debug for details).\n",
4954 registrar, ctx_count, promoted_count);
4955}
#define ast_hashtab_start_traversal(tab)
Definition hashtab.h:356
void ast_hashtab_destroy(struct ast_hashtab *tab, void(*objdestroyfunc)(void *obj))
This func will free the hash table and all its memory.
Definition hashtab.c:363
void ast_hashtab_end_traversal(struct ast_hashtab_iter *it)
end the traversal, free the iterator, unlock if necc.
Definition hashtab.c:674
void * ast_hashtab_next(struct ast_hashtab_iter *it)
Gets the next object in the list, advances iter one step returns null on end of traversal.
Definition hashtab.c:683
static void context_merge(struct ast_context **extcontexts, struct ast_hashtab *exttable, struct ast_context *context, const char *registrar)
Definition pbx.c:4680
static int context_promote(struct ast_context *context)
Definition pbx.c:4812
static void __ast_internal_context_destroy(struct ast_context *con)
Definition pbx.c:6297
an iterator for traversing the buckets
Definition hashtab.h:106
int64_t ast_tvdiff_us(struct timeval end, struct timeval start)
Computes the difference (in microseconds) between two struct timeval instances.
Definition time.h:87
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition time.h:159

References __ast_internal_context_destroy(), ast_hashtab_destroy(), ast_hashtab_end_traversal(), ast_hashtab_next(), ast_hashtab_size(), ast_hashtab_start_traversal, ast_tvdiff_us(), ast_tvnow(), ast_unlock_contexts(), ast_verb, ast_wrlock_contexts(), context_merge(), context_promote(), contexts, contexts_table, ast_context::next, NULL, and registrar.

◆ ast_parseable_goto()

int ast_parseable_goto ( struct ast_channel chan,
const char *  goto_string 
)
Note
This function will handle locking the channel as needed.

Definition at line 7024 of file pbx.c.

7025{
7026 return pbx_parseable_goto(chan, goto_string, 0);
7027}

References pbx_parseable_goto().

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

◆ ast_pbx_exec_application()

int ast_pbx_exec_application ( struct ast_channel chan,
const char *  app_name,
const char *  app_args 
)

Execute an application.

Parameters
chanchannel to execute on
app_namename of app to execute
app_argsthe data passed into the app

This application executes an application by name on a given channel. It is a wrapper around pbx_exec that will perform variable substitution and then execute the application if it exists. If the application is not found, a warning is logged.

Return values
0success
-1failure (including application not found)

Definition at line 513 of file pbx_app.c.

514{
515 int res = -1;
516 struct ast_app *app;
517
519 if (!app) {
520 ast_log(LOG_WARNING, "Could not find application (%s)\n", app_name);
521 } else {
522 struct ast_str *substituted_args = NULL;
523
524 if (!ast_strlen_zero(app_args) && (substituted_args = ast_str_create(16))) {
525 ast_str_substitute_variables(&substituted_args, 0, chan, app_args);
526 res = pbx_exec(chan, app, ast_str_buffer(substituted_args));
527 ast_free(substituted_args);
528 } else {
529 if (!ast_strlen_zero(app_args)) {
530 ast_log(LOG_WARNING, "Could not substitute application argument variables for %s\n", app_name);
531 }
532 res = pbx_exec(chan, app, app_args);
533 }
534 /* Manually make a snapshot now, since pbx_exec won't necessarily get called again immediately. */
536 }
537 return res;
538}
void ast_channel_publish_snapshot(struct ast_channel *chan)
Publish a ast_channel_snapshot for a channel.
void ast_str_substitute_variables(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
const char * app_name(struct ast_app *app)
Definition pbx_app.c:475
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
Definition pbx_app.c:483
struct ast_app * pbx_findapp(const char *app)
Look up an application.
Definition pbx_app.c:93

References app, app_name(), ast_channel_publish_snapshot(), ast_free, ast_log, ast_str_buffer(), ast_str_create, ast_str_substitute_variables(), ast_strlen_zero(), LOG_WARNING, NULL, pbx_exec(), and pbx_findapp().

Referenced by answer_exec_run(), conf_kick_all(), conf_run(), disa_exec(), dundi_exec(), pbx_builtin_execiftime(), run_app_helper(), and snoop_stasis_thread().

◆ ast_pbx_h_exten_run()

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
chanChannel to run the h exten on.
contextContext the h exten is in.

Definition at line 2765 of file pbx.c.

2766{
2767 int autoloopflag;
2768 int found;
2769 int spawn_error;
2770
2771 ast_channel_lock(chan);
2772
2773 /*
2774 * Make sure that the channel is marked as hungup since we are
2775 * going to run the h exten on it.
2776 */
2778
2779 /* Set h exten location */
2780 if (context != ast_channel_context(chan)) {
2781 ast_channel_context_set(chan, context);
2782 }
2783 ast_channel_exten_set(chan, "h");
2784 ast_channel_priority_set(chan, 1);
2785
2786 /* Save autoloop flag */
2789 ast_channel_unlock(chan);
2790
2791 for (;;) {
2792 spawn_error = ast_spawn_extension(chan, ast_channel_context(chan),
2794 S_COR(ast_channel_caller(chan)->id.number.valid,
2795 ast_channel_caller(chan)->id.number.str, NULL), &found, 1);
2796
2797 ast_channel_lock(chan);
2798 if (spawn_error) {
2799 /* The code after the loop needs the channel locked. */
2800 break;
2801 }
2803 ast_channel_unlock(chan);
2804 }
2805 if (found && spawn_error) {
2806 /* Something bad happened, or a hangup has been requested. */
2807 ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n",
2810 ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n",
2813 }
2814
2815 /* An "h" exten has been run, so indicate that one has been run. */
2817
2818 /* Restore autoloop flag */
2820 ast_channel_unlock(chan);
2821}
@ AST_FLAG_BRIDGE_HANGUP_RUN
Definition channel.h:1038
int ast_channel_priority(const struct ast_channel *chan)
const char * ast_channel_context(const struct ast_channel *chan)
@ AST_SOFTHANGUP_HANGUP_EXEC
Definition channel.h:1174
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
const char * ast_channel_exten(const struct ast_channel *chan)
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)
Definition pbx.c:2760
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition strings.h:87
Number structure.
#define ast_set2_flag(p, value, flag)
Definition utils.h:95
#define ast_set_flag(p, flag)
Definition utils.h:71

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

◆ ast_pbx_hangup_handler_destroy()

void ast_pbx_hangup_handler_destroy ( struct ast_channel chan)

Destroy the hangup handler container on a channel.

Since
11.0
Parameters
chanChannel to destroy the hangup handler container on.

Definition at line 103 of file pbx_hangup_handler.c.

104{
106 struct ast_hangup_handler *h_handler;
107
108 ast_channel_lock(chan);
109
110 /* Get rid of each of the hangup handlers on the channel */
112 while ((h_handler = AST_LIST_REMOVE_HEAD(handlers, node))) {
113 ast_free(h_handler);
114 }
115
116 ast_channel_unlock(chan);
117}
struct ast_hangup_handler_list * ast_channel_hangup_handlers(struct ast_channel *chan)
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
static const struct ast_aeap_message_handler handlers[]
Definition test_aeap.c:135

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

Referenced by ast_channel_destructor(), and ast_dummy_channel_destructor().

◆ ast_pbx_hangup_handler_init()

void ast_pbx_hangup_handler_init ( struct ast_channel chan)

Init the hangup handler container on a channel.

Since
11.0
Parameters
chanChannel to init the hangup handler container on.

Definition at line 95 of file pbx_hangup_handler.c.

96{
98
101}
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.

References ast_channel_hangup_handlers(), AST_LIST_HEAD_INIT_NOLOCK, and handlers.

Referenced by __ast_channel_alloc_ap(), and __ast_dummy_channel_alloc().

◆ ast_pbx_hangup_handler_pop()

int ast_pbx_hangup_handler_pop ( struct ast_channel chan)

Pop the top of the channel hangup handler stack.

Since
11.0
Parameters
chanChannel to push the hangup handler onto.
Return values
TRUEif a handler was popped off of the stack.

Definition at line 119 of file pbx_hangup_handler.c.

120{
122 struct ast_hangup_handler *h_handler;
123
124 ast_channel_lock(chan);
126 h_handler = AST_LIST_REMOVE_HEAD(handlers, node);
127 if (h_handler) {
128 publish_hangup_handler_message("pop", chan, h_handler->args);
129 }
130 ast_channel_unlock(chan);
131 if (h_handler) {
132 ast_free(h_handler);
133 return 1;
134 }
135 return 0;
136}
static void publish_hangup_handler_message(const char *action, struct ast_channel *chan, const char *handler)

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

Referenced by func_channel_write_real().

◆ ast_pbx_hangup_handler_push()

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
chanChannel to push the hangup handler onto.
handlerGosub application parameter string.

Definition at line 138 of file pbx_hangup_handler.c.

139{
141 struct ast_hangup_handler *h_handler;
142 const char *expanded_handler;
143
145 return;
146 }
147
148 expanded_handler = ast_app_expand_sub_args(chan, handler);
149 if (!expanded_handler) {
150 return;
151 }
152 h_handler = ast_malloc(sizeof(*h_handler) + 1 + strlen(expanded_handler));
153 if (!h_handler) {
154 ast_free((char *) expanded_handler);
155 return;
156 }
157 strcpy(h_handler->args, expanded_handler);/* Safe */
158 ast_free((char *) expanded_handler);
159
160 ast_channel_lock(chan);
161
164 publish_hangup_handler_message("push", chan, h_handler->args);
165 ast_channel_unlock(chan);
166}
#define ast_malloc(len)
A wrapper for malloc()
Definition astmm.h:191
const char * ast_app_expand_sub_args(struct ast_channel *chan, const char *args)
Add missing context/exten to subroutine argument string.
Definition main/app.c:278
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
static void handler(const char *name, int response_code, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Definition test_ari.c:59

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(), handler(), handlers, and publish_hangup_handler_message().

Referenced by func_channel_write_real().

◆ ast_pbx_hangup_handler_run()

int ast_pbx_hangup_handler_run ( struct ast_channel chan)

Run all hangup handlers on the channel.

Since
11.0
Parameters
chanChannel to run the hangup handlers on.
Note
Absolutely NO channel locks should be held before calling this function.
Return values
Zeroif no hangup handlers run.
non-zeroif hangup handlers were run.

Definition at line 58 of file pbx_hangup_handler.c.

59{
61 struct ast_hangup_handler *h_handler;
62
63 ast_channel_lock(chan);
67 return 0;
68 }
69
70 /*
71 * Make sure that the channel is marked as hungup since we are
72 * going to run the hangup handlers on it.
73 */
75
76 for (;;) {
79 if (!h_handler) {
80 break;
81 }
82
83 publish_hangup_handler_message("run", chan, h_handler->args);
85
86 ast_app_exec_sub(NULL, chan, h_handler->args, 1);
87 ast_free(h_handler);
88
89 ast_channel_lock(chan);
90 }
92 return 1;
93}
int ast_app_exec_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int ignore_hangup)
Run a subroutine on a channel, placing an optional second channel into autoservice.
Definition main/app.c:297
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.

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(), handlers, NULL, and publish_hangup_handler_message().

Referenced by __ast_pbx_run(), and ast_hangup().

◆ ast_pbx_outgoing_app()

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
typeThe channel technology to create
capThe format capabilities for the channel
addrAddress data to pass to the channel technology driver
timeoutHow long we should attempt to dial the outbound channel
appThe name of the application to execute
appdataData to pass to the application
reasonOptional. If provided, the dialed status of the outgoing channel. Codes are AST_CONTROL_xxx values. Valid only if synchronous is non-zero.
synchronousdefined by the ast_pbx_outgoing_sync enum. If AST_OUTGOING_NO_WAIT then don't wait for anything. If AST_OUTGOING_WAIT then block until the outbound channel answers or the call fails. If AST_OUTGOING_WAIT_COMPLETE then wait for the call to complete or fail.
cid_numThe caller ID number to set on the outbound channel
cid_nameThe caller ID name to set on the outbound channel
varsVariables to set on the outbound channel
accountThe accountcode for the outbound channel
locked_channelOptional. The outbound channel that was created if success is returned. Otherwise it is set to NULL. This is returned both locked and reference bumped.
assignedidsOptional. The uniqueid(s) to assign the channel(s) that are created.
Return values
0on success
-1on failure

Definition at line 6262 of file pbx.c.

6267{
6268 return ast_pbx_outgoing_app_predial(type, cap, addr, timeout, app, appdata, reason, synchronous,
6269 cid_num, cid_name, vars, account, locked_channel, assignedids, NULL);
6270}
static const char type[]
int ast_pbx_outgoing_app_predial(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, const char *predial_callee)
Definition pbx.c:6272

References app, ast_pbx_outgoing_app_predial(), NULL, and type.

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

◆ ast_pbx_outgoing_app_predial()

int ast_pbx_outgoing_app_predial ( 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,
const char *  predial_callee 
)

Definition at line 6272 of file pbx.c.

6277{
6278 if (reason) {
6279 *reason = 0;
6280 }
6281 if (locked_channel) {
6282 *locked_channel = NULL;
6283 }
6284 if (ast_strlen_zero(app)) {
6285 return -1;
6286 }
6287
6288 return pbx_outgoing_attempt(type, cap, addr, timeout, NULL, NULL, 0, app, appdata,
6289 reason, synchronous, cid_num, cid_name, vars, account, locked_channel, 0,
6290 assignedids, predial_callee);
6291}
static int pbx_outgoing_attempt(const char *type, struct ast_format_cap *cap, const char *addr, int timeout, const char *context, const char *exten, int priority, 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, int early_media, const struct ast_assigned_ids *assignedids, const char *predial_callee)
Definition pbx.c:6002

References app, ast_strlen_zero(), NULL, pbx_outgoing_attempt(), and type.

Referenced by ast_pbx_outgoing_app(), and originate_exec().

◆ ast_pbx_outgoing_exten()

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
typeThe channel technology to create
capThe format capabilities for the channel
addrAddress data to pass to the channel technology driver
timeoutHow long we should attempt to dial the outbound channel
contextThe destination context for the outbound channel
extenThe destination extension for the outbound channel
priorityThe destination priority for the outbound channel
reasonOptional. If provided, the dialed status of the outgoing channel. Codes are AST_CONTROL_xxx values. Valid only if synchronous is non-zero.
synchronousdefined by the ast_pbx_outgoing_sync enum. If AST_OUTGOING_NO_WAIT then don't wait for anything. If AST_OUTGOING_WAIT then block until the outbound channel answers or the call fails. If AST_OUTGOING_WAIT_COMPLETE then wait for the call to complete or fail. If AST_OUTGOING_WAIT or AST_OUTGOING_WAIT_COMPLETE is specified, the call doesn't answer, and failed@context exists then run a channel named OutgoingSpoolFailed at failed@context.
cid_numThe caller ID number to set on the outbound channel
cid_nameThe caller ID name to set on the outbound channel
varsVariables to set on the outbound channel
accountThe accountcode for the outbound channel
locked_channelOptional. 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_mediaIf non-zero the channel "answers" when progress is indicated.
assignedidsOptional. The uniqueid(s) to assign the channel(s) that are created.
Return values
0on success
-1on failure

Definition at line 6198 of file pbx.c.

6203{
6204 return ast_pbx_outgoing_exten_predial(type, cap, addr, timeout, context, exten, priority, reason,
6205 synchronous, cid_num, cid_name, vars, account, locked_channel, early_media, assignedids, NULL);
6206}
int ast_pbx_outgoing_exten_predial(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, const char *predial_callee)
Definition pbx.c:6208

References ast_pbx_outgoing_exten_predial(), NULL, priority, and type.

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

◆ ast_pbx_outgoing_exten_predial()

int ast_pbx_outgoing_exten_predial ( 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,
const char *  predial_callee 
)
Todo:
XXX Not good. The channel name is not unique if more than one originate fails at a time.

Definition at line 6208 of file pbx.c.

6213{
6214 int res;
6215 int my_reason;
6216
6217 if (!reason) {
6218 reason = &my_reason;
6219 }
6220 *reason = 0;
6221 if (locked_channel) {
6222 *locked_channel = NULL;
6223 }
6224
6225 res = pbx_outgoing_attempt(type, cap, addr, timeout, context, exten, priority,
6226 NULL, NULL, reason, synchronous, cid_num, cid_name, vars, account, locked_channel,
6227 early_media, assignedids, predial_callee);
6228
6229 if (res < 0 /* Call failed to get connected for some reason. */
6230 && 0 < synchronous
6231 && ast_exists_extension(NULL, context, "failed", 1, NULL)) {
6232 struct ast_channel *failed;
6233
6234 /* We do not have to worry about a locked_channel if dialing failed. */
6235 ast_assert(!locked_channel || !*locked_channel);
6236
6237 /*!
6238 * \todo XXX Not good. The channel name is not unique if more than
6239 * one originate fails at a time.
6240 */
6241 failed = ast_channel_alloc(0, AST_STATE_DOWN, cid_num, cid_name, account,
6242 "failed", context, NULL, NULL, 0, "OutgoingSpoolFailed");
6243 if (failed) {
6244 char failed_reason[12];
6245
6246 snprintf(failed_reason, sizeof(failed_reason), "%d", *reason);
6247 pbx_builtin_setvar_helper(failed, "REASON", failed_reason);
6248 ast_channel_unlock(failed);
6249 ast_set_variables(failed, vars);
6250
6251 if (ast_pbx_run(failed)) {
6252 ast_log(LOG_ERROR, "Unable to run PBX on '%s'\n",
6253 ast_channel_name(failed));
6254 ast_hangup(failed);
6255 }
6256 }
6257 }
6258
6259 return res;
6260}
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Definition channel.h:1299
void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars)
adds a list of channel variables to a channel
Definition channel.c:8291
@ AST_STATE_DOWN
enum ast_pbx_result ast_pbx_run(struct ast_channel *c)
Execute the PBX in the current thread.
Definition pbx.c:3315
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition pbx.c:2735
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.

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, ast_channel::context, LOG_ERROR, NULL, pbx_builtin_setvar_helper(), pbx_outgoing_attempt(), priority, and type.

Referenced by action_originate(), ast_pbx_outgoing_exten(), and originate_exec().

◆ ast_pbx_run()

enum ast_pbx_result ast_pbx_run ( struct ast_channel c)

Execute the PBX in the current thread.

Parameters
cchannel 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
Zeroon success
non-zeroon failure

Definition at line 3315 of file pbx.c.

3316{
3317 return ast_pbx_run_args(c, NULL);
3318}
enum ast_pbx_result ast_pbx_run_args(struct ast_channel *c, struct ast_pbx_args *args)
Execute the PBX in the current thread.
Definition pbx.c:3295

References ast_pbx_run_args(), c, and NULL.

Referenced by __analog_ss_thread(), analog_ss_thread(), ari_originate_dial(), ast_bridge_run_after_goto(), ast_pbx_outgoing_exten_predial(), do_notify(), pbx_outgoing_exec(), and unistim_ss().

◆ ast_pbx_run_args()

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
cchannel to run the pbx on
argsoptions 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
Zeroon success
non-zeroon failure

Definition at line 3295 of file pbx.c.

3296{
3298
3299 if (!ast_fully_booted) {
3300 ast_log(LOG_WARNING, "PBX requires Asterisk to be fully booted\n");
3301 return AST_PBX_FAILED;
3302 }
3303
3304 if (increase_call_count(c)) {
3305 return AST_PBX_CALL_LIMIT;
3306 }
3307
3308 res = __ast_pbx_run(c, args);
3309
3311
3312 return res;
3313}
#define ast_fully_booted
Definition options.h:127
static void decrease_call_count(void)
Definition pbx.c:3226
static int increase_call_count(const struct ast_channel *c)
Increase call count for channel.
Definition pbx.c:3177
static enum ast_pbx_result __ast_pbx_run(struct ast_channel *c, struct ast_pbx_args *args)
Definition pbx.c:2866
ast_pbx_result
The result codes when starting the PBX on a channel with ast_pbx_start.
Definition pbx.h:372

References __ast_pbx_run(), args, ast_fully_booted, ast_log, AST_PBX_CALL_LIMIT, AST_PBX_FAILED, AST_PBX_SUCCESS, c, 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().

◆ ast_pbx_start()

enum ast_pbx_result ast_pbx_start ( struct ast_channel c)

Create a new thread and start the PBX.

Parameters
cchannel 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
Zeroon success
non-zeroon failure

Definition at line 3268 of file pbx.c.

3269{
3270 pthread_t t;
3271
3272 if (!c) {
3273 ast_log(LOG_WARNING, "Asked to start thread on NULL channel?\n");
3274 return AST_PBX_FAILED;
3275 }
3276
3277 if (!ast_fully_booted) {
3278 ast_log(LOG_WARNING, "PBX requires Asterisk to be fully booted\n");
3279 return AST_PBX_FAILED;
3280 }
3281
3283 return AST_PBX_CALL_LIMIT;
3284
3285 /* Start a new thread, and get something handling this channel. */
3287 ast_log(LOG_WARNING, "Failed to create new channel thread\n");
3289 return AST_PBX_FAILED;
3290 }
3291
3292 return AST_PBX_SUCCESS;
3293}
static void * pbx_thread(void *data)
Definition pbx.c:3248
#define ast_pthread_create_detached(a, b, c, d)
Definition utils.h:628

References ast_fully_booted, ast_log, AST_PBX_CALL_LIMIT, AST_PBX_FAILED, AST_PBX_SUCCESS, ast_pthread_create_detached, c, decrease_call_count(), increase_call_count(), LOG_WARNING, NULL, and pbx_thread().

Referenced by ast_async_goto(), ast_iax2_new(), bridge_failed_peer_goto(), console_new(), dahdi_new(), dial_exec_full(), do_monitor_headset(), generic_recall(), handle_response_clip(), handle_response_cmgr(), jingle_action_session_initiate(), local_call(), ooh323_new(), pbx_start_incoming_request(), and unistim_new().

◆ ast_processed_calls()

int ast_processed_calls ( void  )

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

Definition at line 3325 of file pbx.c.

3326{
3327 return totalcalls;
3328}
static int totalcalls
Definition pbx.c:423

References totalcalls.

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

◆ ast_rdlock_context()

int ast_rdlock_context ( struct ast_context con)

Read locks a given context.

Parameters
concontext to lock
Return values
0on success
-1on failure

Definition at line 6644 of file pbx.c.

6645{
6646 return ast_rwlock_rdlock(&con->lock);
6647}
#define ast_rwlock_rdlock(a)
Definition lock.h:242

References ast_rwlock_rdlock, and ast_context::lock.

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

◆ ast_rdlock_contexts()

int ast_rdlock_contexts ( void  )

◆ ast_register_switch()

int ast_register_switch ( struct ast_switch sw)

Register an alternative dialplan switch.

Parameters
swswitch to register

This function registers a populated ast_switch structure with the asterisk switching architecture.

Return values
0success
non-zerofailure

Definition at line 58 of file pbx_switch.c.

59{
60 struct ast_switch *tmp;
61
64 if (!strcasecmp(tmp->name, sw->name)) {
66 ast_log(LOG_WARNING, "Switch '%s' already found\n", sw->name);
67 return -1;
68 }
69 }
72
73 return 0;
74}
struct ast_switch::@255 list
const char * name
Definition pbx.h:164

References ast_log, AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_switch::list, LOG_WARNING, and ast_switch::name.

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

◆ ast_spawn_extension()

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
cnot important
contextwhich context to generate the extension within
extennew extension to add
prioritypriority of new extension
calleridcallerid 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
0on success
-1on failure.

Definition at line 2760 of file pbx.c.

2761{
2762 return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_SPAWN, found, combined_find_spawn);
2763}
@ E_SPAWN
Definition extconf.h:219

References c, E_SPAWN, ast_exten::exten, NULL, pbx_extension_helper(), and priority.

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

◆ ast_str_get_hint()

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
hintbuffer for hint
hintsizeMaximum size of hint buffer (<0 to prevent growth, >0 to limit growth to that number of bytes, or 0 for unlimited growth)
namebuffer for name portion of hint
namesizeMaximum size of name buffer (<0 to prevent growth, >0 to limit growth to that number of bytes, or 0 for unlimited growth)
cChannel from which to return the hint. This is only important when the hint or name contains an expression to be expanded.
contextwhich context to look in
extenwhich 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.

If an extension hint exists, return non-zero.

Definition at line 2715 of file pbx.c.

2716{
2717 struct ast_exten *e = ast_hint_extension(c, context, exten);
2718
2719 if (!e) {
2720 return 0;
2721 }
2722
2723 if (hint) {
2724 ast_str_set(hint, hintsize, "%s", ast_get_extension_app(e));
2725 }
2726 if (name) {
2727 const char *tmp = ast_get_extension_app_data(e);
2728 if (tmp) {
2729 ast_str_set(name, namesize, "%s", tmp);
2730 }
2731 }
2732 return -1;
2733}
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition strings.h:1113

References ast_get_extension_app(), ast_get_extension_app_data(), ast_hint_extension(), ast_str_set(), c, ast_exten::exten, and name.

Referenced by ast_str_retrieve_variable().

◆ ast_str_retrieve_variable()

const char * ast_str_retrieve_variable ( struct ast_str **  buf,
ssize_t  maxlen,
struct ast_channel chan,
struct varshead headp,
const char *  var 
)
Parameters
bufResult 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.
chanChannel variables from which to extract values, and channel to pass to any dialplan functions.
headpIf no channel is specified, a channel list from which to extract variable values
varVariable name to retrieve.

Definition at line 257 of file pbx_variables.c.

258{
259 const char not_found = '\0';
260 char *tmpvar;
261 const char *ret;
262 const char *s; /* the result */
263 int offset, length;
264 int i, need_substring;
265 struct varshead *places[2] = { headp, &globals }; /* list of places where we may look */
266 char workspace[20];
267
268 if (c) {
270 places[0] = ast_channel_varshead(c);
271 }
272 /*
273 * Make a copy of var because parse_variable_name() modifies the string.
274 * Then if called directly, we might need to run substring() on the result;
275 * remember this for later in 'need_substring', 'offset' and 'length'
276 */
277 tmpvar = ast_strdupa(var); /* parse_variable_name modifies the string */
278 need_substring = parse_variable_name(tmpvar, &offset, &length, &i /* ignored */);
279
280 /*
281 * Look first into predefined variables, then into variable lists.
282 * Variable 's' points to the result, according to the following rules:
283 * s == &not_found (set at the beginning) means that we did not find a
284 * matching variable and need to look into more places.
285 * If s != &not_found, s is a valid result string as follows:
286 * s = NULL if the variable does not have a value;
287 * you typically do this when looking for an unset predefined variable.
288 * s = workspace if the result has been assembled there;
289 * typically done when the result is built e.g. with an snprintf(),
290 * so we don't need to do an additional copy.
291 * s != workspace in case we have a string, that needs to be copied
292 * (the ast_copy_string is done once for all at the end).
293 * Typically done when the result is already available in some string.
294 */
295 s = &not_found; /* default value */
296 if (c) { /* This group requires a valid channel */
297 /* Names with common parts are looked up a piece at a time using strncmp. */
298 if (!strncmp(var, "CALL", 4)) {
299 if (!strncmp(var + 4, "ING", 3)) {
300 if (!strcmp(var + 7, "PRES")) { /* CALLINGPRES */
301 ast_str_set(str, maxlen, "%d",
303 s = ast_str_buffer(*str);
304 } else if (!strcmp(var + 7, "ANI2")) { /* CALLINGANI2 */
305 ast_str_set(str, maxlen, "%d", ast_channel_caller(c)->ani2);
306 s = ast_str_buffer(*str);
307 } else if (!strcmp(var + 7, "TON")) { /* CALLINGTON */
308 ast_str_set(str, maxlen, "%d", ast_channel_caller(c)->id.number.plan);
309 s = ast_str_buffer(*str);
310 } else if (!strcmp(var + 7, "TNS")) { /* CALLINGTNS */
311 ast_str_set(str, maxlen, "%d", ast_channel_dialed(c)->transit_network_select);
312 s = ast_str_buffer(*str);
313 }
314 }
315 } else if (!strcmp(var, "HINT")) {
317 } else if (!strcmp(var, "HINTNAME")) {
319 } else if (!strcmp(var, "EXTEN")) {
320 s = ast_channel_exten(c);
321 } else if (!strcmp(var, "CONTEXT")) {
323 } else if (!strcmp(var, "PRIORITY")) {
324 ast_str_set(str, maxlen, "%d", ast_channel_priority(c));
325 s = ast_str_buffer(*str);
326 } else if (!strcmp(var, "CHANNEL")) {
327 s = ast_channel_name(c);
328 } else if (!strcmp(var, "UNIQUEID")) {
330 } else if (!strcmp(var, "HANGUPCAUSE")) {
331 ast_str_set(str, maxlen, "%d", ast_channel_hangupcause(c));
332 s = ast_str_buffer(*str);
333 }
334 }
335 if (s == &not_found) { /* look for more */
336 if (!strcmp(var, "EPOCH")) {
337 ast_str_set(str, maxlen, "%d", (int) time(NULL));
338 s = ast_str_buffer(*str);
339 } else if (!strcmp(var, "SYSTEMNAME")) {
341 } else if (!strcmp(var, "ASTCACHEDIR")) {
343 } else if (!strcmp(var, "ASTETCDIR")) {
345 } else if (!strcmp(var, "ASTMODDIR")) {
347 } else if (!strcmp(var, "ASTVARLIBDIR")) {
349 } else if (!strcmp(var, "ASTDBDIR")) {
351 } else if (!strcmp(var, "ASTKEYDIR")) {
353 } else if (!strcmp(var, "ASTDATADIR")) {
355 } else if (!strcmp(var, "ASTAGIDIR")) {
357 } else if (!strcmp(var, "ASTSPOOLDIR")) {
359 } else if (!strcmp(var, "ASTRUNDIR")) {
361 } else if (!strcmp(var, "ASTLOGDIR")) {
363 } else if (!strcmp(var, "ASTSBINDIR")) {
365 } else if (!strcmp(var, "ENTITYID")) {
366 ast_eid_to_str(workspace, sizeof(workspace), &ast_eid_default);
367 s = workspace;
368 }
369 }
370 /* if not found, look into chanvars or global vars */
371 for (i = 0; s == &not_found && i < ARRAY_LEN(places); i++) {
372 struct ast_var_t *variables;
373 if (!places[i])
374 continue;
375 if (places[i] == &globals)
377 AST_LIST_TRAVERSE(places[i], variables, entries) {
378 if (!strcmp(ast_var_name(variables), var)) {
379 s = ast_var_value(variables);
380 break;
381 }
382 }
383 if (places[i] == &globals)
385 }
386 if (s == &not_found || s == NULL) {
387 ast_debug(5, "Result of '%s' is NULL\n", var);
388 ret = NULL;
389 } else {
390 ast_debug(5, "Result of '%s' is '%s'\n", var, s);
391 if (s != ast_str_buffer(*str)) {
392 ast_str_set(str, maxlen, "%s", s);
393 }
394 ret = ast_str_buffer(*str);
395 if (need_substring) {
396 ret = ast_str_substring(*str, offset, length);
397 ast_debug(2, "Final result of '%s' is '%s'\n", var, ret);
398 }
399 }
400
401 if (c) {
403 }
404 return ret;
405}
#define var
Definition ast_expr2f.c:605
struct varshead * ast_channel_varshead(struct ast_channel *chan)
int ast_party_id_presentation(const struct ast_party_id *id)
Determine the overall presentation value for the given party.
Definition channel.c:1808
const char * ast_channel_uniqueid(const struct ast_channel *chan)
int ast_channel_hangupcause(const struct ast_channel *chan)
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
const char * ast_var_name(const struct ast_var_t *var)
Definition chanvars.c:60
const char * ast_var_value(const struct ast_var_t *var)
Definition chanvars.c:80
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define ast_rwlock_unlock(a)
Definition lock.h:241
const char * ast_config_AST_KEY_DIR
Definition options.c:162
const char * ast_config_AST_CACHE_DIR
Definition options.c:151
const char * ast_config_AST_MODULE_DIR
Definition options.c:154
const char * ast_config_AST_RUN_DIR
Definition options.c:163
const char * ast_config_AST_DATA_DIR
Definition options.c:159
const char * ast_config_AST_CONFIG_DIR
Definition options.c:152
const char * ast_config_AST_SPOOL_DIR
Definition options.c:155
const char * ast_config_AST_AGI_DIR
Definition options.c:161
const char * ast_config_AST_VAR_DIR
Definition options.c:158
const char * ast_config_AST_SYSTEM_NAME
Definition options.c:171
const char * ast_config_AST_SBIN_DIR
Definition options.c:164
const char * ast_config_AST_LOG_DIR
Definition options.c:160
const char * ast_config_AST_DB
Definition options.c:166
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.
Definition pbx.c:2715
static ast_rwlock_t globalslock
static const char * ast_str_substring(struct ast_str *value, int offset, int length)
static int parse_variable_name(char *var, int *offset, int *length, int *isfunc)
extract offset:length from variable name.
static struct varshead globals
struct ast_var_t::@221 entries
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
Definition utils.c:2873
struct ast_eid ast_eid_default
Global EID.
Definition options.c:94

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_CACHE_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_SBIN_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(), c, ast_var_t::entries, globals, globalslock, NULL, parse_variable_name(), str, and var.

Referenced by ast_ari_asterisk_get_global_var(), ast_ari_channels_get_channel_var(), ast_ari_channels_get_channel_vars(), ast_str_substitute_variables_full2(), and pbx_retrieve_variable().

◆ ast_str_substitute_variables()

void ast_str_substitute_variables ( struct ast_str **  buf,
ssize_t  maxlen,
struct ast_channel chan,
const char *  templ 
)
Parameters
bufResult 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.
chanChannel variables from which to extract values, and channel to pass to any dialplan functions.
templVariable template to expand.

Definition at line 657 of file pbx_variables.c.

658{
659 ast_str_substitute_variables_full(buf, maxlen, chan, NULL, templ, NULL);
660}
void ast_str_substitute_variables_full(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, struct varshead *headp, const char *templ, size_t *used)

References ast_str_substitute_variables_full(), buf, and NULL.

Referenced by acf_odbc_read(), acf_odbc_write(), ast_pbx_exec_application(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), cli_odbc_read(), cli_odbc_write(), config_curl(), cut_internal(), destroy_curl(), do_notify(), exec_exec(), func_mchan_read(), function_eval2(), function_fieldnum_helper(), function_fieldqty_helper(), handle_exec(), handle_exec(), handle_getvariablefull(), import_helper(), json_decode_read(), listfilter(), log_legacy_dsv_record(), make_email_file(), realtime_curl(), realtime_multi_curl(), replace(), require_curl(), sendmail(), sendpage(), shift_pop(), store_curl(), strbetween(), strreplace(), 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().

◆ ast_str_substitute_variables_full()

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
bufResult 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.
cChannel variables from which to extract values, and channel to pass to any dialplan functions.
headpIf no channel is specified, a channel list from which to extract variable values
templVariable template to expand.
usedNumber of bytes read from the template. (May be NULL)

Definition at line 651 of file pbx_variables.c.

653{
654 ast_str_substitute_variables_full2(buf, maxlen, chan, headp, templ, used, 0);
655}
void ast_str_substitute_variables_full2(struct ast_str **buf, ssize_t maxlen, struct ast_channel *c, struct varshead *headp, const char *templ, size_t *used, int use_both)
Perform variable/function/expression substitution on an ast_str.

References ast_str_substitute_variables_full2(), and buf.

Referenced by ast_str_substitute_variables(), and ast_str_substitute_variables_varshead().

◆ ast_str_substitute_variables_full2()

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

Perform variable/function/expression substitution on an ast_str.

Parameters
bufResult 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.
cA channel from which to extract values, and to pass to any dialplan functions.
headpA channel variables list to also search for variables.
templVariable template to expand.
usedNumber of bytes read from the template. (May be NULL)
use_bothNormally, if a channel is specified, headp is ignored. If this parameter is set to 1 and both a channel and headp are specified, the channel will be searched for variables first and any not found will be searched for in headp.

Definition at line 407 of file pbx_variables.c.

410{
411 /* Substitutes variables into buf, based on string templ */
412 const char *whereweare;
413 struct ast_str *substr1 = ast_str_create(16);
414 struct ast_str *substr2 = NULL;
415 struct ast_str *substr3 = ast_str_create(16);
416
418
419 if (!substr1 || !substr3) {
420 if (used) {
421 *used = ast_str_strlen(*buf);
422 }
423 ast_free(substr1);
424 ast_free(substr3);
425 return;
426 }
427
428 whereweare = templ;
429 while (!ast_strlen_zero(whereweare)) {
430 const char *nextvar = NULL;
431 const char *nextexp = NULL;
432 const char *nextthing;
433 const char *vars;
434 const char *vare;
435 char *finalvars;
436 int pos;
437 int brackets;
438 int needsub;
439 int len;
440
441 /* reset our buffer */
442 ast_str_reset(substr3);
443
444 /* Determine how much simply needs to be copied to the output buf. */
445 nextthing = strchr((char *)whereweare, '$');
446 if (nextthing) {
447 pos = nextthing - whereweare;
448 switch (nextthing[1]) {
449 case '{':
450 /* Variable substitution */
451 nextvar = nextthing;
452 break;
453 case '[':
454 /* Expression substitution */
455 nextexp = nextthing;
456 break;
457 default:
458 /* '$' is not part of a substitution so include it too. */
459 ++pos;
460 break;
461 }
462 } else {
463 /* We're copying the whole remaining string */
464 pos = strlen(whereweare);
465 }
466
467 if (pos) {
468 /* Copy that many bytes */
469 ast_str_append_substr(buf, maxlen, whereweare, pos);
470
471 whereweare += pos;
472 }
473
474 if (nextvar) {
475 int offset;
476 int offset2;
477 int isfunction;
478 int res;
479
480 /* We have a variable. Find the start and end, and determine
481 if we are going to have to recursively call ourselves on the
482 contents */
483 vars = vare = nextvar + 2;
484 brackets = 1;
485 needsub = 0;
486
487 /* Find the end of it */
488 while (brackets && *vare) {
489 if ((vare[0] == '$') && (vare[1] == '{')) {
490 needsub++;
491 brackets++;
492 vare++;
493 } else if (vare[0] == '{') {
494 brackets++;
495 } else if (vare[0] == '}') {
496 brackets--;
497 } else if ((vare[0] == '$') && (vare[1] == '[')) {
498 needsub++;
499 vare++;
500 }
501 vare++;
502 }
503 len = vare - vars;
504 if (brackets) {
505 ast_log(LOG_WARNING, "Error in extension logic (missing '}')\n");
506 } else {
507 /* Don't count the closing '}' in the length. */
508 --len;
509 }
510
511 /* Skip totally over variable string */
512 whereweare = vare;
513
514 /* Store variable name expression to lookup. */
515 ast_str_set_substr(&substr1, 0, vars, len);
516 ast_debug(5, "Evaluating '%s' (from '%s' len %d)\n",
517 ast_str_buffer(substr1), vars, len);
518
519 /* Substitute if necessary */
520 if (needsub) {
521 if (!substr2) {
522 substr2 = ast_str_create(16);
523 if (!substr2) {
524 continue;
525 }
526 }
527 ast_str_substitute_variables_full2(&substr2, 0, c, headp,
528 ast_str_buffer(substr1), NULL, use_both);
529 finalvars = ast_str_buffer(substr2);
530 } else {
531 finalvars = ast_str_buffer(substr1);
532 }
533
534 parse_variable_name(finalvars, &offset, &offset2, &isfunction);
535 if (isfunction) {
536 /* Evaluate function */
537 res = -1;
538 if (c) {
539 res = ast_func_read2(c, finalvars, &substr3, 0);
540 ast_debug(2, "Function %s result is '%s' from channel\n",
541 finalvars, res ? "" : ast_str_buffer(substr3));
542 }
543 if (!c || (c && res < 0 && use_both)) {
544 struct varshead old;
545 struct ast_channel *bogus;
546
547 bogus = ast_dummy_channel_alloc();
548 if (bogus) {
549 old = *ast_channel_varshead(bogus);
550 if (headp) {
551 *ast_channel_varshead(bogus) = *headp;
552 }
553 res = ast_func_read2(bogus, finalvars, &substr3, 0);
554 /* Don't deallocate the varshead that was passed in */
555 if (headp) {
556 *ast_channel_varshead(bogus) = old;
557 }
558 ast_channel_unref(bogus);
559 } else {
560 ast_log(LOG_ERROR, "Unable to allocate bogus channel for function value substitution.\n");
561 res = -1;
562 }
563 ast_debug(2, "Function %s result is '%s' from headp\n",
564 finalvars, res ? "" : ast_str_buffer(substr3));
565 }
566 } else {
567 const char *result;
568 if (c) {
569 result = ast_str_retrieve_variable(&substr3, 0, c, NULL, finalvars);
570 ast_debug(2, "Variable %s result is '%s' from channel\n",
571 finalvars, S_OR(result, ""));
572 }
573 if (!c || (c && !result && use_both)) {
574 result = ast_str_retrieve_variable(&substr3, 0, NULL, headp, finalvars);
575 ast_debug(2, "Variable %s result is '%s' from headp\n",
576 finalvars, S_OR(result, ""));
577 }
578 res = (result ? 0 : -1);
579 }
580 if (!res) {
581 ast_str_substring(substr3, offset, offset2);
582 ast_str_append(buf, maxlen, "%s", ast_str_buffer(substr3));
583 }
584 } else if (nextexp) {
585 /* We have an expression. Find the start and end, and determine
586 if we are going to have to recursively call ourselves on the
587 contents */
588 vars = vare = nextexp + 2;
589 brackets = 1;
590 needsub = 0;
591
592 /* Find the end of it */
593 while (brackets && *vare) {
594 if ((vare[0] == '$') && (vare[1] == '[')) {
595 needsub++;
596 brackets++;
597 vare++;
598 } else if (vare[0] == '[') {
599 brackets++;
600 } else if (vare[0] == ']') {
601 brackets--;
602 } else if ((vare[0] == '$') && (vare[1] == '{')) {
603 needsub++;
604 vare++;
605 }
606 vare++;
607 }
608 len = vare - vars;
609 if (brackets) {
610 ast_log(LOG_WARNING, "Error in extension logic (missing ']')\n");
611 } else {
612 /* Don't count the closing ']' in the length. */
613 --len;
614 }
615
616 /* Skip totally over expression */
617 whereweare = vare;
618
619 /* Store expression to evaluate. */
620 ast_str_set_substr(&substr1, 0, vars, len);
621
622 /* Substitute if necessary */
623 if (needsub) {
624 if (!substr2) {
625 substr2 = ast_str_create(16);
626 if (!substr2) {
627 continue;
628 }
629 }
630 ast_str_substitute_variables_full2(&substr2, 0, c, headp,
631 ast_str_buffer(substr1), NULL, use_both);
632 finalvars = ast_str_buffer(substr2);
633 } else {
634 finalvars = ast_str_buffer(substr1);
635 }
636
637 if (ast_str_expr(&substr3, 0, c, finalvars)) {
638 ast_debug(2, "Expression result is '%s'\n", ast_str_buffer(substr3));
639 }
640 ast_str_append(buf, maxlen, "%s", ast_str_buffer(substr3));
641 }
642 }
643 if (used) {
644 *used = ast_str_strlen(*buf);
645 }
646 ast_free(substr1);
647 ast_free(substr2);
648 ast_free(substr3);
649}
int ast_str_expr(struct ast_str **str, ssize_t maxlen, struct ast_channel *chan, char *expr)
Evaluate the given expression.
static PGresult * result
Definition cel_pgsql.c:84
#define ast_dummy_channel_alloc()
Create a fake channel structure.
Definition channel.h:1328
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
const char * ast_str_retrieve_variable(struct ast_str **str, ssize_t maxlen, struct ast_channel *c, struct varshead *headp, const char *var)
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition strings.h:1139
size_t attribute_pure ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition strings.h:730
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition strings.h:80
char * ast_str_append_substr(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc)
Append a non-NULL terminated substring to the end of a dynamic string.
Definition strings.h:1062
char * ast_str_set_substr(struct ast_str **buf, ssize_t maxlen, const char *src, size_t maxsrc)
Set a dynamic string to a non-NULL terminated substring.
Definition strings.h:1055

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_full2(), ast_str_substring(), ast_strlen_zero(), buf, c, len(), LOG_ERROR, LOG_WARNING, NULL, parse_variable_name(), result, and S_OR.

Referenced by ast_str_substitute_variables_full(), ast_str_substitute_variables_full2(), geoloc_eprofile_resolve_string(), and geoloc_eprofile_resolve_varlist().

◆ ast_str_substitute_variables_varshead()

void ast_str_substitute_variables_varshead ( struct ast_str **  buf,
ssize_t  maxlen,
struct varshead headp,
const char *  templ 
)
Parameters
bufResult 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.
headpIf no channel is specified, a channel list from which to extract variable values
templVariable template to expand.

Definition at line 662 of file pbx_variables.c.

663{
664 ast_str_substitute_variables_full(buf, maxlen, NULL, headp, templ, NULL);
665}

References ast_str_substitute_variables_full(), buf, 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().

◆ ast_thread_inhibit_escalations()

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 494 of file pbx_functions.c.

495{
496 int *thread_inhibit_escalations;
497
498 thread_inhibit_escalations = ast_threadstorage_get(
499 &thread_inhibit_escalations_tl, sizeof(*thread_inhibit_escalations));
500 if (thread_inhibit_escalations == NULL) {
501 ast_log(LOG_ERROR, "Error inhibiting privilege escalations for current thread\n");
502 return -1;
503 }
504
505 *thread_inhibit_escalations = 1;
506 return 0;
507}
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.

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

Referenced by ast_add_extension2_lockopt(), and handle_tcptls_connection().

◆ ast_thread_inhibit_escalations_swap()

int ast_thread_inhibit_escalations_swap ( int  inhibit)

Swap the current thread escalation inhibit setting.

Since
11.24.0
Parameters
inhibitNew setting. Non-zero to inhibit.
Return values
1if dangerous function execution was inhibited.
0if dangerous function execution was allowed.
-1on error.

Definition at line 509 of file pbx_functions.c.

510{
511 int *thread_inhibit_escalations;
512 int orig;
513
514 thread_inhibit_escalations = ast_threadstorage_get(
515 &thread_inhibit_escalations_tl, sizeof(*thread_inhibit_escalations));
516 if (thread_inhibit_escalations == NULL) {
517 ast_log(LOG_ERROR, "Error swapping privilege escalations inhibit for current thread\n");
518 return -1;
519 }
520
521 orig = *thread_inhibit_escalations;
522 *thread_inhibit_escalations = !!inhibit;
523 return orig;
524}

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

Referenced by ast_add_extension2_lockopt().

◆ ast_unlock_context()

int ast_unlock_context ( struct ast_context con)

◆ ast_unlock_contexts()

int ast_unlock_contexts ( void  )

◆ ast_unregister_switch()

void ast_unregister_switch ( struct ast_switch sw)

Unregister an alternative switch.

Parameters
swswitch to unregister

Unregisters a switch from asterisk.

Definition at line 76 of file pbx_switch.c.

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and ast_switch::list.

Referenced by __unload_module(), unload_module(), unload_module(), unload_module(), and unload_module().

◆ ast_walk_context_extensions()

static struct ast_exten * ast_walk_context_extensions ( struct ast_context con,
struct ast_exten priority 
)

◆ ast_walk_context_ignorepats()

const struct ast_ignorepat * ast_walk_context_ignorepats ( const struct ast_context con,
const struct ast_ignorepat ip 
)

Definition at line 6847 of file pbx.c.

6849{
6850 if (!con) {
6851 return NULL;
6852 }
6853
6854 if (ip) {
6855 int idx;
6856 int next = 0;
6857
6858 for (idx = 0; idx < ast_context_ignorepats_count(con); idx++) {
6859 const struct ast_ignorepat *i = ast_context_ignorepats_get(con, idx);
6860
6861 if (next) {
6862 return i;
6863 }
6864
6865 if (ip == i) {
6866 next = 1;
6867 }
6868 }
6869
6870 return NULL;
6871 }
6872
6873 if (!ast_context_ignorepats_count(con)) {
6874 return NULL;
6875 }
6876
6877 return ast_context_ignorepats_get(con, 0);
6878}
struct ast_ignorepat * next
Definition extconf.c:2386

References ast_context_ignorepats_count(), ast_context_ignorepats_get(), ast_ignorepat::next, and NULL.

◆ ast_walk_context_includes()

const struct ast_include * ast_walk_context_includes ( const struct ast_context con,
const struct ast_include inc 
)

Definition at line 6808 of file pbx.c.

6810{
6811 if (inc) {
6812 int idx;
6813 int next = 0;
6814
6815 for (idx = 0; idx < ast_context_includes_count(con); idx++) {
6816 const struct ast_include *include = AST_VECTOR_GET(&con->includes, idx);
6817
6818 if (next) {
6819 return include;
6820 }
6821
6822 if (inc == include) {
6823 next = 1;
6824 }
6825 }
6826
6827 return NULL;
6828 }
6829
6830 if (!ast_context_includes_count(con)) {
6831 return NULL;
6832 }
6833
6834 return ast_context_includes_get(con, 0);
6835}
struct ast_include * next
Definition extconf.c:2368

References ast_context_includes_count(), ast_context_includes_get(), AST_VECTOR_GET, ast_context::includes, ast_include::next, and NULL.

Referenced by context_included().

◆ ast_walk_context_switches()

const struct ast_sw * ast_walk_context_switches ( const struct ast_context con,
const struct ast_sw sw 
)

Definition at line 6763 of file pbx.c.

6765{
6766 if (sw) {
6767 int idx;
6768 int next = 0;
6769
6770 for (idx = 0; idx < ast_context_switches_count(con); idx++) {
6771 const struct ast_sw *s = ast_context_switches_get(con, idx);
6772
6773 if (next) {
6774 return s;
6775 }
6776
6777 if (sw == s) {
6778 next = 1;
6779 }
6780 }
6781
6782 return NULL;
6783 }
6784
6785 if (!ast_context_switches_count(con)) {
6786 return NULL;
6787 }
6788
6789 return ast_context_switches_get(con, 0);
6790}
const struct ast_sw * ast_context_switches_get(const struct ast_context *con, int idx)
Definition pbx.c:6797
struct ast_sw * next
Definition pbx_sw.c:44

References ast_context_switches_count(), ast_context_switches_get(), ast_sw::next, and NULL.

◆ ast_walk_contexts()

static struct ast_context * ast_walk_contexts ( struct ast_context con)

Definition at line 4022 of file extconf.c.

4023{
4024 return con ? con->next : contexts;
4025}
static struct ast_context * contexts
Definition extconf.c:3595

References contexts, contexts, and ast_context::next.

◆ ast_walk_extension_priorities()

static struct ast_exten * ast_walk_extension_priorities ( struct ast_exten exten,
struct ast_exten priority 
)

◆ ast_wrlock_context()

int ast_wrlock_context ( struct ast_context con)

◆ ast_wrlock_contexts()

int ast_wrlock_contexts ( void  )

◆ pbx_builtin_clear_globals()

void pbx_builtin_clear_globals ( void  )

Definition at line 1353 of file pbx_variables.c.

1354{
1355 struct ast_var_t *vardata;
1356
1358 while ((vardata = AST_LIST_REMOVE_HEAD(&globals, entries)))
1359 ast_var_delete(vardata);
1361}
void ast_var_delete(struct ast_var_t *var)
Definition extconf.c:2469

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

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

◆ pbx_builtin_getvar_helper()

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;
if ((var = pbx_builtin_getvar_helper(chan, "MYVAR"))) {
}
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.

Definition at line 1162 of file pbx_variables.c.

1163{
1164 struct ast_var_t *variables;
1165 const char *ret = NULL;
1166 int i;
1167 struct varshead *places[2] = { NULL, &globals };
1168
1169 if (!name)
1170 return NULL;
1171
1172 if (chan) {
1173 ast_channel_lock(chan);
1174 places[0] = ast_channel_varshead(chan);
1175 }
1176
1177 for (i = 0; i < 2; i++) {
1178 if (!places[i])
1179 continue;
1180 if (places[i] == &globals)
1182 AST_LIST_TRAVERSE(places[i], variables, entries) {
1183 if (!strcmp(name, ast_var_name(variables))) {
1184 ret = ast_var_value(variables);
1185 break;
1186 }
1187 }
1188 if (places[i] == &globals)
1190 if (ret)
1191 break;
1192 }
1193
1194 if (chan)
1195 ast_channel_unlock(chan);
1196
1197 return ret;
1198}

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(), globals, globalslock, name, and NULL.

Referenced by __ast_pbx_run(), _while_exec(), action_agents(), add_header_from_channel_var(), agent_handle_show_specific(), agent_login_channel_config(), agent_request_exec(), agent_show_requested(), analog_call(), analog_callwaiting_deluxe(), array(), ast_bridge_add_channel(), ast_bridge_call_with_flags(), ast_bridge_timelimit(), ast_bridge_transfer_attended(), ast_call_forward(), ast_channel_connected_line_sub(), ast_channel_get_ari_vars(), ast_channel_redirecting_sub(), ast_eivr_getvariable(), ast_get_chan_applicationmap(), ast_unreal_hangup(), attended_transfer_exec(), bridge_parking_push(), channel_get_external_vars(), check_bridge_play_sound(), common_exec(), conf_run(), create_dynamic_lot_full(), crement_function_read(), dahdi_hangup(), dial_exec_full(), do_forward(), dundi_exec(), eagi_exec(), eval_sub_read(), feature_automixmonitor(), feature_blind_transfer(), find_by_mark(), find_channel_parking_lot_name(), find_conf_realtime(), func_channel_read(), generate_parked_user(), generic_fax_exec(), get_index(), get_index(), get_transfer_context(), get_transfer_exten(), global_exists_read(), global_read(), gosub_run(), handle_call_forward(), handle_exec(), handle_gosub(), handle_hangup(), hash_read(), iax2_call(), iax2_exec(), if_helper(), leave_voicemail(), local_read(), manager_mixmonitor(), meetme_menu_admin_extended(), minivm_delete_exec(), minivm_notify_exec(), morsecode_exec(), notify_new_message(), notify_new_message(), ooh323_call(), ooh323_hangup(), park_app_exec(), pbx_builtin_gotoiftime(), permit_dtmf_interrupt(), pjsip_acf_parse_uri_read(), pre_bridge_setup(), queue_exec(), receive_ademco_event(), refer_blind_callback(), report_receive_fax_status(), report_send_fax_status(), retrydial_exec(), run_agi(), sayunixtime_exec(), sendtext_exec(), set_from_header(), set_touch_variable(), set_transfer_variables_all(), setup_mixmonitor(), setup_park_common_datastore(), sla_trunk_exec(), speech_background(), transfer_refer(), try_calling(), variable_exists_read(), wait_for_answer(), and wait_for_answer().

◆ pbx_builtin_pushvar_helper()

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 1200 of file pbx_variables.c.

1201{
1202 struct ast_var_t *newvariable;
1203 struct varshead *headp;
1204
1205 if (name[strlen(name)-1] == ')') {
1206 char *function = ast_strdupa(name);
1207
1208 ast_log(LOG_WARNING, "Cannot push a value onto a function\n");
1209 ast_func_write(chan, function, value);
1210 return;
1211 }
1212
1213 if (chan) {
1214 ast_channel_lock(chan);
1215 headp = ast_channel_varshead(chan);
1216 } else {
1218 headp = &globals;
1219 }
1220
1221 if (value && (newvariable = ast_var_assign(name, value))) {
1222 if (headp == &globals)
1223 ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
1224 AST_LIST_INSERT_HEAD(headp, newvariable, entries);
1225 }
1226
1227 if (chan)
1228 ast_channel_unlock(chan);
1229 else
1231}
#define ast_var_assign(name, value)
Definition chanvars.h:40
int ast_func_write(struct ast_channel *chan, const char *function, const char *value)
executes a write operation on a function

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, globals, globalslock, LOG_WARNING, name, and value.

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

◆ pbx_builtin_raise_exception()

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

Definition at line 810 of file pbx_builtins.c.

811{
812 /* Priority will become 1, next time through the AUTOLOOP */
813 return raise_exception(chan, reason, 0);
814}
int raise_exception(struct ast_channel *chan, const char *reason, int priority)
Definition pbx.c:2432

References raise_exception().

◆ pbx_builtin_serialize_variables()

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
chanChannel from which to read variables
bufDynamic 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 1131 of file pbx_variables.c.

1132{
1133 struct ast_var_t *variables;
1134 const char *var, *val;
1135 int total = 0;
1136
1137 if (!chan)
1138 return 0;
1139
1141
1142 ast_channel_lock(chan);
1143
1145 if ((var = ast_var_name(variables)) && (val = ast_var_value(variables))
1146 /* && !ast_strlen_zero(var) && !ast_strlen_zero(val) */
1147 ) {
1148 if (ast_str_append(buf, 0, "%s=%s\n", var, val) < 0) {
1149 ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n");
1150 break;
1151 } else
1152 total++;
1153 } else
1154 break;
1155 }
1156
1157 ast_channel_unlock(chan);
1158
1159 return total;
1160}
static int total
Definition res_adsi.c:970

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(), buf, ast_var_t::entries, LOG_ERROR, total, and var.

Referenced by ast_var_channels_table(), and dumpchan_exec().

◆ pbx_builtin_setvar()

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 1291 of file pbx_variables.c.

1292{
1293 char *name, *value, *mydata;
1294
1295 if (ast_strlen_zero(data)) {
1296 ast_log(LOG_WARNING, "Set requires one variable name/value pair.\n");
1297 return 0;
1298 }
1299
1300 mydata = ast_strdupa(data);
1301 name = strsep(&mydata, "=");
1302 value = mydata;
1303 if (!value) {
1304 ast_log(LOG_WARNING, "Set requires an '=' to be a valid assignment.\n");
1305 return 0;
1306 }
1307
1308 if (strchr(name, ' ')) {
1309 ast_log(LOG_WARNING, "Please avoid unnecessary spaces on variables as it may lead to unexpected results ('%s' set to '%s').\n", name, mydata);
1310 }
1311
1313
1314 return 0;
1315}
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.

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

Referenced by ast_compile_ael2(), and load_pbx_variables().

◆ pbx_builtin_setvar_helper()

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

True if the old value was not an empty string.

Definition at line 1233 of file pbx_variables.c.

1234{
1235 struct ast_var_t *newvariable;
1236 struct varshead *headp;
1237 const char *nametail = name;
1238 /*! True if the old value was not an empty string. */
1239 int old_value_existed = 0;
1240
1241 if (name[strlen(name) - 1] == ')') {
1242 char *function = ast_strdupa(name);
1243
1244 return ast_func_write(chan, function, value);
1245 }
1246
1247 if (chan) {
1248 ast_channel_lock(chan);
1249 headp = ast_channel_varshead(chan);
1250 } else {
1252 headp = &globals;
1253 }
1254
1255 /* For comparison purposes, we have to strip leading underscores */
1256 if (*nametail == '_') {
1257 nametail++;
1258 if (*nametail == '_')
1259 nametail++;
1260 }
1261
1262 AST_LIST_TRAVERSE_SAFE_BEGIN(headp, newvariable, entries) {
1263 if (strcmp(ast_var_name(newvariable), nametail) == 0) {
1264 /* there is already such a variable, delete it */
1265 AST_LIST_REMOVE_CURRENT(entries);
1266 old_value_existed = !ast_strlen_zero(ast_var_value(newvariable));
1267 ast_var_delete(newvariable);
1268 break;
1269 }
1270 }
1272
1273 if (value && (newvariable = ast_var_assign(name, value))) {
1274 if (headp == &globals) {
1275 ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
1276 }
1277 AST_LIST_INSERT_HEAD(headp, newvariable, entries);
1279 } else if (old_value_existed) {
1280 /* We just deleted a non-empty dialplan variable. */
1282 }
1283
1284 if (chan)
1285 ast_channel_unlock(chan);
1286 else
1288 return 0;
1289}
void ast_channel_publish_varset(struct ast_channel *chan, const char *variable, const char *value)
Publish a ast_channel_publish_varset for a channel.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.

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_strlen_zero(), ast_var_assign, ast_var_delete(), ast_var_name(), ast_var_value(), ast_verb, globals, globalslock, name, and value.

Referenced by __analog_ss_thread(), __ast_pbx_run(), _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(), analog_ss_thread(), app_control_set_channel_var(), app_exec(), aqm_exec(), array(), ast_ari_asterisk_set_global_var(), ast_bridge_set_transfer_variables(), ast_bridge_vars_set(), ast_call_forward(), ast_cc_agent_set_interfaces_chanvar(), ast_eivr_setvariable(), ast_iax2_new(), ast_pbx_outgoing_exten_predial(), ast_pickup_call(), ast_set_cc_interfaces_chanvar(), ast_set_variables(), AST_TEST_DEFINE(), ast_unreal_hangup(), asyncgoto_exec(), attended_transfer_bridge(), attended_transfer_exec(), audiosocket_request(), background_detect_exec(), begin_dial_channel(), blind_transfer_bridge(), blind_transfer_exec(), bridge_channel_internal_push_full(), bridge_exec(), bridgeadd_exec(), calendar_write_exec(), caller_joined_bridge(), caller_safety_timeout(), 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(), confkick_exec(), controlplayback_exec(), count_exec(), crement_function_read(), dahdi_handle_dtmf(), dahdi_new(), delete_write(), dial_exec_full(), dial_transfer(), directory_exec(), disa_exec(), do_directory(), do_forward(), do_notify(), do_waiting(), dtmf_store_framehook(), dynamic_dtmf_hook_callback(), end_bridge_callback(), execute_menu_entry(), fax_detect_framehook(), frame_set_var(), func_export_write(), func_mchan_write(), function_db_delete(), function_db_exists(), function_db_read(), function_realtime_store(), generic_recall(), geoloc_profile_read(), geoloc_profile_write(), global_delete_write(), global_write(), gosub_release_frame(), gosub_run(), handle_controlstreamfile(), handle_gosub(), handle_incoming_request(), handle_outgoing_response(), handle_response_cmgr(), handle_set_chanvar(), handle_set_global(), handle_setvariable(), handle_streamfile(), hash_read(), hash_write(), if_helper(), isAnsweringMachine(), kick_conference_participant(), launch_monitor_thread(), leave_marked(), leave_queue(), leave_voicemail(), leave_voicemail(), lua_set_variable(), lua_set_variable_value(), manager_park(), mbl_status_exec(), minivm_accmess_exec(), minivm_delete_exec(), minivm_greet_exec(), minivm_notify_exec(), minivm_record_exec(), mixmonitor_exec(), msg_send_exec(), my_get_callerid(), my_handle_dtmf(), onModeChanged(), ooh323_new(), ooh323_rtp_read(), originate_exec(), parking_duration_callback(), parking_timeout_set_caller_features(), pbx_builtin_background(), pbx_builtin_gotoiftime(), pbx_builtin_setvar(), pbx_builtin_setvar_multiple(), pbx_builtin_waitdigit(), pbx_load_config(), play_message_datetime(), playback_exec(), pqm_exec(), prep_email_sub_vars(), prep_email_sub_vars(), privacy_exec(), queue_exec(), read_exec(), read_mf_digits(), read_mf_exec(), read_sf_digits(), read_sf_exec(), readexten_exec(), realtimefield_read(), receivefax_exec(), record_abandoned(), record_exec(), recvtext_exec(), refer_blind_callback(), reload_exec(), reload_module(), return_exec(), ring_entry(), rollback_exec(), rotate_file(), rqm_exec(), scan_exec(), select_entry(), select_item_menu(), select_item_seq(), sendfax_exec(), sendtext_exec(), set(), set_channel_variables(), set_channel_variables(), set_duration_var(), set_duration_var(), set_queue_result(), set_sipdomain_variable(), shift_pop(), signal_exec(), sla_calc_trunk_timeouts(), sla_station_exec(), sla_trunk_exec(), speech_create(), start_automixmonitor(), stasis_broadcast_exec(), system_exec_helper(), test_chan_variable(), testtime_write(), transfer_exec(), tryexec_exec(), unicast_rtp_request(), unshift_push(), update_qe_rule(), upqm_exec(), user_timeout(), vm_exec(), vm_playmsgexec(), vmauthenticate(), wait_exec(), wait_for_answer(), wait_for_signal_or_hangup(), waitforcond_exec(), waitsignal_exec(), waituntil_exec(), and zapateller_exec().

◆ pbx_builtin_setvar_multiple()

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 1317 of file pbx_variables.c.

1318{
1319 char *data;
1320 int x;
1322 AST_APP_ARG(pair)[99]; /* parse up to 99 variables */
1323 );
1327 );
1328
1329 if (ast_strlen_zero(vdata)) {
1330 ast_log(LOG_WARNING, "MSet requires at least one variable name/value pair.\n");
1331 return 0;
1332 }
1333
1334 data = ast_strdupa(vdata);
1336
1337 for (x = 0; x < args.argc; x++) {
1338 AST_NONSTANDARD_APP_ARGS(pair, args.pair[x], '=');
1339 if (pair.argc == 2) {
1341 if (strchr(pair.name, ' '))
1342 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);
1343 } else if (!chan) {
1344 ast_log(LOG_WARNING, "MSet: ignoring entry '%s' with no '='\n", pair.name);
1345 } else {
1346 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));
1347 }
1348 }
1349
1350 return 0;
1351}
#define AST_APP_ARG(name)
Define an application argument.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)
Performs the 'nonstandard' argument separation process for an application.
const char * name
Definition test_config.c:85

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, name, pair::name, pbx_builtin_setvar_helper(), and value.

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

◆ pbx_checkcondition()

int pbx_checkcondition ( const char *  condition)

Evaluate a condition.

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

Definition at line 6568 of file pbx.c.

6569{
6570 int res;
6571 if (ast_strlen_zero(condition)) { /* NULL or empty strings are false */
6572 return 0;
6573 } else if (sscanf(condition, "%30d", &res) == 1) { /* Numbers are evaluated for truth */
6574 return res;
6575 } else { /* Strings are true */
6576 return 1;
6577 }
6578}

References ast_strlen_zero().

Referenced by _while_exec(), acf_if(), execif_exec(), gosubif_exec(), if_helper(), pbx_builtin_gotoif(), testtime_write(), and waitforcond_exec().

◆ pbx_exec()

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

Execute an application.

Parameters
cchannel to execute on
appwhich app to execute
datathe 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
0success
-1failure
Note
This function is special. It saves the stack so that no matter how many times it is called, it returns to the same place
Parameters
cChannel
appApplication
dataData for execution

Definition at line 483 of file pbx_app.c.

486{
487 int res;
488 struct ast_module_user *u = NULL;
489 const char *saved_c_appl;
490 const char *saved_c_data;
491
492 /* save channel values */
493 saved_c_appl= ast_channel_appl(c);
494 saved_c_data= ast_channel_data(c);
495
498 ast_channel_data_set(c, data);
501
502 if (app->module)
503 u = __ast_module_user_add(app->module, c);
504 res = app->execute(c, S_OR(data, ""));
505 if (app->module && u)
506 __ast_module_user_remove(app->module, u);
507 /* restore channel values */
508 ast_channel_appl_set(c, saved_c_appl);
509 ast_channel_data_set(c, saved_c_data);
510 return res;
511}
void ast_channel_appl_set(struct ast_channel *chan, const char *value)
const char * ast_channel_data(const struct ast_channel *chan)
void ast_channel_data_set(struct ast_channel *chan, const char *value)
const char * ast_channel_appl(const struct ast_channel *chan)
const char * name

References __ast_module_user_add(), __ast_module_user_remove(), app, ast_channel_appl(), ast_channel_appl_set(), ast_channel_data(), ast_channel_data_set(), ast_channel_lock, ast_channel_publish_snapshot(), ast_channel_unlock, c, test_val::name, NULL, and S_OR.

Referenced by aelsub_exec(), ari_channel_thread(), ari_originate_dial(), ast_pbx_exec_application(), AST_TEST_DEFINE(), bridge_stasis_run_cb(), conf_run(), conf_start_record(), exec_exec(), execif_exec(), forward_message(), handle_exec(), handle_exec(), iax2_exec(), lua_pbx_exec(), page_exec(), pbx_extension_helper(), pbx_outgoing_exec(), realtime_exec(), try_calling(), and tryexec_exec().

◆ pbx_find_extension()

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 
)

Definition at line 152 of file ael_main.c.

161{
162 return localized_find_extension(bypass, q, context, exten, priority, label, callerid, action);
163}
struct ast_exten * localized_find_extension(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)
Definition extconf.c:4466

References ast_autoservice_start(), ast_autoservice_stop(), ast_context_includes_count(), ast_context_includes_get(), ast_context_switches_count(), ast_context_switches_get(), ast_debug, ast_get_switch_data(), ast_get_switch_eval(), ast_get_switch_name(), ast_hashtab_lookup(), ast_log, AST_PBX_MAX_STACK, ast_str_buffer(), ast_str_size(), ast_str_thread_get(), ast_strdupa, ast_strlen_zero(), ast_walk_context_extensions(), ast_switch::canmatch, scoreboard::canmatch_exten, create_match_char_tree(), pbx_find_info::data, ast_context::data, E_CANMATCH, E_FINDLABEL, E_MATCHMORE, ast_switch::exists, ast_exten::exten, scoreboard::exten, extenpatternmatchnew, extension_match_core(), find_context(), pbx_find_info::foundcontext, include_rname(), include_valid(), pbx_find_info::incstack, ast_exten::label, scoreboard::last_char, localized_find_extension(), LOG_NOTICE, LOG_WARNING, match(), matchcid(), ast_switch::matchmore, name, new_find_extension(), scoreboard::node, NULL, overrideswitch, ast_context::pattern_tree, pbx_find_extension(), pbx_findswitch(), pbx_substitute_variables_helper(), priority, ast_exten::priority, ast_context::root_table, pbx_find_info::stacklen, pbx_find_info::status, STATUS_NO_CONTEXT, STATUS_NO_EXTENSION, STATUS_NO_LABEL, STATUS_NO_PRIORITY, STATUS_SUCCESS, strsep(), pbx_find_info::swo, scoreboard::total_length, scoreboard::total_specificity, and trie_find_next_match().

Referenced by add_extension(), ast_get_extension_data(), ast_hint_extension_nolock(), ast_sip_persistent_endpoint_update_state(), check_goto(), check_pval_item(), conf_ended(), context_merge(), delete_extens(), extension_state_autohints_device_state_cb(), extension_state_get(), parking_blind_transfer_park(), parking_duration_callback(), parking_is_exten_park(), parking_lot_cfg_create_extensions(), pbx_extension_helper(), pbx_find_extension(), and test_exten().

◆ pbx_findapp()

struct ast_app * pbx_findapp ( const char *  app)

Look up an application.

Parameters
appname 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

Definition at line 165 of file ael_main.c.

166{
167 return (struct ast_app*)1; /* so as not to trigger an error */
168}

References app, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, and pbx_findapp_nolock().

Referenced by aelsub_exec(), ari_channel_thread(), ari_originate_dial(), ast_pbx_exec_application(), AST_TEST_DEFINE(), bridge_stasis_run_cb(), conf_run(), conf_start_record(), exec_exec(), execif_exec(), forward_message(), handle_exec(), handle_exec(), iax2_exec(), lua_pbx_exec(), page_exec(), pbx_extension_helper(), pbx_outgoing_exec(), realtime_exec(), try_calling(), and tryexec_exec().

◆ pbx_live_dangerously()

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_dangerouslyIf true, enable the execution of escalating functions from external protocols.

Definition at line 481 of file pbx_functions.c.

482{
483 if (new_live_dangerously && !live_dangerously) {
484 ast_log(LOG_WARNING, "Privilege escalation protection disabled!\n"
485 "See https://docs.asterisk.org/Configuration/Dialplan/Privilege-Escalations-with-Dialplan-Functions/ for more details.\n");
486 }
487
488 if (!new_live_dangerously && live_dangerously) {
489 ast_log(LOG_NOTICE, "Privilege escalation protection enabled.\n");
490 }
491 live_dangerously = new_live_dangerously;
492}
static int live_dangerously
Set to true (non-zero) to globally allow all dangerous dialplan functions to run.

References ast_log, live_dangerously, LOG_NOTICE, and LOG_WARNING.

Referenced by load_asterisk_conf().

◆ pbx_parse_location()

int pbx_parse_location ( struct ast_channel chan,
char **  context,
char **  exten,
char **  pri,
int *  ipri,
int *  mode,
char *  rest 
)

Parses a dialplan location into context, extension, priority.

Parameters
chanChannel to execute on
contextPointer to initial value for context.
extenPointer to initial value for exten.
priPointer to initial value for pri
ipriPointer to integer value of priority
modePointer to mode (or NULL if mode is not used)
restPointer to buffer to capture rest of parsing (or NULL if not used)

strsep should be used to initially populate context, exten, and pri prior to calling this function. All arguments are modified in place.

Return values
0success
non-zerofailure

Definition at line 6949 of file pbx.c.

6950{
6951 char *context, *exten, *pri;
6952 /* do the strsep before here, so we don't have to alloc and free */
6953 if (!*extenp) {
6954 /* Only a priority in this one */
6955 *prip = *contextp;
6956 *extenp = NULL;
6957 *contextp = NULL;
6958 } else if (!*prip) {
6959 /* Only an extension and priority in this one */
6960 *prip = *extenp;
6961 *extenp = *contextp;
6962 *contextp = NULL;
6963 }
6964 context = *contextp;
6965 exten = *extenp;
6966 pri = *prip;
6967 if (mode) {
6968 if (*pri == '+') {
6969 *mode = 1;
6970 pri++;
6971 } else if (*pri == '-') {
6972 *mode = -1;
6973 pri++;
6974 }
6975 }
6976 if ((rest && sscanf(pri, "%30d%1s", ipri, rest) != 1) || sscanf(pri, "%30d", ipri) != 1) {
6977 *ipri = ast_findlabel_extension(chan, context ? context : ast_channel_context(chan),
6978 exten ? exten : ast_channel_exten(chan), pri,
6980 if (*ipri < 1) {
6981 ast_log(LOG_WARNING, "Priority '%s' must be a number > 0, or valid label\n", pri);
6982 return -1;
6983 } else if (mode) {
6984 *mode = 0;
6985 }
6986 }
6987 return 0;
6988}
enum queue_result id
Definition app_queue.c:1790
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.
Definition pbx.c:2740

References ast_channel_caller(), ast_channel_context(), ast_channel_exten(), ast_findlabel_extension(), ast_log, ast_channel::context, ast_channel::exten, LOG_WARNING, NULL, and S_COR.

Referenced by eval_exten_read(), and pbx_parseable_goto().

◆ pbx_retrieve_variable()

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 246 of file pbx_variables.c.

247{
248 struct ast_str *str = ast_str_create(16);
249 const char *cret;
250
251 cret = ast_str_retrieve_variable(&str, 0, c, headp, var);
252 ast_copy_string(workspace, ast_str_buffer(str), workspacelen);
253 *ret = cret ? workspace : NULL;
254 ast_free(str);
255}

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

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

◆ pbx_set_autofallthrough()

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 3330 of file pbx.c.

3331{
3332 int oldval = autofallthrough;
3333 autofallthrough = newval;
3334 return oldval;
3335}
static int autofallthrough
Definition pbx.c:417

References autofallthrough.

Referenced by pbx_load_module().

◆ pbx_set_extenpatternmatchnew()

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 3337 of file pbx.c.

3338{
3339 int oldval = extenpatternmatchnew;
3340 extenpatternmatchnew = newval;
3341 return oldval;
3342}
static int extenpatternmatchnew
Definition pbx.c:418

References extenpatternmatchnew.

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

◆ pbx_set_overrideswitch()

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 3344 of file pbx.c.

3345{
3346 if (overrideswitch) {
3348 }
3349 if (!ast_strlen_zero(newval)) {
3350 overrideswitch = ast_strdup(newval);
3351 } else {
3353 }
3354}
static char * overrideswitch
Definition pbx.c:419

References ast_free, ast_strdup, ast_strlen_zero(), NULL, and overrideswitch.

Referenced by pbx_load_module().

◆ pbx_substitute_variables_helper()

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

◆ pbx_substitute_variables_helper_full()

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 667 of file pbx_variables.c.

668{
669 pbx_substitute_variables_helper_full_location(c, headp, cp1, cp2, count, used, NULL, NULL, 0);
670}
void pbx_substitute_variables_helper_full_location(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int count, size_t *used, const char *context, const char *exten, int pri)
Substitutes variables, similar to pbx_substitute_variables_helper_full, but allows passing the contex...

References c, NULL, and pbx_substitute_variables_helper_full_location().

Referenced by pbx_substitute_variables_helper(), and pbx_substitute_variables_varshead().

◆ pbx_substitute_variables_helper_full_location()

void pbx_substitute_variables_helper_full_location ( struct ast_channel c,
struct varshead headp,
const char *  cp1,
char *  cp2,
int  cp2_size,
size_t *  used,
const char *  context,
const char *  exten,
int  pri 
)

Substitutes variables, similar to pbx_substitute_variables_helper_full, but allows passing the context, extension, and priority in.

Definition at line 677 of file pbx_variables.c.

678{
679 /* Substitutes variables into cp2, based on string cp1, cp2 NO LONGER NEEDS TO BE ZEROED OUT!!!! */
680 const char *whereweare;
681 const char *orig_cp2 = cp2;
682 char ltmp[VAR_BUF_SIZE];
683 char var[VAR_BUF_SIZE];
684 int *recurse_depth;
685
686 *cp2 = 0; /* just in case nothing ends up there */
687
688 /* It is possible to craft dialplan that will recurse indefinitely and cause a stack overflow.
689 * This is symptomatic of a dialplan bug, so abort substitution rather than crash. */
690 recurse_depth = ast_threadstorage_get(&varsub_recurse_level, sizeof(*recurse_depth));
691 if (!recurse_depth) {
692 return;
693 }
694 if ((*recurse_depth)++ >= MAX_VARIABLE_SUB_RECURSE_DEPTH) {
695 ast_log(LOG_ERROR, "Exceeded maximum variable substitution recursion depth (%d) - possible infinite recursion in dialplan?\n", MAX_VARIABLE_SUB_RECURSE_DEPTH);
696 (*recurse_depth)--;
697 return;
698 }
699
700 whereweare = cp1;
701 while (!ast_strlen_zero(whereweare) && count) {
702 char *nextvar = NULL;
703 char *nextexp = NULL;
704 char *nextthing;
705 char *vars;
706 char *vare;
707 int length;
708 int pos;
709 int brackets;
710 int needsub;
711 int len;
712
713 /* Determine how much simply needs to be copied to the output buf. */
714 nextthing = strchr((char *)whereweare, '$');
715 if (nextthing) {
716 pos = nextthing - whereweare;
717 switch (nextthing[1]) {
718 case '{':
719 /* Variable substitution */
720 nextvar = nextthing;
721 break;
722 case '[':
723 /* Expression substitution */
724 nextexp = nextthing;
725 break;
726 default:
727 /* '$' is not part of a substitution so include it too. */
728 ++pos;
729 break;
730 }
731 } else {
732 /* We're copying the whole remaining string */
733 pos = strlen(whereweare);
734 }
735
736 if (pos) {
737 /* Can't copy more than 'count' bytes */
738 if (pos > count)
739 pos = count;
740
741 /* Copy that many bytes */
742 memcpy(cp2, whereweare, pos);
743
744 count -= pos;
745 cp2 += pos;
746 whereweare += pos;
747 *cp2 = 0;
748 }
749
750 if (nextvar) {
751 int offset;
752 int offset2;
753 int isfunction;
754 char *cp4 = NULL;
755 char workspace[VAR_BUF_SIZE] = "";
756
757 /* We have a variable. Find the start and end, and determine
758 if we are going to have to recursively call ourselves on the
759 contents */
760 vars = vare = nextvar + 2;
761 brackets = 1;
762 needsub = 0;
763
764 /* Find the end of it */
765 while (brackets && *vare) {
766 if ((vare[0] == '$') && (vare[1] == '{')) {
767 needsub++;
768 brackets++;
769 vare++;
770 } else if (vare[0] == '{') {
771 brackets++;
772 } else if (vare[0] == '}') {
773 brackets--;
774 } else if ((vare[0] == '$') && (vare[1] == '[')) {
775 needsub++;
776 vare++;
777 }
778 vare++;
779 }
780 len = vare - vars;
781 if (brackets) {
782 ast_log(LOG_WARNING, "Error in extension logic (missing '}')\n");
783 } else {
784 /* Don't count the closing '}' in the length. */
785 --len;
786 }
787
788 /* Skip totally over variable string */
789 whereweare = vare;
790
791 /* Store variable name expression to lookup (and truncate). */
792 ast_copy_string(var, vars, len + 1);
793
794 /* Substitute if necessary */
795 if (needsub) {
796 pbx_substitute_variables_helper_full_location(c, headp, var, ltmp, VAR_BUF_SIZE - 1, NULL, context, exten, pri);
797 vars = ltmp;
798 } else {
799 vars = var;
800 }
801
802 parse_variable_name(vars, &offset, &offset2, &isfunction);
803 if (isfunction) {
804 /* Evaluate function */
805 if (c || !headp)
806 cp4 = ast_func_read(c, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace;
807 else {
808 struct varshead old;
809 struct ast_channel *bogus;
810
811 bogus = ast_dummy_channel_alloc();
812 if (bogus) {
813 old = *ast_channel_varshead(bogus);
814 *ast_channel_varshead(bogus) = *headp;
815 cp4 = ast_func_read(bogus, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace;
816 /* Don't deallocate the varshead that was passed in */
817 *ast_channel_varshead(bogus) = old;
818 ast_channel_unref(bogus);
819 } else {
820 ast_log(LOG_ERROR, "Unable to allocate bogus channel for function value substitution.\n");
821 cp4 = NULL;
822 }
823 }
824 ast_debug(2, "Function %s result is '%s'\n", vars, cp4 ? cp4 : "(null)");
825 } else {
826 /* Retrieve variable value */
827 /* For dialplan location, if we were told what to substitute explicitly, use that instead */
828 if (exten && !strcmp(vars, "EXTEN")) {
830 cp4 = workspace;
831 } else if (context && !strcmp(vars, "CONTEXT")) {
833 cp4 = workspace;
834 } else if (pri && !strcmp(vars, "PRIORITY")) {
835 snprintf(workspace, VAR_BUF_SIZE, "%d", pri);
836 cp4 = workspace;
837 } else {
838 pbx_retrieve_variable(c, vars, &cp4, workspace, VAR_BUF_SIZE, headp);
839 }
840 }
841 if (cp4) {
842 cp4 = substring(cp4, offset, offset2, workspace, VAR_BUF_SIZE);
843
844 length = strlen(cp4);
845 if (length > count)
846 length = count;
847 memcpy(cp2, cp4, length);
848 count -= length;
849 cp2 += length;
850 *cp2 = 0;
851 }
852 } else if (nextexp) {
853 /* We have an expression. Find the start and end, and determine
854 if we are going to have to recursively call ourselves on the
855 contents */
856 vars = vare = nextexp + 2;
857 brackets = 1;
858 needsub = 0;
859
860 /* Find the end of it */
861 while (brackets && *vare) {
862 if ((vare[0] == '$') && (vare[1] == '[')) {
863 needsub++;
864 brackets++;
865 vare++;
866 } else if (vare[0] == '[') {
867 brackets++;
868 } else if (vare[0] == ']') {
869 brackets--;
870 } else if ((vare[0] == '$') && (vare[1] == '{')) {
871 needsub++;
872 vare++;
873 }
874 vare++;
875 }
876 len = vare - vars;
877 if (brackets) {
878 ast_log(LOG_WARNING, "Error in extension logic (missing ']')\n");
879 } else {
880 /* Don't count the closing ']' in the length. */
881 --len;
882 }
883
884 /* Skip totally over expression */
885 whereweare = vare;
886
887 /* Store expression to evaluate (and truncate). */
888 ast_copy_string(var, vars, len + 1);
889
890 /* Substitute if necessary */
891 if (needsub) {
893 vars = ltmp;
894 } else {
895 vars = var;
896 }
897
898 length = ast_expr(vars, cp2, count, c);
899 if (length) {
900 ast_debug(1, "Expression result is '%s'\n", cp2);
901 count -= length;
902 cp2 += length;
903 *cp2 = 0;
904 }
905 }
906 }
907 if (used) {
908 *used = cp2 - orig_cp2;
909 }
910 (*recurse_depth)--;
911}
int ast_expr(char *expr, char *buf, int length, struct ast_channel *chan)
Evaluate the given expression.
int ast_func_read(struct ast_channel *chan, const char *function, char *workspace, size_t len)
executes a read operation on a function
static char * substring(const char *value, int offset, int length, char *workspace, size_t workspace_len)
takes a substring. It is ok to call with value == workspace.
void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp)
Support for Asterisk built-in variables in the dialplan.
#define MAX_VARIABLE_SUB_RECURSE_DEPTH

References 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(), ast_threadstorage_get(), c, ast_channel::context, ast_channel::exten, len(), LOG_ERROR, LOG_WARNING, MAX_VARIABLE_SUB_RECURSE_DEPTH, NULL, parse_variable_name(), pbx_retrieve_variable(), pbx_substitute_variables_helper_full_location(), substring(), var, and VAR_BUF_SIZE.

Referenced by eval_exten_read(), pbx_substitute_variables_helper_full(), and pbx_substitute_variables_helper_full_location().

◆ pbx_substitute_variables_varshead()

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

Definition at line 918 of file pbx_variables.c.

919{
920 pbx_substitute_variables_helper_full(NULL, headp, cp1, cp2, count, NULL);
921}
void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int count, size_t *used)

References NULL, and pbx_substitute_variables_helper_full().

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