Asterisk - The Open Source Telephony Project  18.5.0
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. More...
 
#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. More...
 
#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_HANGUP   -1
 Special return values from applications to the PBX. More...
 
#define AST_PBX_OK   0
 
#define AST_PBX_ERROR   1
 
#define AST_PBX_INCOMPLETE   12
 

Typedefs

typedef void(* ast_state_cb_destroy_type) (int id, void *data)
 Typedef for devicestate and hint callback removal indication callback. More...
 
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. More...
 
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. More...
 

Enumerations

enum  ast_custom_function_escalation { AST_CFE_NONE, AST_CFE_READ, AST_CFE_WRITE, AST_CFE_BOTH }
 Description of the ways in which a function may escalate privileges. More...
 
enum  ast_ext_matchcid_types { AST_EXT_MATCHCID_OFF = 0, AST_EXT_MATCHCID_ON = 1, AST_EXT_MATCHCID_ANY = 2 }
 extension matchcid types More...
 
enum  ast_extension_states {
  AST_EXTENSION_REMOVED = -2, AST_EXTENSION_DEACTIVATED = -1, AST_EXTENSION_NOT_INUSE = 0, AST_EXTENSION_INUSE = 1 << 0,
  AST_EXTENSION_BUSY = 1 << 1, AST_EXTENSION_UNAVAILABLE = 1 << 2, AST_EXTENSION_RINGING = 1 << 3, AST_EXTENSION_ONHOLD = 1 << 4,
  AST_EXTENSION_REMOVED = -2, AST_EXTENSION_DEACTIVATED = -1, AST_EXTENSION_NOT_INUSE = 0, AST_EXTENSION_INUSE = 1 << 0,
  AST_EXTENSION_BUSY = 1 << 1, AST_EXTENSION_UNAVAILABLE = 1 << 2, AST_EXTENSION_RINGING = 1 << 3, AST_EXTENSION_ONHOLD = 1 << 4
}
 Extension states. More...
 
enum  ast_pbx_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, 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. More...
 
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. More...
 
int ast_active_calls (void)
 Retrieve the number of active calls. More...
 
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. More...
 
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 *. More...
 
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. More...
 
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. More...
 
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. More...
 
int ast_async_goto_if_exists (struct ast_channel *chan, const char *context, const char *exten, int priority)
 
int ast_async_parseable_goto (struct ast_channel *chan, const char *goto_string)
 
int ast_build_timing (struct ast_timing *i, const char *info)
 Construct a timing bitmap, for use in time-based conditionals. More...
 
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. More...
 
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. More...
 
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. More...
 
char * ast_complete_applications (const char *line, const char *word, int state)
 Command completion for the list of installed applications. More...
 
int ast_context_add_ignorepat (const char *context, const char *ignorepat, const char *registrar)
 Add an ignorepat. More...
 
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. More...
 
int ast_context_add_include2 (struct ast_context *con, const char *include, const char *registrar)
 Add a context include. More...
 
int ast_context_add_switch (const char *context, const char *sw, const char *data, int eval, const char *registrar)
 Add a switch. More...
 
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) More...
 
void ast_context_destroy (struct ast_context *con, const char *registrar)
 Destroy a context (matches the specified context or ANY context if NULL) More...
 
int ast_context_destroy_by_name (const char *context, const char *registrar)
 Destroy a context by name. More...
 
struct ast_contextast_context_find (const char *name)
 Find a context. More...
 
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. More...
 
int ast_context_lockmacro (const char *macrocontext)
 locks the macrolock in the given context More...
 
int ast_context_remove_ignorepat (const char *context, const char *ignorepat, const char *registrar)
 
int ast_context_remove_ignorepat2 (struct ast_context *con, const char *ignorepat, const char *registrar)
 
int ast_context_remove_include (const char *context, const char *include, const char *registrar)
 Remove a context include. More...
 
int ast_context_remove_include2 (struct ast_context *con, const char *include, const char *registrar)
 Removes an include by an ast_context structure. More...
 
int ast_context_remove_switch (const char *context, const char *sw, const char *data, const char *registrar)
 Remove a switch. More...
 
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. More...
 
void ast_context_set_autohints (struct ast_context *con, int enabled)
 Enable or disable autohints support on a context. More...
 
int ast_context_unlockmacro (const char *macrocontext)
 Unlocks the macrolock in the given context. More...
 
int ast_context_verify_includes (struct ast_context *con)
 Verifies includes in an ast_contect structure. More...
 
struct ast_custom_functionast_custom_function_find (const char *name)
 
int ast_custom_function_unregister (struct ast_custom_function *acf)
 Unregister a custom function. More...
 
int ast_destroy_timing (struct ast_timing *i)
 Deallocates memory structures associated with a timing bitmap. More...
 
enum ast_extension_states ast_devstate_to_extenstate (enum ast_device_state devstate)
 Map devstate to an extension state. More...
 
int ast_exists_extension (struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
 Determine whether an extension exists. More...
 
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. More...
 
int ast_extension_match (const char *pattern, const char *extension)
 Determine if a given extension matches a given pattern (in NXX format) More...
 
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. More...
 
const char * ast_extension_state2str (int extension_state)
 Return string representation of the state of an extension. More...
 
int ast_extension_state_add (const char *context, const char *exten, ast_state_cb_type change_cb, void *data)
 Add watcher for extension states. More...
 
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. More...
 
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. More...
 
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. More...
 
int ast_extension_state_del (int id, ast_state_cb_type change_cb)
 Deletes a state change watcher by ID. More...
 
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. More...
 
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. More...
 
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. More...
 
int ast_func_read (struct ast_channel *chan, const char *function, char *workspace, size_t len)
 executes a read operation on a function More...
 
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 More...
 
int ast_func_write (struct ast_channel *chan, const char *function, const char *value)
 executes a write operation on a function More...
 
const char * ast_get_extension_registrar_file (struct ast_exten *e)
 Get name of configuration file used by registrar to register this extension. More...
 
int ast_get_extension_registrar_line (struct ast_exten *e)
 Get line number of configuration file used by registrar to register this extension. More...
 
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. More...
 
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. More...
 
int ast_ignore_pattern (const char *context, const char *pattern)
 Checks to see if a number should be ignored. More...
 
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) More...
 
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. More...
 
int ast_parseable_goto (struct ast_channel *chan, const char *goto_string)
 
void ast_pbx_h_exten_run (struct ast_channel *chan, const char *context)
 Run the h exten from the given context. More...
 
void ast_pbx_hangup_handler_destroy (struct ast_channel *chan)
 Destroy the hangup handler container on a channel. More...
 
void ast_pbx_hangup_handler_init (struct ast_channel *chan)
 Init the hangup handler container on a channel. More...
 
int ast_pbx_hangup_handler_pop (struct ast_channel *chan)
 Pop the top of the channel hangup handler stack. More...
 
void ast_pbx_hangup_handler_push (struct ast_channel *chan, const char *handler)
 Push the given hangup handler onto the channel hangup handler stack. More...
 
int ast_pbx_hangup_handler_run (struct ast_channel *chan)
 Run all hangup handlers on the channel. More...
 
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. More...
 
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. More...
 
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. More...
 
enum ast_pbx_result ast_pbx_run_args (struct ast_channel *c, struct ast_pbx_args *args)
 Execute the PBX in the current thread. More...
 
enum ast_pbx_result ast_pbx_start (struct ast_channel *c)
 Create a new thread and start the PBX. More...
 
int ast_processed_calls (void)
 Retrieve the total number of calls processed through the PBX since last restart. More...
 
int ast_rdlock_context (struct ast_context *con)
 Read locks a given context. More...
 
int ast_rdlock_contexts (void)
 Read locks the context list. More...
 
int ast_register_switch (struct ast_switch *sw)
 Register an alternative dialplan switch. More...
 
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) More...
 
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. More...
 
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. More...
 
int ast_thread_inhibit_escalations_swap (int inhibit)
 Swap the current thread escalation inhibit setting. More...
 
int ast_unlock_context (struct ast_context *con)
 
int ast_unlock_contexts (void)
 Unlocks contexts. More...
 
void ast_unregister_switch (struct ast_switch *sw)
 Unregister an alternative switch. More...
 
int ast_wrlock_context (struct ast_context *con)
 Write locks a given context. More...
 
int ast_wrlock_contexts (void)
 Write locks the context list. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
int pbx_checkcondition (const char *condition)
 Evaluate a condition. More...
 
int pbx_exec (struct ast_channel *c, struct ast_app *app, const char *data)
 Execute an application. More...
 
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. More...
 
void pbx_live_dangerously (int new_live_dangerously)
 Enable/disable the execution of 'dangerous' functions from external protocols (AMI, etc.). More...
 
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. More...
 
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. More...
 
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. More...
 
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)
 
const char * ast_get_extension_name (struct ast_exten *exten)
 
struct ast_contextast_get_extension_context (struct ast_exten *exten)
 
const char * ast_get_include_name (const struct ast_include *include)
 
const char * ast_get_ignorepat_name (const struct ast_ignorepat *ip)
 
const char * ast_get_switch_name (const struct ast_sw *sw)
 
const char * ast_get_switch_data (const struct ast_sw *sw)
 
int ast_get_switch_eval (const struct ast_sw *sw)
 
Other Extension stuff
int ast_get_extension_priority (struct ast_exten *exten)
 
int ast_get_extension_matchcid (struct ast_exten *e)
 
const char * ast_get_extension_cidmatch (struct ast_exten *e)
 
const char * ast_get_extension_app (struct ast_exten *e)
 
const char * ast_get_extension_label (struct ast_exten *e)
 
void * ast_get_extension_app_data (struct ast_exten *e)
 
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_include_registrar (const struct ast_include *i)
 
const char * ast_get_ignorepat_registrar (const struct ast_ignorepat *ip)
 
const char * ast_get_switch_registrar (const struct ast_sw *sw)
 
Walking functions ...
struct ast_contextast_walk_contexts (struct ast_context *con)
 
struct ast_extenast_walk_context_extensions (struct ast_context *con, struct ast_exten *priority)
 
struct ast_extenast_walk_extension_priorities (struct ast_exten *exten, struct ast_exten *priority)
 
const struct ast_includeast_walk_context_includes (const struct ast_context *con, const struct ast_include *inc)
 
const struct ast_ignorepatast_walk_context_ignorepats (const struct ast_context *con, const struct ast_ignorepat *ip)
 
const struct ast_swast_walk_context_switches (const struct ast_context *con, const struct ast_sw *sw)
 
Iterator functions ...
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_ignorepats_count (const struct ast_context *con)
 
const struct ast_ignorepatast_context_ignorepats_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_varshead (struct varshead *headp, 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)
 
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_varshead (struct ast_str **buf, ssize_t maxlen, struct varshead *headp, 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)
 
int ast_hashtab_compare_contexts (const void *ah_a, const void *ah_b)
 hashtable functions for contexts More...
 
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 1508 of file pbx.h.

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

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

Referenced by load_module().

◆ AST_MAX_APP

#define AST_MAX_APP   32

Max length of an application

Definition at line 40 of file pbx.h.

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

◆ AST_PBX_ERROR

#define AST_PBX_ERROR   1

Jump to the 'e' exten

Definition at line 50 of file pbx.h.

Referenced by __ast_pbx_run().

◆ AST_PBX_GOTO_FAILED

#define AST_PBX_GOTO_FAILED   -3

Definition at line 42 of file pbx.h.

Referenced by __ast_goto_if_exists().

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

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

◆ 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 1613 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

◆ STATUS_NO_CONTEXT

#define STATUS_NO_CONTEXT   1

Definition at line 1604 of file pbx.h.

◆ STATUS_NO_EXTENSION

#define STATUS_NO_EXTENSION   2

Definition at line 1605 of file pbx.h.

◆ STATUS_NO_LABEL

#define STATUS_NO_LABEL   4

Definition at line 1607 of file pbx.h.

◆ STATUS_NO_PRIORITY

#define STATUS_NO_PRIORITY   3

Definition at line 1606 of file pbx.h.

◆ STATUS_SUCCESS

#define STATUS_SUCCESS   5

Definition at line 1608 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 156 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 1498 of file pbx.h.

1498  {
1499  AST_CFE_NONE,
1500  AST_CFE_READ,
1501  AST_CFE_WRITE,
1502  AST_CFE_BOTH,
1503 };

◆ 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_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

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

1151  {
1152  AST_OUTGOING_NO_WAIT = 0, /*!< Don't wait for originated call to answer */
1153  AST_OUTGOING_WAIT = 1, /*!< Wait for originated call to answer */
1154  AST_OUTGOING_WAIT_COMPLETE = 2, /*!< Wait for originated call to answer and hangup */
1155 };

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

354  {
355  AST_PBX_SUCCESS = 0,
356  AST_PBX_FAILED = -1,
357  AST_PBX_CALL_LIMIT = -2,
358 };

◆ 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 };

◆ 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 
E_MATCHMORE 
E_CANMATCH 
E_MATCH 
E_MATCH_MASK 
E_SPAWN 
E_FINDLABEL 

Definition at line 1595 of file pbx.h.

1595  {
1596  E_MATCHMORE = 0x00, /* extension can match but only with more 'digits' */
1597  E_CANMATCH = 0x01, /* extension can match with or without more 'digits' */
1598  E_MATCH = 0x02, /* extension is an exact match */
1599  E_MATCH_MASK = 0x03, /* mask for the argument to extension_match_core() */
1600  E_SPAWN = 0x12, /* want to spawn an extension. Requires exact match */
1601  E_FINDLABEL = 0x22 /* returns the priority for a given label. Requires exact match */
1602 };
Definition: pbx.h:1600
Definition: pbx.h:1598

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

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

374 {
375  struct ast_custom_function *cur;
376 
377  if (!acf) {
378  return -1;
379  }
380 
381  acf->mod = mod;
382 #ifdef AST_XML_DOCS
383  acf->docsrc = AST_STATIC_DOC;
384 #endif
385 
386  if (acf_retrieve_docs(acf)) {
387  return -1;
388  }
389 
391 
393  if (cur) {
394  ast_log(LOG_ERROR, "Function %s already registered.\n", acf->name);
396  return -1;
397  }
398 
399  /* Store in alphabetical order */
400  AST_RWLIST_TRAVERSE_SAFE_BEGIN(&acf_root, cur, acflist) {
401  if (strcmp(acf->name, cur->name) < 0) {
402  AST_RWLIST_INSERT_BEFORE_CURRENT(acf, acflist);
403  break;
404  }
405  }
407  if (!cur) {
408  AST_RWLIST_INSERT_TAIL(&acf_root, acf, acflist);
409  }
410 
412 
413  ast_verb(2, "Registered custom function '" COLORIZE_FMT "'\n", COLORIZE(COLOR_BRCYAN, 0, acf->name));
414 
415  return 0;
416 }
const char * name
Definition: pbx.h:119
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
enum ast_doc_src docsrc
Definition: pbx.h:127
static struct ast_custom_function * ast_custom_function_find_nolock(const char *name)
struct ast_module * mod
Definition: pbx.h:142
#define ast_verb(level,...)
Definition: logger.h:463
#define COLOR_BRCYAN
Definition: term.h:60
#define COLORIZE(fg, bg, str)
Definition: term.h:68
#define ast_log
Definition: astobj2.c:42
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
#define COLORIZE_FMT
Shortcut macros for coloring a set of text.
Definition: term.h:67
Registered functions container.
Definition: pbx_functions.c:59
#define AST_RWLIST_INSERT_BEFORE_CURRENT
Definition: linkedlists.h:609
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:544
static int acf_retrieve_docs(struct ast_custom_function *acf)
#define LOG_ERROR
Definition: logger.h:285
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:740
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:616

◆ __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 418 of file pbx_functions.c.

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

419 {
420  int res;
421 
422  res = __ast_custom_function_register(acf, mod);
423  if (res != 0) {
424  return -1;
425  }
426 
427  switch (escalation) {
428  case AST_CFE_NONE:
429  break;
430  case AST_CFE_READ:
431  acf->read_escalates = 1;
432  break;
433  case AST_CFE_WRITE:
434  acf->write_escalates = 1;
435  break;
436  case AST_CFE_BOTH:
437  acf->read_escalates = 1;
438  acf->write_escalates = 1;
439  break;
440  }
441 
442  return 0;
443 }
int __ast_custom_function_register(struct ast_custom_function *acf, struct ast_module *mod)
Register a custom function.
unsigned int write_escalates
Definition: pbx.h:147
unsigned int read_escalates
Definition: pbx.h:143

◆ ast_active_calls()

int ast_active_calls ( void  )

Retrieve the number of active calls.

Definition at line 4764 of file pbx.c.

References countcalls.

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

4765 {
4766  return countcalls;
4767 }
static int countcalls
Definition: pbx.c:773

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

References ast_add_extension2(), ast_unlock_contexts(), c, ast_exten::datad, find_context_locked(), and NULL.

Referenced by add_to_regcontext(), app_create(), ast_hint_presence_state(), ast_sip_persistent_endpoint_update_state(), AST_TEST_DEFINE(), create_test_dialplan(), device_state_cb(), extension_state_add_destroy(), handle_cli_dialplan_add_extension(), internal_extension_state_extended(), join_conference_bridge(), load_module(), register_exten(), register_extension(), register_peer_exten(), sla_build_station(), and sla_build_trunk().

6973 {
6974  int ret = -1;
6975  struct ast_context *c;
6976 
6978  if (c) {
6979  ret = ast_add_extension2(c, replace, extension, priority, label, callerid,
6980  application, data, datad, registrar, NULL, 0);
6982  }
6983 
6984  return ret;
6985 }
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:7299
static struct test_val c
#define NULL
Definition: resample.c:96
static int priority
structure to hold extensions
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:8512
static char * registrar
Definition: pbx_ael.c:78
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:4818
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
Definition: func_strings.c:790
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284

◆ 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
registrar_fileoptional configuration file that defines this extension
registrar_lineoptional line number of configuration file that defines extension
Note
For details about the other arguments, check ast_add_extension()

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

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

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

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

Definition at line 7299 of file pbx.c.

References ast_add_extension2_lockopt(), ast_exten::datad, and localized_add_extension2().

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

7303 {
7304  return ast_add_extension2_lockopt(con, replace, extension, priority, label, callerid,
7305  application, data, datad, registrar, registrar_file, registrar_line, 1);
7306 }
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:7325
static int priority
structure to hold extensions
static char * registrar
Definition: pbx_ael.c:78
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
Definition: func_strings.c:790

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

References ast_add_extension2_lockopt(), and ast_exten::datad.

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

7312 {
7313  return ast_add_extension2_lockopt(con, replace, extension, priority, label, callerid,
7314  application, data, datad, registrar, registrar_file, registrar_line, 0);
7315 }
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:7325
static int priority
structure to hold extensions
static char * registrar
Definition: pbx_ael.c:78
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
Definition: func_strings.c:790

◆ 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
Do NOT hold any channel locks when calling this function.

Definition at line 7011 of file pbx.c.

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

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

7012 {
7013  struct ast_channel *newchan;
7014 
7015  ast_channel_lock(chan);
7016  /* Channels in a bridge or running a PBX can be sent directly to the specified destination */
7017  if (ast_channel_is_bridged(chan) || ast_channel_pbx(chan)) {
7019  priority += 1;
7020  }
7023  ast_channel_unlock(chan);
7024  return 0;
7025  }
7026  ast_channel_unlock(chan);
7027 
7028  /* Otherwise, we need to gain control of the channel first */
7029  newchan = ast_channel_yank(chan);
7030  if (!newchan) {
7031  ast_log(LOG_WARNING, "Unable to gain control of channel %s\n", ast_channel_name(chan));
7032  return -1;
7033  }
7035  if (ast_pbx_start(newchan)) {
7036  ast_hangup(newchan);
7037  ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ast_channel_name(newchan));
7038  return -1;
7039  }
7040 
7041  return 0;
7042 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
Main Channel structure associated with a channel.
#define ast_test_flag(p, flag)
Definition: utils.h:63
int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority)
Definition: pbx.c:6987
#define LOG_WARNING
Definition: logger.h:274
struct ast_channel * ast_channel_yank(struct ast_channel *yankee)
Gain control of a channel in the system.
Definition: channel.c:10794
static int priority
#define ast_log
Definition: astobj2.c:42
struct ast_pbx * ast_channel_pbx(const struct ast_channel *chan)
enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
Create a new thread and start the PBX.
Definition: pbx.c:4712
int ast_softhangup_nolock(struct ast_channel *chan, int reason)
Softly hangup up a channel (no channel lock)
Definition: channel.c:2463
int ast_channel_is_bridged(const struct ast_channel *chan)
Determine if a channel is in a bridge.
Definition: channel.c:10746
#define ast_channel_unlock(chan)
Definition: channel.h:2946
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2548
const char * ast_channel_name(const struct ast_channel *chan)
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
struct ast_flags * ast_channel_flags(struct ast_channel *chan)

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

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

7045 {
7046  struct ast_channel *chan;
7047  int res = -1;
7048 
7049  if ((chan = ast_channel_get_by_name(channame))) {
7050  res = ast_async_goto(chan, context, exten, priority);
7051  chan = ast_channel_unref(chan);
7052  }
7053 
7054  return res;
7055 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
static int priority
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:7011
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454

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

References __ast_goto_if_exists().

8799 {
8800  return __ast_goto_if_exists(chan, context, exten, priority, 1);
8801 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
static int __ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, int async)
Definition: pbx.c:8772
static int priority
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

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

References pbx_parseable_goto().

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

8865 {
8866  return pbx_parseable_goto(chan, goto_string, 1);
8867 }
static int pbx_parseable_goto(struct ast_channel *chan, const char *goto_string, int async)
Definition: pbx.c:8803

◆ 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.
infoStandard string containing a timerange, weekday range, monthday range, and month range, as well as an optional timezone.
Return values
Returns1 on success or 0 on failure.

/brief Build timing

/param i info /param info_in

Definition at line 3808 of file extconf.c.

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

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

3809 {
3810  char *info;
3811  int j, num_fields, last_sep = -1;
3812 
3813  i->timezone = NULL;
3814 
3815  /* Check for empty just in case */
3816  if (ast_strlen_zero(info_in)) {
3817  return 0;
3818  }
3819 
3820  /* make a copy just in case we were passed a static string */
3821  info = ast_strdupa(info_in);
3822 
3823  /* count the number of fields in the timespec */
3824  for (j = 0, num_fields = 1; info[j] != '\0'; j++) {
3825  if (info[j] == ',') {
3826  last_sep = j;
3827  num_fields++;
3828  }
3829  }
3830 
3831  /* save the timezone, if it is specified */
3832  if (num_fields == 5) {
3833  i->timezone = ast_strdup(info + last_sep + 1);
3834  }
3835 
3836  /* Assume everything except time */
3837  i->monthmask = 0xfff; /* 12 bits */
3838  i->daymask = 0x7fffffffU; /* 31 bits */
3839  i->dowmask = 0x7f; /* 7 bits */
3840  /* on each call, use strsep() to move info to the next argument */
3841  get_timerange(i, strsep(&info, "|,"));
3842  if (info)
3843  i->dowmask = get_range(strsep(&info, "|,"), 7, days, "day of week");
3844  if (info)
3845  i->daymask = get_range(strsep(&info, "|,"), 31, NULL, "day");
3846  if (info)
3847  i->monthmask = get_range(strsep(&info, "|,"), 12, months, "month");
3848  return 1;
3849 }
unsigned int daymask
Definition: pbx.h:174
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
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, is an array of names that should be mapped to numbers.
Definition: extconf.c:2640
unsigned int monthmask
Definition: pbx.h:173
static force_inline int ast_strlen_zero(const char *s)
Definition: extconf.c:952
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static void get_timerange(struct ast_timing *i, char *times)
store a bitmask of valid times, one bit each 2 minute
Definition: extconf.c:2684
char * days[]
Definition: extconf.c:3777
unsigned int dowmask
Definition: pbx.h:175
def info(msg)
char * months[]
Definition: extconf.c:3789
char * strsep(char **str, const char *delims)
char * timezone
Definition: pbx.h:177

◆ 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 serach 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 4194 of file pbx.c.

References E_CANMATCH, NULL, and pbx_extension_helper().

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

4195 {
4196  return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_CANMATCH, 0, 0);
4197 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
#define NULL
Definition: resample.c:96
static int priority
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
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:2875

◆ 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
Returns1, if the time matches or 0, if the current time falls outside of the specified range.

Definition at line 4002 of file extconf.c.

References ast_check_timing2(), AST_RWLIST_TRAVERSE, ast_tvnow(), ast_walk_contexts(), ast_switch::list, ast_switch::name, and pbx_findswitch().

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

4003 {
4004  /* sorry, but this feature will NOT be available
4005  in the standalone version */
4006  return 0;
4007 }

◆ 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
Returns1, if the time matches or 0, if the time falls outside of the specified range.

Definition at line 251 of file pbx_timing.c.

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

Referenced by ast_check_timing(), and pbx_builtin_gotoiftime().

252 {
253  struct ast_tm tm;
254 
255  ast_localtime(&tv, &tm, i->timezone);
256 
257  /* If it's not the right month, return */
258  if (!(i->monthmask & (1 << tm.tm_mon)))
259  return 0;
260 
261  /* If it's not that time of the month.... */
262  /* Warning, tm_mday has range 1..31! */
263  if (!(i->daymask & (1 << (tm.tm_mday-1))))
264  return 0;
265 
266  /* If it's not the right day of the week */
267  if (!(i->dowmask & (1 << tm.tm_wday)))
268  return 0;
269 
270  /* Sanity check the hour just to be safe */
271  if ((tm.tm_hour < 0) || (tm.tm_hour > 23)) {
272  ast_log(LOG_WARNING, "Insane time...\n");
273  return 0;
274  }
275 
276  /* Now the tough part, we calculate if it fits
277  in the right time based on min/hour */
278  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))))
279  return 0;
280 
281  /* If we got this far, then we're good */
282  return 1;
283 }
unsigned int daymask
Definition: pbx.h:174
#define LOG_WARNING
Definition: logger.h:274
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:176
unsigned int monthmask
Definition: pbx.h:173
#define ast_log
Definition: astobj2.c:42
unsigned int dowmask
Definition: pbx.h:175
char * timezone
Definition: pbx.h:177

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

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

Referenced by handle_orig(), and handle_show_application().

430 {
431  struct ast_app *app;
432  int which = 0;
433  int cmp;
434  char *ret = NULL;
435  size_t wordlen = strlen(word);
436 
438  AST_RWLIST_TRAVERSE(&apps, app, list) {
439  cmp = strncasecmp(word, app->name, wordlen);
440  if (cmp < 0) {
441  /* No more matches. */
442  break;
443  } else if (!cmp) {
444  /* Found match. */
445  if (state != -1) {
446  if (++which <= state) {
447  /* Not enough matches. */
448  continue;
449  }
450  ret = ast_strdup(app->name);
451  break;
452  }
453  if (ast_cli_completion_add(ast_strdup(app->name))) {
454  break;
455  }
456  }
457  }
459 
460  return ret;
461 }
Registered applications container.
Definition: pbx_app.c:67
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
ast_app: A registered application
Definition: pbx_app.c:45
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
Definition: main/cli.c:2726
static const char app[]
Definition: app_mysql.c:62
short word

◆ 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 ignorpattern 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 6877 of file pbx.c.

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

Referenced by handle_cli_dialplan_add_ignorepat().

6878 {
6879  int ret = -1;
6880  struct ast_context *c;
6881 
6883  if (c) {
6886  }
6887  return ret;
6888 }
static struct test_val c
int value
Definition: syslog.c:37
int ast_context_add_ignorepat2(struct ast_context *con, const char *value, const char *registrar)
Definition: pbx.c:6890
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:8512
static char * registrar
Definition: pbx_ael.c:78
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:4818
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284

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

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(), errno, ignorepat_alloc(), ignorepat_free(), ast_context::ignorepats, and localized_context_add_ignorepat2().

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

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 ast_ignorepats ignorepats
Definition: pbx.c:291
int value
Definition: syslog.c:37
static int dump_extensions
Definition: ael_main.c:126
static int no_comp
Definition: ael_main.c:124
#define ADD_LAST(headptr, memptr)
Definition: ael_main.c:64
static char * registrar
Definition: pbx_ael.c:78
struct namelist * create_name(const char *name)
Definition: ael_main.c:79

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

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

Referenced by AST_TEST_DEFINE(), and handle_cli_dialplan_add_include().

6707 {
6708  int ret = -1;
6709  struct ast_context *c;
6710 
6712  if (c) {
6713  ret = ast_context_add_include2(c, include, registrar);
6715  }
6716  return ret;
6717 }
int ast_context_add_include2(struct ast_context *con, const char *value, const char *registrar)
Add a context include.
Definition: pbx.c:6726
static struct test_val c
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:8512
static char * registrar
Definition: pbx_ael.c:78
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:4818
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284

◆ ast_context_add_include2()

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

Add a context include.

Parameters
concontext to add the include to
valueinclude value to add
registrarwho registered the context

Adds an include taking a struct ast_context as the first parameter

Return values
0on success
-1on failure

Definition at line 359 of file ael_main.c.

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(), errno, include_alloc(), include_free(), ast_context::includes, and localized_context_add_include2().

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

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 }
int value
Definition: syslog.c:37
static int dump_extensions
Definition: ael_main.c:126
static int no_comp
Definition: ael_main.c:124
#define ADD_LAST(headptr, memptr)
Definition: ael_main.c:64
struct ast_includes includes
Definition: pbx.c:290
static char * registrar
Definition: pbx_ael.c:78
struct namelist * create_name(const char *name)
Definition: ael_main.c:79

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

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

6772 {
6773  int ret = -1;
6774  struct ast_context *c;
6775 
6777  if (c) { /* found, add switch to this context */
6778  ret = ast_context_add_switch2(c, sw, data, eval, registrar);
6780  }
6781  return ret;
6782 }
static struct test_val c
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:8512
static char * registrar
Definition: pbx_ael.c:78
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:4818
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:6791
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284

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

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(), errno, ast_context::eswitches, localized_context_add_switch2(), namelist::name2, sw_alloc(), sw_free(), and ast_context::switches.

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

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 * eswitches
Definition: ael_main.c:54
int value
Definition: syslog.c:37
struct namelist * switches
Definition: ael_main.c:53
static int dump_extensions
Definition: ael_main.c:126
static int no_comp
Definition: ael_main.c:124
#define ADD_LAST(headptr, memptr)
Definition: ael_main.c:64
static char * registrar
Definition: pbx_ael.c:78
struct namelist * create_name(const char *name)
Definition: ael_main.c:79
char name2[100]
Definition: ael_main.c:42

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

Returns
nothing

Definition at line 625 of file conf2ael.c.

References __ast_context_destroy(), ast_context_verify_includes(), ast_unlock_contexts(), ast_wrlock_contexts(), and localized_context_destroy().

Referenced by ast_context_destroy_by_name(), AST_TEST_DEFINE(), ast_walk_contexts(), parking_lot_cfg_remove_extensions(), remove_all_configured_parking_lot_extensions(), remove_pending_parking_lot_extensions(), sla_destroy(), and unload_module().

626 {
628 }
static char * registrar
Definition: pbx_ael.c:78
void localized_context_destroy(struct ast_context *con, const char *registrar)
Definition: extconf.c:5565

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

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

Referenced by __unload_module(), app_dtor(), ast_sip_destroy_sorcery_global(), check_regcontext(), cleanup_stale_contexts(), handle_cli_dialplan_remove_context(), and unload_module().

8245 {
8246  struct ast_context *con;
8247  int ret = -1;
8248 
8250  con = ast_context_find(context);
8251  if (con) {
8253  ret = 0;
8254  }
8256 
8257  return ret;
8258 }
struct ast_context * ast_context_find(const char *name)
Find a context.
Definition: pbx.c:2443
void ast_context_destroy(struct ast_context *con, const char *registrar)
Destroy a context (matches the specified context or ANY context if NULL)
Definition: pbx.c:8260
int ast_wrlock_contexts(void)
Write locks the context list.
Definition: pbx.c:8502
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:8512
static char * registrar
Definition: pbx_ael.c:78
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284

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

References ast_copy_string(), ast_hashtab_lookup(), ast_rdlock_contexts(), ast_unlock_contexts(), ast_walk_contexts(), ast_context::name, fake_context::name, NULL, and tmp().

Referenced by _macro_exec(), app_create(), ast_context_destroy_by_name(), ast_context_verify_includes(), ast_ignore_pattern(), handle_cli_dialplan_add_extension(), handle_cli_dialplan_add_include(), isexten_function_read(), register_exten(), register_peer_exten(), and unregister_exten().

4175 {
4176  struct ast_context *tmp = NULL;
4177  while ( (tmp = ast_walk_contexts(tmp)) ) {
4178  if (!name || !strcasecmp(name, tmp->name))
4179  break;
4180  }
4181  return tmp;
4182 }
static int tmp()
Definition: bt_open.c:389
#define NULL
Definition: resample.c:96
static struct ast_context * ast_walk_contexts(struct ast_context *con)
Definition: extconf.c:4026
char name[0]
Definition: pbx.c:297
static const char name[]
Definition: cdr_mysql.c:74
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284

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

References __ast_cli_register_multiple(), ast_context::alts, ast_calloc, ast_copy_string(), 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_mutex_init, ast_rdlock_contexts(), ast_rwlock_init, ast_strdup, ast_unlock_contexts(), AST_VECTOR_INIT, ast_wrlock_contexts(), contexts, ast_context::ignorepats, ast_context::includes, local_contexts, localized_context_find_or_create(), ast_context::lock, LOG_ERROR, ast_context::macrolock, ast_context::name, fake_context::name, ast_context::next, NULL, ast_context::refcount, ast_context::registrar, ast_context::root, ast_context::root_table, and tmp().

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

6199 {
6200  struct ast_context *tmp, **local_contexts;
6201  struct fake_context search;
6202  int length = sizeof(struct ast_context) + strlen(name) + 1;
6203 
6204  if (!contexts_table) {
6205  /* Protect creation of contexts_table from reentrancy. */
6207  if (!contexts_table) {
6213  0);
6214  }
6216  }
6217 
6218  ast_copy_string(search.name, name, sizeof(search.name));
6219  if (!extcontexts) {
6221  local_contexts = &contexts;
6222  tmp = ast_hashtab_lookup(contexts_table, &search);
6223  if (tmp) {
6224  tmp->refcount++;
6226  return tmp;
6227  }
6228  } else { /* local contexts just in a linked list; search there for the new context; slow, linear search, but not frequent */
6229  local_contexts = extcontexts;
6230  tmp = ast_hashtab_lookup(exttable, &search);
6231  if (tmp) {
6232  tmp->refcount++;
6233  return tmp;
6234  }
6235  }
6236 
6237  if ((tmp = ast_calloc(1, length))) {
6238  ast_rwlock_init(&tmp->lock);
6239  ast_mutex_init(&tmp->macrolock);
6240  strcpy(tmp->name, name);
6241  tmp->root = NULL;
6242  tmp->root_table = NULL;
6243  tmp->registrar = ast_strdup(registrar);
6244  AST_VECTOR_INIT(&tmp->includes, 0);
6245  AST_VECTOR_INIT(&tmp->ignorepats, 0);
6246  AST_VECTOR_INIT(&tmp->alts, 0);
6247  tmp->refcount = 1;
6248  } else {
6249  ast_log(LOG_ERROR, "Danger! We failed to allocate a context for %s!\n", name);
6250  if (!extcontexts) {
6252  }
6253  return NULL;
6254  }
6255 
6256  if (!extcontexts) {
6257  tmp->next = *local_contexts;
6258  *local_contexts = tmp;
6259  ast_hashtab_insert_safe(contexts_table, tmp); /*put this context into the tree */
6261  } else {
6262  tmp->next = *local_contexts;
6263  if (exttable)
6264  ast_hashtab_insert_immediate(exttable, tmp); /*put this context into the tree */
6265 
6266  *local_contexts = tmp;
6267  }
6268  ast_debug(1, "Registered extension context '%s'; registrar: %s\n", tmp->name, registrar);
6269  return tmp;
6270 }
struct ast_ignorepats ignorepats
Definition: pbx.c:291
void * ast_hashtab_lookup(struct ast_hashtab *tab, const void *obj)
Lookup this object in the hash table.
Definition: hashtab.c:486
int ast_hashtab_newsize_java(struct ast_hashtab *tab)
Create a prime number roughly 2x the current table size.
Definition: hashtab.c:127
struct ast_exten * root
Definition: pbx.c:286
static struct ast_hashtab * contexts_table
Definition: pbx.c:777
static int tmp()
Definition: bt_open.c:389
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
struct ast_context * local_contexts
int ast_rdlock_contexts(void)
Read locks the context list.
Definition: pbx.c:8507
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_hashtab_insert_safe(tab, obj)
Definition: hashtab.h:315
struct ast_context * next
Definition: pbx.c:289
ast_mutex_t macrolock
Definition: pbx.c:296
int ast_wrlock_contexts(void)
Write locks the context list.
Definition: pbx.c:8502
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_hashtab_insert_immediate(tab, obj)
Definition: hashtab.h:291
#define ast_log
Definition: astobj2.c:42
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
char * registrar
Definition: pbx.c:293
struct ast_includes includes
Definition: pbx.c:290
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:8512
ast_rwlock_t lock
Definition: pbx.c:285
#define LOG_ERROR
Definition: logger.h:285
char name[0]
Definition: pbx.c:297
#define ast_rwlock_init(rwlock)
wrapper for rwlock with tracking enabled
Definition: lock.h:222
static char * registrar
Definition: pbx_ael.c:78
static const char name[]
Definition: cdr_mysql.c:74
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
unsigned int ast_hashtab_hash_contexts(const void *obj)
Definition: pbx.c:735
int refcount
Definition: pbx.c:294
struct ast_hashtab * root_table
Definition: pbx.c:287
static struct ast_context * contexts
Definition: pbx.c:776
#define ast_hashtab_create(initial_buckets, compare, resize, newsize, hash, do_locking)
Definition: hashtab.h:261
#define ast_mutex_init(pmutex)
Definition: lock.h:184
struct ast_sws alts
Definition: pbx.c:292
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284
int ast_hashtab_compare_contexts(const void *ah_a, const void *ah_b)
hashtable functions for contexts
Definition: pbx.c:683

◆ 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_lockmacro()

int ast_context_lockmacro ( const char *  context)

locks the macrolock in the given context

Parameters
macrocontextname of the macro-context to lock

Locks the given macro-context to ensure only one thread (call) can execute it at a time

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

Definition at line 5162 of file pbx.c.

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

Referenced by _macro_exec().

5163 {
5164  struct ast_context *c;
5165  int ret = -1;
5166 
5168  if (c) {
5170 
5171  /* if we found context, lock macrolock */
5172  ret = ast_mutex_lock(&c->macrolock);
5173  }
5174 
5175  return ret;
5176 }
#define ast_mutex_lock(a)
Definition: lock.h:187
static struct test_val c
ast_mutex_t macrolock
Definition: pbx.c:296
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:8512
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:4818
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284

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

References ast_context_remove_extension_callerid(), AST_EXT_MATCHCID_ANY, and NULL.

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

4953 {
4955 }
#define NULL
Definition: resample.c:96
static int priority
structure to hold extensions
static char * registrar
Definition: pbx_ael.c:78
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
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:4957

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

References ast_context_remove_extension_callerid2(), AST_EXT_MATCHCID_ANY, and NULL.

Referenced by add_extension(), and add_hints().

4983 {
4985 }
#define NULL
Definition: resample.c:96
static int priority
structure to hold extensions
static char * registrar
Definition: pbx_ael.c:78
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:4987

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

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

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

4958 {
4959  int ret = -1; /* default error return */
4960  struct ast_context *c;
4961 
4963  if (c) { /* ... remove extension ... */
4965  matchcallerid, registrar, 0);
4967  }
4968 
4969  return ret;
4970 }
static struct test_val c
static int priority
structure to hold extensions
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:8512
static char * registrar
Definition: pbx_ael.c:78
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:4818
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:4987
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284

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

References add_exten_to_pattern_tree(), ast_hashtab_insert_immediate, ast_hashtab_lookup(), ast_hashtab_remove_this_object(), ast_hashtab_size(), ast_log, ast_strlen_zero, ast_unlock_context(), ast_verb, ast_wrlock_context(), ast_exten::cidmatch, match_char::deleted, destroy_exten(), 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, ast_exten::priority, ast_exten::registrar, ast_context::root, ast_context::root_table, and match_char::x.

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

4988 {
4989  struct ast_exten *exten, *prev_exten = NULL;
4990  struct ast_exten *peer;
4991  struct ast_exten ex, *exten2, *exten3;
4992  char dummy_name[1024];
4993  char dummy_cid[1024];
4994  struct ast_exten *previous_peer = NULL;
4995  struct ast_exten *next_peer = NULL;
4996  int found = 0;
4997 
4998  if (!already_locked)
4999  ast_wrlock_context(con);
5000 
5001 #ifdef NEED_DEBUG
5002  ast_verb(3,"Removing %s/%s/%d%s%s from trees, registrar=%s\n", con->name, extension, priority, matchcallerid ? "/" : "", matchcallerid ? callerid : "", registrar);
5003 #endif
5004 #ifdef CONTEXT_DEBUG
5005  check_contexts(__FILE__, __LINE__);
5006 #endif
5007  /* find this particular extension */
5008  ex.exten = dummy_name;
5009  ext_strncpy(dummy_name, extension, sizeof(dummy_name), 1);
5010  ex.matchcid = matchcallerid;
5011  if (callerid) {
5012  ex.cidmatch = dummy_cid;
5013  ext_strncpy(dummy_cid, callerid, sizeof(dummy_cid), 1);
5014  } else {
5015  ex.cidmatch = NULL;
5016  }
5017  exten = ast_hashtab_lookup(con->root_table, &ex);
5018  if (exten) {
5019  if (priority == 0) {
5020  exten2 = ast_hashtab_remove_this_object(con->root_table, exten);
5021  if (!exten2)
5022  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);
5023  if (con->pattern_tree) {
5024  struct match_char *x = add_exten_to_pattern_tree(con, exten, 1);
5025 
5026  if (x->exten) { /* this test for safety purposes */
5027  x->deleted = 1; /* with this marked as deleted, it will never show up in the scoreboard, and therefore never be found */
5028  x->exten = 0; /* get rid of what will become a bad pointer */
5029  } else {
5030  ast_log(LOG_WARNING,"Trying to delete an exten from a context, but the pattern tree node returned isn't a full extension\n");
5031  }
5032  }
5033  } else {
5034  ex.priority = priority;
5035  exten2 = ast_hashtab_lookup(exten->peer_table, &ex);
5036  if (exten2) {
5037  if (exten2->label) { /* if this exten has a label, remove that, too */
5038  exten3 = ast_hashtab_remove_this_object(exten->peer_label_table,exten2);
5039  if (!exten3) {
5040  ast_log(LOG_ERROR, "Did not remove this priority label (%d/%s) "
5041  "from the peer_label_table of context %s, extension %s!\n",
5042  priority, exten2->label, con->name, exten2->name);
5043  }
5044  }
5045 
5046  exten3 = ast_hashtab_remove_this_object(exten->peer_table, exten2);
5047  if (!exten3) {
5048  ast_log(LOG_ERROR, "Did not remove this priority (%d) from the "
5049  "peer_table of context %s, extension %s!\n",
5050  priority, con->name, exten2->name);
5051  }
5052  if (exten2 == exten && exten2->peer) {
5053  exten2 = ast_hashtab_remove_this_object(con->root_table, exten);
5055  }
5056  if (ast_hashtab_size(exten->peer_table) == 0) {
5057  /* well, if the last priority of an exten is to be removed,
5058  then, the extension is removed, too! */
5059  exten3 = ast_hashtab_remove_this_object(con->root_table, exten);
5060  if (!exten3) {
5061  ast_log(LOG_ERROR, "Did not remove this exten (%s) from the "
5062  "context root_table (%s) (priority %d)\n",
5063  exten->name, con->name, priority);
5064  }
5065  if (con->pattern_tree) {
5066  struct match_char *x = add_exten_to_pattern_tree(con, exten, 1);
5067  if (x->exten) { /* this test for safety purposes */
5068  x->deleted = 1; /* with this marked as deleted, it will never show up in the scoreboard, and therefore never be found */
5069  x->exten = 0; /* get rid of what will become a bad pointer */
5070  }
5071  }
5072  }
5073  } else {
5074  ast_log(LOG_ERROR,"Could not find priority %d of exten %s in context %s!\n",
5075  priority, exten->name, con->name);
5076  }
5077  }
5078  } else {
5079  /* hmmm? this exten is not in this pattern tree? */
5080  ast_log(LOG_WARNING,"Cannot find extension %s in root_table in context %s\n",
5081  extension, con->name);
5082  }
5083 #ifdef NEED_DEBUG
5084  if (con->pattern_tree) {
5085  ast_log(LOG_NOTICE,"match char tree after exten removal:\n");
5086  log_match_char_tree(con->pattern_tree, " ");
5087  }
5088 #endif
5089 
5090  /* scan the extension list to find first matching extension-registrar */
5091  for (exten = con->root; exten; prev_exten = exten, exten = exten->next) {
5092  if (!strcmp(exten->exten, ex.exten) &&
5093  (!matchcallerid ||
5094  (!ast_strlen_zero(ex.cidmatch) && !ast_strlen_zero(exten->cidmatch) && !strcmp(exten->cidmatch, ex.cidmatch)) ||
5095  (ast_strlen_zero(ex.cidmatch) && ast_strlen_zero(exten->cidmatch)))) {
5096  break;
5097  }
5098  }
5099  if (!exten) {
5100  /* we can't find right extension */
5101  if (!already_locked)
5102  ast_unlock_context(con);
5103  return -1;
5104  }
5105 
5106  /* scan the priority list to remove extension with exten->priority == priority */
5107  for (peer = exten, next_peer = exten->peer ? exten->peer : exten->next;
5108  peer && !strcmp(peer->exten, ex.exten) &&
5109  (!callerid || (!matchcallerid && !peer->matchcid) || (matchcallerid && peer->matchcid && !strcmp(peer->cidmatch, ex.cidmatch))) ;
5110  peer = next_peer, next_peer = next_peer ? (next_peer->peer ? next_peer->peer : next_peer->next) : NULL) {
5111 
5112  if ((priority == 0 || peer->priority == priority) &&
5113  (!registrar || !strcmp(peer->registrar, registrar) )) {
5114  found = 1;
5115 
5116  /* we are first priority extension? */
5117  if (!previous_peer) {
5118  /*
5119  * We are first in the priority chain, so must update the extension chain.
5120  * The next node is either the next priority or the next extension
5121  */
5122  struct ast_exten *next_node = peer->peer ? peer->peer : peer->next;
5123  if (peer->peer) {
5124  /* move the peer_table and peer_label_table down to the next peer, if
5125  it is there */
5126  peer->peer->peer_table = peer->peer_table;
5127  peer->peer->peer_label_table = peer->peer_label_table;
5128  peer->peer_table = NULL;
5129  peer->peer_label_table = NULL;
5130  }
5131  if (!prev_exten) { /* change the root... */
5132  con->root = next_node;
5133  } else {
5134  prev_exten->next = next_node; /* unlink */
5135  }
5136  if (peer->peer) { /* update the new head of the pri list */
5137  peer->peer->next = peer->next;
5138  }
5139  } else { /* easy, we are not first priority in extension */
5140  previous_peer->peer = peer->peer;
5141  }
5142 
5143 
5144  /* now, free whole priority extension */
5145  destroy_exten(peer);
5146  } else {
5147  previous_peer = peer;
5148  }
5149  }
5150  if (!already_locked)
5151  ast_unlock_context(con);
5152  return found ? 0 : -1;
5153 }
const char * label
Definition: pbx.c:244
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
ast_exten: An extension The dialplan is saved as a linked list with each context having it&#39;s own link...
Definition: pbx.c:237
void * ast_hashtab_lookup(struct ast_hashtab *tab, const void *obj)
Lookup this object in the hash table.
Definition: hashtab.c:486
static unsigned int ext_strncpy(char *dst, const char *src, size_t dst_size, int nofluff)
Definition: pbx.c:7068
int ast_unlock_context(struct ast_context *con)
Definition: pbx.c:8530
struct ast_exten * exten
Definition: pbx.c:268
struct ast_exten * root
Definition: pbx.c:286
char * name
Definition: pbx.c:239
static struct match_char * add_exten_to_pattern_tree(struct ast_context *con, struct ast_exten *e1, int findonly)
Definition: pbx.c:1657
#define LOG_WARNING
Definition: logger.h:274
#define NULL
Definition: resample.c:96
struct ast_hashtab * peer_table
Definition: pbx.c:251
static int priority
char x[1]
Definition: pbx.c:269
#define ast_verb(level,...)
Definition: logger.h:463
const char * registrar
Definition: pbx.c:253
#define ast_strlen_zero(foo)
Definition: strings.h:52
int matchcid
Definition: pbx.c:240
struct ast_exten * next
Definition: pbx.c:256
#define ast_hashtab_insert_immediate(tab, obj)
Definition: hashtab.h:291
int priority
Definition: pbx.c:243
#define ast_log
Definition: astobj2.c:42
struct ast_exten * peer
Definition: pbx.c:250
structure to hold extensions
struct ast_hashtab * peer_label_table
Definition: pbx.c:252
char * exten
Definition: pbx.c:238
#define LOG_ERROR
Definition: logger.h:285
char name[0]
Definition: pbx.c:297
int ast_wrlock_context(struct ast_context *con)
Write locks a given context.
Definition: pbx.c:8520
#define LOG_NOTICE
Definition: logger.h:263
static char * registrar
Definition: pbx_ael.c:78
const char * cidmatch
Definition: pbx.c:241
struct ast_hashtab * root_table
Definition: pbx.c:287
int ast_hashtab_size(struct ast_hashtab *tab)
Returns the number of elements stored in the hashtab.
Definition: hashtab.c:577
struct match_char * pattern_tree
Definition: pbx.c:288
static void destroy_exten(struct ast_exten *e)
Definition: pbx.c:4678
int deleted
Definition: pbx.c:264
match_char: forms a syntax tree for quick matching of extension patterns
Definition: pbx.c:261
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

◆ ast_context_remove_ignorepat()

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

Definition at line 6837 of file pbx.c.

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

Referenced by handle_cli_dialplan_remove_ignorepat().

6838 {
6839  int ret = -1;
6840  struct ast_context *c;
6841 
6843  if (c) {
6844  ret = ast_context_remove_ignorepat2(c, ignorepat, registrar);
6846  }
6847  return ret;
6848 }
int ast_context_remove_ignorepat2(struct ast_context *con, const char *ignorepat, const char *registrar)
Definition: pbx.c:6850
static struct test_val c
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:8512
static char * registrar
Definition: pbx_ael.c:78
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:4818
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284

◆ ast_context_remove_ignorepat2()

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

Definition at line 6850 of file pbx.c.

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(), and ast_context::ignorepats.

Referenced by ast_context_remove_ignorepat().

6851 {
6852  int idx;
6853 
6854  ast_wrlock_context(con);
6855 
6856  for (idx = 0; idx < ast_context_ignorepats_count(con); idx++) {
6857  struct ast_ignorepat *ip = AST_VECTOR_GET(&con->ignorepats, idx);
6858 
6859  if (!strcmp(ast_get_ignorepat_name(ip), ignorepat) &&
6862  ignorepat_free(ip);
6863  ast_unlock_context(con);
6864  return 0;
6865  }
6866  }
6867 
6868  ast_unlock_context(con);
6869  errno = EINVAL;
6870  return -1;
6871 }
struct ast_ignorepats ignorepats
Definition: pbx.c:291
int ast_unlock_context(struct ast_context *con)
Definition: pbx.c:8530
const char * ast_get_ignorepat_registrar(const struct ast_ignorepat *ip)
Definition: pbx_ignorepat.c:47
void ignorepat_free(struct ast_ignorepat *ip)
Definition: pbx_ignorepat.c:77
#define AST_VECTOR_REMOVE_ORDERED(vec, idx)
Remove an element from a vector by index while maintaining order.
Definition: vector.h:448
const char * ast_get_ignorepat_name(const struct ast_ignorepat *ip)
Definition: pbx_ignorepat.c:42
int ast_context_ignorepats_count(const struct ast_context *con)
Definition: pbx.c:8740
ast_ignorepat: Ignore patterns in dial plan
Definition: pbx_ignorepat.c:37
int errno
int ast_wrlock_context(struct ast_context *con)
Write locks a given context.
Definition: pbx.c:8520
static char * registrar
Definition: pbx_ael.c:78
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682

◆ 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
Return values
0on success
-1on failure

Remove a context include.

Definition at line 4840 of file pbx.c.

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

Referenced by handle_cli_dialplan_remove_include().

4841 {
4842  int ret = -1;
4843  struct ast_context *c;
4844 
4846  if (c) {
4847  /* found, remove include from this context ... */
4848  ret = ast_context_remove_include2(c, include, registrar);
4850  }
4851  return ret;
4852 }
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, &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: pbx.c:4863
static struct test_val c
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:8512
static char * registrar
Definition: pbx_ael.c:78
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:4818
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284

◆ 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_include2 for information on arguments
Return values
0on success
-1on success

Removes an include by an ast_context structure.

Return values
0on success.
-1on failure.

Definition at line 4863 of file pbx.c.

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(), and ast_context::includes.

Referenced by ast_context_remove_include().

4864 {
4865  int ret = -1;
4866  int idx;
4867 
4868  ast_wrlock_context(con);
4869 
4870  /* find our include */
4871  for (idx = 0; idx < ast_context_includes_count(con); idx++) {
4872  struct ast_include *i = AST_VECTOR_GET(&con->includes, idx);
4873 
4874  if (!strcmp(ast_get_include_name(i), include) &&
4875  (!registrar || !strcmp(ast_get_include_registrar(i), registrar))) {
4876 
4877  /* remove from list */
4878  ast_verb(3, "Removing inclusion of context '%s' in context '%s; registrar=%s'\n", include, ast_get_context_name(con), registrar);
4879  AST_VECTOR_REMOVE_ORDERED(&con->includes, idx);
4880 
4881  /* free include and return */
4882  include_free(i);
4883  ret = 0;
4884  break;
4885  }
4886  }
4887 
4888  ast_unlock_context(con);
4889 
4890  return ret;
4891 }
ast_include: include= support in extensions.conf
Definition: pbx_include.c:37
int ast_unlock_context(struct ast_context *con)
Definition: pbx.c:8530
void include_free(struct ast_include *inc)
Definition: pbx_include.c:106
const char * ast_get_include_registrar(const struct ast_include *i)
Definition: pbx_include.c:60
#define ast_verb(level,...)
Definition: logger.h:463
#define AST_VECTOR_REMOVE_ORDERED(vec, idx)
Remove an element from a vector by index while maintaining order.
Definition: vector.h:448
struct ast_includes includes
Definition: pbx.c:290
int ast_wrlock_context(struct ast_context *con)
Write locks a given context.
Definition: pbx.c:8520
static char * registrar
Definition: pbx_ael.c:78
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
const char * ast_get_include_name(const struct ast_include *include)
Definition: pbx_include.c:50
const char * ast_get_context_name(struct ast_context *con)
Definition: pbx.c:8538
int ast_context_includes_count(const struct ast_context *con)
Definition: pbx.c:8697

◆ 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 rigt context structure, leave context list locked and call ast_context_remove_switch2 which removes switch, unlock contexts list and return ...

Definition at line 4898 of file pbx.c.

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

4899 {
4900  int ret = -1; /* default error return */
4901  struct ast_context *c;
4902 
4904  if (c) {
4905  /* remove switch from this context ... */
4906  ret = ast_context_remove_switch2(c, sw, data, registrar);
4908  }
4909  return ret;
4910 }
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:4920
static struct test_val c
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:8512
static char * registrar
Definition: pbx_ael.c:78
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:4818
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284

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

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

Referenced by ast_context_remove_switch().

4921 {
4922  int idx;
4923  int ret = -1;
4924 
4925  ast_wrlock_context(con);
4926 
4927  /* walk switches */
4928  for (idx = 0; idx < ast_context_switches_count(con); idx++) {
4929  struct ast_sw *i = AST_VECTOR_GET(&con->alts, idx);
4930 
4931  if (!strcmp(ast_get_switch_name(i), sw) &&
4932  !strcmp(ast_get_switch_data(i), data) &&
4933  (!registrar || !strcmp(ast_get_switch_registrar(i), registrar))) {
4934 
4935  /* found, remove from list */
4936  ast_verb(3, "Removing switch '%s' from context '%s; registrar=%s'\n", sw, ast_get_context_name(con), registrar);
4937  AST_VECTOR_REMOVE_ORDERED(&con->alts, idx);
4938 
4939  /* free switch and return */
4940  sw_free(i);
4941  ret = 0;
4942  break;
4943  }
4944  }
4945 
4946  ast_unlock_context(con);
4947 
4948  return ret;
4949 }
const char * ast_get_switch_name(const struct ast_sw *sw)
Definition: pbx_sw.c:48
const char * ast_get_switch_registrar(const struct ast_sw *sw)
Definition: pbx_sw.c:63
int ast_context_switches_count(const struct ast_context *con)
Definition: pbx.c:8652
int ast_unlock_context(struct ast_context *con)
Definition: pbx.c:8530
#define ast_verb(level,...)
Definition: logger.h:463
ast_sw: Switch statement in extensions.conf
Definition: pbx_sw.c:37
const char * data
Definition: pbx_sw.c:42
#define AST_VECTOR_REMOVE_ORDERED(vec, idx)
Remove an element from a vector by index while maintaining order.
Definition: vector.h:448
int ast_wrlock_context(struct ast_context *con)
Write locks a given context.
Definition: pbx.c:8520
static char * registrar
Definition: pbx_ael.c:78
const char * ast_get_switch_data(const struct ast_sw *sw)
Definition: pbx_sw.c:53
void sw_free(struct ast_sw *sw)
Definition: pbx_sw.c:101
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
const char * ast_get_context_name(struct ast_context *con)
Definition: pbx.c:8538
struct ast_sws alts
Definition: pbx.c:292

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

References __ast_context_destroy(), ast_context::autohints, enabled, and ast_exten::registrar.

Referenced by pbx_load_config().

6273 {
6274  con->autohints = enabled;
6275 }
int autohints
Definition: pbx.c:295
static int enabled
Definition: dnsmgr.c:91

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

Definition at line 8657 of file pbx.c.

References ast_context::alts, and AST_VECTOR_GET.

Referenced by ast_context_add_switch2(), ast_walk_context_switches(), context_merge_incls_swits_igps_other_registrars(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), pbx_find_extension(), and show_dialplan_helper().

8658 {
8659  return AST_VECTOR_GET(&con->alts, idx);
8660 }
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
struct ast_sws alts
Definition: pbx.c:292

◆ ast_context_unlockmacro()

int ast_context_unlockmacro ( const char *  context)

Unlocks the macrolock in the given context.

Parameters
macrocontextname of the macro-context to unlock

Unlocks the given macro-context so that another thread (call) can execute it

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

Definition at line 5184 of file pbx.c.

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

Referenced by _macro_exec().

5185 {
5186  struct ast_context *c;
5187  int ret = -1;
5188 
5190  if (c) {
5192 
5193  /* if we found context, unlock macrolock */
5194  ret = ast_mutex_unlock(&c->macrolock);
5195  }
5196 
5197  return ret;
5198 }
static struct test_val c
ast_mutex_t macrolock
Definition: pbx.c:296
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:8512
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:4818
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ 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 632 of file conf2ael.c.

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

Referenced by ast_context_destroy(), and pbx_load_module().

633 {
635 }
int localized_context_verify_includes(struct ast_context *con)
Definition: extconf.c:5640

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

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

274 {
275  struct ast_custom_function *cur;
276 
277  if (!acf) {
278  return -1;
279  }
280 
282  cur = AST_RWLIST_REMOVE(&acf_root, acf, acflist);
283  if (cur) {
284 #ifdef AST_XML_DOCS
285  if (cur->docsrc == AST_XML_DOC) {
287  }
288 #endif
289  ast_verb(2, "Unregistered custom function %s\n", cur->name);
290  }
292 
293  return cur ? 0 : -1;
294 }
const char * name
Definition: pbx.h:119
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
enum ast_doc_src docsrc
Definition: pbx.h:127
#define ast_verb(level,...)
Definition: logger.h:463
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
Registered functions container.
Definition: pbx_functions.c:59
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:884
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:368

◆ 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 285 of file pbx_timing.c.

References ast_free, NULL, and ast_timing::timezone.

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

286 {
287  if (i->timezone) {
288  ast_free(i->timezone);
289  i->timezone = NULL;
290  }
291  return 0;
292 }
#define NULL
Definition: resample.c:96
#define ast_free(a)
Definition: astmm.h:182
char * timezone
Definition: pbx.h:177

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

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

Referenced by ast_extension_state3(), AST_TEST_DEFINE(), and handle_show_device2extenstate().

3007 {
3008  switch (devstate) {
3009  case AST_DEVICE_ONHOLD:
3010  return AST_EXTENSION_ONHOLD;
3011  case AST_DEVICE_BUSY:
3012  return AST_EXTENSION_BUSY;
3013  case AST_DEVICE_UNKNOWN:
3014  return AST_EXTENSION_NOT_INUSE;
3016  case AST_DEVICE_INVALID:
3018  case AST_DEVICE_RINGINUSE:
3020  case AST_DEVICE_RINGING:
3021  return AST_EXTENSION_RINGING;
3022  case AST_DEVICE_INUSE:
3023  return AST_EXTENSION_INUSE;
3024  case AST_DEVICE_NOT_INUSE:
3025  return AST_EXTENSION_NOT_INUSE;
3026  case AST_DEVICE_TOTAL: /* not a device state, included for completeness */
3027  break;
3028  }
3029 
3030  return AST_EXTENSION_NOT_INUSE;
3031 }

◆ 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.
Examples:
/usr/src/asterisk-18.5.0/main/app.c.

Definition at line 4179 of file pbx.c.

References E_MATCH, NULL, and pbx_extension_helper().

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

4180 {
4181  return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCH, 0, 0);
4182 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
#define NULL
Definition: resample.c:96
static int priority
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
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:2875

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

Definition at line 6987 of file pbx.c.

References ast_channel_context_set(), ast_channel_exten_set(), ast_channel_flags(), ast_channel_lock, ast_channel_priority_set(), ast_channel_unlock, AST_FLAG_IN_AUTOLOOP, ast_strlen_zero, ast_test_flag, and ast_exten::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().

6988 {
6989  if (!chan)
6990  return -1;
6991 
6992  ast_channel_lock(chan);
6993 
6994  if (!ast_strlen_zero(context))
6996  if (!ast_strlen_zero(exten))
6998  if (priority > -1) {
6999  /* see flag description in channel.h for explanation */
7001  --priority;
7002  }
7004  }
7005 
7006  ast_channel_unlock(chan);
7007 
7008  return 0;
7009 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
#define ast_test_flag(p, flag)
Definition: utils.h:63
static int priority
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_channel_unlock(chan)
Definition: channel.h:2946
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
void ast_channel_context_set(struct ast_channel *chan, const char *value)
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
void ast_channel_priority_set(struct ast_channel *chan, int value)

◆ ast_extension_close()

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

Definition at line 2418 of file pbx.c.

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

Referenced by lua_find_extension(), and realtime_switch_common().

2419 {
2420  if (needmore != E_MATCHMORE && needmore != E_CANMATCH)
2421  ast_log(LOG_WARNING, "invalid argument %d\n", needmore);
2422  return extension_match_core(pattern, data, needmore);
2423 }
#define LOG_WARNING
Definition: logger.h:274
#define ast_log
Definition: astobj2.c:42
static int extension_match_core(const char *pattern, const char *data, enum ext_match_t mode)
Definition: pbx.c:2400

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

References ext_cmp().

Referenced by lua_extension_cmp().

2184 {
2185  int cmp;
2186 
2187  cmp = ext_cmp(a, b);
2188  if (cmp < 0) {
2189  return -1;
2190  }
2191  if (cmp > 0) {
2192  return 1;
2193  }
2194  return 0;
2195 }
static int ext_cmp(const char *left, const char *right)
Definition: pbx.c:2126
static struct test_val b
static struct test_val a

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

References E_MATCH, and extension_match_core().

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

4298 {
4299  return extension_match_core(pattern, data, E_MATCH);
4300 }
static int extension_match_core(const char *pattern, const char *data, enum ext_match_t mode)
Definition: extconf.c:4288

◆ 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

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

Definition at line 3170 of file pbx.c.

References internal_extension_state_extended(), and NULL.

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

3171 {
3173 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
static int internal_extension_state_extended(struct ast_channel *c, const char *context, const char *exten, struct ao2_container *device_state_info)
Definition: pbx.c:3141
#define NULL
Definition: resample.c:96
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

◆ 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

Return string representation of the state of an extension.

Definition at line 3126 of file pbx.c.

References ARRAY_LEN, extension_states, and cfextension_states::text.

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

3127 {
3128  int i;
3129 
3130  for (i = 0; (i < ARRAY_LEN(extension_states)); i++) {
3131  if (extension_states[i].extension_state == extension_state)
3132  return extension_states[i].text;
3133  }
3134  return "Unknown";
3135 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
const char *const text
Definition: pbx.c:608
static const struct cfextension_states extension_states[]

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

References extension_state_add_destroy(), and NULL.

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

3827 {
3828  return extension_state_add_destroy(context, exten, change_cb, NULL, data, 0);
3829 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
#define NULL
Definition: resample.c:96
static int 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, int extended)
Definition: pbx.c:3729
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

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

References extension_state_add_destroy().

3821 {
3822  return extension_state_add_destroy(context, exten, change_cb, destroy_cb, data, 0);
3823 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
static int 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, int extended)
Definition: pbx.c:3729
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

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

References extension_state_add_destroy().

Referenced by handle_request_subscribe(), and subscription_established().

3833 {
3834  return extension_state_add_destroy(context, exten, change_cb, destroy_cb, data, 1);
3835 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
static int 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, int extended)
Definition: pbx.c:3729
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

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

References extension_state_add_destroy(), and NULL.

3839 {
3840  return extension_state_add_destroy(context, exten, change_cb, NULL, data, 1);
3841 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
#define NULL
Definition: resample.c:96
static int 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, int extended)
Definition: pbx.c:3729
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

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

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

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

3859 {
3860  struct ast_state_cb *p_cur;
3861  int ret = -1;
3862 
3863  if (!id) { /* id == 0 is a callback without extension */
3864  if (!change_cb) {
3865  return ret;
3866  }
3868  if (p_cur) {
3869  ret = 0;
3870  ao2_ref(p_cur, -1);
3871  }
3872  } else { /* callback with extension, find the callback based on ID */
3873  struct ast_hint *hint;
3874 
3875  ao2_lock(hints);/* Locked to hold off ast_merge_contexts_and_delete */
3876  hint = ao2_callback(hints, 0, find_hint_by_cb_id, &id);
3877  if (hint) {
3878  p_cur = ao2_find(hint->callbacks, &id, OBJ_UNLINK);
3879  if (p_cur) {
3880  ret = 0;
3881  ao2_ref(p_cur, -1);
3882  }
3883  ao2_ref(hint, -1);
3884  }
3885  ao2_unlock(hints);
3886  }
3887 
3888  return ret;
3889 }
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
ast_state_cb: An extension state notify register item
Definition: pbx.c:301
#define ao2_unlock(a)
Definition: astobj2.h:730
ast_state_cb_type change_cb
Definition: pbx.c:309
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ao2_lock(a)
Definition: astobj2.h:718
Structure for dial plan hints.
Definition: pbx.c:324
struct ao2_container * callbacks
Definition: pbx.c:332
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
static int find_hint_by_cb_id(void *obj, void *arg, int flags)
Find Hint by callback id.
Definition: pbx.c:3844
static struct ao2_container * statecbs
Definition: pbx.c:803

◆ 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

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

Definition at line 3176 of file pbx.c.

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

Referenced by exten_state_data_alloc(), and handle_request_subscribe().

3178 {
3179  struct ao2_container *container = NULL;
3180  int ret;
3181 
3182  if (device_state_info) {
3183  container = alloc_device_state_info();
3184  }
3185 
3186  ret = internal_extension_state_extended(c, context, exten, container);
3187  if (ret < 0 && container) {
3188  ao2_ref(container, -1);
3189  container = NULL;
3190  }
3191 
3192  if (device_state_info) {
3194  *device_state_info = container;
3195  }
3196 
3197  return ret;
3198 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
static struct ao2_container * alloc_device_state_info(void)
Definition: pbx.c:3076
static int internal_extension_state_extended(struct ast_channel *c, const char *context, const char *exten, struct ao2_container *device_state_info)
Definition: pbx.c:3141
#define NULL
Definition: resample.c:96
static void get_device_state_causing_channels(struct ao2_container *c)
Definition: pbx.c:3296
#define ao2_ref(o, delta)
Definition: astobj2.h:464
struct ao2_container * container
Definition: res_fax.c:502
Generic container type.
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

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

References E_FINDLABEL, NULL, and pbx_extension_helper().

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

4185 {
4186  return pbx_extension_helper(c, NULL, context, exten, 0, label, callerid, E_FINDLABEL, 0, 0);
4187 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
#define NULL
Definition: resample.c:96
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
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:2875

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

References E_FINDLABEL, NULL, and pbx_extension_helper().

Referenced by pbx_load_config().

4979 {
4980  return pbx_extension_helper(c, con, NULL, exten, 0, label, callerid, E_FINDLABEL);
4981 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
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:4917
#define NULL
Definition: resample.c:96

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

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

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

600 {
601  char *copy = ast_strdupa(function);
602  char *args = func_args(copy);
603  struct ast_custom_function *acfptr = ast_custom_function_find(copy);
604  int res;
605  struct ast_module_user *u = NULL;
606 
607  if (acfptr == NULL) {
608  ast_log(LOG_ERROR, "Function %s not registered\n", copy);
609  } else if (!acfptr->read && !acfptr->read2) {
610  ast_log(LOG_ERROR, "Function %s cannot be read\n", copy);
611  } else if (!is_read_allowed(acfptr)) {
612  ast_log(LOG_ERROR, "Dangerous function %s read blocked\n", copy);
613  } else if (acfptr->read) {
614  if (acfptr->mod) {
615  u = __ast_module_user_add(acfptr->mod, chan);
616  }
617  res = acfptr->read(chan, copy, args, workspace, len);
618  if (acfptr->mod && u) {
619  __ast_module_user_remove(acfptr->mod, u);
620  }
621 
622  return res;
623  } else {
624  struct ast_str *str = ast_str_create(16);
625 
626  if (acfptr->mod) {
627  u = __ast_module_user_add(acfptr->mod, chan);
628  }
629  res = acfptr->read2(chan, copy, args, &str, 0);
630  if (acfptr->mod && u) {
631  __ast_module_user_remove(acfptr->mod, u);
632  }
633  ast_copy_string(workspace, ast_str_buffer(str), len > ast_str_size(str) ? ast_str_size(str) : len);
634  ast_free(str);
635 
636  return res;
637  }
638 
639  return -1;
640 }
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition: strings.h:699
static int is_read_allowed(struct ast_custom_function *acfptr)
Determines whether execution of a custom function&#39;s read function is allowed.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void __ast_module_user_remove(struct ast_module *, struct ast_module_user *)
Definition: loader.c:826
static int copy(char *infile, char *outfile)
Utility function to copy a file.
struct ast_module * mod
Definition: pbx.h:142
const char * str
Definition: app_jack.c:147
const char * args
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
static char * func_args(char *function)
return a pointer to the arguments of the function, and terminates the function name with &#39;\0&#39; ...
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
struct ast_module_user * __ast_module_user_add(struct ast_module *, struct ast_channel *)
Definition: loader.c:800
#define LOG_ERROR
Definition: logger.h:285
ast_acf_read2_fn_t read2
Definition: pbx.h:137
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_free(a)
Definition: astmm.h:182
struct ast_custom_function * ast_custom_function_find(const char *name)
ast_acf_read_fn_t read
Definition: pbx.h:129
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

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

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

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

643 {
644  char *copy = ast_strdupa(function);
645  char *args = func_args(copy);
646  struct ast_custom_function *acfptr = ast_custom_function_find(copy);
647  int res;
648  struct ast_module_user *u = NULL;
649 
650  if (acfptr == NULL) {
651  ast_log(LOG_ERROR, "Function %s not registered\n", copy);
652  } else if (!acfptr->read && !acfptr->read2) {
653  ast_log(LOG_ERROR, "Function %s cannot be read\n", copy);
654  } else if (!is_read_allowed(acfptr)) {
655  ast_log(LOG_ERROR, "Dangerous function %s read blocked\n", copy);
656  } else {
657  if (acfptr->mod) {
658  u = __ast_module_user_add(acfptr->mod, chan);
659  }
660  ast_str_reset(*str);
661  if (acfptr->read2) {
662  /* ast_str enabled */
663  res = acfptr->read2(chan, copy, args, str, maxlen);
664  } else {
665  /* Legacy function pointer, allocate buffer for result */
666  int maxsize = ast_str_size(*str);
667 
668  if (maxlen > -1) {
669  if (maxlen == 0) {
670  if (acfptr->read_max) {
671  maxsize = acfptr->read_max;
672  } else {
673  maxsize = VAR_BUF_SIZE;
674  }
675  } else {
676  maxsize = maxlen;
677  }
678  ast_str_make_space(str, maxsize);
679  }
680  res = acfptr->read(chan, copy, args, ast_str_buffer(*str), maxsize);
681  }
682  if (acfptr->mod && u) {
683  __ast_module_user_remove(acfptr->mod, u);
684  }
685 
686  return res;
687  }
688 
689  return -1;
690 }
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition: strings.h:699
static int is_read_allowed(struct ast_custom_function *acfptr)
Determines whether execution of a custom function&#39;s read function is allowed.
#define ast_str_make_space(buf, new_len)
Definition: strings.h:780
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
void __ast_module_user_remove(struct ast_module *, struct ast_module_user *)
Definition: loader.c:826
static int copy(char *infile, char *outfile)
Utility function to copy a file.
struct ast_module * mod
Definition: pbx.h:142
const char * args
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
static char * func_args(char *function)
return a pointer to the arguments of the function, and terminates the function name with &#39;\0&#39; ...
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
size_t read_max
Definition: pbx.h:139
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
struct ast_module_user * __ast_module_user_add(struct ast_module *, struct ast_channel *)
Definition: loader.c:800
#define LOG_ERROR
Definition: logger.h:285
ast_acf_read2_fn_t read2
Definition: pbx.h:137
#define VAR_BUF_SIZE
Definition: pbx_private.h:68
static int maxsize
struct ast_custom_function * ast_custom_function_find(const char *name)
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:653
ast_acf_read_fn_t read
Definition: pbx.h:129

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

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

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

693 {
694  char *copy = ast_strdupa(function);
695  char *args = func_args(copy);
696  struct ast_custom_function *acfptr = ast_custom_function_find(copy);
697 
698  if (acfptr == NULL) {
699  ast_log(LOG_ERROR, "Function %s not registered\n", copy);
700  } else if (!acfptr->write) {
701  ast_log(LOG_ERROR, "Function %s cannot be written to\n", copy);
702  } else if (!is_write_allowed(acfptr)) {
703  ast_log(LOG_ERROR, "Dangerous function %s write blocked\n", copy);
704  } else {
705  int res;
706  struct ast_module_user *u = NULL;
707 
708  if (acfptr->mod) {
709  u = __ast_module_user_add(acfptr->mod, chan);
710  }
711  res = acfptr->write(chan, copy, args, value);
712  if (acfptr->mod && u) {
713  __ast_module_user_remove(acfptr->mod, u);
714  }
715 
716  return res;
717  }
718 
719  return -1;
720 }
void __ast_module_user_remove(struct ast_module *, struct ast_module_user *)
Definition: loader.c:826
static int copy(char *infile, char *outfile)
Utility function to copy a file.
struct ast_module * mod
Definition: pbx.h:142
static int is_write_allowed(struct ast_custom_function *acfptr)
Determines whether execution of a custom function&#39;s write function is allowed.
const char * args
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
#define ast_log
Definition: astobj2.c:42
static char * func_args(char *function)
return a pointer to the arguments of the function, and terminates the function name with &#39;\0&#39; ...
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
ast_acf_write_fn_t write
Definition: pbx.h:141
struct ast_module_user * __ast_module_user_add(struct ast_module *, struct ast_channel *)
Definition: loader.c:800
#define LOG_ERROR
Definition: logger.h:285
struct ast_custom_function * ast_custom_function_find(const char *name)

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

References NULL, and ast_context::registrar.

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

8567 {
8568  return c ? c->registrar : NULL;
8569 }
#define NULL
Definition: resample.c:96
char * registrar
Definition: pbx.c:293

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

Definition at line 8601 of file pbx.c.

References ast_exten::data, and NULL.

Referenced by _macro_exec(), add_extension(), ast_get_hint(), ast_str_get_hint(), get_extension_data(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), parking_blind_transfer_park(), and print_ext().

8602 {
8603  return e ? e->data : NULL;
8604 }
#define NULL
Definition: resample.c:96
void * data
Definition: pbx.c:248

◆ ast_get_extension_cidmatch()

const char* ast_get_extension_cidmatch ( struct ast_exten e)

Definition at line 8591 of file pbx.c.

References ast_exten::cidmatch_display, and NULL.

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

8592 {
8593  return e ? e->cidmatch_display : NULL;
8594 }
#define NULL
Definition: resample.c:96
const char * cidmatch_display
Definition: pbx.c:242

◆ ast_get_extension_context()

struct ast_context* ast_get_extension_context ( struct ast_exten exten)

Definition at line 8543 of file pbx.c.

References NULL, and ast_exten::parent.

Referenced by ast_add_hint(), ast_change_hint(), ast_remove_hint(), device_state_notify_callbacks(), extension_is_compatible(), handle_show_hint(), handle_show_hints(), presence_state_notify_callbacks(), print_hintdevices_key(), and print_hints_key().

8544 {
8545  return exten ? exten->parent : NULL;
8546 }
#define NULL
Definition: resample.c:96
struct ast_context * parent
Definition: pbx.c:245

◆ ast_get_extension_label()

const char* ast_get_extension_label ( struct ast_exten e)

Definition at line 8553 of file pbx.c.

References ast_exten::label, and NULL.

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

8554 {
8555  return exten ? exten->label : NULL;
8556 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
#define NULL
Definition: resample.c:96

◆ ast_get_extension_matchcid()

int ast_get_extension_matchcid ( struct ast_exten e)

Definition at line 8586 of file pbx.c.

References ast_exten::matchcid.

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

8587 {
8588  return e ? e->matchcid : 0;
8589 }
int matchcid
Definition: pbx.c:240

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

Definition at line 8558 of file pbx.c.

References ast_exten::priority.

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

8559 {
8560  return exten ? exten->priority : -1;
8561 }
int priority
Definition: pbx.c:243

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

References NULL, and ast_exten::registrar_file.

Referenced by show_dialplan_helper_extension_output().

8577 {
8578  return e ? e->registrar_file : NULL;
8579 }
#define NULL
Definition: resample.c:96
const char * registrar_file
Definition: pbx.c:254

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

References ast_exten::registrar_line.

Referenced by show_dialplan_helper_extension_output().

8582 {
8583  return e ? e->registrar_line : 0;
8584 }
int registrar_line
Definition: pbx.c:255

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

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

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

4142 {
4143  struct ast_exten *e = ast_hint_extension(c, context, exten);
4144 
4145  if (e) {
4146  if (hint)
4147  ast_copy_string(hint, ast_get_extension_app(e), hintsize);
4148  if (name) {
4149  const char *tmp = ast_get_extension_app_data(e);
4150  if (tmp)
4151  ast_copy_string(name, tmp, namesize);
4152  }
4153  return -1;
4154  }
4155  return 0;
4156 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
ast_exten: An extension The dialplan is saved as a linked list with each context having it&#39;s own link...
Definition: pbx.c:237
static int tmp()
Definition: bt_open.c:389
void * ast_get_extension_app_data(struct ast_exten *e)
Definition: pbx.c:8601
static struct ast_exten * ast_hint_extension(struct ast_channel *c, const char *context, const char *exten)
Definition: pbx.c:2997
static const char name[]
Definition: cdr_mysql.c:74
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
const char * ast_get_extension_app(struct ast_exten *e)
Definition: pbx.c:8596
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

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

References ast_sw::eval.

Referenced by context_merge_incls_swits_igps_other_registrars(), and pbx_find_extension().

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

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

References __ast_goto_if_exists().

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

8794 {
8795  return __ast_goto_if_exists(chan, context, exten, priority, 0);
8796 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
static int __ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, int async)
Definition: pbx.c:8772
static int priority
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

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

References ast_hashtab_hash_contexts(), bc, and ast_context::name.

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

590 {
591  return 0;
592 }

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

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

Referenced by exten_state_data_alloc(), and handle_request_subscribe().

3227 {
3228  struct ast_exten *e;
3229 
3230  if (!(e = ast_hint_extension(c, context, exten))) { /* Do we have a hint for this extension ? */
3231  return -1; /* No hint, return -1 */
3232  }
3233 
3234  if (e->exten[0] == '_') {
3235  /* Create this hint on-the-fly */
3236  ao2_lock(hints);
3237  ast_add_extension(e->parent->name, 0, exten, e->priority, e->label,
3238  e->matchcid ? e->cidmatch : NULL, e->app, ast_strdup(e->data), ast_free_ptr,
3239  e->registrar);
3240  ao2_unlock(hints);
3241  if (!(e = ast_hint_extension(c, context, exten))) {
3242  /* Improbable, but not impossible */
3243  return -1;
3244  }
3245  }
3246 
3247  return extension_presence_state_helper(e, subtype, message);
3248 }
const char * label
Definition: pbx.c:244
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
ast_exten: An extension The dialplan is saved as a linked list with each context having it&#39;s own link...
Definition: pbx.c:237
static int extension_presence_state_helper(struct ast_exten *e, char **subtype, char **message)
Definition: pbx.c:3200
#define ao2_unlock(a)
Definition: astobj2.h:730
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
void ast_free_ptr(void *ptr)
free() wrapper
Definition: astmm.c:1771
const char * registrar
Definition: pbx.c:253
int matchcid
Definition: pbx.c:240
int priority
Definition: pbx.c:243
static struct ast_exten * ast_hint_extension(struct ast_channel *c, const char *context, const char *exten)
Definition: pbx.c:2997
#define ao2_lock(a)
Definition: astobj2.h:718
char * exten
Definition: pbx.c:238
char name[0]
Definition: pbx.c:297
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.
Definition: pbx.c:6970
const char * cidmatch
Definition: pbx.c:241
const char * app
Definition: pbx.c:246
struct ast_context * parent
Definition: pbx.c:245
void * data
Definition: pbx.c:248
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

◆ 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
Examples:
/usr/src/asterisk-18.5.0/main/app.c.

Definition at line 6921 of file pbx.c.

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

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

6922 {
6923  int ret = 0;
6924  struct ast_context *con;
6925 
6927  con = ast_context_find(context);
6928  if (con) {
6929  int idx;
6930 
6931  for (idx = 0; idx < ast_context_ignorepats_count(con); idx++) {
6932  const struct ast_ignorepat *pat = ast_context_ignorepats_get(con, idx);
6933 
6935  ret = 1;
6936  break;
6937  }
6938  }
6939  }
6941 
6942  return ret;
6943 }
const char pattern[0]
Definition: pbx_ignorepat.c:39
const struct ast_ignorepat * ast_context_ignorepats_get(const struct ast_context *con, int idx)
Definition: pbx.c:8745
struct ast_context * ast_context_find(const char *name)
Find a context.
Definition: pbx.c:2443
int ast_rdlock_contexts(void)
Read locks the context list.
Definition: pbx.c:8507
const char * ast_get_ignorepat_name(const struct ast_ignorepat *ip)
Definition: pbx_ignorepat.c:42
int ast_context_ignorepats_count(const struct ast_context *con)
Definition: pbx.c:8740
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:8512
ast_ignorepat: Ignore patterns in dial plan
Definition: pbx_ignorepat.c:37
int ast_extension_match(const char *pattern, const char *data)
Determine if a given extension matches a given pattern (in NXX format)
Definition: pbx.c:2413
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284

◆ 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 serach 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
Examples:
/usr/src/asterisk-18.5.0/main/app.c.

Definition at line 4199 of file pbx.c.

References E_MATCHMORE, NULL, and pbx_extension_helper().

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

4200 {
4201  return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCHMORE, 0, 0);
4202 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
#define NULL
Definition: resample.c:96
static int priority
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
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:2875

◆ 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 639 of file conf2ael.c.

References __ast_internal_context_destroy(), ao2_callback, ao2_container_count(), ao2_find, ao2_iterator_destroy(), AO2_ITERATOR_DONTLOCK, ao2_iterator_init(), ao2_iterator_next, ao2_link, ao2_lock, ao2_ref, ao2_unlock, ast_exten::app, ast_add_extension_nolock(), ast_calloc, ast_copy_string(), ast_free, ast_free_ptr(), ast_get_context_name(), ast_hashtab_destroy(), ast_hashtab_end_traversal(), ast_hashtab_next(), ast_hashtab_start_traversal, ast_hint_extension_nolock(), AST_HINT_UPDATE_DEVICE, AST_LIST_HEAD_NOLOCK_INIT_VALUE, AST_LIST_INSERT_HEAD, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_HEAD, ast_mutex_lock, ast_mutex_unlock, ast_strdup, ast_tvdiff_us(), ast_tvnow(), ast_unlock_contexts(), ast_verb, ast_wrlock_contexts(), ast_hint::callbacks, store_hint::callbacks, ast_state_cb::change_cb, store_hint::context, context_merge(), context_merge_lock, context_table_create_autohints(), contexts, contexts_table, ast_exten::data, ast_state_cb::data, E_MATCH, execute_state_callback(), ast_exten::exten, ast_hint::exten, store_hint::exten, ast_hint::last_presence_message, store_hint::last_presence_message, ast_hint::last_presence_state, store_hint::last_presence_state, ast_hint::last_presence_subtype, store_hint::last_presence_subtype, ast_hint::laststate, store_hint::laststate, localized_merge_contexts_and_delete(), ast_context::name, ast_exten::next, ast_context::next, NULL, OBJ_UNLINK, ast_exten::parent, pbx_find_extension(), PRIORITY_HINT, ast_exten::registrar, pbx_find_info::stacklen, and tmp().

Referenced by ast_context_verify_includes(), lua_reload_extensions(), and pbx_load_module().

640 {
641  localized_merge_contexts_and_delete(extcontexts, exttable, registrar);
642 }
void localized_merge_contexts_and_delete(struct ast_context **extcontexts, void *tab, const char *registrar)
Definition: extconf.c:5618
static char * registrar
Definition: pbx_ael.c:78

◆ 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.
Examples:
/usr/src/asterisk-18.5.0/main/app.c.

Definition at line 8859 of file pbx.c.

References pbx_parseable_goto().

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

8860 {
8861  return pbx_parseable_goto(chan, goto_string, 0);
8862 }
static int pbx_parseable_goto(struct ast_channel *chan, const char *goto_string, int async)
Definition: pbx.c:8803

◆ 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.
Returns
Nothing

Definition at line 4209 of file pbx.c.

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

Referenced by __ast_pbx_run(), and ast_bridge_setup_after_goto().

4210 {
4211  int autoloopflag;
4212  int found;
4213  int spawn_error;
4214 
4215  ast_channel_lock(chan);
4216 
4217  /*
4218  * Make sure that the channel is marked as hungup since we are
4219  * going to run the h exten on it.
4220  */
4222 
4223  /* Set h exten location */
4224  if (context != ast_channel_context(chan)) {
4226  }
4227  ast_channel_exten_set(chan, "h");
4228  ast_channel_priority_set(chan, 1);
4229 
4230  /* Save autoloop flag */
4231  autoloopflag = ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_AUTOLOOP);
4233  ast_channel_unlock(chan);
4234 
4235  for (;;) {
4236  spawn_error = ast_spawn_extension(chan, ast_channel_context(chan),
4238  S_COR(ast_channel_caller(chan)->id.number.valid,
4239  ast_channel_caller(chan)->id.number.str, NULL), &found, 1);
4240 
4241  ast_channel_lock(chan);
4242  if (spawn_error) {
4243  /* The code after the loop needs the channel locked. */
4244  break;
4245  }
4247  ast_channel_unlock(chan);
4248  }
4249  if (found && spawn_error) {
4250  /* Something bad happened, or a hangup has been requested. */
4251  ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n",
4253  ast_channel_priority(chan), ast_channel_name(chan));
4254  ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n",
4256  ast_channel_priority(chan), ast_channel_name(chan));
4257  }
4258 
4259  /* An "h" exten has been run, so indicate that one has been run. */
4261 
4262  /* Restore autoloop flag */
4264  ast_channel_unlock(chan);
4265 }
struct ast_party_caller * ast_channel_caller(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:4204
#define ast_channel_lock(chan)
Definition: channel.h:2945
#define ast_set2_flag(p, value, flag)
Definition: utils.h:94
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define ast_set_flag(p, flag)
Definition: utils.h:70
#define NULL
Definition: resample.c:96
int ast_channel_priority(const struct ast_channel *chan)
#define ast_verb(level,...)
Definition: logger.h:463
Number structure.
Definition: app_followme.c:154
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#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:85
const char * ast_channel_exten(const struct ast_channel *chan)
int ast_softhangup_nolock(struct ast_channel *chan, int reason)
Softly hangup up a channel (no channel lock)
Definition: channel.c:2463
#define ast_channel_unlock(chan)
Definition: channel.h:2946
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
void ast_channel_context_set(struct ast_channel *chan, const char *value)
const char * ast_channel_name(const struct ast_channel *chan)
const char * ast_channel_context(const struct ast_channel *chan)
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
void ast_channel_priority_set(struct ast_channel *chan, int value)

◆ 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.
Returns
Nothing

Definition at line 103 of file pbx_hangup_handler.c.

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

Referenced by ast_channel_destructor(), and ast_dummy_channel_destructor().

104 {
105  struct ast_hangup_handler_list *handlers;
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 */
111  handlers = ast_channel_hangup_handlers(chan);
112  while ((h_handler = AST_LIST_REMOVE_HEAD(handlers, node))) {
113  ast_free(h_handler);
114  }
115 
116  ast_channel_unlock(chan);
117 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
Definition: test_heap.c:38
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
#define ast_channel_unlock(chan)
Definition: channel.h:2946
struct ast_hangup_handler_list * ast_channel_hangup_handlers(struct ast_channel *chan)
#define ast_free(a)
Definition: astmm.h:182

◆ 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.
Returns
Nothing

Definition at line 95 of file pbx_hangup_handler.c.

References ast_channel_hangup_handlers(), and AST_LIST_HEAD_INIT_NOLOCK.

Referenced by __ast_channel_alloc_ap(), and __ast_dummy_channel_alloc().

96 {
97  struct ast_hangup_handler_list *handlers;
98 
99  handlers = ast_channel_hangup_handlers(chan);
100  AST_LIST_HEAD_INIT_NOLOCK(handlers);
101 }
struct ast_hangup_handler_list * ast_channel_hangup_handlers(struct ast_channel *chan)
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:680

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

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

Referenced by func_channel_write_real().

120 {
121  struct ast_hangup_handler_list *handlers;
122  struct ast_hangup_handler *h_handler;
123 
124  ast_channel_lock(chan);
125  handlers = ast_channel_hangup_handlers(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 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
Definition: test_heap.c:38
static void publish_hangup_handler_message(const char *action, struct ast_channel *chan, const char *handler)
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
#define ast_channel_unlock(chan)
Definition: channel.h:2946
struct ast_hangup_handler_list * ast_channel_hangup_handlers(struct ast_channel *chan)
#define ast_free(a)
Definition: astmm.h:182

◆ 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.
Returns
Nothing

Definition at line 138 of file pbx_hangup_handler.c.

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

Referenced by func_channel_write_real().

139 {
140  struct ast_hangup_handler_list *handlers;
141  struct ast_hangup_handler *h_handler;
142  const char *expanded_handler;
143 
144  if (ast_strlen_zero(handler)) {
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 
162  handlers = ast_channel_hangup_handlers(chan);
163  AST_LIST_INSERT_HEAD(handlers, h_handler, node);
164  publish_hangup_handler_message("push", chan, h_handler->args);
165  ast_channel_unlock(chan);
166 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
Definition: test_heap.c:38
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:351
static void publish_hangup_handler_message(const char *action, struct ast_channel *chan, const char *handler)
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:193
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:710
#define ast_channel_unlock(chan)
Definition: channel.h:2946
struct ast_hangup_handler_list * ast_channel_hangup_handlers(struct ast_channel *chan)
#define ast_free(a)
Definition: astmm.h:182
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

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

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

Referenced by __ast_pbx_run(), and ast_hangup().

59 {
60  struct ast_hangup_handler_list *handlers;
61  struct ast_hangup_handler *h_handler;
62 
63  ast_channel_lock(chan);
64  handlers = ast_channel_hangup_handlers(chan);
65  if (AST_LIST_EMPTY(handlers)) {
66  ast_channel_unlock(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 (;;) {
77  handlers = ast_channel_hangup_handlers(chan);
78  h_handler = AST_LIST_REMOVE_HEAD(handlers, node);
79  if (!h_handler) {
80  break;
81  }
82 
83  publish_hangup_handler_message("run", chan, h_handler->args);
84  ast_channel_unlock(chan);
85 
86  ast_app_exec_sub(NULL, chan, h_handler->args, 1);
87  ast_free(h_handler);
88 
89  ast_channel_lock(chan);
90  }
91  ast_channel_unlock(chan);
92  return 1;
93 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
Definition: test_heap.c:38
static void publish_hangup_handler_message(const char *action, struct ast_channel *chan, const char *handler)
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
#define NULL
Definition: resample.c:96
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
int ast_softhangup_nolock(struct ast_channel *chan, int reason)
Softly hangup up a channel (no channel lock)
Definition: channel.c:2463
#define ast_channel_unlock(chan)
Definition: channel.h:2946
struct ast_hangup_handler_list * ast_channel_hangup_handlers(struct ast_channel *chan)
#define ast_free(a)
Definition: astmm.h:182
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:370

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

References ast_pbx_outgoing_app_predial(), and NULL.

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

8020 {
8021  return ast_pbx_outgoing_app_predial(type, cap, addr, timeout, app, appdata, reason, synchronous,
8022  cid_num, cid_name, vars, account, locked_channel, assignedids, NULL);
8023 }
static const char type[]
Definition: chan_ooh323.c:109
static int timeout
Definition: cdr_mysql.c:86
#define NULL
Definition: resample.c:96
static char cid_num[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:164
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:165
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:8025
static const char app[]
Definition: app_mysql.c:62

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

References ast_strlen_zero, NULL, and pbx_outgoing_attempt().

Referenced by ast_pbx_outgoing_app(), and originate_exec().

8030 {
8031  if (reason) {
8032  *reason = 0;
8033  }
8034  if (locked_channel) {
8035  *locked_channel = NULL;
8036  }
8037  if (ast_strlen_zero(app)) {
8038  return -1;
8039  }
8040 
8041  return pbx_outgoing_attempt(type, cap, addr, timeout, NULL, NULL, 0, app, appdata,
8042  reason, synchronous, cid_num, cid_name, vars, account, locked_channel, 0,
8043  assignedids, predial_callee);
8044 }
static const char type[]
Definition: chan_ooh323.c:109
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:7755
static int timeout
Definition: cdr_mysql.c:86
#define NULL
Definition: resample.c:96
static char cid_num[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:164
#define ast_strlen_zero(foo)
Definition: strings.h:52
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:165
static const char app[]
Definition: app_mysql.c:62

◆ 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 exists then run a channel named OutgoingSpoolFailed at failed .
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 7951 of file pbx.c.

References ast_pbx_outgoing_exten_predial(), and NULL.

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

7956 {
7957  return ast_pbx_outgoing_exten_predial(type, cap, addr, timeout, context, exten, priority, reason,
7958  synchronous, cid_num, cid_name, vars, account, locked_channel, early_media, assignedids, NULL);
7959 }
static const char type[]
Definition: chan_ooh323.c:109
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
static int timeout
Definition: cdr_mysql.c:86
#define NULL
Definition: resample.c:96
static int priority
static char cid_num[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:164
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:165
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:7961
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

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

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

Referenced by ast_pbx_outgoing_exten(), and originate_exec().

7966 {
7967  int res;
7968  int my_reason;
7969 
7970  if (!reason) {
7971  reason = &my_reason;
7972  }
7973  *reason = 0;
7974  if (locked_channel) {
7975  *locked_channel = NULL;
7976  }
7977 
7978  res = pbx_outgoing_attempt(type, cap, addr, timeout, context, exten, priority,
7979  NULL, NULL, reason, synchronous, cid_num, cid_name, vars, account, locked_channel,
7980  early_media, assignedids, predial_callee);
7981 
7982  if (res < 0 /* Call failed to get connected for some reason. */
7983  && 0 < synchronous
7984  && ast_exists_extension(NULL, context, "failed", 1, NULL)) {
7985  struct ast_channel *failed;
7986 
7987  /* We do not have to worry about a locked_channel if dialing failed. */
7988  ast_assert(!locked_channel || !*locked_channel);
7989 
7990  /*!
7991  * \todo XXX Not good. The channel name is not unique if more than
7992  * one originate fails at a time.
7993  */
7994  failed = ast_channel_alloc(0, AST_STATE_DOWN, cid_num, cid_name, account,
7995  "failed", context, NULL, NULL, 0, "OutgoingSpoolFailed");
7996  if (failed) {
7997  char failed_reason[12];
7998 
7999  ast_set_variables(failed, vars);
8000  snprintf(failed_reason, sizeof(failed_reason), "%d", *reason);
8001  pbx_builtin_setvar_helper(failed, "REASON", failed_reason);
8002  ast_channel_unlock(failed);
8003 
8004  if (ast_pbx_run(failed)) {
8005  ast_log(LOG_ERROR, "Unable to run PBX on '%s'\n",
8006  ast_channel_name(failed));
8007  ast_hangup(failed);
8008  }
8009  }
8010  }
8011 
8012  return res;
8013 }
static const char type[]
Definition: chan_ooh323.c:109
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
Main Channel structure associated with a channel.
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:7755
static int timeout
Definition: cdr_mysql.c:86
void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars)
adds a list of channel variables to a channel
Definition: channel.c:8217
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
static int priority
static char cid_num[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:164
enum ast_pbx_result ast_pbx_run(struct ast_channel *c)
Execute the PBX in the current thread.
Definition: pbx.c:4759
#define ast_log
Definition: astobj2.c:42
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:4179
#define LOG_ERROR
Definition: logger.h:285
#define ast_channel_unlock(chan)
Definition: channel.h:2946
void ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2548
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:165
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...
const char * ast_channel_name(const struct ast_channel *chan)
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
#define ast_channel_alloc(needqueue, state, cid_num, cid_name, acctcode, exten, context, assignedids, requestor, amaflag,...)
Create a channel structure.
Definition: channel.h:1259

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

References ast_pbx_run_args(), and NULL.

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

4760 {
4761  return ast_pbx_run_args(c, NULL);
4762 }
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:4739
#define NULL
Definition: resample.c:96

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

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

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

4740 {
4741  enum ast_pbx_result res = AST_PBX_SUCCESS;
4742 
4744  ast_log(LOG_WARNING, "PBX requires Asterisk to be fully booted\n");
4745  return AST_PBX_FAILED;
4746  }
4747 
4748  if (increase_call_count(c)) {
4749  return AST_PBX_CALL_LIMIT;
4750  }
4751 
4752  res = __ast_pbx_run(c, args);
4753 
4755 
4756  return res;
4757 }
#define ast_test_flag(p, flag)
Definition: utils.h:63
static void decrease_call_count(void)
Definition: pbx.c:4670
#define LOG_WARNING
Definition: logger.h:274
static enum ast_pbx_result __ast_pbx_run(struct ast_channel *c, struct ast_pbx_args *args)
Definition: pbx.c:4310
#define ast_log
Definition: astobj2.c:42
static int increase_call_count(const struct ast_channel *c)
Increase call count for channel.
Definition: pbx.c:4621
ast_pbx_result
The result codes when starting the PBX on a channel with ast_pbx_start.
Definition: pbx.h:354
struct ast_flags ast_options
Definition: options.c:61

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

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

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

4713 {
4714  pthread_t t;
4715 
4716  if (!c) {
4717  ast_log(LOG_WARNING, "Asked to start thread on NULL channel?\n");
4718  return AST_PBX_FAILED;
4719  }
4720 
4722  ast_log(LOG_WARNING, "PBX requires Asterisk to be fully booted\n");
4723  return AST_PBX_FAILED;
4724  }
4725 
4726  if (increase_call_count(c))
4727  return AST_PBX_CALL_LIMIT;
4728 
4729  /* Start a new thread, and get something handling this channel. */
4731  ast_log(LOG_WARNING, "Failed to create new channel thread\n");
4733  return AST_PBX_FAILED;
4734  }
4735 
4736  return AST_PBX_SUCCESS;
4737 }
#define ast_pthread_create_detached(a, b, c, d)
Definition: utils.h:563
#define ast_test_flag(p, flag)
Definition: utils.h:63
static void decrease_call_count(void)
Definition: pbx.c:4670
#define LOG_WARNING
Definition: logger.h:274
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
static int increase_call_count(const struct ast_channel *c)
Increase call count for channel.
Definition: pbx.c:4621
static void * pbx_thread(void *data)
Definition: pbx.c:4692
struct ast_flags ast_options
Definition: options.c:61

◆ ast_processed_calls()

int ast_processed_calls ( void  )

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

Definition at line 4769 of file pbx.c.

References totalcalls.

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

4770 {
4771  return totalcalls;
4772 }
static int totalcalls
Definition: pbx.c:774

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

References ast_rwlock_rdlock, and ast_context::lock.

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

8526 {
8527  return ast_rwlock_rdlock(&con->lock);
8528 }
#define ast_rwlock_rdlock(a)
Definition: lock.h:233
ast_rwlock_t lock
Definition: pbx.c:285

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

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

Referenced by load_module().

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 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define LOG_WARNING
Definition: logger.h:274
static int tmp()
Definition: bt_open.c:389
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
const char * name
Definition: pbx.h:162
#define ast_log
Definition: astobj2.c:42
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:740
struct ast_switch::@278 list

◆ 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_spawnThis 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 4204 of file pbx.c.

References E_SPAWN, NULL, and pbx_extension_helper().

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

4205 {
4206  return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_SPAWN, found, combined_find_spawn);
4207 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
#define NULL
Definition: resample.c:96
static int priority
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
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:2875

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

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

Referenced by ast_str_retrieve_variable().

4160 {
4161  struct ast_exten *e = ast_hint_extension(c, context, exten);
4162 
4163  if (!e) {
4164  return 0;
4165  }
4166 
4167  if (hint) {
4168  ast_str_set(hint, hintsize, "%s", ast_get_extension_app(e));
4169  }
4170  if (name) {
4171  const char *tmp = ast_get_extension_app_data(e);
4172  if (tmp) {
4173  ast_str_set(name, namesize, "%s", tmp);
4174  }
4175  }
4176  return -1;
4177 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
ast_exten: An extension The dialplan is saved as a linked list with each context having it&#39;s own link...
Definition: pbx.c:237
static int tmp()
Definition: bt_open.c:389
void * ast_get_extension_app_data(struct ast_exten *e)
Definition: pbx.c:8601
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:1065
static struct ast_exten * ast_hint_extension(struct ast_channel *c, const char *context, const char *exten)
Definition: pbx.c:2997
const char * ast_get_extension_app(struct ast_exten *e)
Definition: pbx.c:8596
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

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

References ARRAY_LEN, ast_channel_caller(), ast_channel_context(), ast_channel_dialed(), ast_channel_exten(), ast_channel_hangupcause(), ast_channel_lock, ast_channel_name(), ast_channel_priority(), ast_channel_uniqueid(), ast_channel_unlock, ast_channel_varshead(), ast_config_AST_AGI_DIR, ast_config_AST_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_SPOOL_DIR, ast_config_AST_SYSTEM_NAME, ast_config_AST_VAR_DIR, ast_debug, ast_eid_default, ast_eid_to_str(), AST_LIST_TRAVERSE, ast_party_id_presentation(), ast_rwlock_rdlock, ast_rwlock_unlock, ast_str_buffer(), ast_str_get_hint(), ast_str_set(), ast_str_substring(), ast_strdupa, ast_var_name(), ast_var_value(), ast_var_t::entries, globalslock, NULL, and parse_variable_name().

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

247 {
248  const char not_found = '\0';
249  char *tmpvar;
250  const char *ret;
251  const char *s; /* the result */
252  int offset, length;
253  int i, need_substring;
254  struct varshead *places[2] = { headp, &globals }; /* list of places where we may look */
255  char workspace[20];
256 
257  if (c) {
259  places[0] = ast_channel_varshead(c);
260  }
261  /*
262  * Make a copy of var because parse_variable_name() modifies the string.
263  * Then if called directly, we might need to run substring() on the result;
264  * remember this for later in 'need_substring', 'offset' and 'length'
265  */
266  tmpvar = ast_strdupa(var); /* parse_variable_name modifies the string */
267  need_substring = parse_variable_name(tmpvar, &offset, &length, &i /* ignored */);
268 
269  /*
270  * Look first into predefined variables, then into variable lists.
271  * Variable 's' points to the result, according to the following rules:
272  * s == &not_found (set at the beginning) means that we did not find a
273  * matching variable and need to look into more places.
274  * If s != &not_found, s is a valid result string as follows:
275  * s = NULL if the variable does not have a value;
276  * you typically do this when looking for an unset predefined variable.
277  * s = workspace if the result has been assembled there;
278  * typically done when the result is built e.g. with an snprintf(),
279  * so we don't need to do an additional copy.
280  * s != workspace in case we have a string, that needs to be copied
281  * (the ast_copy_string is done once for all at the end).
282  * Typically done when the result is already available in some string.
283  */
284  s = &not_found; /* default value */
285  if (c) { /* This group requires a valid channel */
286  /* Names with common parts are looked up a piece at a time using strncmp. */
287  if (!strncmp(var, "CALL", 4)) {
288  if (!strncmp(var + 4, "ING", 3)) {
289  if (!strcmp(var + 7, "PRES")) { /* CALLINGPRES */
290  ast_str_set(str, maxlen, "%d",
292  s = ast_str_buffer(*str);
293  } else if (!strcmp(var + 7, "ANI2")) { /* CALLINGANI2 */
294  ast_str_set(str, maxlen, "%d", ast_channel_caller(c)->ani2);
295  s = ast_str_buffer(*str);
296  } else if (!strcmp(var + 7, "TON")) { /* CALLINGTON */
297  ast_str_set(str, maxlen, "%d", ast_channel_caller(c)->id.number.plan);
298  s = ast_str_buffer(*str);
299  } else if (!strcmp(var + 7, "TNS")) { /* CALLINGTNS */
300  ast_str_set(str, maxlen, "%d", ast_channel_dialed(c)->transit_network_select);
301  s = ast_str_buffer(*str);
302  }
303  }
304  } else if (!strcmp(var, "HINT")) {
306  } else if (!strcmp(var, "HINTNAME")) {
308  } else if (!strcmp(var, "EXTEN")) {
309  s = ast_channel_exten(c);
310  } else if (!strcmp(var, "CONTEXT")) {
311  s = ast_channel_context(c);
312  } else if (!strcmp(var, "PRIORITY")) {
313  ast_str_set(str, maxlen, "%d", ast_channel_priority(c));
314  s = ast_str_buffer(*str);
315  } else if (!strcmp(var, "CHANNEL")) {
316  s = ast_channel_name(c);
317  } else if (!strcmp(var, "UNIQUEID")) {
318  s = ast_channel_uniqueid(c);
319  } else if (!strcmp(var, "HANGUPCAUSE")) {
320  ast_str_set(str, maxlen, "%d", ast_channel_hangupcause(c));
321  s = ast_str_buffer(*str);
322  }
323  }
324  if (s == &not_found) { /* look for more */
325  if (!strcmp(var, "EPOCH")) {
326  ast_str_set(str, maxlen, "%d", (int) time(NULL));
327  s = ast_str_buffer(*str);
328  } else if (!strcmp(var, "SYSTEMNAME")) {
330  } else if (!strcmp(var, "ASTCACHEDIR")) {
332  } else if (!strcmp(var, "ASTETCDIR")) {
334  } else if (!strcmp(var, "ASTMODDIR")) {
336  } else if (!strcmp(var, "ASTVARLIBDIR")) {
338  } else if (!strcmp(var, "ASTDBDIR")) {
339  s = ast_config_AST_DB;
340  } else if (!strcmp(var, "ASTKEYDIR")) {
342  } else if (!strcmp(var, "ASTDATADIR")) {
344  } else if (!strcmp(var, "ASTAGIDIR")) {
346  } else if (!strcmp(var, "ASTSPOOLDIR")) {
348  } else if (!strcmp(var, "ASTRUNDIR")) {
350  } else if (!strcmp(var, "ASTLOGDIR")) {
352  } else if (!strcmp(var, "ENTITYID")) {
353  ast_eid_to_str(workspace, sizeof(workspace), &ast_eid_default);
354  s = workspace;
355  }
356  }
357  /* if not found, look into chanvars or global vars */
358  for (i = 0; s == &not_found && i < ARRAY_LEN(places); i++) {
359  struct ast_var_t *variables;
360  if (!places[i])
361  continue;
362  if (places[i] == &globals)
364  AST_LIST_TRAVERSE(places[i], variables, entries) {
365  if (!strcmp(ast_var_name(variables), var)) {
366  s = ast_var_value(variables);
367  break;
368  }
369  }
370  if (places[i] == &globals)
372  }
373  if (s == &not_found || s == NULL) {
374  ast_debug(5, "Result of '%s' is NULL\n", var);
375  ret = NULL;
376  } else {
377  ast_debug(5, "Result of '%s' is '%s'\n", var, s);
378  if (s != ast_str_buffer(*str)) {
379  ast_str_set(str, maxlen, "%s", s);
380  }
381  ret = ast_str_buffer(*str);
382  if (need_substring) {
383  ret = ast_str_substring(*str, offset, length);
384  ast_debug(2, "Final result of '%s' is '%s'\n", var, ret);
385  }
386  }
387 
388  if (c) {
390  }
391  return ret;
392 }
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
const char * ast_config_AST_KEY_DIR
Definition: options.c:161
#define ast_rwlock_rdlock(a)
Definition: lock.h:233
#define ast_channel_lock(chan)
Definition: channel.h:2945
const char * ast_config_AST_CACHE_DIR
Definition: options.c:150
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
const char * ast_config_AST_DB
Definition: options.c:165
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
Definition: main/utils.c:2587
const char * ast_var_value(const struct ast_var_t *var)
Definition: chanvars.c:80
const char * ast_config_AST_MODULE_DIR
Definition: options.c:153
const char * ast_var_name(const struct ast_var_t *var)
Definition: chanvars.c:60
static int parse_variable_name(char *var, int *offset, int *length, int *isfunc)
extract offset:length from variable name.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
int ast_party_id_presentation(const struct ast_party_id *id)
Determine the overall presentation value for the given party.
Definition: channel.c:1821
#define var
Definition: ast_expr2f.c:614
const char * ast_config_AST_RUN_DIR
Definition: options.c:162
static struct test_val c
const char * str
Definition: app_jack.c:147
struct varshead * ast_channel_varshead(struct ast_channel *chan)
#define NULL
Definition: resample.c:96
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:4159
#define ast_rwlock_unlock(a)
Definition: lock.h:232
int ast_channel_priority(const struct ast_channel *chan)
const char * ast_config_AST_SYSTEM_NAME
Definition: options.c:170
Number structure.
Definition: app_followme.c:154
static const char * ast_str_substring(struct ast_str *value, int offset, int length)
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:1065
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
const char * ast_config_AST_AGI_DIR
Definition: options.c:160
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
const char * ast_channel_exten(const struct ast_channel *chan)
const char * ast_channel_uniqueid(const struct ast_channel *chan)
const char * ast_config_AST_DATA_DIR
Definition: options.c:158
const char * ast_config_AST_CONFIG_DIR
Definition: options.c:151
struct ast_party_dialed * ast_channel_dialed(struct ast_channel *chan)
static struct varshead globals
const char * ast_config_AST_LOG_DIR
Definition: options.c:159
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_channel_unlock(chan)
Definition: channel.h:2946
struct ast_var_t::@249 entries
const char * ast_config_AST_SPOOL_DIR
Definition: options.c:154
struct ast_eid ast_eid_default
Global EID.
Definition: options.c:93
int ast_channel_hangupcause(const struct ast_channel *chan)
static ast_rwlock_t globalslock
const char * ast_channel_name(const struct ast_channel *chan)
const char * ast_channel_context(const struct ast_channel *chan)
const char * ast_config_AST_VAR_DIR
Definition: options.c:157

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

References ast_str_substitute_variables_full(), and NULL.

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

617 {
618  ast_str_substitute_variables_full(buf, maxlen, chan, NULL, templ, NULL);
619 }
#define NULL
Definition: resample.c:96
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)

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

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

Referenced by ast_str_substitute_variables(), and ast_str_substitute_variables_varshead().

395 {
396  /* Substitutes variables into buf, based on string templ */
397  const char *whereweare;
398  struct ast_str *substr1 = ast_str_create(16);
399  struct ast_str *substr2 = NULL;
400  struct ast_str *substr3 = ast_str_create(16);
401 
402  ast_str_reset(*buf);
403 
404  if (!substr1 || !substr3) {
405  if (used) {
406  *used = ast_str_strlen(*buf);
407  }
408  ast_free(substr1);
409  ast_free(substr3);
410  return;
411  }
412 
413  whereweare = templ;
414  while (!ast_strlen_zero(whereweare)) {
415  const char *nextvar = NULL;
416  const char *nextexp = NULL;
417  const char *nextthing;
418  const char *vars;
419  const char *vare;
420  char *finalvars;
421  int pos;
422  int brackets;
423  int needsub;
424  int len;
425 
426  /* reset our buffer */
427  ast_str_reset(substr3);
428 
429  /* Determine how much simply needs to be copied to the output buf. */
430  nextthing = strchr(whereweare, '$');
431  if (nextthing) {
432  pos = nextthing - whereweare;
433  switch (nextthing[1]) {
434  case '{':
435  /* Variable substitution */
436  nextvar = nextthing;
437  break;
438  case '[':
439  /* Expression substitution */
440  nextexp = nextthing;
441  break;
442  default:
443  /* '$' is not part of a substitution so include it too. */
444  ++pos;
445  break;
446  }
447  } else {
448  /* We're copying the whole remaining string */
449  pos = strlen(whereweare);
450  }
451 
452  if (pos) {
453  /* Copy that many bytes */
454  ast_str_append_substr(buf, maxlen, whereweare, pos);
455 
456  whereweare += pos;
457  }
458 
459  if (nextvar) {
460  int offset;
461  int offset2;
462  int isfunction;
463  int res;
464 
465  /* We have a variable. Find the start and end, and determine
466  if we are going to have to recursively call ourselves on the
467  contents */
468  vars = vare = nextvar + 2;
469  brackets = 1;
470  needsub = 0;
471 
472  /* Find the end of it */
473  while (brackets && *vare) {
474  if ((vare[0] == '$') && (vare[1] == '{')) {
475  needsub++;
476  brackets++;
477  vare++;
478  } else if (vare[0] == '{') {
479  brackets++;
480  } else if (vare[0] == '}') {
481  brackets--;
482  } else if ((vare[0] == '$') && (vare[1] == '[')) {
483  needsub++;
484  vare++;
485  }
486  vare++;
487  }
488  len = vare - vars;
489  if (brackets) {
490  ast_log(LOG_WARNING, "Error in extension logic (missing '}')\n");
491  } else {
492  /* Don't count the closing '}' in the length. */
493  --len;
494  }
495 
496  /* Skip totally over variable string */
497  whereweare = vare;
498 
499  /* Store variable name expression to lookup. */
500  ast_str_set_substr(&substr1, 0, vars, len);
501  ast_debug(5, "Evaluating '%s' (from '%s' len %d)\n", ast_str_buffer(substr1), vars, len);
502 
503  /* Substitute if necessary */
504  if (needsub) {
505  if (!substr2) {
506  substr2 = ast_str_create(16);
507  if (!substr2) {
508  continue;
509  }
510  }
511  ast_str_substitute_variables_full(&substr2, 0, c, headp, ast_str_buffer(substr1), NULL);
512  finalvars = ast_str_buffer(substr2);
513  } else {
514  finalvars = ast_str_buffer(substr1);
515  }
516 
517  parse_variable_name(finalvars, &offset, &offset2, &isfunction);
518  if (isfunction) {
519  /* Evaluate function */
520  if (c || !headp) {
521  res = ast_func_read2(c, finalvars, &substr3, 0);
522  } else {
523  struct varshead old;
524  struct ast_channel *bogus;
525 
526  bogus = ast_dummy_channel_alloc();
527  if (bogus) {
528  old = *ast_channel_varshead(bogus);
529  *ast_channel_varshead(bogus) = *headp;
530  res = ast_func_read2(bogus, finalvars, &substr3, 0);
531  /* Don't deallocate the varshead that was passed in */
532  *ast_channel_varshead(bogus) = old;
533  ast_channel_unref(bogus);
534  } else {
535  ast_log(LOG_ERROR, "Unable to allocate bogus channel for function value substitution.\n");
536  res = -1;
537  }
538  }
539  ast_debug(2, "Function %s result is '%s'\n",
540  finalvars, res ? "" : ast_str_buffer(substr3));
541  } else {
542  /* Retrieve variable value */
543  ast_str_retrieve_variable(&substr3, 0, c, headp, finalvars);
544  res = 0;
545  }
546  if (!res) {
547  ast_str_substring(substr3, offset, offset2);
548  ast_str_append(buf, maxlen, "%s", ast_str_buffer(substr3));
549  }
550  } else if (nextexp) {
551  /* We have an expression. Find the start and end, and determine
552  if we are going to have to recursively call ourselves on the
553  contents */
554  vars = vare = nextexp + 2;
555  brackets = 1;
556  needsub = 0;
557 
558  /* Find the end of it */
559  while (brackets && *vare) {
560  if ((vare[0] == '$') && (vare[1] == '[')) {
561  needsub++;
562  brackets++;
563  vare++;
564  } else if (vare[0] == '[') {
565  brackets++;
566  } else if (vare[0] == ']') {
567  brackets--;
568  } else if ((vare[0] == '$') && (vare[1] == '{')) {
569  needsub++;
570  vare++;
571  }
572  vare++;
573  }
574  len = vare - vars;
575  if (brackets) {
576  ast_log(LOG_WARNING, "Error in extension logic (missing ']')\n");
577  } else {
578  /* Don't count the closing ']' in the length. */
579  --len;
580  }
581 
582  /* Skip totally over expression */
583  whereweare = vare;
584 
585  /* Store expression to evaluate. */
586  ast_str_set_substr(&substr1, 0, vars, len);
587 
588  /* Substitute if necessary */
589  if (needsub) {
590  if (!substr2) {
591  substr2 = ast_str_create(16);
592  if (!substr2) {
593  continue;
594  }
595  }
596  ast_str_substitute_variables_full(&substr2, 0, c, headp, ast_str_buffer(substr1), NULL);
597  finalvars = ast_str_buffer(substr2);
598  } else {
599  finalvars = ast_str_buffer(substr1);
600  }
601 
602  if (ast_str_expr(&substr3, 0, c, finalvars)) {
603  ast_debug(2, "Expression result is '%s'\n", ast_str_buffer(substr3));
604  }
605  ast_str_append(buf, maxlen, "%s", ast_str_buffer(substr3));
606  }
607  }
608  if (used) {
609  *used = ast_str_strlen(*buf);
610  }
611  ast_free(substr1);
612  ast_free(substr2);
613  ast_free(substr3);
614 }
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
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
static int parse_variable_name(char *var, int *offset, int *length, int *isfunc)
extract offset:length from variable name.
#define LOG_WARNING
Definition: logger.h:274
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
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:1091
struct varshead * ast_channel_varshead(struct ast_channel *chan)
#define NULL
Definition: resample.c:96
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)
#define ast_strlen_zero(foo)
Definition: strings.h:52
static const char * ast_str_substring(struct ast_str *value, int offset, int length)
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define ast_dummy_channel_alloc()
Create a fake channel structure.
Definition: channel.h:1283
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:1014
#define LOG_ERROR
Definition: logger.h:285
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define ast_free(a)
Definition: astmm.h:182
int ast_str_expr(struct ast_str **str, ssize_t maxlen, struct ast_channel *chan, char *expr)
Evaluate the given expression.
Definition: ast_expr2f.c:2447
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:653
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
const char * ast_str_retrieve_variable(struct ast_str **str, ssize_t maxlen, struct ast_channel *c, struct varshead *headp, const char *var)
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:1007
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

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

References ast_str_substitute_variables_full(), and NULL.

Referenced by build_user_routes(), handle_aor(), handle_registrations(), and pp_each_extension_helper().

622 {
623  ast_str_substitute_variables_full(buf, maxlen, NULL, headp, templ, NULL);
624 }
#define NULL
Definition: resample.c:96
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)

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

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

Referenced by ast_add_extension2_lockopt(), and handle_tcptls_connection().

480 {
481  int *thread_inhibit_escalations;
482 
483  thread_inhibit_escalations = ast_threadstorage_get(
484  &thread_inhibit_escalations_tl, sizeof(*thread_inhibit_escalations));
485  if (thread_inhibit_escalations == NULL) {
486  ast_log(LOG_ERROR, "Error inhibiting privilege escalations for current thread\n");
487  return -1;
488  }
489 
490  *thread_inhibit_escalations = 1;
491  return 0;
492 }
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
static struct ast_threadstorage thread_inhibit_escalations_tl
Definition: pbx_functions.c:46

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

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

Referenced by ast_add_extension2_lockopt().

495 {
496  int *thread_inhibit_escalations;
497  int orig;
498 
499  thread_inhibit_escalations = ast_threadstorage_get(
500  &thread_inhibit_escalations_tl, sizeof(*thread_inhibit_escalations));
501  if (thread_inhibit_escalations == NULL) {
502  ast_log(LOG_ERROR, "Error swapping privilege escalations inhibit for current thread\n");
503  return -1;
504  }
505 
506  orig = *thread_inhibit_escalations;
507  *thread_inhibit_escalations = !!inhibit;
508  return orig;
509 }
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
#define NULL
Definition: resample.c:96
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
static struct ast_threadstorage thread_inhibit_escalations_tl
Definition: pbx_functions.c:46

◆ ast_unlock_context()

int ast_unlock_context ( struct ast_context con)

◆ ast_unlock_contexts()

int ast_unlock_contexts ( void  )

Unlocks contexts.

Return values
0on success
-1on failure

Definition at line 8512 of file pbx.c.

References ast_mutex_unlock, and conlock.

Referenced by _macro_exec(), add_hints(), ast_add_extension(), ast_context_add_ignorepat(), ast_context_add_include(), ast_context_add_switch(), ast_context_destroy(), ast_context_destroy_by_name(), ast_context_find(), ast_context_find_or_create(), ast_context_lockmacro(), ast_context_remove_extension_callerid(), ast_context_remove_ignorepat(), ast_context_remove_include(), ast_context_remove_switch(), ast_context_unlockmacro(), ast_hint_extension(), ast_ignore_pattern(), ast_merge_contexts_and_delete(), ast_unregister_application(), complete_dialplan_add_extension(), complete_dialplan_add_ignorepat(), complete_dialplan_add_include(), complete_dialplan_remove_context(), complete_dialplan_remove_extension(), complete_dialplan_remove_ignorepat(), complete_dialplan_remove_include(), complete_show_dialplan_context(), dundi_precache_full(), find_context_locked(), find_matching_endif(), find_matching_endwhile(), get_extension_data(), handle_cli_dialplan_save(), manager_dialplan_extension_add(), manager_show_dialplan_helper(), parking_duration_callback(), parking_lot_cfg_create_extensions(), pbx_extension_helper(), show_debug_helper(), show_dialplan_helper(), and unreference_cached_app().

8513 {
8514  return ast_mutex_unlock(&conlock);
8515 }
static ast_mutex_t conlock
Lock for the ast_context list.
Definition: pbx.c:785
#define ast_mutex_unlock(a)
Definition: lock.h:188

◆ ast_unregister_switch()

void ast_unregister_switch ( struct ast_switch sw)

Unregister an alternative switch.

Parameters
swswitch to unregister

Unregisters a switch from asterisk.

Returns
nothing

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

77 {
79  AST_RWLIST_REMOVE(&switches, sw, list);
81 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:884

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

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

8709 {
8710  if (!con) {
8711  return NULL;
8712  }
8713 
8714  if (ip) {
8715  int idx;
8716  int next = 0;
8717 
8718  for (idx = 0; idx < ast_context_ignorepats_count(con); idx++) {
8719  const struct ast_ignorepat *i = ast_context_ignorepats_get(con, idx);
8720 
8721  if (next) {
8722  return i;
8723  }
8724 
8725  if (ip == i) {
8726  next = 1;
8727  }
8728  }
8729 
8730  return NULL;
8731  }
8732 
8733  if (!ast_context_ignorepats_count(con)) {
8734  return NULL;
8735  }
8736 
8737  return ast_context_ignorepats_get(con, 0);
8738 }
const struct ast_ignorepat * ast_context_ignorepats_get(const struct ast_context *con, int idx)
Definition: pbx.c:8745
#define NULL
Definition: resample.c:96
int ast_context_ignorepats_count(const struct ast_context *con)
Definition: pbx.c:8740
ast_ignorepat: Ignore patterns in dial plan
Definition: pbx_ignorepat.c:37

◆ ast_walk_context_includes()

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

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

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

8625 {
8626  if (sw) {
8627  int idx;
8628  int next = 0;
8629 
8630  for (idx = 0; idx < ast_context_switches_count(con); idx++) {
8631  const struct ast_sw *s = ast_context_switches_get(con, idx);
8632 
8633  if (next) {
8634  return s;
8635  }
8636 
8637  if (sw == s) {
8638  next = 1;
8639  }
8640  }
8641 
8642  return NULL;
8643  }
8644 
8645  if (!ast_context_switches_count(con)) {
8646  return NULL;
8647  }
8648 
8649  return ast_context_switches_get(con, 0);
8650 }
int ast_context_switches_count(const struct ast_context *con)
Definition: pbx.c:8652
const struct ast_sw * ast_context_switches_get(const struct ast_context *con, int idx)
Definition: pbx.c:8657
struct ast_ignorepat * next
Definition: conf2ael.c:169
#define NULL
Definition: resample.c:96
ast_sw: Switch statement in extensions.conf
Definition: pbx_sw.c:37

◆ ast_walk_contexts()

static struct ast_context * ast_walk_contexts ( struct ast_context con)

◆ ast_walk_extension_priorities()

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

Definition at line 4063 of file extconf.c.

References ast_exten::exten, and ast_exten::peer.

Referenced by complete_dialplan_remove_extension(), find_matching_priority(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), show_dialplan_helper(), and unreference_cached_app().

4065 {
4066  return priority ? priority->peer : exten;
4067 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
struct ast_exten * peer
Definition: pbx.c:250

◆ ast_wrlock_context()

int ast_wrlock_context ( struct ast_context con)

Write locks a given context.

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

Definition at line 8520 of file pbx.c.

References ast_rwlock_wrlock, and ast_context::lock.

Referenced by __ast_context_destroy(), add_hints(), ast_add_extension2_lockopt(), ast_context_add_ignorepat2(), ast_context_add_include2(), ast_context_add_switch2(), ast_context_remove_extension_callerid2(), ast_context_remove_ignorepat2(), ast_context_remove_include2(), ast_context_remove_switch2(), parking_duration_callback(), and parking_lot_cfg_create_extensions().

8521 {
8522  return ast_rwlock_wrlock(&con->lock);
8523 }
ast_rwlock_t lock
Definition: pbx.c:285
#define ast_rwlock_wrlock(a)
Definition: lock.h:234

◆ ast_wrlock_contexts()

int ast_wrlock_contexts ( void  )

Write locks the context list.

Return values
0on success
-1on error

Definition at line 8502 of file pbx.c.

References ast_mutex_lock, and conlock.

Referenced by add_hints(), ast_context_destroy(), ast_context_destroy_by_name(), ast_context_find_or_create(), ast_merge_contexts_and_delete(), complete_dialplan_remove_include(), manager_dialplan_extension_add(), parking_duration_callback(), and parking_lot_cfg_create_extensions().

8503 {
8504  return ast_mutex_lock(&conlock);
8505 }
#define ast_mutex_lock(a)
Definition: lock.h:187
static ast_mutex_t conlock
Lock for the ast_context list.
Definition: pbx.c:785

◆ pbx_builtin_clear_globals()

void pbx_builtin_clear_globals ( void  )

Definition at line 1191 of file pbx_variables.c.

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

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

1192 {
1193  struct ast_var_t *vardata;
1194 
1196  while ((vardata = AST_LIST_REMOVE_HEAD(&globals, entries)))
1197  ast_var_delete(vardata);
1199 }
#define ast_rwlock_unlock(a)
Definition: lock.h:232
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
void ast_var_delete(struct ast_var_t *var)
Definition: extconf.c:2473
static struct varshead globals
struct ast_var_t::@249 entries
#define ast_rwlock_wrlock(a)
Definition: lock.h:234
static ast_rwlock_t globalslock

◆ 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"))) {
var = ast_strdupa(var);
}

Definition at line 1000 of file pbx_variables.c.

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

Referenced by __ast_pbx_run(), _if_exec(), _macro_exec(), _while_exec(), action_agents(), add_header_from_channel_var(), agent_handle_show_specific(), agent_login_channel_config(), agent_request_exec(), agent_show_requested(), aMYSQL_connect(), analog_call(), array(), ast_bridge_timelimit(), ast_bridge_transfer_attended(), ast_call_forward(), ast_channel_connected_line_macro(), ast_channel_connected_line_sub(), ast_channel_redirecting_macro(), ast_channel_redirecting_sub(), ast_eivr_getvariable(), ast_get_chan_applicationmap(), ast_monitor_stop(), ast_unreal_hangup(), attended_transfer_exec(), bridge_check_monitor(), 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(), dundi_helper(), eagi_exec(), feature_automixmonitor(), feature_automonitor(), feature_blind_transfer(), find_by_mark(), find_channel_parking_lot_name(), find_conf_realtime(), func_channel_read(), generate_parked_user(), generic_fax_exec(), get_also_info(), get_index(), get_refer_info(), get_transfer_context(), global_read(), gosub_run(), handle_call_forward(), handle_clear_alarms(), handle_gosub(), handle_hangup(), hash_read(), iax2_call(), iax2_exec(), import_ch(), leave_voicemail(), local_read(), macro_fixup(), manager_mixmonitor(), meetme_menu_admin_extended(), mgcp_call(), minivm_delete_exec(), minivm_notify_exec(), misdn_answer(), misdn_hangup(), morsecode_exec(), notify_new_message(), ooh323_call(), ooh323_hangup(), park_app_exec(), pbx_builtin_background(), pbx_builtin_gotoiftime(), pbx_builtin_saycharacters(), pbx_builtin_saycharacters_case(), pbx_builtin_saydigits(), pbx_builtin_saymoney(), pbx_builtin_saynumber(), pbx_builtin_sayphonetic(), pre_bridge_setup(), queue_exec(), receive_ademco_event(), report_receive_fax_status(), report_send_fax_status(), retrydial_exec(), ring_entry(), run_agi(), sayunixtime_exec(), sendtext_exec(), set_from_header(), set_local_info(), set_touch_variable(), set_transfer_variables_all(), setsubstate(), setup_mixmonitor(), setup_park_common_datastore(), sip_addheader(), sla_trunk_exec(), speech_background(), transfer_refer(), try_calling(), try_suggested_sip_codec(), and wait_for_answer().

1001 {
1002  struct ast_var_t *variables;
1003  const char *ret = NULL;
1004  int i;
1005  struct varshead *places[2] = { NULL, &globals };
1006 
1007  if (!name)
1008  return NULL;
1009 
1010  if (chan) {
1011  ast_channel_lock(chan);
1012  places[0] = ast_channel_varshead(chan);
1013  }
1014 
1015  for (i = 0; i < 2; i++) {
1016  if (!places[i])
1017  continue;
1018  if (places[i] == &globals)
1020  AST_LIST_TRAVERSE(places[i], variables, entries) {
1021  if (!strcmp(name, ast_var_name(variables))) {
1022  ret = ast_var_value(variables);
1023  break;
1024  }
1025  }
1026  if (places[i] == &globals)
1028  if (ret)
1029  break;
1030  }
1031 
1032  if (chan)
1033  ast_channel_unlock(chan);
1034 
1035  return ret;
1036 }
#define ast_rwlock_rdlock(a)
Definition: lock.h:233
#define ast_channel_lock(chan)
Definition: channel.h:2945
const char * ast_var_value(const struct ast_var_t *var)
Definition: chanvars.c:80
const char * ast_var_name(const struct ast_var_t *var)
Definition: chanvars.c:60
struct varshead * ast_channel_varshead(struct ast_channel *chan)
#define NULL
Definition: resample.c:96
#define ast_rwlock_unlock(a)
Definition: lock.h:232
static struct varshead globals
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static const char name[]
Definition: cdr_mysql.c:74
static ast_rwlock_t globalslock

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

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

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

1039 {
1040  struct ast_var_t *newvariable;
1041  struct varshead *headp;
1042 
1043  if (name[strlen(name)-1] == ')') {
1044  char *function = ast_strdupa(name);
1045 
1046  ast_log(LOG_WARNING, "Cannot push a value onto a function\n");
1047  ast_func_write(chan, function, value);
1048  return;
1049  }
1050 
1051  if (chan) {
1052  ast_channel_lock(chan);
1053  headp = ast_channel_varshead(chan);
1054  } else {
1056  headp = &globals;
1057  }
1058 
1059  if (value && (newvariable = ast_var_assign(name, value))) {
1060  if (headp == &globals)
1061  ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
1062  AST_LIST_INSERT_HEAD(headp, newvariable, entries);
1063  }
1064 
1065  if (chan)
1066  ast_channel_unlock(chan);
1067  else
1069 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
#define LOG_WARNING
Definition: logger.h:274
struct varshead * ast_channel_varshead(struct ast_channel *chan)
int value
Definition: syslog.c:37
#define ast_rwlock_unlock(a)
Definition: lock.h:232
#define ast_verb(level,...)
Definition: logger.h:463
#define ast_log
Definition: astobj2.c:42
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static struct varshead globals
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:710
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static const char name[]
Definition: cdr_mysql.c:74
#define ast_var_assign(name, value)
Definition: chanvars.h:40
#define ast_rwlock_wrlock(a)
Definition: lock.h:234
static ast_rwlock_t globalslock
int ast_func_write(struct ast_channel *chan, const char *function, const char *value)
executes a write operation on a function

◆ pbx_builtin_raise_exception()

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

Definition at line 703 of file pbx_builtins.c.

References raise_exception().

704 {
705  /* Priority will become 1, next time through the AUTOLOOP */
706  return raise_exception(chan, reason, 0);
707 }
int raise_exception(struct ast_channel *chan, const char *reason, int priority)
Definition: pbx.c:2806

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

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

Referenced by ast_var_channels_table(), and dumpchan_exec().

970 {
971  struct ast_var_t *variables;
972  const char *var, *val;
973  int total = 0;
974 
975  if (!chan)
976  return 0;
977 
978  ast_str_reset(*buf);
979 
980  ast_channel_lock(chan);
981 
982  AST_LIST_TRAVERSE(ast_channel_varshead(chan), variables, entries) {
983  if ((var = ast_var_name(variables)) && (val = ast_var_value(variables))
984  /* && !ast_strlen_zero(var) && !ast_strlen_zero(val) */
985  ) {
986  if (ast_str_append(buf, 0, "%s=%s\n", var, val) < 0) {
987  ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n");
988  break;
989  } else
990  total++;
991  } else
992  break;
993  }
994 
995  ast_channel_unlock(chan);
996 
997  return total;
998 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
Definition: ast_expr2.c:325
const char * ast_var_value(const struct ast_var_t *var)
Definition: chanvars.c:80
const char * ast_var_name(const struct ast_var_t *var)
Definition: chanvars.c:60
#define var
Definition: ast_expr2f.c:614
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:1091
struct varshead * ast_channel_varshead(struct ast_channel *chan)
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_channel_unlock(chan)
Definition: channel.h:2946
struct ast_var_t::@249 entries
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:653
static int total
Definition: res_adsi.c:968

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

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

Referenced by ast_compile_ael2(), and load_pbx_variables().

1130 {
1131  char *name, *value, *mydata;
1132 
1133  if (ast_strlen_zero(data)) {
1134  ast_log(LOG_WARNING, "Set requires one variable name/value pair.\n");
1135  return 0;
1136  }
1137 
1138  mydata = ast_strdupa(data);
1139  name = strsep(&mydata, "=");
1140  value = mydata;
1141  if (!value) {
1142  ast_log(LOG_WARNING, "Set requires an '=' to be a valid assignment.\n");
1143  return 0;
1144  }
1145 
1146  if (strchr(name, ' ')) {
1147  ast_log(LOG_WARNING, "Please avoid unnecessary spaces on variables as it may lead to unexpected results ('%s' set to '%s').\n", name, mydata);
1148  }
1149 
1150  pbx_builtin_setvar_helper(chan, name, value);
1151 
1152  return 0;
1153 }
#define LOG_WARNING
Definition: logger.h:274
int value
Definition: syslog.c:37
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
static const char name[]
Definition: cdr_mysql.c:74
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...
char * strsep(char **str, const char *delims)

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

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

Referenced by __analog_ss_thread(), __ast_pbx_run(), _if_exec(), _macro_exec(), _while_exec(), acf_curl_helper(), acf_fetch(), acf_odbc_read(), acf_odbc_write(), acf_transaction_write(), action_atxfer(), action_kick_last(), action_setvar(), admin_exec(), agent_login_exec(), agent_request_exec(), agi_exec_full(), aMYSQL_fetch(), aMYSQL_set(), analog_ss_thread(), app_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_monitor_start(), ast_monitor_stop(), ast_pbx_outgoing_exten_predial(), ast_pickup_call(), ast_rtp_instance_set_stats_vars(), ast_set_cc_interfaces_chanvar(), ast_set_variables(), AST_TEST_DEFINE(), ast_unreal_hangup(), asyncgoto_exec(), attended_transfer_bridge(), attended_transfer_exec(), audiosocket_request(), background_detect_exec(), begin_dial_channel(), blind_transfer_bridge(), blind_transfer_cb(), blind_transfer_exec(), bridge_channel_internal_push_full(), bridge_exec(), bridgeadd_exec(), calendar_write_exec(), caller_joined_bridge(), caller_safety_timeout(), cb_events(), cccancel_exec(), ccreq_exec(), chan_pjsip_cng_tone_detected(), chan_pjsip_new(), chanavail_exec(), channel_spy(), check_bridge_play_sound(), clear_agent_status(), commit_exec(), conf_run(), confbridge_exec(), confkick_exec(), controlplayback_exec(), count_exec(), crement_function_read(), dahdi_handle_dtmf(), dahdi_new(), dial_exec_full(), dial_transfer(), directory_exec(), disa_exec(), do_directory(), do_forward(), do_notify(), do_waiting(), dtmf_store_framehook(), dynamic_dtmf_hook_callback(), end_bridge_callback(), execute_menu_entry(), export_aoc_vars(), export_ch(), extract_transferrer_headers(), fax_detect_framehook(), frame_set_var(), func_mchan_write(), function_db_delete(), function_db_exists(), function_db_read(), function_realtime_store(), generic_recall(), get_chan_by_ast_name(), get_rdnis(), get_refer_info(), global_write(), gosub_release_frame(), gosub_run(), handle_controlstreamfile(), handle_gosub(), handle_incoming_request(), handle_outgoing_response(), handle_request_bye(), handle_response_cmgr(), handle_set_chanvar(), handle_set_global(), handle_setvariable(), handle_streamfile(), hash_read(), hash_write(), isAnsweringMachine(), kick_conference_participant(), launch_monitor_thread(), leave_marked(), leave_queue(), leave_voicemail(), lua_set_variable(), lua_set_variable_value(), macro_fixup(), mbl_status_exec(), mgcp_new(), minivm_accmess_exec(), minivm_delete_exec(), minivm_greet_exec(), minivm_notify_exec(), minivm_record_exec(), misdn_call(), mixmonitor_exec(), msg_send_exec(), my_handle_dtmf(), MYSQL_exec(), onModeChanged(), ooh323_new(), ooh323_rtp_read(), originate_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), parking_duration_callback(), parking_timeout_set_caller_features(), parse_moved_contact(), pbx_builtin_background(), pbx_builtin_gotoiftime(), pbx_builtin_importvar(), pbx_builtin_setvar(), pbx_builtin_setvar_multiple(), pbx_builtin_waitdigit(), pbx_load_config(), phase_e_handler(), play_message_datetime(), playback_exec(), pqm_exec(), prep_email_sub_vars(), privacy_exec(), process_ast_dsp(), process_sdp(), 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(), refer_blind_callback(), reload(), reload_module(), return_exec(), rollback_exec(), rotate_file(), rqm_exec(), select_entry(), select_item_menu(), select_item_seq(), sendfax_exec(), sendimage_exec(), sendtext_exec(), sendurl_exec(), set(), set_asterisk_int(), set_channel_variables(), set_duration_var(), set_queue_result(), set_sipdomain_variable(), setsubstate(), shift_pop(), sip_addheader(), sip_hangup(), sip_new(), sip_read(), skinny_new(), sla_calc_trunk_timeouts(), sla_station_exec(), sla_trunk_exec(), speech_create(), start_automixmonitor(), start_automonitor(), start_monitor_exec(), system_exec_helper(), test_chan_variable(), testtime_write(), transfer_exec(), transmit(), tryexec_exec(), unicast_rtp_request(), unshift_push(), update_qe_rule(), upqm_exec(), user_timeout(), vm_allocate_dh(), vm_exec(), vm_playmsgexec(), vmauthenticate(), wait_exec(), wait_for_answer(), waituntil_exec(), and zapateller_exec().

1072 {
1073  struct ast_var_t *newvariable;
1074  struct varshead *headp;
1075  const char *nametail = name;
1076  /*! True if the old value was not an empty string. */
1077  int old_value_existed = 0;
1078 
1079  if (name[strlen(name) - 1] == ')') {
1080  char *function = ast_strdupa(name);
1081 
1082  return ast_func_write(chan, function, value);
1083  }
1084 
1085  if (chan) {
1086  ast_channel_lock(chan);
1087  headp = ast_channel_varshead(chan);
1088  } else {
1090  headp = &globals;
1091  }
1092 
1093  /* For comparison purposes, we have to strip leading underscores */
1094  if (*nametail == '_') {
1095  nametail++;
1096  if (*nametail == '_')
1097  nametail++;
1098  }
1099 
1100  AST_LIST_TRAVERSE_SAFE_BEGIN(headp, newvariable, entries) {
1101  if (strcmp(ast_var_name(newvariable), nametail) == 0) {
1102  /* there is already such a variable, delete it */
1103  AST_LIST_REMOVE_CURRENT(entries);
1104  old_value_existed = !ast_strlen_zero(ast_var_value(newvariable));
1105  ast_var_delete(newvariable);
1106  break;
1107  }
1108  }
1110 
1111  if (value && (newvariable = ast_var_assign(name, value))) {
1112  if (headp == &globals) {
1113  ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
1114  }
1115  AST_LIST_INSERT_HEAD(headp, newvariable, entries);
1117  } else if (old_value_existed) {
1118  /* We just deleted a non-empty dialplan variable. */
1119  ast_channel_publish_varset(chan, name, "");
1120  }
1121 
1122  if (chan)
1123  ast_channel_unlock(chan);
1124  else
1126  return 0;
1127 }
#define ast_channel_lock(chan)
Definition: channel.h:2945
const char * ast_var_value(const struct ast_var_t *var)
Definition: chanvars.c:80
const char * ast_var_name(const struct ast_var_t *var)
Definition: chanvars.c:60
struct varshead * ast_channel_varshead(struct ast_channel *chan)
int value
Definition: syslog.c:37
#define ast_rwlock_unlock(a)
Definition: lock.h:232
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
#define ast_verb(level,...)
Definition: logger.h:463
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
void ast_channel_publish_varset(struct ast_channel *chan, const char *variable, const char *value)
Publish a ast_channel_varset for a channel.
void ast_var_delete(struct ast_var_t *var)
Definition: extconf.c:2473
static struct varshead globals
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:710
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static const char name[]
Definition: cdr_mysql.c:74
#define ast_var_assign(name, value)
Definition: chanvars.h:40
#define ast_rwlock_wrlock(a)
Definition: lock.h:234
static ast_rwlock_t globalslock
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
int ast_func_write(struct ast_channel *chan, const char *function, const char *value)
executes a write operation on a function

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

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

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

1156 {
1157  char *data;
1158  int x;
1160  AST_APP_ARG(pair)[24];
1161  );
1163  AST_APP_ARG(name);
1164  AST_APP_ARG(value);
1165  );
1166 
1167  if (ast_strlen_zero(vdata)) {
1168  ast_log(LOG_WARNING, "MSet requires at least one variable name/value pair.\n");
1169  return 0;
1170  }
1171 
1172  data = ast_strdupa(vdata);
1173  AST_STANDARD_APP_ARGS(args, data);
1174 
1175  for (x = 0; x < args.argc; x++) {
1176  AST_NONSTANDARD_APP_ARGS(pair, args.pair[x], '=');
1177  if (pair.argc == 2) {
1178  pbx_builtin_setvar_helper(chan, pair.name, pair.value);
1179  if (strchr(pair.name, ' '))
1180  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);
1181  } else if (!chan) {
1182  ast_log(LOG_WARNING, "MSet: ignoring entry '%s' with no '='\n", pair.name);
1183  } else {
1184  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));
1185  }
1186  }
1187 
1188  return 0;
1189 }
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define LOG_WARNING
Definition: logger.h:274
const char * args
int value
Definition: syslog.c:37
int ast_channel_priority(const struct ast_channel *chan)
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
const char * ast_channel_exten(const struct ast_channel *chan)
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)
Performs the &#39;nonstandard&#39; argument separation process for an application.
static const char name[]
Definition: cdr_mysql.c:74
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...
const char * name
Definition: test_config.c:85
const char * ast_channel_context(const struct ast_channel *chan)
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

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

References ast_strlen_zero.

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

8322 {
8323  int res;
8324  if (ast_strlen_zero(condition)) { /* NULL or empty strings are false */
8325  return 0;
8326  } else if (sscanf(condition, "%30d", &res) == 1) { /* Numbers are evaluated for truth */
8327  return res;
8328  } else { /* Strings are true */
8329  return 1;
8330  }
8331 }
#define ast_strlen_zero(foo)
Definition: strings.h:52

◆ 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
Parameters
cChannel
appApplication
dataData for execution
Examples:
/usr/src/asterisk-18.5.0/main/app.c.

Definition at line 471 of file pbx_app.c.

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

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

474 {
475  int res;
476  struct ast_module_user *u = NULL;
477  const char *saved_c_appl;
478  const char *saved_c_data;
479 
480  /* save channel values */
481  saved_c_appl= ast_channel_appl(c);
482  saved_c_data= ast_channel_data(c);
483 
484  ast_channel_lock(c);
485  ast_channel_appl_set(c, app->name);
486  ast_channel_data_set(c, data);
489 
490  if (app->module)
491  u = __ast_module_user_add(app->module, c);
492  res = app->execute(c, S_OR(data, ""));
493  if (app->module && u)
494  __ast_module_user_remove(app->module, u);
495  /* restore channel values */
496  ast_channel_appl_set(c, saved_c_appl);
497  ast_channel_data_set(c, saved_c_data);
498  return res;
499 }
int(* execute)(struct ast_channel *chan, const char *data)
Definition: pbx_app.c:46
#define ast_channel_lock(chan)
Definition: channel.h:2945
void ast_channel_appl_set(struct ast_channel *chan, const char *value)
void __ast_module_user_remove(struct ast_module *, struct ast_module_user *)
Definition: loader.c:826
#define NULL
Definition: resample.c:96
struct ast_module_user * __ast_module_user_add(struct ast_module *, struct ast_channel *)
Definition: loader.c:800
const char * ast_channel_appl(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2946
const char * ast_channel_data(const struct ast_channel *chan)
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
void ast_channel_publish_snapshot(struct ast_channel *chan)
Publish a ast_channel_snapshot for a channel.
void ast_channel_data_set(struct ast_channel *chan, const char *value)

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

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_compare_contexts(), 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, context, create_match_char_tree(), pbx_find_info::data, E_CANMATCH, E_FINDLABEL, E_MATCHMORE, ast_switch::exists, ast_exten::exten, scoreboard::exten, 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(), ast_exten::matchcid, ast_switch::matchmore, ast_exten::name, ast_context::name, new_find_extension(), scoreboard::node, NULL, ast_context::pattern_tree, pbx_findswitch(), pbx_substitute_variables_helper(), 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(), switch_data, pbx_find_info::swo, tmp(), scoreboard::total_length, scoreboard::total_specificity, and trie_find_next_match().

Referenced by add_extension(), ast_hint_extension_nolock(), ast_log(), ast_merge_contexts_and_delete(), ast_sip_persistent_endpoint_update_state(), ast_walk_context_includes(), check_goto(), check_pval_item(), check_retrieve_call_extensions(), conf_ended(), delete_extens(), get_extension_data(), parking_blind_transfer_park(), parking_duration_callback(), parking_is_exten_park(), parking_lot_cfg_create_extensions(), pbx_extension_helper(), register_peer_exten(), and test_exten().

161 {
162  return localized_find_extension(bypass, q, context, exten, priority, label, callerid, action);
163 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:118
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:4470
static int priority
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116

◆ 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
Examples:
/usr/src/asterisk-18.5.0/main/app.c.

Definition at line 165 of file ael_main.c.

References ast_custom_function_find(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, namelist::name, and pbx_findapp_nolock().

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

166 {
167  return (struct ast_app*)1; /* so as not to trigger an error */
168 }
ast_app: A registered application
Definition: pbx_app.c:45

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

References ast_log, live_dangerously, LOG_NOTICE, and LOG_WARNING.

Referenced by load_asterisk_conf().

467 {
468  if (new_live_dangerously && !live_dangerously) {
469  ast_log(LOG_WARNING, "Privilege escalation protection disabled!\n"
470  "See https://wiki.asterisk.org/wiki/x/1gKfAQ for more details.\n");
471  }
472 
473  if (!new_live_dangerously && live_dangerously) {
474  ast_log(LOG_NOTICE, "Privilege escalation protection enabled.\n");
475  }
476  live_dangerously = new_live_dangerously;
477 }
static int live_dangerously
Set to true (non-zero) to globally allow all dangerous dialplan functions to run. ...
Definition: pbx_functions.c:46
#define LOG_WARNING
Definition: logger.h:274
#define ast_log
Definition: astobj2.c:42
#define LOG_NOTICE
Definition: logger.h:263

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

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

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

236 {
237  struct ast_str *str = ast_str_create(16);
238  const char *cret;
239 
240  cret = ast_str_retrieve_variable(&str, 0, c, headp, var);
241  ast_copy_string(workspace, ast_str_buffer(str), workspacelen);
242  *ret = cret ? workspace : NULL;
243  ast_free(str);
244 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define var
Definition: ast_expr2f.c:614
const char * str
Definition: app_jack.c:147
#define NULL
Definition: resample.c:96
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
#define ast_free(a)
Definition: astmm.h:182
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
const char * ast_str_retrieve_variable(struct ast_str **str, ssize_t maxlen, struct ast_channel *c, struct varshead *headp, const char *var)
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

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

References autofallthrough.

Referenced by pbx_load_module().

4775 {
4776  int oldval = autofallthrough;
4777  autofallthrough = newval;
4778  return oldval;
4779 }
static int autofallthrough
Definition: pbx.c:763

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

References extenpatternmatchnew.

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

4782 {
4783  int oldval = extenpatternmatchnew;
4784  extenpatternmatchnew = newval;
4785  return oldval;
4786 }
static int extenpatternmatchnew
Definition: pbx.c:764

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

References ast_free, ast_strdup, ast_strlen_zero, and NULL.

Referenced by pbx_load_module().

4789 {
4790  if (overrideswitch) {
4792  }
4793  if (!ast_strlen_zero(newval)) {
4794  overrideswitch = ast_strdup(newval);
4795  } else {
4796  overrideswitch = NULL;
4797  }
4798 }
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_free(a)
Definition: astmm.h:182
static char * overrideswitch
Definition: pbx.c:765

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

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, len(), LOG_ERROR, LOG_WARNING, NULL, parse_variable_name(), pbx_retrieve_variable(), substring(), var, and VAR_BUF_SIZE.

Referenced by pbx_substitute_variables_helper(), and pbx_substitute_variables_varshead().

627 {
628  /* Substitutes variables into cp2, based on string cp1, cp2 NO LONGER NEEDS TO BE ZEROED OUT!!!! */
629  const char *whereweare;
630  const char *orig_cp2 = cp2;
631  char ltmp[VAR_BUF_SIZE];
632  char var[VAR_BUF_SIZE];
633 
634  *cp2 = 0; /* just in case nothing ends up there */
635  whereweare = cp1;
636  while (!ast_strlen_zero(whereweare) && count) {
637  char *nextvar = NULL;
638  char *nextexp = NULL;
639  char *nextthing;
640  char *vars;
641  char *vare;
642  int length;
643  int pos;
644  int brackets;
645  int needsub;
646  int len;
647 
648  /* Determine how much simply needs to be copied to the output buf. */
649  nextthing = strchr(whereweare, '$');
650  if (nextthing) {
651  pos = nextthing - whereweare;
652  switch (nextthing[1]) {
653  case '{':
654  /* Variable substitution */
655  nextvar = nextthing;
656  break;
657  case '[':
658  /* Expression substitution */
659  nextexp = nextthing;
660  break;
661  default:
662  /* '$' is not part of a substitution so include it too. */
663  ++pos;
664  break;
665  }
666  } else {
667  /* We're copying the whole remaining string */
668  pos = strlen(whereweare);
669  }
670 
671  if (pos) {
672  /* Can't copy more than 'count' bytes */
673  if (pos > count)
674  pos = count;
675 
676  /* Copy that many bytes */
677  memcpy(cp2, whereweare, pos);
678 
679  count -= pos;
680  cp2 += pos;
681  whereweare += pos;
682  *cp2 = 0;
683  }
684 
685  if (nextvar) {
686  int offset;
687  int offset2;
688  int isfunction;
689  char *cp4;
690  char workspace[VAR_BUF_SIZE] = "";
691 
692  /* We have a variable. Find the start and end, and determine
693  if we are going to have to recursively call ourselves on the
694  contents */
695  vars = vare = nextvar + 2;
696  brackets = 1;
697  needsub = 0;
698 
699  /* Find the end of it */
700  while (brackets && *vare) {
701  if ((vare[0] == '$') && (vare[1] == '{')) {
702  needsub++;
703  brackets++;
704  vare++;
705  } else if (vare[0] == '{') {
706  brackets++;
707  } else if (vare[0] == '}') {
708  brackets--;
709  } else if ((vare[0] == '$') && (vare[1] == '[')) {
710  needsub++;
711  vare++;
712  }
713  vare++;
714  }
715  len = vare - vars;
716  if (brackets) {
717  ast_log(LOG_WARNING, "Error in extension logic (missing '}')\n");
718  } else {
719  /* Don't count the closing '}' in the length. */
720  --len;
721  }
722 
723  /* Skip totally over variable string */
724  whereweare = vare;
725 
726  /* Store variable name expression to lookup (and truncate). */
727  ast_copy_string(var, vars, len + 1);
728 
729  /* Substitute if necessary */
730  if (needsub) {
731  pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, NULL);
732  vars = ltmp;
733  } else {
734  vars = var;
735  }
736 
737  parse_variable_name(vars, &offset, &offset2, &isfunction);
738  if (isfunction) {
739  /* Evaluate function */
740  if (c || !headp)
741  cp4 = ast_func_read(c, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace;
742  else {
743  struct varshead old;
744  struct ast_channel *bogus;
745 
746  bogus = ast_dummy_channel_alloc();
747  if (bogus) {
748  old = *ast_channel_varshead(bogus);
749  *ast_channel_varshead(bogus) = *headp;
750  cp4 = ast_func_read(bogus, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace;
751  /* Don't deallocate the varshead that was passed in */
752  *ast_channel_varshead(bogus) = old;
753  ast_channel_unref(bogus);
754  } else {
755  ast_log(LOG_ERROR, "Unable to allocate bogus channel for function value substitution.\n");
756  cp4 = NULL;
757  }
758  }
759  ast_debug(2, "Function %s result is '%s'\n", vars, cp4 ? cp4 : "(null)");
760  } else {
761  /* Retrieve variable value */
762  pbx_retrieve_variable(c, vars, &cp4, workspace, VAR_BUF_SIZE, headp);
763  }
764  if (cp4) {
765  cp4 = substring(cp4, offset, offset2, workspace, VAR_BUF_SIZE);
766 
767  length = strlen(cp4);
768  if (length > count)
769  length = count;
770  memcpy(cp2, cp4, length);
771  count -= length;
772  cp2 += length;
773  *cp2 = 0;
774  }
775  } else if (nextexp) {
776  /* We have an expression. Find the start and end, and determine
777  if we are going to have to recursively call ourselves on the
778  contents */
779  vars = vare = nextexp + 2;
780  brackets = 1;
781  needsub = 0;
782 
783  /* Find the end of it */
784  while (brackets && *vare) {
785  if ((vare[0] == '$') && (vare[1] == '[')) {
786  needsub++;
787  brackets++;
788  vare++;
789  } else if (vare[0] == '[') {
790  brackets++;
791  } else if (vare[0] == ']') {
792  brackets--;
793  } else if ((vare[0] == '$') && (vare[1] == '{')) {
794  needsub++;
795  vare++;
796  }
797  vare++;
798  }
799  len = vare - vars;
800  if (brackets) {
801  ast_log(LOG_WARNING, "Error in extension logic (missing ']')\n");
802  } else {
803  /* Don't count the closing ']' in the length. */
804  --len;
805  }
806 
807  /* Skip totally over expression */
808  whereweare = vare;
809 
810  /* Store expression to evaluate (and truncate). */
811  ast_copy_string(var, vars, len + 1);
812 
813  /* Substitute if necessary */
814  if (needsub) {
815  pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, NULL);
816  vars = ltmp;
817  } else {
818  vars = var;
819  }
820 
821  length = ast_expr(vars, cp2, count, c);
822  if (length) {
823  ast_debug(1, "Expression result is '%s'\n", cp2);
824  count -= length;
825  cp2 += length;
826  *cp2 = 0;
827  }
828  }
829  }
830  if (used) {
831  *used = cp2 - orig_cp2;
832  }
833 }
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.
int ast_func_read(struct ast_channel *chan, const char *function, char *workspace, size_t len)
executes a read operation on a function
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
static int parse_variable_name(char *var, int *offset, int *length, int *isfunc)
extract offset:length from variable name.
#define LOG_WARNING
Definition: logger.h:274
#define var
Definition: ast_expr2f.c:614
void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int count, size_t *used)
struct varshead * ast_channel_varshead(struct ast_channel *chan)
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define ast_dummy_channel_alloc()
Create a fake channel structure.
Definition: channel.h:1283
#define LOG_ERROR
Definition: logger.h:285
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
#define VAR_BUF_SIZE
Definition: pbx_private.h:68
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
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.
int ast_expr(char *expr, char *buf, int length, struct ast_channel *chan)
Evaluate the given expression.
Definition: ast_expr2f.c:2405

◆ pbx_substitute_variables_varshead()

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

Definition at line 840 of file pbx_variables.c.

References NULL, and pbx_substitute_variables_helper_full().

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

841 {
842  pbx_substitute_variables_helper_full(NULL, headp, cp1, cp2, count, NULL);
843 }
void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int count, size_t *used)
#define NULL
Definition: resample.c:96