Wed Jan 8 2020 09:50:16

Asterisk developer's documentation


pbx.h File Reference

Core PBX routines and definitions. More...

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_pbx
 
struct  ast_pbx_args
 Options for ast_pbx_run() More...
 
struct  ast_switch
 
struct  ast_timing
 
struct  pbx_find_info
 

Macros

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

Typedefs

typedef void(* ast_state_cb_destroy_type )(int id, void *data)
 Typedef for devicestate and hint callback removal indication callback. More...
 
typedef int(* ast_state_cb_type )(char *context, char *id, enum ast_extension_states state, 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
}
 Extension states. More...
 
enum  ast_pbx_result { AST_PBX_SUCCESS = 0, AST_PBX_FAILED = -1, AST_PBX_CALL_LIMIT = -2 }
 The result codes when starting the PBX on a channel with ast_pbx_start. More...
 
enum  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)
 Add an extension to an extension context, this time with an ast_context *. More...
 
int ast_async_goto (struct ast_channel *chan, const char *context, const char *exten, int priority)
 Set the channel to next execute the specified dialplan location. More...
 
int ast_async_goto_by_name (const char *chan, const char *context, const char *exten, int priority)
 Set the channel to next execute the specified dialplan location. More...
 
int ast_async_goto_if_exists (struct ast_channel *chan, const char *context, const char *exten, int priority)
 
int ast_async_parseable_goto (struct ast_channel *chan, const char *goto_string)
 
int ast_build_timing (struct ast_timing *i, const char *info)
 Construct a timing bitmap, for use in time-based conditionals. More...
 
int ast_canmatch_extension (struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
 Looks for a valid matching extension. More...
 
int ast_check_timing (const struct ast_timing *i)
 Evaluate a pre-constructed bitmap as to whether the current time falls within the range specified. More...
 
int ast_check_timing2 (const struct ast_timing *i, const struct timeval tv)
 Evaluate a pre-constructed bitmap as to whether a particular time falls within the range specified. More...
 
char * ast_complete_applications (const char *line, const char *word, int state)
 Command completion for the list of installed applications. More...
 
int ast_context_add_ignorepat (const char *context, const char *ignorepat, const char *registrar)
 Add an ignorepat. More...
 
int ast_context_add_ignorepat2 (struct ast_context *con, const char *ignorepat, const char *registrar)
 
int ast_context_add_include (const char *context, const char *include, const char *registrar)
 Add a context include. More...
 
int ast_context_add_include2 (struct ast_context *con, const char *include, const char *registrar)
 Add a context include. More...
 
int ast_context_add_switch (const char *context, const char *sw, const char *data, int eval, const char *registrar)
 Add a switch. More...
 
int ast_context_add_switch2 (struct ast_context *con, const char *sw, const char *data, int eval, const char *registrar)
 Adds a switch (first param is a ast_context) More...
 
void ast_context_destroy (struct ast_context *con, const char *registrar)
 Destroy a context (matches the specified context (or ANY context if NULL) More...
 
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 given context More...
 
int ast_context_remove_ignorepat (const char *context, const char *ignorepat, const char *registrar)
 
int ast_context_remove_ignorepat2 (struct ast_context *con, const char *ignorepat, const char *registrar)
 
int ast_context_remove_include (const char *context, const char *include, const char *registrar)
 Remove a context include. More...
 
int ast_context_remove_include2 (struct ast_context *con, const char *include, const char *registrar)
 Removes an include by an ast_context structure. More...
 
int ast_context_remove_switch (const char *context, const char *sw, const char *data, const char *registrar)
 Remove a switch. More...
 
int ast_context_remove_switch2 (struct ast_context *con, const char *sw, const char *data, const char *registrar)
 This function locks given context, removes switch, unlock context and return. More...
 
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)
 Registers a state change callback. 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)
 Registers a state change callback with destructor. More...
 
int ast_extension_state_del (int id, ast_state_cb_type change_cb)
 Deletes a registered state change callback by ID. 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...
 
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_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)
 
int ast_pbx_outgoing_app (const char *type, format_t format, void *data, int timeout, const char *app, const char *appdata, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel)
 
int ast_pbx_outgoing_exten (const char *type, format_t format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel)
 
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_unlock_context (struct ast_context *con)
 
int ast_unlock_contexts (void)
 Unlocks contexts. More...
 
void ast_unregister_switch (struct ast_switch *sw)
 Unregister an alternative switch. More...
 
int ast_wrlock_context (struct ast_context *con)
 Write locks a given context. More...
 
int ast_wrlock_contexts (void)
 Write locks the context list. More...
 
void pbx_builtin_clear_globals (void)
 
const char * pbx_builtin_getvar_helper (struct ast_channel *chan, const char *name)
 Return a pointer to the value of the corresponding channel variable. More...
 
void pbx_builtin_pushvar_helper (struct ast_channel *chan, const char *name, const char *value)
 Add a variable to the channel variable stack, without removing any previously set value. More...
 
int pbx_builtin_raise_exception (struct ast_channel *chan, const char *data)
 
int pbx_builtin_serialize_variables (struct ast_channel *chan, struct ast_str **buf)
 Create a human-readable string, specifying all variables and their corresponding values. More...
 
int pbx_builtin_setvar (struct ast_channel *chan, const char *data)
 Parse and set a single channel variable, where the name and value are separated with an '=' character. More...
 
int pbx_builtin_setvar_helper (struct ast_channel *chan, const char *name, const char *value)
 Add a variable to the channel variable stack, removing the most recently set value for the same name. More...
 
int pbx_builtin_setvar_multiple (struct ast_channel *chan, const char *data)
 Parse and set multiple channel variables, where the pairs are separated by the ',' character, and name and value are separated with an '=' character. More...
 
int pbx_checkcondition (const char *condition)
 Evaluate a condition. More...
 
int pbx_exec (struct ast_channel *c, struct ast_app *app, const char *data)
 Execute an application. More...
 
struct ast_extenpbx_find_extension (struct ast_channel *chan, struct ast_context *bypass, struct pbx_find_info *q, const char *context, const char *exten, int priority, const char *label, const char *callerid, enum ext_match_t action)
 
struct ast_apppbx_findapp (const char *app)
 Look up an application. More...
 
void pbx_live_dangerously (int new_live_dangerously)
 Enable/disable the execution of 'dangerous' functions from external protocols (AMI, etc.). More...
 
void pbx_retrieve_variable (struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp)
 Retrieve the value of a builtin variable or variable from the channel variable stack. More...
 
int pbx_set_autofallthrough (int newval)
 
int pbx_set_extenpatternmatchnew (int newval)
 
void pbx_set_overrideswitch (const char *newval)
 
int ast_context_remove_extension (const char *context, const char *extension, int priority, const char *registrar)
 Simply remove extension from context. More...
 
int ast_context_remove_extension2 (struct ast_context *con, const char *extension, int priority, const char *registrar, int already_locked)
 This functionc locks given context, search for the right extension and fires out all peer in this extensions with given priority. If priority is set to 0, all peers are removed. After that, unlock context and return. More...
 
int ast_context_remove_extension_callerid (const char *context, const char *extension, int priority, const char *callerid, int matchcid, const char *registrar)
 
int ast_context_remove_extension_callerid2 (struct ast_context *con, const char *extension, int priority, const char *callerid, int matchcid, const char *registrar, int already_locked)
 

Functions for returning values from structures

const char * ast_get_context_name (struct ast_context *con)
 
const char * ast_get_extension_name (struct ast_exten *exten)
 
struct ast_contextast_get_extension_context (struct ast_exten *exten)
 
const char * ast_get_include_name (struct ast_include *include)
 
const char * ast_get_ignorepat_name (struct ast_ignorepat *ip)
 
const char * ast_get_switch_name (struct ast_sw *sw)
 
const char * ast_get_switch_data (struct ast_sw *sw)
 
int ast_get_switch_eval (struct ast_sw *sw)
 
Other Extension stuff
int ast_get_extension_priority (struct ast_exten *exten)
 
int ast_get_extension_matchcid (struct ast_exten *e)
 
const char * ast_get_extension_cidmatch (struct ast_exten *e)
 
const char * ast_get_extension_app (struct ast_exten *e)
 
const char * ast_get_extension_label (struct ast_exten *e)
 
void * ast_get_extension_app_data (struct ast_exten *e)
 
Registrar info functions ...
const char * ast_get_context_registrar (struct ast_context *c)
 
const char * ast_get_extension_registrar (struct ast_exten *e)
 
const char * ast_get_include_registrar (struct ast_include *i)
 
const char * ast_get_ignorepat_registrar (struct ast_ignorepat *ip)
 
const char * ast_get_switch_registrar (struct ast_sw *sw)
 
Walking functions ...
struct ast_contextast_walk_contexts (struct ast_context *con)
 
struct ast_extenast_walk_context_extensions (struct ast_context *con, struct ast_exten *priority)
 
struct ast_extenast_walk_extension_priorities (struct ast_exten *exten, struct ast_exten *priority)
 
struct ast_includeast_walk_context_includes (struct ast_context *con, struct ast_include *inc)
 
struct ast_ignorepatast_walk_context_ignorepats (struct ast_context *con, struct ast_ignorepat *ip)
 
struct ast_swast_walk_context_switches (struct ast_context *con, struct ast_sw *sw)
 
Substitution routines, using static string buffers
void pbx_substitute_variables_helper (struct ast_channel *c, const char *cp1, char *cp2, int count)
 
void pbx_substitute_variables_varshead (struct varshead *headp, const char *cp1, char *cp2, int count)
 
void pbx_substitute_variables_helper_full (struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int cp2_size, size_t *used)
 
Substitution routines, using dynamic string buffers
const char * ast_str_retrieve_variable (struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, struct varshead *headp, const char *var)
 
void ast_str_substitute_variables (struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ)
 
void ast_str_substitute_variables_varshead (struct ast_str **buf, ssize_t maxlen, struct varshead *headp, const char *templ)
 
void ast_str_substitute_variables_full (struct ast_str **buf, ssize_t maxlen, struct ast_channel *c, struct varshead *headp, const char *templ, size_t *used)
 
int ast_hashtab_compare_contexts (const void *ah_a, const void *ah_b)
 hashtable functions for contexts More...
 
unsigned int ast_hashtab_hash_contexts (const void *obj)
 

Detailed Description

Core PBX routines and definitions.

Definition in file pbx.h.

Macro Definition Documentation

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

Register a custom function.

Definition at line 1164 of file pbx.h.

Referenced by load_module(), and reload().

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

Register a custom function which requires escalated privileges.

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

Definition at line 1173 of file pbx.h.

Referenced by load_module().

#define AST_MAX_APP   32

Max length of an application

Definition at line 39 of file pbx.h.

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

#define AST_PBX_ERROR   1

Jump to the 'e' exten

Definition at line 49 of file pbx.h.

Referenced by __ast_pbx_run().

#define AST_PBX_GOTO_FAILED   -3

Definition at line 41 of file pbx.h.

Referenced by __ast_goto_if_exists().

#define AST_PBX_HANGUP   -1

Special return values from applications to the PBX.

Jump to the 'h' exten

Definition at line 47 of file pbx.h.

#define AST_PBX_INCOMPLETE   12

Return to PBX matching, allowing more digits for the extension

Definition at line 50 of file pbx.h.

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

#define AST_PBX_KEEP   0

Definition at line 42 of file pbx.h.

#define AST_PBX_MAX_STACK   128

Definition at line 1265 of file pbx.h.

#define AST_PBX_OK   0

No errors

Definition at line 48 of file pbx.h.

#define AST_PBX_REPLACE   1

Definition at line 43 of file pbx.h.

#define STATUS_NO_CONTEXT   1

Definition at line 1260 of file pbx.h.

#define STATUS_NO_EXTENSION   2

Definition at line 1261 of file pbx.h.

#define STATUS_NO_LABEL   4

Definition at line 1263 of file pbx.h.

#define STATUS_NO_PRIORITY   3

Definition at line 1262 of file pbx.h.

#define STATUS_SUCCESS   5

Definition at line 1264 of file pbx.h.

Typedef Documentation

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

Typedef for devicestate and hint callback removal indication callback.

Definition at line 92 of file pbx.h.

typedef int(* ast_state_cb_type)(char *context, char *id, enum ast_extension_states state, void *data)

Typedef for devicestate and hint callbacks.

Definition at line 89 of file pbx.h.

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

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

Data structure associated with an Asterisk switch

Definition at line 124 of file pbx.h.

Enumeration Type Documentation

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

Enumerator
AST_CFE_NONE 
AST_CFE_READ 
AST_CFE_WRITE 
AST_CFE_BOTH 

Definition at line 1154 of file pbx.h.

1154  {
1155  AST_CFE_NONE,
1156  AST_CFE_READ,
1157  AST_CFE_WRITE,
1158  AST_CFE_BOTH,
1159 };

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

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

Extension states.

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

Extension removed

AST_EXTENSION_DEACTIVATED 

Extension hint removed

AST_EXTENSION_NOT_INUSE 

No device INUSE or BUSY

AST_EXTENSION_INUSE 

One or more devices INUSE

AST_EXTENSION_BUSY 

All devices BUSY

AST_EXTENSION_UNAVAILABLE 

All devices UNAVAILABLE/UNREGISTERED

AST_EXTENSION_RINGING 

All devices RINGING

AST_EXTENSION_ONHOLD 

All devices ONHOLD

Definition at line 60 of file pbx.h.

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

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

299  {
300  AST_PBX_SUCCESS = 0,
301  AST_PBX_FAILED = -1,
302  AST_PBX_CALL_LIMIT = -2,
303 };

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

1251  {
1252  E_MATCHMORE = 0x00, /* extension can match but only with more 'digits' */
1253  E_CANMATCH = 0x01, /* extension can match with or without more 'digits' */
1254  E_MATCH = 0x02, /* extension is an exact match */
1255  E_MATCH_MASK = 0x03, /* mask for the argument to extension_match_core() */
1256  E_SPAWN = 0x12, /* want to spawn an extension. Requires exact match */
1257  E_FINDLABEL = 0x22 /* returns the priority for a given label. Requires exact match */
1258 };

Function Documentation

int __ast_custom_function_register ( struct ast_custom_function acf,
struct ast_module mod 
)

Register a custom function.

Definition at line 3946 of file pbx.c.

References acf_retrieve_docs(), ast_log(), AST_RWLIST_INSERT_BEFORE_CURRENT, AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, AST_STATIC_DOC, ast_verb, COLOR_BRCYAN, ast_custom_function::docsrc, LOG_ERROR, ast_custom_function::mod, ast_custom_function::name, and term_color().

Referenced by __ast_custom_function_register_escalating(), and load_pbx().

3947 {
3948  struct ast_custom_function *cur;
3949  char tmps[80];
3950 
3951  if (!acf) {
3952  return -1;
3953  }
3954 
3955  acf->mod = mod;
3956 #ifdef AST_XML_DOCS
3957  acf->docsrc = AST_STATIC_DOC;
3958 #endif
3959 
3960  if (acf_retrieve_docs(acf)) {
3961  return -1;
3962  }
3963 
3965 
3966  AST_RWLIST_TRAVERSE(&acf_root, cur, acflist) {
3967  if (!strcmp(acf->name, cur->name)) {
3968  ast_log(LOG_ERROR, "Function %s already registered.\n", acf->name);
3970  return -1;
3971  }
3972  }
3973 
3974  /* Store in alphabetical order */
3975  AST_RWLIST_TRAVERSE_SAFE_BEGIN(&acf_root, cur, acflist) {
3976  if (strcasecmp(acf->name, cur->name) < 0) {
3977  AST_RWLIST_INSERT_BEFORE_CURRENT(acf, acflist);
3978  break;
3979  }
3980  }
3982 
3983  if (!cur) {
3984  AST_RWLIST_INSERT_TAIL(&acf_root, acf, acflist);
3985  }
3986 
3988 
3989  ast_verb(2, "Registered custom function '%s'\n", term_color(tmps, acf->name, COLOR_BRCYAN, 0, sizeof(tmps)));
3990 
3991  return 0;
3992 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
enum ast_doc_src docsrc
Definition: pbx.h:104
struct ast_module * mod
Definition: pbx.h:119
static int acf_retrieve_docs(struct ast_custom_function *acf)
Definition: pbx.c:3901
#define ast_verb(level,...)
Definition: logger.h:243
#define COLOR_BRCYAN
Definition: term.h:60
Data structure associated with a custom dialplan function.
Definition: pbx.h:95
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
Definition: pbx.c:1231
#define AST_RWLIST_INSERT_BEFORE_CURRENT
Definition: linkedlists.h:595
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:542
char * term_color(char *outbuf, const char *inbuf, int fgcolor, int bgcolor, int maxout)
Definition: term.c:184
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:726
const char * name
Definition: pbx.h:96
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:602
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 3994 of file pbx.c.

References __ast_custom_function_register(), ast_calloc, AST_CFE_BOTH, AST_CFE_NONE, AST_CFE_READ, AST_CFE_WRITE, ast_custom_function_unregister(), AST_RWLIST_INSERT_TAIL, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

3995 {
3996  struct ast_custom_escalating_function *acf_escalation = NULL;
3997  int res;
3998 
3999  res = __ast_custom_function_register(acf, mod);
4000  if (res != 0) {
4001  return -1;
4002  }
4003 
4004  if (escalation == AST_CFE_NONE) {
4005  /* No escalations; no need to do anything else */
4006  return 0;
4007  }
4008 
4009  acf_escalation = ast_calloc(1, sizeof(*acf_escalation));
4010  if (!acf_escalation) {
4012  return -1;
4013  }
4014 
4015  acf_escalation->acf = acf;
4016  switch (escalation) {
4017  case AST_CFE_NONE:
4018  break;
4019  case AST_CFE_READ:
4020  acf_escalation->read_escalates = 1;
4021  break;
4022  case AST_CFE_WRITE:
4023  acf_escalation->write_escalates = 1;
4024  break;
4025  case AST_CFE_BOTH:
4026  acf_escalation->read_escalates = 1;
4027  acf_escalation->write_escalates = 1;
4028  break;
4029  }
4030 
4032  AST_RWLIST_INSERT_TAIL(&escalation_root, acf_escalation, list);
4034 
4035  return 0;
4036 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:726
#define ast_calloc(a, b)
Definition: astmm.h:82
Extra information for an ast_custom_function holding privilege escalation information. Kept in a separate structure for ABI compatibility.
Definition: pbx.c:1237
int __ast_custom_function_register(struct ast_custom_function *acf, struct ast_module *mod)
Register a custom function.
Definition: pbx.c:3946
int ast_active_calls ( void  )

Retrieve the number of active calls.

Definition at line 5931 of file pbx.c.

References countcalls.

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

5932 {
5933  return countcalls;
5934 }
static int countcalls
Definition: pbx.c:1228
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
datad
registrarwho registered the extension
Return values
0success
-1failure

Definition at line 8691 of file pbx.c.

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

Referenced by ast_extension_state(), ast_extension_state_add_destroy(), handle_cli_dialplan_add_extension(), manage_parked_call(), park_add_hints(), park_call_full(), parkinglot_activate(), register_exten(), register_peer_exten(), and RegisterExtension().

8694 {
8695  int ret = -1;
8696  struct ast_context *c;
8697 
8699  if (c) {
8700  ret = ast_add_extension2(c, replace, extension, priority, label, callerid,
8701  application, data, datad, registrar);
8703  }
8704 
8705  return ret;
8706 }
int ast_add_extension2(struct ast_context *con, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar)
Add an extension to an extension context, this time with an ast_context *.
Definition: pbx.c:9052
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:11047
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:5985
static char * registrar
Definition: features.c:623
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
Definition: func_strings.c:775
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
ast_context: An extension context
Definition: pbx.c:955
int ast_add_extension2 ( struct ast_context con,
int  replace,
const char *  extension,
int  priority,
const char *  label,
const char *  callerid,
const char *  application,
void *  data,
void(*)(void *)  datad,
const char *  registrar 
)

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

Note
For details about the arguments, check ast_add_extension()

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

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

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

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

Definition at line 9052 of file pbx.c.

References ast_add_extension2_lockopt().

Referenced by add_extensions(), ast_add_extension(), context_merge(), load_module(), pbx_load_config(), pbx_load_users(), sla_build_station(), and sla_build_trunk().

9056 {
9057  return ast_add_extension2_lockopt(con, replace, extension, priority, label, callerid,
9058  application, data, datad, registrar, 1);
9059 }
static int ast_add_extension2_lockopt(struct ast_context *con, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar, int lock_context)
Same as ast_add_extension2() but controls the context locking.
Definition: pbx.c:9068
static char * registrar
Definition: features.c:623
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
Definition: func_strings.c:775
int ast_async_goto ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority 
)

Set the channel to next execute the specified dialplan location.

See Also
ast_async_parseable_goto, ast_async_goto_if_exists
Note
Do NOT hold any channel locks when calling this function.

Definition at line 8731 of file pbx.c.

References ast_channel::_state, accountcode, ast_channel::accountcode, amaflags, ast_channel::amaflags, ast_cdr_discard(), ast_cdr_dup(), ast_channel_alloc(), ast_channel_lock, ast_channel_masquerade(), ast_channel_unlock, ast_do_masquerade(), ast_explicit_goto(), ast_hangup(), ast_log(), ast_pbx_start(), AST_SOFTHANGUP_ASYNCGOTO, ast_softhangup_nolock(), ast_strdupa, ast_channel::cdr, context, ast_channel::context, exten, ast_channel::exten, ast_channel::linkedid, LOG_WARNING, ast_channel::name, ast_sw::name, ast_channel::pbx, ast_channel::readformat, S_OR, state, and ast_channel::writeformat.

Referenced by __ast_goto_if_exists(), action_redirect(), ast_async_goto_by_name(), builtin_blindtransfer(), console_transfer(), dahdi_handle_dtmf(), handle_request_bye(), handle_request_refer(), my_handle_dtmf(), pbx_parseable_goto(), process_ast_dsp(), process_sdp(), sip_read(), and socket_process().

8732 {
8733  int res = 0;
8734  struct ast_channel *tmpchan;
8735  struct {
8736  char *accountcode;
8737  char *exten;
8738  char *context;
8739  char *linkedid;
8740  char *name;
8741  struct ast_cdr *cdr;
8742  int amaflags;
8743  int state;
8746  } tmpvars = { 0, };
8747 
8748  ast_channel_lock(chan);
8749  if (chan->pbx) { /* This channel is currently in the PBX */
8750  ast_explicit_goto(chan, context, exten, priority + 1);
8752  ast_channel_unlock(chan);
8753  return res;
8754  }
8755 
8756  /* In order to do it when the channel doesn't really exist within
8757  * the PBX, we have to make a new channel, masquerade, and start the PBX
8758  * at the new location */
8759  tmpvars.accountcode = ast_strdupa(chan->accountcode);
8760  tmpvars.exten = ast_strdupa(chan->exten);
8761  tmpvars.context = ast_strdupa(chan->context);
8762  tmpvars.linkedid = ast_strdupa(chan->linkedid);
8763  tmpvars.name = ast_strdupa(chan->name);
8764  tmpvars.amaflags = chan->amaflags;
8765  tmpvars.state = chan->_state;
8766  tmpvars.writeformat = chan->writeformat;
8767  tmpvars.readformat = chan->readformat;
8768  tmpvars.cdr = chan->cdr ? ast_cdr_dup(chan->cdr) : NULL;
8769 
8770  ast_channel_unlock(chan);
8771 
8772  /* Do not hold any channel locks while calling channel_alloc() since the function
8773  * locks the channel container when linking the new channel in. */
8774  if (!(tmpchan = ast_channel_alloc(0, tmpvars.state, 0, 0, tmpvars.accountcode, tmpvars.exten, tmpvars.context, tmpvars.linkedid, tmpvars.amaflags, "AsyncGoto/%s", tmpvars.name))) {
8775  ast_cdr_discard(tmpvars.cdr);
8776  return -1;
8777  }
8778 
8779  /* copy the cdr info over */
8780  if (tmpvars.cdr) {
8781  ast_cdr_discard(tmpchan->cdr);
8782  tmpchan->cdr = tmpvars.cdr;
8783  tmpvars.cdr = NULL;
8784  }
8785 
8786  /* Make formats okay */
8787  tmpchan->readformat = tmpvars.readformat;
8788  tmpchan->writeformat = tmpvars.writeformat;
8789 
8790  /* Setup proper location. Never hold another channel lock while calling this function. */
8791  ast_explicit_goto(tmpchan, S_OR(context, tmpvars.context), S_OR(exten, tmpvars.exten), priority);
8792 
8793  /* Masquerade into tmp channel */
8794  if (ast_channel_masquerade(tmpchan, chan)) {
8795  /* Failed to set up the masquerade. It's probably chan_local
8796  * in the middle of optimizing itself out. Sad. :( */
8797  ast_hangup(tmpchan);
8798  tmpchan = NULL;
8799  res = -1;
8800  } else {
8801  ast_do_masquerade(tmpchan);
8802  /* Start the PBX going on our stolen channel */
8803  if (ast_pbx_start(tmpchan)) {
8804  ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmpchan->name);
8805  ast_hangup(tmpchan);
8806  res = -1;
8807  }
8808  }
8809 
8810  return res;
8811 }
int ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2804
enum sip_cc_notify_state state
Definition: chan_sip.c:842
#define ast_channel_lock(chan)
Definition: channel.h:2466
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
Main Channel structure associated with a channel.
Definition: channel.h:742
int ast_channel_masquerade(struct ast_channel *original, struct ast_channel *clone)
Weird function made for call transfers.
Definition: channel.c:6110
format_t writeformat
Definition: channel.h:854
char context[AST_MAX_CONTEXT]
Definition: channel.h:868
#define LOG_WARNING
Definition: logger.h:144
enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
Create a new thread and start the PBX.
Definition: pbx.c:5879
struct ast_cdr * ast_cdr_dup(struct ast_cdr *cdr)
Duplicate a record.
Definition: cdr.c:213
int ast_explicit_goto(struct ast_channel *chan, const char *context, const char *exten, int priority)
Definition: pbx.c:8708
struct ast_cdr * cdr
Definition: channel.h:766
const ast_string_field linkedid
Definition: channel.h:787
struct ast_channel * ast_channel_alloc(int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const char *linkedid, const int amaflag, const char *name_fmt,...)
Definition: channel.c:9825
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
Responsible for call detail data.
Definition: cdr.h:82
int64_t format_t
Definition: frame_defs.h:32
enum ast_channel_state _state
Definition: channel.h:839
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
int ast_softhangup_nolock(struct ast_channel *chan, int reason)
Softly hangup up a channel (no channel lock)
Definition: channel.c:2733
#define ast_channel_unlock(chan)
Definition: channel.h:2467
void ast_cdr_discard(struct ast_cdr *cdr)
Discard and free a CDR record.
Definition: cdr.c:488
format_t readformat
Definition: channel.h:853
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
const ast_string_field accountcode
Definition: channel.h:787
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
int amaflags
Definition: channel.h:843
int ast_do_masquerade(struct ast_channel *chan)
Start masquerading a channel.
Definition: channel.c:6546
char exten[AST_MAX_EXTENSION]
Definition: channel.h:869
struct ast_pbx * pbx
Definition: channel.h:761
int ast_async_goto_by_name ( const char *  chan,
const char *  context,
const char *  exten,
int  priority 
)

Set the channel to next execute the specified dialplan location.

Definition at line 8813 of file pbx.c.

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

8814 {
8815  struct ast_channel *chan;
8816  int res = -1;
8817 
8818  if ((chan = ast_channel_get_by_name(channame))) {
8819  res = ast_async_goto(chan, context, exten, priority);
8820  chan = ast_channel_unref(chan);
8821  }
8822 
8823  return res;
8824 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
Main Channel structure associated with a channel.
Definition: channel.h:742
int priority
Definition: channel.h:841
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2502
int ast_async_goto(struct ast_channel *chan, const char *context, const char *exten, int priority)
Set the channel to next execute the specified dialplan location.
Definition: pbx.c:8731
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1803
int ast_async_goto_if_exists ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority 
)
Note
This function will handle locking the channel as needed.

Definition at line 11266 of file pbx.c.

References __ast_goto_if_exists().

11267 {
11268  return __ast_goto_if_exists(chan, context, exten, priority, 1);
11269 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
static int __ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, int async)
Definition: pbx.c:11240
int priority
Definition: channel.h:841
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
int ast_async_parseable_goto ( struct ast_channel chan,
const char *  goto_string 
)
Note
This function will handle locking the channel as needed.

Definition at line 11331 of file pbx.c.

References pbx_parseable_goto().

Referenced by asyncgoto_exec(), and handle_redirect().

11332 {
11333  return pbx_parseable_goto(chan, goto_string, 1);
11334 }
static int pbx_parseable_goto(struct ast_channel *chan, const char *goto_string, int async)
Definition: pbx.c:11271
int ast_build_timing ( struct ast_timing i,
const char *  info 
)

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

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

Definition at line 8314 of file pbx.c.

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

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

8315 {
8316  char *info;
8317  int j, num_fields, last_sep = -1;
8318 
8319  i->timezone = NULL;
8320 
8321  /* Check for empty just in case */
8322  if (ast_strlen_zero(info_in)) {
8323  return 0;
8324  }
8325 
8326  /* make a copy just in case we were passed a static string */
8327  info = ast_strdupa(info_in);
8328 
8329  /* count the number of fields in the timespec */
8330  for (j = 0, num_fields = 1; info[j] != '\0'; j++) {
8331  if (info[j] == ',') {
8332  last_sep = j;
8333  num_fields++;
8334  }
8335  }
8336 
8337  /* save the timezone, if it is specified */
8338  if (num_fields == 5) {
8339  i->timezone = ast_strdup(info + last_sep + 1);
8340  }
8341 
8342  /* Assume everything except time */
8343  i->monthmask = 0xfff; /* 12 bits */
8344  i->daymask = 0x7fffffffU; /* 31 bits */
8345  i->dowmask = 0x7f; /* 7 bits */
8346  /* on each call, use strsep() to move info to the next argument */
8347  get_timerange(i, strsep(&info, "|,"));
8348  if (info)
8349  i->dowmask = get_range(strsep(&info, "|,"), 7, days, "day of week");
8350  if (info)
8351  i->daymask = get_range(strsep(&info, "|,"), 31, NULL, "day");
8352  if (info)
8353  i->monthmask = get_range(strsep(&info, "|,"), 12, months, "month");
8354  return 1;
8355 }
unsigned int daymask
Definition: pbx.h:142
char * strsep(char **str, const char *delims)
#define ast_strdup(a)
Definition: astmm.h:109
unsigned int monthmask
Definition: pbx.h:141
char * timezone
Definition: pbx.h:145
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
static const char *const months[]
Definition: pbx.c:8297
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
unsigned int dowmask
Definition: pbx.h:143
static const char *const days[]
Definition: pbx.c:8285
static unsigned get_range(char *src, int max, const char *const names[], const char *msg)
helper function to return a range up to max (7, 12, 31 respectively). names, if supplied, is an array of names that should be mapped to numbers.
Definition: pbx.c:8182
static void get_timerange(struct ast_timing *i, char *times)
store a bitmask of valid times, one bit each 1 minute
Definition: pbx.c:8225
int ast_canmatch_extension ( struct ast_channel c,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid 
)

Looks for a valid matching extension.

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

Definition at line 5415 of file pbx.c.

References E_CANMATCH, and pbx_extension_helper().

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

5416 {
5417  return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_CANMATCH, 0, 0);
5418 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
int priority
Definition: channel.h:841
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
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:4706
int ast_check_timing ( const struct ast_timing i)

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

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

Definition at line 8357 of file pbx.c.

References ast_check_timing2(), and ast_tvnow().

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

8358 {
8359  return ast_check_timing2(i, ast_tvnow());
8360 }
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...
Definition: pbx.c:8362
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
int ast_check_timing2 ( const struct ast_timing i,
const struct timeval  tv 
)

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

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

Definition at line 8362 of file pbx.c.

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

Referenced by ast_check_timing(), and pbx_builtin_gotoiftime().

8363 {
8364  struct ast_tm tm;
8365 
8366  ast_localtime(&tv, &tm, i->timezone);
8367 
8368  /* If it's not the right month, return */
8369  if (!(i->monthmask & (1 << tm.tm_mon)))
8370  return 0;
8371 
8372  /* If it's not that time of the month.... */
8373  /* Warning, tm_mday has range 1..31! */
8374  if (!(i->daymask & (1 << (tm.tm_mday-1))))
8375  return 0;
8376 
8377  /* If it's not the right day of the week */
8378  if (!(i->dowmask & (1 << tm.tm_wday)))
8379  return 0;
8380 
8381  /* Sanity check the hour just to be safe */
8382  if ((tm.tm_hour < 0) || (tm.tm_hour > 23)) {
8383  ast_log(LOG_WARNING, "Insane time...\n");
8384  return 0;
8385  }
8386 
8387  /* Now the tough part, we calculate if it fits
8388  in the right time based on min/hour */
8389  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))))
8390  return 0;
8391 
8392  /* If we got this far, then we're good */
8393  return 1;
8394 }
unsigned int daymask
Definition: pbx.h:142
#define LOG_WARNING
Definition: logger.h:144
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:1570
unsigned int monthmask
Definition: pbx.h:141
char * timezone
Definition: pbx.h:145
unsigned int dowmask
Definition: pbx.h:143
unsigned int minmask[48]
Definition: pbx.h:144
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
struct timeval tv
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 11336 of file pbx.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, and ast_strdup.

Referenced by handle_orig(), and handle_show_application().

11337 {
11338  struct ast_app *app = NULL;
11339  int which = 0;
11340  char *ret = NULL;
11341  size_t wordlen = strlen(word);
11342 
11344  AST_RWLIST_TRAVERSE(&apps, app, list) {
11345  if (!strncasecmp(word, app->name, wordlen) && ++which > state) {
11346  ret = ast_strdup(app->name);
11347  break;
11348  }
11349  }
11351 
11352  return ret;
11353 }
#define ast_strdup(a)
Definition: astmm.h:109
Definition: pbx.c:1301
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Definition: ael.tab.c:203
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
static const char app[]
Definition: app_adsiprog.c:49
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
ast_app: A registered application
Definition: pbx.c:971
int ast_context_add_ignorepat ( const char *  context,
const char *  ignorepat,
const char *  registrar 
)

Add an ignorepat.

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

Adds an ignore pattern to a particular context.

Return values
0on success
-1on failure

Definition at line 8598 of file pbx.c.

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

Referenced by handle_cli_dialplan_add_ignorepat().

8599 {
8600  int ret = -1;
8601  struct ast_context *c;
8602 
8604  if (c) {
8607  }
8608  return ret;
8609 }
int value
Definition: syslog.c:39
int ast_context_add_ignorepat2(struct ast_context *con, const char *ignorepat, const char *registrar)
Definition: pbx.c:8611
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:11047
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:5985
static char * registrar
Definition: features.c:623
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
ast_context: An extension context
Definition: pbx.c:955
int ast_context_add_ignorepat2 ( struct ast_context con,
const char *  ignorepat,
const char *  registrar 
)

Definition at line 8611 of file pbx.c.

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

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

8612 {
8613  struct ast_ignorepat *ignorepat, *ignorepatc, *ignorepatl = NULL;
8614  int length;
8615  char *pattern;
8616  length = sizeof(struct ast_ignorepat);
8617  length += strlen(value) + 1;
8618  if (!(ignorepat = ast_calloc(1, length)))
8619  return -1;
8620  /* The cast to char * is because we need to write the initial value.
8621  * The field is not supposed to be modified otherwise. Also, gcc 4.2
8622  * sees the cast as dereferencing a type-punned pointer and warns about
8623  * it. This is the workaround (we're telling gcc, yes, that's really
8624  * what we wanted to do).
8625  */
8626  pattern = (char *) ignorepat->pattern;
8627  strcpy(pattern, value);
8628  ignorepat->next = NULL;
8629  ignorepat->registrar = registrar;
8630  ast_wrlock_context(con);
8631  for (ignorepatc = con->ignorepats; ignorepatc; ignorepatc = ignorepatc->next) {
8632  ignorepatl = ignorepatc;
8633  if (!strcasecmp(ignorepatc->pattern, value)) {
8634  /* Already there */
8635  ast_unlock_context(con);
8636  ast_free(ignorepat);
8637  errno = EEXIST;
8638  return -1;
8639  }
8640  }
8641  if (ignorepatl)
8642  ignorepatl->next = ignorepat;
8643  else
8644  con->ignorepats = ignorepat;
8645  ast_unlock_context(con);
8646  return 0;
8647 
8648 }
int ast_unlock_context(struct ast_context *con)
Definition: pbx.c:11065
struct ast_ignorepat * ignorepats
Definition: pbx.c:962
const char * registrar
Definition: pbx.c:926
const char pattern[0]
Definition: pbx.c:928
int value
Definition: syslog.c:39
ast_ignorepat: Ignore patterns in dial plan
Definition: pbx.c:925
int ast_wrlock_context(struct ast_context *con)
Write locks a given context.
Definition: pbx.c:11055
int errno
#define ast_free(a)
Definition: astmm.h:97
static char * registrar
Definition: features.c:623
#define ast_calloc(a, b)
Definition: astmm.h:82
struct ast_ignorepat * next
Definition: pbx.c:927
int ast_context_add_include ( const char *  context,
const char *  include,
const char *  registrar 
)

Add a context include.

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

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

Return values
0on success
-1on error

Definition at line 8142 of file pbx.c.

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

Referenced by handle_cli_dialplan_add_include().

8143 {
8144  int ret = -1;
8145  struct ast_context *c;
8146 
8148  if (c) {
8149  ret = ast_context_add_include2(c, include, registrar);
8151  }
8152  return ret;
8153 }
int ast_context_add_include2(struct ast_context *con, const char *include, const char *registrar)
Add a context include.
Definition: pbx.c:8411
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:11047
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:5985
static char * registrar
Definition: features.c:623
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
ast_context: An extension context
Definition: pbx.c:955
int ast_context_add_include2 ( struct ast_context con,
const char *  include,
const char *  registrar 
)

Add a context include.

Parameters
concontext to add the include to
includeinclude to add
registrarwho registered the context

Adds an include taking a struct ast_context as the first parameter

Return values
0on success
-1on failure

Definition at line 8411 of file pbx.c.

References ast_build_timing(), ast_calloc, ast_destroy_timing(), ast_free, ast_get_context_name(), ast_unlock_context(), ast_verb, ast_wrlock_context(), errno, ast_include::hastime, ast_context::includes, ast_include::name, ast_include::next, ast_include::registrar, ast_sw::registrar, ast_include::rname, ast_include::stuff, and ast_include::timing.

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

8413 {
8414  struct ast_include *new_include;
8415  char *c;
8416  struct ast_include *i, *il = NULL; /* include, include_last */
8417  int length;
8418  char *p;
8419 
8420  length = sizeof(struct ast_include);
8421  length += 2 * (strlen(value) + 1);
8422 
8423  /* allocate new include structure ... */
8424  if (!(new_include = ast_calloc(1, length)))
8425  return -1;
8426  /* Fill in this structure. Use 'p' for assignments, as the fields
8427  * in the structure are 'const char *'
8428  */
8429  p = new_include->stuff;
8430  new_include->name = p;
8431  strcpy(p, value);
8432  p += strlen(value) + 1;
8433  new_include->rname = p;
8434  strcpy(p, value);
8435  /* Strip off timing info, and process if it is there */
8436  if ( (c = strchr(p, ',')) ) {
8437  *c++ = '\0';
8438  new_include->hastime = ast_build_timing(&(new_include->timing), c);
8439  }
8440  new_include->next = NULL;
8441  new_include->registrar = registrar;
8442 
8443  ast_wrlock_context(con);
8444 
8445  /* ... go to last include and check if context is already included too... */
8446  for (i = con->includes; i; i = i->next) {
8447  if (!strcasecmp(i->name, new_include->name)) {
8448  ast_destroy_timing(&(new_include->timing));
8449  ast_free(new_include);
8450  ast_unlock_context(con);
8451  errno = EEXIST;
8452  return -1;
8453  }
8454  il = i;
8455  }
8456 
8457  /* ... include new context into context list, unlock, return */
8458  if (il)
8459  il->next = new_include;
8460  else
8461  con->includes = new_include;
8462  ast_verb(3, "Including context '%s' in context '%s'\n", new_include->name, ast_get_context_name(con));
8463 
8464  ast_unlock_context(con);
8465 
8466  return 0;
8467 }
ast_include: include= support in extensions.conf
Definition: pbx.c:904
int ast_unlock_context(struct ast_context *con)
Definition: pbx.c:11065
int hastime
Definition: pbx.c:908
struct ast_include * next
Definition: pbx.c:910
struct ast_include * includes
Definition: pbx.c:961
const char * rname
Definition: pbx.c:906
int value
Definition: syslog.c:39
struct ast_timing timing
Definition: pbx.c:909
#define ast_verb(level,...)
Definition: logger.h:243
const char * registrar
Definition: pbx.c:907
const char * ast_get_context_name(struct ast_context *con)
Definition: pbx.c:11073
char stuff[0]
Definition: pbx.c:911
const char * name
Definition: pbx.c:905
int ast_wrlock_context(struct ast_context *con)
Write locks a given context.
Definition: pbx.c:11055
int ast_destroy_timing(struct ast_timing *i)
Deallocates memory structures associated with a timing bitmap.
Definition: pbx.c:8396
int errno
#define ast_free(a)
Definition: astmm.h:97
static char * registrar
Definition: features.c:623
int ast_build_timing(struct ast_timing *i, const char *info)
Construct a timing bitmap, for use in time-based conditionals.
Definition: pbx.c:8314
#define ast_calloc(a, b)
Definition: astmm.h:82
int ast_context_add_switch ( const char *  context,
const char *  sw,
const char *  data,
int  eval,
const char *  registrar 
)

Add a switch.

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

This function registers a switch with the asterisk switch architecture

Return values
0on success
-1on failure

Definition at line 8474 of file pbx.c.

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

8475 {
8476  int ret = -1;
8477  struct ast_context *c;
8478 
8480  if (c) { /* found, add switch to this context */
8481  ret = ast_context_add_switch2(c, sw, data, eval, registrar);
8483  }
8484  return ret;
8485 }
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)
Definition: pbx.c:8494
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:11047
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:5985
static char * registrar
Definition: features.c:623
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
ast_context: An extension context
Definition: pbx.c:955
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 8494 of file pbx.c.

References ast_context::alts, ast_calloc, ast_free, ast_get_context_name(), AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_unlock_context(), ast_verb, ast_wrlock_context(), ast_sw::data, errno, ast_sw::eval, ast_sw::name, ast_sw::registrar, and ast_sw::stuff.

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

8496 {
8497  struct ast_sw *new_sw;
8498  struct ast_sw *i;
8499  int length;
8500  char *p;
8501 
8502  length = sizeof(struct ast_sw);
8503  length += strlen(value) + 1;
8504  if (data)
8505  length += strlen(data);
8506  length++;
8507 
8508  /* allocate new sw structure ... */
8509  if (!(new_sw = ast_calloc(1, length)))
8510  return -1;
8511  /* ... fill in this structure ... */
8512  p = new_sw->stuff;
8513  new_sw->name = p;
8514  strcpy(new_sw->name, value);
8515  p += strlen(value) + 1;
8516  new_sw->data = p;
8517  if (data) {
8518  strcpy(new_sw->data, data);
8519  p += strlen(data) + 1;
8520  } else {
8521  strcpy(new_sw->data, "");
8522  p++;
8523  }
8524  new_sw->eval = eval;
8525  new_sw->registrar = registrar;
8526 
8527  /* ... try to lock this context ... */
8528  ast_wrlock_context(con);
8529 
8530  /* ... go to last sw and check if context is already swd too... */
8531  AST_LIST_TRAVERSE(&con->alts, i, list) {
8532  if (!strcasecmp(i->name, new_sw->name) && !strcasecmp(i->data, new_sw->data)) {
8533  ast_free(new_sw);
8534  ast_unlock_context(con);
8535  errno = EEXIST;
8536  return -1;
8537  }
8538  }
8539 
8540  /* ... sw new context into context list, unlock, return */
8541  AST_LIST_INSERT_TAIL(&con->alts, new_sw, list);
8542 
8543  ast_verb(3, "Including switch '%s/%s' in context '%s'\n", new_sw->name, new_sw->data, ast_get_context_name(con));
8544 
8545  ast_unlock_context(con);
8546 
8547  return 0;
8548 }
int ast_unlock_context(struct ast_context *con)
Definition: pbx.c:11065
int value
Definition: syslog.c:39
#define ast_verb(level,...)
Definition: logger.h:243
ast_sw: Switch statement in extensions.conf
Definition: pbx.c:915
char stuff[0]
Definition: pbx.c:921
const char * ast_get_context_name(struct ast_context *con)
Definition: pbx.c:11073
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:716
int eval
Definition: pbx.c:919
char * data
Definition: pbx.c:918
struct ast_sw::@289 list
int ast_wrlock_context(struct ast_context *con)
Write locks a given context.
Definition: pbx.c:11055
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
int errno
#define ast_free(a)
Definition: astmm.h:97
static char * registrar
Definition: features.c:623
#define ast_calloc(a, b)
Definition: astmm.h:82
struct ast_context::@290 alts
const char * registrar
Definition: pbx.c:917
char * name
Definition: pbx.c:916
void ast_context_destroy ( struct ast_context con,
const char *  registrar 
)

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

Parameters
concontext to destroy
registrarwho registered it

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

Returns
nothing

Definition at line 9875 of file pbx.c.

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

Referenced by __unload_module(), ast_features_reload(), cleanup_stale_contexts(), features_shutdown(), remove_dead_dialplan_useage(), sla_destroy(), and unload_module().

9876 {
9880 }
void __ast_context_destroy(struct ast_context *list, struct ast_hashtab *contexttab, struct ast_context *con, const char *registrar)
Definition: pbx.c:9718
static struct ast_hashtab * contexts_table
Definition: pbx.c:1286
int ast_wrlock_contexts(void)
Write locks the context list.
Definition: pbx.c:11037
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:11047
static char * registrar
Definition: features.c:623
static struct ast_context * contexts
Definition: pbx.c:1285
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 2971 of file pbx.c.

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

Referenced by __unload_module(), _macro_exec(), ast_context_verify_includes(), ast_features_reload(), ast_ignore_pattern(), cleanup_stale_contexts(), isexten_function_read(), manage_parkinglot(), parked_call_exec(), register_exten(), register_peer_exten(), remove_dead_dialplan_useage(), unload_module(), and unregister_exten().

2972 {
2973  struct ast_context *tmp;
2974  struct fake_context item;
2975 
2976  if (!name) {
2977  return NULL;
2978  }
2980  if (contexts_table) {
2981  ast_copy_string(item.name, name, sizeof(item.name));
2982  tmp = ast_hashtab_lookup(contexts_table, &item);
2983  } else {
2984  tmp = NULL;
2985  while ((tmp = ast_walk_contexts(tmp))) {
2986  if (!strcasecmp(name, tmp->name)) {
2987  break;
2988  }
2989  }
2990  }
2992  return tmp;
2993 }
void * ast_hashtab_lookup(struct ast_hashtab *tab, const void *obj)
Lookup this object in the hash table.
Definition: hashtab.c:534
static struct ast_hashtab * contexts_table
Definition: pbx.c:1286
int ast_rdlock_contexts(void)
Read locks the context list.
Definition: pbx.c:11042
char name[0]
Definition: pbx.c:967
struct ast_context * ast_walk_contexts(struct ast_context *con)
Definition: pbx.c:11174
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:11047
static const char name[]
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
ast_context: An extension context
Definition: pbx.c:955
struct ast_context* ast_context_find_or_create ( struct ast_context **  extcontexts,
struct ast_hashtab exttable,
const char *  name,
const char *  registrar 
)

Register a new context or find an existing one.

Parameters
extcontextspointer to the ast_context structure pointer
exttablepointer to the hashtable that contains all the elements in extcontexts
namename of the new context
registrarregistrar of the context

This function allows you to play in two environments: the global contexts (active dialplan) or an external context set of your choosing. To act on the external set, make sure extcontexts and exttable are set; for the globals, make sure both extcontexts and exttable are NULL.

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

Returns
NULL on failure, and an ast_context structure on success

Definition at line 7726 of file pbx.c.

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

Referenced by ast_compile_ael2(), config_parse_variables(), context_merge(), load_module(), lua_register_switches(), manage_parked_call(), parkinglot_activate(), pbx_load_config(), pbx_load_users(), reload_config(), set_config(), sla_build_station(), and sla_build_trunk().

7727 {
7728  struct ast_context *tmp, **local_contexts;
7729  struct fake_context search;
7730  int length = sizeof(struct ast_context) + strlen(name) + 1;
7731 
7732  if (!contexts_table) {
7733  /* Protect creation of contexts_table from reentrancy. */
7735  if (!contexts_table) {
7741  0);
7742  }
7744  }
7745 
7746  ast_copy_string(search.name, name, sizeof(search.name));
7747  if (!extcontexts) {
7749  local_contexts = &contexts;
7750  tmp = ast_hashtab_lookup(contexts_table, &search);
7752  if (tmp) {
7753  tmp->refcount++;
7754  return tmp;
7755  }
7756  } else { /* local contexts just in a linked list; search there for the new context; slow, linear search, but not frequent */
7757  local_contexts = extcontexts;
7758  tmp = ast_hashtab_lookup(exttable, &search);
7759  if (tmp) {
7760  tmp->refcount++;
7761  return tmp;
7762  }
7763  }
7764 
7765  if ((tmp = ast_calloc(1, length))) {
7766  ast_rwlock_init(&tmp->lock);
7767  ast_mutex_init(&tmp->macrolock);
7768  strcpy(tmp->name, name);
7769  tmp->root = NULL;
7770  tmp->root_table = NULL;
7771  tmp->registrar = ast_strdup(registrar);
7772  tmp->includes = NULL;
7773  tmp->ignorepats = NULL;
7774  tmp->refcount = 1;
7775  } else {
7776  ast_log(LOG_ERROR, "Danger! We failed to allocate a context for %s!\n", name);
7777  return NULL;
7778  }
7779 
7780  if (!extcontexts) {
7782  tmp->next = *local_contexts;
7783  *local_contexts = tmp;
7784  ast_hashtab_insert_safe(contexts_table, tmp); /*put this context into the tree */
7786  ast_debug(1, "Registered context '%s'(%p) in table %p registrar: %s\n", tmp->name, tmp, contexts_table, registrar);
7787  ast_verb(3, "Registered extension context '%s'; registrar: %s\n", tmp->name, registrar);
7788  } else {
7789  tmp->next = *local_contexts;
7790  if (exttable)
7791  ast_hashtab_insert_immediate(exttable, tmp); /*put this context into the tree */
7792 
7793  *local_contexts = tmp;
7794  ast_debug(1, "Registered context '%s'(%p) in local table %p; registrar: %s\n", tmp->name, tmp, exttable, registrar);
7795  ast_verb(3, "Registered extension context '%s'; registrar: %s\n", tmp->name, registrar);
7796  }
7797  return tmp;
7798 }
int ast_hashtab_compare_contexts(const void *ah_a, const void *ah_b)
hashtable functions for contexts
Definition: pbx.c:1136
void * ast_hashtab_lookup(struct ast_hashtab *tab, const void *obj)
Lookup this object in the hash table.
Definition: hashtab.c:534
int ast_hashtab_newsize_java(struct ast_hashtab *tab)
Create a prime number roughly 2x the current table size.
Definition: hashtab.c:131
struct ast_include * includes
Definition: pbx.c:961
#define ast_strdup(a)
Definition: astmm.h:109
static struct ast_hashtab * contexts_table
Definition: pbx.c:1286
struct ast_ignorepat * ignorepats
Definition: pbx.c:962
int ast_rdlock_contexts(void)
Read locks the context list.
Definition: pbx.c:11042
int ast_wrlock_contexts(void)
Write locks the context list.
Definition: pbx.c:11037
#define ast_verb(level,...)
Definition: logger.h:243
int ast_hashtab_resize_java(struct ast_hashtab *tab)
Determines if a table resize should occur using the Java algorithm (if the table load factor is 75% o...
Definition: hashtab.c:88
ast_mutex_t macrolock
Definition: pbx.c:966
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
int ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj)
Insert without checking.
Definition: hashtab.c:432
char * registrar
Definition: pbx.c:963
char name[0]
Definition: pbx.c:967
struct ast_hashtab * ast_hashtab_create(int initial_buckets, int(*compare)(const void *a, const void *b), int(*resize)(struct ast_hashtab *), int(*newsize)(struct ast_hashtab *tab), unsigned int(*hash)(const void *obj), int do_locking)
Create the hashtable list.
Definition: hashtab.c:226
ast_rwlock_t lock
Definition: pbx.c:956
#define LOG_ERROR
Definition: logger.h:155
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:11047
#define ast_rwlock_init(rwlock)
wrapper for rwlock with tracking enabled
Definition: lock.h:190
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
struct ast_context * next
Definition: pbx.c:960
static const char name[]
unsigned int ast_hashtab_hash_contexts(const void *obj)
Definition: pbx.c:1188
static char * registrar
Definition: features.c:623
#define ast_calloc(a, b)
Definition: astmm.h:82
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
int ast_hashtab_insert_safe(struct ast_hashtab *tab, const void *obj)
Check and insert new object only if it is not there.
Definition: hashtab.c:503
static struct ast_context * local_contexts
Definition: pbx_config.c:60
int refcount
Definition: pbx.c:964
struct ast_hashtab * root_table
Definition: pbx.c:958
static struct ast_context * contexts
Definition: pbx.c:1285
#define ast_mutex_init(pmutex)
Definition: lock.h:152
ast_context: An extension context
Definition: pbx.c:955
struct ast_exten * root
Definition: pbx.c:957
int ast_context_lockmacro ( const char *  context)

locks the macrolock in the given 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 6306 of file pbx.c.

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

Referenced by _macro_exec().

6307 {
6308  struct ast_context *c;
6309  int ret = -1;
6310 
6312  if (c) {
6314 
6315  /* if we found context, lock macrolock */
6316  ret = ast_mutex_lock(&c->macrolock);
6317  }
6318 
6319  return ret;
6320 }
#define ast_mutex_lock(a)
Definition: lock.h:155
ast_mutex_t macrolock
Definition: pbx.c:966
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:11047
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:5985
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
ast_context: An extension context
Definition: pbx.c:955
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 6114 of file pbx.c.

References ast_context_remove_extension_callerid(), and AST_EXT_MATCHCID_ANY.

Referenced by register_peer_exten(), remove_exten_if_exist(), sla_station_destructor(), sla_trunk_destructor(), unregister_exten(), and UnregisterExtension().

6115 {
6117 }
int ast_context_remove_extension_callerid(const char *context, const char *extension, int priority, const char *callerid, int matchcid, const char *registrar)
Definition: pbx.c:6119
static char * registrar
Definition: features.c:623
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
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 6144 of file pbx.c.

References ast_context_remove_extension_callerid2(), and AST_EXT_MATCHCID_ANY.

Referenced by manage_parkinglot(), parked_call_exec(), and unload_module().

6145 {
6146  return ast_context_remove_extension_callerid2(con, extension, priority, NULL, AST_EXT_MATCHCID_ANY, registrar, already_locked);
6147 }
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: pbx.c:6149
static char * registrar
Definition: features.c:623
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 6119 of file pbx.c.

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

Referenced by ast_context_remove_extension(), and handle_cli_dialplan_remove_extension().

6120 {
6121  int ret = -1; /* default error return */
6122  struct ast_context *c;
6123 
6125  if (c) { /* ... remove extension ... */
6126  ret = ast_context_remove_extension_callerid2(c, extension, priority, callerid,
6127  matchcallerid, registrar, 0);
6129  }
6130 
6131  return ret;
6132 }
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: pbx.c:6149
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:11047
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:5985
static char * registrar
Definition: features.c:623
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
ast_context: An extension context
Definition: pbx.c:955
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 6149 of file pbx.c.

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

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

6150 {
6151  struct ast_exten *exten, *prev_exten = NULL;
6152  struct ast_exten *peer;
6153  struct ast_exten ex, *exten2, *exten3;
6154  char dummy_name[1024];
6155  struct ast_exten *previous_peer = NULL;
6156  struct ast_exten *next_peer = NULL;
6157  int found = 0;
6158 
6159  if (!already_locked)
6160  ast_wrlock_context(con);
6161 
6162 #ifdef NEED_DEBUG
6163  ast_verb(3,"Removing %s/%s/%d%s%s from trees, registrar=%s\n", con->name, extension, priority, matchcallerid ? "/" : "", matchcallerid ? callerid : "", registrar);
6164 #endif
6165 #ifdef CONTEXT_DEBUG
6166  check_contexts(__FILE__, __LINE__);
6167 #endif
6168  /* find this particular extension */
6169  ex.exten = dummy_name;
6170  ex.matchcid = matchcallerid;
6171  ex.cidmatch = callerid;
6172  ast_copy_string(dummy_name, extension, sizeof(dummy_name));
6173  exten = ast_hashtab_lookup(con->root_table, &ex);
6174  if (exten) {
6175  if (priority == 0) {
6176  exten2 = ast_hashtab_remove_this_object(con->root_table, exten);
6177  if (!exten2)
6178  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);
6179  if (con->pattern_tree) {
6180  struct match_char *x = add_exten_to_pattern_tree(con, exten, 1);
6181 
6182  if (x->exten) { /* this test for safety purposes */
6183  x->deleted = 1; /* with this marked as deleted, it will never show up in the scoreboard, and therefore never be found */
6184  x->exten = 0; /* get rid of what will become a bad pointer */
6185  } else {
6186  ast_log(LOG_WARNING,"Trying to delete an exten from a context, but the pattern tree node returned isn't a full extension\n");
6187  }
6188  }
6189  } else {
6190  ex.priority = priority;
6191  exten2 = ast_hashtab_lookup(exten->peer_table, &ex);
6192  if (exten2) {
6193  if (exten2->label) { /* if this exten has a label, remove that, too */
6194  exten3 = ast_hashtab_remove_this_object(exten->peer_label_table,exten2);
6195  if (!exten3)
6196  ast_log(LOG_ERROR,"Did not remove this priority label (%d/%s) from the peer_label_table of context %s, extension %s!\n", priority, exten2->label, con->name, exten2->exten);
6197  }
6198 
6199  exten3 = ast_hashtab_remove_this_object(exten->peer_table, exten2);
6200  if (!exten3)
6201  ast_log(LOG_ERROR,"Did not remove this priority (%d) from the peer_table of context %s, extension %s!\n", priority, con->name, exten2->exten);
6202  if (exten2 == exten && exten2->peer) {
6203  exten2 = ast_hashtab_remove_this_object(con->root_table, exten);
6205  }
6206  if (ast_hashtab_size(exten->peer_table) == 0) {
6207  /* well, if the last priority of an exten is to be removed,
6208  then, the extension is removed, too! */
6209  exten3 = ast_hashtab_remove_this_object(con->root_table, exten);
6210  if (!exten3)
6211  ast_log(LOG_ERROR,"Did not remove this exten (%s) from the context root_table (%s) (priority %d)\n", exten->exten, con->name, priority);
6212  if (con->pattern_tree) {
6213  struct match_char *x = add_exten_to_pattern_tree(con, exten, 1);
6214  if (x->exten) { /* this test for safety purposes */
6215  x->deleted = 1; /* with this marked as deleted, it will never show up in the scoreboard, and therefore never be found */
6216  x->exten = 0; /* get rid of what will become a bad pointer */
6217  }
6218  }
6219  }
6220  } else {
6221  ast_log(LOG_ERROR,"Could not find priority %d of exten %s in context %s!\n",
6222  priority, exten->exten, con->name);
6223  }
6224  }
6225  } else {
6226  /* hmmm? this exten is not in this pattern tree? */
6227  ast_log(LOG_WARNING,"Cannot find extension %s in root_table in context %s\n",
6228  extension, con->name);
6229  }
6230 #ifdef NEED_DEBUG
6231  if (con->pattern_tree) {
6232  ast_log(LOG_NOTICE,"match char tree after exten removal:\n");
6233  log_match_char_tree(con->pattern_tree, " ");
6234  }
6235 #endif
6236 
6237  /* scan the extension list to find first matching extension-registrar */
6238  for (exten = con->root; exten; prev_exten = exten, exten = exten->next) {
6239  if (!strcmp(exten->exten, extension) &&
6240  (!registrar || !strcmp(exten->registrar, registrar)) &&
6241  (!matchcallerid || (!ast_strlen_zero(callerid) && !ast_strlen_zero(exten->cidmatch) && !strcmp(exten->cidmatch, callerid)) || (ast_strlen_zero(callerid) && ast_strlen_zero(exten->cidmatch))))
6242  break;
6243  }
6244  if (!exten) {
6245  /* we can't find right extension */
6246  if (!already_locked)
6247  ast_unlock_context(con);
6248  return -1;
6249  }
6250 
6251  /* scan the priority list to remove extension with exten->priority == priority */
6252  for (peer = exten, next_peer = exten->peer ? exten->peer : exten->next;
6253  peer && !strcmp(peer->exten, extension) &&
6254  (!callerid || (!matchcallerid && !peer->matchcid) || (matchcallerid && peer->matchcid && !strcmp(peer->cidmatch, callerid))) ;
6255  peer = next_peer, next_peer = next_peer ? (next_peer->peer ? next_peer->peer : next_peer->next) : NULL) {
6256 
6257  if ((priority == 0 || peer->priority == priority) &&
6258  (!registrar || !strcmp(peer->registrar, registrar) )) {
6259  found = 1;
6260 
6261  /* we are first priority extension? */
6262  if (!previous_peer) {
6263  /*
6264  * We are first in the priority chain, so must update the extension chain.
6265  * The next node is either the next priority or the next extension
6266  */
6267  struct ast_exten *next_node = peer->peer ? peer->peer : peer->next;
6268  if (peer->peer) {
6269  /* move the peer_table and peer_label_table down to the next peer, if
6270  it is there */
6271  peer->peer->peer_table = peer->peer_table;
6272  peer->peer->peer_label_table = peer->peer_label_table;
6273  peer->peer_table = NULL;
6274  peer->peer_label_table = NULL;
6275  }
6276  if (!prev_exten) { /* change the root... */
6277  con->root = next_node;
6278  } else {
6279  prev_exten->next = next_node; /* unlink */
6280  }
6281  if (peer->peer) { /* update the new head of the pri list */
6282  peer->peer->next = peer->next;
6283  }
6284  } else { /* easy, we are not first priority in extension */
6285  previous_peer->peer = peer->peer;
6286  }
6287 
6288 
6289  /* now, free whole priority extension */
6290  destroy_exten(peer);
6291  } else {
6292  previous_peer = peer;
6293  }
6294  }
6295  if (!already_locked)
6296  ast_unlock_context(con);
6297  return found ? 0 : -1;
6298 }
int ast_unlock_context(struct ast_context *con)
Definition: pbx.c:11065
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
ast_exten: An extension The dialplan is saved as a linked list with each context having it&#39;s own link...
Definition: pbx.c:884
void * ast_hashtab_lookup(struct ast_hashtab *tab, const void *obj)
Lookup this object in the hash table.
Definition: hashtab.c:534
struct ast_exten * exten
Definition: pbx.c:939
static struct match_char * add_exten_to_pattern_tree(struct ast_context *con, struct ast_exten *e1, int findonly)
Definition: pbx.c:2222
#define LOG_WARNING
Definition: logger.h:144
const char * label
Definition: pbx.c:889
struct ast_hashtab * peer_table
Definition: pbx.c:896
char x[1]
Definition: pbx.c:940
#define ast_verb(level,...)
Definition: logger.h:243
int matchcid
Definition: pbx.c:886
int priority
Definition: pbx.c:888
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
int ast_hashtab_insert_immediate(struct ast_hashtab *tab, const void *obj)
Insert without checking.
Definition: hashtab.c:432
char * exten
Definition: pbx.c:885
struct ast_exten * peer
Definition: pbx.c:895
char name[0]
Definition: pbx.c:967
struct ast_hashtab * peer_label_table
Definition: pbx.c:897
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
int ast_wrlock_context(struct ast_context *con)
Write locks a given context.
Definition: pbx.c:11055
static char * registrar
Definition: features.c:623
const char * registrar
Definition: pbx.c:898
struct ast_exten * next
Definition: pbx.c:899
const char * cidmatch
Definition: pbx.c:887
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
struct ast_hashtab * root_table
Definition: pbx.c:958
int ast_hashtab_size(struct ast_hashtab *tab)
Returns the number of elements stored in the hashtab.
Definition: hashtab.c:625
struct ast_exten * root
Definition: pbx.c:957
struct match_char * pattern_tree
Definition: pbx.c:959
static void destroy_exten(struct ast_exten *e)
Definition: pbx.c:5845
int deleted
Definition: pbx.c:935
match_char: forms a syntax tree for quick matching of extension patterns
Definition: pbx.c:932
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:859
int ast_context_remove_ignorepat ( const char *  context,
const char *  ignorepat,
const char *  registrar 
)

Definition at line 8554 of file pbx.c.

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

Referenced by handle_cli_dialplan_remove_ignorepat().

8555 {
8556  int ret = -1;
8557  struct ast_context *c;
8558 
8560  if (c) {
8561  ret = ast_context_remove_ignorepat2(c, ignorepat, registrar);
8563  }
8564  return ret;
8565 }
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:11047
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:5985
static char * registrar
Definition: features.c:623
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
ast_context: An extension context
Definition: pbx.c:955
int ast_context_remove_ignorepat2(struct ast_context *con, const char *ignorepat, const char *registrar)
Definition: pbx.c:8567
int ast_context_remove_ignorepat2 ( struct ast_context con,
const char *  ignorepat,
const char *  registrar 
)

Definition at line 8567 of file pbx.c.

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

Referenced by ast_context_remove_ignorepat().

8568 {
8569  struct ast_ignorepat *ip, *ipl = NULL;
8570 
8571  ast_wrlock_context(con);
8572 
8573  for (ip = con->ignorepats; ip; ip = ip->next) {
8574  if (!strcmp(ip->pattern, ignorepat) &&
8575  (!registrar || (registrar == ip->registrar))) {
8576  if (ipl) {
8577  ipl->next = ip->next;
8578  ast_free(ip);
8579  } else {
8580  con->ignorepats = ip->next;
8581  ast_free(ip);
8582  }
8583  ast_unlock_context(con);
8584  return 0;
8585  }
8586  ipl = ip;
8587  }
8588 
8589  ast_unlock_context(con);
8590  errno = EINVAL;
8591  return -1;
8592 }
int ast_unlock_context(struct ast_context *con)
Definition: pbx.c:11065
struct ast_ignorepat * ignorepats
Definition: pbx.c:962
const char * registrar
Definition: pbx.c:926
const char pattern[0]
Definition: pbx.c:928
ast_ignorepat: Ignore patterns in dial plan
Definition: pbx.c:925
int ast_wrlock_context(struct ast_context *con)
Write locks a given context.
Definition: pbx.c:11055
int errno
#define ast_free(a)
Definition: astmm.h:97
static char * registrar
Definition: features.c:623
struct ast_ignorepat * next
Definition: pbx.c:927
int ast_context_remove_include ( const char *  context,
const char *  include,
const char *  registrar 
)

Remove a context include.

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

Remove a context include.

Definition at line 6007 of file pbx.c.

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

Referenced by handle_cli_dialplan_remove_include().

6008 {
6009  int ret = -1;
6010  struct ast_context *c;
6011 
6013  if (c) {
6014  /* found, remove include from this context ... */
6015  ret = ast_context_remove_include2(c, include, registrar);
6017  }
6018  return ret;
6019 }
int ast_context_remove_include2(struct ast_context *con, const char *include, const char *registrar)
Removes an include by an ast_context structure.
Definition: pbx.c:6030
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:11047
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:5985
static char * registrar
Definition: features.c:623
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
ast_context: An extension context
Definition: pbx.c:955
int ast_context_remove_include2 ( struct ast_context con,
const char *  include,
const char *  registrar 
)

Removes an include by an ast_context structure.

Note
See ast_context_add_include2 for information on arguments
Return values
0on success
-1on success

Removes an include by an ast_context structure.

Return values
0on success.
-1on failure.

Definition at line 6030 of file pbx.c.

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

Referenced by ast_context_remove_include().

6031 {
6032  struct ast_include *i, *pi = NULL;
6033  int ret = -1;
6034 
6035  ast_wrlock_context(con);
6036 
6037  /* find our include */
6038  for (i = con->includes; i; pi = i, i = i->next) {
6039  if (!strcmp(i->name, include) &&
6040  (!registrar || !strcmp(i->registrar, registrar))) {
6041  /* remove from list */
6042  ast_verb(3, "Removing inclusion of context '%s' in context '%s; registrar=%s'\n", include, ast_get_context_name(con), registrar);
6043  if (pi)
6044  pi->next = i->next;
6045  else
6046  con->includes = i->next;
6047  /* free include and return */
6048  ast_destroy_timing(&(i->timing));
6049  ast_free(i);
6050  ret = 0;
6051  break;
6052  }
6053  }
6054 
6055  ast_unlock_context(con);
6056 
6057  return ret;
6058 }
ast_include: include= support in extensions.conf
Definition: pbx.c:904
int ast_unlock_context(struct ast_context *con)
Definition: pbx.c:11065
struct ast_include * next
Definition: pbx.c:910
struct ast_include * includes
Definition: pbx.c:961
struct ast_timing timing
Definition: pbx.c:909
#define ast_verb(level,...)
Definition: logger.h:243
const char * registrar
Definition: pbx.c:907
const char * ast_get_context_name(struct ast_context *con)
Definition: pbx.c:11073
const char * name
Definition: pbx.c:905
int ast_wrlock_context(struct ast_context *con)
Write locks a given context.
Definition: pbx.c:11055
int ast_destroy_timing(struct ast_timing *i)
Deallocates memory structures associated with a timing bitmap.
Definition: pbx.c:8396
#define ast_free(a)
Definition: astmm.h:97
static char * registrar
Definition: features.c:623
int ast_context_remove_switch ( const char *  context,
const char *  sw,
const char *  data,
const char *  registrar 
)

Remove a switch.

Removes a switch with the given parameters

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

Definition at line 6065 of file pbx.c.

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

6066 {
6067  int ret = -1; /* default error return */
6068  struct ast_context *c;
6069 
6071  if (c) {
6072  /* remove switch from this context ... */
6073  ret = ast_context_remove_switch2(c, sw, data, registrar);
6075  }
6076  return ret;
6077 }
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:11047
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:5985
static char * registrar
Definition: features.c:623
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
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:6087
ast_context: An extension context
Definition: pbx.c:955
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 6087 of file pbx.c.

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

Referenced by ast_context_remove_switch().

6088 {
6089  struct ast_sw *i;
6090  int ret = -1;
6091 
6092  ast_wrlock_context(con);
6093 
6094  /* walk switches */
6096  if (!strcmp(i->name, sw) && !strcmp(i->data, data) &&
6097  (!registrar || !strcmp(i->registrar, registrar))) {
6098  /* found, remove from list */
6099  ast_verb(3, "Removing switch '%s' from context '%s; registrar=%s'\n", sw, ast_get_context_name(con), registrar);
6101  ast_free(i); /* free switch and return */
6102  ret = 0;
6103  break;
6104  }
6105  }
6107 
6108  ast_unlock_context(con);
6109 
6110  return ret;
6111 }
int ast_unlock_context(struct ast_context *con)
Definition: pbx.c:11065
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:600
#define ast_verb(level,...)
Definition: logger.h:243
ast_sw: Switch statement in extensions.conf
Definition: pbx.c:915
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:554
const char * ast_get_context_name(struct ast_context *con)
Definition: pbx.c:11073
char * data
Definition: pbx.c:918
struct ast_sw::@289 list
int ast_wrlock_context(struct ast_context *con)
Write locks a given context.
Definition: pbx.c:11055
#define ast_free(a)
Definition: astmm.h:97
static char * registrar
Definition: features.c:623
struct ast_context::@290 alts
const char * registrar
Definition: pbx.c:917
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
char * name
Definition: pbx.c:916
int ast_context_unlockmacro ( const char *  context)

Unlocks the macrolock in the given context.

Parameters
macrocontextname of the macro-context to unlock

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

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

Definition at line 6327 of file pbx.c.

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

Referenced by _macro_exec().

6328 {
6329  struct ast_context *c;
6330  int ret = -1;
6331 
6333  if (c) {
6335 
6336  /* if we found context, unlock macrolock */
6337  ret = ast_mutex_unlock(&c->macrolock);
6338  }
6339 
6340  return ret;
6341 }
ast_mutex_t macrolock
Definition: pbx.c:966
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:11047
static struct ast_context * find_context_locked(const char *context)
lookup for a context with a given name,
Definition: pbx.c:5985
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
ast_context: An extension context
Definition: pbx.c:955
#define ast_mutex_unlock(a)
Definition: lock.h:156
int ast_context_verify_includes ( struct ast_context con)

Verifies includes in an ast_contect structure.

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

Definition at line 11221 of file pbx.c.

References ast_context_find(), ast_get_context_name(), ast_log(), ast_walk_context_includes(), LOG_WARNING, and ast_include::rname.

Referenced by pbx_load_module().

11222 {
11223  struct ast_include *inc = NULL;
11224  int res = 0;
11225 
11226  while ( (inc = ast_walk_context_includes(con, inc)) ) {
11227  if (ast_context_find(inc->rname))
11228  continue;
11229 
11230  res = -1;
11231  ast_log(LOG_WARNING, "Context '%s' tries to include nonexistent context '%s'\n",
11232  ast_get_context_name(con), inc->rname);
11233  break;
11234  }
11235 
11236  return res;
11237 }
struct ast_include * ast_walk_context_includes(struct ast_context *con, struct ast_include *inc)
Definition: pbx.c:11203
ast_include: include= support in extensions.conf
Definition: pbx.c:904
const char * rname
Definition: pbx.c:906
#define LOG_WARNING
Definition: logger.h:144
const char * ast_get_context_name(struct ast_context *con)
Definition: pbx.c:11073
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
struct ast_context * ast_context_find(const char *name)
Find a context.
Definition: pbx.c:2971
struct ast_custom_function* ast_custom_function_find ( const char *  name)

Definition at line 3800 of file pbx.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, and ast_custom_function::name.

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

3801 {
3802  struct ast_custom_function *acf = NULL;
3803 
3805  AST_RWLIST_TRAVERSE(&acf_root, acf, acflist) {
3806  if (!strcmp(name, acf->name))
3807  break;
3808  }
3810 
3811  return acf;
3812 }
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
Data structure associated with a custom dialplan function.
Definition: pbx.h:95
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
Definition: pbx.c:1231
static const char name[]
const char * name
Definition: pbx.h:96
int ast_custom_function_unregister ( struct ast_custom_function acf)

Unregister a custom function.

Definition at line 3814 of file pbx.c.

References ast_free, AST_RWLIST_REMOVE, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, 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 __ast_custom_function_register_escalating(), _unload_module(), load_module(), reload(), unload_module(), and unload_pbx().

3815 {
3816  struct ast_custom_function *cur;
3817  struct ast_custom_escalating_function *cur_escalation;
3818 
3819  if (!acf) {
3820  return -1;
3821  }
3822 
3824  if ((cur = AST_RWLIST_REMOVE(&acf_root, acf, acflist))) {
3825 #ifdef AST_XML_DOCS
3826  if (cur->docsrc == AST_XML_DOC) {
3828  }
3829 #endif
3830  ast_verb(2, "Unregistered custom function %s\n", cur->name);
3831  }
3833 
3834  /* Remove from the escalation list */
3836  AST_RWLIST_TRAVERSE_SAFE_BEGIN(&escalation_root, cur_escalation, list) {
3837  if (cur_escalation->acf == acf) {
3839  ast_free(cur_escalation);
3840  break;
3841  }
3842  }
3845 
3846  return cur ? 0 : -1;
3847 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
enum ast_doc_src docsrc
Definition: pbx.h:104
#define ast_verb(level,...)
Definition: logger.h:243
Data structure associated with a custom dialplan function.
Definition: pbx.h:95
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:565
Definition: pbx.c:1231
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:542
#define ast_free(a)
Definition: astmm.h:97
Extra information for an ast_custom_function holding privilege escalation information. Kept in a separate structure for ABI compatibility.
Definition: pbx.c:1237
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:870
const char * name
Definition: pbx.h:96
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:253
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:602
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 8396 of file pbx.c.

References ast_free, and ast_timing::timezone.

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

8397 {
8398  if (i->timezone) {
8399  ast_free(i->timezone);
8400  i->timezone = NULL;
8401  }
8402  return 0;
8403 }
char * timezone
Definition: pbx.h:145
#define ast_free(a)
Definition: astmm.h:97
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 4844 of file pbx.c.

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

Referenced by ast_extension_state3().

4845 {
4846  switch (devstate) {
4847  case AST_DEVICE_ONHOLD:
4848  return AST_EXTENSION_ONHOLD;
4849  case AST_DEVICE_BUSY:
4850  return AST_EXTENSION_BUSY;
4851  case AST_DEVICE_UNKNOWN:
4852  return AST_EXTENSION_NOT_INUSE;
4854  case AST_DEVICE_INVALID:
4856  case AST_DEVICE_RINGINUSE:
4858  case AST_DEVICE_RINGING:
4859  return AST_EXTENSION_RINGING;
4860  case AST_DEVICE_INUSE:
4861  return AST_EXTENSION_INUSE;
4862  case AST_DEVICE_NOT_INUSE:
4863  return AST_EXTENSION_NOT_INUSE;
4864  case AST_DEVICE_TOTAL: /* not a device state, included for completeness */
4865  break;
4866  }
4867 
4868  return AST_EXTENSION_NOT_INUSE;
4869 }
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 5400 of file pbx.c.

References E_MATCH, and pbx_extension_helper().

Referenced by __analog_ss_thread(), __ast_goto_if_exists(), __ast_pbx_run(), _macro_exec(), acf_isexten_exec(), analog_ss_thread(), answer_call(), ast_app_dtget(), ast_bridge_call(), ast_pbx_outgoing_exten(), cb_events(), cli_console_dial(), conf_run(), console_dial(), console_transfer(), dahdi_handle_dtmf(), dahdi_r2_on_call_offered(), dahdi_r2_on_dnis_digit_received(), dial_exec_full(), disa_exec(), dp_lookup(), dundi_lookup_local(), findmeexec(), get_also_info(), get_destination(), get_refer_info(), gosub_exec(), handle_gosub(), handle_stimulus_message(), isexten_function_read(), leave_voicemail(), local_alloc(), local_call(), local_devicestate(), loopback_exists(), metermaidstate(), mgcp_ss(), minivm_greet_exec(), misdn_overlap_dial_task(), my_handle_dtmf(), parkandannounce_exec(), pbx_builtin_waitexten(), phone_check_exception(), pri_dchannel(), pri_ss_thread(), privacy_exec(), process_ast_dsp(), process_sdp(), readexten_exec(), register_peer_exten(), show_debug_helper(), sip_new(), sip_read(), skinny_ss(), socket_process(), try_calling(), vm_authenticate(), and waitstream_core().

5401 {
5402  return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCH, 0, 0);
5403 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
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:4706
int ast_explicit_goto ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority 
)
Note
This function will handle locking the channel as needed.

Definition at line 8708 of file pbx.c.

References ast_channel_lock, ast_channel_unlock, ast_copy_string(), AST_FLAG_IN_AUTOLOOP, ast_strlen_zero(), ast_test_flag, ast_channel::context, ast_channel::exten, and ast_channel::priority.

Referenced by __ast_goto_if_exists(), ast_async_goto(), builtin_atxfer(), disa_exec(), do_bridge_masquerade(), handle_setpriority(), and pbx_parseable_goto().

8709 {
8710  if (!chan)
8711  return -1;
8712 
8713  ast_channel_lock(chan);
8714 
8715  if (!ast_strlen_zero(context))
8716  ast_copy_string(chan->context, context, sizeof(chan->context));
8717  if (!ast_strlen_zero(exten))
8718  ast_copy_string(chan->exten, exten, sizeof(chan->exten));
8719  if (priority > -1) {
8720  chan->priority = priority;
8721  /* see flag description in channel.h for explanation */
8723  chan->priority--;
8724  }
8725 
8726  ast_channel_unlock(chan);
8727 
8728  return 0;
8729 }
#define ast_channel_lock(chan)
Definition: channel.h:2466
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
int priority
Definition: channel.h:841
#define ast_test_flag(p, flag)
Definition: utils.h:63
char context[AST_MAX_CONTEXT]
Definition: channel.h:868
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_channel_unlock(chan)
Definition: channel.h:2467
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
char exten[AST_MAX_EXTENSION]
Definition: channel.h:869
int ast_extension_close ( const char *  pattern,
const char *  data,
int  needmore 
)

Definition at line 2948 of file pbx.c.

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

Referenced by lua_find_extension(), and realtime_switch_common().

2949 {
2950  if (needmore != E_MATCHMORE && needmore != E_CANMATCH)
2951  ast_log(LOG_WARNING, "invalid argument %d\n", needmore);
2952  return extension_match_core(pattern, data, needmore);
2953 }
#define LOG_WARNING
Definition: logger.h:144
static int extension_match_core(const char *pattern, const char *data, enum ext_match_t mode)
Definition: pbx.c:2930
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
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 2713 of file pbx.c.

References ext_cmp().

Referenced by lua_extension_cmp().

2714 {
2715  int cmp;
2716 
2717  cmp = ext_cmp(a, b);
2718  if (cmp < 0) {
2719  return -1;
2720  }
2721  if (cmp > 0) {
2722  return 1;
2723  }
2724  return 0;
2725 }
static int ext_cmp(const char *left, const char *right)
Definition: pbx.c:2691
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 2943 of file pbx.c.

References E_MATCH, and extension_match_core().

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

2944 {
2945  return extension_match_core(pattern, data, E_MATCH);
2946 }
static int extension_match_core(const char *pattern, const char *data, enum ext_match_t mode)
Definition: pbx.c:2930
int ast_extension_patmatch ( const char *  pattern,
const char *  data 
)
int ast_extension_state ( struct ast_channel c,
const char *  context,
const char *  exten 
)

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

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

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

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

4915 {
4916  struct ast_exten *e;
4917 
4918  if (!(e = ast_hint_extension(c, context, exten))) { /* Do we have a hint for this extension ? */
4919  return -1; /* No hint, return -1 */
4920  }
4921 
4922  if (e->exten[0] == '_') {
4923  /* Create this hint on-the-fly */
4924  ast_add_extension(e->parent->name, 0, exten, e->priority, e->label,
4925  e->matchcid ? e->cidmatch : NULL, e->app, ast_strdup(e->data), ast_free_ptr,
4926  e->registrar);
4927  if (!(e = ast_hint_extension(c, context, exten))) {
4928  /* Improbable, but not impossible */
4929  return -1;
4930  }
4931  }
4932 
4933  return ast_extension_state2(e); /* Check all devices in the hint */
4934 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
ast_exten: An extension The dialplan is saved as a linked list with each context having it&#39;s own link...
Definition: pbx.c:884
#define ast_strdup(a)
Definition: astmm.h:109
static int ast_extension_state2(struct ast_exten *e)
Check state of extension by using hints.
Definition: pbx.c:4889
const char * label
Definition: pbx.c:889
void ast_free_ptr(void *ptr)
int matchcid
Definition: pbx.c:886
int priority
Definition: pbx.c:888
static struct ast_exten * ast_hint_extension(struct ast_channel *c, const char *context, const char *exten)
Definition: pbx.c:4835
char * exten
Definition: pbx.c:885
char name[0]
Definition: pbx.c:967
void * data
Definition: pbx.c:893
const char * registrar
Definition: pbx.c:898
const char * cidmatch
Definition: pbx.c:887
struct ast_context * parent
Definition: pbx.c:890
int ast_add_extension(const char *context, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar)
Add and extension to an extension context.
Definition: pbx.c:8691
const char * app
Definition: pbx.c:891
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
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 4902 of file pbx.c.

References ARRAY_LEN, extension_states, and cfextension_states::text.

Referenced by cb_extensionstate(), handle_request_subscribe(), handle_show_hint(), handle_show_hints(), hints_data_provider_get(), and show_channels_cb().

4903 {
4904  int i;
4905 
4906  for (i = 0; (i < ARRAY_LEN(extension_states)); i++) {
4907  if (extension_states[i].extension_state == extension_state)
4908  return extension_states[i].text;
4909  }
4910  return "Unknown";
4911 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
const char *const text
Definition: pbx.c:1033
static struct cfextension_states extension_states[]
int ast_extension_state_add ( const char *  context,
const char *  exten,
ast_state_cb_type  change_cb,
void *  data 
)

Registers a state change callback.

Parameters
contextwhich context to look in
extenwhich extension to get state
change_cbcallback to call if state changed
datato pass to callback
Note
The change_cb is called if the state of an extension is changed.
Return values
-1on failure
IDon success

Registers a state change callback.

Definition at line 5135 of file pbx.c.

References ast_extension_state_add_destroy().

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

5137 {
5138  return ast_extension_state_add_destroy(context, exten, change_cb, NULL, data);
5139 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
int ast_extension_state_add_destroy(const char *context, const char *exten, ast_state_cb_type change_cb, ast_state_cb_destroy_type destroy_cb, void *data)
Registers a state change callback with destructor.
Definition: pbx.c:5048
void * data
Definition: pbx.c:893
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
int ast_extension_state_add_destroy ( const char *  context,
const char *  exten,
ast_state_cb_type  change_cb,
ast_state_cb_destroy_type  destroy_cb,
void *  data 
)

Registers a state change callback with destructor.

Since
1.8.9
10.1.0
Parameters
contextwhich context to look in
extenwhich extension to get state
change_cbcallback to call if state changed
destroy_cbcallback to call when registration destroyed.
datato pass to callback
Note
The change_cb is called if the state of an extension is changed.
The destroy_cb is called when the registration is deleted so the registerer can release any associated resources.
Return values
-1on failure
IDon success

Registers a state change callback with destructor.

Definition at line 5048 of file pbx.c.

References ao2_alloc, ao2_find, ao2_link, ao2_lock, ao2_ref, ao2_unlock, ast_exten::app, ast_add_extension(), ast_free_ptr(), ast_hint_extension(), ast_strdup, ast_hint::callbacks, ast_state_cb::change_cb, ast_exten::cidmatch, ast_exten::data, ast_sw::data, ast_state_cb::data, ast_state_cb::destroy_cb, destroy_state_cb(), ast_exten::exten, hints, ast_state_cb::id, id, ast_exten::label, ast_exten::matchcid, ast_context::name, OBJ_NODATA, OBJ_UNLINK, ast_exten::parent, ast_exten::priority, ast_exten::registrar, statecbs, and stateid.

Referenced by ast_extension_state_add(), and handle_request_subscribe().

5050 {
5051  struct ast_hint *hint;
5052  struct ast_state_cb *state_cb;
5053  struct ast_exten *e;
5054  int id;
5055 
5056  /* If there's no context and extension: add callback to statecbs list */
5057  if (!context && !exten) {
5058  /* Prevent multiple adds from adding the same change_cb at the same time. */
5059  ao2_lock(statecbs);
5060 
5061  /* Remove any existing change_cb. */
5062  ao2_find(statecbs, change_cb, OBJ_UNLINK | OBJ_NODATA);
5063 
5064  /* Now insert the change_cb */
5065  if (!(state_cb = ao2_alloc(sizeof(*state_cb), destroy_state_cb))) {
5067  return -1;
5068  }
5069  state_cb->id = 0;
5070  state_cb->change_cb = change_cb;
5071  state_cb->destroy_cb = destroy_cb;
5072  state_cb->data = data;
5073  ao2_link(statecbs, state_cb);
5074 
5075  ao2_ref(state_cb, -1);
5077  return 0;
5078  }
5079 
5080  if (!context || !exten)
5081  return -1;
5082 
5083  /* This callback type is for only one hint, so get the hint */
5084  e = ast_hint_extension(NULL, context, exten);
5085  if (!e) {
5086  return -1;
5087  }
5088 
5089  /* If this is a pattern, dynamically create a new extension for this
5090  * particular match. Note that this will only happen once for each
5091  * individual extension, because the pattern will no longer match first.
5092  */
5093  if (e->exten[0] == '_') {
5094  ast_add_extension(e->parent->name, 0, exten, e->priority, e->label,
5095  e->matchcid ? e->cidmatch : NULL, e->app, ast_strdup(e->data), ast_free_ptr,
5096  e->registrar);
5097  e = ast_hint_extension(NULL, context, exten);
5098  if (!e || e->exten[0] == '_') {
5099  return -1;
5100  }
5101  }
5102 
5103  /* Find the hint in the hints container */
5104  ao2_lock(hints);/* Locked to hold off ast_merge_contexts_and_delete */
5105  hint = ao2_find(hints, e, 0);
5106  if (!hint) {
5107  ao2_unlock(hints);
5108  return -1;
5109  }
5110 
5111  /* Now insert the callback in the callback list */
5112  if (!(state_cb = ao2_alloc(sizeof(*state_cb), destroy_state_cb))) {
5113  ao2_ref(hint, -1);
5114  ao2_unlock(hints);
5115  return -1;
5116  }
5117  do {
5118  id = stateid++; /* Unique ID for this callback */
5119  /* Do not allow id to ever be -1 or 0. */
5120  } while (id == -1 || id == 0);
5121  state_cb->id = id;
5122  state_cb->change_cb = change_cb; /* Pointer to callback routine */
5123  state_cb->destroy_cb = destroy_cb;
5124  state_cb->data = data; /* Data for the callback */
5125  ao2_link(hint->callbacks, state_cb);
5126 
5127  ao2_ref(state_cb, -1);
5128  ao2_ref(hint, -1);
5129  ao2_unlock(hints);
5130 
5131  return id;
5132 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
ast_exten: An extension The dialplan is saved as a linked list with each context having it&#39;s own link...
Definition: pbx.c:884
#define ao2_link(arg1, arg2)
Definition: astobj2.h:785
#define ast_strdup(a)
Definition: astmm.h:109
ast_state_cb: An extension state notify register item
Definition: pbx.c:989
static int stateid
Definition: pbx.c:1305
#define ao2_unlock(a)
Definition: astobj2.h:497
const char * label
Definition: pbx.c:889
static struct ao2_container * hints
Definition: pbx.c:1314
void ast_free_ptr(void *ptr)
ast_state_cb_type change_cb
Definition: pbx.c:995
int matchcid
Definition: pbx.c:886
int priority
Definition: pbx.c:888
int id
Definition: pbx.c:991
static struct ast_exten * ast_hint_extension(struct ast_channel *c, const char *context, const char *exten)
Definition: pbx.c:4835
#define ao2_ref(o, delta)
Definition: astobj2.h:472
#define ao2_lock(a)
Definition: astobj2.h:488
char * exten
Definition: pbx.c:885
char name[0]
Definition: pbx.c:967
void * data
Definition: pbx.c:893
ast_state_cb_destroy_type destroy_cb
Definition: pbx.c:997
Structure for dial plan hints.
Definition: pbx.c:1010
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:430
#define ao2_find(arg1, arg2, arg3)
Definition: astobj2.h:964
const char * registrar
Definition: pbx.c:898
static void destroy_state_cb(void *doomed)
Definition: pbx.c:5038
const char * cidmatch
Definition: pbx.c:887
struct ast_context * parent
Definition: pbx.c:890
int ast_add_extension(const char *context, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar)
Add and extension to an extension context.
Definition: pbx.c:8691
const char * app
Definition: pbx.c:891
static struct ao2_container * statecbs
Definition: pbx.c:1316
enum queue_result id
Definition: app_queue.c:1090
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
void * data
Definition: pbx.c:993
struct ao2_container * callbacks
Definition: pbx.c:1018
int ast_extension_state_del ( int  id,
ast_state_cb_type  change_cb 
)

Deletes a registered state change callback by ID.

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

Deletes a registered state change callback by ID.

Definition at line 5157 of file pbx.c.

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

Referenced by dialog_unlink_all(), handle_request_subscribe(), skinny_unregister(), and unload_module().

5158 {
5159  struct ast_state_cb *p_cur;
5160  int ret = -1;
5161 
5162  if (!id) { /* id == 0 is a callback without extension */
5163  if (!change_cb) {
5164  return ret;
5165  }
5167  if (p_cur) {
5168  ret = 0;
5169  ao2_ref(p_cur, -1);
5170  }
5171  } else { /* callback with extension, find the callback based on ID */
5172  struct ast_hint *hint;
5173 
5174  ao2_lock(hints);/* Locked to hold off ast_merge_contexts_and_delete */
5175  hint = ao2_callback(hints, 0, find_hint_by_cb_id, &id);
5176  if (hint) {
5177  p_cur = ao2_find(hint->callbacks, &id, OBJ_UNLINK);
5178  if (p_cur) {
5179  ret = 0;
5180  ao2_ref(p_cur, -1);
5181  }
5182  ao2_ref(hint, -1);
5183  }
5184  ao2_unlock(hints);
5185  }
5186 
5187  return ret;
5188 }
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:910
ast_state_cb: An extension state notify register item
Definition: pbx.c:989
#define ao2_unlock(a)
Definition: astobj2.h:497
static struct ao2_container * hints
Definition: pbx.c:1314
ast_state_cb_type change_cb
Definition: pbx.c:995
#define ao2_ref(o, delta)
Definition: astobj2.h:472
#define ao2_lock(a)
Definition: astobj2.h:488
Structure for dial plan hints.
Definition: pbx.c:1010
#define ao2_find(arg1, arg2, arg3)
Definition: astobj2.h:964
static int find_hint_by_cb_id(void *obj, void *arg, int flags)
Remove a watcher from the callback list.
Definition: pbx.c:5142
static struct ao2_container * statecbs
Definition: pbx.c:1316
struct ao2_container * callbacks
Definition: pbx.c:1018
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 5405 of file pbx.c.

References E_FINDLABEL, and pbx_extension_helper().

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

5406 {
5407  return pbx_extension_helper(c, NULL, context, exten, 0, label, callerid, E_FINDLABEL, 0, 0);
5408 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
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:4706
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 5410 of file pbx.c.

References E_FINDLABEL, and pbx_extension_helper().

Referenced by pbx_load_config().

5411 {
5412  return pbx_extension_helper(c, con, NULL, exten, 0, label, callerid, E_FINDLABEL, 0, 0);
5413 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
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:4706
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 4177 of file pbx.c.

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

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

4178 {
4179  char *copy = ast_strdupa(function);
4180  char *args = func_args(copy);
4181  struct ast_custom_function *acfptr = ast_custom_function_find(copy);
4182  int res;
4183  struct ast_module_user *u = NULL;
4184 
4185  if (acfptr == NULL) {
4186  ast_log(LOG_ERROR, "Function %s not registered\n", copy);
4187  } else if (!acfptr->read && !acfptr->read2) {
4188  ast_log(LOG_ERROR, "Function %s cannot be read\n", copy);
4189  } else if (!is_read_allowed(acfptr)) {
4190  ast_log(LOG_ERROR, "Dangerous function %s read blocked\n", copy);
4191  } else if (acfptr->read) {
4192  if (acfptr->mod) {
4193  u = __ast_module_user_add(acfptr->mod, chan);
4194  }
4195  res = acfptr->read(chan, copy, args, workspace, len);
4196  if (acfptr->mod && u) {
4197  __ast_module_user_remove(acfptr->mod, u);
4198  }
4199  return res;
4200  } else {
4201  struct ast_str *str = ast_str_create(16);
4202  if (acfptr->mod) {
4203  u = __ast_module_user_add(acfptr->mod, chan);
4204  }
4205  res = acfptr->read2(chan, copy, args, &str, 0);
4206  if (acfptr->mod && u) {
4207  __ast_module_user_remove(acfptr->mod, u);
4208  }
4209  ast_copy_string(workspace, ast_str_buffer(str), len > ast_str_size(str) ? ast_str_size(str) : len);
4210  ast_free(str);
4211  return res;
4212  }
4213  return -1;
4214 }
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition: strings.h:482
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
void __ast_module_user_remove(struct ast_module *, struct ast_module_user *)
Definition: loader.c:231
static int copy(char *infile, char *outfile)
Utility function to copy a file.
struct ast_str * ast_str_create(size_t init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:420
struct ast_module * mod
Definition: pbx.h:119
const char * str
Definition: app_jack.c:144
Data structure associated with a custom dialplan function.
Definition: pbx.h:95
static int is_read_allowed(struct ast_custom_function *acfptr)
Determines whether execution of a custom function&#39;s read function is allowed.
Definition: pbx.c:4119
struct ast_module_user * __ast_module_user_add(struct ast_module *, struct ast_channel *)
Definition: loader.c:209
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
struct ast_custom_function * ast_custom_function_find(const char *name)
Definition: pbx.c:3800
#define LOG_ERROR
Definition: logger.h:155
ast_acf_read2_fn_t read2
Definition: pbx.h:114
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
static struct @350 args
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_free(a)
Definition: astmm.h:97
ast_acf_read_fn_t read
Definition: pbx.h:106
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
static char * func_args(char *function)
return a pointer to the arguments of the function, and terminates the function name with &#39;\0&#39; ...
Definition: pbx.c:4041
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 4216 of file pbx.c.

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

Referenced by append_channel_vars(), and ast_str_substitute_variables_full().

4217 {
4218  char *copy = ast_strdupa(function);
4219  char *args = func_args(copy);
4220  struct ast_custom_function *acfptr = ast_custom_function_find(copy);
4221  int res;
4222  struct ast_module_user *u = NULL;
4223 
4224  if (acfptr == NULL) {
4225  ast_log(LOG_ERROR, "Function %s not registered\n", copy);
4226  } else if (!acfptr->read && !acfptr->read2) {
4227  ast_log(LOG_ERROR, "Function %s cannot be read\n", copy);
4228  } else if (!is_read_allowed(acfptr)) {
4229  ast_log(LOG_ERROR, "Dangerous function %s read blocked\n", copy);
4230  } else {
4231  if (acfptr->mod) {
4232  u = __ast_module_user_add(acfptr->mod, chan);
4233  }
4234  ast_str_reset(*str);
4235  if (acfptr->read2) {
4236  /* ast_str enabled */
4237  res = acfptr->read2(chan, copy, args, str, maxlen);
4238  } else {
4239  /* Legacy function pointer, allocate buffer for result */
4240  int maxsize = ast_str_size(*str);
4241  if (maxlen > -1) {
4242  if (maxlen == 0) {
4243  if (acfptr->read_max) {
4244  maxsize = acfptr->read_max;
4245  } else {
4246  maxsize = VAR_BUF_SIZE;
4247  }
4248  } else {
4249  maxsize = maxlen;
4250  }
4251  ast_str_make_space(str, maxsize);
4252  }
4253  res = acfptr->read(chan, copy, args, ast_str_buffer(*str), maxsize);
4254  }
4255  if (acfptr->mod && u) {
4256  __ast_module_user_remove(acfptr->mod, u);
4257  }
4258  return res;
4259  }
4260  return -1;
4261 }
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition: strings.h:482
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
void __ast_module_user_remove(struct ast_module *, struct ast_module_user *)
Definition: loader.c:231
static int copy(char *infile, char *outfile)
Utility function to copy a file.
struct ast_module * mod
Definition: pbx.h:119
int ast_str_make_space(struct ast_str **buf, size_t new_len)
Definition: strings.h:588
Data structure associated with a custom dialplan function.
Definition: pbx.h:95
static int is_read_allowed(struct ast_custom_function *acfptr)
Determines whether execution of a custom function&#39;s read function is allowed.
Definition: pbx.c:4119
size_t read_max
Definition: pbx.h:116
struct ast_module_user * __ast_module_user_add(struct ast_module *, struct ast_channel *)
Definition: loader.c:209
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
struct ast_custom_function * ast_custom_function_find(const char *name)
Definition: pbx.c:3800
#define LOG_ERROR
Definition: logger.h:155
ast_acf_read2_fn_t read2
Definition: pbx.h:114
static struct @350 args
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static int maxsize
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:436
ast_acf_read_fn_t read
Definition: pbx.h:106
static char * func_args(char *function)
return a pointer to the arguments of the function, and terminates the function name with &#39;\0&#39; ...
Definition: pbx.c:4041
#define VAR_BUF_SIZE
Definition: pbx.c:833
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 4263 of file pbx.c.

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

Referenced by conf_run(), pbx_builtin_pushvar_helper(), and pbx_builtin_setvar_helper().

4264 {
4265  char *copy = ast_strdupa(function);
4266  char *args = func_args(copy);
4267  struct ast_custom_function *acfptr = ast_custom_function_find(copy);
4268 
4269  if (acfptr == NULL) {
4270  ast_log(LOG_ERROR, "Function %s not registered\n", copy);
4271  } else if (!acfptr->write) {
4272  ast_log(LOG_ERROR, "Function %s cannot be written to\n", copy);
4273  } else if (!is_write_allowed(acfptr)) {
4274  ast_log(LOG_ERROR, "Dangerous function %s write blocked\n", copy);
4275  } else {
4276  int res;
4277  struct ast_module_user *u = NULL;
4278  if (acfptr->mod)
4279  u = __ast_module_user_add(acfptr->mod, chan);
4280  res = acfptr->write(chan, copy, args, value);
4281  if (acfptr->mod && u)
4282  __ast_module_user_remove(acfptr->mod, u);
4283  return res;
4284  }
4285 
4286  return -1;
4287 }
void __ast_module_user_remove(struct ast_module *, struct ast_module_user *)
Definition: loader.c:231
static int is_write_allowed(struct ast_custom_function *acfptr)
Determines whether execution of a custom function&#39;s write function is allowed.
Definition: pbx.c:4152
static int copy(char *infile, char *outfile)
Utility function to copy a file.
struct ast_module * mod
Definition: pbx.h:119
int value
Definition: syslog.c:39
Data structure associated with a custom dialplan function.
Definition: pbx.h:95
ast_acf_write_fn_t write
Definition: pbx.h:118
struct ast_module_user * __ast_module_user_add(struct ast_module *, struct ast_channel *)
Definition: loader.c:209
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
struct ast_custom_function * ast_custom_function_find(const char *name)
Definition: pbx.c:3800
#define LOG_ERROR
Definition: logger.h:155
static struct @350 args
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static char * func_args(char *function)
return a pointer to the arguments of the function, and terminates the function name with &#39;\0&#39; ...
Definition: pbx.c:4041
const char* ast_get_context_registrar ( struct ast_context c)

Definition at line 11111 of file pbx.c.

References ast_context::registrar.

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

11112 {
11113  return c ? c->registrar : NULL;
11114 }
char * registrar
Definition: pbx.c:963
void* ast_get_extension_app_data ( struct ast_exten e)
const char* ast_get_extension_cidmatch ( struct ast_exten e)

Definition at line 11136 of file pbx.c.

References ast_exten::cidmatch.

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

11137 {
11138  return e ? e->cidmatch : NULL;
11139 }
const char * cidmatch
Definition: pbx.c:887
struct ast_context* ast_get_extension_context ( struct ast_exten exten)

Definition at line 11078 of file pbx.c.

References ast_exten::parent.

Referenced by ast_remove_hint(), destroy_hint(), handle_show_hint(), handle_show_hints(), handle_statechange(), and hints_data_provider_get().

11079 {
11080  return exten ? exten->parent : NULL;
11081 }
struct ast_context * parent
Definition: pbx.c:890
const char* ast_get_extension_label ( struct ast_exten e)

Definition at line 11088 of file pbx.c.

References ast_exten::label.

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

11089 {
11090  return exten ? exten->label : NULL;
11091 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
int ast_get_extension_matchcid ( struct ast_exten e)

Definition at line 11131 of file pbx.c.

References ast_exten::matchcid.

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

11132 {
11133  return e ? e->matchcid : 0;
11134 }
int matchcid
Definition: pbx.c:886
int ast_get_extension_priority ( struct ast_exten exten)

Definition at line 11103 of file pbx.c.

References ast_exten::priority.

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

11104 {
11105  return exten ? exten->priority : -1;
11106 }
int priority
Definition: pbx.c:888
const char* ast_get_extension_registrar ( struct ast_exten e)

Definition at line 11116 of file pbx.c.

References ast_exten::registrar.

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

11117 {
11118  return e ? e->registrar : NULL;
11119 }
const char * registrar
Definition: pbx.c:898
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 5362 of file pbx.c.

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

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

5363 {
5364  struct ast_exten *e = ast_hint_extension(c, context, exten);
5365 
5366  if (e) {
5367  if (hint)
5368  ast_copy_string(hint, ast_get_extension_app(e), hintsize);
5369  if (name) {
5370  const char *tmp = ast_get_extension_app_data(e);
5371  if (tmp)
5372  ast_copy_string(name, tmp, namesize);
5373  }
5374  return -1;
5375  }
5376  return 0;
5377 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
ast_exten: An extension The dialplan is saved as a linked list with each context having it&#39;s own link...
Definition: pbx.c:884
const char * ast_get_extension_app(struct ast_exten *e)
Definition: pbx.c:11141
void * ast_get_extension_app_data(struct ast_exten *e)
Definition: pbx.c:11146
static struct ast_exten * ast_hint_extension(struct ast_channel *c, const char *context, const char *exten)
Definition: pbx.c:4835
static const char name[]
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
const char* ast_get_ignorepat_name ( struct ast_ignorepat ip)
const char* ast_get_ignorepat_registrar ( struct ast_ignorepat ip)

Definition at line 11126 of file pbx.c.

References ast_ignorepat::registrar.

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

11127 {
11128  return ip ? ip->registrar : NULL;
11129 }
const char * registrar
Definition: pbx.c:926
const char* ast_get_include_name ( struct ast_include include)
const char* ast_get_include_registrar ( struct ast_include i)

Definition at line 11121 of file pbx.c.

References ast_include::registrar.

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

11122 {
11123  return i ? i->registrar : NULL;
11124 }
const char * registrar
Definition: pbx.c:907
const char* ast_get_switch_data ( struct ast_sw sw)

Definition at line 11156 of file pbx.c.

References ast_sw::data.

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

11157 {
11158  return sw ? sw->data : NULL;
11159 }
char * data
Definition: pbx.c:918
int ast_get_switch_eval ( struct ast_sw sw)

Definition at line 11161 of file pbx.c.

References ast_sw::eval.

Referenced by context_merge_incls_swits_igps_other_registrars().

11162 {
11163  return sw->eval;
11164 }
int eval
Definition: pbx.c:919
const char* ast_get_switch_name ( struct ast_sw sw)

Definition at line 11151 of file pbx.c.

References ast_sw::name.

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

11152 {
11153  return sw ? sw->name : NULL;
11154 }
char * name
Definition: pbx.c:916
const char* ast_get_switch_registrar ( struct ast_sw sw)

Definition at line 11166 of file pbx.c.

References ast_sw::registrar.

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

11167 {
11168  return sw ? sw->registrar : NULL;
11169 }
const char * registrar
Definition: pbx.c:917
int ast_goto_if_exists ( struct ast_channel chan,
const char *  context,
const char *  exten,
int  priority 
)
Note
This function will handle locking the channel as needed.

Definition at line 11261 of file pbx.c.

References __ast_goto_if_exists().

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

11262 {
11263  return __ast_goto_if_exists(chan, context, exten, priority, 0);
11264 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
static int __ast_goto_if_exists(struct ast_channel *chan, const char *context, const char *exten, int priority, int async)
Definition: pbx.c:11240
int priority
Definition: pbx.c:888
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
int ast_hashtab_compare_contexts ( const void *  ah_a,
const void *  ah_b 
)

hashtable functions for contexts

Definition at line 1136 of file pbx.c.

References ast_context::name.

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

1137 {
1138  const struct ast_context *ac = ah_a;
1139  const struct ast_context *bc = ah_b;
1140  if (!ac || !bc) /* safety valve, but it might prevent a crash you'd rather have happen */
1141  return 1;
1142  /* assume context names are registered in a string table! */
1143  return strcmp(ac->name, bc->name);
1144 }
char name[0]
Definition: pbx.c:967
ast_context: An extension context
Definition: pbx.c:955
unsigned int ast_hashtab_hash_contexts ( const void *  obj)

Definition at line 1188 of file pbx.c.

References ast_hashtab_hash_string(), and ast_context::name.

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

1189 {
1190  const struct ast_context *ac = obj;
1191  return ast_hashtab_hash_string(ac->name);
1192 }
char name[0]
Definition: pbx.c:967
unsigned int ast_hashtab_hash_string(const void *obj)
Hashes a string to a number.
Definition: hashtab.c:157
ast_context: An extension context
Definition: pbx.c:955
int ast_ignore_pattern ( const char *  context,
const char *  pattern 
)

Checks to see if a number should be ignored.

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

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

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

Definition at line 8650 of file pbx.c.

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

Referenced by __analog_ss_thread(), analog_ss_thread(), ast_app_dtget(), disa_exec(), dp_lookup(), dundi_lookup_local(), handle_enbloc_call_message(), handle_soft_key_event_message(), handle_stimulus_message(), mgcp_ss(), pri_dchannel(), pri_ss_thread(), and skinny_ss().

8651 {
8652  struct ast_context *con = ast_context_find(context);
8653 
8654  if (con) {
8655  struct ast_ignorepat *pat;
8656 
8657  for (pat = con->ignorepats; pat; pat = pat->next) {
8658  if (ast_extension_match(pat->pattern, pattern))
8659  return 1;
8660  }
8661  }
8662 
8663  return 0;
8664 }
struct ast_ignorepat * ignorepats
Definition: pbx.c:962
const char pattern[0]
Definition: pbx.c:928
ast_ignorepat: Ignore patterns in dial plan
Definition: pbx.c:925
int ast_extension_match(const char *pattern, const char *extension)
Determine if a given extension matches a given pattern (in NXX format)
Definition: pbx.c:2943
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
ast_context: An extension context
Definition: pbx.c:955
struct ast_ignorepat * next
Definition: pbx.c:927
struct ast_context * ast_context_find(const char *name)
Find a context.
Definition: pbx.c:2971
int ast_matchmore_extension ( struct ast_channel c,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid 
)

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

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

Definition at line 5420 of file pbx.c.

References E_MATCHMORE, and pbx_extension_helper().

Referenced by __analog_ss_thread(), __ast_pbx_run(), analog_ss_thread(), ast_app_dtget(), collect_digits(), dahdi_r2_on_dnis_digit_received(), disa_exec(), dp_lookup(), dundi_lookup_local(), loopback_matchmore(), mgcp_ss(), pbx_builtin_background(), pri_dchannel(), pri_ss_thread(), readexten_exec(), and skinny_ss().

5421 {
5422  return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCHMORE, 0, 0);
5423 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
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:4706
void ast_merge_contexts_and_delete ( struct ast_context **  extcontexts,
struct ast_hashtab exttable,
const char *  registrar 
)

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

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

Definition at line 7937 of file pbx.c.

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

Referenced by lua_reload_extensions(), and pbx_load_module().

7938 {
7939  double ft;
7940  struct ast_context *tmp;
7941  struct ast_context *oldcontextslist;
7942  struct ast_hashtab *oldtable;
7943  struct store_hints hints_stored = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
7944  struct store_hints hints_removed = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
7945  struct store_hint *saved_hint;
7946  struct ast_hint *hint;
7947  struct ast_exten *exten;
7948  int length;
7949  struct ast_state_cb *thiscb;
7950  struct ast_hashtab_iter *iter;
7951  struct ao2_iterator i;
7952  struct timeval begintime;
7953  struct timeval writelocktime;
7954  struct timeval endlocktime;
7955  struct timeval enddeltime;
7956 
7957  /*
7958  * It is very important that this function hold the hints
7959  * container lock _and_ the conlock during its operation; not
7960  * only do we need to ensure that the list of contexts and
7961  * extensions does not change, but also that no hint callbacks
7962  * (watchers) are added or removed during the merge/delete
7963  * process
7964  *
7965  * In addition, the locks _must_ be taken in this order, because
7966  * there are already other code paths that use this order
7967  */
7968 
7969  begintime = ast_tvnow();
7970  ast_mutex_lock(&context_merge_lock);/* Serialize ast_merge_contexts_and_delete */
7972 
7973  if (!contexts_table) {
7974  /* Well, that's odd. There are no contexts. */
7975  contexts_table = exttable;
7976  contexts = *extcontexts;
7979  return;
7980  }
7981 
7983  while ((tmp = ast_hashtab_next(iter))) {
7984  context_merge(extcontexts, exttable, tmp, registrar);
7985  }
7987 
7988  ao2_lock(hints);
7989  writelocktime = ast_tvnow();
7990 
7991  /* preserve all watchers for hints */
7993  for (; (hint = ao2_iterator_next(&i)); ao2_ref(hint, -1)) {
7994  if (ao2_container_count(hint->callbacks)) {
7995  ao2_lock(hint);
7996  if (!hint->exten) {
7997  /* The extension has already been destroyed. (Should never happen here) */
7998  ao2_unlock(hint);
7999  continue;
8000  }
8001 
8002  length = strlen(hint->exten->exten) + strlen(hint->exten->parent->name) + 2
8003  + sizeof(*saved_hint);
8004  if (!(saved_hint = ast_calloc(1, length))) {
8005  ao2_unlock(hint);
8006  continue;
8007  }
8008 
8009  /* This removes all the callbacks from the hint into saved_hint. */
8010  while ((thiscb = ao2_callback(hint->callbacks, OBJ_UNLINK, NULL, NULL))) {
8011  AST_LIST_INSERT_TAIL(&saved_hint->callbacks, thiscb, entry);
8012  /*
8013  * We intentionally do not unref thiscb to account for the
8014  * non-ao2 reference in saved_hint->callbacks
8015  */
8016  }
8017 
8018  saved_hint->laststate = hint->laststate;
8019  saved_hint->context = saved_hint->data;
8020  strcpy(saved_hint->data, hint->exten->parent->name);
8021  saved_hint->exten = saved_hint->data + strlen(saved_hint->context) + 1;
8022  strcpy(saved_hint->exten, hint->exten->exten);
8023  ao2_unlock(hint);
8024  AST_LIST_INSERT_HEAD(&hints_stored, saved_hint, list);
8025  }
8026  }
8028 
8029  /* save the old table and list */
8030  oldtable = contexts_table;
8031  oldcontextslist = contexts;
8032 
8033  /* move in the new table and list */
8034  contexts_table = exttable;
8035  contexts = *extcontexts;
8036 
8037  /*
8038  * Restore the watchers for hints that can be found; notify
8039  * those that cannot be restored.
8040  */
8041  while ((saved_hint = AST_LIST_REMOVE_HEAD(&hints_stored, list))) {
8042  struct pbx_find_info q = { .stacklen = 0 };
8043 
8044  exten = pbx_find_extension(NULL, NULL, &q, saved_hint->context, saved_hint->exten,
8045  PRIORITY_HINT, NULL, "", E_MATCH);
8046  /*
8047  * If this is a pattern, dynamically create a new extension for this
8048  * particular match. Note that this will only happen once for each
8049  * individual extension, because the pattern will no longer match first.
8050  */
8051  if (exten && exten->exten[0] == '_') {
8052  ast_add_extension_nolock(exten->parent->name, 0, saved_hint->exten,
8053  PRIORITY_HINT, NULL, 0, exten->app, ast_strdup(exten->data), ast_free_ptr,
8054  exten->registrar);
8055  /* rwlocks are not recursive locks */
8056  exten = ast_hint_extension_nolock(NULL, saved_hint->context,
8057  saved_hint->exten);
8058  }
8059 
8060  /* Find the hint in the hints container */
8061  hint = exten ? ao2_find(hints, exten, 0) : NULL;
8062  if (!hint) {
8063  /*
8064  * Notify watchers of this removed hint later when we aren't
8065  * encumberd by so many locks.
8066  */
8067  AST_LIST_INSERT_HEAD(&hints_removed, saved_hint, list);
8068  } else {
8069  ao2_lock(hint);
8070  while ((thiscb = AST_LIST_REMOVE_HEAD(&saved_hint->callbacks, entry))) {
8071  ao2_link(hint->callbacks, thiscb);
8072  /* Ref that we added when putting into saved_hint->callbacks */
8073  ao2_ref(thiscb, -1);
8074  }
8075  hint->laststate = saved_hint->laststate;
8076  ao2_unlock(hint);
8077  ao2_ref(hint, -1);
8078  ast_free(saved_hint);
8079  }
8080  }
8081 
8082  ao2_unlock(hints);
8084 
8085  /*
8086  * Notify watchers of all removed hints with the same lock
8087  * environment as handle_statechange().
8088  */
8089  while ((saved_hint = AST_LIST_REMOVE_HEAD(&hints_removed, list))) {
8090  /* this hint has been removed, notify the watchers */
8091  while ((thiscb = AST_LIST_REMOVE_HEAD(&saved_hint->callbacks, entry))) {
8092  thiscb->change_cb(saved_hint->context, saved_hint->exten,
8093  AST_EXTENSION_REMOVED, thiscb->data);
8094  /* Ref that we added when putting into saved_hint->callbacks */
8095  ao2_ref(thiscb, -1);
8096  }
8097  ast_free(saved_hint);
8098  }
8099 
8101  endlocktime = ast_tvnow();
8102 
8103  /*
8104  * The old list and hashtab no longer are relevant, delete them
8105  * while the rest of asterisk is now freely using the new stuff
8106  * instead.
8107  */
8108 
8109  ast_hashtab_destroy(oldtable, NULL);
8110 
8111  for (tmp = oldcontextslist; tmp; ) {
8112  struct ast_context *next; /* next starting point */
8113 
8114  next = tmp->next;
8116  tmp = next;
8117  }
8118  enddeltime = ast_tvnow();
8119 
8120  ft = ast_tvdiff_us(writelocktime, begintime);
8121  ft /= 1000000.0;
8122  ast_verb(3,"Time to scan old dialplan and merge leftovers back into the new: %8.6f sec\n", ft);
8123 
8124  ft = ast_tvdiff_us(endlocktime, writelocktime);
8125  ft /= 1000000.0;
8126  ast_verb(3,"Time to restore hints and swap in new dialplan: %8.6f sec\n", ft);
8127 
8128  ft = ast_tvdiff_us(enddeltime, endlocktime);
8129  ft /= 1000000.0;
8130  ast_verb(3,"Time to delete the old dialplan: %8.6f sec\n", ft);
8131 
8132  ft = ast_tvdiff_us(enddeltime, begintime);
8133  ft /= 1000000.0;
8134  ast_verb(3,"Total time merge_contexts_delete: %8.6f sec\n", ft);
8135 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
ast_exten: An extension The dialplan is saved as a linked list with each context having it&#39;s own link...
Definition: pbx.c:884
#define ao2_link(arg1, arg2)
Definition: astobj2.h:785
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
Definition: astobj2.c:470
static void __ast_internal_context_destroy(struct ast_context *con)
Definition: pbx.c:9670
#define ast_strdup(a)
Definition: astmm.h:109
static struct ast_hashtab * contexts_table
Definition: pbx.c:1286
#define ao2_iterator_next(arg1)
Definition: astobj2.h:1126
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:910
struct ast_exten * exten
Hint extension.
Definition: pbx.c:1017
ast_state_cb: An extension state notify register item
Definition: pbx.c:989
void * ast_hashtab_next(struct ast_hashtab_iter *it)
Gets the next object in the list, advances iter one step returns null on end of traversal.
Definition: hashtab.c:753
char * context
Definition: pbx.c:7803
struct ast_hashtab_iter * ast_hashtab_start_traversal(struct ast_hashtab *tab)
Gives an iterator to hastable.
Definition: hashtab.c:696
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:142
#define ast_mutex_lock(a)
Definition: lock.h:155
int ast_wrlock_contexts(void)
Write locks the context list.
Definition: pbx.c:11037
static ast_mutex_t context_merge_lock
Lock to hold off restructuring of hints by ast_merge_contexts_and_delete.
Definition: pbx.c:1299
#define ao2_unlock(a)
Definition: astobj2.h:497
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags)
Create an iterator for a container.
Definition: astobj2.c:818
static struct ao2_container * hints
Definition: pbx.c:1314
void ast_free_ptr(void *ptr)
#define ast_verb(level,...)
Definition: logger.h:243
ast_state_cb_type change_cb
Definition: pbx.c:995
#define ao2_ref(o, delta)
Definition: astobj2.h:472
char * exten
Definition: pbx.c:7804
#define ao2_lock(a)
Definition: astobj2.h:488
char * exten
Definition: pbx.c:885
char name[0]
Definition: pbx.c:967
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:818
#define PRIORITY_HINT
Definition: pbx.h:53
void ast_hashtab_end_traversal(struct ast_hashtab_iter *it)
end the traversal, free the iterator, unlock if necc.
Definition: hashtab.c:746
static void context_merge(struct ast_context **extcontexts, struct ast_hashtab *exttable, struct ast_context *context, const char *registrar)
Definition: pbx.c:7846
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:716
int laststate
Definition: pbx.c:1019
void * data
Definition: pbx.c:893
int laststate
Definition: pbx.c:7806
int ast_unlock_contexts(void)
Unlocks contexts.
Definition: pbx.c:11047
Structure for dial plan hints.
Definition: pbx.c:1010
struct ast_context * next
Definition: pbx.c:960
an iterator for traversing the buckets
Definition: hashtab.h:105
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:696
char data[1]
Definition: pbx.c:7808
#define ao2_find(arg1, arg2, arg3)
Definition: astobj2.h:964
#define ast_free(a)
Definition: astmm.h:97
int stacklen
Definition: extconf.h:234
static char * registrar
Definition: features.c:623
const char * registrar
Definition: pbx.c:898
static int ast_add_extension_nolock(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)
Definition: pbx.c:8671
void ao2_iterator_destroy(struct ao2_iterator *i)
Destroy a container iterator.
Definition: astobj2.c:833
#define AST_LIST_HEAD_NOLOCK_INIT_VALUE
Defines initial values for a declaration of AST_LIST_HEAD_NOLOCK.
Definition: linkedlists.h:251
static struct ast_exten * ast_hint_extension_nolock(struct ast_channel *c, const char *context, const char *exten)
Find hint for given extension in context.
Definition: pbx.c:4829
struct ast_context * parent
Definition: pbx.c:890
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1053
#define ast_calloc(a, b)
Definition: astmm.h:82
const char * app
Definition: pbx.c:891
static struct ast_context * contexts
Definition: pbx.c:1285
int64_t ast_tvdiff_us(struct timeval end, struct timeval start)
Computes the difference (in microseconds) between two struct timeval instances.
Definition: time.h:70
struct store_hint::@294 callbacks
struct ast_exten * pbx_find_extension(struct ast_channel *chan, struct ast_context *bypass, struct pbx_find_info *q, const char *context, const char *exten, int priority, const char *label, const char *callerid, enum ext_match_t action)
Definition: pbx.c:3013
void * data
Definition: pbx.c:993
ast_context: An extension context
Definition: pbx.c:955
struct ao2_container * callbacks
Definition: pbx.c:1018
#define ast_mutex_unlock(a)
Definition: lock.h:156
void ast_hashtab_destroy(struct ast_hashtab *tab, void(*objdestroyfunc)(void *obj))
This func will free the hash table and all its memory.
Definition: hashtab.c:388
int ast_parseable_goto ( struct ast_channel chan,
const char *  goto_string 
)
Note
This function will handle locking the channel as needed.

Definition at line 11326 of file pbx.c.

References pbx_parseable_goto().

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

11327 {
11328  return pbx_parseable_goto(chan, goto_string, 0);
11329 }
static int pbx_parseable_goto(struct ast_channel *chan, const char *goto_string, int async)
Definition: pbx.c:11271
int ast_pbx_outgoing_app ( const char *  type,
format_t  format,
void *  data,
int  timeout,
const char *  app,
const char *  appdata,
int *  reason,
int  sync,
const char *  cid_num,
const char *  cid_name,
struct ast_variable vars,
const char *  account,
struct ast_channel **  locked_channel 
)

Synchronously or asynchronously make an outbound call and send it to a particular application with given extension

Definition at line 9544 of file pbx.c.

References __ast_request_and_dial(), ast_channel::_state, outgoing_helper::account, async_stat::app, async_stat::appdata, ast_calloc, ast_cdr_disposition(), ast_cdr_failed(), ast_cdr_setaccount(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_free, ast_hangup(), ast_log(), ast_pbx_outgoing_cdr_failed(), ast_pbx_run_app(), ast_pthread_create_detached, ast_set_variables(), AST_STATE_UP, ast_string_field_free_memory, ast_string_field_init, ast_string_field_set, ast_strlen_zero(), ast_variables_destroy(), ast_verb, async_wait(), ast_channel::cdr, async_stat::chan, app_tmp::chan, errno, ast_channel::hangupcause, LOG_WARNING, ast_channel::name, async_stat::p, app_tmp::t, async_stat::timeout, and outgoing_helper::vars.

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

9545 {
9546  struct ast_channel *chan;
9547  struct app_tmp *tmp;
9548  int res = -1, cdr_res = -1;
9549  struct outgoing_helper oh;
9550 
9551  memset(&oh, 0, sizeof(oh));
9552  oh.vars = vars;
9553  oh.account = account;
9554 
9555  if (locked_channel)
9556  *locked_channel = NULL;
9557  if (ast_strlen_zero(app)) {
9558  res = -1;
9559  goto outgoing_app_cleanup;
9560  }
9561  if (synchronous) {
9562  chan = __ast_request_and_dial(type, format, NULL, data, timeout, reason, cid_num, cid_name, &oh);
9563  if (chan) {
9564  ast_set_variables(chan, vars);
9565  if (account)
9566  ast_cdr_setaccount(chan, account);
9567  if (chan->_state == AST_STATE_UP) {
9568  res = 0;
9569  ast_verb(4, "Channel %s was answered.\n", chan->name);
9570  tmp = ast_calloc(1, sizeof(*tmp));
9571  if (!tmp || ast_string_field_init(tmp, 252)) {
9572  if (tmp) {
9573  ast_free(tmp);
9574  }
9575  res = -1;
9576  } else {
9577  ast_string_field_set(tmp, app, app);
9578  ast_string_field_set(tmp, data, appdata);
9579  tmp->chan = chan;
9580  if (synchronous > 1) {
9581  if (locked_channel)
9582  ast_channel_unlock(chan);
9583  ast_pbx_run_app(tmp);
9584  } else {
9585  if (locked_channel)
9586  ast_channel_lock(chan);
9587  if (ast_pthread_create_detached(&tmp->t, NULL, ast_pbx_run_app, tmp)) {
9588  ast_log(LOG_WARNING, "Unable to spawn execute thread on %s: %s\n", chan->name, strerror(errno));
9590  ast_free(tmp);
9591  if (locked_channel)
9592  ast_channel_unlock(chan);
9593  ast_hangup(chan);
9594  res = -1;
9595  } else {
9596  if (locked_channel)
9597  *locked_channel = chan;
9598  }
9599  }
9600  }
9601  } else {
9602  ast_verb(4, "Channel %s was never answered.\n", chan->name);
9603  if (chan->cdr) { /* update the cdr */
9604  /* here we update the status of the call, which sould be busy.
9605  * if that fails then we set the status to failed */
9606  if (ast_cdr_disposition(chan->cdr, chan->hangupcause))
9607  ast_cdr_failed(chan->cdr);
9608  }
9609  ast_hangup(chan);
9610  }
9611  }
9612 
9613  if (res < 0) { /* the call failed for some reason */
9614  if (*reason == 0) { /* if the call failed (not busy or no answer)
9615  * update the cdr with the failed message */
9616  cdr_res = ast_pbx_outgoing_cdr_failed();
9617  if (cdr_res != 0) {
9618  res = cdr_res;
9619  goto outgoing_app_cleanup;
9620  }
9621  }
9622  }
9623 
9624  } else {
9625  struct async_stat *as;
9626  if (!(as = ast_calloc(1, sizeof(*as)))) {
9627  res = -1;
9628  goto outgoing_app_cleanup;
9629  }
9630  chan = __ast_request_and_dial(type, format, NULL, data, timeout, reason, cid_num, cid_name, &oh);
9631  if (!chan) {
9632  ast_free(as);
9633  res = -1;
9634  goto outgoing_app_cleanup;
9635  }
9636  as->chan = chan;
9637  ast_copy_string(as->app, app, sizeof(as->app));
9638  if (appdata)
9639  ast_copy_string(as->appdata, appdata, sizeof(as->appdata));
9640  as->timeout = timeout;
9641  ast_set_variables(chan, vars);
9642  if (account)
9643  ast_cdr_setaccount(chan, account);
9644  /* Start a new thread, and get something handling this channel. */
9645  if (locked_channel)
9646  ast_channel_lock(chan);
9647  if (ast_pthread_create_detached(&as->p, NULL, async_wait, as)) {
9648  ast_log(LOG_WARNING, "Failed to start async wait\n");
9649  ast_free(as);
9650  if (locked_channel)
9651  ast_channel_unlock(chan);
9652  ast_hangup(chan);
9653  res = -1;
9654  goto outgoing_app_cleanup;
9655  } else {
9656  if (locked_channel)
9657  *locked_channel = chan;
9658  }
9659  res = 0;
9660  }
9661 outgoing_app_cleanup:
9662  ast_variables_destroy(vars);
9663  return res;
9664 }
int ast_cdr_disposition(struct ast_cdr *cdr, int cause)
Save the result of the call based on the AST_CAUSE_*.
Definition: cdr.c:790
int ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2804
#define ast_channel_lock(chan)
Definition: channel.h:2466
Main Channel structure associated with a channel.
Definition: channel.h:742
void ast_cdr_failed(struct ast_cdr *cdr)
Fail a call.
Definition: cdr.c:764
struct ast_channel * chan
Definition: pbx.c:9276
#define ast_pthread_create_detached(a, b, c, d)
Definition: utils.h:422
static int ast_pbx_outgoing_cdr_failed(void)
Function to post an empty cdr after a spool call fails.
Definition: pbx.c:9348
pthread_t p
Definition: pbx.c:9275
struct ast_channel * __ast_request_and_dial(const char *type, format_t format, const struct ast_channel *requestor, void *data, int timeout, int *reason, const char *cid_num, const char *cid_name, struct outgoing_helper *oh)
Request a channel of a given type, with data as optional information used by the low level module and...
Definition: channel.c:5456
#define LOG_WARNING
Definition: logger.h:144
int ast_cdr_setaccount(struct ast_channel *chan, const char *account)
Set account code, will generate AMI event.
Definition: cdr.c:990
void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars)
adds a list of channel variables to a channel
Definition: channel.c:8261
struct ast_cdr * cdr
Definition: channel.h:766
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: config.c:586
static char cid_num[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:157
struct ast_channel * chan
Definition: pbx.c:9519
#define ast_verb(level,...)
Definition: logger.h:243
int timeout
Definition: pbx.c:9280
struct ast_variable * vars
Definition: channel.h:1005
static const char app[]
Definition: app_adsiprog.c:49
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:249
const char * account
Definition: channel.h:1004
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
Definition: pbx.c:9518
enum ast_channel_state _state
Definition: channel.h:839
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_channel_unlock(chan)
Definition: channel.h:2467
int errno
#define ast_free(a)
Definition: astmm.h:97
char app[AST_MAX_EXTENSION]
Definition: pbx.c:9281
static const char type[]
Definition: chan_nbs.c:57
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:158
static void * async_wait(void *data)
Definition: pbx.c:9285
#define ast_calloc(a, b)
Definition: astmm.h:82
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
static void * ast_pbx_run_app(void *data)
run the application and free the descriptor once done
Definition: pbx.c:9528
int hangupcause
Definition: channel.h:849
pthread_t t
Definition: pbx.c:9520
static snd_pcm_format_t format
Definition: chan_alsa.c:93
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Definition: stringfields.h:253
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:344
char appdata[1024]
Definition: pbx.c:9282
int ast_pbx_outgoing_exten ( const char *  type,
format_t  format,
void *  data,
int  timeout,
const char *  context,
const char *  exten,
int  priority,
int *  reason,
int  sync,
const char *  cid_num,
const char *  cid_name,
struct ast_variable vars,
const char *  account,
struct ast_channel **  locked_channel 
)

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

Definition at line 9375 of file pbx.c.

References __ast_request_and_dial(), ast_channel::_state, outgoing_helper::account, ast_calloc, ast_cdr_disposition(), ast_cdr_failed(), ast_cdr_setaccount(), ast_channel_alloc(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_exists_extension(), ast_free, ast_hangup(), ast_log(), ast_pbx_outgoing_cdr_failed(), ast_pbx_run(), ast_pbx_start(), ast_pthread_create_detached, ast_request_and_dial(), ast_set_variables(), AST_STATE_DOWN, AST_STATE_UP, ast_strlen_zero(), ast_variables_destroy(), ast_verb, async_wait(), ast_channel::cdr, async_stat::chan, cid_name, outgoing_helper::cid_name, cid_num, outgoing_helper::cid_num, context, ast_channel::context, outgoing_helper::context, async_stat::context, exten, outgoing_helper::exten, ast_channel::hangupcause, LOG_ERROR, LOG_WARNING, ast_channel::name, async_stat::p, outgoing_helper::parent_channel, pbx_builtin_setvar_helper(), outgoing_helper::priority, set_ext_pri(), async_stat::timeout, and outgoing_helper::vars.

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

9376 {
9377  struct ast_channel *chan;
9378  struct async_stat *as;
9379  int res = -1, cdr_res = -1;
9380  struct outgoing_helper oh;
9381 
9382  if (synchronous) {
9383  oh.context = context;
9384  oh.exten = exten;
9385  oh.priority = priority;
9386  oh.cid_num = cid_num;
9387  oh.cid_name = cid_name;
9388  oh.account = account;
9389  oh.vars = vars;
9390  oh.parent_channel = NULL;
9391 
9392  chan = __ast_request_and_dial(type, format, NULL, data, timeout, reason, cid_num, cid_name, &oh);
9393  if (channel) {
9394  *channel = chan;
9395  if (chan)
9396  ast_channel_lock(chan);
9397  }
9398  if (chan) {
9399  if (chan->_state == AST_STATE_UP) {
9400  res = 0;
9401  ast_verb(4, "Channel %s was answered.\n", chan->name);
9402 
9403  if (synchronous > 1) {
9404  if (channel)
9405  ast_channel_unlock(chan);
9406  if (ast_pbx_run(chan)) {
9407  ast_log(LOG_ERROR, "Unable to run PBX on %s\n", chan->name);
9408  if (channel)
9409  *channel = NULL;
9410  ast_hangup(chan);
9411  chan = NULL;
9412  res = -1;
9413  }
9414  } else {
9415  if (ast_pbx_start(chan)) {
9416  ast_log(LOG_ERROR, "Unable to start PBX on %s\n", chan->name);
9417  if (channel) {
9418  *channel = NULL;
9419  ast_channel_unlock(chan);
9420  }
9421  ast_hangup(chan);
9422  res = -1;
9423  }
9424  chan = NULL;
9425  }
9426  } else {
9427  ast_verb(4, "Channel %s was never answered.\n", chan->name);
9428 
9429  if (chan->cdr) { /* update the cdr */
9430  /* here we update the status of the call, which sould be busy.
9431  * if that fails then we set the status to failed */
9432  if (ast_cdr_disposition(chan->cdr, chan->hangupcause))
9433  ast_cdr_failed(chan->cdr);
9434  }
9435 
9436  if (channel) {
9437  *channel = NULL;
9438  ast_channel_unlock(chan);
9439  }
9440  ast_hangup(chan);
9441  chan = NULL;
9442  }
9443  }
9444 
9445  if (res < 0) { /* the call failed for some reason */
9446  if (*reason == 0) { /* if the call failed (not busy or no answer)
9447  * update the cdr with the failed message */
9448  cdr_res = ast_pbx_outgoing_cdr_failed();
9449  if (cdr_res != 0) {
9450  res = cdr_res;
9451  goto outgoing_exten_cleanup;
9452  }
9453  }
9454 
9455  /* create a fake channel and execute the "failed" extension (if it exists) within the requested context */
9456  /* check if "failed" exists */
9457  if (ast_exists_extension(chan, context, "failed", 1, NULL)) {
9458  chan = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", NULL, 0, "OutgoingSpoolFailed");
9459  if (chan) {
9460  char failed_reason[4] = "";
9461  if (!ast_strlen_zero(context))
9462  ast_copy_string(chan->context, context, sizeof(chan->context));
9463  set_ext_pri(chan, "failed", 1);
9464  ast_set_variables(chan, vars);
9465  snprintf(failed_reason, sizeof(failed_reason), "%d", *reason);
9466  pbx_builtin_setvar_helper(chan, "REASON", failed_reason);
9467  if (account)
9468  ast_cdr_setaccount(chan, account);
9469  if (ast_pbx_run(chan)) {
9470  ast_log(LOG_ERROR, "Unable to run PBX on %s\n", chan->name);
9471  ast_hangup(chan);
9472  }
9473  chan = NULL;
9474  }
9475  }
9476  }
9477  } else {
9478  if (!(as = ast_calloc(1, sizeof(*as)))) {
9479  res = -1;
9480  goto outgoing_exten_cleanup;
9481  }
9482  chan = ast_request_and_dial(type, format, NULL, data, timeout, reason, cid_num, cid_name);
9483  if (channel) {
9484  *channel = chan;
9485  if (chan)
9486  ast_channel_lock(chan);
9487  }
9488  if (!chan) {
9489  ast_free(as);
9490  res = -1;
9491  goto outgoing_exten_cleanup;
9492  }
9493  as->chan = chan;
9494  ast_copy_string(as->context, context, sizeof(as->context));
9495  set_ext_pri(as->chan, exten, priority);
9496  as->timeout = timeout;
9497  ast_set_variables(chan, vars);
9498  if (account)
9499  ast_cdr_setaccount(chan, account);
9500  if (ast_pthread_create_detached(&as->p, NULL, async_wait, as)) {
9501  ast_log(LOG_WARNING, "Failed to start async wait\n");
9502  ast_free(as);
9503  if (channel) {
9504  *channel = NULL;
9505  ast_channel_unlock(chan);
9506  }
9507  ast_hangup(chan);
9508  res = -1;
9509  goto outgoing_exten_cleanup;
9510  }
9511  res = 0;
9512  }
9513 outgoing_exten_cleanup:
9514  ast_variables_destroy(vars);
9515  return res;
9516 }
int ast_cdr_disposition(struct ast_cdr *cdr, int cause)
Save the result of the call based on the AST_CAUSE_*.
Definition: cdr.c:790
int ast_hangup(struct ast_channel *chan)
Hang up a channel.
Definition: channel.c:2804
#define ast_channel_lock(chan)
Definition: channel.h:2466
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
Main Channel structure associated with a channel.
Definition: channel.h:742
void ast_cdr_failed(struct ast_cdr *cdr)
Fail a call.
Definition: cdr.c:764
struct ast_channel * chan
Definition: pbx.c:9276
char context[AST_MAX_CONTEXT]
Definition: pbx.c:9277
#define ast_pthread_create_detached(a, b, c, d)
Definition: utils.h:422
static int ast_pbx_outgoing_cdr_failed(void)
Function to post an empty cdr after a spool call fails.
Definition: pbx.c:9348
pthread_t p
Definition: pbx.c:9275
char context[AST_MAX_CONTEXT]
Definition: channel.h:868
struct ast_channel * __ast_request_and_dial(const char *type, format_t format, const struct ast_channel *requestor, void *data, int timeout, int *reason, const char *cid_num, const char *cid_name, struct outgoing_helper *oh)
Request a channel of a given type, with data as optional information used by the low level module and...
Definition: channel.c:5456
#define LOG_WARNING
Definition: logger.h:144
enum ast_pbx_result ast_pbx_start(struct ast_channel *c)
Create a new thread and start the PBX.
Definition: pbx.c:5879
int ast_cdr_setaccount(struct ast_channel *chan, const char *account)
Set account code, will generate AMI event.
Definition: cdr.c:990
void ast_set_variables(struct ast_channel *chan, struct ast_variable *vars)
adds a list of channel variables to a channel
Definition: channel.c:8261
struct ast_cdr * cdr
Definition: channel.h:766
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: config.c:586
static char cid_num[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:157
#define ast_verb(level,...)
Definition: logger.h:243
int timeout
Definition: pbx.c:9280
struct ast_channel * ast_channel_alloc(int needqueue, int state, const char *cid_num, const char *cid_name, const char *acctcode, const char *exten, const char *context, const char *linkedid, const int amaflag, const char *name_fmt,...)
Definition: channel.c:9825
struct ast_variable * vars
Definition: channel.h:1005
const char * account
Definition: channel.h:1004
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition: pbx.c:5400
#define LOG_ERROR
Definition: logger.h:155
enum ast_channel_state _state
Definition: channel.h:839
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_channel_unlock(chan)
Definition: channel.h:2467
#define ast_free(a)
Definition: astmm.h:97
static const char type[]
Definition: chan_nbs.c:57
static char cid_name[AST_MAX_EXTENSION]
Definition: chan_mgcp.c:158
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...
Definition: pbx.c:10546
static void * async_wait(void *data)
Definition: pbx.c:9285
struct ast_channel * ast_request_and_dial(const char *type, format_t format, const struct ast_channel *requestor, void *data, int timeout, int *reason, const char *cid_num, const char *cid_name)
Request a channel of a given type, with data as optional information used by the low level module and...
Definition: channel.c:5650
#define ast_calloc(a, b)
Definition: astmm.h:82
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
const char * context
Definition: channel.h:999
enum ast_pbx_result ast_pbx_run(struct ast_channel *c)
Execute the PBX in the current thread.
Definition: pbx.c:5926
int hangupcause
Definition: channel.h:849
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
static void set_ext_pri(struct ast_channel *c, const char *exten, int pri)
Definition: pbx.c:5431
static snd_pcm_format_t format
Definition: chan_alsa.c:93
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 5926 of file pbx.c.

References ast_pbx_run_args().

Referenced by __analog_ss_thread(), analog_ss_thread(), ast_pbx_outgoing_exten(), async_wait(), do_idle_thread(), do_notify(), mgcp_ss(), pri_ss_thread(), skinny_newcall(), and unistim_ss().

5927 {
5928  return ast_pbx_run_args(c, NULL);
5929 }
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:5906
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 5906 of file pbx.c.

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

Referenced by ast_pbx_run(), dial_exec_full(), handle_gosub(), and try_calling().

5907 {
5908  enum ast_pbx_result res = AST_PBX_SUCCESS;
5909 
5911  ast_log(LOG_WARNING, "PBX requires Asterisk to be fully booted\n");
5912  return AST_PBX_FAILED;
5913  }
5914 
5915  if (increase_call_count(c)) {
5916  return AST_PBX_CALL_LIMIT;
5917  }
5918 
5919  res = __ast_pbx_run(c, args);
5920 
5922 
5923  return res;
5924 }
#define ast_test_flag(p, flag)
Definition: utils.h:63
static void decrease_call_count(void)
Definition: pbx.c:5837
#define LOG_WARNING
Definition: logger.h:144
static enum ast_pbx_result __ast_pbx_run(struct ast_channel *c, struct ast_pbx_args *args)
Definition: pbx.c:5473
static int increase_call_count(const struct ast_channel *c)
Increase call count for channel.
Definition: pbx.c:5790
ast_pbx_result
The result codes when starting the PBX on a channel with ast_pbx_start.
Definition: pbx.h:299
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
struct ast_flags ast_options
Definition: asterisk.c:178
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 5879 of file pbx.c.

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

Referenced by __oh323_new(), alsa_new(), ast_async_goto(), ast_iax2_new(), ast_pbx_outgoing_exten(), bridge_call_thread(), bridge_exec(), check_goto_on_transfer(), console_new(), dahdi_new(), dial_exec_full(), generic_recall(), gtalk_new(), gtalk_newcall(), handle_request_invite(), jingle_new(), jingle_newcall(), local_call(), manage_parked_call(), mgcp_new(), nbs_new(), oss_new(), pbx_start_chan(), phone_new(), pri_dchannel(), skinny_new(), and unistim_new().

5880 {
5881  pthread_t t;
5882 
5883  if (!c) {
5884  ast_log(LOG_WARNING, "Asked to start thread on NULL channel?\n");
5885  return AST_PBX_FAILED;
5886  }
5887 
5889  ast_log(LOG_WARNING, "PBX requires Asterisk to be fully booted\n");
5890  return AST_PBX_FAILED;
5891  }
5892 
5893  if (increase_call_count(c))
5894  return AST_PBX_CALL_LIMIT;
5895 
5896  /* Start a new thread, and get something handling this channel. */
5897  if (ast_pthread_create_detached(&t, NULL, pbx_thread, c)) {
5898  ast_log(LOG_WARNING, "Failed to create new channel thread\n");
5900  return AST_PBX_FAILED;
5901  }
5902 
5903  return AST_PBX_SUCCESS;
5904 }
#define ast_pthread_create_detached(a, b, c, d)
Definition: utils.h:422
#define ast_test_flag(p, flag)
Definition: utils.h:63
static void decrease_call_count(void)
Definition: pbx.c:5837
#define LOG_WARNING
Definition: logger.h:144
static int increase_call_count(const struct ast_channel *c)
Increase call count for channel.
Definition: pbx.c:5790
static void * pbx_thread(void *data)
Definition: pbx.c:5859
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
struct ast_flags ast_options
Definition: asterisk.c:178
int ast_processed_calls ( void  )

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

Definition at line 5936 of file pbx.c.

References totalcalls.

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

5937 {
5938  return totalcalls;
5939 }
static int totalcalls
Definition: pbx.c:1229
int ast_rdlock_context ( struct ast_context con)

Read locks a given context.

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

Definition at line 11060 of file pbx.c.

References ast_rwlock_rdlock, and ast_context::lock.

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

11061 {
11062  return ast_rwlock_rdlock(&con->lock);
11063 }
#define ast_rwlock_rdlock(a)
Definition: lock.h:201
ast_rwlock_t lock
Definition: pbx.c:956
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 6439 of file pbx.c.

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

Referenced by load_module().

6440 {
6441  struct ast_switch *tmp;
6442 
6445  if (!strcasecmp(tmp->name, sw->name)) {
6447  ast_log(LOG_WARNING, "Switch '%s' already found\n", sw->name);
6448  return -1;
6449  }
6450  }
6453 
6454  return 0;
6455 }
struct ast_switch::@191 list
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define LOG_WARNING
Definition: logger.h:144
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
const char * name
Definition: pbx.h:130
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
Definition: pbx.c:1303
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:726
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 5425 of file pbx.c.

References E_SPAWN, and pbx_extension_helper().

Referenced by __ast_pbx_run(), _macro_exec(), ast_bridge_call(), dial_exec_full(), gosub_run(), and loopback_exec().

5426 {
5427  return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_SPAWN, found, combined_find_spawn);
5428 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
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:4706
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 5380 of file pbx.c.

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

Referenced by ast_str_retrieve_variable().

5381 {
5382  struct ast_exten *e = ast_hint_extension(c, context, exten);
5383 
5384  if (!e) {
5385  return 0;
5386  }
5387 
5388  if (hint) {
5389  ast_str_set(hint, hintsize, "%s", ast_get_extension_app(e));
5390  }
5391  if (name) {
5392  const char *tmp = ast_get_extension_app_data(e);
5393  if (tmp) {
5394  ast_str_set(name, namesize, "%s", tmp);
5395  }
5396  }
5397  return -1;
5398 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
ast_exten: An extension The dialplan is saved as a linked list with each context having it&#39;s own link...
Definition: pbx.c:884
const char * ast_get_extension_app(struct ast_exten *e)
Definition: pbx.c:11141
void * ast_get_extension_app_data(struct ast_exten *e)
Definition: pbx.c:11146
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:874
static struct ast_exten * ast_hint_extension(struct ast_channel *c, const char *context, const char *exten)
Definition: pbx.c:4835
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
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 3445 of file pbx.c.

References ast_party_caller::ani2, ARRAY_LEN, ast_channel_lock, ast_channel_unlock, ast_config_AST_SYSTEM_NAME, ast_debug, ast_eid_default, ast_eid_to_str(), AST_LIST_TRAVERSE, ast_party_id_presentation(), ast_rwlock_rdlock, ast_rwlock_unlock, ast_str_buffer(), ast_str_get_hint(), ast_str_set(), ast_str_substring(), ast_strdupa, ast_var_name(), ast_var_value(), ast_channel::caller, ast_channel::context, ast_channel::dialed, ast_var_t::entries, ast_channel::exten, globals, globalslock, ast_channel::hangupcause, ast_party_caller::id, ast_channel::name, ast_party_id::number, parse_variable_name(), ast_party_number::plan, ast_channel::priority, ast_party_dialed::transit_network_select, ast_channel::uniqueid, and ast_channel::varshead.

Referenced by ast_str_substitute_variables_full(), and pbx_retrieve_variable().

3446 {
3447  const char not_found = '\0';
3448  char *tmpvar;
3449  const char *ret;
3450  const char *s; /* the result */
3451  int offset, length;
3452  int i, need_substring;
3453  struct varshead *places[2] = { headp, &globals }; /* list of places where we may look */
3454  char workspace[20];
3455 
3456  if (c) {
3457  ast_channel_lock(c);
3458  places[0] = &c->varshead;
3459  }
3460  /*
3461  * Make a copy of var because parse_variable_name() modifies the string.
3462  * Then if called directly, we might need to run substring() on the result;
3463  * remember this for later in 'need_substring', 'offset' and 'length'
3464  */
3465  tmpvar = ast_strdupa(var); /* parse_variable_name modifies the string */
3466  need_substring = parse_variable_name(tmpvar, &offset, &length, &i /* ignored */);
3467 
3468  /*
3469  * Look first into predefined variables, then into variable lists.
3470  * Variable 's' points to the result, according to the following rules:
3471  * s == &not_found (set at the beginning) means that we did not find a
3472  * matching variable and need to look into more places.
3473  * If s != &not_found, s is a valid result string as follows:
3474  * s = NULL if the variable does not have a value;
3475  * you typically do this when looking for an unset predefined variable.
3476  * s = workspace if the result has been assembled there;
3477  * typically done when the result is built e.g. with an snprintf(),
3478  * so we don't need to do an additional copy.
3479  * s != workspace in case we have a string, that needs to be copied
3480  * (the ast_copy_string is done once for all at the end).
3481  * Typically done when the result is already available in some string.
3482  */
3483  s = &not_found; /* default value */
3484  if (c) { /* This group requires a valid channel */
3485  /* Names with common parts are looked up a piece at a time using strncmp. */
3486  if (!strncmp(var, "CALL", 4)) {
3487  if (!strncmp(var + 4, "ING", 3)) {
3488  if (!strcmp(var + 7, "PRES")) { /* CALLINGPRES */
3489  ast_str_set(str, maxlen, "%d",
3490  ast_party_id_presentation(&c->caller.id));
3491  s = ast_str_buffer(*str);
3492  } else if (!strcmp(var + 7, "ANI2")) { /* CALLINGANI2 */
3493  ast_str_set(str, maxlen, "%d", c->caller.ani2);
3494  s = ast_str_buffer(*str);
3495  } else if (!strcmp(var + 7, "TON")) { /* CALLINGTON */
3496  ast_str_set(str, maxlen, "%d", c->caller.id.number.plan);
3497  s = ast_str_buffer(*str);
3498  } else if (!strcmp(var + 7, "TNS")) { /* CALLINGTNS */
3499  ast_str_set(str, maxlen, "%d", c->dialed.transit_network_select);
3500  s = ast_str_buffer(*str);
3501  }
3502  }
3503  } else if (!strcmp(var, "HINT")) {
3504  s = ast_str_get_hint(str, maxlen, NULL, 0, c, c->context, c->exten) ? ast_str_buffer(*str) : NULL;
3505  } else if (!strcmp(var, "HINTNAME")) {
3506  s = ast_str_get_hint(NULL, 0, str, maxlen, c, c->context, c->exten) ? ast_str_buffer(*str) : NULL;
3507  } else if (!strcmp(var, "EXTEN")) {
3508  s = c->exten;
3509  } else if (!strcmp(var, "CONTEXT")) {
3510  s = c->context;
3511  } else if (!strcmp(var, "PRIORITY")) {
3512  ast_str_set(str, maxlen, "%d", c->priority);
3513  s = ast_str_buffer(*str);
3514  } else if (!strcmp(var, "CHANNEL")) {
3515  s = c->name;
3516  } else if (!strcmp(var, "UNIQUEID")) {
3517  s = c->uniqueid;
3518  } else if (!strcmp(var, "HANGUPCAUSE")) {
3519  ast_str_set(str, maxlen, "%d", c->hangupcause);
3520  s = ast_str_buffer(*str);
3521  }
3522  }
3523  if (s == &not_found) { /* look for more */
3524  if (!strcmp(var, "EPOCH")) {
3525  ast_str_set(str, maxlen, "%d", (int) time(NULL));
3526  s = ast_str_buffer(*str);
3527  } else if (!strcmp(var, "SYSTEMNAME")) {
3529  } else if (!strcmp(var, "ENTITYID")) {
3530  ast_eid_to_str(workspace, sizeof(workspace), &ast_eid_default);
3531  s = workspace;
3532  }
3533  }
3534  /* if not found, look into chanvars or global vars */
3535  for (i = 0; s == &not_found && i < ARRAY_LEN(places); i++) {
3536  struct ast_var_t *variables;
3537  if (!places[i])
3538  continue;
3539  if (places[i] == &globals)
3541  AST_LIST_TRAVERSE(places[i], variables, entries) {
3542  if (!strcasecmp(ast_var_name(variables), var)) {
3543  s = ast_var_value(variables);
3544  break;
3545  }
3546  }
3547  if (places[i] == &globals)
3549  }
3550  if (s == &not_found || s == NULL) {
3551  ast_debug(5, "Result of '%s' is NULL\n", var);
3552  ret = NULL;
3553  } else {
3554  ast_debug(5, "Result of '%s' is '%s'\n", var, s);
3555  if (s != ast_str_buffer(*str)) {
3556  ast_str_set(str, maxlen, "%s", s);
3557  }
3558  ret = ast_str_buffer(*str);
3559  if (need_substring) {
3560  ret = ast_str_substring(*str, offset, length);
3561  ast_debug(2, "Final result of '%s' is '%s'\n", var, ret);
3562  }
3563  }
3564 
3565  if (c) {
3566  ast_channel_unlock(c);
3567  }
3568  return ret;
3569 }
#define ast_rwlock_rdlock(a)
Definition: lock.h:201
#define ast_channel_lock(chan)
Definition: channel.h:2466
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Definition: netsock.c:222
const char * ast_var_value(const struct ast_var_t *var)
Definition: chanvars.c:89
const char * ast_var_name(const struct ast_var_t *var)
Definition: chanvars.c:69
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
int ast_party_id_presentation(const struct ast_party_id *id)
Determine the overall presentation value for the given party.
Definition: channel.c:2151
static ast_rwlock_t globalslock
Definition: pbx.c:1217
#define var
Definition: ast_expr2f.c:606
const char * str
Definition: app_jack.c:144
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:5380
#define ast_rwlock_unlock(a)
Definition: lock.h:200
const char * ast_config_AST_SYSTEM_NAME
Definition: asterisk.c:273
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:874
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_channel_unlock(chan)
Definition: channel.h:2467
struct ast_var_t::@158 entries
struct ast_eid ast_eid_default
Global EID.
Definition: asterisk.c:192
static int parse_variable_name(char *var, int *offset, int *length, int *isfunc)
extract offset:length from variable name.
Definition: pbx.c:3311
static struct varshead globals
Definition: pbx.c:1218
static const char * ast_str_substring(struct ast_str *value, int offset, int length)
Definition: pbx.c:3380
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 4468 of file pbx.c.

References ast_str_substitute_variables_full().

Referenced by _macro_exec(), acf_odbc_read(), acf_odbc_write(), cli_odbc_read(), cli_odbc_write(), config_curl(), custom_log(), cut_internal(), destroy_curl(), exec_exec(), func_mchan_read(), function_eval2(), function_fieldnum_helper(), function_fieldqty_helper(), handle_getvariablefull(), import_helper(), listfilter(), make_email_file(), realtime_curl(), realtime_multi_curl(), replace(), require_curl(), sendmail(), sendpage(), shift_pop(), store_curl(), syslog_log(), tryexec_exec(), unshift_push(), update2_curl(), and update_curl().

4469 {
4470  size_t used;
4471  ast_str_substitute_variables_full(buf, maxlen, chan, NULL, templ, &used);
4472 }
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)
Definition: pbx.c:4289
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.

Definition at line 4289 of file pbx.c.

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

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

4290 {
4291  /* Substitutes variables into buf, based on string templ */
4292  char *cp4 = NULL;
4293  const char *tmp, *whereweare;
4294  int orig_size = 0;
4295  int offset, offset2, isfunction;
4296  const char *nextvar, *nextexp, *nextthing;
4297  const char *vars, *vare;
4298  char *finalvars;
4299  int pos, brackets, needsub, len;
4300  struct ast_str *substr1 = ast_str_create(16), *substr2 = NULL, *substr3 = ast_str_create(16);
4301 
4302  ast_str_reset(*buf);
4303  whereweare = tmp = templ;
4304  while (!ast_strlen_zero(whereweare)) {
4305  /* reset our buffer */
4306  ast_str_reset(substr3);
4307 
4308  /* Assume we're copying the whole remaining string */
4309  pos = strlen(whereweare);
4310  nextvar = NULL;
4311  nextexp = NULL;
4312  nextthing = strchr(whereweare, '$');
4313  if (nextthing) {
4314  switch (nextthing[1]) {
4315  case '{':
4316  nextvar = nextthing;
4317  pos = nextvar - whereweare;
4318  break;
4319  case '[':
4320  nextexp = nextthing;
4321  pos = nextexp - whereweare;
4322  break;
4323  default:
4324  pos = 1;
4325  }
4326  }
4327 
4328  if (pos) {
4329  /* Copy that many bytes */
4330  ast_str_append_substr(buf, maxlen, whereweare, pos);
4331 
4332  templ += pos;
4333  whereweare += pos;
4334  }
4335 
4336  if (nextvar) {
4337  /* We have a variable. Find the start and end, and determine
4338  if we are going to have to recursively call ourselves on the
4339  contents */
4340  vars = vare = nextvar + 2;
4341  brackets = 1;
4342  needsub = 0;
4343 
4344  /* Find the end of it */
4345  while (brackets && *vare) {
4346  if ((vare[0] == '$') && (vare[1] == '{')) {
4347  needsub++;
4348  } else if (vare[0] == '{') {
4349  brackets++;
4350  } else if (vare[0] == '}') {
4351  brackets--;
4352  } else if ((vare[0] == '$') && (vare[1] == '['))
4353  needsub++;
4354  vare++;
4355  }
4356  if (brackets)
4357  ast_log(LOG_WARNING, "Error in extension logic (missing '}')\n");
4358  len = vare - vars - 1;
4359 
4360  /* Skip totally over variable string */
4361  whereweare += (len + 3);
4362 
4363  /* Store variable name (and truncate) */
4364  ast_str_set_substr(&substr1, 0, vars, len);
4365  ast_debug(5, "Evaluating '%s' (from '%s' len %d)\n", ast_str_buffer(substr1), vars, len);
4366 
4367  /* Substitute if necessary */
4368  if (needsub) {
4369  size_t used;
4370  if (!substr2) {
4371  substr2 = ast_str_create(16);
4372  }
4373 
4374  ast_str_substitute_variables_full(&substr2, 0, c, headp, ast_str_buffer(substr1), &used);
4375  finalvars = ast_str_buffer(substr2);
4376  } else {
4377  finalvars = ast_str_buffer(substr1);
4378  }
4379 
4380  parse_variable_name(finalvars, &offset, &offset2, &isfunction);
4381  if (isfunction) {
4382  /* Evaluate function */
4383  if (c || !headp) {
4384  cp4 = ast_func_read2(c, finalvars, &substr3, 0) ? NULL : ast_str_buffer(substr3);
4385  } else {
4386  struct varshead old;
4387  struct ast_channel *bogus = ast_dummy_channel_alloc();
4388  if (bogus) {
4389  memcpy(&old, &bogus->varshead, sizeof(old));
4390  memcpy(&bogus->varshead, headp, sizeof(bogus->varshead));
4391  cp4 = ast_func_read2(c, finalvars, &substr3, 0) ? NULL : ast_str_buffer(substr3);
4392  /* Don't deallocate the varshead that was passed in */
4393  memcpy(&bogus->varshead, &old, sizeof(bogus->varshead));
4394  ast_channel_unref(bogus);
4395  } else {
4396  ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution. Function results may be blank.\n");
4397  }
4398  }
4399  ast_debug(2, "Function %s result is '%s'\n", finalvars, cp4 ? cp4 : "(null)");
4400  } else {
4401  /* Retrieve variable value */
4402  ast_str_retrieve_variable(&substr3, 0, c, headp, finalvars);
4403  cp4 = ast_str_buffer(substr3);
4404  }
4405  if (cp4) {
4406  ast_str_substring(substr3, offset, offset2);
4407  ast_str_append(buf, maxlen, "%s", ast_str_buffer(substr3));
4408  }
4409  } else if (nextexp) {
4410  /* We have an expression. Find the start and end, and determine
4411  if we are going to have to recursively call ourselves on the
4412  contents */
4413  vars = vare = nextexp + 2;
4414  brackets = 1;
4415  needsub = 0;
4416 
4417  /* Find the end of it */
4418  while (brackets && *vare) {
4419  if ((vare[0] == '$') && (vare[1] == '[')) {
4420  needsub++;
4421  brackets++;
4422  vare++;
4423  } else if (vare[0] == '[') {
4424  brackets++;
4425  } else if (vare[0] == ']') {
4426  brackets--;
4427  } else if ((vare[0] == '$') && (vare[1] == '{')) {
4428  needsub++;
4429  vare++;
4430  }
4431  vare++;
4432  }
4433  if (brackets)
4434  ast_log(LOG_WARNING, "Error in extension logic (missing ']')\n");
4435  len = vare - vars - 1;
4436 
4437  /* Skip totally over expression */
4438  whereweare += (len + 3);
4439 
4440  /* Store variable name (and truncate) */
4441  ast_str_set_substr(&substr1, 0, vars, len);
4442 
4443  /* Substitute if necessary */
4444  if (needsub) {
4445  size_t used;
4446  if (!substr2) {
4447  substr2 = ast_str_create(16);
4448  }
4449 
4450  ast_str_substitute_variables_full(&substr2, 0, c, headp, ast_str_buffer(substr1), &used);
4451  finalvars = ast_str_buffer(substr2);
4452  } else {
4453  finalvars = ast_str_buffer(substr1);
4454  }
4455 
4456  if (ast_str_expr(&substr3, 0, c, finalvars)) {
4457  ast_debug(2, "Expression result is '%s'\n", ast_str_buffer(substr3));
4458  }
4459  ast_str_append(buf, maxlen, "%s", ast_str_buffer(substr3));
4460  }
4461  }
4462  *used = ast_str_strlen(*buf) - orig_size;
4463  ast_free(substr1);
4464  ast_free(substr2);
4465  ast_free(substr3);
4466 }
Main Channel structure associated with a channel.
Definition: channel.h:742
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2502
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
Definition: pbx.c:4216
#define LOG_WARNING
Definition: logger.h:144
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
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:900
struct ast_str * ast_str_create(size_t init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:420
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
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:823
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)
Definition: pbx.c:4289
#define LOG_ERROR
Definition: logger.h:155
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_free(a)
Definition: astmm.h:97
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:2438
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:436
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:471
const char * ast_str_retrieve_variable(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, struct varshead *headp, const char *var)
Definition: pbx.c:3445
static int parse_variable_name(char *var, int *offset, int *length, int *isfunc)
extract offset:length from variable name.
Definition: pbx.c:3311
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:816
struct ast_channel * ast_dummy_channel_alloc(void)
Create a fake channel structure.
Definition: channel.c:1391
struct varshead varshead
Definition: channel.h:817
static const char * ast_str_substring(struct ast_str *value, int offset, int length)
Definition: pbx.c:3380
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 4474 of file pbx.c.

References ast_str_substitute_variables_full().

4475 {
4476  size_t used;
4477  ast_str_substitute_variables_full(buf, maxlen, NULL, headp, templ, &used);
4478 }
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)
Definition: pbx.c:4289
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 4072 of file pbx.c.

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

Referenced by handle_tcptls_connection().

4073 {
4074  int *thread_inhibit_escalations;
4075 
4076  thread_inhibit_escalations = ast_threadstorage_get(
4077  &thread_inhibit_escalations_tl, sizeof(*thread_inhibit_escalations));
4078 
4079  if (thread_inhibit_escalations == NULL) {
4080  ast_log(LOG_ERROR, "Error inhibiting privilege escalations for current thread\n");
4081  return -1;
4082  }
4083 
4084  *thread_inhibit_escalations = 1;
4085  return 0;
4086 }
void * ast_threadstorage_get(struct ast_threadstorage *ts, size_t init_size)
Retrieve thread storage.
static struct ast_threadstorage thread_inhibit_escalations_tl
Definition: pbx.c:870
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
void ast_unregister_switch ( struct ast_switch sw)

Unregister an alternative switch.

Parameters
swswitch to unregister

Unregisters a switch from asterisk.

Returns
nothing

Definition at line 6457 of file pbx.c.

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

Referenced by __unload_module(), and unload_module().

6458 {
6460  AST_RWLIST_REMOVE(&switches, sw, list);
6462 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
Definition: pbx.c:1303
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:870
struct ast_exten* ast_walk_context_extensions ( struct ast_context con,
struct ast_exten priority 
)

Definition at line 11179 of file pbx.c.

References ast_exten::next, and ast_context::root.

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

11181 {
11182  if (!exten)
11183  return con ? con->root : NULL;
11184  else
11185  return exten->next;
11186 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
struct ast_exten * root
Definition: pbx.c:957
struct ast_ignorepat* ast_walk_context_ignorepats ( struct ast_context con,
struct ast_ignorepat ip 
)

Definition at line 11212 of file pbx.c.

References ast_context::ignorepats, and ast_ignorepat::next.

Referenced by complete_dialplan_remove_ignorepat(), context_merge_incls_swits_igps_other_registrars(), context_used(), handle_cli_dialplan_save(), lookup_c_ip(), manager_show_dialplan_helper(), and show_dialplan_helper().

11214 {
11215  if (!ip)
11216  return con ? con->ignorepats : NULL;
11217  else
11218  return ip->next;
11219 }
struct ast_ignorepat * ignorepats
Definition: pbx.c:962
struct ast_ignorepat * next
Definition: pbx.c:927
struct ast_include* ast_walk_context_includes ( struct ast_context con,
struct ast_include inc 
)

Definition at line 11203 of file pbx.c.

References ast_context::includes, and ast_include::next.

Referenced by ast_context_verify_includes(), complete_dialplan_remove_include(), context_merge_incls_swits_igps_other_registrars(), context_used(), find_matching_priority(), handle_cli_dialplan_save(), lookup_ci(), manager_show_dialplan_helper(), and show_dialplan_helper().

11205 {
11206  if (!inc)
11207  return con ? con->includes : NULL;
11208  else
11209  return inc->next;
11210 }
struct ast_include * next
Definition: pbx.c:910
struct ast_include * includes
Definition: pbx.c:961
struct ast_sw* ast_walk_context_switches ( struct ast_context con,
struct ast_sw sw 
)

Definition at line 11188 of file pbx.c.

References ast_context::alts, AST_LIST_FIRST, and AST_LIST_NEXT.

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

11190 {
11191  if (!sw)
11192  return con ? AST_LIST_FIRST(&con->alts) : NULL;
11193  else
11194  return AST_LIST_NEXT(sw, list);
11195 }
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:420
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:438
struct ast_context::@290 alts
struct ast_exten* ast_walk_extension_priorities ( struct ast_exten exten,
struct ast_exten priority 
)

Definition at line 11197 of file pbx.c.

References exten, and ast_exten::peer.

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

11199 {
11200  return priority ? priority->peer : exten;
11201 }
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
struct ast_exten * peer
Definition: pbx.c:895
int ast_wrlock_context ( struct ast_context con)

Write locks a given context.

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

Definition at line 11055 of file pbx.c.

References ast_rwlock_wrlock, and ast_context::lock.

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

11056 {
11057  return ast_rwlock_wrlock(&con->lock);
11058 }
ast_rwlock_t lock
Definition: pbx.c:956
#define ast_rwlock_wrlock(a)
Definition: lock.h:202
int ast_wrlock_contexts ( void  )

Write locks the context list.

Return values
0on success
-1on error

Definition at line 11037 of file pbx.c.

References ast_mutex_lock, and conlock.

Referenced by ast_context_destroy(), ast_context_find_or_create(), ast_merge_contexts_and_delete(), and complete_dialplan_remove_include().

11038 {
11039  return ast_mutex_lock(&conlock);
11040 }
#define ast_mutex_lock(a)
Definition: lock.h:155
static ast_mutex_t conlock
Lock for the ast_context list.
Definition: pbx.c:1294
void pbx_builtin_clear_globals ( void  )

Definition at line 10709 of file pbx.c.

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

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

10710 {
10711  struct ast_var_t *vardata;
10712 
10714  while ((vardata = AST_LIST_REMOVE_HEAD(&globals, entries)))
10715  ast_var_delete(vardata);
10717 }
static ast_rwlock_t globalslock
Definition: pbx.c:1217
#define ast_rwlock_unlock(a)
Definition: lock.h:200
void ast_var_delete(struct ast_var_t *var)
Definition: chanvars.c:63
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:818
struct ast_var_t::@158 entries
#define ast_rwlock_wrlock(a)
Definition: lock.h:202
static struct varshead globals
Definition: pbx.c:1218
const char* pbx_builtin_getvar_helper ( struct ast_channel chan,
const char *  name 
)

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

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

Definition at line 10475 of file pbx.c.

References ast_channel_lock, ast_channel_unlock, AST_LIST_TRAVERSE, ast_rwlock_rdlock, ast_rwlock_unlock, ast_var_name(), ast_var_value(), globals, globalslock, and ast_channel::varshead.

Referenced by __ast_pbx_run(), _macro_exec(), _while_exec(), agentmonitoroutgoing_exec(), analog_call(), append_channel_vars(), array(), ast_bridge_call(), ast_bridge_timelimit(), ast_call_forward(), ast_channel_connected_line_macro(), ast_channel_redirecting_macro(), ast_eivr_getvariable(), ast_hangup(), ast_monitor_stop(), bridge_play_sounds(), builtin_atxfer(), builtin_automixmonitor(), builtin_automonitor(), check_goto_on_transfer(), common_exec(), conf_run(), confbridge_exec(), create_dynamic_parkinglot(), crement_function_read(), dahdi_hangup(), dahdi_r2_answer(), dahdi_r2_get_channel_category(), dial_exec_full(), do_forward(), dundi_exec(), dundi_helper(), feature_check(), feature_interpret(), find_by_mark(), find_conf_realtime(), findparkinglotname(), func_channel_read(), generic_fax_exec(), get_also_info(), get_index(), get_refer_info(), global_read(), gosub_run(), handle_gosub(), hash_read(), iax2_call(), iax2_exec(), import_ch(), leave_voicemail(), local_attended_transfer(), local_hangup(), local_read(), login_exec(), macro_fixup(), meetme_menu_admin_extended(), minivm_delete_exec(), minivm_notify_exec(), misdn_answer(), misdn_hangup(), morsecode_exec(), notify_new_message(), oh323_call(), oh323_hangup(), park_call_exec(), park_call_full(), park_space_reserve(), pbx_builtin_background(), pbx_builtin_gotoiftime(), queue_exec(), real_ctx(), receivefax_exec(), retrydial_exec(), ring_entry(), run_agi(), sendfax_exec(), set_config_flags(), set_local_info(), sig_pri_call(), sig_pri_hangup(), sip_addheader(), sla_trunk_exec(), speech_background(), try_calling(), try_suggested_sip_codec(), update_bridge_vars(), and wait_for_answer().

10476 {
10477  struct ast_var_t *variables;
10478  const char *ret = NULL;
10479  int i;
10480  struct varshead *places[2] = { NULL, &globals };
10481 
10482  if (!name)
10483  return NULL;
10484 
10485  if (chan) {
10486  ast_channel_lock(chan);
10487  places[0] = &chan->varshead;
10488  }
10489 
10490  for (i = 0; i < 2; i++) {
10491  if (!places[i])
10492  continue;
10493  if (places[i] == &globals)
10495  AST_LIST_TRAVERSE(places[i], variables, entries) {
10496  if (!strcmp(name, ast_var_name(variables))) {
10497  ret = ast_var_value(variables);
10498  break;
10499  }
10500  }
10501  if (places[i] == &globals)
10503  if (ret)
10504  break;
10505  }
10506 
10507  if (chan)
10508  ast_channel_unlock(chan);
10509 
10510  return ret;
10511 }
#define ast_rwlock_rdlock(a)
Definition: lock.h:201
#define ast_channel_lock(chan)
Definition: channel.h:2466
const char * ast_var_value(const struct ast_var_t *var)
Definition: chanvars.c:89
const char * ast_var_name(const struct ast_var_t *var)
Definition: chanvars.c:69
static ast_rwlock_t globalslock
Definition: pbx.c:1217
#define ast_rwlock_unlock(a)
Definition: lock.h:200
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_channel_unlock(chan)
Definition: channel.h:2467
static const char name[]
static struct varshead globals
Definition: pbx.c:1218
struct varshead varshead
Definition: channel.h:817
void pbx_builtin_pushvar_helper ( struct ast_channel chan,
const char *  name,
const char *  value 
)

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

Note
Will lock the channel.

Definition at line 10513 of file pbx.c.

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

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

10514 {
10515  struct ast_var_t *newvariable;
10516  struct varshead *headp;
10517 
10518  if (name[strlen(name)-1] == ')') {
10519  char *function = ast_strdupa(name);
10520 
10521  ast_log(LOG_WARNING, "Cannot push a value onto a function\n");
10522  ast_func_write(chan, function, value);
10523  return;
10524  }
10525 
10526  if (chan) {
10527  ast_channel_lock(chan);
10528  headp = &chan->varshead;
10529  } else {
10531  headp = &globals;
10532  }
10533 
10534  if (value && (newvariable = ast_var_assign(name, value))) {
10535  if (headp == &globals)
10536  ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
10537  AST_LIST_INSERT_HEAD(headp, newvariable, entries);
10538  }
10539 
10540  if (chan)
10541  ast_channel_unlock(chan);
10542  else
10544 }
#define ast_channel_lock(chan)
Definition: channel.h:2466
struct ast_var_t * ast_var_assign(const char *name, const char *value)
Definition: chanvars.c:41
#define LOG_WARNING
Definition: logger.h:144
static ast_rwlock_t globalslock
Definition: pbx.c:1217
int value
Definition: syslog.c:39
#define ast_rwlock_unlock(a)
Definition: lock.h:200
#define ast_verb(level,...)
Definition: logger.h:243
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:696
#define ast_channel_unlock(chan)
Definition: channel.h:2467
static const char name[]
#define ast_rwlock_wrlock(a)
Definition: lock.h:202
static struct varshead globals
Definition: pbx.c:1218
int ast_func_write(struct ast_channel *chan, const char *function, const char *value)
executes a write operation on a function
Definition: pbx.c:4263
struct varshead varshead
Definition: channel.h:817
int pbx_builtin_raise_exception ( struct ast_channel chan,
const char *  data 
)

Definition at line 3620 of file pbx.c.

References raise_exception().

3621 {
3622  /* Priority will become 1, next time through the AUTOLOOP */
3623  return raise_exception(chan, reason, 0);
3624 }
static int raise_exception(struct ast_channel *chan, const char *reason, int priority)
Definition: pbx.c:3594
int pbx_builtin_serialize_variables ( struct ast_channel chan,
struct ast_str **  buf 
)

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

Parameters
chanChannel from which to read variables
bufDynamic string in which to place the result (should be allocated with ast_str_create).
See Also
ast_str_create
Note
Will lock the channel.

Definition at line 10444 of file pbx.c.

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

Referenced by ast_var_channels_table(), dumpchan_exec(), handle_show_chanvar(), handle_showchan(), and vars2manager().

10445 {
10446  struct ast_var_t *variables;
10447  const char *var, *val;
10448  int total = 0;
10449 
10450  if (!chan)
10451  return 0;
10452 
10453  ast_str_reset(*buf);
10454 
10455  ast_channel_lock(chan);
10456 
10457  AST_LIST_TRAVERSE(&chan->varshead, variables, entries) {
10458  if ((var = ast_var_name(variables)) && (val = ast_var_value(variables))
10459  /* && !ast_strlen_zero(var) && !ast_strlen_zero(val) */
10460  ) {
10461  if (ast_str_append(buf, 0, "%s=%s\n", var, val) < 0) {
10462  ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n");
10463  break;
10464  } else
10465  total++;
10466  } else
10467  break;
10468  }
10469 
10470  ast_channel_unlock(chan);
10471 
10472  return total;
10473 }
#define ast_channel_lock(chan)
Definition: channel.h:2466
Definition: ast_expr2.c:325
const char * ast_var_value(const struct ast_var_t *var)
Definition: chanvars.c:89
const char * ast_var_name(const struct ast_var_t *var)
Definition: chanvars.c:69
#define var
Definition: ast_expr2f.c:606
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:900
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_channel_unlock(chan)
Definition: channel.h:2467
struct ast_var_t::@158 entries
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
Definition: strings.h:436
static int total
Definition: res_adsi.c:967
struct varshead varshead
Definition: channel.h:817
int pbx_builtin_setvar ( struct ast_channel chan,
const char *  data 
)

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

Note
Will lock the channel.

Definition at line 10603 of file pbx.c.

References ast_compat_app_set, ast_log(), ast_strdupa, ast_strlen_zero(), LOG_WARNING, ast_sw::name, pbx_builtin_setvar_helper(), pbx_builtin_setvar_multiple(), strsep(), and value.

Referenced by ast_compile_ael2().

10604 {
10605  char *name, *value, *mydata;
10606 
10607  if (ast_compat_app_set) {
10608  return pbx_builtin_setvar_multiple(chan, data);
10609  }
10610 
10611  if (ast_strlen_zero(data)) {
10612  ast_log(LOG_WARNING, "Set requires one variable name/value pair.\n");
10613  return 0;
10614  }
10615 
10616  mydata = ast_strdupa(data);
10617  name = strsep(&mydata, "=");
10618  value = mydata;
10619  if (!value) {
10620  ast_log(LOG_WARNING, "Set requires an '=' to be a valid assignment.\n");
10621  return 0;
10622  }
10623 
10624  if (strchr(name, ' ')) {
10625  ast_log(LOG_WARNING, "Please avoid unnecessary spaces on variables as it may lead to unexpected results ('%s' set to '%s').\n", name, mydata);
10626  }
10627 
10628  pbx_builtin_setvar_helper(chan, name, value);
10629 
10630  return 0;
10631 }
char * strsep(char **str, const char *delims)
#define LOG_WARNING
Definition: logger.h:144
#define ast_compat_app_set
Definition: options.h:144
int value
Definition: syslog.c:39
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
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 &#39;,&#39; character...
Definition: pbx.c:10633
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static const char name[]
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...
Definition: pbx.c:10546
int pbx_builtin_setvar_helper ( struct ast_channel chan,
const char *  name,
const char *  value 
)

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

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

Definition at line 10546 of file pbx.c.

References ast_channel_lock, ast_channel_unlock, ast_func_write(), AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_rwlock_unlock, ast_rwlock_wrlock, ast_strdupa, ast_var_assign(), ast_var_delete(), ast_var_name(), ast_verb, EVENT_FLAG_DIALPLAN, globals, globalslock, manager_event, ast_channel::name, ast_sw::name, ast_channel::uniqueid, and ast_channel::varshead.

Referenced by __analog_ss_thread(), __ast_pbx_run(), __oh323_new(), _macro_exec(), _while_exec(), acf_curl_helper(), acf_fetch(), acf_odbc_read(), acf_odbc_write(), acf_transaction_write(), action_atxfer(), action_setvar(), admin_exec(), agi_exec_full(), aji_status_exec(), analog_ss_thread(), aqm_exec(), array(), ast_bridge_call(), ast_cc_agent_set_interfaces_chanvar(), ast_eivr_setvariable(), ast_iax2_new(), ast_monitor_start(), ast_monitor_stop(), ast_pbx_outgoing_exten(), ast_pickup_call(), ast_rtp_instance_set_stats_vars(), ast_set_cc_interfaces_chanvar(), ast_set_variables(), asyncgoto_exec(), background_detect_exec(), bridge_exec(), bridge_play_sounds(), builtin_atxfer(), builtin_automixmonitor(), builtin_automonitor(), builtin_blindtransfer(), cb_events(), cccancel_exec(), ccreq_exec(), chanavail_exec(), channel_spy(), commit_exec(), conf_run(), controlplayback_exec(), count_exec(), crement_function_read(), dahdi_handle_dtmf(), dahdi_new(), dial_exec_full(), disa_exec(), do_waiting(), end_bridge_callback(), export_aoc_vars(), export_ch(), feature_exec_app(), feature_request_and_dial(), frame_set_var(), func_mchan_write(), function_db_delete(), function_db_exists(), function_db_read(), function_realtime_store(), generic_recall(), get_rdnis(), get_refer_info(), global_write(), gosub_release_frame(), gosub_run(), handle_gosub(), handle_incoming(), handle_request_bye(), handle_request_refer(), handle_set_chanvar(), handle_set_global(), handle_setvariable(), hash_read(), hash_write(), isAnsweringMachine(), leave_queue(), leave_voicemail(), local_hangup(), lua_set_variable(), lua_set_variable_value(), macro_fixup(), manage_parked_call(), mgcp_new(), minivm_accmess_exec(), minivm_delete_exec(), minivm_greet_exec(), minivm_notify_exec(), minivm_record_exec(), misdn_call(), mixmonitor_exec(), my_handle_dtmf(), originate_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), park_call_full(), parked_call_exec(), parse_moved_contact(), pbx_builtin_background(), pbx_builtin_gotoiftime(), pbx_builtin_importvar(), pbx_builtin_saydate(), pbx_builtin_saytime(), pbx_builtin_setvar(), pbx_builtin_setvar_multiple(), pbx_load_config(), phase_e_handler(), play_message_datetime(), playback_exec(), pqm_exec(), prep_email_sub_vars(), pri_dchannel(), privacy_exec(), process_ast_dsp(), process_sdp(), read_exec(), readexten_exec(), readfile_exec(), realtimefield_read(), receivefax_exec(), record_exec(), reload_module(), return_exec(), ring_entry(), rollback_exec(), rotate_file(), rqm_exec(), sendfax_exec(), sendimage_exec(), sendtext_exec(), sendurl_exec(), set(), set_channel_variables(), set_queue_result(), shift_pop(), sig_pri_new_ast_channel(), sip_addheader(), sip_hangup(), sip_new(), sip_read(), skinny_new(), sla_calc_trunk_timeouts(), sla_station_exec(), sla_trunk_exec(), socket_process(), speech_create(), start_monitor_exec(), system_exec_helper(), testtime_write(), transfer_exec(), transmit(), tryexec_exec(), unshift_push(), update_bridge_vars(), update_qe_rule(), upqm_exec(), vm_box_exists(), vm_exec(), vmauthenticate(), waituntil_exec(), and zapateller_exec().

10547 {
10548  struct ast_var_t *newvariable;
10549  struct varshead *headp;
10550  const char *nametail = name;
10551 
10552  if (name[strlen(name) - 1] == ')') {
10553  char *function = ast_strdupa(name);
10554 
10555  return ast_func_write(chan, function, value);
10556  }
10557 
10558  if (chan) {
10559  ast_channel_lock(chan);
10560  headp = &chan->varshead;
10561  } else {
10563  headp = &globals;
10564  }
10565 
10566  /* For comparison purposes, we have to strip leading underscores */
10567  if (*nametail == '_') {
10568  nametail++;
10569  if (*nametail == '_')
10570  nametail++;
10571  }
10572 
10573  AST_LIST_TRAVERSE_SAFE_BEGIN(headp, newvariable, entries) {
10574  if (strcmp(ast_var_name(newvariable), nametail) == 0) {
10575  /* there is already such a variable, delete it */
10576  AST_LIST_REMOVE_CURRENT(entries);
10577  ast_var_delete(newvariable);
10578  break;
10579  }
10580  }
10582 
10583  if (value && (newvariable = ast_var_assign(name, value))) {
10584  if (headp == &globals)
10585  ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
10586  AST_LIST_INSERT_HEAD(headp, newvariable, entries);
10588  "Channel: %s\r\n"
10589  "Variable: %s\r\n"
10590  "Value: %s\r\n"
10591  "Uniqueid: %s\r\n",
10592  chan ? chan->name : "none", name, value,
10593  chan ? chan->uniqueid : "none");
10594  }
10595 
10596  if (chan)
10597  ast_channel_unlock(chan);
10598  else
10600  return 0;
10601 }
#define ast_channel_lock(chan)
Definition: channel.h:2466
const ast_string_field uniqueid
Definition: channel.h:787
struct ast_var_t * ast_var_assign(const char *name, const char *value)
Definition: chanvars.c:41
const char * ast_var_name(const struct ast_var_t *var)
Definition: chanvars.c:69
static ast_rwlock_t globalslock
Definition: pbx.c:1217
int value
Definition: syslog.c:39
#define ast_rwlock_unlock(a)
Definition: lock.h:200
#define EVENT_FLAG_DIALPLAN
Definition: manager.h:82
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:600
void ast_var_delete(struct ast_var_t *var)
Definition: chanvars.c:63
#define ast_verb(level,...)
Definition: logger.h:243
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:554
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
const ast_string_field name
Definition: channel.h:787
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
Definition: linkedlists.h:696
#define ast_channel_unlock(chan)
Definition: channel.h:2467
static const char name[]
#define ast_rwlock_wrlock(a)
Definition: lock.h:202
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
static struct varshead globals
Definition: pbx.c:1218
#define manager_event(category, event, contents,...)
External routines may send asterisk manager events this way.
Definition: manager.h:219
int ast_func_write(struct ast_channel *chan, const char *function, const char *value)
executes a write operation on a function
Definition: pbx.c:4263
struct varshead varshead
Definition: channel.h:817
int pbx_builtin_setvar_multiple ( struct ast_channel chan,
const char *  data 
)

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

Note
Will lock the channel.

Definition at line 10633 of file pbx.c.

References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_channel::context, ast_sw::data, ast_channel::exten, LOG_WARNING, ast_channel::name, pbx_builtin_setvar_helper(), ast_channel::priority, and value.

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

10634 {
10635  char *data;
10636  int x;
10638  AST_APP_ARG(pair)[24];
10639  );
10640  AST_DECLARE_APP_ARGS(pair,
10641  AST_APP_ARG(name);
10642  AST_APP_ARG(value);
10643  );
10644 
10645  if (ast_strlen_zero(vdata)) {
10646  ast_log(LOG_WARNING, "MSet requires at least one variable name/value pair.\n");
10647  return 0;
10648  }
10649 
10650  data = ast_strdupa(vdata);
10651  AST_STANDARD_APP_ARGS(args, data);
10652 
10653  for (x = 0; x < args.argc; x++) {
10654  AST_NONSTANDARD_APP_ARGS(pair, args.pair[x], '=');
10655  if (pair.argc == 2) {
10656  pbx_builtin_setvar_helper(chan, pair.name, pair.value);
10657  if (strchr(pair.name, ' '))
10658  ast_log(LOG_WARNING, "Please avoid unnecessary spaces on variables as it may lead to unexpected results ('%s' set to '%s').\n", pair.name, pair.value);
10659  } else if (!chan) {
10660  ast_log(LOG_WARNING, "MSet: ignoring entry '%s' with no '='\n", pair.name);
10661  } else {
10662  ast_log(LOG_WARNING, "MSet: ignoring entry '%s' with no '=' (in %s@%s:%d\n", pair.name, chan->exten, chan->context, chan->priority);
10663  }
10664  }
10665 
10666  return 0;
10667 }
int priority
Definition: channel.h:841
char context[AST_MAX_CONTEXT]
Definition: channel.h:868
#define LOG_WARNING
Definition: logger.h:144
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
int value
Definition: syslog.c:39
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static struct @350 args
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static const char name[]
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...
Definition: pbx.c:10546
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
#define AST_NONSTANDARD_APP_ARGS(args, parse, sep)
Performs the &#39;nonstandard&#39; argument separation process for an application.
Definition: app.h:619
char exten[AST_MAX_EXTENSION]
Definition: channel.h:869
int pbx_checkcondition ( const char *  condition)

Evaluate a condition.

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

Definition at line 10719 of file pbx.c.

References ast_strlen_zero().

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

10720 {
10721  int res;
10722  if (ast_strlen_zero(condition)) { /* NULL or empty strings are false */
10723  return 0;
10724  } else if (sscanf(condition, "%30d", &res) == 1) { /* Numbers are evaluated for truth */
10725  return res;
10726  } else { /* Strings are true */
10727  return 1;
10728  }
10729 }
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
int pbx_exec ( struct ast_channel c,
struct ast_app app,
const char *  data 
)

Execute an application.

Parameters
cchannel to execute on
appwhich app to execute
datathe data passed into the app

This application executes an application on a given channel. It saves the stack and executes the given application passing in the given data.

Return values
0success
-1failure
Parameters
cChannel
appApplication
dataData for execution

Definition at line 1497 of file pbx.c.

References __ast_module_user_add(), __ast_module_user_remove(), ast_channel::appl, ast_cdr_setapp(), AST_CEL_APP_END, AST_CEL_APP_START, ast_cel_report_event(), ast_check_hangup(), ast_log(), ast_opt_dont_warn, ast_strlen_zero(), ast_channel::cdr, ast_channel::data, ast_sw::data, ast_app::execute, LOG_WARNING, and S_OR.

Referenced by aelsub_exec(), answer_exec_run(), ast_app_exec_macro(), ast_bridge_call(), ast_pbx_run_app(), async_wait(), builtin_automixmonitor(), builtin_automonitor(), conf_run(), dial_exec_full(), do_magic_pickup(), dundi_exec(), exec_exec(), execif_exec(), feature_exec_app(), forward_message(), handle_exec(), iax2_exec(), lua_pbx_exec(), page_exec(), pbx_builtin_execiftime(), pbx_extension_helper(), realtime_exec(), try_calling(), and tryexec_exec().

1500 {
1501  int res;
1502  struct ast_module_user *u = NULL;
1503  const char *saved_c_appl;
1504  const char *saved_c_data;
1505 
1506  if (c->cdr && !ast_check_hangup(c))
1507  ast_cdr_setapp(c->cdr, app->name, data);
1508 
1509  /* save channel values */
1510  saved_c_appl= c->appl;
1511  saved_c_data= c->data;
1512 
1513  c->appl = app->name;
1514  c->data = data;
1515  ast_cel_report_event(c, AST_CEL_APP_START, NULL, NULL, NULL);
1516 
1517  if (app->module)
1518  u = __ast_module_user_add(app->module, c);
1519  if (strcasecmp(app->name, "system") && !ast_strlen_zero(data) &&
1520  strchr(data, '|') && !strchr(data, ',') && !ast_opt_dont_warn) {
1521  ast_log(LOG_WARNING, "The application delimiter is now the comma, not "
1522  "the pipe. Did you forget to convert your dialplan? (%s(%s))\n",
1523  app->name, (char *) data);
1524  }
1525  res = app->execute(c, S_OR(data, ""));
1526  if (app->module && u)
1527  __ast_module_user_remove(app->module, u);
1528  ast_cel_report_event(c, AST_CEL_APP_END, NULL, NULL, NULL);
1529  /* restore channel values */
1530  c->appl = saved_c_appl;
1531  c->data = saved_c_data;
1532  return res;
1533 }
#define LOG_WARNING
Definition: logger.h:144
int ast_cel_report_event(struct ast_channel *chan, enum ast_cel_event_type event_type, const char *userdefevname, const char *extra, struct ast_channel *peer2)
Report a channel event.
Definition: cel.c:645
void __ast_module_user_remove(struct ast_module *, struct ast_module_user *)
Definition: loader.c:231
struct ast_cdr * cdr
Definition: channel.h:766
const char * data
Definition: channel.h:755
const char * appl
Definition: channel.h:754
#define ast_opt_dont_warn
Definition: options.h:121
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
an app ends
Definition: cel.h:60
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:806
struct ast_module_user * __ast_module_user_add(struct ast_module *, struct ast_channel *)
Definition: loader.c:209
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
void ast_cdr_setapp(struct ast_cdr *cdr, const char *app, const char *data)
Set the last executed application.
Definition: cdr.c:822
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:77
int(* execute)(struct ast_channel *chan, const char *data)
Definition: pbx.c:972
an app starts
Definition: cel.h:58
struct ast_exten* pbx_find_extension ( struct ast_channel chan,
struct ast_context bypass,
struct pbx_find_info q,
const char *  context,
const char *  exten,
int  priority,
const char *  label,
const char *  callerid,
enum ext_match_t  action 
)

Definition at line 3013 of file pbx.c.

References ast_context::alts, ast_autoservice_start(), ast_autoservice_stop(), ast_hashtab_lookup(), AST_LIST_TRAVERSE, ast_log(), AST_PBX_MAX_STACK, ast_str_buffer(), ast_str_size(), ast_str_thread_get(), ast_strdupa, ast_strlen_zero(), ast_walk_context_extensions(), ast_switch::canmatch, scoreboard::canmatch_exten, context, create_match_char_tree(), pbx_find_info::data, ast_sw::data, E_CANMATCH, E_FINDLABEL, E_MATCHMORE, ast_sw::eval, ast_switch::exists, ast_exten::exten, scoreboard::exten, extenpatternmatchnew, extension_match_core(), find_context(), pbx_find_info::foundcontext, include_valid(), ast_context::includes, pbx_find_info::incstack, ast_exten::label, scoreboard::last_char, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, match(), matchcid(), ast_switch::matchmore, ast_sw::name, ast_context::name, new_find_extension(), ast_include::next, scoreboard::node, overrideswitch, ast_context::pattern_tree, pbx_find_extension(), pbx_findswitch(), pbx_substitute_variables_helper(), ast_exten::priority, ast_include::rname, ast_context::root_table, pbx_find_info::stacklen, pbx_find_info::status, STATUS_NO_CONTEXT, STATUS_NO_EXTENSION, STATUS_NO_LABEL, STATUS_NO_PRIORITY, STATUS_SUCCESS, strsep(), switch_data, pbx_find_info::swo, scoreboard::total_length, scoreboard::total_specificity, and trie_find_next_match().

Referenced by ast_hint_extension_nolock(), ast_merge_contexts_and_delete(), check_goto(), check_pval_item(), get_parking_exten(), pbx_extension_helper(), pbx_find_extension(), register_peer_exten(), and remove_exten_if_exist().

3017 {
3018  int x, res;
3019  struct ast_context *tmp = NULL;
3020  struct ast_exten *e = NULL, *eroot = NULL;
3021  struct ast_include *i = NULL;
3022  struct ast_sw *sw = NULL;
3023  struct ast_exten pattern = {NULL, };
3024  struct scoreboard score = {0, };
3025  struct ast_str *tmpdata = NULL;
3026 
3027  pattern.label = label;
3028  pattern.priority = priority;
3029 #ifdef NEED_DEBUG_HERE
3030  ast_log(LOG_NOTICE, "Looking for cont/ext/prio/label/action = %s/%s/%d/%s/%d\n", context, exten, priority, label, (int) action);
3031 #endif
3032 
3033  /* Initialize status if appropriate */
3034  if (q->stacklen == 0) {
3036  q->swo = NULL;
3037  q->data = NULL;
3038  q->foundcontext = NULL;
3039  } else if (q->stacklen >= AST_PBX_MAX_STACK) {
3040  ast_log(LOG_WARNING, "Maximum PBX stack exceeded\n");
3041  return NULL;
3042  }
3043 
3044  /* Check first to see if we've already been checked */
3045  for (x = 0; x < q->stacklen; x++) {
3046  if (!strcasecmp(q->incstack[x], context))
3047  return NULL;
3048  }
3049 
3050  if (bypass) { /* bypass means we only look there */
3051  tmp = bypass;
3052  } else { /* look in contexts */
3053  tmp = find_context(context);
3054  if (!tmp) {
3055  return NULL;
3056  }
3057  }
3058 
3059  if (q->status < STATUS_NO_EXTENSION)
3061 
3062  /* Do a search for matching extension */
3063 
3064  eroot = NULL;
3065  score.total_specificity = 0;
3066  score.exten = 0;
3067  score.total_length = 0;
3068  if (!tmp->pattern_tree && tmp->root_table) {
3070 #ifdef NEED_DEBUG
3071  ast_log(LOG_DEBUG, "Tree Created in context %s:\n", context);
3072  log_match_char_tree(tmp->pattern_tree," ");
3073 #endif
3074  }
3075 #ifdef NEED_DEBUG
3076  ast_log(LOG_NOTICE, "The Trie we are searching in:\n");
3077  log_match_char_tree(tmp->pattern_tree, ":: ");
3078 #endif
3079 
3080  do {
3082  char *osw = ast_strdupa(overrideswitch), *name;
3083  struct ast_switch *asw;
3084  ast_switch_f *aswf = NULL;
3085  char *datap;
3086  int eval = 0;
3087 
3088  name = strsep(&osw, "/");
3089  asw = pbx_findswitch(name);
3090 
3091  if (!asw) {
3092  ast_log(LOG_WARNING, "No such switch '%s'\n", name);
3093  break;
3094  }
3095 
3096  if (osw && strchr(osw, '$')) {
3097  eval = 1;
3098  }
3099 
3100  if (eval && !(tmpdata = ast_str_thread_get(&switch_data, 512))) {
3101  ast_log(LOG_WARNING, "Can't evaluate overrideswitch?!\n");
3102  break;
3103  } else if (eval) {
3104  /* Substitute variables now */
3105  pbx_substitute_variables_helper(chan, osw, ast_str_buffer(tmpdata), ast_str_size(tmpdata));
3106  datap = ast_str_buffer(tmpdata);
3107  } else {
3108  datap = osw;
3109  }
3110 
3111  /* equivalent of extension_match_core() at the switch level */
3112  if (action == E_CANMATCH)
3113  aswf = asw->canmatch;
3114  else if (action == E_MATCHMORE)
3115  aswf = asw->matchmore;
3116  else /* action == E_MATCH */
3117  aswf = asw->exists;
3118  if (!aswf) {
3119  res = 0;
3120  } else {
3121  if (chan) {
3122  ast_autoservice_start(chan);
3123  }
3124  res = aswf(chan, context, exten, priority, callerid, datap);
3125  if (chan) {
3126  ast_autoservice_stop(chan);
3127  }
3128  }
3129  if (res) { /* Got a match */
3130  q->swo = asw;
3131  q->data = datap;
3132  q->foundcontext = context;
3133  /* XXX keep status = STATUS_NO_CONTEXT ? */
3134  return NULL;
3135  }
3136  }
3137  } while (0);
3138 
3139  if (extenpatternmatchnew) {
3140  new_find_extension(exten, &score, tmp->pattern_tree, 0, 0, callerid, label, action);
3141  eroot = score.exten;
3142 
3143  if (score.last_char == '!' && action == E_MATCHMORE) {
3144  /* We match an extension ending in '!'.
3145  * The decision in this case is final and is NULL (no match).
3146  */
3147 #ifdef NEED_DEBUG_HERE
3148  ast_log(LOG_NOTICE,"Returning MATCHMORE NULL with exclamation point.\n");
3149 #endif
3150  return NULL;
3151  }
3152 
3153  if (!eroot && (action == E_CANMATCH || action == E_MATCHMORE) && score.canmatch_exten) {
3154  q->status = STATUS_SUCCESS;
3155 #ifdef NEED_DEBUG_HERE
3156  ast_log(LOG_NOTICE,"Returning CANMATCH exten %s\n", score.canmatch_exten->exten);
3157 #endif
3158  return score.canmatch_exten;
3159  }
3160 
3161  if ((action == E_MATCHMORE || action == E_CANMATCH) && eroot) {
3162  if (score.node) {
3163  struct ast_exten *z = trie_find_next_match(score.node);
3164  if (z) {
3165 #ifdef NEED_DEBUG_HERE
3166  ast_log(LOG_NOTICE,"Returning CANMATCH/MATCHMORE next_match exten %s\n", z->exten);
3167 #endif
3168  } else {
3169  if (score.canmatch_exten) {
3170 #ifdef NEED_DEBUG_HERE
3171  ast_log(LOG_NOTICE,"Returning CANMATCH/MATCHMORE canmatchmatch exten %s(%p)\n", score.canmatch_exten->exten, score.canmatch_exten);
3172 #endif
3173  return score.canmatch_exten;
3174  } else {
3175 #ifdef NEED_DEBUG_HERE
3176  ast_log(LOG_NOTICE,"Returning CANMATCH/MATCHMORE next_match exten NULL\n");
3177 #endif
3178  }
3179  }
3180  return z;
3181  }
3182 #ifdef NEED_DEBUG_HERE
3183  ast_log(LOG_NOTICE, "Returning CANMATCH/MATCHMORE NULL (no next_match)\n");
3184 #endif
3185  return NULL; /* according to the code, complete matches are null matches in MATCHMORE mode */
3186  }
3187 
3188  if (eroot) {
3189  /* found entry, now look for the right priority */
3190  if (q->status < STATUS_NO_PRIORITY)
3192  e = NULL;
3193  if (action == E_FINDLABEL && label ) {
3194  if (q->status < STATUS_NO_LABEL)
3195  q->status = STATUS_NO_LABEL;
3196  e = ast_hashtab_lookup(eroot->peer_label_table, &pattern);
3197  } else {
3198  e = ast_hashtab_lookup(eroot->peer_table, &pattern);
3199  }
3200  if (e) { /* found a valid match */
3201  q->status = STATUS_SUCCESS;
3202  q->foundcontext = context;
3203 #ifdef NEED_DEBUG_HERE
3204  ast_log(LOG_NOTICE,"Returning complete match of exten %s\n", e->exten);
3205 #endif
3206  return e;
3207  }
3208  }
3209  } else { /* the old/current default exten pattern match algorithm */
3210 
3211  /* scan the list trying to match extension and CID */
3212  eroot = NULL;
3213  while ( (eroot = ast_walk_context_extensions(tmp, eroot)) ) {
3214  int match = extension_match_core(eroot->exten, exten, action);
3215  /* 0 on fail, 1 on match, 2 on earlymatch */
3216 
3217  if (!match || (eroot->matchcid && !matchcid(eroot->cidmatch, callerid)))
3218  continue; /* keep trying */
3219  if (match == 2 && action == E_MATCHMORE) {
3220  /* We match an extension ending in '!'.
3221  * The decision in this case is final and is NULL (no match).
3222  */
3223  return NULL;
3224  }
3225  /* found entry, now look for the right priority */
3226  if (q->status < STATUS_NO_PRIORITY)
3228  e = NULL;
3229  if (action == E_FINDLABEL && label ) {
3230  if (q->status < STATUS_NO_LABEL)
3231  q->status = STATUS_NO_LABEL;
3232  e = ast_hashtab_lookup(eroot->peer_label_table, &pattern);
3233  } else {
3234  e = ast_hashtab_lookup(eroot->peer_table, &pattern);
3235  }
3236  if (e) { /* found a valid match */
3237  q->status = STATUS_SUCCESS;
3238  q->foundcontext = context;
3239  return e;
3240  }
3241  }
3242  }
3243 
3244  /* Check alternative switches */
3245  AST_LIST_TRAVERSE(&tmp->alts, sw, list) {
3246  struct ast_switch *asw = pbx_findswitch(sw->name);
3247  ast_switch_f *aswf = NULL;
3248  char *datap;
3249 
3250  if (!asw) {
3251  ast_log(LOG_WARNING, "No such switch '%s'\n", sw->name);
3252  continue;
3253  }
3254 
3255  /* Substitute variables now */
3256  if (sw->eval) {
3257  if (!(tmpdata = ast_str_thread_get(&switch_data, 512))) {
3258  ast_log(LOG_WARNING, "Can't evaluate switch?!\n");
3259  continue;
3260  }
3261  pbx_substitute_variables_helper(chan, sw->data, ast_str_buffer(tmpdata), ast_str_size(tmpdata));
3262  }
3263 
3264  /* equivalent of extension_match_core() at the switch level */
3265  if (action == E_CANMATCH)
3266  aswf = asw->canmatch;
3267  else if (action == E_MATCHMORE)
3268  aswf = asw->matchmore;
3269  else /* action == E_MATCH */
3270  aswf = asw->exists;
3271  datap = sw->eval ? ast_str_buffer(tmpdata) : sw->data;
3272  if (!aswf)
3273  res = 0;
3274  else {
3275  if (chan)
3276  ast_autoservice_start(chan);
3277  res = aswf(chan, context, exten, priority, callerid, datap);
3278  if (chan)
3279  ast_autoservice_stop(chan);
3280  }
3281  if (res) { /* Got a match */
3282  q->swo = asw;
3283  q->data = datap;
3284  q->foundcontext = context;
3285  /* XXX keep status = STATUS_NO_CONTEXT ? */
3286  return NULL;
3287  }
3288  }
3289  q->incstack[q->stacklen++] = tmp->name; /* Setup the stack */
3290  /* Now try any includes we have in this context */
3291  for (i = tmp->includes; i; i = i->next) {
3292  if (include_valid(i)) {
3293  if ((e = pbx_find_extension(chan, bypass, q, i->rname, exten, priority, label, callerid, action))) {
3294 #ifdef NEED_DEBUG_HERE
3295  ast_log(LOG_NOTICE,"Returning recursive match of %s\n", e->exten);
3296 #endif
3297  return e;
3298  }
3299  if (q->swo)
3300  return NULL;
3301  }
3302  }
3303  return NULL;
3304 }
ast_include: include= support in extensions.conf
Definition: pbx.c:904
void pbx_substitute_variables_helper(struct ast_channel *c, const char *cp1, char *cp2, int count)
Definition: pbx.c:4676
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.
Definition: pbx.h:124
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:109
ast_exten: An extension The dialplan is saved as a linked list with each context having it&#39;s own link...
Definition: pbx.c:884
void * ast_hashtab_lookup(struct ast_hashtab *tab, const void *obj)
Lookup this object in the hash table.
Definition: hashtab.c:534
struct ast_include * next
Definition: pbx.c:910
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
Definition: autoservice.c:179
char * strsep(char **str, const char *delims)
struct ast_include * includes
Definition: pbx.c:961
#define STATUS_NO_PRIORITY
Definition: pbx.c:2997
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition: strings.h:482
static void new_find_extension(const char *str, struct scoreboard *score, struct match_char *tree, int length, int spec, const char *callerid, const char *label, enum ext_match_t action)
Definition: pbx.c:1807
const char * rname
Definition: pbx.c:906
#define LOG_WARNING
Definition: logger.h:144
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
char last_char
Definition: pbx.c:947
#define STATUS_NO_EXTENSION
Definition: pbx.c:2996
const char * label
Definition: pbx.c:889
char * incstack[AST_PBX_MAX_STACK]
Definition: extconf.h:233
#define LOG_DEBUG
Definition: logger.h:122
static struct ast_exten * trie_find_next_match(struct match_char *node)
Definition: pbx.c:1748
ast_switch_f * matchmore
Definition: pbx.h:136
int priority
Definition: pbx.c:888
ast_sw: Switch statement in extensions.conf
Definition: pbx.c:915
struct ast_exten * ast_walk_context_extensions(struct ast_context *con, struct ast_exten *priority)
Definition: pbx.c:11179
const char * data
Definition: extconf.h:237
static void create_match_char_tree(struct ast_context *con)
Definition: pbx.c:2321
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
struct ast_exten * canmatch_exten
Definition: pbx.c:950
static struct ast_threadstorage switch_data
Definition: pbx.c:864
char * exten
Definition: pbx.c:885
#define STATUS_SUCCESS
Definition: pbx.c:2999
char name[0]
Definition: pbx.c:967
int total_specificity
Definition: pbx.c:945
#define STATUS_NO_LABEL
Definition: pbx.c:2998
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
Definition: autoservice.c:238
static int extension_match_core(const char *pattern, const char *data, enum ext_match_t mode)
Definition: pbx.c:2930
ast_switch_f * canmatch
Definition: pbx.h:134
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
int eval
Definition: pbx.c:919
char * data
Definition: pbx.c:918
#define STATUS_NO_CONTEXT
Definition: pbx.c:2995
#define AST_PBX_MAX_STACK
Definition: extconf.h:223
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
static int extenpatternmatchnew
Definition: pbx.c:1221
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
static int matchcid(const char *cidpattern, const char *callerid)
Definition: pbx.c:3001
static const char name[]
const char * foundcontext
Definition: extconf.h:238
int stacklen
Definition: extconf.h:234
struct pval * find_context(char *name)
Definition: pval.c:1960
struct match_char * node
Definition: pbx.c:949
static struct ast_switch * pbx_findswitch(const char *sw)
Definition: pbx.c:1551
struct ast_context::@290 alts
static char * overrideswitch
Definition: pbx.c:1222
struct ast_switch * swo
Definition: extconf.h:236
static int include_valid(struct ast_include *i)
Definition: pbx.c:1565
struct ast_hashtab * root_table
Definition: pbx.c:958
ast_switch_f * exists
Definition: pbx.h:133
struct ast_exten * pbx_find_extension(struct ast_channel *chan, struct ast_context *bypass, struct pbx_find_info *q, const char *context, const char *exten, int priority, const char *label, const char *callerid, enum ext_match_t action)
Definition: pbx.c:3013
int total_length
Definition: pbx.c:946
struct ast_str * ast_str_thread_get(struct ast_threadstorage *ts, size_t init_len)
Retrieve a thread locally stored dynamic string.
Definition: strings.h:669
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
struct ast_exten * exten
Definition: pbx.c:951
char * name
Definition: pbx.c:916
static int match(struct sockaddr_in *sin, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2069
ast_context: An extension context
Definition: pbx.c:955
struct match_char * pattern_tree
Definition: pbx.c:959
struct ast_app* pbx_findapp ( const char *  app)

Look up an application.

Parameters
appname of the app

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

Returns
the ast_app structure that matches on success, or NULL on failure

Look up an application.

Definition at line 1537 of file pbx.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, and AST_RWLIST_UNLOCK.

Referenced by aelsub_exec(), answer_exec_run(), ast_app_exec_macro(), ast_bridge_call(), ast_pbx_run_app(), async_wait(), builtin_automixmonitor(), builtin_automonitor(), conf_run(), dial_exec_full(), do_magic_pickup(), dundi_exec(), exec_exec(), execif_exec(), feature_exec_app(), forward_message(), handle_exec(), iax2_exec(), lua_pbx_exec(), page_exec(), pbx_builtin_execiftime(), pbx_extension_helper(), realtime_exec(), try_calling(), and tryexec_exec().

1538 {
1539  struct ast_app *tmp;
1540 
1542  AST_RWLIST_TRAVERSE(&apps, tmp, list) {
1543  if (!strcasecmp(tmp->name, app))
1544  break;
1545  }
1547 
1548  return tmp;
1549 }
Definition: pbx.c:1301
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
static const char app[]
Definition: app_adsiprog.c:49
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
ast_app: A registered application
Definition: pbx.c:971
void pbx_live_dangerously ( int  new_live_dangerously)

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

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

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

Parameters
new_live_dangerouslyIf true, enable the execution of escalating functions from external protocols.

Definition at line 4059 of file pbx.c.

References ast_log(), LOG_NOTICE, and LOG_WARNING.

Referenced by ast_readconfig().

4060 {
4061  if (new_live_dangerously && !live_dangerously) {
4062  ast_log(LOG_WARNING, "Privilege escalation protection disabled!\n"
4063  "See https://wiki.asterisk.org/wiki/x/1gKfAQ for more details.\n");
4064  }
4065 
4066  if (!new_live_dangerously && live_dangerously) {
4067  ast_log(LOG_NOTICE, "Privilege escalation protection enabled.\n");
4068  }
4069  live_dangerously = new_live_dangerously;
4070 }
#define LOG_WARNING
Definition: logger.h:144
static int live_dangerously
Set to true (non-zero) to globally allow all dangerous dialplan functions to run. ...
Definition: pbx.c:870
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
void pbx_retrieve_variable ( struct ast_channel c,
const char *  var,
char **  ret,
char *  workspace,
int  workspacelen,
struct varshead headp 
)

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

Note
Will lock the channel.

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

Note
See also

Definition at line 3434 of file pbx.c.

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

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

3435 {
3436  struct ast_str *str = ast_str_create(16);
3437  const char *cret;
3438 
3439  cret = ast_str_retrieve_variable(&str, 0, c, headp, var);
3440  ast_copy_string(workspace, ast_str_buffer(str), workspacelen);
3441  *ret = cret ? workspace : NULL;
3442  ast_free(str);
3443 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
#define var
Definition: ast_expr2f.c:606
struct ast_str * ast_str_create(size_t init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:420
const char * str
Definition: app_jack.c:144
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
#define ast_free(a)
Definition: astmm.h:97
const char * ast_str_retrieve_variable(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, struct varshead *headp, const char *var)
Definition: pbx.c:3445
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
int pbx_set_autofallthrough ( int  newval)

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

Definition at line 5941 of file pbx.c.

References autofallthrough.

Referenced by pbx_load_module().

5942 {
5943  int oldval = autofallthrough;
5944  autofallthrough = newval;
5945  return oldval;
5946 }
static int autofallthrough
Definition: pbx.c:1220
int pbx_set_extenpatternmatchnew ( int  newval)

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

Definition at line 5948 of file pbx.c.

References extenpatternmatchnew.

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

5949 {
5950  int oldval = extenpatternmatchnew;
5951  extenpatternmatchnew = newval;
5952  return oldval;
5953 }
static int extenpatternmatchnew
Definition: pbx.c:1221
void pbx_set_overrideswitch ( const char *  newval)

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

Since
1.6.1

Definition at line 5955 of file pbx.c.

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

Referenced by pbx_load_module().

5956 {
5957  if (overrideswitch) {
5959  }
5960  if (!ast_strlen_zero(newval)) {
5961  overrideswitch = ast_strdup(newval);
5962  } else {
5963  overrideswitch = NULL;
5964  }
5965 }
#define ast_strdup(a)
Definition: astmm.h:109
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_free(a)
Definition: astmm.h:97
static char * overrideswitch
Definition: pbx.c:1222
void pbx_substitute_variables_helper ( struct ast_channel c,
const char *  cp1,
char *  cp2,
int  count 
)

Definition at line 4676 of file pbx.c.

References pbx_substitute_variables_helper_full(), and ast_channel::varshead.

Referenced by add_extensions(), ast_add_extension2_lockopt(), function_eval(), get_manager_event_info(), get_mapping_weight(), import_helper(), launch_monitor_thread(), manager_log(), pbx_builtin_importvar(), pbx_extension_helper(), pbx_find_extension(), pbx_load_config(), realtime_exec(), rotate_file(), substituted(), and try_calling().

4677 {
4678  size_t used;
4679  pbx_substitute_variables_helper_full(c, (c) ? &c->varshead : NULL, cp1, cp2, count, &used);
4680 }
void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int cp2_size, size_t *used)
Definition: pbx.c:4480
struct varshead varshead
Definition: channel.h:817
void pbx_substitute_variables_helper_full ( struct ast_channel c,
struct varshead headp,
const char *  cp1,
char *  cp2,
int  cp2_size,
size_t *  used 
)

Definition at line 4480 of file pbx.c.

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

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

4481 {
4482  /* Substitutes variables into cp2, based on string cp1, cp2 NO LONGER NEEDS TO BE ZEROED OUT!!!! */
4483  char *cp4 = NULL;
4484  const char *tmp, *whereweare, *orig_cp2 = cp2;
4485  int length, offset, offset2, isfunction;
4486  char *workspace = NULL;
4487  char *ltmp = NULL, *var = NULL;
4488  char *nextvar, *nextexp, *nextthing;
4489  char *vars, *vare;
4490  int pos, brackets, needsub, len;
4491 
4492  *cp2 = 0; /* just in case nothing ends up there */
4493  whereweare=tmp=cp1;
4494  while (!ast_strlen_zero(whereweare) && count) {
4495  /* Assume we're copying the whole remaining string */
4496  pos = strlen(whereweare);
4497  nextvar = NULL;
4498  nextexp = NULL;
4499  nextthing = strchr(whereweare, '$');
4500  if (nextthing) {
4501  switch (nextthing[1]) {
4502  case '{':
4503  nextvar = nextthing;
4504  pos = nextvar - whereweare;
4505  break;
4506  case '[':
4507  nextexp = nextthing;
4508  pos = nextexp - whereweare;
4509  break;
4510  default:
4511  pos = 1;
4512  }
4513  }
4514 
4515  if (pos) {
4516  /* Can't copy more than 'count' bytes */
4517  if (pos > count)
4518  pos = count;
4519 
4520  /* Copy that many bytes */
4521  memcpy(cp2, whereweare, pos);
4522 
4523  count -= pos;
4524  cp2 += pos;
4525  whereweare += pos;
4526  *cp2 = 0;
4527  }
4528 
4529  if (nextvar) {
4530  /* We have a variable. Find the start and end, and determine
4531  if we are going to have to recursively call ourselves on the
4532  contents */
4533  vars = vare = nextvar + 2;
4534  brackets = 1;
4535  needsub = 0;
4536 
4537  /* Find the end of it */
4538  while (brackets && *vare) {
4539  if ((vare[0] == '$') && (vare[1] == '{')) {
4540  needsub++;
4541  } else if (vare[0] == '{') {
4542  brackets++;
4543  } else if (vare[0] == '}') {
4544  brackets--;
4545  } else if ((vare[0] == '$') && (vare[1] == '['))
4546  needsub++;
4547  vare++;
4548  }
4549  if (brackets)
4550  ast_log(LOG_WARNING, "Error in extension logic (missing '}')\n");
4551  len = vare - vars - 1;
4552 
4553  /* Skip totally over variable string */
4554  whereweare += (len + 3);
4555 
4556  if (!var)
4557  var = ast_alloca(VAR_BUF_SIZE);
4558 
4559  /* Store variable name (and truncate) */
4560  ast_copy_string(var, vars, len + 1);
4561 
4562  /* Substitute if necessary */
4563  if (needsub) {
4564  size_t used;
4565  if (!ltmp)
4566  ltmp = ast_alloca(VAR_BUF_SIZE);
4567 
4568  pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, &used);
4569  vars = ltmp;
4570  } else {
4571  vars = var;
4572  }
4573 
4574  if (!workspace)
4575  workspace = ast_alloca(VAR_BUF_SIZE);
4576 
4577  workspace[0] = '\0';
4578 
4579  parse_variable_name(vars, &offset, &offset2, &isfunction);
4580  if (isfunction) {
4581  /* Evaluate function */
4582  if (c || !headp)
4583  cp4 = ast_func_read(c, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace;
4584  else {
4585  struct varshead old;
4586  struct ast_channel *c = ast_dummy_channel_alloc();
4587  if (c) {
4588  memcpy(&old, &c->varshead, sizeof(old));
4589  memcpy(&c->varshead, headp, sizeof(c->varshead));
4590  cp4 = ast_func_read(c, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace;
4591  /* Don't deallocate the varshead that was passed in */
4592  memcpy(&c->varshead, &old, sizeof(c->varshead));
4593  c = ast_channel_unref(c);
4594  } else {
4595  ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution. Function results may be blank.\n");
4596  }
4597  }
4598  ast_debug(2, "Function %s result is '%s'\n", vars, cp4 ? cp4 : "(null)");
4599  } else {
4600  /* Retrieve variable value */
4601  pbx_retrieve_variable(c, vars, &cp4, workspace, VAR_BUF_SIZE, headp);
4602  }
4603  if (cp4) {
4604  cp4 = substring(cp4, offset, offset2, workspace, VAR_BUF_SIZE);
4605 
4606  length = strlen(cp4);
4607  if (length > count)
4608  length = count;
4609  memcpy(cp2, cp4, length);
4610  count -= length;
4611  cp2 += length;
4612  *cp2 = 0;
4613  }
4614  } else if (nextexp) {
4615  /* We have an expression. Find the start and end, and determine
4616  if we are going to have to recursively call ourselves on the
4617  contents */
4618  vars = vare = nextexp + 2;
4619  brackets = 1;
4620  needsub = 0;
4621 
4622  /* Find the end of it */
4623  while (brackets && *vare) {
4624  if ((vare[0] == '$') && (vare[1] == '[')) {
4625  needsub++;
4626  brackets++;
4627  vare++;
4628  } else if (vare[0] == '[') {
4629  brackets++;
4630  } else if (vare[0] == ']') {
4631  brackets--;
4632  } else if ((vare[0] == '$') && (vare[1] == '{')) {
4633  needsub++;
4634  vare++;
4635  }
4636  vare++;
4637  }
4638  if (brackets)
4639  ast_log(LOG_WARNING, "Error in extension logic (missing ']')\n");
4640  len = vare - vars - 1;
4641 
4642  /* Skip totally over expression */
4643  whereweare += (len + 3);
4644 
4645  if (!var)
4646  var = ast_alloca(VAR_BUF_SIZE);
4647 
4648  /* Store variable name (and truncate) */
4649  ast_copy_string(var, vars, len + 1);
4650 
4651  /* Substitute if necessary */
4652  if (needsub) {
4653  size_t used;
4654  if (!ltmp)
4655  ltmp = ast_alloca(VAR_BUF_SIZE);
4656 
4657  pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, &used);
4658  vars = ltmp;
4659  } else {
4660  vars = var;
4661  }
4662 
4663  length = ast_expr(vars, cp2, count, c);
4664 
4665  if (length) {
4666  ast_debug(1, "Expression result is '%s'\n", cp2);
4667  count -= length;
4668  cp2 += length;
4669  *cp2 = 0;
4670  }
4671  }
4672  }
4673  *used = cp2 - orig_cp2;
4674 }
int ast_func_read(struct ast_channel *chan, const char *function, char *workspace, size_t len)
executes a read operation on a function
Definition: pbx.c:4177
Main Channel structure associated with a channel.
Definition: channel.h:742
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: utils.h:653
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2502
static char * substring(const char *value, int offset, int length, char *workspace, size_t workspace_len)
takes a substring. It is ok to call with value == workspace.
Definition: pbx.c:3344
#define LOG_WARNING
Definition: logger.h:144
#define var
Definition: ast_expr2f.c:606
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define LOG_ERROR
Definition: logger.h:155
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.
Definition: pbx.c:3434
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
static int parse_variable_name(char *var, int *offset, int *length, int *isfunc)
extract offset:length from variable name.
Definition: pbx.c:3311
void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int cp2_size, size_t *used)
Definition: pbx.c:4480
struct ast_channel * ast_dummy_channel_alloc(void)
Create a fake channel structure.
Definition: channel.c:1391
int ast_expr(char *expr, char *buf, int length, struct ast_channel *chan)
Evaluate the given expression.
Definition: ast_expr2f.c:2396
struct varshead varshead
Definition: channel.h:817
#define VAR_BUF_SIZE
Definition: pbx.c:833
void pbx_substitute_variables_varshead ( struct varshead headp,
const char *  cp1,
char *  cp2,
int  count 
)

Definition at line 4682 of file pbx.c.

References pbx_substitute_variables_helper_full().

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

4683 {
4684  size_t used;
4685  pbx_substitute_variables_helper_full(NULL, headp, cp1, cp2, count, &used);
4686 }
void pbx_substitute_variables_helper_full(struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int cp2_size, size_t *used)
Definition: pbx.c:4480