Core PBX routines and definitions. More...
#include "asterisk/sched.h"
#include "asterisk/devicestate.h"
#include "asterisk/chanvars.h"
#include "asterisk/hashtab.h"
#include "asterisk/stringfields.h"
#include "asterisk/devicestate.h"
#include "asterisk/hashtab.h"
Go to the source code of this file.
Data Structures | |
struct | ast_custom_function |
Data structure associated with a custom dialplan function. More... | |
struct | ast_pbx |
struct | ast_pbx_args |
Options for ast_pbx_run() More... | |
struct | ast_switch |
struct | ast_timing |
struct | pbx_find_info |
Defines | |
#define | ast_custom_function_register(acf) __ast_custom_function_register(acf, ast_module_info->self) |
Register a custom function. | |
#define | AST_MAX_APP 32 |
#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. | |
#define | AST_PBX_OK 0 |
#define | AST_PBX_ERROR 1 |
#define | AST_PBX_INCOMPLETE 12 |
Typedefs | |
typedef int(* | ast_state_cb_type )(char *context, char *id, enum ast_extension_states state, void *data) |
Typedef for devicestate and hint callbacks. | |
typedef int( | ast_switch_f )(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data) |
All switch functions have the same interface, so define a type for them. | |
Enumerations | |
enum | ast_doc_src { AST_XML_DOC, AST_STATIC_DOC } |
From where the documentation come from. 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. 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. | |
int | ast_active_calls (void) |
Retrieve the number of active calls. | |
int | ast_add_extension (const char *context, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar) |
Add and extension to an extension context. | |
int | ast_add_extension2 (struct ast_context *con, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar) |
Add an extension to an extension context, this time with an ast_context *. | |
int | ast_async_goto (struct ast_channel *chan, const char *context, const char *exten, int priority) |
Set the channel to next execute the specified dialplan location. | |
int | ast_async_goto_by_name (const char *chan, const char *context, const char *exten, int priority) |
Set the channel to next execute the specified dialplan location. | |
int | ast_async_goto_if_exists (struct ast_channel *chan, const char *context, const char *exten, int priority) |
int | ast_async_parseable_goto (struct ast_channel *chan, const char *goto_string) |
int | ast_build_timing (struct ast_timing *i, const char *info) |
Construct a timing bitmap, for use in time-based conditionals. | |
int | ast_canmatch_extension (struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid) |
Looks for a valid matching extension. | |
int | ast_check_timing (const struct ast_timing *i) |
Evaluate a pre-constructed bitmap as to whether the current time falls within the range specified. | |
int | ast_context_add_ignorepat (const char *context, const char *ignorepat, const char *registrar) |
Add an ignorepat. | |
int | ast_context_add_ignorepat2 (struct ast_context *con, const char *ignorepat, const char *registrar) |
int | ast_context_add_include (const char *context, const char *include, const char *registrar) |
Add a context include. | |
int | ast_context_add_include2 (struct ast_context *con, const char *include, const char *registrar) |
Add a context include. | |
int | ast_context_add_switch (const char *context, const char *sw, const char *data, int eval, const char *registrar) |
Add a switch. | |
int | ast_context_add_switch2 (struct ast_context *con, const char *sw, const char *data, int eval, const char *registrar) |
Adds a switch (first param is a ast_context) | |
void | ast_context_destroy (struct ast_context *con, const char *registrar) |
Destroy a context (matches the specified context (or ANY context if NULL) | |
struct ast_context * | ast_context_find (const char *name) |
Find a context. | |
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. | |
int | ast_context_lockmacro (const char *macrocontext) |
locks the macrolock in the given given context | |
int | ast_context_remove_ignorepat (const char *context, const char *ignorepat, const char *registrar) |
int | ast_context_remove_ignorepat2 (struct ast_context *con, const char *ignorepat, const char *registrar) |
int | ast_context_remove_include (const char *context, const char *include, const char *registrar) |
Remove a context include. | |
int | ast_context_remove_include2 (struct ast_context *con, const char *include, const char *registrar) |
Removes an include by an ast_context structure. | |
int | ast_context_remove_switch (const char *context, const char *sw, const char *data, const char *registrar) |
Remove a switch. | |
int | ast_context_remove_switch2 (struct ast_context *con, const char *sw, const char *data, const char *registrar) |
This function locks given context, removes switch, unlock context and return. | |
int | ast_context_unlockmacro (const char *macrocontext) |
Unlocks the macrolock in the given context. | |
int | ast_context_verify_includes (struct ast_context *con) |
Verifies includes in an ast_contect structure. | |
struct ast_custom_function * | ast_custom_function_find (const char *name) |
int | ast_custom_function_unregister (struct ast_custom_function *acf) |
Unregister a custom function. | |
int | ast_destroy_timing (struct ast_timing *i) |
Deallocates memory structures associated with a timing bitmap. | |
enum ast_extension_states | ast_devstate_to_extenstate (enum ast_device_state devstate) |
Map devstate to an extension state. | |
int | ast_exists_extension (struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid) |
Determine whether an extension exists. | |
int | ast_explicit_goto (struct ast_channel *chan, const char *context, const char *exten, int priority) |
int | ast_extension_close (const char *pattern, const char *data, int needmore) |
int | ast_extension_cmp (const char *a, const char *b) |
Determine if one extension should match before another. | |
int | ast_extension_match (const char *pattern, const char *extension) |
Determine if a given extension matches a given pattern (in NXX format) | |
int | ast_extension_patmatch (const char *pattern, const char *data) |
int | ast_extension_state (struct ast_channel *c, const char *context, const char *exten) |
Uses hint and devicestate callback to get the state of an extension. | |
const char * | ast_extension_state2str (int extension_state) |
Return string representation of the state of an extension. | |
int | ast_extension_state_add (const char *context, const char *exten, ast_state_cb_type callback, void *data) |
Registers a state change callback. | |
int | ast_extension_state_del (int id, ast_state_cb_type callback) |
Deletes a registered state change callback by ID. | |
int | ast_findlabel_extension (struct ast_channel *c, const char *context, const char *exten, const char *label, const char *callerid) |
Find the priority of an extension that has the specified label. | |
int | ast_findlabel_extension2 (struct ast_channel *c, struct ast_context *con, const char *exten, const char *label, const char *callerid) |
Find the priority of an extension that has the specified label. | |
int | ast_func_read (struct ast_channel *chan, const char *function, char *workspace, size_t len) |
executes a read operation on a function | |
int | ast_func_write (struct ast_channel *chan, const char *function, const char *value) |
executes a write operation on a function | |
int | ast_get_hint (char *hint, int hintsize, char *name, int namesize, struct ast_channel *c, const char *context, const char *exten) |
If an extension hint exists, return non-zero. | |
int | ast_goto_if_exists (struct ast_channel *chan, const char *context, const char *exten, int priority) |
int | ast_ignore_pattern (const char *context, const char *pattern) |
Checks to see if a number should be ignored. | |
int | ast_matchmore_extension (struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid) |
Looks to see if adding anything to this extension might match something. (exists ^ canmatch) | |
void | ast_merge_contexts_and_delete (struct ast_context **extcontexts, struct ast_hashtab *exttable, const char *registrar) |
Merge the temporary contexts into a global contexts list and delete from the global list the ones that are being added. | |
int | ast_parseable_goto (struct ast_channel *chan, const char *goto_string) |
int | ast_pbx_outgoing_app (const char *type, int 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, int 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. | |
enum ast_pbx_result | ast_pbx_run_args (struct ast_channel *c, struct ast_pbx_args *args) |
Execute the PBX in the current thread. | |
enum ast_pbx_result | ast_pbx_start (struct ast_channel *c) |
Create a new thread and start the PBX. | |
int | ast_processed_calls (void) |
Retrieve the total number of calls processed through the PBX since last restart. | |
int | ast_rdlock_context (struct ast_context *con) |
Read locks a given context. | |
int | ast_rdlock_contexts (void) |
Read locks the context list. | |
int | ast_register_switch (struct ast_switch *sw) |
Register an alternative dialplan switch. | |
int | ast_spawn_extension (struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid, int *found, int combined_find_spawn) |
Launch a new extension (i.e. new stack) | |
int | ast_unlock_context (struct ast_context *con) |
int | ast_unlock_contexts (void) |
Unlocks contexts. | |
void | ast_unregister_switch (struct ast_switch *sw) |
Unregister an alternative switch. | |
int | ast_wrlock_context (struct ast_context *con) |
Write locks a given context. | |
int | ast_wrlock_contexts (void) |
Write locks the context list. | |
void | pbx_builtin_clear_globals (void) |
const char * | pbx_builtin_getvar_helper (struct ast_channel *chan, const char *name) |
Return a pointer to the value of the corresponding channel variable. | |
void | pbx_builtin_pushvar_helper (struct ast_channel *chan, const char *name, const char *value) |
Add a variable to the channel variable stack, without removing any previously set value. | |
int | pbx_builtin_raise_exception (struct ast_channel *chan, void *data) |
int | pbx_builtin_serialize_variables (struct ast_channel *chan, struct ast_str **buf) |
Create a human-readable string, specifying all variables and their corresponding values. | |
int | pbx_builtin_setvar (struct ast_channel *chan, void *data) |
Parse and set a single channel variable, where the name and value are separated with an '=' character. | |
void | pbx_builtin_setvar_helper (struct ast_channel *chan, const char *name, const char *value) |
Add a variable to the channel variable stack, removing the most recently set value for the same name. | |
int | pbx_builtin_setvar_multiple (struct ast_channel *chan, void *data) |
Parse and set multiple channel variables, where the pairs are separated by the ',' character, and name and value are separated with an '=' character. | |
int | pbx_checkcondition (const char *condition) |
Evaluate a condition. | |
int | pbx_exec (struct ast_channel *c, struct ast_app *app, void *data) |
Execute an application. | |
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) |
struct ast_app * | pbx_findapp (const char *app) |
Look up an application. | |
void | pbx_retrieve_variable (struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp) |
Retrieve the value of a builtin variable or variable from the channel variable stack. | |
int | pbx_set_autofallthrough (int newval) |
int | pbx_set_extenpatternmatchnew (int newval) |
void | pbx_set_overrideswitch (const char *newval) |
int | ast_context_remove_extension (const char *context, const char *extension, int priority, const char *registrar) |
Simply remove extension from context. | |
int | ast_context_remove_extension2 (struct ast_context *con, const char *extension, int priority, const char *registrar, int already_locked) |
This functionc locks given context, search for the right extension and fires out all peer in this extensions with given priority. If priority is set to 0, all peers are removed. After that, unlock context and return. | |
int | ast_context_remove_extension_callerid (const char *context, const char *extension, int priority, const char *callerid, int matchcid, const char *registrar) |
int | ast_context_remove_extension_callerid2 (struct ast_context *con, const char *extension, int priority, const char *callerid, int matchcid, const char *registrar, int already_locked) |
Functions for returning values from structures | |
const char * | ast_get_context_name (struct ast_context *con) |
const char * | ast_get_extension_name (struct ast_exten *exten) |
struct ast_context * | ast_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_context * | ast_walk_contexts (struct ast_context *con) |
struct ast_exten * | ast_walk_context_extensions (struct ast_context *con, struct ast_exten *priority) |
struct ast_exten * | ast_walk_extension_priorities (struct ast_exten *exten, struct ast_exten *priority) |
struct ast_include * | ast_walk_context_includes (struct ast_context *con, struct ast_include *inc) |
struct ast_ignorepat * | ast_walk_context_ignorepats (struct ast_context *con, struct ast_ignorepat *ip) |
struct ast_sw * | ast_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) |
void | ast_str_substitute_variables (struct ast_str **buf, size_t maxlen, struct ast_channel *chan, const char *templ) |
int | ast_hashtab_compare_contexts (const void *ah_a, const void *ah_b) |
hashtable functions for contexts | |
unsigned int | ast_hashtab_hash_contexts (const void *obj) |
Core PBX routines and definitions.
Definition in file pbx.h.
#define ast_custom_function_register | ( | acf | ) | __ast_custom_function_register(acf, ast_module_info->self) |
Register a custom function.
Definition at line 1028 of file pbx.h.
Referenced by load_module(), and reload().
#define AST_MAX_APP 32 |
Max length of an application
Definition at line 36 of file pbx.h.
Referenced by destroy_station(), handle_show_function(), print_app_docs(), and sla_build_station().
#define AST_PBX_ERROR 1 |
#define AST_PBX_HANGUP -1 |
#define AST_PBX_INCOMPLETE 12 |
Return to PBX matching, allowing more digits for the extension
Definition at line 46 of file pbx.h.
Referenced by __ast_pbx_run(), dial_exec_full(), pbx_builtin_incomplete(), and retrydial_exec().
#define PRIORITY_HINT -1 |
Special Priority for a hint
Definition at line 49 of file pbx.h.
Referenced by add_extensions(), add_pri_lockopt(), ast_add_extension2_lockopt(), ast_hint_extension_nolock(), ast_merge_contexts_and_delete(), destroy_exten(), destroy_station(), handle_cli_dialplan_add_extension(), handle_cli_dialplan_remove_extension(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), park_add_hints(), pbx_load_config(), print_ext(), and sla_build_station().
typedef int(* ast_state_cb_type)(char *context, char *id, enum ast_extension_states state, void *data) |
typedef int( ast_switch_f)(struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data) |
enum ast_doc_src |
From where the documentation come from.
AST_XML_DOC |
From XML documentation |
AST_STATIC_DOC |
From application/function registration |
Definition at line 77 of file pbx.h.
{ AST_XML_DOC, /*!< From XML documentation */ AST_STATIC_DOC /*!< From application/function registration */ };
enum ast_extension_states |
Extension states.
Definition at line 55 of file pbx.h.
{ AST_EXTENSION_REMOVED = -2, /*!< Extension removed */ AST_EXTENSION_DEACTIVATED = -1, /*!< Extension hint removed */ AST_EXTENSION_NOT_INUSE = 0, /*!< No device INUSE or BUSY */ AST_EXTENSION_INUSE = 1 << 0, /*!< One or more devices INUSE */ AST_EXTENSION_BUSY = 1 << 1, /*!< All devices BUSY */ AST_EXTENSION_UNAVAILABLE = 1 << 2, /*!< All devices UNAVAILABLE/UNREGISTERED */ AST_EXTENSION_RINGING = 1 << 3, /*!< All devices RINGING */ AST_EXTENSION_ONHOLD = 1 << 4, /*!< All devices ONHOLD */ };
enum ast_pbx_result |
The result codes when starting the PBX on a channel with.
Definition at line 262 of file pbx.h.
{ AST_PBX_SUCCESS = 0, AST_PBX_FAILED = -1, AST_PBX_CALL_LIMIT = -2, };
enum ext_match_t |
When looking up extensions, we can have different requests identified by the 'action' argument, as follows. Note that the coding is such that the low 4 bits are the third argument to extension_match_core.
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 1081 of file pbx.h.
{ E_MATCHMORE = 0x00, /* extension can match but only with more 'digits' */ E_CANMATCH = 0x01, /* extension can match with or without more 'digits' */ E_MATCH = 0x02, /* extension is an exact match */ E_MATCH_MASK = 0x03, /* mask for the argument to extension_match_core() */ E_SPAWN = 0x12, /* want to spawn an extension. Requires exact match */ E_FINDLABEL = 0x22 /* returns the priority for a given label. Requires exact match */ };
int __ast_custom_function_register | ( | struct ast_custom_function * | acf, |
struct ast_module * | mod | ||
) |
Register a custom function.
Definition at line 3304 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 load_pbx().
{ struct ast_custom_function *cur; char tmps[80]; if (!acf) { return -1; } acf->mod = mod; acf->docsrc = AST_STATIC_DOC; if (acf_retrieve_docs(acf)) { return -1; } AST_RWLIST_WRLOCK(&acf_root); AST_RWLIST_TRAVERSE(&acf_root, cur, acflist) { if (!strcmp(acf->name, cur->name)) { ast_log(LOG_ERROR, "Function %s already registered.\n", acf->name); AST_RWLIST_UNLOCK(&acf_root); return -1; } } /* Store in alphabetical order */ AST_RWLIST_TRAVERSE_SAFE_BEGIN(&acf_root, cur, acflist) { if (strcasecmp(acf->name, cur->name) < 0) { AST_RWLIST_INSERT_BEFORE_CURRENT(acf, acflist); break; } } AST_RWLIST_TRAVERSE_SAFE_END; if (!cur) { AST_RWLIST_INSERT_TAIL(&acf_root, acf, acflist); } AST_RWLIST_UNLOCK(&acf_root); ast_verb(2, "Registered custom function '%s'\n", term_color(tmps, acf->name, COLOR_BRCYAN, 0, sizeof(tmps))); return 0; }
int ast_active_calls | ( | void | ) |
Retrieve the number of active calls.
Definition at line 4659 of file pbx.c.
References countcalls.
Referenced by ast_var_Config(), handle_chanlist(), handle_showcalls(), and sysinfo_helper().
{ return countcalls; }
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.
context | context to add the extension to |
replace | |
extension | extension to add |
priority | priority level of extension addition |
label | extension label |
callerid | pattern to match CallerID, or NULL to match any CallerID |
application | application to run on the extension with that priority level |
data | data to pass to the application |
datad | |
registrar | who registered the extension |
0 | success |
-1 | failure |
Definition at line 7374 of file pbx.c.
References ast_add_extension2(), ast_unlock_contexts(), and find_context_locked().
Referenced by ast_extension_state(), ast_extension_state_add(), handle_cli_dialplan_add_extension(), park_add_hints(), register_exten(), register_peer_exten(), and RegisterExtension().
{ int ret = -1; struct ast_context *c = find_context_locked(context); if (c) { ret = ast_add_extension2(c, replace, extension, priority, label, callerid, application, data, datad, registrar); ast_unlock_contexts(); } return ret; }
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 *.
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 7693 of file pbx.c.
References ast_add_extension2_lockopt().
Referenced by add_extensions(), ast_add_extension(), build_parkinglot(), context_merge(), load_config(), load_module(), manage_parkinglot(), park_call_full(), pbx_load_config(), pbx_load_users(), sla_build_station(), and sla_build_trunk().
{ return ast_add_extension2_lockopt(con, replace, extension, priority, label, callerid, application, data, datad, registrar, 1, 1); }
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 at line 7413 of file pbx.c.
References ast_channel::_state, ast_channel::accountcode, 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_channel::cdr, ast_channel::context, ast_channel::exten, LOG_WARNING, ast_channel::name, ast_channel::pbx, ast_channel::readformat, S_OR, 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(), pbx_parseable_goto(), process_ast_dsp(), process_sdp(), sip_read(), and socket_process().
{ int res = 0; ast_channel_lock(chan); if (chan->pbx) { /* This channel is currently in the PBX */ ast_explicit_goto(chan, context, exten, priority + 1); ast_softhangup_nolock(chan, AST_SOFTHANGUP_ASYNCGOTO); } else { /* In order to do it when the channel doesn't really exist within the PBX, we have to make a new channel, masquerade, and start the PBX at the new location */ struct ast_channel *tmpchan = ast_channel_alloc(0, chan->_state, 0, 0, chan->accountcode, chan->exten, chan->context, chan->amaflags, "AsyncGoto/%s", chan->name); if (!tmpchan) { res = -1; } else { if (chan->cdr) { ast_cdr_discard(tmpchan->cdr); tmpchan->cdr = ast_cdr_dup(chan->cdr); /* share the love */ } /* Make formats okay */ tmpchan->readformat = chan->readformat; tmpchan->writeformat = chan->writeformat; /* Setup proper location */ ast_explicit_goto(tmpchan, S_OR(context, chan->context), S_OR(exten, chan->exten), priority); /* Masquerade into temp channel */ if (ast_channel_masquerade(tmpchan, chan)) { /* Failed to set up the masquerade. It's probably chan_local * in the middle of optimizing itself out. Sad. :( */ ast_hangup(tmpchan); tmpchan = NULL; res = -1; } else { /* Grab the locks and get going */ ast_channel_lock(tmpchan); ast_do_masquerade(tmpchan); ast_channel_unlock(tmpchan); /* Start the PBX going on our stolen channel */ if (ast_pbx_start(tmpchan)) { ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmpchan->name); ast_hangup(tmpchan); res = -1; } } } } ast_channel_unlock(chan); return res; }
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 7466 of file pbx.c.
References ast_async_goto(), ast_channel_unlock, ast_get_channel_by_name_locked(), and chan.
{ struct ast_channel *chan; int res = -1; chan = ast_get_channel_by_name_locked(channame); if (chan) { res = ast_async_goto(chan, context, exten, priority); ast_channel_unlock(chan); } return res; }
int ast_async_goto_if_exists | ( | struct ast_channel * | chan, |
const char * | context, | ||
const char * | exten, | ||
int | priority | ||
) |
Definition at line 9642 of file pbx.c.
References __ast_goto_if_exists().
{ return __ast_goto_if_exists(chan, context, exten, priority, 1); }
int ast_async_parseable_goto | ( | struct ast_channel * | chan, |
const char * | goto_string | ||
) |
Definition at line 9705 of file pbx.c.
References pbx_parseable_goto().
Referenced by asyncgoto_exec(), and handle_redirect().
{ return pbx_parseable_goto(chan, goto_string, 1); }
int ast_build_timing | ( | struct ast_timing * | i, |
const char * | info | ||
) |
Construct a timing bitmap, for use in time-based conditionals.
i | Pointer to an ast_timing structure. |
info | Standard string containing a timerange, weekday range, monthday range, and month range, as well as an optional timezone. |
Returns | 1 on success or 0 on failure. |
Definition at line 7008 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().
{ char *info_save, *info; int j, num_fields, last_sep = -1; /* Check for empty just in case */ if (ast_strlen_zero(info_in)) { return 0; } /* make a copy just in case we were passed a static string */ info_save = info = ast_strdupa(info_in); /* count the number of fields in the timespec */ for (j = 0, num_fields = 1; info[j] != '\0'; j++) { if (info[j] == ',') { last_sep = j; num_fields++; } } /* save the timezone, if it is specified */ if (num_fields == 5) { i->timezone = ast_strdup(info + last_sep + 1); } else { i->timezone = NULL; } /* Assume everything except time */ i->monthmask = 0xfff; /* 12 bits */ i->daymask = 0x7fffffffU; /* 31 bits */ i->dowmask = 0x7f; /* 7 bits */ /* on each call, use strsep() to move info to the next argument */ get_timerange(i, strsep(&info, "|,")); if (info) i->dowmask = get_range(strsep(&info, "|,"), 7, days, "day of week"); if (info) i->daymask = get_range(strsep(&info, "|,"), 31, NULL, "day"); if (info) i->monthmask = get_range(strsep(&info, "|,"), 12, months, "month"); return 1; }
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.
c | not really important |
context | context to serach within |
exten | extension to check |
priority | priority of extension path |
callerid | callerid of extension being searched for |
Definition at line 4216 of file pbx.c.
References E_CANMATCH, and pbx_extension_helper().
Referenced by background_detect_exec(), cb_events(), do_immediate_setup(), dp_lookup(), dundi_lookup_local(), get_also_info(), get_destination(), handle_link_data(), handle_link_phone_dtmf(), leave_voicemail(), local_dtmf_helper(), loopback_canmatch(), mgcp_ss(), pbx_builtin_background(), phone_check_exception(), skinny_ss(), ss_thread(), and valid_exit().
{ return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_CANMATCH, 0, 0); }
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.
i | Pointer to an ast_timing structure. |
Returns | 1, if the time matches or 0, if the current time falls outside of the specified range. |
Definition at line 7051 of file pbx.c.
References ast_localtime(), ast_log(), ast_tvnow(), 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 iftime(), include_valid(), pbx_builtin_execiftime(), and pbx_builtin_gotoiftime().
{ struct ast_tm tm; struct timeval now = ast_tvnow(); ast_localtime(&now, &tm, i->timezone); /* If it's not the right month, return */ if (!(i->monthmask & (1 << tm.tm_mon))) return 0; /* If it's not that time of the month.... */ /* Warning, tm_mday has range 1..31! */ if (!(i->daymask & (1 << (tm.tm_mday-1)))) return 0; /* If it's not the right day of the week */ if (!(i->dowmask & (1 << tm.tm_wday))) return 0; /* Sanity check the hour just to be safe */ if ((tm.tm_hour < 0) || (tm.tm_hour > 23)) { ast_log(LOG_WARNING, "Insane time...\n"); return 0; } /* Now the tough part, we calculate if it fits in the right time based on min/hour */ 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)))) return 0; /* If we got this far, then we're good */ return 1; }
int ast_context_add_ignorepat | ( | const char * | context, |
const char * | ignorepat, | ||
const char * | registrar | ||
) |
Add an ignorepat.
context | which context to add the ignorpattern to |
ignorepat | ignorepattern to set up for the extension |
registrar | registrar of the ignore pattern |
Adds an ignore pattern to a particular context.
0 | on success |
-1 | on failure |
Definition at line 7286 of file pbx.c.
References ast_context_add_ignorepat2(), ast_unlock_contexts(), and find_context_locked().
Referenced by handle_cli_dialplan_add_ignorepat().
{ int ret = -1; struct ast_context *c = find_context_locked(context); if (c) { ret = ast_context_add_ignorepat2(c, value, registrar); ast_unlock_contexts(); } return ret; }
int ast_context_add_ignorepat2 | ( | struct ast_context * | con, |
const char * | ignorepat, | ||
const char * | registrar | ||
) |
Definition at line 7298 of file pbx.c.
References ast_calloc, 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().
{ struct ast_ignorepat *ignorepat, *ignorepatc, *ignorepatl = NULL; int length; char *pattern; length = sizeof(struct ast_ignorepat); length += strlen(value) + 1; if (!(ignorepat = ast_calloc(1, length))) return -1; /* The cast to char * is because we need to write the initial value. * The field is not supposed to be modified otherwise. Also, gcc 4.2 * sees the cast as dereferencing a type-punned pointer and warns about * it. This is the workaround (we're telling gcc, yes, that's really * what we wanted to do). */ pattern = (char *) ignorepat->pattern; strcpy(pattern, value); ignorepat->next = NULL; ignorepat->registrar = registrar; ast_wrlock_context(con); for (ignorepatc = con->ignorepats; ignorepatc; ignorepatc = ignorepatc->next) { ignorepatl = ignorepatc; if (!strcasecmp(ignorepatc->pattern, value)) { /* Already there */ ast_unlock_context(con); errno = EEXIST; return -1; } } if (ignorepatl) ignorepatl->next = ignorepat; else con->ignorepats = ignorepat; ast_unlock_context(con); return 0; }
int ast_context_add_include | ( | const char * | context, |
const char * | include, | ||
const char * | registrar | ||
) |
Add a context include.
context | context to add include to |
include | new include to add |
registrar | who's registering it |
Adds an include taking a char * string as the context parameter
0 | on success |
-1 | on error |
Definition at line 6837 of file pbx.c.
References ast_context_add_include2(), ast_unlock_contexts(), and find_context_locked().
Referenced by handle_cli_dialplan_add_include().
{ int ret = -1; struct ast_context *c = find_context_locked(context); if (c) { ret = ast_context_add_include2(c, include, registrar); ast_unlock_contexts(); } return ret; }
int ast_context_add_include2 | ( | struct ast_context * | con, |
const char * | include, | ||
const char * | registrar | ||
) |
Add a context include.
con | context to add the include to |
include | include to add |
registrar | who registered the context |
Adds an include taking a struct ast_context as the first parameter
0 | on success |
-1 | on failure |
Definition at line 7101 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_sw::registrar, ast_include::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().
{ struct ast_include *new_include; char *c; struct ast_include *i, *il = NULL; /* include, include_last */ int length; char *p; length = sizeof(struct ast_include); length += 2 * (strlen(value) + 1); /* allocate new include structure ... */ if (!(new_include = ast_calloc(1, length))) return -1; /* Fill in this structure. Use 'p' for assignments, as the fields * in the structure are 'const char *' */ p = new_include->stuff; new_include->name = p; strcpy(p, value); p += strlen(value) + 1; new_include->rname = p; strcpy(p, value); /* Strip off timing info, and process if it is there */ if ( (c = strchr(p, ',')) ) { *c++ = '\0'; new_include->hastime = ast_build_timing(&(new_include->timing), c); } new_include->next = NULL; new_include->registrar = registrar; ast_wrlock_context(con); /* ... go to last include and check if context is already included too... */ for (i = con->includes; i; i = i->next) { if (!strcasecmp(i->name, new_include->name)) { ast_destroy_timing(&(new_include->timing)); ast_free(new_include); ast_unlock_context(con); errno = EEXIST; return -1; } il = i; } /* ... include new context into context list, unlock, return */ if (il) il->next = new_include; else con->includes = new_include; ast_verb(3, "Including context '%s' in context '%s'\n", new_include->name, ast_get_context_name(con)); ast_unlock_context(con); return 0; }
int ast_context_add_switch | ( | const char * | context, |
const char * | sw, | ||
const char * | data, | ||
int | eval, | ||
const char * | registrar | ||
) |
Add a switch.
context | context to which to add the switch |
sw | switch to add |
data | data to pass to switch |
eval | whether to evaluate variables when running switch |
registrar | whoever registered the switch |
This function registers a switch with the asterisk switch architecture
0 | on success |
-1 | on failure |
Definition at line 7164 of file pbx.c.
References ast_context_add_switch2(), ast_unlock_contexts(), and find_context_locked().
{ int ret = -1; struct ast_context *c = find_context_locked(context); if (c) { /* found, add switch to this context */ ret = ast_context_add_switch2(c, sw, data, eval, registrar); ast_unlock_contexts(); } return ret; }
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 at line 7183 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().
{ struct ast_sw *new_sw; struct ast_sw *i; int length; char *p; length = sizeof(struct ast_sw); length += strlen(value) + 1; if (data) length += strlen(data); length++; /* allocate new sw structure ... */ if (!(new_sw = ast_calloc(1, length))) return -1; /* ... fill in this structure ... */ p = new_sw->stuff; new_sw->name = p; strcpy(new_sw->name, value); p += strlen(value) + 1; new_sw->data = p; if (data) { strcpy(new_sw->data, data); p += strlen(data) + 1; } else { strcpy(new_sw->data, ""); p++; } new_sw->eval = eval; new_sw->registrar = registrar; /* ... try to lock this context ... */ ast_wrlock_context(con); /* ... go to last sw and check if context is already swd too... */ AST_LIST_TRAVERSE(&con->alts, i, list) { if (!strcasecmp(i->name, new_sw->name) && !strcasecmp(i->data, new_sw->data)) { ast_free(new_sw); ast_unlock_context(con); errno = EEXIST; return -1; } } /* ... sw new context into context list, unlock, return */ AST_LIST_INSERT_TAIL(&con->alts, new_sw, list); ast_verb(3, "Including switch '%s/%s' in context '%s'\n", new_sw->name, new_sw->data, ast_get_context_name(con)); ast_unlock_context(con); return 0; }
void ast_context_destroy | ( | struct ast_context * | con, |
const char * | registrar | ||
) |
Destroy a context (matches the specified context (or ANY context if NULL)
con | context to destroy |
registrar | who registered it |
You can optionally leave out either parameter. It will find it based on either the ast_context or the registrar name.
Definition at line 8484 of file pbx.c.
References __ast_context_destroy(), ast_unlock_contexts(), ast_wrlock_contexts(), contexts, and contexts_table.
Referenced by __unload_module(), cleanup_stale_contexts(), parkinglot_destroy(), sla_destroy(), and unload_module().
{ ast_wrlock_contexts(); __ast_context_destroy(contexts, contexts_table, con,registrar); ast_unlock_contexts(); }
struct ast_context* ast_context_find | ( | const char * | name | ) | [read] |
Find a context.
name | name of the context to find |
Will search for the context with the given name.
Definition at line 2445 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_ignore_pattern(), cleanup_stale_contexts(), isexten_function_read(), load_config(), manage_parkinglot(), park_exec_full(), parkinglot_destroy(), register_exten(), register_peer_exten(), unload_module(), and unregister_exten().
{ struct ast_context *tmp = NULL; struct fake_context item; ast_copy_string(item.name, name, sizeof(item.name)); ast_rdlock_contexts(); if( contexts_table ) { tmp = ast_hashtab_lookup(contexts_table,&item); } else { while ( (tmp = ast_walk_contexts(tmp)) ) { if (!name || !strcasecmp(name, tmp->name)) { break; } } } ast_unlock_contexts(); return tmp; }
struct ast_context* ast_context_find_or_create | ( | struct ast_context ** | extcontexts, |
struct ast_hashtab * | exttable, | ||
const char * | name, | ||
const char * | registrar | ||
) | [read] |
Register a new context or find an existing one.
extcontexts | pointer to the ast_context structure pointer |
exttable | pointer to the hashtable that contains all the elements in extcontexts |
name | name of the new context |
registrar | registrar of the context |
This function allows you to play in two environments: the global contexts (active dialplan) or an external context set of your choosing. To act on the external set, make sure extcontexts and exttable are set; for the globals, make sure both extcontexts and exttable are NULL.
This will first search for a context with your name. If it exists already, it will not create a new one. If it does not exist, it will create a new one with the given name and registrar.
Definition at line 6482 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(), build_parkinglot(), config_parse_variables(), context_merge(), load_config(), load_module(), lua_register_switches(), manage_parkinglot(), park_call_full(), pbx_load_config(), pbx_load_users(), reload_config(), set_config(), sla_build_station(), and sla_build_trunk().
{ struct ast_context *tmp, **local_contexts; struct fake_context search; int length = sizeof(struct ast_context) + strlen(name) + 1; if (!contexts_table) { contexts_table = ast_hashtab_create(17, ast_hashtab_compare_contexts, ast_hashtab_resize_java, ast_hashtab_newsize_java, ast_hashtab_hash_contexts, 0); } ast_copy_string(search.name, name, sizeof(search.name)); if (!extcontexts) { ast_rdlock_contexts(); local_contexts = &contexts; tmp = ast_hashtab_lookup(contexts_table, &search); ast_unlock_contexts(); if (tmp) { tmp->refcount++; return tmp; } } else { /* local contexts just in a linked list; search there for the new context; slow, linear search, but not frequent */ local_contexts = extcontexts; tmp = ast_hashtab_lookup(exttable, &search); if (tmp) { tmp->refcount++; return tmp; } } if ((tmp = ast_calloc(1, length))) { ast_rwlock_init(&tmp->lock); ast_mutex_init(&tmp->macrolock); strcpy(tmp->name, name); tmp->root = NULL; tmp->root_table = NULL; tmp->registrar = ast_strdup(registrar); tmp->includes = NULL; tmp->ignorepats = NULL; tmp->refcount = 1; } else { ast_log(LOG_ERROR, "Danger! We failed to allocate a context for %s!\n", name); return NULL; } if (!extcontexts) { ast_wrlock_contexts(); tmp->next = *local_contexts; *local_contexts = tmp; ast_hashtab_insert_safe(contexts_table, tmp); /*put this context into the tree */ ast_unlock_contexts(); ast_debug(1, "Registered context '%s'(%p) in table %p registrar: %s\n", tmp->name, tmp, contexts_table, registrar); ast_verb(3, "Registered extension context '%s' (%p) in table %p; registrar: %s\n", tmp->name, tmp, contexts_table, registrar); } else { tmp->next = *local_contexts; if (exttable) ast_hashtab_insert_immediate(exttable, tmp); /*put this context into the tree */ *local_contexts = tmp; ast_debug(1, "Registered context '%s'(%p) in local table %p; registrar: %s\n", tmp->name, tmp, exttable, registrar); ast_verb(3, "Registered extension context '%s' (%p) in local table %p; registrar: %s\n", tmp->name, tmp, exttable, registrar); } return tmp; }
int ast_context_lockmacro | ( | const char * | context | ) |
locks the macrolock in the given given context
macrocontext | name of the macro-context to lock |
Locks the given macro-context to ensure only one thread (call) can execute it at a time
0 | on success |
-1 | on failure |
Definition at line 5046 of file pbx.c.
References ast_copy_string(), ast_get_context_name(), ast_hashtab_lookup(), ast_mutex_lock(), ast_rdlock_contexts(), ast_unlock_contexts(), ast_walk_contexts(), contexts_table, ast_context::macrolock, and fake_context::name.
Referenced by _macro_exec().
{ struct ast_context *c = NULL; int ret = -1; struct fake_context item; ast_rdlock_contexts(); ast_copy_string(item.name, context, sizeof(item.name)); c = ast_hashtab_lookup(contexts_table,&item); if (c) ret = 0; #ifdef NOTNOW while ((c = ast_walk_contexts(c))) { if (!strcmp(ast_get_context_name(c), context)) { ret = 0; break; } } #endif ast_unlock_contexts(); /* if we found context, lock macrolock */ if (ret == 0) { ret = ast_mutex_lock(&c->macrolock); } return ret; }
int ast_context_remove_extension | ( | const char * | context, |
const char * | extension, | ||
int | priority, | ||
const char * | registrar | ||
) |
Simply remove extension from context.
context | context to remove extension from |
extension | which extension to remove |
priority | priority of extension to remove (0 to remove all) |
callerid | NULL to remove all; non-NULL to match a single record per priority |
matchcid | non-zero to match callerid element (if non-NULL); 0 to match default case |
registrar | registrar of the extension |
This function removes an extension from a given context.
0 | on success |
-1 | on failure |
Definition at line 4854 of file pbx.c.
References ast_context_remove_extension_callerid().
Referenced by destroy_station(), destroy_trunk(), register_peer_exten(), unregister_exten(), and UnregisterExtension().
{ return ast_context_remove_extension_callerid(context, extension, priority, NULL, 0, registrar); }
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.
Definition at line 4881 of file pbx.c.
References ast_context_remove_extension_callerid2().
Referenced by load_config(), manage_parkinglot(), park_exec_full(), and unload_module().
{ return ast_context_remove_extension_callerid2(con, extension, priority, NULL, 0, registrar, already_locked); }
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 4859 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().
{ int ret = -1; /* default error return */ struct ast_context *c = find_context_locked(context); if (c) { /* ... remove extension ... */ ret = ast_context_remove_extension_callerid2(c, extension, priority, callerid, matchcallerid, registrar, 1); ast_unlock_contexts(); } return ret; }
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 4886 of file pbx.c.
References add_exten_to_pattern_tree(), ast_copy_string(), ast_hashtab_insert_immediate(), ast_hashtab_lookup(), ast_hashtab_remove_this_object(), ast_hashtab_size(), ast_log(), ast_strlen_zero(), ast_unlock_context(), ast_verb, ast_wrlock_context(), ast_exten::cidmatch, match_char::deleted, destroy_exten(), match_char::exten, ast_exten::exten, exten, ast_exten::label, LOG_ERROR, log_match_char_tree(), 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().
{ struct ast_exten *exten, *prev_exten = NULL; struct ast_exten *peer; struct ast_exten ex, *exten2, *exten3; char dummy_name[1024]; struct ast_exten *previous_peer = NULL; struct ast_exten *next_peer = NULL; int found = 0; if (!already_locked) ast_wrlock_context(con); /* Handle this is in the new world */ /* FIXME For backwards compatibility, if callerid==NULL, then remove ALL * peers, not just those matching the callerid. */ #ifdef NEED_DEBUG ast_verb(3,"Removing %s/%s/%d%s%s from trees, registrar=%s\n", con->name, extension, priority, matchcallerid ? "/" : "", matchcallerid ? callerid : "", registrar); #endif #ifdef CONTEXT_DEBUG check_contexts(__FILE__, __LINE__); #endif /* find this particular extension */ ex.exten = dummy_name; ex.matchcid = matchcallerid && !ast_strlen_zero(callerid); /* don't say match if there's no callerid */ ex.cidmatch = callerid; ast_copy_string(dummy_name, extension, sizeof(dummy_name)); exten = ast_hashtab_lookup(con->root_table, &ex); if (exten) { if (priority == 0) { exten2 = ast_hashtab_remove_this_object(con->root_table, exten); if (!exten2) 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); if (con->pattern_tree) { struct match_char *x = add_exten_to_pattern_tree(con, exten, 1); if (x->exten) { /* this test for safety purposes */ x->deleted = 1; /* with this marked as deleted, it will never show up in the scoreboard, and therefore never be found */ x->exten = 0; /* get rid of what will become a bad pointer */ } else { ast_log(LOG_WARNING,"Trying to delete an exten from a context, but the pattern tree node returned isn't a full extension\n"); } } } else { ex.priority = priority; exten2 = ast_hashtab_lookup(exten->peer_table, &ex); if (exten2) { if (exten2->label) { /* if this exten has a label, remove that, too */ exten3 = ast_hashtab_remove_this_object(exten->peer_label_table,exten2); if (!exten3) 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); } exten3 = ast_hashtab_remove_this_object(exten->peer_table, exten2); if (!exten3) 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); if (exten2 == exten && exten2->peer) { exten2 = ast_hashtab_remove_this_object(con->root_table, exten); ast_hashtab_insert_immediate(con->root_table, exten2->peer); } if (ast_hashtab_size(exten->peer_table) == 0) { /* well, if the last priority of an exten is to be removed, then, the extension is removed, too! */ exten3 = ast_hashtab_remove_this_object(con->root_table, exten); if (!exten3) ast_log(LOG_ERROR,"Did not remove this exten (%s) from the context root_table (%s) (priority %d)\n", exten->exten, con->name, priority); if (con->pattern_tree) { struct match_char *x = add_exten_to_pattern_tree(con, exten, 1); if (x->exten) { /* this test for safety purposes */ x->deleted = 1; /* with this marked as deleted, it will never show up in the scoreboard, and therefore never be found */ x->exten = 0; /* get rid of what will become a bad pointer */ } } } } else { ast_log(LOG_ERROR,"Could not find priority %d of exten %s in context %s!\n", priority, exten->exten, con->name); } } } else { /* hmmm? this exten is not in this pattern tree? */ ast_log(LOG_WARNING,"Cannot find extension %s in root_table in context %s\n", extension, con->name); } #ifdef NEED_DEBUG if (con->pattern_tree) { ast_log(LOG_NOTICE,"match char tree after exten removal:\n"); log_match_char_tree(con->pattern_tree, " "); } #endif /* scan the extension list to find first matching extension-registrar */ for (exten = con->root; exten; prev_exten = exten, exten = exten->next) { if (!strcmp(exten->exten, extension) && (!registrar || !strcmp(exten->registrar, registrar)) && (!matchcallerid || (!ast_strlen_zero(callerid) && !ast_strlen_zero(exten->cidmatch) && !strcmp(exten->cidmatch, callerid)) || (ast_strlen_zero(callerid) && ast_strlen_zero(exten->cidmatch)))) break; } if (!exten) { /* we can't find right extension */ if (!already_locked) ast_unlock_context(con); return -1; } /* scan the priority list to remove extension with exten->priority == priority */ for (peer = exten, next_peer = exten->peer ? exten->peer : exten->next; peer && !strcmp(peer->exten, extension) && (!matchcallerid || (!ast_strlen_zero(callerid) && !ast_strlen_zero(peer->cidmatch) && !strcmp(peer->cidmatch,callerid)) || (ast_strlen_zero(callerid) && ast_strlen_zero(peer->cidmatch))); peer = next_peer, next_peer = next_peer ? (next_peer->peer ? next_peer->peer : next_peer->next) : NULL) { if ((priority == 0 || peer->priority == priority) && (!callerid || !matchcallerid || (matchcallerid && !strcmp(peer->cidmatch, callerid))) && (!registrar || !strcmp(peer->registrar, registrar) )) { found = 1; /* we are first priority extension? */ if (!previous_peer) { /* * We are first in the priority chain, so must update the extension chain. * The next node is either the next priority or the next extension */ struct ast_exten *next_node = peer->peer ? peer->peer : peer->next; if (peer->peer) { /* move the peer_table and peer_label_table down to the next peer, if it is there */ peer->peer->peer_table = peer->peer_table; peer->peer->peer_label_table = peer->peer_label_table; peer->peer_table = NULL; peer->peer_label_table = NULL; } if (!prev_exten) { /* change the root... */ con->root = next_node; } else { prev_exten->next = next_node; /* unlink */ } if (peer->peer) { /* update the new head of the pri list */ peer->peer->next = peer->next; } } else { /* easy, we are not first priority in extension */ previous_peer->peer = peer->peer; } /* now, free whole priority extension */ destroy_exten(peer); } else { previous_peer = peer; } } if (!already_locked) ast_unlock_context(con); return found ? 0 : -1; }
int ast_context_remove_ignorepat | ( | const char * | context, |
const char * | ignorepat, | ||
const char * | registrar | ||
) |
Definition at line 7243 of file pbx.c.
References ast_context_remove_ignorepat2(), ast_unlock_contexts(), and find_context_locked().
Referenced by handle_cli_dialplan_remove_ignorepat().
{ int ret = -1; struct ast_context *c = find_context_locked(context); if (c) { ret = ast_context_remove_ignorepat2(c, ignorepat, registrar); ast_unlock_contexts(); } return ret; }
int ast_context_remove_ignorepat2 | ( | struct ast_context * | con, |
const char * | ignorepat, | ||
const char * | registrar | ||
) |
Definition at line 7255 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().
{ struct ast_ignorepat *ip, *ipl = NULL; ast_wrlock_context(con); for (ip = con->ignorepats; ip; ip = ip->next) { if (!strcmp(ip->pattern, ignorepat) && (!registrar || (registrar == ip->registrar))) { if (ipl) { ipl->next = ip->next; ast_free(ip); } else { con->ignorepats = ip->next; ast_free(ip); } ast_unlock_context(con); return 0; } ipl = ip; } ast_unlock_context(con); errno = EINVAL; return -1; }
int ast_context_remove_include | ( | const char * | context, |
const char * | include, | ||
const char * | registrar | ||
) |
Remove a context include.
0 | on success |
-1 | on failure |
Definition at line 4745 of file pbx.c.
References ast_context_remove_include2(), ast_unlock_contexts(), and find_context_locked().
Referenced by handle_cli_dialplan_remove_include().
{ int ret = -1; struct ast_context *c = find_context_locked(context); if (c) { /* found, remove include from this context ... */ ret = ast_context_remove_include2(c, include, registrar); ast_unlock_contexts(); } return ret; }
int ast_context_remove_include2 | ( | struct ast_context * | con, |
const char * | include, | ||
const char * | registrar | ||
) |
Removes an include by an ast_context structure.
0 | on success |
-1 | on success |
Removes an include by an ast_context structure.
0 | on success. |
-1 | on failure. |
Definition at line 4767 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().
{ struct ast_include *i, *pi = NULL; int ret = -1; ast_wrlock_context(con); /* find our include */ for (i = con->includes; i; pi = i, i = i->next) { if (!strcmp(i->name, include) && (!registrar || !strcmp(i->registrar, registrar))) { /* remove from list */ ast_verb(3, "Removing inclusion of context '%s' in context '%s; registrar=%s'\n", include, ast_get_context_name(con), registrar); if (pi) pi->next = i->next; else con->includes = i->next; /* free include and return */ ast_destroy_timing(&(i->timing)); ast_free(i); ret = 0; break; } } ast_unlock_context(con); return ret; }
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
0 | on success |
-1 | on failure |
Definition at line 4802 of file pbx.c.
References ast_context_remove_switch2(), ast_unlock_contexts(), and find_context_locked().
{ int ret = -1; /* default error return */ struct ast_context *c = find_context_locked(context); if (c) { /* remove switch from this context ... */ ret = ast_context_remove_switch2(c, sw, data, registrar); ast_unlock_contexts(); } return ret; }
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 at line 4823 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().
{ struct ast_sw *i; int ret = -1; ast_wrlock_context(con); /* walk switches */ AST_LIST_TRAVERSE_SAFE_BEGIN(&con->alts, i, list) { if (!strcmp(i->name, sw) && !strcmp(i->data, data) && (!registrar || !strcmp(i->registrar, registrar))) { /* found, remove from list */ ast_verb(3, "Removing switch '%s' from context '%s; registrar=%s'\n", sw, ast_get_context_name(con), registrar); AST_LIST_REMOVE_CURRENT(list); ast_free(i); /* free switch and return */ ret = 0; break; } } AST_LIST_TRAVERSE_SAFE_END; ast_unlock_context(con); return ret; }
int ast_context_unlockmacro | ( | const char * | context | ) |
Unlocks the macrolock in the given context.
macrocontext | name of the macro-context to unlock |
Unlocks the given macro-context so that another thread (call) can execute it
0 | on success |
-1 | on failure |
Definition at line 5086 of file pbx.c.
References ast_copy_string(), ast_get_context_name(), ast_hashtab_lookup(), ast_mutex_unlock(), ast_rdlock_contexts(), ast_unlock_contexts(), ast_walk_contexts(), contexts_table, ast_context::macrolock, and fake_context::name.
Referenced by _macro_exec().
{ struct ast_context *c = NULL; int ret = -1; struct fake_context item; ast_rdlock_contexts(); ast_copy_string(item.name, context, sizeof(item.name)); c = ast_hashtab_lookup(contexts_table,&item); if (c) ret = 0; #ifdef NOTNOW while ((c = ast_walk_contexts(c))) { if (!strcmp(ast_get_context_name(c), context)) { ret = 0; break; } } #endif ast_unlock_contexts(); /* if we found context, unlock macrolock */ if (ret == 0) { ret = ast_mutex_unlock(&c->macrolock); } return ret; }
int ast_context_verify_includes | ( | struct ast_context * | con | ) |
Verifies includes in an ast_contect structure.
con | context in which to verify the includes |
0 | if no problems found |
-1 | if there were any missing context |
Definition at line 9599 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().
{ struct ast_include *inc = NULL; int res = 0; while ( (inc = ast_walk_context_includes(con, inc)) ) { if (ast_context_find(inc->rname)) continue; res = -1; ast_log(LOG_WARNING, "Context '%s' tries to include nonexistent context '%s'\n", ast_get_context_name(con), inc->rname); break; } return res; }
struct ast_custom_function* ast_custom_function_find | ( | const char * | name | ) | [read] |
Definition at line 3217 of file pbx.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, and ast_custom_function::name.
Referenced by ast_func_read(), 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().
{ struct ast_custom_function *acf = NULL; AST_RWLIST_RDLOCK(&acf_root); AST_RWLIST_TRAVERSE(&acf_root, acf, acflist) { if (!strcmp(name, acf->name)) break; } AST_RWLIST_UNLOCK(&acf_root); return acf; }
int ast_custom_function_unregister | ( | struct ast_custom_function * | acf | ) |
Unregister a custom function.
Definition at line 3231 of file pbx.c.
References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_string_field_free_memory, ast_verb, AST_XML_DOC, ast_custom_function::docsrc, and ast_custom_function::name.
Referenced by _unload_module(), load_module(), reload(), and unload_module().
{ struct ast_custom_function *cur; if (!acf) { return -1; } AST_RWLIST_WRLOCK(&acf_root); if ((cur = AST_RWLIST_REMOVE(&acf_root, acf, acflist))) { if (cur->docsrc == AST_XML_DOC) { ast_string_field_free_memory(acf); } ast_verb(2, "Unregistered custom function %s\n", cur->name); } AST_RWLIST_UNLOCK(&acf_root); return cur ? 0 : -1; }
int ast_destroy_timing | ( | struct ast_timing * | i | ) |
Deallocates memory structures associated with a timing bitmap.
i | Pointer to an ast_timing structure. |
0 | success |
non-zero | failure (number suitable to pass to |
Definition at line 7086 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().
enum ast_extension_states ast_devstate_to_extenstate | ( | enum ast_device_state | devstate | ) |
Map devstate to an extension state.
[in] | device | state |
Definition at line 3785 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_state2().
{ switch (devstate) { case AST_DEVICE_ONHOLD: return AST_EXTENSION_ONHOLD; case AST_DEVICE_BUSY: return AST_EXTENSION_BUSY; case AST_DEVICE_UNKNOWN: return AST_EXTENSION_NOT_INUSE; case AST_DEVICE_UNAVAILABLE: case AST_DEVICE_INVALID: return AST_EXTENSION_UNAVAILABLE; case AST_DEVICE_RINGINUSE: return (AST_EXTENSION_INUSE | AST_EXTENSION_RINGING); case AST_DEVICE_RINGING: return AST_EXTENSION_RINGING; case AST_DEVICE_INUSE: return AST_EXTENSION_INUSE; case AST_DEVICE_NOT_INUSE: return AST_EXTENSION_NOT_INUSE; case AST_DEVICE_TOTAL: /* not a device state, included for completeness */ break; } return AST_EXTENSION_NOT_INUSE; }
int ast_exists_extension | ( | struct ast_channel * | c, |
const char * | context, | ||
const char * | exten, | ||
int | priority, | ||
const char * | callerid | ||
) |
Determine whether an extension exists.
c | this is not important |
context | which context to look in |
exten | which extension to search for |
priority | priority of the action within the extension |
callerid | callerid to search for |
Definition at line 4201 of file pbx.c.
References E_MATCH, and pbx_extension_helper().
Referenced by __ast_goto_if_exists(), __ast_pbx_run(), _macro_exec(), acf_isexten_exec(), 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(), dial_exec_full(), disa_exec(), dp_lookup(), dundi_lookup_local(), findmeexec(), get_also_info(), get_destination(), get_refer_info(), gosub_exec(), handle_gosub(), handle_link_data(), handle_link_phone_dtmf(), handle_stimulus_message(), isexten_function_read(), leave_voicemail(), local_alloc(), local_call(), local_devicestate(), local_dtmf_helper(), loopback_exists(), metermaidstate(), mgcp_ss(), minivm_greet_exec(), misdn_overlap_dial_task(), park_space_reserve(), parkandannounce_exec(), pbx_builtin_waitexten(), phone_check_exception(), privacy_exec(), process_ast_dsp(), process_sdp(), readexten_exec(), register_peer_exten(), rpt_exec(), show_debug_helper(), sip_new(), sip_read(), skinny_ss(), socket_process(), ss_thread(), and waitstream_core().
{ return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCH, 0, 0); }
int ast_explicit_goto | ( | struct ast_channel * | chan, |
const char * | context, | ||
const char * | exten, | ||
int | priority | ||
) |
Definition at line 7390 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(), pbx_parseable_goto(), and return_exec().
{ if (!chan) return -1; ast_channel_lock(chan); if (!ast_strlen_zero(context)) ast_copy_string(chan->context, context, sizeof(chan->context)); if (!ast_strlen_zero(exten)) ast_copy_string(chan->exten, exten, sizeof(chan->exten)); if (priority > -1) { chan->priority = priority; /* see flag description in channel.h for explanation */ if (ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP)) chan->priority--; } ast_channel_unlock(chan); return 0; }
int ast_extension_close | ( | const char * | pattern, |
const char * | data, | ||
int | needmore | ||
) |
Definition at line 2422 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().
{ if (needmore != E_MATCHMORE && needmore != E_CANMATCH) ast_log(LOG_WARNING, "invalid argument %d\n", needmore); return extension_match_core(pattern, data, needmore); }
int ast_extension_cmp | ( | const char * | a, |
const char * | b | ||
) |
Determine if one extension should match before another.
a | extension to compare with b |
b | extension to compare with a |
Checks whether or extension a should match before extension b
0 | if the two extensions have equal matching priority |
1 | on a > b |
-1 | on a < b |
Definition at line 2224 of file pbx.c.
References ext_cmp().
Referenced by lua_extension_cmp().
{ return ext_cmp(a, b); }
int ast_extension_match | ( | const char * | pattern, |
const char * | extension | ||
) |
Determine if a given extension matches a given pattern (in NXX format)
pattern | pattern to match |
extension | extension to check against the pattern. |
Checks whether or not the given extension matches the given pattern.
1 | on match |
0 | on failure |
Definition at line 2417 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(), and show_dialplan_helper().
{ return extension_match_core(pattern, data, E_MATCH); }
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.
c | this is not important |
context | which context to look in |
exten | which extension to get state |
Definition at line 3848 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(), and handle_request_subscribe().
{ struct ast_exten *e; if (!(e = ast_hint_extension(c, context, exten))) { /* Do we have a hint for this extension ? */ return -1; /* No hint, return -1 */ } if (e->exten[0] == '_') { /* Create this hint on-the-fly */ ast_add_extension(e->parent->name, 0, exten, e->priority, e->label, e->matchcid ? e->cidmatch : NULL, e->app, ast_strdup(e->data), ast_free_ptr, e->registrar); if (!(e = ast_hint_extension(c, context, exten))) { /* Improbable, but not impossible */ return -1; } } return ast_extension_state2(e); /* Check all devices in the hint */ }
const char* ast_extension_state2str | ( | int | extension_state | ) |
Return string representation of the state of an extension.
extension_state | is the numerical state delivered by ast_extension_state |
Definition at line 3836 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(), and show_channels_cb().
{ int i; for (i = 0; (i < ARRAY_LEN(extension_states)); i++) { if (extension_states[i].extension_state == extension_state) return extension_states[i].text; } return "Unknown"; }
int ast_extension_state_add | ( | const char * | context, |
const char * | exten, | ||
ast_state_cb_type | callback, | ||
void * | data | ||
) |
Registers a state change callback.
context | which context to look in |
exten | which extension to get state |
callback | callback to call if state changed |
data | to pass to callback |
The callback is called if the state of an extension is changed.
-1 | on failure |
ID | on success |
Definition at line 3945 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_state_cb::callback, ast_hint::callbacks, ast_exten::cidmatch, ast_exten::data, ast_sw::data, ast_state_cb::data, ast_exten::exten, hints, ast_state_cb::id, ast_exten::label, ast_exten::matchcid, ast_context::name, ast_exten::parent, ast_exten::priority, ast_exten::registrar, statecbs, and stateid.
Referenced by __init_manager(), handle_request_subscribe(), and skinny_register().
{ struct ast_hint *hint; struct ast_state_cb *state_cb; struct ast_exten *e; /* If there's no context and extension: add callback to statecbs list */ if (!context && !exten) { ao2_lock(hints); state_cb = ao2_find(statecbs, callback, 0); if (state_cb) { state_cb->data = data; ao2_ref(state_cb, -1); ao2_unlock(hints); return 0; } /* Now insert the callback */ if (!(state_cb = ao2_alloc(sizeof(*state_cb), NULL))) { ao2_unlock(hints); return -1; } state_cb->id = 0; state_cb->callback = callback; state_cb->data = data; ao2_link(statecbs, state_cb); ao2_ref(state_cb, -1); ao2_unlock(hints); return 0; } if (!context || !exten) return -1; /* This callback type is for only one hint, so get the hint */ e = ast_hint_extension(NULL, context, exten); if (!e) { return -1; } /* If this is a pattern, dynamically create a new extension for this * particular match. Note that this will only happen once for each * individual extension, because the pattern will no longer match first. */ if (e->exten[0] == '_') { ast_add_extension(e->parent->name, 0, exten, e->priority, e->label, e->matchcid ? e->cidmatch : NULL, e->app, ast_strdup(e->data), ast_free_ptr, e->registrar); e = ast_hint_extension(NULL, context, exten); if (!e || e->exten[0] == '_') { return -1; } } /* Find the hint in the list of hints */ hint = ao2_find(hints, e, 0); if (!hint) { return -1; } /* Now insert the callback in the callback list */ if (!(state_cb = ao2_alloc(sizeof(*state_cb), NULL))) { ao2_ref(hint, -1); return -1; } state_cb->id = stateid++; /* Unique ID for this callback */ state_cb->callback = callback; /* Pointer to callback routine */ state_cb->data = data; /* Data for the callback */ ao2_lock(hint); ao2_link(hint->callbacks, state_cb); ao2_ref(state_cb, -1); ao2_unlock(hint); ao2_ref(hint, -1); return state_cb->id; }
int ast_extension_state_del | ( | int | id, |
ast_state_cb_type | callback | ||
) |
Deletes a registered state change callback by ID.
id | of the callback to delete |
callback | callback |
Removes the callback from list of callbacks
0 | success |
-1 | failure |
Definition at line 4046 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(), and skinny_unregister().
{ struct ast_state_cb *p_cur = NULL; int ret = -1; if (!id && !callback) { return -1; } if (!id) { /* id == 0 is a callback without extension */ ao2_lock(hints); p_cur = ao2_find(statecbs, callback, OBJ_UNLINK); if (p_cur) { ret = 0; ao2_ref(p_cur, -1); } ao2_unlock(hints); } else { /* callback with extension, find the callback based on ID */ struct ast_hint *hint; hint = ao2_callback(hints, 0, find_hint_by_cb_id, &id); if (hint) { ao2_lock(hint); p_cur = ao2_find(hint->callbacks, &id, OBJ_UNLINK); if (p_cur) { ret = 0; ao2_ref(p_cur, -1); } ao2_unlock(hint); ao2_ref(hint, -1); } } return ret; }
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.
c | this is not important |
context | which context to look in |
exten | which extension to search for |
label | label of the action within the extension to match to priority |
callerid | callerid to search for |
the | priority which matches the given label in the extension |
-1 | if not found. |
Definition at line 4206 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().
{ return pbx_extension_helper(c, NULL, context, exten, 0, label, callerid, E_FINDLABEL, 0, 0); }
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.
Definition at line 4211 of file pbx.c.
References E_FINDLABEL, and pbx_extension_helper().
Referenced by pbx_load_config().
{ return pbx_extension_helper(c, con, NULL, exten, 0, label, callerid, E_FINDLABEL, 0, 0); }
int ast_func_read | ( | struct ast_channel * | chan, |
const char * | function, | ||
char * | workspace, | ||
size_t | len | ||
) |
executes a read operation on a function
chan | Channel to execute on |
function | Data containing the function call string (will be modified) |
workspace | A pointer to safe memory to use for a return value |
len | the number of bytes in workspace |
This application executes a function in read mode on a given channel.
0 | success |
non-zero | failure |
Definition at line 3371 of file pbx.c.
References __ast_module_user_add(), __ast_module_user_remove(), ast_custom_function_find(), ast_log(), ast_strdupa, copy(), func_args(), LOG_ERROR, ast_custom_function::mod, and ast_custom_function::read.
Referenced by action_getvar(), action_status(), handle_getvariable(), lua_get_variable_value(), and pbx_substitute_variables_helper_full().
{ char *copy = ast_strdupa(function); char *args = func_args(copy); struct ast_custom_function *acfptr = ast_custom_function_find(copy); if (acfptr == NULL) ast_log(LOG_ERROR, "Function %s not registered\n", copy); else if (!acfptr->read) ast_log(LOG_ERROR, "Function %s cannot be read\n", copy); else { int res; struct ast_module_user *u = NULL; if (acfptr->mod) u = __ast_module_user_add(acfptr->mod, chan); res = acfptr->read(chan, copy, args, workspace, len); if (acfptr->mod && u) __ast_module_user_remove(acfptr->mod, u); return res; } return -1; }
int ast_func_write | ( | struct ast_channel * | chan, |
const char * | function, | ||
const char * | value | ||
) |
executes a write operation on a function
chan | Channel to execute on |
function | Data containing the function call string (will be modified) |
value | A value parameter to pass for writing |
This application executes a function in write mode on a given channel.
0 | success |
non-zero | failure |
Definition at line 3394 of file pbx.c.
References __ast_module_user_add(), __ast_module_user_remove(), ast_custom_function_find(), ast_log(), ast_strdupa, copy(), func_args(), LOG_ERROR, ast_custom_function::mod, and ast_custom_function::write.
Referenced by action_setvar(), pbx_builtin_pushvar_helper(), and pbx_builtin_setvar_helper().
{ char *copy = ast_strdupa(function); char *args = func_args(copy); struct ast_custom_function *acfptr = ast_custom_function_find(copy); if (acfptr == NULL) ast_log(LOG_ERROR, "Function %s not registered\n", copy); else if (!acfptr->write) ast_log(LOG_ERROR, "Function %s cannot be written to\n", copy); else { int res; struct ast_module_user *u = NULL; if (acfptr->mod) u = __ast_module_user_add(acfptr->mod, chan); res = acfptr->write(chan, copy, args, value); if (acfptr->mod && u) __ast_module_user_remove(acfptr->mod, u); return res; } return -1; }
const char* ast_get_context_name | ( | struct ast_context * | con | ) |
Definition at line 9451 of file pbx.c.
References ast_context::name.
Referenced by _macro_exec(), ast_context_add_include2(), ast_context_add_switch2(), ast_context_lockmacro(), ast_context_remove_include2(), ast_context_remove_switch2(), ast_context_unlockmacro(), ast_context_verify_includes(), complete_dialplan_add_extension(), complete_dialplan_add_ignorepat(), complete_dialplan_add_include(), complete_dialplan_remove_extension(), complete_dialplan_remove_ignorepat(), complete_dialplan_remove_include(), complete_show_dialplan_context(), context_merge_incls_swits_igps_other_registrars(), dundi_precache_full(), find_context_locked(), find_matching_endwhile(), find_matching_priority(), handle_cli_dialplan_save(), handle_show_hint(), handle_show_hints(), manager_show_dialplan_helper(), show_debug_helper(), and show_dialplan_helper().
{ return con ? con->name : NULL; }
const char* ast_get_context_registrar | ( | struct ast_context * | c | ) |
Definition at line 9489 of file pbx.c.
References ast_context::registrar.
Referenced by handle_cli_dialplan_save(), show_debug_helper(), and show_dialplan_helper().
{ return c ? c->registrar : NULL; }
const char* ast_get_extension_app | ( | struct ast_exten * | e | ) |
Definition at line 9519 of file pbx.c.
References ast_exten::app.
Referenced by _macro_exec(), ast_add_hint(), ast_extension_state2(), ast_get_hint(), find_matching_endwhile(), handle_cli_dialplan_save(), handle_show_hint(), handle_show_hints(), handle_statechange(), manager_show_dialplan_helper(), and print_ext().
{ return e ? e->app : NULL; }
void* ast_get_extension_app_data | ( | struct ast_exten * | e | ) |
Definition at line 9524 of file pbx.c.
References ast_exten::data.
Referenced by _macro_exec(), ast_get_hint(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), and print_ext().
{ return e ? e->data : NULL; }
const char* ast_get_extension_cidmatch | ( | struct ast_exten * | e | ) |
Definition at line 9514 of file pbx.c.
References ast_exten::cidmatch.
Referenced by complete_dialplan_remove_extension(), find_matching_priority(), and handle_cli_dialplan_save().
{ return e ? e->cidmatch : NULL; }
struct ast_context* ast_get_extension_context | ( | struct ast_exten * | exten | ) | [read] |
Definition at line 9456 of file pbx.c.
References ast_exten::parent.
Referenced by handle_show_hint(), and handle_show_hints().
{ return exten ? exten->parent : NULL; }
const char* ast_get_extension_label | ( | struct ast_exten * | e | ) |
Definition at line 9466 of file pbx.c.
References ast_exten::label.
Referenced by handle_cli_dialplan_save(), manager_show_dialplan_helper(), and show_dialplan_helper().
int ast_get_extension_matchcid | ( | struct ast_exten * | e | ) |
Definition at line 9509 of file pbx.c.
References ast_exten::matchcid.
Referenced by complete_dialplan_remove_extension(), find_matching_priority(), and handle_cli_dialplan_save().
{ return e ? e->matchcid : 0; }
const char* ast_get_extension_name | ( | struct ast_exten * | exten | ) |
Definition at line 9461 of file pbx.c.
References ast_exten::exten.
Referenced by ast_add_hint(), complete_core_show_hint(), complete_dialplan_remove_extension(), dundi_precache_full(), find_matching_priority(), handle_cli_dialplan_save(), handle_show_hint(), handle_show_hints(), hint_hash(), manager_show_dialplan_helper(), and show_dialplan_helper().
{ return exten ? exten->exten : NULL; }
int ast_get_extension_priority | ( | struct ast_exten * | exten | ) |
Definition at line 9481 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().
{ return exten ? exten->priority : -1; }
const char* ast_get_extension_registrar | ( | struct ast_exten * | e | ) |
Definition at line 9494 of file pbx.c.
References ast_exten::registrar.
Referenced by handle_cli_dialplan_save(), manager_show_dialplan_helper(), and show_dialplan_helper().
{ return e ? e->registrar : NULL; }
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.
hint | buffer for hint |
hintsize | size of hint buffer, in bytes |
name | buffer for name portion of hint |
namesize | size of name buffer |
c | Channel from which to return the hint. This is only important when the hint or name contains an expression to be expanded. |
context | which context to look in |
exten | which extension to search for |
Definition at line 4184 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(), pbx_retrieve_variable(), skinny_extensionstate_cb(), and transmit_state_notify().
{ struct ast_exten *e = ast_hint_extension(c, context, exten); if (e) { if (hint) ast_copy_string(hint, ast_get_extension_app(e), hintsize); if (name) { const char *tmp = ast_get_extension_app_data(e); if (tmp) ast_copy_string(name, tmp, namesize); } return -1; } return 0; }
const char* ast_get_ignorepat_name | ( | struct ast_ignorepat * | ip | ) |
Definition at line 9476 of file pbx.c.
References ast_ignorepat::pattern.
Referenced by complete_dialplan_remove_ignorepat(), context_merge_incls_swits_igps_other_registrars(), handle_cli_dialplan_save(), lookup_c_ip(), manager_show_dialplan_helper(), and show_dialplan_helper().
{ return ip ? ip->pattern : NULL; }
const char* ast_get_ignorepat_registrar | ( | struct ast_ignorepat * | ip | ) |
Definition at line 9504 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().
{ return ip ? ip->registrar : NULL; }
const char* ast_get_include_name | ( | struct ast_include * | include | ) |
Definition at line 9471 of file pbx.c.
References ast_include::name.
Referenced by complete_dialplan_remove_include(), context_merge_incls_swits_igps_other_registrars(), find_matching_priority(), handle_cli_dialplan_save(), lookup_ci(), manager_show_dialplan_helper(), and show_dialplan_helper().
{
return inc ? inc->name : NULL;
}
const char* ast_get_include_registrar | ( | struct ast_include * | i | ) |
Definition at line 9499 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().
{ return i ? i->registrar : NULL; }
const char* ast_get_switch_data | ( | struct ast_sw * | sw | ) |
Definition at line 9534 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().
{ return sw ? sw->data : NULL; }
int ast_get_switch_eval | ( | struct ast_sw * | sw | ) |
Definition at line 9539 of file pbx.c.
References ast_sw::eval.
Referenced by context_merge_incls_swits_igps_other_registrars().
{ return sw->eval; }
const char* ast_get_switch_name | ( | struct ast_sw * | sw | ) |
Definition at line 9529 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().
{ return sw ? sw->name : NULL; }
const char* ast_get_switch_registrar | ( | struct ast_sw * | sw | ) |
Definition at line 9544 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().
{ return sw ? sw->registrar : NULL; }
int ast_goto_if_exists | ( | struct ast_channel * | chan, |
const char * | context, | ||
const char * | exten, | ||
int | priority | ||
) |
Definition at line 9637 of file pbx.c.
References __ast_goto_if_exists().
Referenced by background_detect_exec(), channel_spy(), common_exec(), conf_run(), goto_exten(), onedigit_goto(), priority_jump(), select_entry(), and valid_exit().
{ return __ast_goto_if_exists(chan, context, exten, priority, 0); }
int ast_hashtab_compare_contexts | ( | const void * | ah_a, |
const void * | ah_b | ||
) |
hashtable functions for contexts
Definition at line 1001 of file pbx.c.
References ast_context::name.
Referenced by ast_context_find_or_create(), lua_register_switches(), and pbx_load_module().
{ const struct ast_context *ac = ah_a; const struct ast_context *bc = ah_b; if (!ac || !bc) /* safety valve, but it might prevent a crash you'd rather have happen */ return 1; /* assume context names are registered in a string table! */ return strcmp(ac->name, bc->name); }
unsigned int ast_hashtab_hash_contexts | ( | const void * | obj | ) |
Definition at line 1044 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().
{ const struct ast_context *ac = obj; return ast_hashtab_hash_string(ac->name); }
int ast_ignore_pattern | ( | const char * | context, |
const char * | pattern | ||
) |
Checks to see if a number should be ignored.
context | context to search within |
pattern | to check whether it should be ignored or not |
Check if a number should be ignored with respect to dialtone cancellation.
0 | if the pattern should not be ignored |
non-zero | if the pattern should be ignored |
Definition at line 7336 of file pbx.c.
References ast_context_find(), ast_extension_match(), ast_context::ignorepats, ast_ignorepat::next, and ast_ignorepat::pattern.
Referenced by ast_app_dtget(), disa_exec(), dp_lookup(), dundi_lookup_local(), handle_enbloc_call_message(), handle_soft_key_event_message(), handle_stimulus_message(), mgcp_ss(), skinny_ss(), and ss_thread().
{ struct ast_context *con = ast_context_find(context); if (con) { struct ast_ignorepat *pat; for (pat = con->ignorepats; pat; pat = pat->next) { if (ast_extension_match(pat->pattern, pattern)) return 1; } } return 0; }
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)
c | not really important XXX |
context | context to serach within |
exten | extension to check |
priority | priority of extension path |
callerid | callerid of extension being searched for |
Definition at line 4221 of file pbx.c.
References E_MATCHMORE, and pbx_extension_helper().
Referenced by __ast_pbx_run(), ast_app_dtget(), collect_digits(), disa_exec(), dp_lookup(), dundi_lookup_local(), handle_link_data(), handle_link_phone_dtmf(), local_dtmf_helper(), loopback_matchmore(), mgcp_ss(), pbx_builtin_background(), readexten_exec(), skinny_ss(), and ss_thread().
{ return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCHMORE, 0, 0); }
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.
extcontexts | pointer to the ast_context structure |
exttable | pointer to the ast_hashtab structure that contains all the elements in extcontexts |
registrar | of the context; if it's set the routine will delete all contexts that belong to that registrar; if NULL only the contexts that are specified in extcontexts |
Definition at line 6681 of file pbx.c.
References __ast_internal_context_destroy(), ao2_callback, ao2_container_count(), ao2_find, 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_INIT_VALUE, AST_LIST_INSERT_HEAD, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_HEAD, ast_rdlock_contexts(), ast_strdup, ast_tvdiff_us(), ast_tvnow(), ast_unlock_contexts(), ast_verb, ast_state_cb::callback, ast_hint::callbacks, context_merge(), contexts, contexts_table, ast_state_cb::data, ast_exten::data, ast_sw::data, E_MATCH, ast_exten::exten, ast_hint::exten, exten, hints, ast_hint::laststate, ast_context::name, ast_context::next, ast_sw::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().
{ double ft; struct ast_context *tmp, *oldcontextslist; struct ast_hashtab *oldtable; struct store_hints store = AST_LIST_HEAD_INIT_VALUE; struct store_hint *this; struct ast_hint *hint; struct ast_exten *exten; int length; struct ast_state_cb *thiscb; struct ast_hashtab_iter *iter; struct ao2_iterator i; /* it is very important that this function hold the hint list lock _and_ the conlock during its operation; not only do we need to ensure that the list of contexts and extensions does not change, but also that no hint callbacks (watchers) are added or removed during the merge/delete process in addition, the locks _must_ be taken in this order, because there are already other code paths that use this order */ struct timeval begintime, writelocktime, endlocktime, enddeltime; begintime = ast_tvnow(); ast_rdlock_contexts(); iter = ast_hashtab_start_traversal(contexts_table); while ((tmp = ast_hashtab_next(iter))) { context_merge(extcontexts, exttable, tmp, registrar); } ast_hashtab_end_traversal(iter); ao2_lock(hints); writelocktime = ast_tvnow(); /* preserve all watchers for hints */ i = ao2_iterator_init(hints, AO2_ITERATOR_DONTLOCK); for (hint = ao2_iterator_next(&i); hint; ao2_ref(hint, -1), hint = ao2_iterator_next(&i)) { if (ao2_container_count(hint->callbacks)) { length = strlen(hint->exten->exten) + strlen(hint->exten->parent->name) + 2 + sizeof(*this); if (!(this = ast_calloc(1, length))) { continue; } ao2_lock(hint); if (hint->exten == NULL) { ao2_unlock(hint); continue; } /* this removes all the callbacks from the hint into 'this'. */ while ((thiscb = ao2_callback(hint->callbacks, OBJ_UNLINK, NULL, NULL))) { AST_LIST_INSERT_TAIL(&this->callbacks, thiscb, entry); /* We intentionally do not unref thiscb to account for the non-ao2 reference in this->callbacks */ } this->laststate = hint->laststate; this->context = this->data; strcpy(this->data, hint->exten->parent->name); this->exten = this->data + strlen(this->context) + 1; strcpy(this->exten, hint->exten->exten); ao2_unlock(hint); AST_LIST_INSERT_HEAD(&store, this, list); } } /* save the old table and list */ oldtable = contexts_table; oldcontextslist = contexts; /* move in the new table and list */ contexts_table = exttable; contexts = *extcontexts; /* restore the watchers for hints that can be found; notify those that cannot be restored */ while ((this = AST_LIST_REMOVE_HEAD(&store, list))) { struct pbx_find_info q = { .stacklen = 0 }; exten = pbx_find_extension(NULL, NULL, &q, this->context, this->exten, PRIORITY_HINT, NULL, "", E_MATCH); /* If this is a pattern, dynamically create a new extension for this * particular match. Note that this will only happen once for each * individual extension, because the pattern will no longer match first. */ if (exten && exten->exten[0] == '_') { ast_add_extension_nolock(exten->parent->name, 0, this->exten, PRIORITY_HINT, NULL, 0, exten->app, ast_strdup(exten->data), ast_free_ptr, exten->registrar); /* rwlocks are not recursive locks */ exten = ast_hint_extension_nolock(NULL, this->context, this->exten); } /* Find the hint in the list of hints */ hint = ao2_find(hints, exten, 0); if (!exten || !hint) { /* this hint has been removed, notify the watchers */ while ((thiscb = AST_LIST_REMOVE_HEAD(&this->callbacks, entry))) { thiscb->callback(this->context, this->exten, AST_EXTENSION_REMOVED, thiscb->data); ao2_ref(thiscb, -1); /* Ref that we added when putting into this->callbacks */ } } else { ao2_lock(hint); while ((thiscb = AST_LIST_REMOVE_HEAD(&this->callbacks, entry))) { ao2_link(hint->callbacks, thiscb); ao2_ref(thiscb, -1); /* Ref that we added when putting into this->callbacks */ } hint->laststate = this->laststate; ao2_unlock(hint); } ast_free(this); if (hint) { ao2_ref(hint, -1); } } ao2_unlock(hints); ast_unlock_contexts(); endlocktime = ast_tvnow(); /* the old list and hashtab no longer are relevant, delete them while the rest of asterisk is now freely using the new stuff instead */ ast_hashtab_destroy(oldtable, NULL); for (tmp = oldcontextslist; tmp; ) { struct ast_context *next; /* next starting point */ next = tmp->next; __ast_internal_context_destroy(tmp); tmp = next; } enddeltime = ast_tvnow(); ft = ast_tvdiff_us(writelocktime, begintime); ft /= 1000000.0; ast_verb(3,"Time to scan old dialplan and merge leftovers back into the new: %8.6f sec\n", ft); ft = ast_tvdiff_us(endlocktime, writelocktime); ft /= 1000000.0; ast_verb(3,"Time to restore hints and swap in new dialplan: %8.6f sec\n", ft); ft = ast_tvdiff_us(enddeltime, endlocktime); ft /= 1000000.0; ast_verb(3,"Time to delete the old dialplan: %8.6f sec\n", ft); ft = ast_tvdiff_us(enddeltime, begintime); ft /= 1000000.0; ast_verb(3,"Total time merge_contexts_delete: %8.6f sec\n", ft); return; }
int ast_parseable_goto | ( | struct ast_channel * | chan, |
const char * | goto_string | ||
) |
Definition at line 9700 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().
{ return pbx_parseable_goto(chan, goto_string, 0); }
int ast_pbx_outgoing_app | ( | const char * | type, |
int | 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 8175 of file pbx.c.
References __ast_request_and_dial(), ast_channel::_state, outgoing_helper::account, async_stat::app, app_tmp::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_strlen_zero(), ast_variables_destroy(), ast_verb, async_wait(), ast_channel::cdr, async_stat::chan, app_tmp::chan, chan, app_tmp::data, 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().
{ struct ast_channel *chan; struct app_tmp *tmp; int res = -1, cdr_res = -1; struct outgoing_helper oh; memset(&oh, 0, sizeof(oh)); oh.vars = vars; oh.account = account; if (locked_channel) *locked_channel = NULL; if (ast_strlen_zero(app)) { res = -1; goto outgoing_app_cleanup; } if (synchronous) { chan = __ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name, &oh); if (chan) { ast_set_variables(chan, vars); if (account) ast_cdr_setaccount(chan, account); if (chan->_state == AST_STATE_UP) { res = 0; ast_verb(4, "Channel %s was answered.\n", chan->name); tmp = ast_calloc(1, sizeof(*tmp)); if (!tmp) res = -1; else { ast_copy_string(tmp->app, app, sizeof(tmp->app)); if (appdata) ast_copy_string(tmp->data, appdata, sizeof(tmp->data)); tmp->chan = chan; if (synchronous > 1) { if (locked_channel) ast_channel_unlock(chan); ast_pbx_run_app(tmp); } else { if (locked_channel) ast_channel_lock(chan); if (ast_pthread_create_detached(&tmp->t, NULL, ast_pbx_run_app, tmp)) { ast_log(LOG_WARNING, "Unable to spawn execute thread on %s: %s\n", chan->name, strerror(errno)); ast_free(tmp); if (locked_channel) ast_channel_unlock(chan); ast_hangup(chan); res = -1; } else { if (locked_channel) *locked_channel = chan; } } } } else { ast_verb(4, "Channel %s was never answered.\n", chan->name); if (chan->cdr) { /* update the cdr */ /* here we update the status of the call, which sould be busy. * if that fails then we set the status to failed */ if (ast_cdr_disposition(chan->cdr, chan->hangupcause)) ast_cdr_failed(chan->cdr); } ast_hangup(chan); } } if (res < 0) { /* the call failed for some reason */ if (*reason == 0) { /* if the call failed (not busy or no answer) * update the cdr with the failed message */ cdr_res = ast_pbx_outgoing_cdr_failed(); if (cdr_res != 0) { res = cdr_res; goto outgoing_app_cleanup; } } } } else { struct async_stat *as; if (!(as = ast_calloc(1, sizeof(*as)))) { res = -1; goto outgoing_app_cleanup; } chan = __ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name, &oh); if (!chan) { ast_free(as); res = -1; goto outgoing_app_cleanup; } as->chan = chan; ast_copy_string(as->app, app, sizeof(as->app)); if (appdata) ast_copy_string(as->appdata, appdata, sizeof(as->appdata)); as->timeout = timeout; ast_set_variables(chan, vars); if (account) ast_cdr_setaccount(chan, account); /* Start a new thread, and get something handling this channel. */ if (locked_channel) ast_channel_lock(chan); if (ast_pthread_create_detached(&as->p, NULL, async_wait, as)) { ast_log(LOG_WARNING, "Failed to start async wait\n"); ast_free(as); if (locked_channel) ast_channel_unlock(chan); ast_hangup(chan); res = -1; goto outgoing_app_cleanup; } else { if (locked_channel) *locked_channel = chan; } res = 0; } outgoing_app_cleanup: ast_variables_destroy(vars); return res; }
int ast_pbx_outgoing_exten | ( | const char * | type, |
int | 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 8009 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, chan, cid_name, outgoing_helper::cid_name, cid_num, outgoing_helper::cid_num, async_stat::context, ast_channel::context, context, outgoing_helper::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().
{ struct ast_channel *chan; struct async_stat *as; int res = -1, cdr_res = -1; struct outgoing_helper oh; if (synchronous) { oh.context = context; oh.exten = exten; oh.priority = priority; oh.cid_num = cid_num; oh.cid_name = cid_name; oh.account = account; oh.vars = vars; oh.parent_channel = NULL; chan = __ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name, &oh); if (channel) { *channel = chan; if (chan) ast_channel_lock(chan); } if (chan) { if (chan->_state == AST_STATE_UP) { res = 0; ast_verb(4, "Channel %s was answered.\n", chan->name); if (synchronous > 1) { if (channel) ast_channel_unlock(chan); if (ast_pbx_run(chan)) { ast_log(LOG_ERROR, "Unable to run PBX on %s\n", chan->name); if (channel) *channel = NULL; ast_hangup(chan); chan = NULL; res = -1; } } else { if (ast_pbx_start(chan)) { ast_log(LOG_ERROR, "Unable to start PBX on %s\n", chan->name); if (channel) { *channel = NULL; ast_channel_unlock(chan); } ast_hangup(chan); res = -1; } chan = NULL; } } else { ast_verb(4, "Channel %s was never answered.\n", chan->name); if (chan->cdr) { /* update the cdr */ /* here we update the status of the call, which sould be busy. * if that fails then we set the status to failed */ if (ast_cdr_disposition(chan->cdr, chan->hangupcause)) ast_cdr_failed(chan->cdr); } if (channel) { *channel = NULL; ast_channel_unlock(chan); } ast_hangup(chan); chan = NULL; } } if (res < 0) { /* the call failed for some reason */ if (*reason == 0) { /* if the call failed (not busy or no answer) * update the cdr with the failed message */ cdr_res = ast_pbx_outgoing_cdr_failed(); if (cdr_res != 0) { res = cdr_res; goto outgoing_exten_cleanup; } } /* create a fake channel and execute the "failed" extension (if it exists) within the requested context */ /* check if "failed" exists */ if (ast_exists_extension(chan, context, "failed", 1, NULL)) { chan = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", 0, "OutgoingSpoolFailed"); if (chan) { char failed_reason[4] = ""; if (!ast_strlen_zero(context)) ast_copy_string(chan->context, context, sizeof(chan->context)); set_ext_pri(chan, "failed", 1); ast_set_variables(chan, vars); snprintf(failed_reason, sizeof(failed_reason), "%d", *reason); pbx_builtin_setvar_helper(chan, "REASON", failed_reason); if (account) ast_cdr_setaccount(chan, account); if (ast_pbx_run(chan)) { ast_log(LOG_ERROR, "Unable to run PBX on %s\n", chan->name); ast_hangup(chan); } chan = NULL; } } } } else { if (!(as = ast_calloc(1, sizeof(*as)))) { res = -1; goto outgoing_exten_cleanup; } chan = ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name); if (channel) { *channel = chan; if (chan) ast_channel_lock(chan); } if (!chan) { ast_free(as); res = -1; goto outgoing_exten_cleanup; } as->chan = chan; ast_copy_string(as->context, context, sizeof(as->context)); set_ext_pri(as->chan, exten, priority); as->timeout = timeout; ast_set_variables(chan, vars); if (account) ast_cdr_setaccount(chan, account); if (ast_pthread_create_detached(&as->p, NULL, async_wait, as)) { ast_log(LOG_WARNING, "Failed to start async wait\n"); ast_free(as); if (channel) { *channel = NULL; ast_channel_unlock(chan); } ast_hangup(chan); res = -1; goto outgoing_exten_cleanup; } res = 0; } outgoing_exten_cleanup: ast_variables_destroy(vars); return res; }
enum ast_pbx_result ast_pbx_run | ( | struct ast_channel * | c | ) |
Execute the PBX in the current thread.
c | channel to run the pbx on |
This executes the PBX on a given channel. It allocates a new PBX structure for the channel, and provides all PBX functionality. See ast_pbx_start for an asynchronous function to run the PBX in a new thread as opposed to the current one.
Zero | on success |
non-zero | on failure |
Definition at line 4654 of file pbx.c.
References ast_pbx_run_args().
Referenced by ast_pbx_outgoing_exten(), async_wait(), mgcp_ss(), skinny_newcall(), ss_thread(), and unistim_ss().
{ return ast_pbx_run_args(c, NULL); }
enum ast_pbx_result ast_pbx_run_args | ( | struct ast_channel * | c, |
struct ast_pbx_args * | args | ||
) |
Execute the PBX in the current thread.
c | channel to run the pbx on |
args | options for the pbx |
This executes the PBX on a given channel. It allocates a new PBX structure for the channel, and provides all PBX functionality. See ast_pbx_start for an asynchronous function to run the PBX in a new thread as opposed to the current one.
Zero | on success |
non-zero | on failure |
Definition at line 4639 of file pbx.c.
References __ast_pbx_run(), AST_PBX_CALL_LIMIT, AST_PBX_SUCCESS, decrease_call_count(), and increase_call_count().
Referenced by ast_pbx_run(), dial_exec_full(), handle_gosub(), and try_calling().
{ enum ast_pbx_result res = AST_PBX_SUCCESS; if (increase_call_count(c)) { return AST_PBX_CALL_LIMIT; } res = __ast_pbx_run(c, args); decrease_call_count(); return res; }
enum ast_pbx_result ast_pbx_start | ( | struct ast_channel * | c | ) |
Create a new thread and start the PBX.
c | channel to start the pbx on |
Zero | on success |
non-zero | on failure |
Definition at line 4617 of file pbx.c.
References ast_log(), AST_PBX_CALL_LIMIT, AST_PBX_FAILED, AST_PBX_SUCCESS, ast_pthread_create_detached, 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(), gtalk_new(), gtalk_newcall(), handle_request_invite(), jingle_new(), jingle_newcall(), local_call(), manage_parkinglot(), mgcp_new(), nbs_new(), oss_new(), pbx_start_chan(), phone_new(), rpt_call(), sip_new(), skinny_new(), unistim_new(), and usbradio_new().
{ pthread_t t; if (!c) { ast_log(LOG_WARNING, "Asked to start thread on NULL channel?\n"); return AST_PBX_FAILED; } if (increase_call_count(c)) return AST_PBX_CALL_LIMIT; /* Start a new thread, and get something handling this channel. */ if (ast_pthread_create_detached(&t, NULL, pbx_thread, c)) { ast_log(LOG_WARNING, "Failed to create new channel thread\n"); decrease_call_count(); return AST_PBX_FAILED; } return AST_PBX_SUCCESS; }
int ast_processed_calls | ( | void | ) |
Retrieve the total number of calls processed through the PBX since last restart.
Definition at line 4664 of file pbx.c.
References totalcalls.
Referenced by ast_var_Config(), handle_chanlist(), and handle_showcalls().
{ return totalcalls; }
int ast_rdlock_context | ( | struct ast_context * | con | ) |
Read locks a given context.
con | context to lock |
0 | on success |
-1 | on failure |
Definition at line 9438 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().
{ return ast_rwlock_rdlock(&con->lock); }
int ast_rdlock_contexts | ( | void | ) |
Read locks the context list.
0 | on success |
-1 | on error |
Definition at line 9420 of file pbx.c.
References ast_mutex_lock(), and conlock.
Referenced by _macro_exec(), ast_context_find(), ast_context_find_or_create(), ast_context_lockmacro(), ast_context_unlockmacro(), ast_hint_extension(), ast_merge_contexts_and_delete(), complete_dialplan_add_extension(), complete_dialplan_add_ignorepat(), complete_dialplan_add_include(), complete_dialplan_remove_extension(), complete_dialplan_remove_ignorepat(), complete_dialplan_remove_include(), complete_show_dialplan_context(), dundi_precache_full(), find_context_locked(), find_matching_endwhile(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), pbx_extension_helper(), show_debug_helper(), show_dialplan_helper(), and unreference_cached_app().
{ return ast_mutex_lock(&conlock); }
int ast_register_switch | ( | struct ast_switch * | sw | ) |
Register an alternative dialplan switch.
sw | switch to register |
This function registers a populated ast_switch structure with the asterisk switching architecture.
0 | success |
non-zero | failure |
Definition at line 5215 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().
{ struct ast_switch *tmp; AST_RWLIST_WRLOCK(&switches); AST_RWLIST_TRAVERSE(&switches, tmp, list) { if (!strcasecmp(tmp->name, sw->name)) { AST_RWLIST_UNLOCK(&switches); ast_log(LOG_WARNING, "Switch '%s' already found\n", sw->name); return -1; } } AST_RWLIST_INSERT_TAIL(&switches, sw, list); AST_RWLIST_UNLOCK(&switches); return 0; }
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)
c | not important |
context | which context to generate the extension within |
exten | new extension to add |
priority | priority of new extension |
callerid | callerid of extension |
found | |
combined_find_spawn |
This adds a new extension to the asterisk extension list.
0 | on success |
-1 | on failure. |
Definition at line 4226 of file pbx.c.
References E_SPAWN, and pbx_extension_helper().
Referenced by __ast_pbx_run(), _macro_exec(), ast_bridge_call(), dial_exec_full(), and loopback_exec().
{ return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_SPAWN, found, combined_find_spawn); }
void ast_str_substitute_variables | ( | struct ast_str ** | buf, |
size_t | maxlen, | ||
struct ast_channel * | chan, | ||
const char * | templ | ||
) |
Definition at line 115 of file strings.c.
References ast_str_make_space(), first, and pbx_substitute_variables_helper_full().
Referenced by acf_odbc_read(), acf_odbc_write(), cli_odbc_read(), and cli_odbc_write().
{ int first = 1; do { ast_str_make_space(buf, maxlen ? maxlen : (first ? strlen(template) * 2 : (*buf)->__AST_STR_LEN * 2)); pbx_substitute_variables_helper_full(chan, NULL, template, (*buf)->__AST_STR_STR, (*buf)->__AST_STR_LEN - 1, &((*buf)->__AST_STR_USED)); first = 0; } while (maxlen == 0 && (*buf)->__AST_STR_LEN - 5 < (*buf)->__AST_STR_USED); }
int ast_unlock_context | ( | struct ast_context * | con | ) |
Unlocks | the given context |
con | context to unlock |
0 | on success |
-1 | on failure |
Definition at line 9443 of file pbx.c.
References ast_rwlock_unlock(), and ast_context::lock.
Referenced by __ast_context_destroy(), _macro_exec(), ast_add_extension2_lockopt(), ast_context_add_ignorepat2(), ast_context_add_include2(), ast_context_add_switch2(), ast_context_remove_extension_callerid2(), ast_context_remove_ignorepat2(), ast_context_remove_include2(), ast_context_remove_switch2(), 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().
{ return ast_rwlock_unlock(&con->lock); }
int ast_unlock_contexts | ( | void | ) |
Unlocks contexts.
0 | on success |
-1 | on failure |
Definition at line 9425 of file pbx.c.
References ast_mutex_unlock(), and conlock.
Referenced by _macro_exec(), ast_add_extension(), ast_context_add_ignorepat(), ast_context_add_include(), ast_context_add_switch(), ast_context_destroy(), ast_context_find(), ast_context_find_or_create(), ast_context_lockmacro(), ast_context_remove_extension_callerid(), ast_context_remove_ignorepat(), ast_context_remove_include(), ast_context_remove_switch(), ast_context_unlockmacro(), ast_hint_extension(), ast_merge_contexts_and_delete(), complete_dialplan_add_extension(), complete_dialplan_add_ignorepat(), complete_dialplan_add_include(), complete_dialplan_remove_extension(), complete_dialplan_remove_ignorepat(), complete_dialplan_remove_include(), complete_show_dialplan_context(), dundi_precache_full(), find_context_locked(), find_matching_endwhile(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), pbx_extension_helper(), show_debug_helper(), show_dialplan_helper(), and unreference_cached_app().
{ return ast_mutex_unlock(&conlock); }
void ast_unregister_switch | ( | struct ast_switch * | sw | ) |
Unregister an alternative switch.
sw | switch to unregister |
Unregisters a switch from asterisk.
Definition at line 5233 of file pbx.c.
References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.
Referenced by __unload_module(), and unload_module().
{ AST_RWLIST_WRLOCK(&switches); AST_RWLIST_REMOVE(&switches, sw, list); AST_RWLIST_UNLOCK(&switches); }
struct ast_exten* ast_walk_context_extensions | ( | struct ast_context * | con, |
struct ast_exten * | priority | ||
) | [read] |
Definition at line 9557 of file pbx.c.
References ast_exten::next, and ast_context::root.
Referenced by complete_dialplan_remove_extension(), dundi_precache_full(), find_matching_priority(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), pbx_find_extension(), show_dialplan_helper(), and unreference_cached_app().
struct ast_ignorepat* ast_walk_context_ignorepats | ( | struct ast_context * | con, |
struct ast_ignorepat * | ip | ||
) | [read] |
Definition at line 9590 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(), handle_cli_dialplan_save(), lookup_c_ip(), manager_show_dialplan_helper(), and show_dialplan_helper().
{ if (!ip) return con ? con->ignorepats : NULL; else return ip->next; }
struct ast_include* ast_walk_context_includes | ( | struct ast_context * | con, |
struct ast_include * | inc | ||
) | [read] |
Definition at line 9581 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(), find_matching_priority(), handle_cli_dialplan_save(), lookup_ci(), manager_show_dialplan_helper(), and show_dialplan_helper().
struct ast_sw* ast_walk_context_switches | ( | struct ast_context * | con, |
struct ast_sw * | sw | ||
) | [read] |
Definition at line 9566 of file pbx.c.
References ast_context::alts, AST_LIST_FIRST, and AST_LIST_NEXT.
Referenced by context_merge_incls_swits_igps_other_registrars(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), and show_dialplan_helper().
{ if (!sw) return con ? AST_LIST_FIRST(&con->alts) : NULL; else return AST_LIST_NEXT(sw, list); }
struct ast_context* ast_walk_contexts | ( | struct ast_context * | con | ) | [read] |
Definition at line 9552 of file pbx.c.
References contexts, and ast_context::next.
Referenced by _macro_exec(), ast_context_find(), ast_context_lockmacro(), ast_context_unlockmacro(), complete_dialplan_add_extension(), complete_dialplan_add_ignorepat(), complete_dialplan_add_include(), complete_dialplan_remove_extension(), complete_dialplan_remove_ignorepat(), complete_dialplan_remove_include(), complete_show_dialplan_context(), dundi_precache_full(), find_context_locked(), find_matching_endwhile(), find_matching_priority(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), pbx_find_extension(), pbx_load_module(), show_debug_helper(), show_dialplan_helper(), and unreference_cached_app().
struct ast_exten* ast_walk_extension_priorities | ( | struct ast_exten * | exten, |
struct ast_exten * | priority | ||
) | [read] |
Definition at line 9575 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(), pbx_find_extension(), show_dialplan_helper(), and unreference_cached_app().
int ast_wrlock_context | ( | struct ast_context * | con | ) |
Write locks a given context.
con | context to lock |
0 | on success |
-1 | on failure |
Definition at line 9433 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().
{ return ast_rwlock_wrlock(&con->lock); }
int ast_wrlock_contexts | ( | void | ) |
Write locks the context list.
0 | on success |
-1 | on error |
Definition at line 9415 of file pbx.c.
References ast_mutex_lock(), and conlock.
Referenced by ast_context_destroy(), ast_context_find_or_create(), and complete_dialplan_remove_include().
{ return ast_mutex_lock(&conlock); }
void pbx_builtin_clear_globals | ( | void | ) |
Definition at line 9258 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(), and reload().
{ struct ast_var_t *vardata; ast_rwlock_wrlock(&globalslock); while ((vardata = AST_LIST_REMOVE_HEAD(&globals, entries))) ast_var_delete(vardata); ast_rwlock_unlock(&globalslock); }
const char* pbx_builtin_getvar_helper | ( | struct ast_channel * | chan, |
const char * | name | ||
) |
Return a pointer to the value of the corresponding channel variable.
const char *var; ast_channel_lock(chan); if ((var = pbx_builtin_getvar_helper(chan, "MYVAR"))) { var = ast_strdupa(var); } ast_channel_unlock(chan);
Definition at line 9020 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(), agent_hangup(), agent_read(), agentmonitoroutgoing_exec(), array(), ast_bridge_call(), ast_call_forward(), ast_eivr_getvariable(), ast_monitor_stop(), bridge_play_sounds(), builtin_atxfer(), builtin_automixmonitor(), builtin_automonitor(), check_goto_on_transfer(), common_exec(), conf_exec(), conf_run(), confbridge_exec(), dahdi_call(), dahdi_hangup(), dial_exec_full(), do_forward(), do_timelimit(), dundi_exec(), dundi_helper(), feature_interpret(), find_by_mark(), find_conf_realtime(), findparkinglotname(), get_also_info(), get_index(), get_refer_info(), global_read(), hash_read(), iax2_call(), iax2_exec(), import_ch(), leave_voicemail(), listfilter(), local_attended_transfer(), local_hangup(), local_read(), login_exec(), macro_fixup(), minivm_delete_exec(), minivm_notify_exec(), misdn_answer(), misdn_hangup(), morsecode_exec(), notify_new_message(), oh323_call(), oh323_hangup(), park_call_full(), park_space_reserve(), pbx_builtin_background(), queue_exec(), real_ctx(), retrydial_exec(), ring_entry(), run_agi(), set_config_flags(), set_local_info(), sip_addheader(), sla_trunk_exec(), speech_background(), try_calling(), try_suggested_sip_codec(), update_bridge_vars(), and wait_for_answer().
{ struct ast_var_t *variables; const char *ret = NULL; int i; struct varshead *places[2] = { NULL, &globals }; if (!name) return NULL; if (chan) { ast_channel_lock(chan); places[0] = &chan->varshead; } for (i = 0; i < 2; i++) { if (!places[i]) continue; if (places[i] == &globals) ast_rwlock_rdlock(&globalslock); AST_LIST_TRAVERSE(places[i], variables, entries) { if (!strcmp(name, ast_var_name(variables))) { ret = ast_var_value(variables); break; } } if (places[i] == &globals) ast_rwlock_unlock(&globalslock); if (ret) break; } if (chan) ast_channel_unlock(chan); return ret; }
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.
Definition at line 9058 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().
{ struct ast_var_t *newvariable; struct varshead *headp; if (name[strlen(name)-1] == ')') { char *function = ast_strdupa(name); ast_log(LOG_WARNING, "Cannot push a value onto a function\n"); ast_func_write(chan, function, value); return; } if (chan) { ast_channel_lock(chan); headp = &chan->varshead; } else { ast_rwlock_wrlock(&globalslock); headp = &globals; } if (value) { if (headp == &globals) ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value); newvariable = ast_var_assign(name, value); AST_LIST_INSERT_HEAD(headp, newvariable, entries); } if (chan) ast_channel_unlock(chan); else ast_rwlock_unlock(&globalslock); }
int pbx_builtin_raise_exception | ( | struct ast_channel * | chan, |
void * | data | ||
) |
Definition at line 3010 of file pbx.c.
References ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_datastore_alloc(), ast_datastore_free(), ast_free, ast_string_field_init, ast_string_field_set, ast_channel::context, ast_datastore::data, exception_store_info, ast_channel::exten, exten, ast_channel::priority, pbx_exception::priority, and set_ext_pri().
Referenced by __ast_pbx_run().
{ const char *reason = vreason; struct ast_datastore *ds = ast_channel_datastore_find(chan, &exception_store_info, NULL); struct pbx_exception *exception = NULL; if (!ds) { ds = ast_datastore_alloc(&exception_store_info, NULL); if (!ds) return -1; exception = ast_calloc(1, sizeof(struct pbx_exception)); if (!exception) { ast_datastore_free(ds); return -1; } if (ast_string_field_init(exception, 128)) { ast_free(exception); ast_datastore_free(ds); return -1; } ds->data = exception; ast_channel_datastore_add(chan, ds); } else exception = ds->data; ast_string_field_set(exception, reason, reason); ast_string_field_set(exception, context, chan->context); ast_string_field_set(exception, exten, chan->exten); exception->priority = chan->priority; set_ext_pri(chan, "e", 0); return 0; }
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.
chan | Channel from which to read variables |
buf | Dynamic string in which to place the result (should be allocated with |
Definition at line 8989 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, val, var, and ast_channel::varshead.
Referenced by ast_var_channels_table(), dumpchan_exec(), handle_show_chanvar(), handle_showchan(), and vars2manager().
{ struct ast_var_t *variables; const char *var, *val; int total = 0; if (!chan) return 0; ast_str_reset(*buf); ast_channel_lock(chan); AST_LIST_TRAVERSE(&chan->varshead, variables, entries) { if ((var = ast_var_name(variables)) && (val = ast_var_value(variables)) /* && !ast_strlen_zero(var) && !ast_strlen_zero(val) */ ) { if (ast_str_append(buf, 0, "%s=%s\n", var, val) < 0) { ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n"); break; } else total++; } else break; } ast_channel_unlock(chan); return total; }
int pbx_builtin_setvar | ( | struct ast_channel * | chan, |
void * | data | ||
) |
Parse and set a single channel variable, where the name and value are separated with an '=' character.
Definition at line 9150 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(), and strsep().
Referenced by ast_compile_ael2(), and rpt_exec().
{ char *name, *value, *mydata; if (ast_compat_app_set) { return pbx_builtin_setvar_multiple(chan, data); } if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "Set requires one variable name/value pair.\n"); return 0; } mydata = ast_strdupa(data); name = strsep(&mydata, "="); value = mydata; if (!value) { ast_log(LOG_WARNING, "Set requires an '=' to be a valid assignment.\n"); return 0; } if (strchr(name, ' ')) { ast_log(LOG_WARNING, "Please avoid unnecessary spaces on variables as it may lead to unexpected results ('%s' set to '%s').\n", name, mydata); } pbx_builtin_setvar_helper(chan, name, value); return 0; }
void 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 at line 9092 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 __ast_pbx_run(), __oh323_new(), _macro_exec(), _while_exec(), acf_curl_exec(), acf_fetch(), acf_odbc_read(), acf_odbc_write(), acf_transaction_write(), action_atxfer(), action_setvar(), admin_exec(), agi_exec_full(), aji_status_exec(), aqm_exec(), array(), ast_bridge_call(), ast_eivr_setvariable(), ast_iax2_new(), ast_monitor_start(), ast_monitor_stop(), ast_pbx_outgoing_exten(), ast_rtp_set_vars(), ast_set_variables(), asyncgoto_exec(), background_detect_exec(), bridge_exec(), bridge_play_sounds(), builtin_atxfer(), builtin_automixmonitor(), builtin_automonitor(), builtin_blindtransfer(), cb_events(), chanavail_exec(), channel_spy(), commit_exec(), conf_run(), controlplayback_exec(), count_exec(), dahdi_handle_dtmf(), dahdi_new(), dial_exec_full(), disa_exec(), do_waiting(), end_bridge_callback(), export_aoc_vars(), export_ch(), feature_request_and_dial(), frame_set_var(), function_db_delete(), function_db_exists(), function_db_read(), function_realtime_store(), get_rdnis(), get_refer_info(), global_write(), gosub_release_frame(), handle_request_bye(), handle_request_refer(), handle_set_chanvar(), handle_set_global(), handle_setvariable(), hash_read(), hash_write(), isAnsweringMachine(), leave_voicemail(), local_hangup(), lua_set_variable(), lua_set_variable_value(), macro_fixup(), manage_parkinglot(), minivm_accmess_exec(), minivm_delete_exec(), minivm_greet_exec(), minivm_notify_exec(), minivm_record_exec(), misdn_call(), mixmonitor_exec(), originate_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), park_exec_full(), parse_moved_contact(), pbx_builtin_background(), pbx_builtin_importvar(), pbx_builtin_setvar(), pbx_builtin_setvar_multiple(), pbx_load_config(), phase_e_handler(), play_message_datetime(), playback_exec(), pqm_exec(), prep_email_sub_vars(), privacy_exec(), process_ast_dsp(), process_sdp(), read_exec(), readexten_exec(), readfile_exec(), realtimefield_read(), record_exec(), return_exec(), rollback_exec(), rotate_file(), rpt_exec(), rqm_exec(), sendimage_exec(), sendtext_exec(), sendurl_exec(), set(), set_agentbycallerid(), set_queue_result(), sip_addheader(), sip_hangup(), sip_new(), sip_read(), skinny_new(), sla_calc_trunk_timeouts(), sla_station_exec(), sla_trunk_exec(), socket_process(), speech_create(), ss_thread(), start_monitor_exec(), system_exec_helper(), transfer_exec(), transmit(), tryexec_exec(), update_bridge_vars(), update_qe_rule(), upqm_exec(), vm_box_exists(), vm_exec(), vmauthenticate(), waituntil_exec(), and zapateller_exec().
{ struct ast_var_t *newvariable; struct varshead *headp; const char *nametail = name; if (name[strlen(name) - 1] == ')') { char *function = ast_strdupa(name); ast_func_write(chan, function, value); return; } if (chan) { ast_channel_lock(chan); headp = &chan->varshead; } else { ast_rwlock_wrlock(&globalslock); headp = &globals; } /* For comparison purposes, we have to strip leading underscores */ if (*nametail == '_') { nametail++; if (*nametail == '_') nametail++; } AST_LIST_TRAVERSE_SAFE_BEGIN(headp, newvariable, entries) { if (strcmp(ast_var_name(newvariable), nametail) == 0) { /* there is already such a variable, delete it */ AST_LIST_REMOVE_CURRENT(entries); ast_var_delete(newvariable); break; } } AST_LIST_TRAVERSE_SAFE_END; if (value) { if (headp == &globals) ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value); newvariable = ast_var_assign(name, value); AST_LIST_INSERT_HEAD(headp, newvariable, entries); manager_event(EVENT_FLAG_DIALPLAN, "VarSet", "Channel: %s\r\n" "Variable: %s\r\n" "Value: %s\r\n" "Uniqueid: %s\r\n", chan ? chan->name : "none", name, value, chan ? chan->uniqueid : "none"); } if (chan) ast_channel_unlock(chan); else ast_rwlock_unlock(&globalslock); }
int pbx_builtin_setvar_multiple | ( | struct ast_channel * | chan, |
void * | data | ||
) |
Parse and set multiple channel variables, where the pairs are separated by the ',' character, and name and value are separated with an '=' character.
Definition at line 9180 of file pbx.c.
References 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(), and ast_channel::priority.
Referenced by pbx_builtin_setvar(), queue_function_var(), set_queue_variables(), and try_calling().
{ char *data; int x; AST_DECLARE_APP_ARGS(args, AST_APP_ARG(pair)[24]; ); AST_DECLARE_APP_ARGS(pair, AST_APP_ARG(name); AST_APP_ARG(value); ); if (ast_strlen_zero(vdata)) { ast_log(LOG_WARNING, "MSet requires at least one variable name/value pair.\n"); return 0; } data = ast_strdupa(vdata); AST_STANDARD_APP_ARGS(args, data); for (x = 0; x < args.argc; x++) { AST_NONSTANDARD_APP_ARGS(pair, args.pair[x], '='); if (pair.argc == 2) { pbx_builtin_setvar_helper(chan, pair.name, pair.value); if (strchr(pair.name, ' ')) 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); } else if (!chan) { ast_log(LOG_WARNING, "MSet: ignoring entry '%s' with no '='\n", pair.name); } else { ast_log(LOG_WARNING, "MSet: ignoring entry '%s' with no '=' (in %s@%s:%d\n", pair.name, chan->exten, chan->context, chan->priority); } } return 0; }
int pbx_checkcondition | ( | const char * | condition | ) |
Evaluate a condition.
0 | if the condition is NULL or of zero length |
int | If the string is an integer, the integer representation of the integer is returned |
1 | Any other non-empty string |
Definition at line 9268 of file pbx.c.
References ast_strlen_zero().
Referenced by _macro_exec(), _while_exec(), acf_if(), execif_exec(), gosubif_exec(), macroif_exec(), and pbx_builtin_gotoif().
{ int res; if (ast_strlen_zero(condition)) { /* NULL or empty strings are false */ return 0; } else if (sscanf(condition, "%30d", &res) == 1) { /* Numbers are evaluated for truth */ return res; } else { /* Strings are true */ return 1; } }
int pbx_exec | ( | struct ast_channel * | c, |
struct ast_app * | app, | ||
void * | data | ||
) |
Execute an application.
c | channel to execute on |
app | which app to execute |
data | the data passed into the app |
This application executes an application on a given channel. It saves the stack and executes the given application passing in the given data.
0 | success |
-1 | failure |
c | Channel |
app | Application |
data | Data for execution |
Definition at line 1333 of file pbx.c.
References __ast_module_user_add(), __ast_module_user_remove(), ast_channel::appl, ast_cdr_setapp(), ast_check_hangup(), ast_log(), ast_opt_dont_warn, ast_strlen_zero(), ast_channel::cdr, ast_sw::data, ast_channel::data, ast_app::execute, LOG_WARNING, and S_OR.
Referenced by answer_exec_run(), 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(), handle_gosub(), iax2_exec(), lua_pbx_exec(), page_exec(), pbx_builtin_execiftime(), pbx_extension_helper(), realtime_exec(), try_calling(), and tryexec_exec().
{ int res; struct ast_module_user *u = NULL; const char *saved_c_appl; const char *saved_c_data; if (c->cdr && !ast_check_hangup(c)) ast_cdr_setapp(c->cdr, app->name, data); /* save channel values */ saved_c_appl= c->appl; saved_c_data= c->data; c->appl = app->name; c->data = data; if (app->module) u = __ast_module_user_add(app->module, c); if (strcasecmp(app->name, "system") && !ast_strlen_zero(data) && strchr(data, '|') && !strchr(data, ',') && !ast_opt_dont_warn) { ast_log(LOG_WARNING, "The application delimiter is now the comma, not " "the pipe. Did you forget to convert your dialplan? (%s(%s))\n", app->name, (char *) data); } res = app->execute(c, S_OR((char *) data, "")); if (app->module && u) __ast_module_user_remove(app->module, u); /* restore channel values */ c->appl = saved_c_appl; c->data = saved_c_data; return res; }
struct ast_exten* pbx_find_extension | ( | struct ast_channel * | chan, |
struct ast_context * | bypass, | ||
struct pbx_find_info * | q, | ||
const char * | context, | ||
const char * | exten, | ||
int | priority, | ||
const char * | label, | ||
const char * | callerid, | ||
enum ext_match_t | action | ||
) | [read] |
Definition at line 2484 of file pbx.c.
References ast_context::alts, ast_autoservice_start(), ast_autoservice_stop(), ast_copy_string(), 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_walk_contexts(), ast_walk_extension_priorities(), ast_switch::canmatch, scoreboard::canmatch_exten, context, contexts_table, create_match_char_tree(), ast_sw::data, pbx_find_info::data, E_CANMATCH, E_FINDLABEL, E_MATCHMORE, ast_sw::eval, ast_switch::exists, ast_exten::exten, scoreboard::exten, extenpatternmatchnew, extension_match_core(), pbx_find_info::foundcontext, include_valid(), ast_context::includes, pbx_find_info::incstack, ast_exten::label, scoreboard::last_char, LOG_DEBUG, log_match_char_tree(), LOG_NOTICE, LOG_WARNING, match(), matchcid(), ast_switch::matchmore, ast_sw::name, ast_context::name, fake_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(), 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(), pbx_extension_helper(), pbx_find_extension(), and register_peer_exten().
{ int x, res; struct ast_context *tmp = NULL; struct ast_exten *e = NULL, *eroot = NULL; struct ast_include *i = NULL; struct ast_sw *sw = NULL; struct ast_exten pattern = {NULL, }; struct scoreboard score = {0, }; struct ast_str *tmpdata = NULL; pattern.label = label; pattern.priority = priority; #ifdef NEED_DEBUG_HERE ast_log(LOG_NOTICE, "Looking for cont/ext/prio/label/action = %s/%s/%d/%s/%d\n", context, exten, priority, label, (int) action); #endif /* Initialize status if appropriate */ if (q->stacklen == 0) { q->status = STATUS_NO_CONTEXT; q->swo = NULL; q->data = NULL; q->foundcontext = NULL; } else if (q->stacklen >= AST_PBX_MAX_STACK) { ast_log(LOG_WARNING, "Maximum PBX stack exceeded\n"); return NULL; } /* Check first to see if we've already been checked */ for (x = 0; x < q->stacklen; x++) { if (!strcasecmp(q->incstack[x], context)) return NULL; } if (bypass) { /* bypass means we only look there */ tmp = bypass; } else { /* look in contexts */ struct fake_context item; ast_copy_string(item.name, context, sizeof(item.name)); tmp = ast_hashtab_lookup(contexts_table, &item); #ifdef NOTNOW tmp = NULL; while ((tmp = ast_walk_contexts(tmp)) ) { if (!strcmp(tmp->name, context)) { break; } } #endif if (!tmp) { return NULL; } } if (q->status < STATUS_NO_EXTENSION) q->status = STATUS_NO_EXTENSION; /* Do a search for matching extension */ eroot = NULL; score.total_specificity = 0; score.exten = 0; score.total_length = 0; if (!tmp->pattern_tree && tmp->root_table) { create_match_char_tree(tmp); #ifdef NEED_DEBUG ast_log(LOG_DEBUG, "Tree Created in context %s:\n", context); log_match_char_tree(tmp->pattern_tree," "); #endif } #ifdef NEED_DEBUG ast_log(LOG_NOTICE, "The Trie we are searching in:\n"); log_match_char_tree(tmp->pattern_tree, ":: "); #endif do { if (!ast_strlen_zero(overrideswitch)) { char *osw = ast_strdupa(overrideswitch), *name; struct ast_switch *asw; ast_switch_f *aswf = NULL; char *datap; int eval = 0; name = strsep(&osw, "/"); asw = pbx_findswitch(name); if (!asw) { ast_log(LOG_WARNING, "No such switch '%s'\n", name); break; } if (osw && strchr(osw, '$')) { eval = 1; } if (eval && !(tmpdata = ast_str_thread_get(&switch_data, 512))) { ast_log(LOG_WARNING, "Can't evaluate overrideswitch?!"); break; } else if (eval) { /* Substitute variables now */ pbx_substitute_variables_helper(chan, osw, ast_str_buffer(tmpdata), ast_str_size(tmpdata)); datap = ast_str_buffer(tmpdata); } else { datap = osw; } /* equivalent of extension_match_core() at the switch level */ if (action == E_CANMATCH) aswf = asw->canmatch; else if (action == E_MATCHMORE) aswf = asw->matchmore; else /* action == E_MATCH */ aswf = asw->exists; if (!aswf) { res = 0; } else { if (chan) { ast_autoservice_start(chan); } res = aswf(chan, context, exten, priority, callerid, datap); if (chan) { ast_autoservice_stop(chan); } } if (res) { /* Got a match */ q->swo = asw; q->data = datap; q->foundcontext = context; /* XXX keep status = STATUS_NO_CONTEXT ? */ return NULL; } } } while (0); if (extenpatternmatchnew) { new_find_extension(exten, &score, tmp->pattern_tree, 0, 0, callerid, label, action); eroot = score.exten; if (score.last_char == '!' && action == E_MATCHMORE) { /* We match an extension ending in '!'. * The decision in this case is final and is NULL (no match). */ #ifdef NEED_DEBUG_HERE ast_log(LOG_NOTICE,"Returning MATCHMORE NULL with exclamation point.\n"); #endif return NULL; } if (!eroot && (action == E_CANMATCH || action == E_MATCHMORE) && score.canmatch_exten) { q->status = STATUS_SUCCESS; #ifdef NEED_DEBUG_HERE ast_log(LOG_NOTICE,"Returning CANMATCH exten %s\n", score.canmatch_exten->exten); #endif return score.canmatch_exten; } if ((action == E_MATCHMORE || action == E_CANMATCH) && eroot) { if (score.node) { struct ast_exten *z = trie_find_next_match(score.node); if (z) { #ifdef NEED_DEBUG_HERE ast_log(LOG_NOTICE,"Returning CANMATCH/MATCHMORE next_match exten %s\n", z->exten); #endif } else { if (score.canmatch_exten) { #ifdef NEED_DEBUG_HERE ast_log(LOG_NOTICE,"Returning CANMATCH/MATCHMORE canmatchmatch exten %s(%p)\n", score.canmatch_exten->exten, score.canmatch_exten); #endif return score.canmatch_exten; } else { #ifdef NEED_DEBUG_HERE ast_log(LOG_NOTICE,"Returning CANMATCH/MATCHMORE next_match exten NULL\n"); #endif } } return z; } #ifdef NEED_DEBUG_HERE ast_log(LOG_NOTICE, "Returning CANMATCH/MATCHMORE NULL (no next_match)\n"); #endif return NULL; /* according to the code, complete matches are null matches in MATCHMORE mode */ } if (eroot) { /* found entry, now look for the right priority */ if (q->status < STATUS_NO_PRIORITY) q->status = STATUS_NO_PRIORITY; e = NULL; if (action == E_FINDLABEL && label ) { if (q->status < STATUS_NO_LABEL) q->status = STATUS_NO_LABEL; e = ast_hashtab_lookup(eroot->peer_label_table, &pattern); } else { e = ast_hashtab_lookup(eroot->peer_table, &pattern); } if (e) { /* found a valid match */ q->status = STATUS_SUCCESS; q->foundcontext = context; #ifdef NEED_DEBUG_HERE ast_log(LOG_NOTICE,"Returning complete match of exten %s\n", e->exten); #endif return e; } } } else { /* the old/current default exten pattern match algorithm */ /* scan the list trying to match extension and CID */ eroot = NULL; while ( (eroot = ast_walk_context_extensions(tmp, eroot)) ) { int match = extension_match_core(eroot->exten, exten, action); /* 0 on fail, 1 on match, 2 on earlymatch */ if (!match || (eroot->matchcid && !matchcid(eroot->cidmatch, callerid))) continue; /* keep trying */ if (match == 2 && action == E_MATCHMORE) { /* We match an extension ending in '!'. * The decision in this case is final and is NULL (no match). */ return NULL; } /* found entry, now look for the right priority */ if (q->status < STATUS_NO_PRIORITY) q->status = STATUS_NO_PRIORITY; e = NULL; if (action == E_FINDLABEL && label ) { if (q->status < STATUS_NO_LABEL) q->status = STATUS_NO_LABEL; e = ast_hashtab_lookup(eroot->peer_label_table, &pattern); } else { e = ast_hashtab_lookup(eroot->peer_table, &pattern); } #ifdef NOTNOW while ( (e = ast_walk_extension_priorities(eroot, e)) ) { /* Match label or priority */ if (action == E_FINDLABEL) { if (q->status < STATUS_NO_LABEL) q->status = STATUS_NO_LABEL; if (label && e->label && !strcmp(label, e->label)) break; /* found it */ } else if (e->priority == priority) { break; /* found it */ } /* else keep searching */ } #endif if (e) { /* found a valid match */ q->status = STATUS_SUCCESS; q->foundcontext = context; return e; } } } /* Check alternative switches */ AST_LIST_TRAVERSE(&tmp->alts, sw, list) { struct ast_switch *asw = pbx_findswitch(sw->name); ast_switch_f *aswf = NULL; char *datap; if (!asw) { ast_log(LOG_WARNING, "No such switch '%s'\n", sw->name); continue; } /* Substitute variables now */ if (sw->eval) { if (!(tmpdata = ast_str_thread_get(&switch_data, 512))) { ast_log(LOG_WARNING, "Can't evaluate switch?!"); continue; } pbx_substitute_variables_helper(chan, sw->data, ast_str_buffer(tmpdata), ast_str_size(tmpdata)); } /* equivalent of extension_match_core() at the switch level */ if (action == E_CANMATCH) aswf = asw->canmatch; else if (action == E_MATCHMORE) aswf = asw->matchmore; else /* action == E_MATCH */ aswf = asw->exists; datap = sw->eval ? ast_str_buffer(tmpdata) : sw->data; if (!aswf) res = 0; else { if (chan) ast_autoservice_start(chan); res = aswf(chan, context, exten, priority, callerid, datap); if (chan) ast_autoservice_stop(chan); } if (res) { /* Got a match */ q->swo = asw; q->data = datap; q->foundcontext = context; /* XXX keep status = STATUS_NO_CONTEXT ? */ return NULL; } } q->incstack[q->stacklen++] = tmp->name; /* Setup the stack */ /* Now try any includes we have in this context */ for (i = tmp->includes; i; i = i->next) { if (include_valid(i)) { if ((e = pbx_find_extension(chan, bypass, q, i->rname, exten, priority, label, callerid, action))) { #ifdef NEED_DEBUG_HERE ast_log(LOG_NOTICE,"Returning recursive match of %s\n", e->exten); #endif return e; } if (q->swo) return NULL; } } return NULL; }
struct ast_app* pbx_findapp | ( | const char * | app | ) | [read] |
Look up an application.
app | name of the app |
This function searches for the ast_app structure within the apps that are registered for the one with the name you passed in.
Definition at line 1374 of file pbx.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, and AST_RWLIST_UNLOCK.
Referenced by answer_exec_run(), 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(), handle_gosub(), iax2_exec(), lua_pbx_exec(), page_exec(), pbx_builtin_execiftime(), pbx_extension_helper(), realtime_exec(), try_calling(), and tryexec_exec().
{ struct ast_app *tmp; AST_RWLIST_RDLOCK(&apps); AST_RWLIST_TRAVERSE(&apps, tmp, list) { if (!strcasecmp(tmp->name, app)) break; } AST_RWLIST_UNLOCK(&apps); return tmp; }
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.
Retrieve the value of a builtin variable or variable from the channel variable stack.
Definition at line 2882 of file pbx.c.
References ARRAY_LEN, ast_channel_lock, ast_channel_unlock, ast_config_AST_SYSTEM_NAME, ast_copy_string(), ast_eid_default, ast_eid_to_str(), ast_get_hint(), AST_LIST_TRAVERSE, ast_rwlock_rdlock(), ast_rwlock_unlock(), ast_strdupa, ast_var_name(), ast_var_value(), ast_channel::cid, ast_callerid::cid_ani2, ast_callerid::cid_pres, ast_callerid::cid_tns, ast_callerid::cid_ton, ast_channel::context, ast_var_t::entries, ast_channel::exten, globals, globalslock, ast_channel::hangupcause, ast_channel::name, parse_variable_name(), ast_channel::priority, s, substring(), ast_channel::uniqueid, and ast_channel::varshead.
Referenced by action_getvar(), action_status(), handle_getvariable(), lua_get_variable(), lua_get_variable_value(), and pbx_substitute_variables_helper_full().
{ const char not_found = '\0'; char *tmpvar; const char *s; /* the result */ int offset, length; int i, need_substring; struct varshead *places[2] = { headp, &globals }; /* list of places where we may look */ if (c) { ast_channel_lock(c); places[0] = &c->varshead; } /* * Make a copy of var because parse_variable_name() modifies the string. * Then if called directly, we might need to run substring() on the result; * remember this for later in 'need_substring', 'offset' and 'length' */ tmpvar = ast_strdupa(var); /* parse_variable_name modifies the string */ need_substring = parse_variable_name(tmpvar, &offset, &length, &i /* ignored */); /* * Look first into predefined variables, then into variable lists. * Variable 's' points to the result, according to the following rules: * s == ¬_found (set at the beginning) means that we did not find a * matching variable and need to look into more places. * If s != ¬_found, s is a valid result string as follows: * s = NULL if the variable does not have a value; * you typically do this when looking for an unset predefined variable. * s = workspace if the result has been assembled there; * typically done when the result is built e.g. with an snprintf(), * so we don't need to do an additional copy. * s != workspace in case we have a string, that needs to be copied * (the ast_copy_string is done once for all at the end). * Typically done when the result is already available in some string. */ s = ¬_found; /* default value */ if (c) { /* This group requires a valid channel */ /* Names with common parts are looked up a piece at a time using strncmp. */ if (!strncmp(var, "CALL", 4)) { if (!strncmp(var + 4, "ING", 3)) { if (!strcmp(var + 7, "PRES")) { /* CALLINGPRES */ snprintf(workspace, workspacelen, "%d", c->cid.cid_pres); s = workspace; } else if (!strcmp(var + 7, "ANI2")) { /* CALLINGANI2 */ snprintf(workspace, workspacelen, "%d", c->cid.cid_ani2); s = workspace; } else if (!strcmp(var + 7, "TON")) { /* CALLINGTON */ snprintf(workspace, workspacelen, "%d", c->cid.cid_ton); s = workspace; } else if (!strcmp(var + 7, "TNS")) { /* CALLINGTNS */ snprintf(workspace, workspacelen, "%d", c->cid.cid_tns); s = workspace; } } } else if (!strcmp(var, "HINT")) { s = ast_get_hint(workspace, workspacelen, NULL, 0, c, c->context, c->exten) ? workspace : NULL; } else if (!strcmp(var, "HINTNAME")) { s = ast_get_hint(NULL, 0, workspace, workspacelen, c, c->context, c->exten) ? workspace : NULL; } else if (!strcmp(var, "EXTEN")) { s = c->exten; } else if (!strcmp(var, "CONTEXT")) { s = c->context; } else if (!strcmp(var, "PRIORITY")) { snprintf(workspace, workspacelen, "%d", c->priority); s = workspace; } else if (!strcmp(var, "CHANNEL")) { s = c->name; } else if (!strcmp(var, "UNIQUEID")) { s = c->uniqueid; } else if (!strcmp(var, "HANGUPCAUSE")) { snprintf(workspace, workspacelen, "%d", c->hangupcause); s = workspace; } } if (s == ¬_found) { /* look for more */ if (!strcmp(var, "EPOCH")) { snprintf(workspace, workspacelen, "%u",(int)time(NULL)); s = workspace; } else if (!strcmp(var, "SYSTEMNAME")) { s = ast_config_AST_SYSTEM_NAME; } else if (!strcmp(var, "ENTITYID")) { ast_eid_to_str(workspace, workspacelen, &ast_eid_default); s = workspace; } } /* if not found, look into chanvars or global vars */ for (i = 0; s == ¬_found && i < ARRAY_LEN(places); i++) { struct ast_var_t *variables; if (!places[i]) continue; if (places[i] == &globals) ast_rwlock_rdlock(&globalslock); AST_LIST_TRAVERSE(places[i], variables, entries) { if (!strcasecmp(ast_var_name(variables), var)) { s = ast_var_value(variables); break; } } if (places[i] == &globals) ast_rwlock_unlock(&globalslock); } if (s == ¬_found || s == NULL) *ret = NULL; else { if (s != workspace) ast_copy_string(workspace, s, workspacelen); *ret = workspace; if (need_substring) *ret = substring(*ret, offset, length, workspace, workspacelen); } if (c) ast_channel_unlock(c); }
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 4669 of file pbx.c.
References autofallthrough.
Referenced by pbx_load_module().
{ int oldval = autofallthrough; autofallthrough = newval; return oldval; }
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 4676 of file pbx.c.
References extenpatternmatchnew.
Referenced by handle_set_extenpatternmatchnew(), handle_unset_extenpatternmatchnew(), and pbx_load_module().
{ int oldval = extenpatternmatchnew; extenpatternmatchnew = newval; return oldval; }
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.
Definition at line 4683 of file pbx.c.
References ast_free, ast_strdup, ast_strlen_zero(), and overrideswitch.
Referenced by pbx_load_module().
{ if (overrideswitch) { ast_free(overrideswitch); } if (!ast_strlen_zero(newval)) { overrideswitch = ast_strdup(newval); } else { overrideswitch = NULL; } }
void pbx_substitute_variables_helper | ( | struct ast_channel * | c, |
const char * | cp1, | ||
char * | cp2, | ||
int | count | ||
) |
Definition at line 3613 of file pbx.c.
References pbx_substitute_variables_helper_full(), and ast_channel::varshead.
Referenced by _macro_exec(), acf_import(), add_extensions(), ast_add_extension2_lockopt(), config_curl(), custom_log(), cut_internal(), destroy_curl(), exec_exec(), function_eval(), function_fieldqty(), get_mapping_weight(), handle_getvariablefull(), launch_monitor_thread(), make_email_file(), manager_log(), pbx_builtin_importvar(), pbx_find_extension(), pbx_load_config(), pbx_substitute_variables(), realtime_curl(), realtime_exec(), realtime_multi_curl(), require_curl(), rotate_file(), rpt_do_lstats(), rpt_exec(), sendmail(), sendpage(), store_curl(), substituted(), try_calling(), tryexec_exec(), update2_curl(), update_curl(), and write_cdr().
{ size_t used; pbx_substitute_variables_helper_full(c, (c) ? &c->varshead : NULL, cp1, cp2, count, &used); }
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 3418 of file pbx.c.
References ast_channel_alloc(), ast_channel_free(), ast_copy_string(), ast_debug, 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 ast_str_substitute_variables(), pbx_substitute_variables_helper(), pbx_substitute_variables_helper_full(), and pbx_substitute_variables_varshead().
{ /* Substitutes variables into cp2, based on string cp1, cp2 NO LONGER NEEDS TO BE ZEROED OUT!!!! */ char *cp4; const char *tmp, *whereweare, *orig_cp2 = cp2; int length, offset, offset2, isfunction; char *workspace = NULL; char *ltmp = NULL, *var = NULL; char *nextvar, *nextexp, *nextthing; char *vars, *vare; int pos, brackets, needsub, len; *cp2 = 0; /* just in case nothing ends up there */ whereweare=tmp=cp1; while (!ast_strlen_zero(whereweare) && count) { /* Assume we're copying the whole remaining string */ pos = strlen(whereweare); nextvar = NULL; nextexp = NULL; nextthing = strchr(whereweare, '$'); if (nextthing) { switch (nextthing[1]) { case '{': nextvar = nextthing; pos = nextvar - whereweare; break; case '[': nextexp = nextthing; pos = nextexp - whereweare; break; default: pos = 1; } } if (pos) { /* Can't copy more than 'count' bytes */ if (pos > count) pos = count; /* Copy that many bytes */ memcpy(cp2, whereweare, pos); count -= pos; cp2 += pos; whereweare += pos; *cp2 = 0; } if (nextvar) { /* We have a variable. Find the start and end, and determine if we are going to have to recursively call ourselves on the contents */ vars = vare = nextvar + 2; brackets = 1; needsub = 0; /* Find the end of it */ while (brackets && *vare) { if ((vare[0] == '$') && (vare[1] == '{')) { needsub++; } else if (vare[0] == '{') { brackets++; } else if (vare[0] == '}') { brackets--; } else if ((vare[0] == '$') && (vare[1] == '[')) needsub++; vare++; } if (brackets) ast_log(LOG_WARNING, "Error in extension logic (missing '}')\n"); len = vare - vars - 1; /* Skip totally over variable string */ whereweare += (len + 3); if (!var) var = alloca(VAR_BUF_SIZE); /* Store variable name (and truncate) */ ast_copy_string(var, vars, len + 1); /* Substitute if necessary */ if (needsub) { size_t used; if (!ltmp) ltmp = alloca(VAR_BUF_SIZE); pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, &used); vars = ltmp; } else { vars = var; } if (!workspace) workspace = alloca(VAR_BUF_SIZE); workspace[0] = '\0'; parse_variable_name(vars, &offset, &offset2, &isfunction); if (isfunction) { /* Evaluate function */ if (c || !headp) cp4 = ast_func_read(c, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace; else { struct varshead old; struct ast_channel *bogus = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Bogus/%p", vars); if (bogus) { memcpy(&old, &bogus->varshead, sizeof(old)); memcpy(&bogus->varshead, headp, sizeof(bogus->varshead)); cp4 = ast_func_read(bogus, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace; /* Don't deallocate the varshead that was passed in */ memcpy(&bogus->varshead, &old, sizeof(bogus->varshead)); ast_channel_free(bogus); } else ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution. Function results may be blank.\n"); } ast_debug(2, "Function result is '%s'\n", cp4 ? cp4 : "(null)"); } else { /* Retrieve variable value */ pbx_retrieve_variable(c, vars, &cp4, workspace, VAR_BUF_SIZE, headp); } if (cp4) { cp4 = substring(cp4, offset, offset2, workspace, VAR_BUF_SIZE); length = strlen(cp4); if (length > count) length = count; memcpy(cp2, cp4, length); count -= length; cp2 += length; *cp2 = 0; } } else if (nextexp) { /* We have an expression. Find the start and end, and determine if we are going to have to recursively call ourselves on the contents */ vars = vare = nextexp + 2; brackets = 1; needsub = 0; /* Find the end of it */ while (brackets && *vare) { if ((vare[0] == '$') && (vare[1] == '[')) { needsub++; brackets++; vare++; } else if (vare[0] == '[') { brackets++; } else if (vare[0] == ']') { brackets--; } else if ((vare[0] == '$') && (vare[1] == '{')) { needsub++; vare++; } vare++; } if (brackets) ast_log(LOG_WARNING, "Error in extension logic (missing ']')\n"); len = vare - vars - 1; /* Skip totally over expression */ whereweare += (len + 3); if (!var) var = alloca(VAR_BUF_SIZE); /* Store variable name (and truncate) */ ast_copy_string(var, vars, len + 1); /* Substitute if necessary */ if (needsub) { size_t used; if (!ltmp) ltmp = alloca(VAR_BUF_SIZE); pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, &used); vars = ltmp; } else { vars = var; } length = ast_expr(vars, cp2, count, c); if (length) { ast_debug(1, "Expression result is '%s'\n", cp2); count -= length; cp2 += length; *cp2 = 0; } } } *used = cp2 - orig_cp2; }
void pbx_substitute_variables_varshead | ( | struct varshead * | headp, |
const char * | cp1, | ||
char * | cp2, | ||
int | count | ||
) |
Definition at line 3619 of file pbx.c.
References pbx_substitute_variables_helper_full().
Referenced by add_user_extension(), build_user_routes(), do_say(), dundi_lookup_local(), loopback_subst(), phoneprov_callback(), pp_each_extension_exec(), and pp_each_user_exec().
{ size_t used; pbx_substitute_variables_helper_full(NULL, headp, cp1, cp2, count, &used); }