Asterisk - The Open Source Telephony Project  GIT-master-a24979a
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_ERROR   1
 
#define AST_PBX_HANGUP   -1
 Special return values from applications to the PBX. More...
 
#define AST_PBX_INCOMPLETE   12
 
#define AST_PBX_OK   0
 

Typedefs

typedef void(* ast_state_cb_destroy_type) (int id, void *data)
 Typedef for devicestate and hint callback removal indication callback. 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_in)
 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 *value, 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)
 Remove an ignorepat. More...
 
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...
 
int pbx_parse_location (struct ast_channel *chan, char **context, char **exten, char **pri, int *ipri, int *mode, char *rest)
 Parses a dialplan location into context, extension, priority. 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)
 
struct ast_contextast_get_extension_context (struct ast_exten *exten)
 
const char * ast_get_extension_name (struct ast_exten *exten)
 
const char * ast_get_ignorepat_name (const struct ast_ignorepat *ip)
 
const char * ast_get_include_name (const struct ast_include *include)
 
const char * ast_get_switch_data (const struct ast_sw *sw)
 
int ast_get_switch_eval (const struct ast_sw *sw)
 
const char * ast_get_switch_name (const struct ast_sw *sw)
 
Other Extension stuff
const char * ast_get_extension_app (struct ast_exten *e)
 
void * ast_get_extension_app_data (struct ast_exten *e)
 
const char * ast_get_extension_cidmatch (struct ast_exten *e)
 
int ast_get_extension_data (char *buf, int bufsize, struct ast_channel *c, const char *context, const char *exten, int priority)
 Fill a string buffer with the data at a dialplan extension. More...
 
const char * ast_get_extension_label (struct ast_exten *e)
 
int ast_get_extension_matchcid (struct ast_exten *e)
 
int ast_get_extension_priority (struct ast_exten *exten)
 
Registrar info functions ...
const char * ast_get_context_registrar (struct ast_context *c)
 
const char * ast_get_extension_registrar (struct ast_exten *e)
 
const char * ast_get_ignorepat_registrar (const struct ast_ignorepat *ip)
 
const char * ast_get_include_registrar (const struct ast_include *i)
 
const char * ast_get_switch_registrar (const struct ast_sw *sw)
 
Walking functions ...
struct ast_extenast_walk_context_extensions (struct ast_context *con, struct ast_exten *priority)
 
const struct ast_ignorepatast_walk_context_ignorepats (const struct ast_context *con, const struct ast_ignorepat *ip)
 
const struct ast_includeast_walk_context_includes (const struct ast_context *con, const struct ast_include *inc)
 
const struct ast_swast_walk_context_switches (const struct ast_context *con, const struct ast_sw *sw)
 
struct ast_contextast_walk_contexts (struct ast_context *con)
 
struct ast_extenast_walk_extension_priorities (struct ast_exten *exten, struct ast_exten *priority)
 
Iterator functions ...
int ast_context_ignorepats_count (const struct ast_context *con)
 
const struct ast_ignorepatast_context_ignorepats_get (const struct ast_context *con, int idx)
 
int ast_context_includes_count (const struct ast_context *con)
 
const struct ast_includeast_context_includes_get (const struct ast_context *con, int idx)
 
int ast_context_switches_count (const struct ast_context *con)
 
const struct ast_swast_context_switches_get (const struct ast_context *con, int idx)
 
Substitution routines, using static string buffers
void pbx_substitute_variables_helper (struct ast_channel *c, const char *cp1, char *cp2, int count)
 
void pbx_substitute_variables_helper_full (struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int cp2_size, size_t *used)
 
void pbx_substitute_variables_helper_full_location (struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int cp2_size, size_t *used, char *context, char *exten, int pri)
 Substitutes variables, similar to pbx_substitute_variables_helper_full, but allows passing the context, extension, and priority in. More...
 
void pbx_substitute_variables_varshead (struct varshead *headp, const char *cp1, char *cp2, int count)
 
Substitution routines, using dynamic string buffers
const char * ast_str_retrieve_variable (struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, struct varshead *headp, const char *var)
 
void ast_str_substitute_variables (struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
 
void ast_str_substitute_variables_full (struct ast_str **buf, ssize_t maxlen, struct ast_channel *c, struct varshead *headp, const char *templ, size_t *used)
 
void ast_str_substitute_variables_varshead (struct ast_str **buf, ssize_t maxlen, struct varshead *headp, const char *templ)
 
int ast_hashtab_compare_contexts (const void *ah_a, const void *ah_b)
 hashtable functions for contexts 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 1543 of file pbx.h.

◆ ast_custom_function_register_escalating

#define ast_custom_function_register_escalating (   acf,
  escalation 
)    __ast_custom_function_register_escalating(acf, escalation, AST_MODULE_SELF)

Register a custom function which requires escalated privileges.

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

Definition at line 1552 of file pbx.h.

◆ AST_MAX_APP

#define AST_MAX_APP   32

Max length of an application

Definition at line 40 of file pbx.h.

◆ AST_PBX_ERROR

#define AST_PBX_ERROR   1

Jump to the 'e' exten

Definition at line 50 of file pbx.h.

◆ AST_PBX_GOTO_FAILED

#define AST_PBX_GOTO_FAILED   -3

Definition at line 42 of file pbx.h.

◆ AST_PBX_HANGUP

#define AST_PBX_HANGUP   -1

Special return values from applications to the PBX.

Jump to the 'h' exten

Definition at line 48 of file pbx.h.

◆ AST_PBX_INCOMPLETE

#define AST_PBX_INCOMPLETE   12

Return to PBX matching, allowing more digits for the extension

Definition at line 51 of file pbx.h.

◆ AST_PBX_KEEP

#define AST_PBX_KEEP   0

Definition at line 43 of file pbx.h.

◆ AST_PBX_MAX_STACK

#define AST_PBX_MAX_STACK   512

Definition at line 1648 of file pbx.h.

◆ AST_PBX_OK

#define AST_PBX_OK   0

No errors

Definition at line 49 of file pbx.h.

◆ AST_PBX_REPLACE

#define AST_PBX_REPLACE   1

Definition at line 44 of file pbx.h.

◆ PRIORITY_HINT

#define PRIORITY_HINT   -1

Special Priority for a hint

Definition at line 54 of file pbx.h.

◆ STATUS_NO_CONTEXT

#define STATUS_NO_CONTEXT   1

Definition at line 1639 of file pbx.h.

◆ STATUS_NO_EXTENSION

#define STATUS_NO_EXTENSION   2

Definition at line 1640 of file pbx.h.

◆ STATUS_NO_LABEL

#define STATUS_NO_LABEL   4

Definition at line 1642 of file pbx.h.

◆ STATUS_NO_PRIORITY

#define STATUS_NO_PRIORITY   3

Definition at line 1641 of file pbx.h.

◆ STATUS_SUCCESS

#define STATUS_SUCCESS   5

Definition at line 1643 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 1533 of file pbx.h.

1533  {
1534  AST_CFE_NONE,
1535  AST_CFE_READ,
1536  AST_CFE_WRITE,
1537  AST_CFE_BOTH,
1538 };
@ AST_CFE_NONE
Definition: pbx.h:1534
@ AST_CFE_READ
Definition: pbx.h:1535
@ AST_CFE_WRITE
Definition: pbx.h:1536
@ AST_CFE_BOTH
Definition: pbx.h:1537

◆ ast_ext_matchcid_types

extension matchcid types

Note
matchcid in ast_exten retains 0/1, this adds 3rd state for functions to specify all
See also
ast_context_remove_extension_callerid
Enumerator
AST_EXT_MATCHCID_OFF 

Match only extensions with matchcid=0

AST_EXT_MATCHCID_ON 

Match only extensions with matchcid=1 AND cidmatch matches

AST_EXT_MATCHCID_ANY 

Match both - used only in functions manipulating ast_exten's

Definition at line 77 of file pbx.h.

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

◆ ast_extension_states

Extension states.

Note
States can be combined Extension and device states in Asterisk
Enumerator
AST_EXTENSION_REMOVED 

Extension removed

AST_EXTENSION_DEACTIVATED 

Extension hint removed

AST_EXTENSION_NOT_INUSE 

No device INUSE or BUSY

AST_EXTENSION_INUSE 

One or more devices INUSE

AST_EXTENSION_BUSY 

All devices BUSY

AST_EXTENSION_UNAVAILABLE 

All devices UNAVAILABLE/UNREGISTERED

AST_EXTENSION_RINGING 

All devices RINGING

AST_EXTENSION_ONHOLD 

All devices ONHOLD

AST_EXTENSION_REMOVED 

Extension removed

AST_EXTENSION_DEACTIVATED 

Extension hint removed

AST_EXTENSION_NOT_INUSE 

No device INUSE or BUSY

AST_EXTENSION_INUSE 

One or more devices INUSE

AST_EXTENSION_BUSY 

All devices BUSY

AST_EXTENSION_UNAVAILABLE 

All devices UNAVAILABLE/UNREGISTERED

AST_EXTENSION_RINGING 

All devices RINGING

AST_EXTENSION_ONHOLD 

All devices ONHOLD

Definition at line 61 of file pbx.h.

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

◆ ast_pbx_outgoing_sync

Enumerator
AST_OUTGOING_NO_WAIT 

Don't wait for originated call to answer

AST_OUTGOING_WAIT 

Wait for originated call to answer

AST_OUTGOING_WAIT_COMPLETE 

Wait for originated call to answer and hangup

Definition at line 1146 of file pbx.h.

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

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

353  {
354  AST_PBX_SUCCESS = 0,
355  AST_PBX_FAILED = -1,
356  AST_PBX_CALL_LIMIT = -2,
357 };
@ AST_PBX_FAILED
Definition: pbx.h:355
@ AST_PBX_CALL_LIMIT
Definition: pbx.h:356
@ AST_PBX_SUCCESS
Definition: pbx.h:354

◆ ast_state_cb_update_reason

Enumerator
AST_HINT_UPDATE_DEVICE 

The extension state update is a result of a device state changing on the extension.

AST_HINT_UPDATE_PRESENCE 

The extension state update is a result of presence state changing on the extension.

Definition at line 89 of file pbx.h.

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

◆ ext_match_t

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

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

Definition at line 1630 of file pbx.h.

1630  {
1631  E_MATCHMORE = 0x00, /* extension can match but only with more 'digits' */
1632  E_CANMATCH = 0x01, /* extension can match with or without more 'digits' */
1633  E_MATCH = 0x02, /* extension is an exact match */
1634  E_MATCH_MASK = 0x03, /* mask for the argument to extension_match_core() */
1635  E_SPAWN = 0x12, /* want to spawn an extension. Requires exact match */
1636  E_FINDLABEL = 0x22 /* returns the priority for a given label. Requires exact match */
1637 };
@ E_MATCH_MASK
Definition: pbx.h:1634
@ E_MATCH
Definition: pbx.h:1633
@ E_CANMATCH
Definition: pbx.h:1632
@ E_FINDLABEL
Definition: pbx.h:1636
@ E_MATCHMORE
Definition: pbx.h:1631
@ E_SPAWN
Definition: pbx.h:1635

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.

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 }
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
#define ast_verb(level,...)
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:545
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:617
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:741
#define AST_RWLIST_INSERT_BEFORE_CURRENT
Definition: linkedlists.h:610
static struct ast_custom_function * ast_custom_function_find_nolock(const char *name)
static int acf_retrieve_docs(struct ast_custom_function *acf)
Registered functions container.
Definition: pbx_functions.c:59
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
struct ast_module * mod
Definition: pbx.h:142
enum ast_doc_src docsrc
Definition: pbx.h:127
const char * name
Definition: pbx.h:119
#define COLOR_BRCYAN
Definition: term.h:63
#define COLORIZE(fg, bg, str)
Definition: term.h:72
#define COLORIZE_FMT
Shortcut macros for coloring a set of text.
Definition: term.h:71
@ AST_STATIC_DOC
Definition: xmldoc.h:32

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

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

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 read_escalates
Definition: pbx.h:143
unsigned int write_escalates
Definition: pbx.h:147

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

◆ ast_active_calls()

int ast_active_calls ( void  )

Retrieve the number of active calls.

Definition at line 4767 of file pbx.c.

4768 {
4769  return countcalls;
4770 }
static int countcalls
Definition: pbx.c:771

References countcalls.

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

◆ 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

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

◆ ast_add_extension2()

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

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

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

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

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

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

◆ ast_async_goto()

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

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

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

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

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

◆ ast_build_timing()

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

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

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

Definition at line 3807 of file extconf.c.

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

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

◆ ast_canmatch_extension()

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

Looks for a valid matching extension.

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

Definition at line 4197 of file pbx.c.

4198 {
4199  return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_CANMATCH, 0, 0);
4200 }
static int priority
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:122
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:120
@ E_CANMATCH
Definition: extconf.h:217
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:2882
static struct test_val c

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

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

◆ ast_check_timing()

int ast_check_timing ( const struct ast_timing i)

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

Parameters
iPointer to an ast_timing structure.
Return values
1if the time matches.
0if the current time falls outside of the specified range.

Definition at line 4001 of file extconf.c.

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

References ast_check_timing2(), and ast_tvnow().

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

◆ ast_check_timing2()

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

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

Parameters
iPointer to an ast_timing structure.
tvSpecified time
Return values
1if the time matches.
0if the time falls outside of the specified range.

Definition at line 245 of file pbx_timing.c.

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

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

Referenced by ast_check_timing(), and pbx_builtin_gotoiftime().

◆ ast_complete_applications()

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

Command completion for the list of installed applications.

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

Definition at line 429 of file pbx_app.c.

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 }
static const char app[]
Definition: app_adsiprog.c:56
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
Definition: main/cli.c:2760
short word
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:494
Registered applications container.
Definition: pbx_app.c:67
ast_app: A registered application
Definition: pbx_app.c:45

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

◆ ast_context_add_ignorepat()

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

Add an ignorepat.

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

Adds an ignore pattern to a particular context.

Return values
0on success
-1on failure

Referenced by handle_cli_dialplan_add_ignorepat().

◆ ast_context_add_ignorepat2()

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

Definition at line 348 of file ael_main.c.

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

References ADD_LAST, create_name(), dump_extensions, ast_context::ignorepats, no_comp, registrar, and value.

Referenced by ast_compile_ael2(), and pbx_load_config().

◆ ast_context_add_include()

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

Add a context include.

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

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

Return values
0on success
-1on error

Referenced by AST_TEST_DEFINE(), and handle_cli_dialplan_add_include().

◆ ast_context_add_include2()

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

Add a context include.

Adds an include taking a struct ast_context as the first parameter

Note
See ast_context_add_include for information on arguments

Definition at line 359 of file ael_main.c.

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

References ADD_LAST, create_name(), dump_extensions, ast_context::includes, no_comp, registrar, and value.

Referenced by ast_compile_ael2(), and pbx_load_config().

◆ ast_context_add_switch()

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

Add a switch.

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

This function registers a switch with the asterisk switch architecture

Return values
0on success
-1on failure

◆ ast_context_add_switch2()

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

Adds a switch (first param is a ast_context)

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

Definition at line 370 of file ael_main.c.

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

References ADD_LAST, create_name(), dump_extensions, ast_context::eswitches, namelist::name2, no_comp, registrar, ast_context::switches, and value.

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

◆ ast_context_destroy()

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

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

Parameters
concontext to destroy
registrarwho registered it

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

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

◆ 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

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

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

4174 {
4175  struct ast_context *tmp = NULL;
4176  while ( (tmp = ast_walk_contexts(tmp)) ) {
4177  if (!name || !strcasecmp(name, tmp->name))
4178  break;
4179  }
4180  return tmp;
4181 }
static int tmp()
Definition: bt_open.c:389
static struct ast_context * ast_walk_contexts(struct ast_context *con)
Definition: extconf.c:4025
static const char name[]
Definition: format_mp3.c:68
ast_context: An extension context - must remain in sync with fake_context
Definition: pbx.c:284

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

Referenced by _macro_exec(), app_create(), context_included(), handle_cli_dialplan_add_extension(), handle_cli_dialplan_add_include(), isexten_function_read(), register_exten(), register_peer_exten(), and unregister_exten().

◆ 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

Referenced by add_hints(), app_create(), ast_compile_ael2(), ast_sip_persistent_endpoint_add_to_regcontext(), AST_TEST_DEFINE(), config_parse_variables(), 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().

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

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.

Definition at line 5164 of file pbx.c.

5165 {
5166  struct ast_context *c;
5167  int ret = -1;
5168 
5169  c = find_context_locked(macrocontext);
5170  if (c) {
5172 
5173  /* if we found context, lock macrolock */
5174  ret = ast_mutex_lock(&c->macrolock);
5175  }
5176 
5177  return ret;
5178 }
#define ast_mutex_lock(a)
Definition: lock.h:187
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:4821
int ast_unlock_contexts(void)
Unlocks contexts.

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

Referenced by _macro_exec().

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

4956 {
4958 }
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:4960
structure to hold extensions

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

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

◆ ast_context_remove_extension2()

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

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

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

Definition at line 4985 of file pbx.c.

4986 {
4988 }
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:4990

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

Referenced by add_extension(), and add_hints().

◆ ast_context_remove_extension_callerid()

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

Definition at line 4960 of file pbx.c.

4961 {
4962  int ret = -1; /* default error return */
4963  struct ast_context *c;
4964 
4966  if (c) { /* ... remove extension ... */
4968  matchcallerid, registrar, 0);
4970  }
4971 
4972  return ret;
4973 }

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

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

◆ ast_context_remove_extension_callerid2()

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

Definition at line 4990 of file pbx.c.

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

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

Referenced by ast_context_remove_extension2(), and ast_context_remove_extension_callerid().

◆ ast_context_remove_ignorepat()

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

Remove an ignorepat.

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

This removes the given ignorepattern

Return values
0on success
-1on failure

Referenced by handle_cli_dialplan_remove_ignorepat().

◆ ast_context_remove_ignorepat2()

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

◆ ast_context_remove_include()

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

Remove a context include.

Note
See ast_context_add_include for information on arguments

Remove a context include.

Definition at line 4843 of file pbx.c.

4844 {
4845  int ret = -1;
4846  struct ast_context *c;
4847 
4849  if (c) {
4850  /* found, remove include from this context ... */
4851  ret = ast_context_remove_include2(c, include, registrar);
4853  }
4854  return ret;
4855 }
int ast_context_remove_include2(struct ast_context *con, const char *include, const char *registrar)
Locks context, remove included contexts, unlocks context. When we call this function,...
Definition: pbx.c:4866

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

Referenced by handle_cli_dialplan_remove_include().

◆ ast_context_remove_include2()

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

Removes an include by an ast_context structure.

Note
See ast_context_add_include for information on arguments

Removes an include by an ast_context structure.

Return values
0on success.
-1on failure.

Definition at line 4866 of file pbx.c.

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

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

Referenced by ast_context_remove_include().

◆ ast_context_remove_switch()

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

Remove a switch.

Removes a switch with the given parameters

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

Definition at line 4901 of file pbx.c.

4902 {
4903  int ret = -1; /* default error return */
4904  struct ast_context *c;
4905 
4907  if (c) {
4908  /* remove switch from this context ... */
4909  ret = ast_context_remove_switch2(c, sw, data, registrar);
4911  }
4912  return ret;
4913 }
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:4923

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

◆ ast_context_remove_switch2()

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

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

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

Definition at line 4923 of file pbx.c.

4924 {
4925  int idx;
4926  int ret = -1;
4927 
4928  ast_wrlock_context(con);
4929 
4930  /* walk switches */
4931  for (idx = 0; idx < ast_context_switches_count(con); idx++) {
4932  struct ast_sw *i = AST_VECTOR_GET(&con->alts, idx);
4933 
4934  if (!strcmp(ast_get_switch_name(i), sw) &&
4935  !strcmp(ast_get_switch_data(i), data) &&
4936  (!registrar || !strcmp(ast_get_switch_registrar(i), registrar))) {
4937 
4938  /* found, remove from list */
4939  ast_verb(3, "Removing switch '%s' from context '%s; registrar=%s'\n", sw, ast_get_context_name(con), registrar);
4940  AST_VECTOR_REMOVE_ORDERED(&con->alts, idx);
4941 
4942  /* free switch and return */
4943  sw_free(i);
4944  ret = 0;
4945  break;
4946  }
4947  }
4948 
4949  ast_unlock_context(con);
4950 
4951  return ret;
4952 }
const char * ast_get_switch_registrar(const struct ast_sw *sw)
Definition: pbx_sw.c:63
const char * ast_get_switch_name(const struct ast_sw *sw)
Definition: pbx_sw.c:48
const char * ast_get_switch_data(const struct ast_sw *sw)
Definition: pbx_sw.c:53
int ast_context_switches_count(const struct ast_context *con)
void sw_free(struct ast_sw *sw)
Definition: pbx_sw.c:101
struct ast_sws alts
Definition: pbx.c:292
ast_sw: Switch statement in extensions.conf
Definition: pbx_sw.c:37
const char * data
Definition: pbx_sw.c:42

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

Referenced by ast_context_remove_switch().

◆ ast_context_set_autohints()

void ast_context_set_autohints ( struct ast_context con,
int  enabled 
)

Enable or disable autohints support on a context.

Parameters
conpointer to the context
enabledwhether autohints are enabled

Referenced by pbx_load_config().

◆ ast_context_switches_count()

int ast_context_switches_count ( const struct ast_context con)

◆ ast_context_switches_get()

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

◆ ast_context_unlockmacro()

int ast_context_unlockmacro ( const char *  macrocontext)

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.

Definition at line 5185 of file pbx.c.

5186 {
5187  struct ast_context *c;
5188  int ret = -1;
5189 
5190  c = find_context_locked(macrocontext);
5191  if (c) {
5193 
5194  /* if we found context, unlock macrolock */
5195  ret = ast_mutex_unlock(&c->macrolock);
5196  }
5197 
5198  return ret;
5199 }
#define ast_mutex_unlock(a)
Definition: lock.h:188

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

Referenced by _macro_exec().

◆ 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

Referenced by pbx_load_module().

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

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 }
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:885
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:374
@ AST_XML_DOC
Definition: xmldoc.h:31

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

◆ ast_destroy_timing()

int ast_destroy_timing ( struct ast_timing i)

Deallocates memory structures associated with a timing bitmap.

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

Definition at line 279 of file pbx_timing.c.

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

References ast_free, NULL, and ast_timing::timezone.

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

◆ ast_devstate_to_extenstate()

enum ast_extension_states ast_devstate_to_extenstate ( enum ast_device_state  devstate)

Map devstate to an extension state.

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

Definition at line 3004 of file pbx.c.

3014 {
3015  switch (devstate) {
3016  case AST_DEVICE_ONHOLD:
3017  return AST_EXTENSION_ONHOLD;
3018  case AST_DEVICE_BUSY:
3019  return AST_EXTENSION_BUSY;
3020  case AST_DEVICE_UNKNOWN:
3021  return AST_EXTENSION_NOT_INUSE;
3023  case AST_DEVICE_INVALID:
3025  case AST_DEVICE_RINGINUSE:
3027  case AST_DEVICE_RINGING:
3028  return AST_EXTENSION_RINGING;
3029  case AST_DEVICE_INUSE:
3030  return AST_EXTENSION_INUSE;
3031  case AST_DEVICE_NOT_INUSE:
3032  return AST_EXTENSION_NOT_INUSE;
3033  case AST_DEVICE_TOTAL: /* not a device state, included for completeness */
3034  break;
3035  }
3036 
3037  return AST_EXTENSION_NOT_INUSE;
3038 }
@ AST_DEVICE_RINGINUSE
Definition: devicestate.h:60
@ AST_DEVICE_INUSE
Definition: devicestate.h:55
@ AST_DEVICE_UNKNOWN
Definition: devicestate.h:53
@ AST_DEVICE_ONHOLD
Definition: devicestate.h:61
@ AST_DEVICE_RINGING
Definition: devicestate.h:59
@ AST_DEVICE_INVALID
Definition: devicestate.h:57
@ AST_DEVICE_BUSY
Definition: devicestate.h:56
@ AST_DEVICE_NOT_INUSE
Definition: devicestate.h:54
@ AST_DEVICE_TOTAL
Definition: devicestate.h:62
@ AST_DEVICE_UNAVAILABLE
Definition: devicestate.h:58

References ast_hint_extension_nolock(), ast_rdlock_contexts(), ast_unlock_contexts(), c, context, and exten.

Referenced by ast_extension_state3(), and AST_TEST_DEFINE().

◆ ast_exists_extension()

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

Determine whether an extension exists.

Parameters
cthis is not important
contextwhich context to look in
extenwhich extension to search for
prioritypriority of the action within the extension
calleridcallerid to search for
Note
It is possible for autoservice to be started and stopped on c during this function call, it is important that c is not locked prior to calling this. Otherwise a deadlock may occur
Returns
If an extension within the given context(or callerid) with the given priority is found a non zero value will be returned. Otherwise, 0 is returned.

Definition at line 4182 of file pbx.c.

4183 {
4184  return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCH, 0, 0);
4185 }
@ E_MATCH
Definition: extconf.h:218

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

Referenced by __analog_ss_thread(), _macro_exec(), action_originate(), add_to_regcontext(), analog_ss_thread(), ast_app_dtget(), ast_bridge_setup_after_goto(), ast_sip_persistent_endpoint_update_state(), 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_refer_info(), gosub_exec(), isexten_function_read(), jingle_new(), join_conference_bridge(), key_dial_page(), leave_voicemail(), local_call(), local_devicestate(), loopback_exists(), mgcp_ss(), minivm_greet_exec(), my_handle_dtmf(), new_subscribe(), onModeChanged(), ooh323_rtp_read(), options_on_rx_request(), pbx_builtin_waitexten(), privacy_exec(), 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().

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

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

◆ ast_extension_close()

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

Definition at line 2425 of file pbx.c.

2426 {
2427  if (needmore != E_MATCHMORE && needmore != E_CANMATCH)
2428  ast_log(LOG_WARNING, "invalid argument %d\n", needmore);
2429  return extension_match_core(pattern, data, needmore);
2430 }
@ E_MATCHMORE
Definition: extconf.h:216
static int extension_match_core(const char *pattern, const char *data, enum ext_match_t mode)
Definition: pbx.c:2407

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

Referenced by lua_find_extension(), and realtime_switch_common().

◆ ast_extension_cmp()

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

Determine if one extension should match before another.

Parameters
aextension to compare with b
bextension to compare with a

Checks whether or extension a should match before extension b

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

Definition at line 2190 of file pbx.c.

2191 {
2192  int cmp;
2193 
2194  cmp = ext_cmp(a, b);
2195  if (cmp < 0) {
2196  return -1;
2197  }
2198  if (cmp > 0) {
2199  return 1;
2200  }
2201  return 0;
2202 }
static int ext_cmp(const char *left, const char *right)
Definition: pbx.c:2133
static struct test_val b
static struct test_val a

References a, b, and ext_cmp().

Referenced by lua_extension_cmp().

◆ ast_extension_match()

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

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

Parameters
patternpattern to match
extensionextension to check against the pattern.

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

Return values
1on match
0on failure

Definition at line 4296 of file extconf.c.

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

References E_MATCH, and extension_match_core().

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

◆ ast_extension_patmatch()

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

◆ ast_extension_state()

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

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

Parameters
cthis is not important
contextwhich context to look in
extenwhich extension to get state
Returns
extension state as defined in the ast_extension_states enum

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

Definition at line 3177 of file pbx.c.

3178 {
3180 }
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:3148

References c, context, exten, internal_extension_state_extended(), and NULL.

Referenced by action_extensionstate(), and get_queue_member_status().

◆ ast_extension_state2str()

const char* ast_extension_state2str ( int  extension_state)

Return string representation of the state of an extension.

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

Return string representation of the state of an extension.

Definition at line 3133 of file pbx.c.

3134 {
3135  int i;
3136 
3137  for (i = 0; (i < ARRAY_LEN(extension_states)); i++) {
3138  if (extension_states[i].extension_state == extension_state)
3139  return extension_states[i].text;
3140  }
3141  return "Unknown";
3142 }
static const struct cfextension_states extension_states[]
const char *const text
Definition: pbx.c:606
#define ARRAY_LEN(a)
Definition: utils.h:661

References ARRAY_LEN, extension_states, and cfextension_states::text.

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

◆ ast_extension_state_add()

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

Add watcher for extension states.

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

Definition at line 3830 of file pbx.c.

3832 {
3833  return extension_state_add_destroy(context, exten, change_cb, NULL, data, 0);
3834 }
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:3734

References context, ast_exten::data, exten, extension_state_add_destroy(), and NULL.

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

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

3826 {
3827  return extension_state_add_destroy(context, exten, change_cb, destroy_cb, data, 0);
3828 }

References context, ast_exten::data, exten, and extension_state_add_destroy().

◆ ast_extension_state_add_destroy_extended()

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

Add watcher for extended extension states with destructor.

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

Definition at line 3836 of file pbx.c.

3838 {
3839  return extension_state_add_destroy(context, exten, change_cb, destroy_cb, data, 1);
3840 }

References context, ast_exten::data, exten, and extension_state_add_destroy().

Referenced by handle_request_subscribe(), and subscription_established().

◆ ast_extension_state_add_extended()

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

Add watcher for extended extension states.

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

Definition at line 3842 of file pbx.c.

3844 {
3845  return extension_state_add_destroy(context, exten, change_cb, NULL, data, 1);
3846 }

References context, ast_exten::data, exten, extension_state_add_destroy(), and NULL.

◆ ast_extension_state_del()

int ast_extension_state_del ( int  id,
ast_state_cb_type  change_cb 
)

Deletes a state change watcher by ID.

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

Definition at line 3863 of file pbx.c.

3864 {
3865  struct ast_state_cb *p_cur;
3866  int ret = -1;
3867 
3868  if (!id) { /* id == 0 is a callback without extension */
3869  if (!change_cb) {
3870  return ret;
3871  }
3873  if (p_cur) {
3874  ret = 0;
3875  ao2_ref(p_cur, -1);
3876  }
3877  } else { /* callback with extension, find the callback based on ID */
3878  struct ast_hint *hint;
3879 
3880  ao2_lock(hints);/* Locked to hold off ast_merge_contexts_and_delete */
3881  hint = ao2_callback(hints, 0, find_hint_by_cb_id, &id);
3882  if (hint) {
3883  p_cur = ao2_find(hint->callbacks, &id, OBJ_UNLINK);
3884  if (p_cur) {
3885  ret = 0;
3886  ao2_ref(p_cur, -1);
3887  }
3888  ao2_ref(hint, -1);
3889  }
3890  ao2_unlock(hints);
3891  }
3892 
3893  return ret;
3894 }
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container,...
Definition: astobj2.h:1693
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1736
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_lock(a)
Definition: astobj2.h:717
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
@ OBJ_UNLINK
Definition: astobj2.h:1039
static struct ao2_container * statecbs
Definition: pbx.c:801
static int find_hint_by_cb_id(void *obj, void *arg, int flags)
Find Hint by callback id.
Definition: pbx.c:3849
Structure for dial plan hints.
Definition: pbx.c:324
struct ao2_container * callbacks
Definition: pbx.c:332
ast_state_cb: An extension state notify register item
Definition: pbx.c:301
ast_state_cb_type change_cb
Definition: pbx.c:309

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

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

◆ ast_extension_state_extended()

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

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

Since
11
Parameters
cthis is not important
contextwhich context to look in
extenwhich extension to get state
[out]device_state_infoptr to an ao2_container with extended state info, must be unref'd after use.
Returns
extension state as defined in the ast_extension_states enum

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

Definition at line 3183 of file pbx.c.

3185 {
3186  struct ao2_container *container = NULL;
3187  int ret;
3188 
3189  if (device_state_info) {
3191  }
3192 
3194  if (ret < 0 && container) {
3195  ao2_ref(container, -1);
3196  container = NULL;
3197  }
3198 
3199  if (device_state_info) {
3201  *device_state_info = container;
3202  }
3203 
3204  return ret;
3205 }
static void get_device_state_causing_channels(struct ao2_container *c)
Definition: pbx.c:3303
static struct ao2_container * alloc_device_state_info(void)
Definition: pbx.c:3083
struct ao2_container * container
Definition: res_fax.c:501
Generic container type.

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

Referenced by exten_state_data_alloc(), and handle_request_subscribe().

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

4188 {
4189  return pbx_extension_helper(c, NULL, context, exten, 0, label, callerid, E_FINDLABEL, 0, 0);
4190 }
@ E_FINDLABEL
Definition: extconf.h:221

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

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

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

4978 {
4979  return pbx_extension_helper(c, con, NULL, exten, 0, label, callerid, E_FINDLABEL);
4980 }
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:4916

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

Referenced by pbx_load_config().

◆ ast_func_read()

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

executes a read operation on a function

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

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

Return values
0success
non-zerofailure

Definition at line 599 of file pbx_functions.c.

600 {
601  char *copy = ast_strdupa(function);
602  char *args = func_args(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  }
634  ast_free(str);
635 
636  return res;
637  }
638 
639  return -1;
640 }
const char * str
Definition: app_jack.c:147
static int copy(char *infile, char *outfile)
Utility function to copy a file.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
struct ast_module_user * __ast_module_user_add(struct ast_module *, struct ast_channel *)
Definition: loader.c:800
void __ast_module_user_remove(struct ast_module *, struct ast_module_user *)
Definition: loader.c:826
static int is_read_allowed(struct ast_custom_function *acfptr)
Determines whether execution of a custom function's read function is allowed.
static char * func_args(char *function)
return a pointer to the arguments of the function, and terminates the function name with '\0'
struct ast_custom_function * ast_custom_function_find(const char *name)
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:739
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:640
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:406
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition: strings.h:723
ast_acf_read_fn_t read
Definition: pbx.h:129
ast_acf_read2_fn_t read2
Definition: pbx.h:137
struct ast_channel * chan
Definition: loader.c:128
Support for dynamic strings.
Definition: strings.h:604
const char * args

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

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

◆ ast_func_read2()

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

executes a read operation on a function

Parameters
chanChannel to execute on
functionData containing the function call string (will be modified)
strA dynamic string buffer into which to place the result.
maxlen<0 if the dynamic buffer should not grow; >0 if the dynamic buffer should be limited to that number of bytes; 0 if the dynamic buffer has no upper limit

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

Return values
0success
non-zerofailure

Definition at line 642 of file pbx_functions.c.

643 {
644  char *copy = ast_strdupa(function);
645  char *args = func_args(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 {
674  }
675  } else {
676  maxsize = maxlen;
677  }
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 }
static int maxsize
#define VAR_BUF_SIZE
Definition: pbx_private.h:68
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:674
#define ast_str_make_space(buf, new_len)
Definition: strings.h:806
size_t read_max
Definition: pbx.h:139

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

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

◆ ast_func_write()

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

executes a write operation on a function

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

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

Return values
0success
non-zerofailure

Definition at line 692 of file pbx_functions.c.

693 {
694  char *copy = ast_strdupa(function);
695  char *args = func_args(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 }
static int is_write_allowed(struct ast_custom_function *acfptr)
Determines whether execution of a custom function's write function is allowed.
ast_acf_write_fn_t write
Definition: pbx.h:141

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

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

◆ ast_get_extension_app()

const char* ast_get_extension_app ( struct ast_exten e)

◆ ast_get_extension_app_data()

void* ast_get_extension_app_data ( struct ast_exten e)

◆ ast_get_extension_cidmatch()

const char* ast_get_extension_cidmatch ( struct ast_exten e)

◆ ast_get_extension_context()

struct ast_context* ast_get_extension_context ( struct ast_exten exten)

◆ ast_get_extension_data()

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

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

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

◆ ast_get_extension_label()

const char* ast_get_extension_label ( struct ast_exten e)

◆ ast_get_extension_matchcid()

int ast_get_extension_matchcid ( struct ast_exten e)

◆ ast_get_extension_name()

const char* ast_get_extension_name ( struct ast_exten exten)

◆ ast_get_extension_priority()

int ast_get_extension_priority ( struct ast_exten exten)

◆ ast_get_extension_registrar()

const char* ast_get_extension_registrar ( struct ast_exten e)

◆ ast_get_extension_registrar_file()

const char* ast_get_extension_registrar_file ( struct ast_exten e)

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

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

Referenced by show_dialplan_helper_extension_output().

◆ ast_get_extension_registrar_line()

int ast_get_extension_registrar_line ( struct ast_exten e)

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

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

Referenced by show_dialplan_helper_extension_output().

◆ ast_get_hint()

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

If an extension hint exists, return non-zero.

Parameters
hintbuffer for hint
hintsizesize of hint buffer, in bytes
namebuffer for name portion of hint
namesizesize of name buffer
cChannel from which to return the hint. This is only important when the hint or name contains an expression to be expanded.
contextwhich context to look in
extenwhich extension to search for
Returns
If an extension within the given context with the priority PRIORITY_HINT is found, a non zero value will be returned. Otherwise, 0 is returned.

If an extension hint exists, return non-zero.

Definition at line 4144 of file pbx.c.

4145 {
4146  struct ast_exten *e = ast_hint_extension(c, context, exten);
4147 
4148  if (e) {
4149  if (hint)
4150  ast_copy_string(hint, ast_get_extension_app(e), hintsize);
4151  if (name) {
4152  const char *tmp = ast_get_extension_app_data(e);
4153  if (tmp)
4154  ast_copy_string(name, tmp, namesize);
4155  }
4156  return -1;
4157  }
4158  return 0;
4159 }
static struct ast_exten * ast_hint_extension(struct ast_channel *c, const char *context, const char *exten)
Definition: pbx.c:3004
const char * ast_get_extension_app(struct ast_exten *e)
void * ast_get_extension_app_data(struct ast_exten *e)

References ast_copy_string(), ast_get_extension_app(), ast_get_extension_app_data(), ast_hint_extension(), c, context, exten, name, and tmp().

Referenced by action_extensionstate(), custom_devstate_callback(), device_state_cb(), get_cid_name(), get_resource_display_name(), manager_state_cb(), skinny_extensionstate_cb(), and state_notify_build_xml().

◆ ast_get_ignorepat_name()

const char* ast_get_ignorepat_name ( const struct ast_ignorepat ip)

Definition at line 42 of file pbx_ignorepat.c.

43 {
44  return ip ? ip->pattern : NULL;
45 }
const char pattern[0]
Definition: pbx_ignorepat.c:39

References NULL, and ast_ignorepat::pattern.

Referenced by complete_dialplan_remove_ignorepat(), handle_cli_dialplan_save(), lookup_c_ip(), and show_dialplan_helper().

◆ ast_get_ignorepat_registrar()

const char* ast_get_ignorepat_registrar ( const struct ast_ignorepat ip)

Definition at line 47 of file pbx_ignorepat.c.

48 {
49  return ip ? ip->registrar : NULL;
50 }
const char * registrar
Definition: pbx_ignorepat.c:38

References NULL, and ast_ignorepat::registrar.

Referenced by handle_cli_dialplan_save(), and show_dialplan_helper().

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

Definition at line 60 of file pbx_include.c.

61 {
62  return inc ? inc->registrar : NULL;
63 }

References NULL, and ast_include::registrar.

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

◆ ast_get_switch_data()

const char* ast_get_switch_data ( const struct ast_sw sw)

Definition at line 53 of file pbx_sw.c.

54 {
55  return sw ? sw->data : NULL;
56 }

References ast_sw::data, and NULL.

Referenced by ast_context_remove_switch2(), handle_cli_dialplan_save(), pbx_find_extension(), and show_dialplan_helper().

◆ ast_get_switch_eval()

int ast_get_switch_eval ( const struct ast_sw sw)

Definition at line 58 of file pbx_sw.c.

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

References ast_sw::eval.

Referenced by pbx_find_extension().

◆ ast_get_switch_name()

const char* ast_get_switch_name ( const struct ast_sw sw)

Definition at line 48 of file pbx_sw.c.

49 {
50  return sw ? sw->name : NULL;
51 }
const char * name
Definition: pbx_sw.c:38

References ast_sw::name, and NULL.

Referenced by ast_context_remove_switch2(), handle_cli_dialplan_save(), pbx_find_extension(), and show_dialplan_helper().

◆ ast_get_switch_registrar()

const char* ast_get_switch_registrar ( const struct ast_sw sw)

Definition at line 63 of file pbx_sw.c.

64 {
65  return sw ? sw->registrar : NULL;
66 }
const char * registrar
Definition: pbx_sw.c:40

References NULL, and ast_sw::registrar.

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

◆ ast_goto_if_exists()

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

◆ ast_hashtab_compare_contexts()

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

hashtable functions for contexts

Definition at line 589 of file ael_main.c.

590 {
591  return 0;
592 }

References bc, and ast_context::name.

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

◆ ast_hashtab_hash_contexts()

unsigned int ast_hashtab_hash_contexts ( const void *  obj)

Definition at line 596 of file ael_main.c.

597 {
598  return 0;
599 }

References ast_hashtab_hash_string(), and ast_context::name.

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

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

3234 {
3235  struct ast_exten *e;
3236 
3237  if (!(e = ast_hint_extension(c, context, exten))) { /* Do we have a hint for this extension ? */
3238  return -1; /* No hint, return -1 */
3239  }
3240 
3241  if (e->exten[0] == '_') {
3242  /* Create this hint on-the-fly */
3243  ao2_lock(hints);
3244  ast_add_extension(e->parent->name, 0, exten, e->priority, e->label,
3245  e->matchcid ? e->cidmatch : NULL, e->app, ast_strdup(e->data), ast_free_ptr,
3246  e->registrar);
3247  ao2_unlock(hints);
3248  if (!(e = ast_hint_extension(c, context, exten))) {
3249  /* Improbable, but not impossible */
3250  return -1;
3251  }
3252  }
3253 
3254  return extension_presence_state_helper(e, subtype, message);
3255 }
void ast_free_ptr(void *ptr)
free() wrapper
Definition: astmm.c:1739
static int extension_presence_state_helper(struct ast_exten *e, char **subtype, char **message)
Definition: pbx.c:3207
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.
const char * app
Definition: pbx.c:246
struct ast_context * parent
Definition: pbx.c:245
void * data
Definition: pbx.c:248

References ao2_lock, ao2_unlock, ast_exten::app, ast_add_extension(), ast_free_ptr(), ast_hint_extension(), ast_strdup, c, ast_exten::cidmatch, context, ast_exten::data, exten, 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().

◆ 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

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

◆ ast_matchmore_extension()

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

Looks to see if adding anything to this extension might match something. (exists ^ canmatch)

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

Definition at line 4202 of file pbx.c.

4203 {
4204  return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCHMORE, 0, 0);
4205 }

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

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

◆ 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

Referenced by lua_reload_extensions(), and pbx_load_module().

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

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

◆ ast_pbx_h_exten_run()

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

Run the h exten from the given context.

Since
11.0
Parameters
chanChannel to run the h exten on.
contextContext the h exten is in.

Definition at line 4212 of file pbx.c.

4213 {
4214  int autoloopflag;
4215  int found;
4216  int spawn_error;
4217 
4218  ast_channel_lock(chan);
4219 
4220  /*
4221  * Make sure that the channel is marked as hungup since we are
4222  * going to run the h exten on it.
4223  */
4225 
4226  /* Set h exten location */
4227  if (context != ast_channel_context(chan)) {
4229  }
4230  ast_channel_exten_set(chan, "h");
4231  ast_channel_priority_set(chan, 1);
4232 
4233  /* Save autoloop flag */
4234  autoloopflag = ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_AUTOLOOP);
4236  ast_channel_unlock(chan);
4237 
4238  for (;;) {
4239  spawn_error = ast_spawn_extension(chan, ast_channel_context(chan),
4241  S_COR(ast_channel_caller(chan)->id.number.valid,
4242  ast_channel_caller(chan)->id.number.str, NULL), &found, 1);
4243 
4244  ast_channel_lock(chan);
4245  if (spawn_error) {
4246  /* The code after the loop needs the channel locked. */
4247  break;
4248  }
4250  ast_channel_unlock(chan);
4251  }
4252  if (found && spawn_error) {
4253  /* Something bad happened, or a hangup has been requested. */
4254  ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n",
4256  ast_channel_priority(chan), ast_channel_name(chan));
4257  ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n",
4259  ast_channel_priority(chan), ast_channel_name(chan));
4260  }
4261 
4262  /* An "h" exten has been run, so indicate that one has been run. */
4264 
4265  /* Restore autoloop flag */
4267  ast_channel_unlock(chan);
4268 }
void ast_channel_exten_set(struct ast_channel *chan, const char *value)
@ AST_SOFTHANGUP_HANGUP_EXEC
Definition: channel.h:1154
#define ast_channel_lock(chan)
Definition: channel.h:2922
const char * ast_channel_context(const struct ast_channel *chan)
int ast_channel_priority(const struct ast_channel *chan)
const char * ast_channel_name(const struct ast_channel *chan)
@ AST_FLAG_BRIDGE_HANGUP_RUN
Definition: channel.h:1018
@ AST_FLAG_IN_AUTOLOOP
Definition: channel.h:997
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
const char * ast_channel_exten(const struct ast_channel *chan)
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
void ast_channel_context_set(struct ast_channel *chan, const char *value)
int ast_softhangup_nolock(struct ast_channel *chan, int cause)
Softly hangup up a channel (no channel lock)
Definition: channel.c:2457
void ast_channel_priority_set(struct ast_channel *chan, int value)
#define ast_channel_unlock(chan)
Definition: channel.h:2923
#define ast_debug(level,...)
Log a DEBUG message.
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:4207
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:87
Number structure.
Definition: app_followme.c:154
#define ast_test_flag(p, flag)
Definition: utils.h:63
#define ast_set2_flag(p, value, flag)
Definition: utils.h:94
#define ast_set_flag(p, flag)
Definition: utils.h:70

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, context, NULL, and S_COR.

Referenced by ast_bridge_setup_after_goto().

◆ ast_pbx_hangup_handler_destroy()

void ast_pbx_hangup_handler_destroy ( struct ast_channel chan)

Destroy the hangup handler container on a channel.

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

Definition at line 103 of file pbx_hangup_handler.c.

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

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

Referenced by ast_channel_destructor(), and ast_dummy_channel_destructor().

◆ ast_pbx_hangup_handler_init()

void ast_pbx_hangup_handler_init ( struct ast_channel chan)

Init the hangup handler container on a channel.

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

Definition at line 95 of file pbx_hangup_handler.c.

96 {
98 
101 }
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:681

References ast_channel_hangup_handlers(), AST_LIST_HEAD_INIT_NOLOCK, and handlers.

Referenced by __ast_channel_alloc_ap(), and __ast_dummy_channel_alloc().

◆ ast_pbx_hangup_handler_pop()

int ast_pbx_hangup_handler_pop ( struct ast_channel chan)

Pop the top of the channel hangup handler stack.

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

Definition at line 119 of file pbx_hangup_handler.c.

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

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

Referenced by func_channel_write_real().

◆ ast_pbx_hangup_handler_push()

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

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

Since
11.0
Parameters
chanChannel to push the hangup handler onto.
handlerGosub application parameter string.

Definition at line 138 of file pbx_hangup_handler.c.

139 {
141  struct ast_hangup_handler *h_handler;
142  const char *expanded_handler;
143 
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 
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_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
const char * ast_app_expand_sub_args(struct ast_channel *chan, const char *args)
Add missing context/exten to subroutine argument string.
Definition: main/app.c:348
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:711
static void handler(const char *name, int response_code, struct ast_variable *get_params, struct ast_variable *path_vars, struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
Definition: test_ari.c:59

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

Referenced by func_channel_write_real().

◆ ast_pbx_hangup_handler_run()

int ast_pbx_hangup_handler_run ( struct ast_channel chan)

Run all hangup handlers on the channel.

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

Definition at line 58 of file pbx_hangup_handler.c.

59 {
61  struct ast_hangup_handler *h_handler;
62 
63  ast_channel_lock(chan);
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 (;;) {
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 }
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:367
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:450

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

Referenced by ast_hangup().

◆ ast_pbx_outgoing_app()

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

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

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

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

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

◆ ast_pbx_outgoing_app_predial()

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

Referenced by originate_exec().

◆ ast_pbx_outgoing_exten()

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

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

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

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

◆ ast_pbx_outgoing_exten_predial()

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

Referenced by originate_exec().

◆ ast_pbx_run()

enum ast_pbx_result ast_pbx_run ( struct ast_channel c)

Execute the PBX in the current thread.

Parameters
cchannel to run the pbx on

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

Return values
Zeroon success
non-zeroon failure

Definition at line 4695 of file pbx.c.

4763 {
4764  return ast_pbx_run_args(c, NULL);
4765 }
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:4742

References __ast_pbx_run(), c, ast_channel::data, decrease_call_count(), and NULL.

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

◆ ast_pbx_run_args()

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

Execute the PBX in the current thread.

Parameters
cchannel to run the pbx on
argsoptions for the pbx

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

Return values
Zeroon success
non-zeroon failure

Definition at line 4695 of file pbx.c.

4743 {
4744  enum ast_pbx_result res = AST_PBX_SUCCESS;
4745 
4747  ast_log(LOG_WARNING, "PBX requires Asterisk to be fully booted\n");
4748  return AST_PBX_FAILED;
4749  }
4750 
4751  if (increase_call_count(c)) {
4752  return AST_PBX_CALL_LIMIT;
4753  }
4754 
4755  res = __ast_pbx_run(c, args);
4756 
4758 
4759  return res;
4760 }
struct ast_flags ast_options
Definition: options.c:61
@ AST_OPT_FLAG_FULLY_BOOTED
Definition: options.h:58
static void decrease_call_count(void)
Definition: pbx.c:4673
static int increase_call_count(const struct ast_channel *c)
Increase call count for channel.
Definition: pbx.c:4624
static enum ast_pbx_result __ast_pbx_run(struct ast_channel *c, struct ast_pbx_args *args)
Definition: pbx.c:4313
ast_pbx_result
The result codes when starting the PBX on a channel with ast_pbx_start.
Definition: pbx.h:353

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

◆ ast_pbx_start()

enum ast_pbx_result ast_pbx_start ( struct ast_channel c)

Create a new thread and start the PBX.

Parameters
cchannel to start the pbx on
See also
ast_pbx_run for a synchronous function to run the PBX in the current thread, as opposed to starting a new one.
Return values
Zeroon success
non-zeroon failure

Definition at line 4695 of file pbx.c.

4716 {
4717  pthread_t t;
4718 
4719  if (!c) {
4720  ast_log(LOG_WARNING, "Asked to start thread on NULL channel?\n");
4721  return AST_PBX_FAILED;
4722  }
4723 
4725  ast_log(LOG_WARNING, "PBX requires Asterisk to be fully booted\n");
4726  return AST_PBX_FAILED;
4727  }
4728 
4729  if (increase_call_count(c))
4730  return AST_PBX_CALL_LIMIT;
4731 
4732  /* Start a new thread, and get something handling this channel. */
4734  ast_log(LOG_WARNING, "Failed to create new channel thread\n");
4736  return AST_PBX_FAILED;
4737  }
4738 
4739  return AST_PBX_SUCCESS;
4740 }
static void * pbx_thread(void *data)
Definition: pbx.c:4695
#define ast_pthread_create_detached(a, b, c, d)
Definition: utils.h:583

Referenced by alsa_new(), 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(), ooh323_new(), pbx_start_incoming_request(), skinny_new(), and unistim_new().

◆ ast_processed_calls()

int ast_processed_calls ( void  )

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

Definition at line 4772 of file pbx.c.

4773 {
4774  return totalcalls;
4775 }
static int totalcalls
Definition: pbx.c:772

References totalcalls.

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

◆ ast_rdlock_context()

int ast_rdlock_context ( struct ast_context con)

◆ ast_rdlock_contexts()

int ast_rdlock_contexts ( void  )

◆ ast_register_switch()

int ast_register_switch ( struct ast_switch sw)

Register an alternative dialplan switch.

Parameters
swswitch to register

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

Return values
0success
non-zerofailure

Definition at line 58 of file pbx_switch.c.

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

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

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

4208 {
4209  return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_SPAWN, found, combined_find_spawn);
4210 }
@ E_SPAWN
Definition: extconf.h:220

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

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

◆ ast_str_get_hint()

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

If an extension hint exists, return non-zero.

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

If an extension hint exists, return non-zero.

Definition at line 4162 of file pbx.c.

4163 {
4164  struct ast_exten *e = ast_hint_extension(c, context, exten);
4165 
4166  if (!e) {
4167  return 0;
4168  }
4169 
4170  if (hint) {
4171  ast_str_set(hint, hintsize, "%s", ast_get_extension_app(e));
4172  }
4173  if (name) {
4174  const char *tmp = ast_get_extension_app_data(e);
4175  if (tmp) {
4176  ast_str_set(name, namesize, "%s", tmp);
4177  }
4178  }
4179  return -1;
4180 }
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:1091

References ast_get_extension_app(), ast_get_extension_app_data(), ast_hint_extension(), ast_str_set(), c, context, exten, name, and tmp().

Referenced by ast_str_retrieve_variable().

◆ ast_str_retrieve_variable()

const char* ast_str_retrieve_variable ( struct ast_str **  buf,
ssize_t  maxlen,
struct ast_channel chan,
struct varshead headp,
const char *  var 
)
Parameters
bufResult will be placed in this buffer.
maxlen-1 if the buffer should not grow, 0 if the buffer may grow to any size, and >0 if the buffer should grow only to that number of bytes.
chanChannel variables from which to extract values, and channel to pass to any dialplan functions.
headpIf no channel is specified, a channel list from which to extract variable values
varVariable name to retrieve.

Definition at line 247 of file pbx_variables.c.

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

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

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

◆ ast_str_substitute_variables()

void ast_str_substitute_variables ( struct ast_str **  buf,
ssize_t  maxlen,
struct ast_channel chan,
const char *  templ 
)
Parameters
bufResult will be placed in this buffer.
maxlen-1 if the buffer should not grow, 0 if the buffer may grow to any size, and >0 if the buffer should grow only to that number of bytes.
chanChannel variables from which to extract values, and channel to pass to any dialplan functions.
templVariable template to expand.

Definition at line 619 of file pbx_variables.c.

620 {
621  ast_str_substitute_variables_full(buf, maxlen, chan, NULL, templ, NULL);
622 }
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
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)

References ast_str_substitute_variables_full(), buf, and NULL.

Referenced by _macro_exec(), acf_odbc_read(), acf_odbc_write(), AST_TEST_DEFINE(), cli_odbc_read(), config_curl(), custom_log(), cut_internal(), destroy_curl(), do_notify(), exec_exec(), func_mchan_read(), 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(), store_curl(), strbetween(), strreplace(), test_2way_function(), tryexec_exec(), update2_curl(), and update_curl().

◆ ast_str_substitute_variables_full()

void ast_str_substitute_variables_full ( struct ast_str **  buf,
ssize_t  maxlen,
struct ast_channel c,
struct varshead headp,
const char *  templ,
size_t *  used 
)
Parameters
bufResult will be placed in this buffer.
maxlen-1 if the buffer should not grow, 0 if the buffer may grow to any size, and >0 if the buffer should grow only to that number of bytes.
cChannel variables from which to extract values, and channel to pass to any dialplan functions.
headpIf no channel is specified, a channel list from which to extract variable values
templVariable template to expand.
usedNumber of bytes read from the template. (May be NULL)

Definition at line 397 of file pbx_variables.c.

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

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

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

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

625 {
626  ast_str_substitute_variables_full(buf, maxlen, NULL, headp, templ, NULL);
627 }

References ast_str_substitute_variables_full(), buf, and NULL.

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

◆ ast_thread_inhibit_escalations()

int ast_thread_inhibit_escalations ( void  )

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

Returns
0 if successfuly marked current thread.
Non-zero if marking current thread failed.

Definition at line 479 of file pbx_functions.c.

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 }
static struct ast_threadstorage thread_inhibit_escalations_tl
Definition: pbx_functions.c:46
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.

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

Referenced by handle_tcptls_connection().

◆ ast_thread_inhibit_escalations_swap()

int ast_thread_inhibit_escalations_swap ( int  inhibit)

Swap the current thread escalation inhibit setting.

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

Definition at line 494 of file pbx_functions.c.

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 }

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

◆ ast_unlock_context()

int ast_unlock_context ( struct ast_context con)

◆ ast_unlock_contexts()

int ast_unlock_contexts ( void  )

◆ ast_unregister_switch()

void ast_unregister_switch ( struct ast_switch sw)

Unregister an alternative switch.

Parameters
swswitch to unregister

Unregisters a switch from asterisk.

Definition at line 76 of file pbx_switch.c.

77 {
79  AST_RWLIST_REMOVE(&switches, sw, list);
81 }

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

Referenced by __unload_module(), and unload_module().

◆ ast_walk_context_extensions()

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

◆ ast_walk_context_ignorepats()

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

◆ ast_walk_context_includes()

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

Referenced by context_included().

◆ ast_walk_context_switches()

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

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

4064 {
4065  return priority ? priority->peer : exten;
4066 }

References exten, and priority.

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

◆ 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

Referenced by add_hints(), ast_context_remove_extension_callerid2(), ast_context_remove_include2(), ast_context_remove_switch2(), parking_duration_callback(), and parking_lot_cfg_create_extensions().

◆ ast_wrlock_contexts()

int ast_wrlock_contexts ( void  )

Write locks the context list.

Return values
0on success
-1on error

Referenced by add_hints(), complete_dialplan_remove_include(), manager_dialplan_extension_add(), parking_duration_callback(), and parking_lot_cfg_create_extensions().

◆ pbx_builtin_clear_globals()

void pbx_builtin_clear_globals ( void  )

Definition at line 1257 of file pbx_variables.c.

1258 {
1259  struct ast_var_t *vardata;
1260 
1262  while ((vardata = AST_LIST_REMOVE_HEAD(&globals, entries)))
1263  ast_var_delete(vardata);
1265 }
void ast_var_delete(struct ast_var_t *var)
Definition: extconf.c:2472
#define ast_rwlock_wrlock(a)
Definition: lock.h:234

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

Referenced by unload_pbx_variables().

◆ pbx_builtin_getvar_helper()

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

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

Note
Will lock the channel.
This function will return a pointer to the buffer inside the channel variable. This value should only be accessed with the channel locked. If the value needs to be kept around, it should be done by using the following thread-safe code:
const char *var;
if ((var = pbx_builtin_getvar_helper(chan, "MYVAR"))) {
}
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.

Definition at line 1066 of file pbx_variables.c.

1067 {
1068  struct ast_var_t *variables;
1069  const char *ret = NULL;
1070  int i;
1071  struct varshead *places[2] = { NULL, &globals };
1072 
1073  if (!name)
1074  return NULL;
1075 
1076  if (chan) {
1077  ast_channel_lock(chan);
1078  places[0] = ast_channel_varshead(chan);
1079  }
1080 
1081  for (i = 0; i < 2; i++) {
1082  if (!places[i])
1083  continue;
1084  if (places[i] == &globals)
1086  AST_LIST_TRAVERSE(places[i], variables, entries) {
1087  if (!strcmp(name, ast_var_name(variables))) {
1088  ret = ast_var_value(variables);
1089  break;
1090  }
1091  }
1092  if (places[i] == &globals)
1094  if (ret)
1095  break;
1096  }
1097 
1098  if (chan)
1099  ast_channel_unlock(chan);
1100 
1101  return ret;
1102 }

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

Referenced by _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(), analog_call(), array(), ast_bridge_timelimit(), 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(), 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(),