#include "asterisk/channel.h"
#include "asterisk/sched.h"
#include "asterisk/devicestate.h"
#include "asterisk/chanvars.h"
#include "asterisk/hashtab.h"
#include "asterisk/stringfields.h"
#include "asterisk/xmldoc.h"
#include "asterisk/frame_defs.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_GOTO_FAILED -3 |
| #define | AST_PBX_KEEP 0 |
| #define | AST_PBX_MAX_STACK 128 |
| #define | AST_PBX_REPLACE 1 |
| #define | PRIORITY_HINT -1 |
| #define | STATUS_NO_CONTEXT 1 |
| #define | STATUS_NO_EXTENSION 2 |
| #define | STATUS_NO_LABEL 4 |
| #define | STATUS_NO_PRIORITY 3 |
| #define | STATUS_SUCCESS 5 |
| #define | AST_PBX_ERROR 1 |
| #define | AST_PBX_HANGUP -1 |
| Special return values from applications to the PBX. | |
| #define | AST_PBX_INCOMPLETE 12 |
| #define | AST_PBX_OK 0 |
Typedefs | |
| typedef 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_extension_states { AST_EXTENSION_REMOVED = -2, AST_EXTENSION_DEACTIVATED = -1, AST_EXTENSION_NOT_INUSE = 0, AST_EXTENSION_INUSE = 1 << 0, AST_EXTENSION_BUSY = 1 << 1, AST_EXTENSION_UNAVAILABLE = 1 << 2, AST_EXTENSION_RINGING = 1 << 3, AST_EXTENSION_ONHOLD = 1 << 4 } |
| Extension states. More... | |
| enum | ast_pbx_result { AST_PBX_SUCCESS = 0, AST_PBX_FAILED = -1, AST_PBX_CALL_LIMIT = -2 } |
| The result codes when starting the PBX on a channel with ast_pbx_start. More... | |
| enum | ext_match_t { E_MATCHMORE = 0x00, E_CANMATCH = 0x01, E_MATCH = 0x02, E_MATCH_MASK = 0x03, E_SPAWN = 0x12, E_FINDLABEL = 0x22, E_MATCHMORE = 0x00, E_CANMATCH = 0x01, E_MATCH = 0x02, E_MATCH_MASK = 0x03, E_SPAWN = 0x12, E_FINDLABEL = 0x22 } |
Functions | |
| int | __ast_custom_function_register (struct ast_custom_function *acf, struct ast_module *mod) |
| Register a custom function. | |
| 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_check_timing2 (const struct ast_timing *i, const struct timeval tv) |
| Evaluate a pre-constructed bitmap as to whether a particular time falls within the range specified. | |
| char * | ast_complete_applications (const char *line, const char *word, int state) |
| Command completion for the list of installed applications. | |
| int | ast_context_add_ignorepat (const char *context, const char *ignorepat, const char *registrar) |
| Add an ignorepat. | |
| int | ast_context_add_ignorepat2 (struct ast_context *con, const char *ignorepat, const char *registrar) |
| int | ast_context_add_include (const char *context, const char *include, const char *registrar) |
| Add a context include. | |
| int | ast_context_add_include2 (struct ast_context *con, const char *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_read2 (struct ast_channel *chan, const char *function, struct ast_str **str, ssize_t maxlen) |
| executes a read operation on a function | |
| int | ast_func_write (struct ast_channel *chan, const char *function, const char *value) |
| executes a write operation on a function | |
| 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, format_t format, void *data, int timeout, const char *app, const char *appdata, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel) |
| int | ast_pbx_outgoing_exten (const char *type, format_t format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int sync, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel) |
| enum ast_pbx_result | ast_pbx_run (struct ast_channel *c) |
| Execute the PBX in the current thread. | |
| enum ast_pbx_result | ast_pbx_run_args (struct ast_channel *c, struct ast_pbx_args *args) |
| Execute the PBX in the current thread. | |
| enum ast_pbx_result | ast_pbx_start (struct ast_channel *c) |
| Create a new thread and start the PBX. | |
| int | ast_processed_calls (void) |
| Retrieve the total number of calls processed through the PBX since last restart. | |
| int | ast_rdlock_context (struct ast_context *con) |
| Read locks a given context. | |
| int | ast_rdlock_contexts (void) |
| Read locks the context list. | |
| int | ast_register_switch (struct ast_switch *sw) |
| Register an alternative dialplan switch. | |
| int | ast_spawn_extension (struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid, int *found, int combined_find_spawn) |
| Launch a new extension (i.e. new stack). | |
| int | ast_str_get_hint (struct ast_str **hint, ssize_t hintsize, struct ast_str **name, ssize_t namesize, struct ast_channel *c, const char *context, const char *exten) |
| If an extension hint exists, return non-zero. | |
| int | ast_unlock_context (struct ast_context *con) |
| int | ast_unlock_contexts (void) |
| Unlocks contexts. | |
| void | ast_unregister_switch (struct ast_switch *sw) |
| Unregister an alternative switch. | |
| int | ast_wrlock_context (struct ast_context *con) |
| Write locks a given context. | |
| int | ast_wrlock_contexts (void) |
| Write locks the context list. | |
| void | pbx_builtin_clear_globals (void) |
| const char * | pbx_builtin_getvar_helper (struct ast_channel *chan, const char *name) |
| Return a pointer to the value of the corresponding channel variable. | |
| void | pbx_builtin_pushvar_helper (struct ast_channel *chan, const char *name, const char *value) |
| Add a variable to the channel variable stack, without removing any previously set value. | |
| int | pbx_builtin_raise_exception (struct ast_channel *chan, const char *data) |
| int | pbx_builtin_serialize_variables (struct ast_channel *chan, struct ast_str **buf) |
| Create a human-readable string, specifying all variables and their corresponding values. | |
| int | pbx_builtin_setvar (struct ast_channel *chan, const char *data) |
| Parse and set a single channel variable, where the name and value are separated with an '=' character. | |
| int | pbx_builtin_setvar_helper (struct ast_channel *chan, const char *name, const char *value) |
| Add a variable to the channel variable stack, removing the most recently set value for the same name. | |
| int | pbx_builtin_setvar_multiple (struct ast_channel *chan, const char *data) |
| Parse and set multiple channel variables, where the pairs are separated by the ',' character, and name and value are separated with an '=' character. | |
| int | pbx_checkcondition (const char *condition) |
| Evaluate a condition. | |
| int | pbx_exec (struct ast_channel *c, struct ast_app *app, const char *data) |
| Execute an application. | |
| struct ast_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) |
| const char * | ast_get_context_name (struct ast_context *con) |
| struct ast_context * | ast_get_extension_context (struct ast_exten *exten) |
| const char * | ast_get_extension_name (struct ast_exten *exten) |
| const char * | ast_get_ignorepat_name (struct ast_ignorepat *ip) |
| const char * | ast_get_include_name (struct ast_include *include) |
| const char * | ast_get_switch_data (struct ast_sw *sw) |
| int | ast_get_switch_eval (struct ast_sw *sw) |
| const char * | ast_get_switch_name (struct ast_sw *sw) |
Registrar info functions ... | |
| const char * | ast_get_context_registrar (struct ast_context *c) |
| const char * | ast_get_extension_registrar (struct ast_exten *e) |
| const char * | ast_get_ignorepat_registrar (struct ast_ignorepat *ip) |
| const char * | ast_get_include_registrar (struct ast_include *i) |
| const char * | ast_get_switch_registrar (struct ast_sw *sw) |
Other Extension stuff | |
| const char * | ast_get_extension_app (struct ast_exten *e) |
| void * | ast_get_extension_app_data (struct ast_exten *e) |
| const char * | ast_get_extension_cidmatch (struct ast_exten *e) |
| const char * | ast_get_extension_label (struct ast_exten *e) |
| int | ast_get_extension_matchcid (struct ast_exten *e) |
| int | ast_get_extension_priority (struct ast_exten *exten) |
| 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) |
Substitution routines, using dynamic string buffers | |
| const char * | ast_str_retrieve_variable (struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, struct varshead *headp, const char *var) |
| void | ast_str_substitute_variables (struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, const char *templ) |
| void | ast_str_substitute_variables_full (struct ast_str **buf, ssize_t maxlen, struct ast_channel *c, struct varshead *headp, const char *templ, size_t *used) |
| void | ast_str_substitute_variables_varshead (struct ast_str **buf, ssize_t maxlen, struct varshead *headp, const char *templ) |
Walking functions ... | |
| struct ast_exten * | ast_walk_context_extensions (struct ast_context *con, struct ast_exten *priority) |
| struct ast_ignorepat * | ast_walk_context_ignorepats (struct ast_context *con, struct ast_ignorepat *ip) |
| struct ast_include * | ast_walk_context_includes (struct ast_context *con, struct ast_include *inc) |
| struct ast_sw * | ast_walk_context_switches (struct ast_context *con, struct ast_sw *sw) |
| struct ast_context * | ast_walk_contexts (struct ast_context *con) |
| struct ast_exten * | ast_walk_extension_priorities (struct ast_exten *exten, struct ast_exten *priority) |
Substitution routines, using static string buffers | |
| void | pbx_substitute_variables_helper (struct ast_channel *c, const char *cp1, char *cp2, int count) |
| void | pbx_substitute_variables_helper_full (struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int cp2_size, size_t *used) |
| void | pbx_substitute_variables_varshead (struct varshead *headp, const char *cp1, char *cp2, int count) |
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 1118 of file pbx.h.
Referenced by load_module(), and reload().
| #define AST_MAX_APP 32 |
Max length of an application
Definition at line 39 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_GOTO_FAILED -3 |
| #define AST_PBX_HANGUP -1 |
| #define AST_PBX_INCOMPLETE 12 |
Return to PBX matching, allowing more digits for the extension
Definition at line 50 of file pbx.h.
Referenced by __ast_pbx_run(), dial_exec_full(), pbx_builtin_incomplete(), and retrydial_exec().
| #define PRIORITY_HINT -1 |
Special Priority for a hint
Definition at line 53 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_extension_states |
Extension states.
| AST_EXTENSION_REMOVED | Extension removed |
| AST_EXTENSION_DEACTIVATED | Extension hint removed |
| AST_EXTENSION_NOT_INUSE | No device INUSE or BUSY |
| AST_EXTENSION_INUSE | One or more devices INUSE |
| AST_EXTENSION_BUSY | All devices BUSY |
| AST_EXTENSION_UNAVAILABLE | All devices UNAVAILABLE/UNREGISTERED |
| AST_EXTENSION_RINGING | All devices RINGING |
| AST_EXTENSION_ONHOLD | All devices ONHOLD |
Definition at line 60 of file pbx.h.
00060 { 00061 AST_EXTENSION_REMOVED = -2, /*!< Extension removed */ 00062 AST_EXTENSION_DEACTIVATED = -1, /*!< Extension hint removed */ 00063 AST_EXTENSION_NOT_INUSE = 0, /*!< No device INUSE or BUSY */ 00064 AST_EXTENSION_INUSE = 1 << 0, /*!< One or more devices INUSE */ 00065 AST_EXTENSION_BUSY = 1 << 1, /*!< All devices BUSY */ 00066 AST_EXTENSION_UNAVAILABLE = 1 << 2, /*!< All devices UNAVAILABLE/UNREGISTERED */ 00067 AST_EXTENSION_RINGING = 1 << 3, /*!< All devices RINGING */ 00068 AST_EXTENSION_ONHOLD = 1 << 4, /*!< All devices ONHOLD */ 00069 };
| enum ast_pbx_result |
The result codes when starting the PBX on a channel with ast_pbx_start.
Definition at line 286 of file pbx.h.
00286 { 00287 AST_PBX_SUCCESS = 0, 00288 AST_PBX_FAILED = -1, 00289 AST_PBX_CALL_LIMIT = -2, 00290 };
| enum ext_match_t |
When looking up extensions, we can have different requests identified by the 'action' argument, as follows.
| 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 1187 of file pbx.h.
01187 { 01188 E_MATCHMORE = 0x00, /* extension can match but only with more 'digits' */ 01189 E_CANMATCH = 0x01, /* extension can match with or without more 'digits' */ 01190 E_MATCH = 0x02, /* extension is an exact match */ 01191 E_MATCH_MASK = 0x03, /* mask for the argument to extension_match_core() */ 01192 E_SPAWN = 0x12, /* want to spawn an extension. Requires exact match */ 01193 E_FINDLABEL = 0x22 /* returns the priority for a given label. Requires exact match */ 01194 };
| int __ast_custom_function_register | ( | struct ast_custom_function * | acf, | |
| struct ast_module * | mod | |||
| ) |
Register a custom function.
Definition at line 3406 of file pbx.c.
References acf_retrieve_docs(), ast_custom_function::acflist, 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().
03407 { 03408 struct ast_custom_function *cur; 03409 char tmps[80]; 03410 03411 if (!acf) { 03412 return -1; 03413 } 03414 03415 acf->mod = mod; 03416 #ifdef AST_XML_DOCS 03417 acf->docsrc = AST_STATIC_DOC; 03418 #endif 03419 03420 if (acf_retrieve_docs(acf)) { 03421 return -1; 03422 } 03423 03424 AST_RWLIST_WRLOCK(&acf_root); 03425 03426 AST_RWLIST_TRAVERSE(&acf_root, cur, acflist) { 03427 if (!strcmp(acf->name, cur->name)) { 03428 ast_log(LOG_ERROR, "Function %s already registered.\n", acf->name); 03429 AST_RWLIST_UNLOCK(&acf_root); 03430 return -1; 03431 } 03432 } 03433 03434 /* Store in alphabetical order */ 03435 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&acf_root, cur, acflist) { 03436 if (strcasecmp(acf->name, cur->name) < 0) { 03437 AST_RWLIST_INSERT_BEFORE_CURRENT(acf, acflist); 03438 break; 03439 } 03440 } 03441 AST_RWLIST_TRAVERSE_SAFE_END; 03442 03443 if (!cur) { 03444 AST_RWLIST_INSERT_TAIL(&acf_root, acf, acflist); 03445 } 03446 03447 AST_RWLIST_UNLOCK(&acf_root); 03448 03449 ast_verb(2, "Registered custom function '%s'\n", term_color(tmps, acf->name, COLOR_BRCYAN, 0, sizeof(tmps))); 03450 03451 return 0; 03452 }
| int ast_active_calls | ( | void | ) |
Retrieve the number of active calls.
Definition at line 5036 of file pbx.c.
References countcalls.
Referenced by ast_var_Config(), handle_chanlist(), handle_showcalls(), and sysinfo_helper().
05037 { 05038 return countcalls; 05039 }
| 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 7687 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().
07690 { 07691 int ret = -1; 07692 struct ast_context *c = find_context_locked(context); 07693 07694 if (c) { 07695 ret = ast_add_extension2(c, replace, extension, priority, label, callerid, 07696 application, data, datad, registrar); 07697 ast_unlock_contexts(); 07698 } 07699 07700 return ret; 07701 }
| 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 *.
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 8008 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().
08012 { 08013 return ast_add_extension2_lockopt(con, replace, extension, priority, label, callerid, application, data, datad, registrar, 1, 1); 08014 }
| 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 7726 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, ast_channel::linkedid, 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_dtmfup(), handle_request_bye(), handle_request_refer(), my_handle_dtmfup(), pbx_parseable_goto(), process_ast_dsp(), process_sdp(), sip_read(), and socket_process().
07727 { 07728 int res = 0; 07729 07730 ast_channel_lock(chan); 07731 07732 if (chan->pbx) { /* This channel is currently in the PBX */ 07733 ast_explicit_goto(chan, context, exten, priority + 1); 07734 ast_softhangup_nolock(chan, AST_SOFTHANGUP_ASYNCGOTO); 07735 } else { 07736 /* In order to do it when the channel doesn't really exist within 07737 the PBX, we have to make a new channel, masquerade, and start the PBX 07738 at the new location */ 07739 struct ast_channel *tmpchan = ast_channel_alloc(0, chan->_state, 0, 0, chan->accountcode, chan->exten, chan->context, chan->linkedid, chan->amaflags, "AsyncGoto/%s", chan->name); 07740 if (!tmpchan) { 07741 res = -1; 07742 } else { 07743 if (chan->cdr) { 07744 ast_cdr_discard(tmpchan->cdr); 07745 tmpchan->cdr = ast_cdr_dup(chan->cdr); /* share the love */ 07746 } 07747 /* Make formats okay */ 07748 tmpchan->readformat = chan->readformat; 07749 tmpchan->writeformat = chan->writeformat; 07750 /* Setup proper location */ 07751 ast_explicit_goto(tmpchan, 07752 S_OR(context, chan->context), S_OR(exten, chan->exten), priority); 07753 07754 /* Masquerade into temp channel */ 07755 if (ast_channel_masquerade(tmpchan, chan)) { 07756 /* Failed to set up the masquerade. It's probably chan_local 07757 * in the middle of optimizing itself out. Sad. :( */ 07758 ast_hangup(tmpchan); 07759 tmpchan = NULL; 07760 res = -1; 07761 } else { 07762 /* it may appear odd to unlock chan here since the masquerade is on 07763 * tmpchan, but no channel locks should be held when doing a masquerade 07764 * since a masquerade requires a lock on the channels ao2 container. */ 07765 ast_channel_unlock(chan); 07766 ast_do_masquerade(tmpchan); 07767 ast_channel_lock(chan); 07768 /* Start the PBX going on our stolen channel */ 07769 if (ast_pbx_start(tmpchan)) { 07770 ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmpchan->name); 07771 ast_hangup(tmpchan); 07772 res = -1; 07773 } 07774 } 07775 } 07776 } 07777 ast_channel_unlock(chan); 07778 return res; 07779 }
| 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 7781 of file pbx.c.
References ast_async_goto(), ast_channel_get_by_name(), and ast_channel_unref.
07782 { 07783 struct ast_channel *chan; 07784 int res = -1; 07785 07786 if ((chan = ast_channel_get_by_name(channame))) { 07787 res = ast_async_goto(chan, context, exten, priority); 07788 chan = ast_channel_unref(chan); 07789 } 07790 07791 return res; 07792 }
| int ast_async_goto_if_exists | ( | struct ast_channel * | chan, | |
| const char * | context, | |||
| const char * | exten, | |||
| int | priority | |||
| ) |
Definition at line 10084 of file pbx.c.
References __ast_goto_if_exists().
10085 { 10086 return __ast_goto_if_exists(chan, context, exten, priority, 1); 10087 }
| int ast_async_parseable_goto | ( | struct ast_channel * | chan, | |
| const char * | goto_string | |||
| ) |
Definition at line 10149 of file pbx.c.
References pbx_parseable_goto().
Referenced by asyncgoto_exec(), and handle_redirect().
10150 { 10151 return pbx_parseable_goto(chan, goto_string, 1); 10152 }
| 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 7317 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().
07318 { 07319 char *info_save, *info; 07320 int j, num_fields, last_sep = -1; 07321 07322 /* Check for empty just in case */ 07323 if (ast_strlen_zero(info_in)) { 07324 return 0; 07325 } 07326 07327 /* make a copy just in case we were passed a static string */ 07328 info_save = info = ast_strdupa(info_in); 07329 07330 /* count the number of fields in the timespec */ 07331 for (j = 0, num_fields = 1; info[j] != '\0'; j++) { 07332 if (info[j] == ',') { 07333 last_sep = j; 07334 num_fields++; 07335 } 07336 } 07337 07338 /* save the timezone, if it is specified */ 07339 if (num_fields == 5) { 07340 i->timezone = ast_strdup(info + last_sep + 1); 07341 } else { 07342 i->timezone = NULL; 07343 } 07344 07345 /* Assume everything except time */ 07346 i->monthmask = 0xfff; /* 12 bits */ 07347 i->daymask = 0x7fffffffU; /* 31 bits */ 07348 i->dowmask = 0x7f; /* 7 bits */ 07349 /* on each call, use strsep() to move info to the next argument */ 07350 get_timerange(i, strsep(&info, "|,")); 07351 if (info) 07352 i->dowmask = get_range(strsep(&info, "|,"), 7, days, "day of week"); 07353 if (info) 07354 i->daymask = get_range(strsep(&info, "|,"), 31, NULL, "day"); 07355 if (info) 07356 i->monthmask = get_range(strsep(&info, "|,"), 12, months, "month"); 07357 return 1; 07358 }
| 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 4565 of file pbx.c.
References E_CANMATCH, and pbx_extension_helper().
Referenced by __analog_ss_thread(), analog_ss_thread(), background_detect_exec(), cb_events(), do_immediate_setup(), dp_lookup(), dundi_lookup_local(), get_also_info(), get_destination(), handle_link_data(), handle_link_phone_dtmf(), leave_voicemail(), local_dtmf_helper(), loopback_canmatch(), mgcp_ss(), pbx_builtin_background(), phone_check_exception(), pri_dchannel(), skinny_ss(), and valid_exit().
04566 { 04567 return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_CANMATCH, 0, 0); 04568 }
| 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 7360 of file pbx.c.
References ast_check_timing2(), and ast_tvnow().
Referenced by iftime(), include_valid(), and pbx_builtin_execiftime().
07361 { 07362 return ast_check_timing2(i, ast_tvnow()); 07363 }
| int ast_check_timing2 | ( | const struct ast_timing * | i, | |
| const struct timeval | tv | |||
| ) |
Evaluate a pre-constructed bitmap as to whether a particular time falls within the range specified.
| i | Pointer to an ast_timing structure. | |
| tv | Specified time |
| Returns | 1, if the time matches or 0, if the time falls outside of the specified range. |
Definition at line 7365 of file pbx.c.
References ast_localtime(), ast_log(), ast_timing::daymask, ast_timing::dowmask, LOG_WARNING, ast_timing::minmask, ast_timing::monthmask, ast_timing::timezone, ast_tm::tm_hour, ast_tm::tm_mday, ast_tm::tm_min, ast_tm::tm_mon, and ast_tm::tm_wday.
Referenced by ast_check_timing(), and pbx_builtin_gotoiftime().
07366 { 07367 struct ast_tm tm; 07368 07369 ast_localtime(&tv, &tm, i->timezone); 07370 07371 /* If it's not the right month, return */ 07372 if (!(i->monthmask & (1 << tm.tm_mon))) 07373 return 0; 07374 07375 /* If it's not that time of the month.... */ 07376 /* Warning, tm_mday has range 1..31! */ 07377 if (!(i->daymask & (1 << (tm.tm_mday-1)))) 07378 return 0; 07379 07380 /* If it's not the right day of the week */ 07381 if (!(i->dowmask & (1 << tm.tm_wday))) 07382 return 0; 07383 07384 /* Sanity check the hour just to be safe */ 07385 if ((tm.tm_hour < 0) || (tm.tm_hour > 23)) { 07386 ast_log(LOG_WARNING, "Insane time...\n"); 07387 return 0; 07388 } 07389 07390 /* Now the tough part, we calculate if it fits 07391 in the right time based on min/hour */ 07392 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)))) 07393 return 0; 07394 07395 /* If we got this far, then we're good */ 07396 return 1; 07397 }
| char* ast_complete_applications | ( | const char * | line, | |
| const char * | word, | |||
| int | state | |||
| ) |
Command completion for the list of installed applications.
This can be called from a CLI command completion function that wants to complete from the list of available applications.
Definition at line 10154 of file pbx.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, and ast_app::name.
Referenced by handle_orig(), and handle_show_application().
10155 { 10156 struct ast_app *app = NULL; 10157 int which = 0; 10158 char *ret = NULL; 10159 size_t wordlen = strlen(word); 10160 10161 AST_RWLIST_RDLOCK(&apps); 10162 AST_RWLIST_TRAVERSE(&apps, app, list) { 10163 if (!strncasecmp(word, app->name, wordlen) && ++which > state) { 10164 ret = ast_strdup(app->name); 10165 break; 10166 } 10167 } 10168 AST_RWLIST_UNLOCK(&apps); 10169 10170 return ret; 10171 }
| 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 |
| 0 | on success | |
| -1 | on failure |
Definition at line 7599 of file pbx.c.
References ast_context_add_ignorepat2(), ast_unlock_contexts(), and find_context_locked().
Referenced by handle_cli_dialplan_add_ignorepat().
07600 { 07601 int ret = -1; 07602 struct ast_context *c = find_context_locked(context); 07603 07604 if (c) { 07605 ret = ast_context_add_ignorepat2(c, value, registrar); 07606 ast_unlock_contexts(); 07607 } 07608 return ret; 07609 }
| int ast_context_add_ignorepat2 | ( | struct ast_context * | con, | |
| const char * | ignorepat, | |||
| const char * | registrar | |||
| ) |
Definition at line 7611 of file pbx.c.
References ast_calloc, ast_unlock_context(), ast_wrlock_context(), errno, ast_context::ignorepats, ast_ignorepat::next, ast_ignorepat::pattern, and ast_ignorepat::registrar.
Referenced by ast_compile_ael2(), ast_context_add_ignorepat(), context_merge_incls_swits_igps_other_registrars(), and pbx_load_config().
07612 { 07613 struct ast_ignorepat *ignorepat, *ignorepatc, *ignorepatl = NULL; 07614 int length; 07615 char *pattern; 07616 length = sizeof(struct ast_ignorepat); 07617 length += strlen(value) + 1; 07618 if (!(ignorepat = ast_calloc(1, length))) 07619 return -1; 07620 /* The cast to char * is because we need to write the initial value. 07621 * The field is not supposed to be modified otherwise. Also, gcc 4.2 07622 * sees the cast as dereferencing a type-punned pointer and warns about 07623 * it. This is the workaround (we're telling gcc, yes, that's really 07624 * what we wanted to do). 07625 */ 07626 pattern = (char *) ignorepat->pattern; 07627 strcpy(pattern, value); 07628 ignorepat->next = NULL; 07629 ignorepat->registrar = registrar; 07630 ast_wrlock_context(con); 07631 for (ignorepatc = con->ignorepats; ignorepatc; ignorepatc = ignorepatc->next) { 07632 ignorepatl = ignorepatc; 07633 if (!strcasecmp(ignorepatc->pattern, value)) { 07634 /* Already there */ 07635 ast_unlock_context(con); 07636 errno = EEXIST; 07637 return -1; 07638 } 07639 } 07640 if (ignorepatl) 07641 ignorepatl->next = ignorepat; 07642 else 07643 con->ignorepats = ignorepat; 07644 ast_unlock_context(con); 07645 return 0; 07646 07647 }
| 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 |
| 0 | on success | |
| -1 | on error |
Definition at line 7146 of file pbx.c.
References ast_context_add_include2(), ast_unlock_contexts(), and find_context_locked().
Referenced by handle_cli_dialplan_add_include().
07147 { 07148 int ret = -1; 07149 struct ast_context *c = find_context_locked(context); 07150 07151 if (c) { 07152 ret = ast_context_add_include2(c, include, registrar); 07153 ast_unlock_contexts(); 07154 } 07155 return ret; 07156 }
| 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 |
| 0 | on success | |
| -1 | on failure |
Definition at line 7414 of file pbx.c.
References ast_build_timing(), ast_calloc, ast_destroy_timing(), ast_free, ast_get_context_name(), ast_unlock_context(), ast_verb, ast_wrlock_context(), errno, ast_include::hastime, ast_context::includes, ast_include::name, ast_include::next, ast_include::registrar, ast_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().
07416 { 07417 struct ast_include *new_include; 07418 char *c; 07419 struct ast_include *i, *il = NULL; /* include, include_last */ 07420 int length; 07421 char *p; 07422 07423 length = sizeof(struct ast_include); 07424 length += 2 * (strlen(value) + 1); 07425 07426 /* allocate new include structure ... */ 07427 if (!(new_include = ast_calloc(1, length))) 07428 return -1; 07429 /* Fill in this structure. Use 'p' for assignments, as the fields 07430 * in the structure are 'const char *' 07431 */ 07432 p = new_include->stuff; 07433 new_include->name = p; 07434 strcpy(p, value); 07435 p += strlen(value) + 1; 07436 new_include->rname = p; 07437 strcpy(p, value); 07438 /* Strip off timing info, and process if it is there */ 07439 if ( (c = strchr(p, ',')) ) { 07440 *c++ = '\0'; 07441 new_include->hastime = ast_build_timing(&(new_include->timing), c); 07442 } 07443 new_include->next = NULL; 07444 new_include->registrar = registrar; 07445 07446 ast_wrlock_context(con); 07447 07448 /* ... go to last include and check if context is already included too... */ 07449 for (i = con->includes; i; i = i->next) { 07450 if (!strcasecmp(i->name, new_include->name)) { 07451 ast_destroy_timing(&(new_include->timing)); 07452 ast_free(new_include); 07453 ast_unlock_context(con); 07454 errno = EEXIST; 07455 return -1; 07456 } 07457 il = i; 07458 } 07459 07460 /* ... include new context into context list, unlock, return */ 07461 if (il) 07462 il->next = new_include; 07463 else 07464 con->includes = new_include; 07465 ast_verb(3, "Including context '%s' in context '%s'\n", new_include->name, ast_get_context_name(con)); 07466 07467 ast_unlock_context(con); 07468 07469 return 0; 07470 }
| 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 |
| 0 | on success | |
| -1 | on failure |
Definition at line 7477 of file pbx.c.
References ast_context_add_switch2(), ast_unlock_contexts(), and find_context_locked().
07478 { 07479 int ret = -1; 07480 struct ast_context *c = find_context_locked(context); 07481 07482 if (c) { /* found, add switch to this context */ 07483 ret = ast_context_add_switch2(c, sw, data, eval, registrar); 07484 ast_unlock_contexts(); 07485 } 07486 return ret; 07487 }
| 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 7496 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().
07498 { 07499 struct ast_sw *new_sw; 07500 struct ast_sw *i; 07501 int length; 07502 char *p; 07503 07504 length = sizeof(struct ast_sw); 07505 length += strlen(value) + 1; 07506 if (data) 07507 length += strlen(data); 07508 length++; 07509 07510 /* allocate new sw structure ... */ 07511 if (!(new_sw = ast_calloc(1, length))) 07512 return -1; 07513 /* ... fill in this structure ... */ 07514 p = new_sw->stuff; 07515 new_sw->name = p; 07516 strcpy(new_sw->name, value); 07517 p += strlen(value) + 1; 07518 new_sw->data = p; 07519 if (data) { 07520 strcpy(new_sw->data, data); 07521 p += strlen(data) + 1; 07522 } else { 07523 strcpy(new_sw->data, ""); 07524 p++; 07525 } 07526 new_sw->eval = eval; 07527 new_sw->registrar = registrar; 07528 07529 /* ... try to lock this context ... */ 07530 ast_wrlock_context(con); 07531 07532 /* ... go to last sw and check if context is already swd too... */ 07533 AST_LIST_TRAVERSE(&con->alts, i, list) { 07534 if (!strcasecmp(i->name, new_sw->name) && !strcasecmp(i->data, new_sw->data)) { 07535 ast_free(new_sw); 07536 ast_unlock_context(con); 07537 errno = EEXIST; 07538 return -1; 07539 } 07540 } 07541 07542 /* ... sw new context into context list, unlock, return */ 07543 AST_LIST_INSERT_TAIL(&con->alts, new_sw, list); 07544 07545 ast_verb(3, "Including switch '%s/%s' in context '%s'\n", new_sw->name, new_sw->data, ast_get_context_name(con)); 07546 07547 ast_unlock_context(con); 07548 07549 return 0; 07550 }
| 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 |
Definition at line 8820 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().
08821 { 08822 ast_wrlock_contexts(); 08823 __ast_context_destroy(contexts, contexts_table, con,registrar); 08824 ast_unlock_contexts(); 08825 }
| struct ast_context* ast_context_find | ( | const char * | name | ) | [read] |
Find a context.
| name | name of the context to find |
Definition at line 2504 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(), manage_parkinglot(), park_exec_full(), parkinglot_destroy(), register_exten(), register_peer_exten(), unload_module(), and unregister_exten().
02505 { 02506 struct ast_context *tmp = NULL; 02507 struct fake_context item; 02508 02509 ast_copy_string(item.name, name, sizeof(item.name)); 02510 02511 ast_rdlock_contexts(); 02512 if( contexts_table ) { 02513 tmp = ast_hashtab_lookup(contexts_table,&item); 02514 } else { 02515 while ( (tmp = ast_walk_contexts(tmp)) ) { 02516 if (!name || !strcasecmp(name, tmp->name)) { 02517 break; 02518 } 02519 } 02520 } 02521 ast_unlock_contexts(); 02522 return tmp; 02523 }
| 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 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 6812 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().
06813 { 06814 struct ast_context *tmp, **local_contexts; 06815 struct fake_context search; 06816 int length = sizeof(struct ast_context) + strlen(name) + 1; 06817 06818 if (!contexts_table) { 06819 contexts_table = ast_hashtab_create(17, 06820 ast_hashtab_compare_contexts, 06821 ast_hashtab_resize_java, 06822 ast_hashtab_newsize_java, 06823 ast_hashtab_hash_contexts, 06824 0); 06825 } 06826 06827 ast_copy_string(search.name, name, sizeof(search.name)); 06828 if (!extcontexts) { 06829 ast_rdlock_contexts(); 06830 local_contexts = &contexts; 06831 tmp = ast_hashtab_lookup(contexts_table, &search); 06832 ast_unlock_contexts(); 06833 if (tmp) { 06834 tmp->refcount++; 06835 return tmp; 06836 } 06837 } else { /* local contexts just in a linked list; search there for the new context; slow, linear search, but not frequent */ 06838 local_contexts = extcontexts; 06839 tmp = ast_hashtab_lookup(exttable, &search); 06840 if (tmp) { 06841 tmp->refcount++; 06842 return tmp; 06843 } 06844 } 06845 06846 if ((tmp = ast_calloc(1, length))) { 06847 ast_rwlock_init(&tmp->lock); 06848 ast_mutex_init(&tmp->macrolock); 06849 strcpy(tmp->name, name); 06850 tmp->root = NULL; 06851 tmp->root_table = NULL; 06852 tmp->registrar = ast_strdup(registrar); 06853 tmp->includes = NULL; 06854 tmp->ignorepats = NULL; 06855 tmp->refcount = 1; 06856 } else { 06857 ast_log(LOG_ERROR, "Danger! We failed to allocate a context for %s!\n", name); 06858 return NULL; 06859 } 06860 06861 if (!extcontexts) { 06862 ast_wrlock_contexts(); 06863 tmp->next = *local_contexts; 06864 *local_contexts = tmp; 06865 ast_hashtab_insert_safe(contexts_table, tmp); /*put this context into the tree */ 06866 ast_unlock_contexts(); 06867 ast_debug(1, "Registered context '%s'(%p) in table %p registrar: %s\n", tmp->name, tmp, contexts_table, registrar); 06868 ast_verb(3, "Registered extension context '%s'; registrar: %s\n", tmp->name, registrar); 06869 } else { 06870 tmp->next = *local_contexts; 06871 if (exttable) 06872 ast_hashtab_insert_immediate(exttable, tmp); /*put this context into the tree */ 06873 06874 *local_contexts = tmp; 06875 ast_debug(1, "Registered context '%s'(%p) in local table %p; registrar: %s\n", tmp->name, tmp, exttable, registrar); 06876 ast_verb(3, "Registered extension context '%s'; registrar: %s\n", tmp->name, registrar); 06877 } 06878 return tmp; 06879 }
| int ast_context_lockmacro | ( | const char * | context | ) |
locks the macrolock in the given given context
| macrocontext | name of the macro-context to lock |
| 0 | on success | |
| -1 | on failure |
Definition at line 5416 of file pbx.c.
References ast_copy_string(), ast_hashtab_lookup(), ast_mutex_lock, ast_rdlock_contexts(), ast_unlock_contexts(), contexts_table, ast_context::macrolock, and fake_context::name.
Referenced by _macro_exec().
05417 { 05418 struct ast_context *c = NULL; 05419 int ret = -1; 05420 struct fake_context item; 05421 05422 ast_rdlock_contexts(); 05423 05424 ast_copy_string(item.name, context, sizeof(item.name)); 05425 05426 c = ast_hashtab_lookup(contexts_table,&item); 05427 if (c) 05428 ret = 0; 05429 ast_unlock_contexts(); 05430 05431 /* if we found context, lock macrolock */ 05432 if (ret == 0) { 05433 ret = ast_mutex_lock(&c->macrolock); 05434 } 05435 05436 return ret; 05437 }
| 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) | |
| registrar | registrar of the extension |
| 0 | on success | |
| -1 | on failure |
Definition at line 5224 of file pbx.c.
References ast_context_remove_extension_callerid().
Referenced by destroy_station(), destroy_trunk(), register_peer_exten(), unregister_exten(), and UnregisterExtension().
05225 { 05226 return ast_context_remove_extension_callerid(context, extension, priority, NULL, 0, registrar); 05227 }
| 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 5251 of file pbx.c.
References ast_context_remove_extension_callerid2().
Referenced by manage_parkinglot(), park_exec_full(), and unload_module().
05252 { 05253 return ast_context_remove_extension_callerid2(con, extension, priority, NULL, 0, registrar, already_locked); 05254 }
| 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 5229 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().
05230 { 05231 int ret = -1; /* default error return */ 05232 struct ast_context *c = find_context_locked(context); 05233 05234 if (c) { /* ... remove extension ... */ 05235 ret = ast_context_remove_extension_callerid2(c, extension, priority, callerid, matchcallerid, registrar, 1); 05236 ast_unlock_contexts(); 05237 } 05238 return ret; 05239 }
| 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 5256 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, ast_exten::label, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_exten::matchcid, ast_context::name, ast_exten::next, ast_context::pattern_tree, ast_exten::peer, ast_exten::peer_label_table, ast_exten::peer_table, ast_exten::priority, ast_exten::registrar, ast_context::root, ast_context::root_table, and match_char::x.
Referenced by __ast_context_destroy(), ast_context_remove_extension2(), and ast_context_remove_extension_callerid().
05257 { 05258 struct ast_exten *exten, *prev_exten = NULL; 05259 struct ast_exten *peer; 05260 struct ast_exten ex, *exten2, *exten3; 05261 char dummy_name[1024]; 05262 struct ast_exten *previous_peer = NULL; 05263 struct ast_exten *next_peer = NULL; 05264 int found = 0; 05265 05266 if (!already_locked) 05267 ast_wrlock_context(con); 05268 05269 /* Handle this is in the new world */ 05270 05271 /* FIXME For backwards compatibility, if callerid==NULL, then remove ALL 05272 * peers, not just those matching the callerid. */ 05273 #ifdef NEED_DEBUG 05274 ast_verb(3,"Removing %s/%s/%d%s%s from trees, registrar=%s\n", con->name, extension, priority, matchcallerid ? "/" : "", matchcallerid ? callerid : "", registrar); 05275 #endif 05276 #ifdef CONTEXT_DEBUG 05277 check_contexts(__FILE__, __LINE__); 05278 #endif 05279 /* find this particular extension */ 05280 ex.exten = dummy_name; 05281 ex.matchcid = matchcallerid && !ast_strlen_zero(callerid); /* don't say match if there's no callerid */ 05282 ex.cidmatch = callerid; 05283 ast_copy_string(dummy_name, extension, sizeof(dummy_name)); 05284 exten = ast_hashtab_lookup(con->root_table, &ex); 05285 if (exten) { 05286 if (priority == 0) { 05287 exten2 = ast_hashtab_remove_this_object(con->root_table, exten); 05288 if (!exten2) 05289 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); 05290 if (con->pattern_tree) { 05291 struct match_char *x = add_exten_to_pattern_tree(con, exten, 1); 05292 05293 if (x->exten) { /* this test for safety purposes */ 05294 x->deleted = 1; /* with this marked as deleted, it will never show up in the scoreboard, and therefore never be found */ 05295 x->exten = 0; /* get rid of what will become a bad pointer */ 05296 } else { 05297 ast_log(LOG_WARNING,"Trying to delete an exten from a context, but the pattern tree node returned isn't a full extension\n"); 05298 } 05299 } 05300 } else { 05301 ex.priority = priority; 05302 exten2 = ast_hashtab_lookup(exten->peer_table, &ex); 05303 if (exten2) { 05304 05305 if (exten2->label) { /* if this exten has a label, remove that, too */ 05306 exten3 = ast_hashtab_remove_this_object(exten->peer_label_table,exten2); 05307 if (!exten3) 05308 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); 05309 } 05310 05311 exten3 = ast_hashtab_remove_this_object(exten->peer_table, exten2); 05312 if (!exten3) 05313 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); 05314 if (exten2 == exten && exten2->peer) { 05315 exten2 = ast_hashtab_remove_this_object(con->root_table, exten); 05316 ast_hashtab_insert_immediate(con->root_table, exten2->peer); 05317 } 05318 if (ast_hashtab_size(exten->peer_table) == 0) { 05319 /* well, if the last priority of an exten is to be removed, 05320 then, the extension is removed, too! */ 05321 exten3 = ast_hashtab_remove_this_object(con->root_table, exten); 05322 if (!exten3) 05323 ast_log(LOG_ERROR,"Did not remove this exten (%s) from the context root_table (%s) (priority %d)\n", exten->exten, con->name, priority); 05324 if (con->pattern_tree) { 05325 struct match_char *x = add_exten_to_pattern_tree(con, exten, 1); 05326 if (x->exten) { /* this test for safety purposes */ 05327 x->deleted = 1; /* with this marked as deleted, it will never show up in the scoreboard, and therefore never be found */ 05328 x->exten = 0; /* get rid of what will become a bad pointer */ 05329 } 05330 } 05331 } 05332 } else { 05333 ast_log(LOG_ERROR,"Could not find priority %d of exten %s in context %s!\n", 05334 priority, exten->exten, con->name); 05335 } 05336 } 05337 } else { 05338 /* hmmm? this exten is not in this pattern tree? */ 05339 ast_log(LOG_WARNING,"Cannot find extension %s in root_table in context %s\n", 05340 extension, con->name); 05341 } 05342 #ifdef NEED_DEBUG 05343 if (con->pattern_tree) { 05344 ast_log(LOG_NOTICE,"match char tree after exten removal:\n"); 05345 log_match_char_tree(con->pattern_tree, " "); 05346 } 05347 #endif 05348 05349 /* scan the extension list to find first matching extension-registrar */ 05350 for (exten = con->root; exten; prev_exten = exten, exten = exten->next) { 05351 if (!strcmp(exten->exten, extension) && 05352 (!registrar || !strcmp(exten->registrar, registrar)) && 05353 (!matchcallerid || (!ast_strlen_zero(callerid) && !ast_strlen_zero(exten->cidmatch) && !strcmp(exten->cidmatch, callerid)) || (ast_strlen_zero(callerid) && ast_strlen_zero(exten->cidmatch)))) 05354 break; 05355 } 05356 if (!exten) { 05357 /* we can't find right extension */ 05358 if (!already_locked) 05359 ast_unlock_context(con); 05360 return -1; 05361 } 05362 05363 /* scan the priority list to remove extension with exten->priority == priority */ 05364 for (peer = exten, next_peer = exten->peer ? exten->peer : exten->next; 05365 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))); 05366 peer = next_peer, next_peer = next_peer ? (next_peer->peer ? next_peer->peer : next_peer->next) : NULL) { 05367 if ((priority == 0 || peer->priority == priority) && 05368 (!callerid || !matchcallerid || (matchcallerid && !strcmp(peer->cidmatch, callerid))) && 05369 (!registrar || !strcmp(peer->registrar, registrar) )) { 05370 found = 1; 05371 05372 /* we are first priority extension? */ 05373 if (!previous_peer) { 05374 /* 05375 * We are first in the priority chain, so must update the extension chain. 05376 * The next node is either the next priority or the next extension 05377 */ 05378 struct ast_exten *next_node = peer->peer ? peer->peer : peer->next; 05379 if (peer->peer) { 05380 /* move the peer_table and peer_label_table down to the next peer, if 05381 it is there */ 05382 peer->peer->peer_table = peer->peer_table; 05383 peer->peer->peer_label_table = peer->peer_label_table; 05384 peer->peer_table = NULL; 05385 peer->peer_label_table = NULL; 05386 } 05387 if (!prev_exten) { /* change the root... */ 05388 con->root = next_node; 05389 } else { 05390 prev_exten->next = next_node; /* unlink */ 05391 } 05392 if (peer->peer) { /* update the new head of the pri list */ 05393 peer->peer->next = peer->next; 05394 } 05395 } else { /* easy, we are not first priority in extension */ 05396 previous_peer->peer = peer->peer; 05397 } 05398 05399 /* now, free whole priority extension */ 05400 destroy_exten(peer); 05401 } else { 05402 previous_peer = peer; 05403 } 05404 } 05405 if (!already_locked) 05406 ast_unlock_context(con); 05407 return found ? 0 : -1; 05408 }
| int ast_context_remove_ignorepat | ( | const char * | context, | |
| const char * | ignorepat, | |||
| const char * | registrar | |||
| ) |
Definition at line 7556 of file pbx.c.
References ast_context_remove_ignorepat2(), ast_unlock_contexts(), and find_context_locked().
Referenced by handle_cli_dialplan_remove_ignorepat().
07557 { 07558 int ret = -1; 07559 struct ast_context *c = find_context_locked(context); 07560 07561 if (c) { 07562 ret = ast_context_remove_ignorepat2(c, ignorepat, registrar); 07563 ast_unlock_contexts(); 07564 } 07565 return ret; 07566 }
| int ast_context_remove_ignorepat2 | ( | struct ast_context * | con, | |
| const char * | ignorepat, | |||
| const char * | registrar | |||
| ) |
Definition at line 7568 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().
07569 { 07570 struct ast_ignorepat *ip, *ipl = NULL; 07571 07572 ast_wrlock_context(con); 07573 07574 for (ip = con->ignorepats; ip; ip = ip->next) { 07575 if (!strcmp(ip->pattern, ignorepat) && 07576 (!registrar || (registrar == ip->registrar))) { 07577 if (ipl) { 07578 ipl->next = ip->next; 07579 ast_free(ip); 07580 } else { 07581 con->ignorepats = ip->next; 07582 ast_free(ip); 07583 } 07584 ast_unlock_context(con); 07585 return 0; 07586 } 07587 ipl = ip; 07588 } 07589 07590 ast_unlock_context(con); 07591 errno = EINVAL; 07592 return -1; 07593 }
| 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 5115 of file pbx.c.
References ast_context_remove_include2(), ast_unlock_contexts(), and find_context_locked().
Referenced by handle_cli_dialplan_remove_include().
05116 { 05117 int ret = -1; 05118 struct ast_context *c = find_context_locked(context); 05119 05120 if (c) { 05121 /* found, remove include from this context ... */ 05122 ret = ast_context_remove_include2(c, include, registrar); 05123 ast_unlock_contexts(); 05124 } 05125 return ret; 05126 }
| 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 |
| 0 | on success. | |
| -1 | on failure. |
Definition at line 5137 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().
05138 { 05139 struct ast_include *i, *pi = NULL; 05140 int ret = -1; 05141 05142 ast_wrlock_context(con); 05143 05144 /* find our include */ 05145 for (i = con->includes; i; pi = i, i = i->next) { 05146 if (!strcmp(i->name, include) && 05147 (!registrar || !strcmp(i->registrar, registrar))) { 05148 /* remove from list */ 05149 ast_verb(3, "Removing inclusion of context '%s' in context '%s; registrar=%s'\n", include, ast_get_context_name(con), registrar); 05150 if (pi) 05151 pi->next = i->next; 05152 else 05153 con->includes = i->next; 05154 /* free include and return */ 05155 ast_destroy_timing(&(i->timing)); 05156 ast_free(i); 05157 ret = 0; 05158 break; 05159 } 05160 } 05161 05162 ast_unlock_context(con); 05163 05164 return ret; 05165 }
| 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 5172 of file pbx.c.
References ast_context_remove_switch2(), ast_unlock_contexts(), and find_context_locked().
05173 { 05174 int ret = -1; /* default error return */ 05175 struct ast_context *c = find_context_locked(context); 05176 05177 if (c) { 05178 /* remove switch from this context ... */ 05179 ret = ast_context_remove_switch2(c, sw, data, registrar); 05180 ast_unlock_contexts(); 05181 } 05182 return ret; 05183 }
| 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 5193 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().
05194 { 05195 struct ast_sw *i; 05196 int ret = -1; 05197 05198 ast_wrlock_context(con); 05199 05200 /* walk switches */ 05201 AST_LIST_TRAVERSE_SAFE_BEGIN(&con->alts, i, list) { 05202 if (!strcmp(i->name, sw) && !strcmp(i->data, data) && 05203 (!registrar || !strcmp(i->registrar, registrar))) { 05204 /* found, remove from list */ 05205 ast_verb(3, "Removing switch '%s' from context '%s; registrar=%s'\n", sw, ast_get_context_name(con), registrar); 05206 AST_LIST_REMOVE_CURRENT(list); 05207 ast_free(i); /* free switch and return */ 05208 ret = 0; 05209 break; 05210 } 05211 } 05212 AST_LIST_TRAVERSE_SAFE_END; 05213 05214 ast_unlock_context(con); 05215 05216 return ret; 05217 }
| int ast_context_unlockmacro | ( | const char * | context | ) |
Unlocks the macrolock in the given context.
| macrocontext | name of the macro-context to unlock |
| 0 | on success | |
| -1 | on failure |
Definition at line 5444 of file pbx.c.
References ast_copy_string(), ast_hashtab_lookup(), ast_mutex_unlock, ast_rdlock_contexts(), ast_unlock_contexts(), contexts_table, ast_context::macrolock, and fake_context::name.
Referenced by _macro_exec().
05445 { 05446 struct ast_context *c = NULL; 05447 int ret = -1; 05448 struct fake_context item; 05449 05450 ast_rdlock_contexts(); 05451 05452 ast_copy_string(item.name, context, sizeof(item.name)); 05453 05454 c = ast_hashtab_lookup(contexts_table,&item); 05455 if (c) 05456 ret = 0; 05457 ast_unlock_contexts(); 05458 05459 /* if we found context, unlock macrolock */ 05460 if (ret == 0) { 05461 ret = ast_mutex_unlock(&c->macrolock); 05462 } 05463 05464 return ret; 05465 }
| 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 10039 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().
10040 { 10041 struct ast_include *inc = NULL; 10042 int res = 0; 10043 10044 while ( (inc = ast_walk_context_includes(con, inc)) ) { 10045 if (ast_context_find(inc->rname)) 10046 continue; 10047 10048 res = -1; 10049 ast_log(LOG_WARNING, "Context '%s' tries to include nonexistent context '%s'\n", 10050 ast_get_context_name(con), inc->rname); 10051 break; 10052 } 10053 10054 return res; 10055 }
| struct ast_custom_function* ast_custom_function_find | ( | const char * | name | ) | [read] |
Definition at line 3317 of file pbx.c.
References ast_custom_function::acflist, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, and ast_custom_function::name.
Referenced by ast_func_read(), ast_func_read2(), ast_func_write(), config_curl(), destroy_curl(), handle_show_function(), op_func(), realtime_curl(), realtime_multi_curl(), require_curl(), store_curl(), update2_curl(), and update_curl().
03318 { 03319 struct ast_custom_function *acf = NULL; 03320 03321 AST_RWLIST_RDLOCK(&acf_root); 03322 AST_RWLIST_TRAVERSE(&acf_root, acf, acflist) { 03323 if (!strcmp(name, acf->name)) 03324 break; 03325 } 03326 AST_RWLIST_UNLOCK(&acf_root); 03327 03328 return acf; 03329 }
| int ast_custom_function_unregister | ( | struct ast_custom_function * | acf | ) |
Unregister a custom function.
Definition at line 3331 of file pbx.c.
References ast_custom_function::acflist, AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_string_field_free_memory, ast_verb, AST_XML_DOC, ast_custom_function::docsrc, and ast_custom_function::name.
Referenced by _unload_module(), load_module(), reload(), and unload_module().
03332 { 03333 struct ast_custom_function *cur; 03334 03335 if (!acf) { 03336 return -1; 03337 } 03338 03339 AST_RWLIST_WRLOCK(&acf_root); 03340 if ((cur = AST_RWLIST_REMOVE(&acf_root, acf, acflist))) { 03341 #ifdef AST_XML_DOCS 03342 if (cur->docsrc == AST_XML_DOC) { 03343 ast_string_field_free_memory(acf); 03344 } 03345 #endif 03346 ast_verb(2, "Unregistered custom function %s\n", cur->name); 03347 } 03348 AST_RWLIST_UNLOCK(&acf_root); 03349 03350 return cur ? 0 : -1; 03351 }
| 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 7399 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().
07400 { 07401 if (i->timezone) { 07402 ast_free(i->timezone); 07403 i->timezone = NULL; 07404 } 07405 return 0; 07406 }
| enum ast_extension_states ast_devstate_to_extenstate | ( | enum ast_device_state | devstate | ) |
Map devstate to an extension state.
| [in] | devstate | device state |
Definition at line 4137 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().
04138 { 04139 switch (devstate) { 04140 case AST_DEVICE_ONHOLD: 04141 return AST_EXTENSION_ONHOLD; 04142 case AST_DEVICE_BUSY: 04143 return AST_EXTENSION_BUSY; 04144 case AST_DEVICE_UNKNOWN: 04145 return AST_EXTENSION_NOT_INUSE; 04146 case AST_DEVICE_UNAVAILABLE: 04147 case AST_DEVICE_INVALID: 04148 return AST_EXTENSION_UNAVAILABLE; 04149 case AST_DEVICE_RINGINUSE: 04150 return (AST_EXTENSION_INUSE | AST_EXTENSION_RINGING); 04151 case AST_DEVICE_RINGING: 04152 return AST_EXTENSION_RINGING; 04153 case AST_DEVICE_INUSE: 04154 return AST_EXTENSION_INUSE; 04155 case AST_DEVICE_NOT_INUSE: 04156 return AST_EXTENSION_NOT_INUSE; 04157 case AST_DEVICE_TOTAL: /* not a device state, included for completeness */ 04158 break; 04159 } 04160 04161 return AST_EXTENSION_NOT_INUSE; 04162 }
| 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 4550 of file pbx.c.
References E_MATCH, and pbx_extension_helper().
Referenced by __analog_ss_thread(), __ast_goto_if_exists(), __ast_pbx_run(), _macro_exec(), acf_isexten_exec(), analog_ss_thread(), answer_call(), ast_app_dtget(), ast_bridge_call(), ast_pbx_outgoing_exten(), builtin_atxfer(), builtin_blindtransfer(), cb_events(), cli_console_dial(), conf_run(), console_dial(), console_transfer(), dahdi_handle_dtmfup(), dahdi_r2_on_call_offered(), dahdi_r2_on_dnis_digit_received(), dial_exec_full(), disa_exec(), dp_lookup(), dundi_lookup_local(), 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(), my_handle_dtmfup(), park_space_reserve(), parkandannounce_exec(), pbx_builtin_waitexten(), phone_check_exception(), pri_dchannel(), pri_ss_thread(), privacy_exec(), process_ast_dsp(), process_sdp(), readexten_exec(), register_peer_exten(), rpt_exec(), show_debug_helper(), sip_new(), sip_read(), skinny_ss(), socket_process(), ss7_linkset(), vm_authenticate(), and waitstream_core().
04551 { 04552 return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCH, 0, 0); 04553 }
| int ast_explicit_goto | ( | struct ast_channel * | chan, | |
| const char * | context, | |||
| const char * | exten, | |||
| int | priority | |||
| ) |
Definition at line 7703 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().
07704 { 07705 if (!chan) 07706 return -1; 07707 07708 ast_channel_lock(chan); 07709 07710 if (!ast_strlen_zero(context)) 07711 ast_copy_string(chan->context, context, sizeof(chan->context)); 07712 if (!ast_strlen_zero(exten)) 07713 ast_copy_string(chan->exten, exten, sizeof(chan->exten)); 07714 if (priority > -1) { 07715 chan->priority = priority; 07716 /* see flag description in channel.h for explanation */ 07717 if (ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP)) 07718 chan->priority--; 07719 } 07720 07721 ast_channel_unlock(chan); 07722 07723 return 0; 07724 }
| int ast_extension_close | ( | const char * | pattern, | |
| const char * | data, | |||
| int | needmore | |||
| ) |
Definition at line 2481 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().
02482 { 02483 if (needmore != E_MATCHMORE && needmore != E_CANMATCH) 02484 ast_log(LOG_WARNING, "invalid argument %d\n", needmore); 02485 return extension_match_core(pattern, data, needmore); 02486 }
| int ast_extension_cmp | ( | const char * | a, | |
| const char * | b | |||
| ) |
Determine if one extension should match before another.
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 2283 of file pbx.c.
References ext_cmp().
Referenced by lua_extension_cmp().
02284 { 02285 return ext_cmp(a, b); 02286 }
| int ast_extension_match | ( | const char * | pattern, | |
| const char * | extension | |||
| ) |
Determine if a given extension matches a given pattern (in NXX format).
Checks whether or not the given extension matches the given pattern.
| 1 | on match | |
| 0 | on failure |
Definition at line 2476 of file pbx.c.
References E_MATCH, and extension_match_core().
Referenced by ast_ignore_pattern(), do_say(), find_matching_priority(), load_module(), loopback_canmatch(), loopback_exists(), loopback_matchmore(), lua_find_extension(), manager_show_dialplan_helper(), matchcid(), misdn_cfg_is_msn_valid(), realtime_switch_common(), reload(), show_dialplan_helper(), and sig_pri_msn_match().
02477 { 02478 return extension_match_core(pattern, data, E_MATCH); 02479 }
| 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 4200 of file pbx.c.
References ast_exten::app, ast_add_extension(), ast_extension_state2(), ast_free_ptr, ast_hint_extension(), ast_strdup, ast_exten::cidmatch, ast_exten::data, ast_exten::exten, ast_exten::label, ast_exten::matchcid, ast_context::name, ast_exten::parent, ast_exten::priority, and ast_exten::registrar.
Referenced by action_extensionstate(), extstate_read(), get_queue_member_status(), and handle_request_subscribe().
04201 { 04202 struct ast_exten *e; 04203 04204 if (!(e = ast_hint_extension(c, context, exten))) { /* Do we have a hint for this extension ? */ 04205 return -1; /* No hint, return -1 */ 04206 } 04207 04208 if (e->exten[0] == '_') { 04209 /* Create this hint on-the-fly */ 04210 ast_add_extension(e->parent->name, 0, exten, e->priority, e->label, 04211 e->matchcid ? e->cidmatch : NULL, e->app, ast_strdup(e->data), ast_free_ptr, 04212 e->registrar); 04213 if (!(e = ast_hint_extension(c, context, exten))) { 04214 /* Improbable, but not impossible */ 04215 return -1; 04216 } 04217 } 04218 04219 return ast_extension_state2(e); /* Check all devices in the hint */ 04220 }
| 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 4188 of file pbx.c.
References ARRAY_LEN, extension_states, and cfextension_states::text.
Referenced by cb_extensionstate(), handle_request_subscribe(), handle_show_hint(), handle_show_hints(), hints_data_provider_get(), and show_channels_cb().
04189 { 04190 int i; 04191 04192 for (i = 0; (i < ARRAY_LEN(extension_states)); i++) { 04193 if (extension_states[i].extension_state == extension_state) 04194 return extension_states[i].text; 04195 } 04196 return "Unknown"; 04197 }
| 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 |
| -1 | on failure | |
| ID | on success |
Definition at line 4282 of file pbx.c.
References ast_exten::app, ast_add_extension(), ast_calloc, ast_free_ptr, ast_hint_extension(), AST_LIST_INSERT_HEAD, AST_LIST_TRAVERSE, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strdup, ast_state_cb::callback, ast_hint::callbacks, ast_exten::cidmatch, ast_exten::data, ast_state_cb::data, ast_hint::exten, ast_exten::exten, ast_state_cb::id, ast_exten::label, ast_exten::matchcid, ast_context::name, ast_exten::parent, ast_exten::priority, ast_exten::registrar, and stateid.
Referenced by __init_manager(), handle_request_subscribe(), load_module(), and skinny_register().
04284 { 04285 struct ast_hint *hint; 04286 struct ast_state_cb *cblist; 04287 struct ast_exten *e; 04288 04289 /* If there's no context and extension: add callback to statecbs list */ 04290 if (!context && !exten) { 04291 AST_RWLIST_WRLOCK(&hints); 04292 04293 AST_LIST_TRAVERSE(&statecbs, cblist, entry) { 04294 if (cblist->callback == callback) { 04295 cblist->data = data; 04296 AST_RWLIST_UNLOCK(&hints); 04297 return 0; 04298 } 04299 } 04300 04301 /* Now insert the callback */ 04302 if (!(cblist = ast_calloc(1, sizeof(*cblist)))) { 04303 AST_RWLIST_UNLOCK(&hints); 04304 return -1; 04305 } 04306 cblist->id = 0; 04307 cblist->callback = callback; 04308 cblist->data = data; 04309 04310 AST_LIST_INSERT_HEAD(&statecbs, cblist, entry); 04311 04312 AST_RWLIST_UNLOCK(&hints); 04313 04314 return 0; 04315 } 04316 04317 if (!context || !exten) 04318 return -1; 04319 04320 /* This callback type is for only one hint, so get the hint */ 04321 e = ast_hint_extension(NULL, context, exten); 04322 if (!e) { 04323 return -1; 04324 } 04325 04326 /* If this is a pattern, dynamically create a new extension for this 04327 * particular match. Note that this will only happen once for each 04328 * individual extension, because the pattern will no longer match first. 04329 */ 04330 if (e->exten[0] == '_') { 04331 ast_add_extension(e->parent->name, 0, exten, e->priority, e->label, 04332 e->matchcid ? e->cidmatch : NULL, e->app, ast_strdup(e->data), ast_free_ptr, 04333 e->registrar); 04334 e = ast_hint_extension(NULL, context, exten); 04335 if (!e || e->exten[0] == '_') { 04336 return -1; 04337 } 04338 } 04339 04340 /* Find the hint in the list of hints */ 04341 AST_RWLIST_WRLOCK(&hints); 04342 04343 AST_RWLIST_TRAVERSE(&hints, hint, list) { 04344 if (hint->exten == e) 04345 break; 04346 } 04347 04348 if (!hint) { 04349 /* We have no hint, sorry */ 04350 AST_RWLIST_UNLOCK(&hints); 04351 return -1; 04352 } 04353 04354 /* Now insert the callback in the callback list */ 04355 if (!(cblist = ast_calloc(1, sizeof(*cblist)))) { 04356 AST_RWLIST_UNLOCK(&hints); 04357 return -1; 04358 } 04359 04360 cblist->id = stateid++; /* Unique ID for this callback */ 04361 cblist->callback = callback; /* Pointer to callback routine */ 04362 cblist->data = data; /* Data for the callback */ 04363 04364 AST_LIST_INSERT_HEAD(&hint->callbacks, cblist, entry); 04365 04366 AST_RWLIST_UNLOCK(&hints); 04367 04368 return cblist->id; 04369 }
| 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 |
| 0 | success | |
| -1 | failure |
Definition at line 4372 of file pbx.c.
References ast_free, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_state_cb::callback, ast_hint::callbacks, and ast_state_cb::id.
Referenced by dialog_unlink_all(), handle_request_subscribe(), skinny_unregister(), and unload_module().
04373 { 04374 struct ast_state_cb *p_cur = NULL; 04375 int ret = -1; 04376 04377 if (!id && !callback) 04378 return -1; 04379 04380 AST_RWLIST_WRLOCK(&hints); 04381 04382 if (!id) { /* id == 0 is a callback without extension */ 04383 AST_LIST_TRAVERSE_SAFE_BEGIN(&statecbs, p_cur, entry) { 04384 if (p_cur->callback == callback) { 04385 AST_LIST_REMOVE_CURRENT(entry); 04386 break; 04387 } 04388 } 04389 AST_LIST_TRAVERSE_SAFE_END; 04390 } else { /* callback with extension, find the callback based on ID */ 04391 struct ast_hint *hint; 04392 AST_RWLIST_TRAVERSE(&hints, hint, list) { 04393 AST_LIST_TRAVERSE_SAFE_BEGIN(&hint->callbacks, p_cur, entry) { 04394 if (p_cur->id == id) { 04395 AST_LIST_REMOVE_CURRENT(entry); 04396 break; 04397 } 04398 } 04399 AST_LIST_TRAVERSE_SAFE_END; 04400 04401 if (p_cur) 04402 break; 04403 } 04404 } 04405 04406 if (p_cur) { 04407 ast_free(p_cur); 04408 } 04409 04410 AST_RWLIST_UNLOCK(&hints); 04411 04412 return ret; 04413 }
| 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 4555 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().
04556 { 04557 return pbx_extension_helper(c, NULL, context, exten, 0, label, callerid, E_FINDLABEL, 0, 0); 04558 }
| 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.
This function is the same as ast_findlabel_extension, except that it accepts a pointer to an ast_context structure to specify the context instead of the name of the context. Otherwise, the functions behave the same.
Definition at line 4560 of file pbx.c.
References E_FINDLABEL, and pbx_extension_helper().
Referenced by pbx_load_config().
04561 { 04562 return pbx_extension_helper(c, con, NULL, exten, 0, label, callerid, E_FINDLABEL, 0, 0); 04563 }
| 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 |
| 0 | success | |
| non-zero | failure |
Definition at line 3475 of file pbx.c.
References __ast_module_user_add(), __ast_module_user_remove(), args, ast_copy_string(), ast_custom_function_find(), ast_free, ast_log(), ast_str_buffer(), ast_str_create(), ast_str_size(), ast_strdupa, copy(), func_args(), LOG_ERROR, ast_custom_function::mod, ast_custom_function::read, ast_custom_function::read2, and str.
Referenced by action_getvar(), action_status(), handle_getvariable(), lua_get_variable_value(), and pbx_substitute_variables_helper_full().
03476 { 03477 char *copy = ast_strdupa(function); 03478 char *args = func_args(copy); 03479 struct ast_custom_function *acfptr = ast_custom_function_find(copy); 03480 int res; 03481 struct ast_module_user *u = NULL; 03482 03483 if (acfptr == NULL) { 03484 ast_log(LOG_ERROR, "Function %s not registered\n", copy); 03485 } else if (!acfptr->read && !acfptr->read2) { 03486 ast_log(LOG_ERROR, "Function %s cannot be read\n", copy); 03487 } else if (acfptr->read) { 03488 if (acfptr->mod) { 03489 u = __ast_module_user_add(acfptr->mod, chan); 03490 } 03491 res = acfptr->read(chan, copy, args, workspace, len); 03492 if (acfptr->mod && u) { 03493 __ast_module_user_remove(acfptr->mod, u); 03494 } 03495 return res; 03496 } else { 03497 struct ast_str *str = ast_str_create(16); 03498 if (acfptr->mod) { 03499 u = __ast_module_user_add(acfptr->mod, chan); 03500 } 03501 res = acfptr->read2(chan, copy, args, &str, 0); 03502 if (acfptr->mod && u) { 03503 __ast_module_user_remove(acfptr->mod, u); 03504 } 03505 ast_copy_string(workspace, ast_str_buffer(str), len > ast_str_size(str) ? ast_str_size(str) : len); 03506 ast_free(str); 03507 return res; 03508 } 03509 return -1; 03510 }
| int ast_func_read2 | ( | struct ast_channel * | chan, | |
| const char * | function, | |||
| struct ast_str ** | str, | |||
| ssize_t | maxlen | |||
| ) |
executes a read operation on a function
| chan | Channel to execute on | |
| function | Data containing the function call string (will be modified) | |
| str | A dynamic string buffer into which to place the result. | |
| maxlen | <0 if the dynamic buffer should not grow; >0 if the dynamic buffer should be limited to that number of bytes; 0 if the dynamic buffer has no upper limit |
| 0 | success | |
| non-zero | failure |
Definition at line 3512 of file pbx.c.
References __ast_module_user_add(), __ast_module_user_remove(), args, ast_custom_function_find(), ast_log(), ast_str_buffer(), ast_str_make_space(), ast_str_reset(), ast_str_size(), ast_strdupa, copy(), func_args(), LOG_ERROR, maxsize, ast_custom_function::mod, ast_custom_function::read, ast_custom_function::read2, ast_custom_function::read_max, and VAR_BUF_SIZE.
Referenced by append_channel_vars(), and ast_str_substitute_variables_full().
03513 { 03514 char *copy = ast_strdupa(function); 03515 char *args = func_args(copy); 03516 struct ast_custom_function *acfptr = ast_custom_function_find(copy); 03517 int res; 03518 struct ast_module_user *u = NULL; 03519 03520 if (acfptr == NULL) { 03521 ast_log(LOG_ERROR, "Function %s not registered\n", copy); 03522 } else if (!acfptr->read && !acfptr->read2) { 03523 ast_log(LOG_ERROR, "Function %s cannot be read\n", copy); 03524 } else { 03525 if (acfptr->mod) { 03526 u = __ast_module_user_add(acfptr->mod, chan); 03527 } 03528 if (acfptr->read2) { 03529 /* ast_str enabled */ 03530 ast_str_reset(*str); 03531 res = acfptr->read2(chan, copy, args, str, maxlen); 03532 } else { 03533 /* Legacy function pointer, allocate buffer for result */ 03534 int maxsize = ast_str_size(*str); 03535 if (maxlen > -1) { 03536 if (maxlen == 0) { 03537 if (acfptr->read_max) { 03538 maxsize = acfptr->read_max; 03539 } else { 03540 maxsize = VAR_BUF_SIZE; 03541 } 03542 } else { 03543 maxsize = maxlen; 03544 } 03545 ast_str_make_space(str, maxsize); 03546 } 03547 res = acfptr->read(chan, copy, args, ast_str_buffer(*str), maxsize); 03548 } 03549 if (acfptr->mod && u) { 03550 __ast_module_user_remove(acfptr->mod, u); 03551 } 03552 return res; 03553 } 03554 return -1; 03555 }
| 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 |
| 0 | success | |
| non-zero | failure |
Definition at line 3557 of file pbx.c.
References __ast_module_user_add(), __ast_module_user_remove(), args, ast_custom_function_find(), ast_log(), ast_strdupa, copy(), func_args(), LOG_ERROR, ast_custom_function::mod, and ast_custom_function::write.
Referenced by conf_run(), pbx_builtin_pushvar_helper(), and pbx_builtin_setvar_helper().
03558 { 03559 char *copy = ast_strdupa(function); 03560 char *args = func_args(copy); 03561 struct ast_custom_function *acfptr = ast_custom_function_find(copy); 03562 03563 if (acfptr == NULL) 03564 ast_log(LOG_ERROR, "Function %s not registered\n", copy); 03565 else if (!acfptr->write) 03566 ast_log(LOG_ERROR, "Function %s cannot be written to\n", copy); 03567 else { 03568 int res; 03569 struct ast_module_user *u = NULL; 03570 if (acfptr->mod) 03571 u = __ast_module_user_add(acfptr->mod, chan); 03572 res = acfptr->write(chan, copy, args, value); 03573 if (acfptr->mod && u) 03574 __ast_module_user_remove(acfptr->mod, u); 03575 return res; 03576 } 03577 03578 return -1; 03579 }
| const char* ast_get_context_name | ( | struct ast_context * | con | ) |
Definition at line 9891 of file pbx.c.
References ast_context::name.
Referenced by _macro_exec(), ast_context_add_include2(), ast_context_add_switch2(), ast_context_remove_include2(), ast_context_remove_switch2(), 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_matching_endwhile(), find_matching_priority(), handle_cli_dialplan_save(), handle_show_hint(), handle_show_hints(), hints_data_provider_get(), manager_show_dialplan_helper(), show_debug_helper(), and show_dialplan_helper().
09892 { 09893 return con ? con->name : NULL; 09894 }
| const char* ast_get_context_registrar | ( | struct ast_context * | c | ) |
Definition at line 9929 of file pbx.c.
References ast_context::registrar.
Referenced by handle_cli_dialplan_save(), show_debug_helper(), and show_dialplan_helper().
09930 { 09931 return c ? c->registrar : NULL; 09932 }
| const char* ast_get_extension_app | ( | struct ast_exten * | e | ) |
Definition at line 9959 of file pbx.c.
References ast_exten::app.
Referenced by _macro_exec(), ast_add_hint_nolock(), ast_extension_state2(), ast_get_hint(), ast_parking_ext_valid(), ast_str_get_hint(), find_matching_endwhile(), handle_cli_dialplan_save(), handle_show_hint(), handle_show_hints(), handle_statechange(), hints_data_provider_get(), manager_show_dialplan_helper(), and print_ext().
09960 { 09961 return e ? e->app : NULL; 09962 }
| void* ast_get_extension_app_data | ( | struct ast_exten * | e | ) |
Definition at line 9964 of file pbx.c.
References ast_exten::data.
Referenced by _macro_exec(), ast_get_hint(), ast_str_get_hint(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), and print_ext().
09965 { 09966 return e ? e->data : NULL; 09967 }
| const char* ast_get_extension_cidmatch | ( | struct ast_exten * | e | ) |
Definition at line 9954 of file pbx.c.
References ast_exten::cidmatch.
Referenced by complete_dialplan_remove_extension(), find_matching_priority(), and handle_cli_dialplan_save().
09955 { 09956 return e ? e->cidmatch : NULL; 09957 }
| struct ast_context* ast_get_extension_context | ( | struct ast_exten * | exten | ) | [read] |
Definition at line 9896 of file pbx.c.
References ast_exten::parent.
Referenced by handle_show_hint(), handle_show_hints(), and hints_data_provider_get().
09897 { 09898 return exten ? exten->parent : NULL; 09899 }
| const char* ast_get_extension_label | ( | struct ast_exten * | e | ) |
Definition at line 9906 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 9949 of file pbx.c.
References ast_exten::matchcid.
Referenced by complete_dialplan_remove_extension(), find_matching_priority(), and handle_cli_dialplan_save().
09950 { 09951 return e ? e->matchcid : 0; 09952 }
| const char* ast_get_extension_name | ( | struct ast_exten * | exten | ) |
Definition at line 9901 of file pbx.c.
References ast_exten::exten.
Referenced by ast_add_hint_nolock(), complete_core_show_hint(), complete_dialplan_remove_extension(), dundi_precache_full(), find_matching_priority(), handle_cli_dialplan_save(), handle_show_hint(), handle_show_hints(), hints_data_provider_get(), manager_show_dialplan_helper(), and show_dialplan_helper().
09902 { 09903 return exten ? exten->exten : NULL; 09904 }
| int ast_get_extension_priority | ( | struct ast_exten * | exten | ) |
Definition at line 9921 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().
09922 { 09923 return exten ? exten->priority : -1; 09924 }
| const char* ast_get_extension_registrar | ( | struct ast_exten * | e | ) |
Definition at line 9934 of file pbx.c.
References ast_exten::registrar.
Referenced by handle_cli_dialplan_save(), manager_show_dialplan_helper(), and show_dialplan_helper().
09935 { 09936 return e ? e->registrar : NULL; 09937 }
| 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 4512 of file pbx.c.
References ast_copy_string(), ast_get_extension_app(), ast_get_extension_app_data(), and ast_hint_extension().
Referenced by action_extensionstate(), get_cid_name(), get_destination(), hint_read(), manager_state_cb(), skinny_extensionstate_cb(), and state_notify_build_xml().
04513 { 04514 struct ast_exten *e = ast_hint_extension(c, context, exten); 04515 04516 if (e) { 04517 if (hint) 04518 ast_copy_string(hint, ast_get_extension_app(e), hintsize); 04519 if (name) { 04520 const char *tmp = ast_get_extension_app_data(e); 04521 if (tmp) 04522 ast_copy_string(name, tmp, namesize); 04523 } 04524 return -1; 04525 } 04526 return 0; 04527 }
| const char* ast_get_ignorepat_name | ( | struct ast_ignorepat * | ip | ) |
Definition at line 9916 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().
09917 { 09918 return ip ? ip->pattern : NULL; 09919 }
| const char* ast_get_ignorepat_registrar | ( | struct ast_ignorepat * | ip | ) |
Definition at line 9944 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().
09945 { 09946 return ip ? ip->registrar : NULL; 09947 }
| const char* ast_get_include_name | ( | struct ast_include * | include | ) |
Definition at line 9911 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().
| const char* ast_get_include_registrar | ( | struct ast_include * | i | ) |
Definition at line 9939 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().
09940 { 09941 return i ? i->registrar : NULL; 09942 }
| const char* ast_get_switch_data | ( | struct ast_sw * | sw | ) |
Definition at line 9974 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().
09975 { 09976 return sw ? sw->data : NULL; 09977 }
| int ast_get_switch_eval | ( | struct ast_sw * | sw | ) |
Definition at line 9979 of file pbx.c.
References ast_sw::eval.
Referenced by context_merge_incls_swits_igps_other_registrars().
09980 { 09981 return sw->eval; 09982 }
| const char* ast_get_switch_name | ( | struct ast_sw * | sw | ) |
Definition at line 9969 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().
09970 { 09971 return sw ? sw->name : NULL; 09972 }
| const char* ast_get_switch_registrar | ( | struct ast_sw * | sw | ) |
Definition at line 9984 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().
09985 { 09986 return sw ? sw->registrar : NULL; 09987 }
| int ast_goto_if_exists | ( | struct ast_channel * | chan, | |
| const char * | context, | |||
| const char * | exten, | |||
| int | priority | |||
| ) |
Definition at line 10079 of file pbx.c.
References __ast_goto_if_exists().
Referenced by background_detect_exec(), channel_spy(), common_exec(), conf_run(), dial_exec_full(), goto_exten(), onedigit_goto(), priority_jump(), select_entry(), valid_exit(), vm_execmain(), and vmauthenticate().
10080 { 10081 return __ast_goto_if_exists(chan, context, exten, priority, 0); 10082 }
| int ast_hashtab_compare_contexts | ( | const void * | ah_a, | |
| const void * | ah_b | |||
| ) |
hashtable functions for contexts
Definition at line 1039 of file pbx.c.
References ast_context::name.
Referenced by ast_context_find_or_create(), lua_register_switches(), and pbx_load_module().
01040 { 01041 const struct ast_context *ac = ah_a; 01042 const struct ast_context *bc = ah_b; 01043 if (!ac || !bc) /* safety valve, but it might prevent a crash you'd rather have happen */ 01044 return 1; 01045 /* assume context names are registered in a string table! */ 01046 return strcmp(ac->name, bc->name); 01047 }
| unsigned int ast_hashtab_hash_contexts | ( | const void * | obj | ) |
Definition at line 1082 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().
01083 { 01084 const struct ast_context *ac = obj; 01085 return ast_hashtab_hash_string(ac->name); 01086 }
| 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 |
| 0 | if the pattern should not be ignored | |
| non-zero | if the pattern should be ignored |
Definition at line 7649 of file pbx.c.
References ast_context_find(), ast_extension_match(), ast_context::ignorepats, ast_ignorepat::next, and ast_ignorepat::pattern.
Referenced by __analog_ss_thread(), analog_ss_thread(), ast_app_dtget(), disa_exec(), dp_lookup(), dundi_lookup_local(), handle_enbloc_call_message(), handle_soft_key_event_message(), handle_stimulus_message(), mgcp_ss(), pri_ss_thread(), and skinny_ss().
07650 { 07651 struct ast_context *con = ast_context_find(context); 07652 if (con) { 07653 struct ast_ignorepat *pat; 07654 for (pat = con->ignorepats; pat; pat = pat->next) { 07655 if (ast_extension_match(pat->pattern, pattern)) 07656 return 1; 07657 } 07658 } 07659 07660 return 0; 07661 }
| 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 4570 of file pbx.c.
References E_MATCHMORE, and pbx_extension_helper().
Referenced by __analog_ss_thread(), __ast_pbx_run(), analog_ss_thread(), ast_app_dtget(), collect_digits(), dahdi_r2_on_dnis_digit_received(), disa_exec(), dp_lookup(), dundi_lookup_local(), handle_link_data(), handle_link_phone_dtmf(), local_dtmf_helper(), loopback_matchmore(), mgcp_ss(), pbx_builtin_background(), pri_dchannel(), pri_ss_thread(), readexten_exec(), and skinny_ss().
04571 { 04572 return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCHMORE, 0, 0); 04573 }
| 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 7011 of file pbx.c.
References __ast_internal_context_destroy(), 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_APPEND_LIST, AST_LIST_EMPTY, AST_LIST_HEAD_INIT_VALUE, AST_LIST_INSERT_HEAD, AST_LIST_REMOVE_HEAD, ast_rdlock_contexts(), AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, 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, E_MATCH, ast_exten::exten, ast_hint::exten, ast_hint::laststate, ast_context::name, ast_context::next, ast_sw::next, 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().
07012 { 07013 double ft; 07014 struct ast_context *tmp, *oldcontextslist; 07015 struct ast_hashtab *oldtable; 07016 struct store_hints store = AST_LIST_HEAD_INIT_VALUE; 07017 struct store_hint *this; 07018 struct ast_hint *hint; 07019 struct ast_exten *exten; 07020 int length; 07021 struct ast_state_cb *thiscb; 07022 struct ast_hashtab_iter *iter; 07023 07024 /* it is very important that this function hold the hint list lock _and_ the conlock 07025 during its operation; not only do we need to ensure that the list of contexts 07026 and extensions does not change, but also that no hint callbacks (watchers) are 07027 added or removed during the merge/delete process 07028 07029 in addition, the locks _must_ be taken in this order, because there are already 07030 other code paths that use this order 07031 */ 07032 07033 struct timeval begintime, writelocktime, endlocktime, enddeltime; 07034 07035 begintime = ast_tvnow(); 07036 ast_rdlock_contexts(); 07037 iter = ast_hashtab_start_traversal(contexts_table); 07038 while ((tmp = ast_hashtab_next(iter))) { 07039 context_merge(extcontexts, exttable, tmp, registrar); 07040 } 07041 ast_hashtab_end_traversal(iter); 07042 07043 AST_RWLIST_WRLOCK(&hints); 07044 writelocktime = ast_tvnow(); 07045 07046 /* preserve all watchers for hints */ 07047 AST_RWLIST_TRAVERSE(&hints, hint, list) { 07048 if (!AST_LIST_EMPTY(&hint->callbacks)) { 07049 length = strlen(hint->exten->exten) + strlen(hint->exten->parent->name) + 2 + sizeof(*this); 07050 if (!(this = ast_calloc(1, length))) 07051 continue; 07052 /* this removes all the callbacks from the hint into this. */ 07053 AST_LIST_APPEND_LIST(&this->callbacks, &hint->callbacks, entry); 07054 this->laststate = hint->laststate; 07055 this->context = this->data; 07056 strcpy(this->data, hint->exten->parent->name); 07057 this->exten = this->data + strlen(this->context) + 1; 07058 strcpy(this->exten, hint->exten->exten); 07059 AST_LIST_INSERT_HEAD(&store, this, list); 07060 } 07061 } 07062 07063 /* save the old table and list */ 07064 oldtable = contexts_table; 07065 oldcontextslist = contexts; 07066 07067 /* move in the new table and list */ 07068 contexts_table = exttable; 07069 contexts = *extcontexts; 07070 07071 /* restore the watchers for hints that can be found; notify those that 07072 cannot be restored 07073 */ 07074 while ((this = AST_LIST_REMOVE_HEAD(&store, list))) { 07075 struct pbx_find_info q = { .stacklen = 0 }; 07076 exten = pbx_find_extension(NULL, NULL, &q, this->context, this->exten, PRIORITY_HINT, NULL, "", E_MATCH); 07077 /* If this is a pattern, dynamically create a new extension for this 07078 * particular match. Note that this will only happen once for each 07079 * individual extension, because the pattern will no longer match first. 07080 */ 07081 if (exten && exten->exten[0] == '_') { 07082 ast_add_extension_nolock(exten->parent->name, 0, this->exten, PRIORITY_HINT, NULL, 07083 0, exten->app, ast_strdup(exten->data), ast_free_ptr, exten->registrar); 07084 /* rwlocks are not recursive locks */ 07085 exten = ast_hint_extension_nolock(NULL, this->context, this->exten); 07086 } 07087 07088 /* Find the hint in the list of hints */ 07089 AST_RWLIST_TRAVERSE(&hints, hint, list) { 07090 if (hint->exten == exten) 07091 break; 07092 } 07093 if (!exten || !hint) { 07094 /* this hint has been removed, notify the watchers */ 07095 while ((thiscb = AST_LIST_REMOVE_HEAD(&this->callbacks, entry))) { 07096 thiscb->callback(this->context, this->exten, AST_EXTENSION_REMOVED, thiscb->data); 07097 ast_free(thiscb); 07098 } 07099 } else { 07100 AST_LIST_APPEND_LIST(&hint->callbacks, &this->callbacks, entry); 07101 hint->laststate = this->laststate; 07102 } 07103 ast_free(this); 07104 } 07105 07106 AST_RWLIST_UNLOCK(&hints); 07107 ast_unlock_contexts(); 07108 endlocktime = ast_tvnow(); 07109 07110 /* the old list and hashtab no longer are relevant, delete them while the rest of asterisk 07111 is now freely using the new stuff instead */ 07112 07113 ast_hashtab_destroy(oldtable, NULL); 07114 07115 for (tmp = oldcontextslist; tmp; ) { 07116 struct ast_context *next; /* next starting point */ 07117 next = tmp->next; 07118 __ast_internal_context_destroy(tmp); 07119 tmp = next; 07120 } 07121 enddeltime = ast_tvnow(); 07122 07123 ft = ast_tvdiff_us(writelocktime, begintime); 07124 ft /= 1000000.0; 07125 ast_verb(3,"Time to scan old dialplan and merge leftovers back into the new: %8.6f sec\n", ft); 07126 07127 ft = ast_tvdiff_us(endlocktime, writelocktime); 07128 ft /= 1000000.0; 07129 ast_verb(3,"Time to restore hints and swap in new dialplan: %8.6f sec\n", ft); 07130 07131 ft = ast_tvdiff_us(enddeltime, endlocktime); 07132 ft /= 1000000.0; 07133 ast_verb(3,"Time to delete the old dialplan: %8.6f sec\n", ft); 07134 07135 ft = ast_tvdiff_us(enddeltime, begintime); 07136 ft /= 1000000.0; 07137 ast_verb(3,"Total time merge_contexts_delete: %8.6f sec\n", ft); 07138 return; 07139 }
| int ast_parseable_goto | ( | struct ast_channel * | chan, | |
| const char * | goto_string | |||
| ) |
Definition at line 10144 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().
10145 { 10146 return pbx_parseable_goto(chan, goto_string, 0); 10147 }
| int ast_pbx_outgoing_app | ( | const char * | type, | |
| format_t | format, | |||
| void * | data, | |||
| int | timeout, | |||
| const char * | app, | |||
| const char * | appdata, | |||
| int * | reason, | |||
| int | sync, | |||
| const char * | cid_num, | |||
| const char * | cid_name, | |||
| struct ast_variable * | vars, | |||
| const char * | account, | |||
| struct ast_channel ** | locked_channel | |||
| ) |
Synchronously or asynchronously make an outbound call and send it to a particular application with given extension
Definition at line 8492 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, 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().
08493 { 08494 struct ast_channel *chan; 08495 struct app_tmp *tmp; 08496 int res = -1, cdr_res = -1; 08497 struct outgoing_helper oh; 08498 08499 memset(&oh, 0, sizeof(oh)); 08500 oh.vars = vars; 08501 oh.account = account; 08502 08503 if (locked_channel) 08504 *locked_channel = NULL; 08505 if (ast_strlen_zero(app)) { 08506 res = -1; 08507 goto outgoing_app_cleanup; 08508 } 08509 if (synchronous) { 08510 chan = __ast_request_and_dial(type, format, NULL, data, timeout, reason, cid_num, cid_name, &oh); 08511 if (chan) { 08512 ast_set_variables(chan, vars); 08513 if (account) 08514 ast_cdr_setaccount(chan, account); 08515 if (chan->_state == AST_STATE_UP) { 08516 res = 0; 08517 ast_verb(4, "Channel %s was answered.\n", chan->name); 08518 tmp = ast_calloc(1, sizeof(*tmp)); 08519 if (!tmp) 08520 res = -1; 08521 else { 08522 ast_copy_string(tmp->app, app, sizeof(tmp->app)); 08523 if (appdata) 08524 ast_copy_string(tmp->data, appdata, sizeof(tmp->data)); 08525 tmp->chan = chan; 08526 if (synchronous > 1) { 08527 if (locked_channel) 08528 ast_channel_unlock(chan); 08529 ast_pbx_run_app(tmp); 08530 } else { 08531 if (locked_channel) 08532 ast_channel_lock(chan); 08533 if (ast_pthread_create_detached(&tmp->t, NULL, ast_pbx_run_app, tmp)) { 08534 ast_log(LOG_WARNING, "Unable to spawn execute thread on %s: %s\n", chan->name, strerror(errno)); 08535 ast_free(tmp); 08536 if (locked_channel) 08537 ast_channel_unlock(chan); 08538 ast_hangup(chan); 08539 res = -1; 08540 } else { 08541 if (locked_channel) 08542 *locked_channel = chan; 08543 } 08544 } 08545 } 08546 } else { 08547 ast_verb(4, "Channel %s was never answered.\n", chan->name); 08548 if (chan->cdr) { /* update the cdr */ 08549 /* here we update the status of the call, which sould be busy. 08550 * if that fails then we set the status to failed */ 08551 if (ast_cdr_disposition(chan->cdr, chan->hangupcause)) 08552 ast_cdr_failed(chan->cdr); 08553 } 08554 ast_hangup(chan); 08555 } 08556 } 08557 08558 if (res < 0) { /* the call failed for some reason */ 08559 if (*reason == 0) { /* if the call failed (not busy or no answer) 08560 * update the cdr with the failed message */ 08561 cdr_res = ast_pbx_outgoing_cdr_failed(); 08562 if (cdr_res != 0) { 08563 res = cdr_res; 08564 goto outgoing_app_cleanup; 08565 } 08566 } 08567 } 08568 08569 } else { 08570 struct async_stat *as; 08571 if (!(as = ast_calloc(1, sizeof(*as)))) { 08572 res = -1; 08573 goto outgoing_app_cleanup; 08574 } 08575 chan = __ast_request_and_dial(type, format, NULL, data, timeout, reason, cid_num, cid_name, &oh); 08576 if (!chan) { 08577 ast_free(as); 08578 res = -1; 08579 goto outgoing_app_cleanup; 08580 } 08581 as->chan = chan; 08582 ast_copy_string(as->app, app, sizeof(as->app)); 08583 if (appdata) 08584 ast_copy_string(as->appdata, appdata, sizeof(as->appdata)); 08585 as->timeout = timeout; 08586 ast_set_variables(chan, vars); 08587 if (account) 08588 ast_cdr_setaccount(chan, account); 08589 /* Start a new thread, and get something handling this channel. */ 08590 if (locked_channel) 08591 ast_channel_lock(chan); 08592 if (ast_pthread_create_detached(&as->p, NULL, async_wait, as)) { 08593 ast_log(LOG_WARNING, "Failed to start async wait\n"); 08594 ast_free(as); 08595 if (locked_channel) 08596 ast_channel_unlock(chan); 08597 ast_hangup(chan); 08598 res = -1; 08599 goto outgoing_app_cleanup; 08600 } else { 08601 if (locked_channel) 08602 *locked_channel = chan; 08603 } 08604 res = 0; 08605 } 08606 outgoing_app_cleanup: 08607 ast_variables_destroy(vars); 08608 return res; 08609 }
| int ast_pbx_outgoing_exten | ( | const char * | type, | |
| format_t | format, | |||
| void * | data, | |||
| int | timeout, | |||
| const char * | context, | |||
| const char * | exten, | |||
| int | priority, | |||
| int * | reason, | |||
| int | sync, | |||
| const char * | cid_num, | |||
| const char * | cid_name, | |||
| struct ast_variable * | vars, | |||
| const char * | account, | |||
| struct ast_channel ** | locked_channel | |||
| ) |
Synchronously or asynchronously make an outbound call and send it to a particular extension
Definition at line 8326 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, outgoing_helper::cid_name, outgoing_helper::cid_num, async_stat::context, ast_channel::context, outgoing_helper::context, 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().
08327 { 08328 struct ast_channel *chan; 08329 struct async_stat *as; 08330 int res = -1, cdr_res = -1; 08331 struct outgoing_helper oh; 08332 08333 if (synchronous) { 08334 oh.context = context; 08335 oh.exten = exten; 08336 oh.priority = priority; 08337 oh.cid_num = cid_num; 08338 oh.cid_name = cid_name; 08339 oh.account = account; 08340 oh.vars = vars; 08341 oh.parent_channel = NULL; 08342 08343 chan = __ast_request_and_dial(type, format, NULL, data, timeout, reason, cid_num, cid_name, &oh); 08344 if (channel) { 08345 *channel = chan; 08346 if (chan) 08347 ast_channel_lock(chan); 08348 } 08349 if (chan) { 08350 if (chan->_state == AST_STATE_UP) { 08351 res = 0; 08352 ast_verb(4, "Channel %s was answered.\n", chan->name); 08353 08354 if (synchronous > 1) { 08355 if (channel) 08356 ast_channel_unlock(chan); 08357 if (ast_pbx_run(chan)) { 08358 ast_log(LOG_ERROR, "Unable to run PBX on %s\n", chan->name); 08359 if (channel) 08360 *channel = NULL; 08361 ast_hangup(chan); 08362 chan = NULL; 08363 res = -1; 08364 } 08365 } else { 08366 if (ast_pbx_start(chan)) { 08367 ast_log(LOG_ERROR, "Unable to start PBX on %s\n", chan->name); 08368 if (channel) { 08369 *channel = NULL; 08370 ast_channel_unlock(chan); 08371 } 08372 ast_hangup(chan); 08373 res = -1; 08374 } 08375 chan = NULL; 08376 } 08377 } else { 08378 ast_verb(4, "Channel %s was never answered.\n", chan->name); 08379 08380 if (chan->cdr) { /* update the cdr */ 08381 /* here we update the status of the call, which sould be busy. 08382 * if that fails then we set the status to failed */ 08383 if (ast_cdr_disposition(chan->cdr, chan->hangupcause)) 08384 ast_cdr_failed(chan->cdr); 08385 } 08386 08387 if (channel) { 08388 *channel = NULL; 08389 ast_channel_unlock(chan); 08390 } 08391 ast_hangup(chan); 08392 chan = NULL; 08393 } 08394 } 08395 08396 if (res < 0) { /* the call failed for some reason */ 08397 if (*reason == 0) { /* if the call failed (not busy or no answer) 08398 * update the cdr with the failed message */ 08399 cdr_res = ast_pbx_outgoing_cdr_failed(); 08400 if (cdr_res != 0) { 08401 res = cdr_res; 08402 goto outgoing_exten_cleanup; 08403 } 08404 } 08405 08406 /* create a fake channel and execute the "failed" extension (if it exists) within the requested context */ 08407 /* check if "failed" exists */ 08408 if (ast_exists_extension(chan, context, "failed", 1, NULL)) { 08409 chan = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", NULL, 0, "OutgoingSpoolFailed"); 08410 if (chan) { 08411 char failed_reason[4] = ""; 08412 if (!ast_strlen_zero(context)) 08413 ast_copy_string(chan->context, context, sizeof(chan->context)); 08414 set_ext_pri(chan, "failed", 1); 08415 ast_set_variables(chan, vars); 08416 snprintf(failed_reason, sizeof(failed_reason), "%d", *reason); 08417 pbx_builtin_setvar_helper(chan, "REASON", failed_reason); 08418 if (account) 08419 ast_cdr_setaccount(chan, account); 08420 if (ast_pbx_run(chan)) { 08421 ast_log(LOG_ERROR, "Unable to run PBX on %s\n", chan->name); 08422 ast_hangup(chan); 08423 } 08424 chan = NULL; 08425 } 08426 } 08427 } 08428 } else { 08429 if (!(as = ast_calloc(1, sizeof(*as)))) { 08430 res = -1; 08431 goto outgoing_exten_cleanup; 08432 } 08433 chan = ast_request_and_dial(type, format, NULL, data, timeout, reason, cid_num, cid_name); 08434 if (channel) { 08435 *channel = chan; 08436 if (chan) 08437 ast_channel_lock(chan); 08438 } 08439 if (!chan) { 08440 ast_free(as); 08441 res = -1; 08442 goto outgoing_exten_cleanup; 08443 } 08444 as->chan = chan; 08445 ast_copy_string(as->context, context, sizeof(as->context)); 08446 set_ext_pri(as->chan, exten, priority); 08447 as->timeout = timeout; 08448 ast_set_variables(chan, vars); 08449 if (account) 08450 ast_cdr_setaccount(chan, account); 08451 if (ast_pthread_create_detached(&as->p, NULL, async_wait, as)) { 08452 ast_log(LOG_WARNING, "Failed to start async wait\n"); 08453 ast_free(as); 08454 if (channel) { 08455 *channel = NULL; 08456 ast_channel_unlock(chan); 08457 } 08458 ast_hangup(chan); 08459 res = -1; 08460 goto outgoing_exten_cleanup; 08461 } 08462 res = 0; 08463 } 08464 outgoing_exten_cleanup: 08465 ast_variables_destroy(vars); 08466 return res; 08467 }
| 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 |
| Zero | on success | |
| non-zero | on failure |
Definition at line 5031 of file pbx.c.
References ast_pbx_run_args().
Referenced by __analog_ss_thread(), analog_ss_thread(), ast_pbx_outgoing_exten(), async_wait(), do_idle_thread(), do_notify(), mgcp_ss(), pri_ss_thread(), skinny_newcall(), and unistim_ss().
05032 { 05033 return ast_pbx_run_args(c, NULL); 05034 }
| 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 |
| Zero | on success | |
| non-zero | on failure |
Definition at line 5016 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().
05017 { 05018 enum ast_pbx_result res = AST_PBX_SUCCESS; 05019 05020 if (increase_call_count(c)) { 05021 return AST_PBX_CALL_LIMIT; 05022 } 05023 05024 res = __ast_pbx_run(c, args); 05025 05026 decrease_call_count(); 05027 05028 return res; 05029 }
| 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 4994 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(), generic_recall(), 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(), pri_dchannel(), rpt_call(), sip_new(), skinny_new(), ss7_start_call(), unistim_new(), and usbradio_new().
04995 { 04996 pthread_t t; 04997 04998 if (!c) { 04999 ast_log(LOG_WARNING, "Asked to start thread on NULL channel?\n"); 05000 return AST_PBX_FAILED; 05001 } 05002 05003 if (increase_call_count(c)) 05004 return AST_PBX_CALL_LIMIT; 05005 05006 /* Start a new thread, and get something handling this channel. */ 05007 if (ast_pthread_create_detached(&t, NULL, pbx_thread, c)) { 05008 ast_log(LOG_WARNING, "Failed to create new channel thread\n"); 05009 decrease_call_count(); 05010 return AST_PBX_FAILED; 05011 } 05012 05013 return AST_PBX_SUCCESS; 05014 }
| int ast_processed_calls | ( | void | ) |
Retrieve the total number of calls processed through the PBX since last restart.
Definition at line 5041 of file pbx.c.
References totalcalls.
Referenced by ast_var_Config(), handle_chanlist(), and handle_showcalls().
05042 { 05043 return totalcalls; 05044 }
| 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 9878 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().
09879 { 09880 return ast_rwlock_rdlock(&con->lock); 09881 }
| int ast_rdlock_contexts | ( | void | ) |
Read locks the context list.
| 0 | on success | |
| -1 | on error |
Definition at line 9860 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(), handle_statechange(), manager_show_dialplan_helper(), pbx_extension_helper(), show_debug_helper(), show_dialplan_helper(), and unreference_cached_app().
09861 { 09862 return ast_mutex_lock(&conlock); 09863 }
| int ast_register_switch | ( | struct ast_switch * | sw | ) |
Register an alternative dialplan switch.
| sw | switch to register |
| 0 | success | |
| non-zero | failure |
Definition at line 5563 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().
05564 { 05565 struct ast_switch *tmp; 05566 05567 AST_RWLIST_WRLOCK(&switches); 05568 AST_RWLIST_TRAVERSE(&switches, tmp, list) { 05569 if (!strcasecmp(tmp->name, sw->name)) { 05570 AST_RWLIST_UNLOCK(&switches); 05571 ast_log(LOG_WARNING, "Switch '%s' already found\n", sw->name); 05572 return -1; 05573 } 05574 } 05575 AST_RWLIST_INSERT_TAIL(&switches, sw, list); 05576 AST_RWLIST_UNLOCK(&switches); 05577 05578 return 0; 05579 }
| 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 4575 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().
04576 { 04577 return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_SPAWN, found, combined_find_spawn); 04578 }
| int ast_str_get_hint | ( | struct ast_str ** | hint, | |
| ssize_t | hintsize, | |||
| struct ast_str ** | name, | |||
| ssize_t | namesize, | |||
| struct ast_channel * | c, | |||
| const char * | context, | |||
| const char * | exten | |||
| ) |
If an extension hint exists, return non-zero.
| hint | buffer for hint | |
| hintsize | Maximum size of hint buffer (<0 to prevent growth, >0 to limit growth to that number of bytes, or 0 for unlimited growth) | |
| name | buffer for name portion of hint | |
| namesize | Maximum size of name buffer (<0 to prevent growth, >0 to limit growth to that number of bytes, or 0 for unlimited growth) | |
| 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 4530 of file pbx.c.
References ast_get_extension_app(), ast_get_extension_app_data(), ast_hint_extension(), and ast_str_set().
Referenced by ast_str_retrieve_variable().
04531 { 04532 struct ast_exten *e = ast_hint_extension(c, context, exten); 04533 04534 if (!e) { 04535 return 0; 04536 } 04537 04538 if (hint) { 04539 ast_str_set(hint, hintsize, "%s", ast_get_extension_app(e)); 04540 } 04541 if (name) { 04542 const char *tmp = ast_get_extension_app_data(e); 04543 if (tmp) { 04544 ast_str_set(name, namesize, "%s", tmp); 04545 } 04546 } 04547 return -1; 04548 }
| const char* ast_str_retrieve_variable | ( | struct ast_str ** | buf, | |
| ssize_t | maxlen, | |||
| struct ast_channel * | chan, | |||
| struct varshead * | headp, | |||
| const char * | var | |||
| ) |
| buf | Result will be placed in this buffer. | |
| maxlen | -1 if the buffer should not grow, 0 if the buffer may grow to any size, and >0 if the buffer should grow only to that number of bytes. | |
| chan | Channel variables from which to extract values, and channel to pass to any dialplan functions. | |
| headp | If no channel is specified, a channel list from which to extract variable values | |
| var | Variable name to retrieve. |
Definition at line 2979 of file pbx.c.
References ast_party_caller::ani2, ARRAY_LEN, ast_channel_lock, ast_channel_unlock, ast_config_AST_SYSTEM_NAME, ast_debug, ast_eid_default, ast_eid_to_str(), AST_LIST_TRAVERSE, ast_party_id_presentation(), ast_rwlock_rdlock, ast_rwlock_unlock, ast_str_buffer(), ast_str_get_hint(), ast_str_set(), ast_str_substring(), ast_strdupa, ast_var_name(), ast_var_value(), ast_channel::caller, ast_channel::context, ast_channel::dialed, ast_var_t::entries, ast_channel::exten, globals, globalslock, ast_channel::hangupcause, ast_party_caller::id, ast_channel::name, ast_party_id::number, parse_variable_name(), ast_party_number::plan, ast_channel::priority, ast_party_dialed::transit_network_select, ast_channel::uniqueid, and ast_channel::varshead.
Referenced by ast_str_substitute_variables_full(), and pbx_retrieve_variable().
02980 { 02981 const char not_found = '\0'; 02982 char *tmpvar; 02983 const char *ret; 02984 const char *s; /* the result */ 02985 int offset, length; 02986 int i, need_substring; 02987 struct varshead *places[2] = { headp, &globals }; /* list of places where we may look */ 02988 02989 if (c) { 02990 ast_channel_lock(c); 02991 places[0] = &c->varshead; 02992 } 02993 /* 02994 * Make a copy of var because parse_variable_name() modifies the string. 02995 * Then if called directly, we might need to run substring() on the result; 02996 * remember this for later in 'need_substring', 'offset' and 'length' 02997 */ 02998 tmpvar = ast_strdupa(var); /* parse_variable_name modifies the string */ 02999 need_substring = parse_variable_name(tmpvar, &offset, &length, &i /* ignored */); 03000 03001 /* 03002 * Look first into predefined variables, then into variable lists. 03003 * Variable 's' points to the result, according to the following rules: 03004 * s == ¬_found (set at the beginning) means that we did not find a 03005 * matching variable and need to look into more places. 03006 * If s != ¬_found, s is a valid result string as follows: 03007 * s = NULL if the variable does not have a value; 03008 * you typically do this when looking for an unset predefined variable. 03009 * s = workspace if the result has been assembled there; 03010 * typically done when the result is built e.g. with an snprintf(), 03011 * so we don't need to do an additional copy. 03012 * s != workspace in case we have a string, that needs to be copied 03013 * (the ast_copy_string is done once for all at the end). 03014 * Typically done when the result is already available in some string. 03015 */ 03016 s = ¬_found; /* default value */ 03017 if (c) { /* This group requires a valid channel */ 03018 /* Names with common parts are looked up a piece at a time using strncmp. */ 03019 if (!strncmp(var, "CALL", 4)) { 03020 if (!strncmp(var + 4, "ING", 3)) { 03021 if (!strcmp(var + 7, "PRES")) { /* CALLINGPRES */ 03022 ast_str_set(str, maxlen, "%d", 03023 ast_party_id_presentation(&c->caller.id)); 03024 s = ast_str_buffer(*str); 03025 } else if (!strcmp(var + 7, "ANI2")) { /* CALLINGANI2 */ 03026 ast_str_set(str, maxlen, "%d", c->caller.ani2); 03027 s = ast_str_buffer(*str); 03028 } else if (!strcmp(var + 7, "TON")) { /* CALLINGTON */ 03029 ast_str_set(str, maxlen, "%d", c->caller.id.number.plan); 03030 s = ast_str_buffer(*str); 03031 } else if (!strcmp(var + 7, "TNS")) { /* CALLINGTNS */ 03032 ast_str_set(str, maxlen, "%d", c->dialed.transit_network_select); 03033 s = ast_str_buffer(*str); 03034 } 03035 } 03036 } else if (!strcmp(var, "HINT")) { 03037 s = ast_str_get_hint(str, maxlen, NULL, 0, c, c->context, c->exten) ? ast_str_buffer(*str) : NULL; 03038 } else if (!strcmp(var, "HINTNAME")) { 03039 s = ast_str_get_hint(NULL, 0, str, maxlen, c, c->context, c->exten) ? ast_str_buffer(*str) : NULL; 03040 } else if (!strcmp(var, "EXTEN")) { 03041 s = c->exten; 03042 } else if (!strcmp(var, "CONTEXT")) { 03043 s = c->context; 03044 } else if (!strcmp(var, "PRIORITY")) { 03045 ast_str_set(str, maxlen, "%d", c->priority); 03046 s = ast_str_buffer(*str); 03047 } else if (!strcmp(var, "CHANNEL")) { 03048 s = c->name; 03049 } else if (!strcmp(var, "UNIQUEID")) { 03050 s = c->uniqueid; 03051 } else if (!strcmp(var, "HANGUPCAUSE")) { 03052 ast_str_set(str, maxlen, "%d", c->hangupcause); 03053 s = ast_str_buffer(*str); 03054 } 03055 } 03056 if (s == ¬_found) { /* look for more */ 03057 if (!strcmp(var, "EPOCH")) { 03058 ast_str_set(str, maxlen, "%u", (int) time(NULL)); 03059 s = ast_str_buffer(*str); 03060 } else if (!strcmp(var, "SYSTEMNAME")) { 03061 s = ast_config_AST_SYSTEM_NAME; 03062 } else if (!strcmp(var, "ENTITYID")) { 03063 char workspace[20]; 03064 ast_eid_to_str(workspace, sizeof(workspace), &ast_eid_default); 03065 s = workspace; 03066 } 03067 } 03068 /* if not found, look into chanvars or global vars */ 03069 for (i = 0; s == ¬_found && i < ARRAY_LEN(places); i++) { 03070 struct ast_var_t *variables; 03071 if (!places[i]) 03072 continue; 03073 if (places[i] == &globals) 03074 ast_rwlock_rdlock(&globalslock); 03075 AST_LIST_TRAVERSE(places[i], variables, entries) { 03076 if (!strcasecmp(ast_var_name(variables), var)) { 03077 s = ast_var_value(variables); 03078 break; 03079 } 03080 } 03081 if (places[i] == &globals) 03082 ast_rwlock_unlock(&globalslock); 03083 } 03084 if (s == ¬_found || s == NULL) { 03085 ast_debug(5, "Result of '%s' is NULL\n", var); 03086 ret = NULL; 03087 } else { 03088 ast_debug(5, "Result of '%s' is '%s'\n", var, s); 03089 if (s != ast_str_buffer(*str)) { 03090 ast_str_set(str, maxlen, "%s", s); 03091 } 03092 ret = ast_str_buffer(*str); 03093 if (need_substring) { 03094 ret = ast_str_substring(*str, offset, length); 03095 ast_debug(2, "Final result of '%s' is '%s'\n", var, ret); 03096 } 03097 } 03098 03099 if (c) { 03100 ast_channel_unlock(c); 03101 } 03102 return ret; 03103 }
| void ast_str_substitute_variables | ( | struct ast_str ** | buf, | |
| ssize_t | maxlen, | |||
| struct ast_channel * | chan, | |||
| const char * | templ | |||
| ) |
| buf | Result will be placed in this buffer. | |
| maxlen | -1 if the buffer should not grow, 0 if the buffer may grow to any size, and >0 if the buffer should grow only to that number of bytes. | |
| chan | Channel variables from which to extract values, and channel to pass to any dialplan functions. | |
| templ | Variable template to expand. |
Definition at line 3757 of file pbx.c.
References ast_str_substitute_variables_full().
Referenced by _macro_exec(), acf_odbc_read(), acf_odbc_write(), cli_odbc_read(), cli_odbc_write(), config_curl(), custom_log(), cut_internal(), destroy_curl(), exec_exec(), func_mchan_read(), function_eval2(), function_fieldnum_helper(), function_fieldqty_helper(), handle_getvariablefull(), import_helper(), listfilter(), make_email_file(), realtime_curl(), realtime_multi_curl(), replace(), require_curl(), sendmail(), sendpage(), shift_pop(), store_curl(), syslog_log(), tryexec_exec(), unshift_push(), update2_curl(), and update_curl().
03758 { 03759 size_t used; 03760 ast_str_substitute_variables_full(buf, maxlen, chan, NULL, templ, &used); 03761 }
| void ast_str_substitute_variables_full | ( | struct ast_str ** | buf, | |
| ssize_t | maxlen, | |||
| struct ast_channel * | c, | |||
| struct varshead * | headp, | |||
| const char * | templ, | |||
| size_t * | used | |||
| ) |
| buf | Result will be placed in this buffer. | |
| maxlen | -1 if the buffer should not grow, 0 if the buffer may grow to any size, and >0 if the buffer should grow only to that number of bytes. | |
| c | Channel variables from which to extract values, and channel to pass to any dialplan functions. | |
| headp | If no channel is specified, a channel list from which to extract variable values | |
| templ | Variable template to expand. | |
| used | Number of bytes read from the template. |
Definition at line 3581 of file pbx.c.
References ast_channel_release(), ast_debug, ast_dummy_channel_alloc(), ast_free, ast_func_read2(), ast_log(), ast_str_append(), ast_str_append_substr(), ast_str_buffer(), ast_str_create(), ast_str_expr(), ast_str_reset(), ast_str_retrieve_variable(), ast_str_set_substr(), ast_str_strlen(), ast_str_substitute_variables_full(), ast_str_substring(), ast_strlen_zero(), len(), LOG_ERROR, LOG_WARNING, parse_variable_name(), and ast_channel::varshead.
Referenced by ast_str_substitute_variables(), ast_str_substitute_variables_full(), and ast_str_substitute_variables_varshead().
03582 { 03583 /* Substitutes variables into buf, based on string templ */ 03584 char *cp4 = NULL; 03585 const char *tmp, *whereweare; 03586 int orig_size = 0; 03587 int offset, offset2, isfunction; 03588 const char *nextvar, *nextexp, *nextthing; 03589 const char *vars, *vare; 03590 char *finalvars; 03591 int pos, brackets, needsub, len; 03592 struct ast_str *substr1 = ast_str_create(16), *substr2 = NULL, *substr3 = ast_str_create(16); 03593 03594 ast_str_reset(*buf); 03595 whereweare = tmp = templ; 03596 while (!ast_strlen_zero(whereweare)) { 03597 /* Assume we're copying the whole remaining string */ 03598 pos = strlen(whereweare); 03599 nextvar = NULL; 03600 nextexp = NULL; 03601 nextthing = strchr(whereweare, '$'); 03602 if (nextthing) { 03603 switch (nextthing[1]) { 03604 case '{': 03605 nextvar = nextthing; 03606 pos = nextvar - whereweare; 03607 break; 03608 case '[': 03609 nextexp = nextthing; 03610 pos = nextexp - whereweare; 03611 break; 03612 default: 03613 pos = 1; 03614 } 03615 } 03616 03617 if (pos) { 03618 /* Copy that many bytes */ 03619 ast_str_append_substr(buf, maxlen, whereweare, pos); 03620 03621 templ += pos; 03622 whereweare += pos; 03623 } 03624 03625 if (nextvar) { 03626 /* We have a variable. Find the start and end, and determine 03627 if we are going to have to recursively call ourselves on the 03628 contents */ 03629 vars = vare = nextvar + 2; 03630 brackets = 1; 03631 needsub = 0; 03632 03633 /* Find the end of it */ 03634 while (brackets && *vare) { 03635 if ((vare[0] == '$') && (vare[1] == '{')) { 03636 needsub++; 03637 } else if (vare[0] == '{') { 03638 brackets++; 03639 } else if (vare[0] == '}') { 03640 brackets--; 03641 } else if ((vare[0] == '$') && (vare[1] == '[')) 03642 needsub++; 03643 vare++; 03644 } 03645 if (brackets) 03646 ast_log(LOG_WARNING, "Error in extension logic (missing '}')\n"); 03647 len = vare - vars - 1; 03648 03649 /* Skip totally over variable string */ 03650 whereweare += (len + 3); 03651 03652 /* Store variable name (and truncate) */ 03653 ast_str_set_substr(&substr1, 0, vars, len); 03654 ast_debug(5, "Evaluating '%s' (from '%s' len %d)\n", ast_str_buffer(substr1), vars, len); 03655 03656 /* Substitute if necessary */ 03657 if (needsub) { 03658 size_t used; 03659 if (!substr2) { 03660 substr2 = ast_str_create(16); 03661 } 03662 03663 ast_str_substitute_variables_full(&substr2, 0, c, headp, ast_str_buffer(substr1), &used); 03664 finalvars = ast_str_buffer(substr2); 03665 } else { 03666 finalvars = ast_str_buffer(substr1); 03667 } 03668 03669 parse_variable_name(finalvars, &offset, &offset2, &isfunction); 03670 if (isfunction) { 03671 /* Evaluate function */ 03672 if (c || !headp) { 03673 cp4 = ast_func_read2(c, finalvars, &substr3, 0) ? NULL : ast_str_buffer(substr3); 03674 } else { 03675 struct varshead old; 03676 struct ast_channel *bogus = ast_dummy_channel_alloc(); 03677 if (bogus) { 03678 memcpy(&old, &bogus->varshead, sizeof(old)); 03679 memcpy(&bogus->varshead, headp, sizeof(bogus->varshead)); 03680 cp4 = ast_func_read2(c, finalvars, &substr3, 0) ? NULL : ast_str_buffer(substr3); 03681 /* Don't deallocate the varshead that was passed in */ 03682 memcpy(&bogus->varshead, &old, sizeof(bogus->varshead)); 03683 ast_channel_release(bogus); 03684 } else { 03685 ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution. Function results may be blank.\n"); 03686 } 03687 } 03688 ast_debug(2, "Function result is '%s'\n", cp4 ? cp4 : "(null)"); 03689 } else { 03690 /* Retrieve variable value */ 03691 ast_str_retrieve_variable(&substr3, 0, c, headp, finalvars); 03692 cp4 = ast_str_buffer(substr3); 03693 } 03694 if (cp4) { 03695 ast_str_substring(substr3, offset, offset2); 03696 ast_str_append(buf, maxlen, "%s", ast_str_buffer(substr3)); 03697 } 03698 } else if (nextexp) { 03699 /* We have an expression. Find the start and end, and determine 03700 if we are going to have to recursively call ourselves on the 03701 contents */ 03702 vars = vare = nextexp + 2; 03703 brackets = 1; 03704 needsub = 0; 03705 03706 /* Find the end of it */ 03707 while (brackets && *vare) { 03708 if ((vare[0] == '$') && (vare[1] == '[')) { 03709 needsub++; 03710 brackets++; 03711 vare++; 03712 } else if (vare[0] == '[') { 03713 brackets++; 03714 } else if (vare[0] == ']') { 03715 brackets--; 03716 } else if ((vare[0] == '$') && (vare[1] == '{')) { 03717 needsub++; 03718 vare++; 03719 } 03720 vare++; 03721 } 03722 if (brackets) 03723 ast_log(LOG_WARNING, "Error in extension logic (missing ']')\n"); 03724 len = vare - vars - 1; 03725 03726 /* Skip totally over expression */ 03727 whereweare += (len + 3); 03728 03729 /* Store variable name (and truncate) */ 03730 ast_str_set_substr(&substr1, 0, vars, len); 03731 03732 /* Substitute if necessary */ 03733 if (needsub) { 03734 size_t used; 03735 if (!substr2) { 03736 substr2 = ast_str_create(16); 03737 } 03738 03739 ast_str_substitute_variables_full(&substr2, 0, c, headp, ast_str_buffer(substr1), &used); 03740 finalvars = ast_str_buffer(substr2); 03741 } else { 03742 finalvars = ast_str_buffer(substr1); 03743 } 03744 03745 if (ast_str_expr(&substr3, 0, c, finalvars)) { 03746 ast_debug(2, "Expression result is '%s'\n", ast_str_buffer(substr3)); 03747 } 03748 ast_str_append(buf, maxlen, "%s", ast_str_buffer(substr3)); 03749 } 03750 } 03751 *used = ast_str_strlen(*buf) - orig_size; 03752 ast_free(substr1); 03753 ast_free(substr2); 03754 ast_free(substr3); 03755 }
| void ast_str_substitute_variables_varshead | ( | struct ast_str ** | buf, | |
| ssize_t | maxlen, | |||
| struct varshead * | headp, | |||
| const char * | templ | |||
| ) |
| buf | Result will be placed in this buffer. | |
| maxlen | -1 if the buffer should not grow, 0 if the buffer may grow to any size, and >0 if the buffer should grow only to that number of bytes. | |
| headp | If no channel is specified, a channel list from which to extract variable values | |
| templ | Variable template to expand. |
Definition at line 3763 of file pbx.c.
References ast_str_substitute_variables_full().
Referenced by add_user_extension(), build_user_routes(), phoneprov_callback(), pp_each_extension_helper(), and pp_each_user_helper().
03764 { 03765 size_t used; 03766 ast_str_substitute_variables_full(buf, maxlen, NULL, headp, templ, &used); 03767 }
| 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 9883 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().
09884 { 09885 return ast_rwlock_unlock(&con->lock); 09886 }
| int ast_unlock_contexts | ( | void | ) |
Unlocks contexts.
| 0 | on success | |
| -1 | on failure |
Definition at line 9865 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(), handle_statechange(), manager_show_dialplan_helper(), pbx_extension_helper(), show_debug_helper(), show_dialplan_helper(), and unreference_cached_app().
09866 { 09867 return ast_mutex_unlock(&conlock); 09868 }
| void ast_unregister_switch | ( | struct ast_switch * | sw | ) |
Unregister an alternative switch.
| sw | switch to unregister |
Definition at line 5581 of file pbx.c.
References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.
Referenced by __unload_module(), and unload_module().
05582 { 05583 AST_RWLIST_WRLOCK(&switches); 05584 AST_RWLIST_REMOVE(&switches, sw, list); 05585 AST_RWLIST_UNLOCK(&switches); 05586 }
| struct ast_exten* ast_walk_context_extensions | ( | struct ast_context * | con, | |
| struct ast_exten * | priority | |||
| ) | [read] |
Definition at line 9997 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().
09999 { 10000 if (!exten) 10001 return con ? con->root : NULL; 10002 else 10003 return exten->next; 10004 }
| struct ast_ignorepat* ast_walk_context_ignorepats | ( | struct ast_context * | con, | |
| struct ast_ignorepat * | ip | |||
| ) | [read] |
Definition at line 10030 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().
10032 { 10033 if (!ip) 10034 return con ? con->ignorepats : NULL; 10035 else 10036 return ip->next; 10037 }
| struct ast_include* ast_walk_context_includes | ( | struct ast_context * | con, | |
| struct ast_include * | inc | |||
| ) | [read] |
Definition at line 10021 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().
10023 { 10024 if (!inc) 10025 return con ? con->includes : NULL; 10026 else 10027 return inc->next; 10028 }
| struct ast_sw* ast_walk_context_switches | ( | struct ast_context * | con, | |
| struct ast_sw * | sw | |||
| ) | [read] |
Definition at line 10006 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().
10008 { 10009 if (!sw) 10010 return con ? AST_LIST_FIRST(&con->alts) : NULL; 10011 else 10012 return AST_LIST_NEXT(sw, list); 10013 }
| struct ast_context* ast_walk_contexts | ( | struct ast_context * | con | ) | [read] |
Definition at line 9992 of file pbx.c.
References contexts, and ast_context::next.
Referenced by _macro_exec(), ast_context_find(), 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_matching_endwhile(), find_matching_priority(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), 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 10015 of file pbx.c.
References ast_exten::peer.
Referenced by complete_dialplan_remove_extension(), find_matching_priority(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), show_dialplan_helper(), and unreference_cached_app().
10017 { 10018 return priority ? priority->peer : exten; 10019 }
| 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 9873 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().
09874 { 09875 return ast_rwlock_wrlock(&con->lock); 09876 }
| int ast_wrlock_contexts | ( | void | ) |
Write locks the context list.
| 0 | on success | |
| -1 | on error |
Definition at line 9855 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().
09856 { 09857 return ast_mutex_lock(&conlock); 09858 }
| void pbx_builtin_clear_globals | ( | void | ) |
Definition at line 9645 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().
09646 { 09647 struct ast_var_t *vardata; 09648 09649 ast_rwlock_wrlock(&globalslock); 09650 while ((vardata = AST_LIST_REMOVE_HEAD(&globals, entries))) 09651 ast_var_delete(vardata); 09652 ast_rwlock_unlock(&globalslock); 09653 }
| const char* pbx_builtin_getvar_helper | ( | struct ast_channel * | chan, | |
| const char * | name | |||
| ) |
Return a pointer to the value of the corresponding channel variable.
This function will return a pointer to the buffer inside the channel variable. This value should only be accessed with the channel locked. If the value needs to be kept around, it should be done by using the following thread-safe code:
const char *var; ast_channel_lock(chan); if ((var = pbx_builtin_getvar_helper(chan, "MYVAR"))) { var = ast_strdupa(var); } ast_channel_unlock(chan);
Definition at line 9407 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(), add_header_max_forwards(), agentmonitoroutgoing_exec(), analog_call(), append_channel_vars(), array(), ast_bridge_call(), ast_bridge_timelimit(), ast_call_forward(), ast_channel_connected_line_macro(), ast_channel_redirecting_macro(), ast_eivr_getvariable(), ast_hangup(), ast_monitor_stop(), bridge_play_sounds(), builtin_atxfer(), builtin_automixmonitor(), builtin_automonitor(), check_goto_on_transfer(), common_exec(), conf_run(), confbridge_exec(), crement_function_read(), dahdi_hangup(), dahdi_r2_answer(), dahdi_r2_get_channel_category(), dial_exec_full(), do_forward(), dundi_exec(), dundi_helper(), feature_interpret(), find_by_mark(), find_conf_realtime(), findparkinglotname(), func_channel_read(), generic_fax_exec(), get_also_info(), get_index(), get_refer_info(), global_read(), hash_read(), iax2_call(), iax2_exec(), import_ch(), leave_voicemail(), 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(), pbx_builtin_gotoiftime(), queue_exec(), real_ctx(), receivefax_exec(), retrydial_exec(), ring_entry(), run_agi(), sendfax_exec(), set_config_flags(), set_local_info(), sig_pri_call(), sig_pri_hangup(), sig_ss7_call(), sig_ss7_hangup(), sip_addheader(), sla_trunk_exec(), speech_background(), try_calling(), try_suggested_sip_codec(), update_bridge_vars(), and wait_for_answer().
09408 { 09409 struct ast_var_t *variables; 09410 const char *ret = NULL; 09411 int i; 09412 struct varshead *places[2] = { NULL, &globals }; 09413 09414 if (!name) 09415 return NULL; 09416 09417 if (chan) { 09418 ast_channel_lock(chan); 09419 places[0] = &chan->varshead; 09420 } 09421 09422 for (i = 0; i < 2; i++) { 09423 if (!places[i]) 09424 continue; 09425 if (places[i] == &globals) 09426 ast_rwlock_rdlock(&globalslock); 09427 AST_LIST_TRAVERSE(places[i], variables, entries) { 09428 if (!strcmp(name, ast_var_name(variables))) { 09429 ret = ast_var_value(variables); 09430 break; 09431 } 09432 } 09433 if (places[i] == &globals) 09434 ast_rwlock_unlock(&globalslock); 09435 if (ret) 09436 break; 09437 } 09438 09439 if (chan) 09440 ast_channel_unlock(chan); 09441 09442 return ret; 09443 }
| 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 9445 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().
09446 { 09447 struct ast_var_t *newvariable; 09448 struct varshead *headp; 09449 09450 if (name[strlen(name)-1] == ')') { 09451 char *function = ast_strdupa(name); 09452 09453 ast_log(LOG_WARNING, "Cannot push a value onto a function\n"); 09454 ast_func_write(chan, function, value); 09455 return; 09456 } 09457 09458 if (chan) { 09459 ast_channel_lock(chan); 09460 headp = &chan->varshead; 09461 } else { 09462 ast_rwlock_wrlock(&globalslock); 09463 headp = &globals; 09464 } 09465 09466 if (value) { 09467 if (headp == &globals) 09468 ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value); 09469 newvariable = ast_var_assign(name, value); 09470 AST_LIST_INSERT_HEAD(headp, newvariable, entries); 09471 } 09472 09473 if (chan) 09474 ast_channel_unlock(chan); 09475 else 09476 ast_rwlock_unlock(&globalslock); 09477 }
| int pbx_builtin_raise_exception | ( | struct ast_channel * | chan, | |
| const char * | data | |||
| ) |
Definition at line 3117 of file pbx.c.
References ast_calloc_with_stringfields, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_datastore_alloc, ast_datastore_free(), ast_string_field_set, ast_channel::context, ast_datastore::data, exception_store_info, ast_channel::exten, ast_channel::priority, pbx_exception::priority, and set_ext_pri().
Referenced by __ast_pbx_run().
03118 { 03119 struct ast_datastore *ds = ast_channel_datastore_find(chan, &exception_store_info, NULL); 03120 struct pbx_exception *exception = NULL; 03121 03122 if (!ds) { 03123 ds = ast_datastore_alloc(&exception_store_info, NULL); 03124 if (!ds) 03125 return -1; 03126 if (!(exception = ast_calloc_with_stringfields(1, struct pbx_exception, 128))) { 03127 ast_datastore_free(ds); 03128 return -1; 03129 } 03130 ds->data = exception; 03131 ast_channel_datastore_add(chan, ds); 03132 } else 03133 exception = ds->data; 03134 03135 ast_string_field_set(exception, reason, reason); 03136 ast_string_field_set(exception, context, chan->context); 03137 ast_string_field_set(exception, exten, chan->exten); 03138 exception->priority = chan->priority; 03139 set_ext_pri(chan, "e", 0); 03140 return 0; 03141 }
| 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 ast_str_create). |
Definition at line 9376 of file pbx.c.
References ast_channel_lock, ast_channel_unlock, AST_LIST_TRAVERSE, ast_log(), ast_str_append(), ast_str_reset(), ast_var_name(), ast_var_value(), ast_var_t::entries, LOG_ERROR, total, var, and ast_channel::varshead.
Referenced by ast_var_channels_table(), dumpchan_exec(), handle_show_chanvar(), handle_showchan(), and vars2manager().
09377 { 09378 struct ast_var_t *variables; 09379 const char *var, *val; 09380 int total = 0; 09381 09382 if (!chan) 09383 return 0; 09384 09385 ast_str_reset(*buf); 09386 09387 ast_channel_lock(chan); 09388 09389 AST_LIST_TRAVERSE(&chan->varshead, variables, entries) { 09390 if ((var = ast_var_name(variables)) && (val = ast_var_value(variables)) 09391 /* && !ast_strlen_zero(var) && !ast_strlen_zero(val) */ 09392 ) { 09393 if (ast_str_append(buf, 0, "%s=%s\n", var, val) < 0) { 09394 ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n"); 09395 break; 09396 } else 09397 total++; 09398 } else 09399 break; 09400 } 09401 09402 ast_channel_unlock(chan); 09403 09404 return total; 09405 }
| int pbx_builtin_setvar | ( | struct ast_channel * | chan, | |
| const char * | data | |||
| ) |
Parse and set a single channel variable, where the name and value are separated with an '=' character.
Definition at line 9537 of file pbx.c.
References ast_compat_app_set, ast_log(), ast_strdupa, ast_strlen_zero(), LOG_WARNING, pbx_builtin_setvar_helper(), pbx_builtin_setvar_multiple(), strsep(), and value.
Referenced by ast_compile_ael2(), and rpt_exec().
09538 { 09539 char *name, *value, *mydata; 09540 09541 if (ast_compat_app_set) { 09542 return pbx_builtin_setvar_multiple(chan, data); 09543 } 09544 09545 if (ast_strlen_zero(data)) { 09546 ast_log(LOG_WARNING, "Set requires one variable name/value pair.\n"); 09547 return 0; 09548 } 09549 09550 mydata = ast_strdupa(data); 09551 name = strsep(&mydata, "="); 09552 value = mydata; 09553 if (!value) { 09554 ast_log(LOG_WARNING, "Set requires an '=' to be a valid assignment.\n"); 09555 return 0; 09556 } 09557 09558 if (strchr(name, ' ')) { 09559 ast_log(LOG_WARNING, "Please avoid unnecessary spaces on variables as it may lead to unexpected results ('%s' set to '%s').\n", name, mydata); 09560 } 09561 09562 pbx_builtin_setvar_helper(chan, name, value); 09563 09564 return 0; 09565 }
| int pbx_builtin_setvar_helper | ( | struct ast_channel * | chan, | |
| const char * | name, | |||
| const char * | value | |||
| ) |
Add a variable to the channel variable stack, removing the most recently set value for the same name.
Definition at line 9479 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_channel::uniqueid, and ast_channel::varshead.
Referenced by __ast_pbx_run(), __oh323_new(), _macro_exec(), _while_exec(), acf_curl_helper(), acf_fetch(), acf_odbc_read(), acf_odbc_write(), acf_transaction_write(), action_atxfer(), action_setvar(), admin_exec(), agi_exec_full(), aji_status_exec(), analog_ss_thread(), aqm_exec(), array(), ast_bridge_call(), ast_cc_agent_set_interfaces_chanvar(), ast_cel_fabricate_channel_from_event(), ast_eivr_setvariable(), ast_iax2_new(), ast_monitor_start(), ast_monitor_stop(), ast_pbx_outgoing_exten(), ast_rtp_instance_set_stats_vars(), ast_set_cc_interfaces_chanvar(), ast_set_variables(), asyncgoto_exec(), background_detect_exec(), bridge_exec(), bridge_play_sounds(), builtin_atxfer(), builtin_automixmonitor(), builtin_automonitor(), builtin_blindtransfer(), cb_events(), ccreq_exec(), chanavail_exec(), channel_spy(), commit_exec(), conf_run(), controlplayback_exec(), count_exec(), crement_function_read(), dahdi_handle_dtmfup(), dahdi_new(), dial_exec_full(), disa_exec(), do_waiting(), end_bridge_callback(), export_aoc_vars(), export_ch(), feature_exec_app(), feature_request_and_dial(), frame_set_var(), func_mchan_write(), function_db_delete(), function_db_exists(), function_db_read(), function_realtime_store(), get_rdnis(), get_refer_info(), global_write(), gosub_release_frame(), handle_incoming(), handle_request_bye(), handle_request_refer(), handle_set_chanvar(), handle_set_global(), handle_setvariable(), hash_read(), hash_write(), isAnsweringMachine(), leave_queue(), leave_voicemail(), local_hangup(), lua_set_variable(), lua_set_variable_value(), macro_fixup(), manage_parkinglot(), mgcp_new(), minivm_accmess_exec(), minivm_delete_exec(), minivm_greet_exec(), minivm_notify_exec(), minivm_record_exec(), misdn_call(), mixmonitor_exec(), my_handle_dtmfup(), originate_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), park_exec_full(), parse_moved_contact(), pbx_builtin_background(), pbx_builtin_gotoiftime(), 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(), pri_dchannel(), privacy_exec(), process_ast_dsp(), process_sdp(), read_exec(), readexten_exec(), readfile_exec(), realtimefield_read(), receivefax_exec(), record_exec(), reload_module(), return_exec(), rollback_exec(), rotate_file(), rpt_exec(), rqm_exec(), sendfax_exec(), sendimage_exec(), sendtext_exec(), sendurl_exec(), set(), set_channel_variables(), set_queue_result(), shift_pop(), sig_pri_new_ast_channel(), sig_ss7_new_ast_channel(), sip_addheader(), sip_hangup(), sip_new(), sip_read(), skinny_new(), sla_calc_trunk_timeouts(), sla_station_exec(), sla_trunk_exec(), socket_process(), speech_create(), ss7_start_call(), start_monitor_exec(), system_exec_helper(), testtime_write(), transfer_exec(), transmit(), tryexec_exec(), unshift_push(), update_bridge_vars(), update_qe_rule(), upqm_exec(), vm_box_exists(), vm_exec(), vmauthenticate(), waituntil_exec(), and zapateller_exec().
09480 { 09481 struct ast_var_t *newvariable; 09482 struct varshead *headp; 09483 const char *nametail = name; 09484 09485 if (name[strlen(name) - 1] == ')') { 09486 char *function = ast_strdupa(name); 09487 09488 return ast_func_write(chan, function, value); 09489 } 09490 09491 if (chan) { 09492 ast_channel_lock(chan); 09493 headp = &chan->varshead; 09494 } else { 09495 ast_rwlock_wrlock(&globalslock); 09496 headp = &globals; 09497 } 09498 09499 /* For comparison purposes, we have to strip leading underscores */ 09500 if (*nametail == '_') { 09501 nametail++; 09502 if (*nametail == '_') 09503 nametail++; 09504 } 09505 09506 AST_LIST_TRAVERSE_SAFE_BEGIN(headp, newvariable, entries) { 09507 if (strcmp(ast_var_name(newvariable), nametail) == 0) { 09508 /* there is already such a variable, delete it */ 09509 AST_LIST_REMOVE_CURRENT(entries); 09510 ast_var_delete(newvariable); 09511 break; 09512 } 09513 } 09514 AST_LIST_TRAVERSE_SAFE_END; 09515 09516 if (value) { 09517 if (headp == &globals) 09518 ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value); 09519 newvariable = ast_var_assign(name, value); 09520 AST_LIST_INSERT_HEAD(headp, newvariable, entries); 09521 manager_event(EVENT_FLAG_DIALPLAN, "VarSet", 09522 "Channel: %s\r\n" 09523 "Variable: %s\r\n" 09524 "Value: %s\r\n" 09525 "Uniqueid: %s\r\n", 09526 chan ? chan->name : "none", name, value, 09527 chan ? chan->uniqueid : "none"); 09528 } 09529 09530 if (chan) 09531 ast_channel_unlock(chan); 09532 else 09533 ast_rwlock_unlock(&globalslock); 09534 return 0; 09535 }
| int pbx_builtin_setvar_multiple | ( | struct ast_channel * | chan, | |
| const char * | data | |||
| ) |
Parse and set multiple channel variables, where the pairs are separated by the ',' character, and name and value are separated with an '=' character.
Definition at line 9567 of file pbx.c.
References args, AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_log(), AST_NONSTANDARD_APP_ARGS, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_channel::context, ast_channel::exten, LOG_WARNING, ast_channel::name, pbx_builtin_setvar_helper(), ast_channel::priority, and value.
Referenced by pbx_builtin_setvar(), queue_function_var(), set_queue_variables(), and try_calling().
09568 { 09569 char *data; 09570 int x; 09571 AST_DECLARE_APP_ARGS(args, 09572 AST_APP_ARG(pair)[24]; 09573 ); 09574 AST_DECLARE_APP_ARGS(pair, 09575 AST_APP_ARG(name); 09576 AST_APP_ARG(value); 09577 ); 09578 09579 if (ast_strlen_zero(vdata)) { 09580 ast_log(LOG_WARNING, "MSet requires at least one variable name/value pair.\n"); 09581 return 0; 09582 } 09583 09584 data = ast_strdupa(vdata); 09585 AST_STANDARD_APP_ARGS(args, data); 09586 09587 for (x = 0; x < args.argc; x++) { 09588 AST_NONSTANDARD_APP_ARGS(pair, args.pair[x], '='); 09589 if (pair.argc == 2) { 09590 pbx_builtin_setvar_helper(chan, pair.name, pair.value); 09591 if (strchr(pair.name, ' ')) 09592 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); 09593 } else if (!chan) { 09594 ast_log(LOG_WARNING, "MSet: ignoring entry '%s' with no '='\n", pair.name); 09595 } else { 09596 ast_log(LOG_WARNING, "MSet: ignoring entry '%s' with no '=' (in %s@%s:%d\n", pair.name, chan->exten, chan->context, chan->priority); 09597 } 09598 } 09599 09600 return 0; 09601 }
| 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 9655 of file pbx.c.
References ast_strlen_zero().
Referenced by _macro_exec(), _while_exec(), acf_if(), execif_exec(), gosubif_exec(), macroif_exec(), pbx_builtin_gotoif(), and testtime_write().
09656 { 09657 int res; 09658 if (ast_strlen_zero(condition)) { /* NULL or empty strings are false */ 09659 return 0; 09660 } else if (sscanf(condition, "%30d", &res) == 1) { /* Numbers are evaluated for truth */ 09661 return res; 09662 } else { /* Strings are true */ 09663 return 1; 09664 } 09665 }
| int pbx_exec | ( | struct ast_channel * | c, | |
| struct ast_app * | app, | |||
| const char * | data | |||
| ) |
Execute an application.
| c | channel to execute on | |
| app | which app to execute | |
| data | the data passed into the app |
| 0 | success | |
| -1 | failure |
| c | Channel | |
| app | Application | |
| data | Data for execution |
Definition at line 1371 of file pbx.c.
References __ast_module_user_add(), __ast_module_user_remove(), ast_channel::appl, ast_cdr_setapp(), AST_CEL_APP_END, AST_CEL_APP_START, ast_cel_report_event(), ast_check_hangup(), ast_log(), ast_opt_dont_warn, ast_strlen_zero(), ast_channel::cdr, ast_channel::data, ast_app::execute, LOG_WARNING, ast_app::module, ast_app::name, and S_OR.
Referenced by answer_exec_run(), ast_app_run_macro(), ast_bridge_call(), ast_pbx_run_app(), async_wait(), builtin_automixmonitor(), builtin_automonitor(), conf_run(), dial_exec_full(), do_magic_pickup(), dundi_exec(), exec_exec(), execif_exec(), feature_exec_app(), forward_message(), handle_exec(), handle_gosub(), iax2_exec(), lua_pbx_exec(), page_exec(), pbx_builtin_execiftime(), pbx_extension_helper(), realtime_exec(), try_calling(), and tryexec_exec().
01374 { 01375 int res; 01376 struct ast_module_user *u = NULL; 01377 const char *saved_c_appl; 01378 const char *saved_c_data; 01379 01380 if (c->cdr && !ast_check_hangup(c)) 01381 ast_cdr_setapp(c->cdr, app->name, data); 01382 01383 /* save channel values */ 01384 saved_c_appl= c->appl; 01385 saved_c_data= c->data; 01386 01387 c->appl = app->name; 01388 c->data = data; 01389 ast_cel_report_event(c, AST_CEL_APP_START, NULL, NULL, NULL); 01390 01391 if (app->module) 01392 u = __ast_module_user_add(app->module, c); 01393 if (strcasecmp(app->name, "system") && !ast_strlen_zero(data) && 01394 strchr(data, '|') && !strchr(data, ',') && !ast_opt_dont_warn) { 01395 ast_log(LOG_WARNING, "The application delimiter is now the comma, not " 01396 "the pipe. Did you forget to convert your dialplan? (%s(%s))\n", 01397 app->name, (char *) data); 01398 } 01399 res = app->execute(c, S_OR(data, "")); 01400 if (app->module && u) 01401 __ast_module_user_remove(app->module, u); 01402 ast_cel_report_event(c, AST_CEL_APP_END, NULL, NULL, NULL); 01403 /* restore channel values */ 01404 c->appl = saved_c_appl; 01405 c->data = saved_c_data; 01406 return res; 01407 }
| 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 2543 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_switch::canmatch, scoreboard::canmatch_exten, 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_NOTICE, LOG_WARNING, match(), matchcid(), ast_switch::matchmore, ast_context::name, ast_sw::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(), switch_data, pbx_find_info::swo, scoreboard::total_length, scoreboard::total_specificity, and trie_find_next_match().
Referenced by ast_hint_extension_nolock(), ast_merge_contexts_and_delete(), ast_parking_ext_valid(), check_goto(), check_pval_item(), pbx_extension_helper(), pbx_find_extension(), and register_peer_exten().
02547 { 02548 int x, res; 02549 struct ast_context *tmp = NULL; 02550 struct ast_exten *e = NULL, *eroot = NULL; 02551 struct ast_include *i = NULL; 02552 struct ast_sw *sw = NULL; 02553 struct ast_exten pattern = {NULL, }; 02554 struct scoreboard score = {0, }; 02555 struct ast_str *tmpdata = NULL; 02556 02557 pattern.label = label; 02558 pattern.priority = priority; 02559 #ifdef NEED_DEBUG_HERE 02560 ast_log(LOG_NOTICE, "Looking for cont/ext/prio/label/action = %s/%s/%d/%s/%d\n", context, exten, priority, label, (int) action); 02561 #endif 02562 02563 /* Initialize status if appropriate */ 02564 if (q->stacklen == 0) { 02565 q->status = STATUS_NO_CONTEXT; 02566 q->swo = NULL; 02567 q->data = NULL; 02568 q->foundcontext = NULL; 02569 } else if (q->stacklen >= AST_PBX_MAX_STACK) { 02570 ast_log(LOG_WARNING, "Maximum PBX stack exceeded\n"); 02571 return NULL; 02572 } 02573 02574 /* Check first to see if we've already been checked */ 02575 for (x = 0; x < q->stacklen; x++) { 02576 if (!strcasecmp(q->incstack[x], context)) 02577 return NULL; 02578 } 02579 02580 if (bypass) { /* bypass means we only look there */ 02581 tmp = bypass; 02582 } else { /* look in contexts */ 02583 struct fake_context item; 02584 02585 ast_copy_string(item.name, context, sizeof(item.name)); 02586 02587 tmp = ast_hashtab_lookup(contexts_table, &item); 02588 if (!tmp) { 02589 return NULL; 02590 } 02591 } 02592 02593 if (q->status < STATUS_NO_EXTENSION) 02594 q->status = STATUS_NO_EXTENSION; 02595 02596 /* Do a search for matching extension */ 02597 02598 eroot = NULL; 02599 score.total_specificity = 0; 02600 score.exten = 0; 02601 score.total_length = 0; 02602 if (!tmp->pattern_tree && tmp->root_table) { 02603 create_match_char_tree(tmp); 02604 #ifdef NEED_DEBUG 02605 ast_log(LOG_DEBUG, "Tree Created in context %s:\n", context); 02606 log_match_char_tree(tmp->pattern_tree," "); 02607 #endif 02608 } 02609 #ifdef NEED_DEBUG 02610 ast_log(LOG_NOTICE, "The Trie we are searching in:\n"); 02611 log_match_char_tree(tmp->pattern_tree, ":: "); 02612 #endif 02613 02614 do { 02615 if (!ast_strlen_zero(overrideswitch)) { 02616 char *osw = ast_strdupa(overrideswitch), *name; 02617 struct ast_switch *asw; 02618 ast_switch_f *aswf = NULL; 02619 char *datap; 02620 int eval = 0; 02621 02622 name = strsep(&osw, "/"); 02623 asw = pbx_findswitch(name); 02624 02625 if (!asw) { 02626 ast_log(LOG_WARNING, "No such switch '%s'\n", name); 02627 break; 02628 } 02629 02630 if (osw && strchr(osw, '$')) { 02631 eval = 1; 02632 } 02633 02634 if (eval && !(tmpdata = ast_str_thread_get(&switch_data, 512))) { 02635 ast_log(LOG_WARNING, "Can't evaluate overrideswitch?!"); 02636 break; 02637 } else if (eval) { 02638 /* Substitute variables now */ 02639 pbx_substitute_variables_helper(chan, osw, ast_str_buffer(tmpdata), ast_str_size(tmpdata)); 02640 datap = ast_str_buffer(tmpdata); 02641 } else { 02642 datap = osw; 02643 } 02644 02645 /* equivalent of extension_match_core() at the switch level */ 02646 if (action == E_CANMATCH) 02647 aswf = asw->canmatch; 02648 else if (action == E_MATCHMORE) 02649 aswf = asw->matchmore; 02650 else /* action == E_MATCH */ 02651 aswf = asw->exists; 02652 if (!aswf) { 02653 res = 0; 02654 } else { 02655 if (chan) { 02656 ast_autoservice_start(chan); 02657 } 02658 res = aswf(chan, context, exten, priority, callerid, datap); 02659 if (chan) { 02660 ast_autoservice_stop(chan); 02661 } 02662 } 02663 if (res) { /* Got a match */ 02664 q->swo = asw; 02665 q->data = datap; 02666 q->foundcontext = context; 02667 /* XXX keep status = STATUS_NO_CONTEXT ? */ 02668 return NULL; 02669 } 02670 } 02671 } while (0); 02672 02673 if (extenpatternmatchnew) { 02674 new_find_extension(exten, &score, tmp->pattern_tree, 0, 0, callerid, label, action); 02675 eroot = score.exten; 02676 02677 if (score.last_char == '!' && action == E_MATCHMORE) { 02678 /* We match an extension ending in '!'. 02679 * The decision in this case is final and is NULL (no match). 02680 */ 02681 #ifdef NEED_DEBUG_HERE 02682 ast_log(LOG_NOTICE,"Returning MATCHMORE NULL with exclamation point.\n"); 02683 #endif 02684 return NULL; 02685 } 02686 02687 if (!eroot && (action == E_CANMATCH || action == E_MATCHMORE) && score.canmatch_exten) { 02688 q->status = STATUS_SUCCESS; 02689 #ifdef NEED_DEBUG_HERE 02690 ast_log(LOG_NOTICE,"Returning CANMATCH exten %s\n", score.canmatch_exten->exten); 02691 #endif 02692 return score.canmatch_exten; 02693 } 02694 02695 if ((action == E_MATCHMORE || action == E_CANMATCH) && eroot) { 02696 if (score.node) { 02697 struct ast_exten *z = trie_find_next_match(score.node); 02698 if (z) { 02699 #ifdef NEED_DEBUG_HERE 02700 ast_log(LOG_NOTICE,"Returning CANMATCH/MATCHMORE next_match exten %s\n", z->exten); 02701 #endif 02702 } else { 02703 if (score.canmatch_exten) { 02704 #ifdef NEED_DEBUG_HERE 02705 ast_log(LOG_NOTICE,"Returning CANMATCH/MATCHMORE canmatchmatch exten %s(%p)\n", score.canmatch_exten->exten, score.canmatch_exten); 02706 #endif 02707 return score.canmatch_exten; 02708 } else { 02709 #ifdef NEED_DEBUG_HERE 02710 ast_log(LOG_NOTICE,"Returning CANMATCH/MATCHMORE next_match exten NULL\n"); 02711 #endif 02712 } 02713 } 02714 return z; 02715 } 02716 #ifdef NEED_DEBUG_HERE 02717 ast_log(LOG_NOTICE, "Returning CANMATCH/MATCHMORE NULL (no next_match)\n"); 02718 #endif 02719 return NULL; /* according to the code, complete matches are null matches in MATCHMORE mode */ 02720 } 02721 02722 if (eroot) { 02723 /* found entry, now look for the right priority */ 02724 if (q->status < STATUS_NO_PRIORITY) 02725 q->status = STATUS_NO_PRIORITY; 02726 e = NULL; 02727 if (action == E_FINDLABEL && label ) { 02728 if (q->status < STATUS_NO_LABEL) 02729 q->status = STATUS_NO_LABEL; 02730 e = ast_hashtab_lookup(eroot->peer_label_table, &pattern); 02731 } else { 02732 e = ast_hashtab_lookup(eroot->peer_table, &pattern); 02733 } 02734 if (e) { /* found a valid match */ 02735 q->status = STATUS_SUCCESS; 02736 q->foundcontext = context; 02737 #ifdef NEED_DEBUG_HERE 02738 ast_log(LOG_NOTICE,"Returning complete match of exten %s\n", e->exten); 02739 #endif 02740 return e; 02741 } 02742 } 02743 } else { /* the old/current default exten pattern match algorithm */ 02744 02745 /* scan the list trying to match extension and CID */ 02746 eroot = NULL; 02747 while ( (eroot = ast_walk_context_extensions(tmp, eroot)) ) { 02748 int match = extension_match_core(eroot->exten, exten, action); 02749 /* 0 on fail, 1 on match, 2 on earlymatch */ 02750 02751 if (!match || (eroot->matchcid && !matchcid(eroot->cidmatch, callerid))) 02752 continue; /* keep trying */ 02753 if (match == 2 && action == E_MATCHMORE) { 02754 /* We match an extension ending in '!'. 02755 * The decision in this case is final and is NULL (no match). 02756 */ 02757 return NULL; 02758 } 02759 /* found entry, now look for the right priority */ 02760 if (q->status < STATUS_NO_PRIORITY) 02761 q->status = STATUS_NO_PRIORITY; 02762 e = NULL; 02763 if (action == E_FINDLABEL && label ) { 02764 if (q->status < STATUS_NO_LABEL) 02765 q->status = STATUS_NO_LABEL; 02766 e = ast_hashtab_lookup(eroot->peer_label_table, &pattern); 02767 } else { 02768 e = ast_hashtab_lookup(eroot->peer_table, &pattern); 02769 } 02770 if (e) { /* found a valid match */ 02771 q->status = STATUS_SUCCESS; 02772 q->foundcontext = context; 02773 return e; 02774 } 02775 } 02776 } 02777 02778 /* Check alternative switches */ 02779 AST_LIST_TRAVERSE(&tmp->alts, sw, list) { 02780 struct ast_switch *asw = pbx_findswitch(sw->name); 02781 ast_switch_f *aswf = NULL; 02782 char *datap; 02783 02784 if (!asw) { 02785 ast_log(LOG_WARNING, "No such switch '%s'\n", sw->name); 02786 continue; 02787 } 02788 02789 /* Substitute variables now */ 02790 if (sw->eval) { 02791 if (!(tmpdata = ast_str_thread_get(&switch_data, 512))) { 02792 ast_log(LOG_WARNING, "Can't evaluate switch?!"); 02793 continue; 02794 } 02795 pbx_substitute_variables_helper(chan, sw->data, ast_str_buffer(tmpdata), ast_str_size(tmpdata)); 02796 } 02797 02798 /* equivalent of extension_match_core() at the switch level */ 02799 if (action == E_CANMATCH) 02800 aswf = asw->canmatch; 02801 else if (action == E_MATCHMORE) 02802 aswf = asw->matchmore; 02803 else /* action == E_MATCH */ 02804 aswf = asw->exists; 02805 datap = sw->eval ? ast_str_buffer(tmpdata) : sw->data; 02806 if (!aswf) 02807 res = 0; 02808 else { 02809 if (chan) 02810 ast_autoservice_start(chan); 02811 res = aswf(chan, context, exten, priority, callerid, datap); 02812 if (chan) 02813 ast_autoservice_stop(chan); 02814 } 02815 if (res) { /* Got a match */ 02816 q->swo = asw; 02817 q->data = datap; 02818 q->foundcontext = context; 02819 /* XXX keep status = STATUS_NO_CONTEXT ? */ 02820 return NULL; 02821 } 02822 } 02823 q->incstack[q->stacklen++] = tmp->name; /* Setup the stack */ 02824 /* Now try any includes we have in this context */ 02825 for (i = tmp->includes; i; i = i->next) { 02826 if (include_valid(i)) { 02827 if ((e = pbx_find_extension(chan, bypass, q, i->rname, exten, priority, label, callerid, action))) { 02828 #ifdef NEED_DEBUG_HERE 02829 ast_log(LOG_NOTICE,"Returning recursive match of %s\n", e->exten); 02830 #endif 02831 return e; 02832 } 02833 if (q->swo) 02834 return NULL; 02835 } 02836 } 02837 return NULL; 02838 }
| struct ast_app* pbx_findapp | ( | const char * | app | ) | [read] |
Look up an application.
| app | name of the app |
Definition at line 1415 of file pbx.c.
References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, and ast_app::name.
Referenced by answer_exec_run(), ast_app_run_macro(), ast_bridge_call(), ast_pbx_run_app(), async_wait(), builtin_automixmonitor(), builtin_automonitor(), conf_run(), dial_exec_full(), do_magic_pickup(), dundi_exec(), exec_exec(), execif_exec(), feature_exec_app(), forward_message(), handle_exec(), handle_gosub(), iax2_exec(), lua_pbx_exec(), page_exec(), pbx_builtin_execiftime(), pbx_extension_helper(), realtime_exec(), try_calling(), and tryexec_exec().
01416 { 01417 struct ast_app *tmp; 01418 01419 AST_RWLIST_RDLOCK(&apps); 01420 AST_RWLIST_TRAVERSE(&apps, tmp, list) { 01421 if (!strcasecmp(tmp->name, app)) 01422 break; 01423 } 01424 AST_RWLIST_UNLOCK(&apps); 01425 01426 return tmp; 01427 }
| void pbx_retrieve_variable | ( | struct ast_channel * | c, | |
| const char * | var, | |||
| char ** | ret, | |||
| char * | workspace, | |||
| int | workspacelen, | |||
| struct varshead * | headp | |||
| ) |
Retrieve the value of a builtin variable or variable from the channel variable stack.
Definition at line 2968 of file pbx.c.
References ast_copy_string(), ast_free, ast_str_buffer(), ast_str_create(), ast_str_retrieve_variable(), and str.
Referenced by action_getvar(), action_status(), handle_getvariable(), lua_get_variable(), lua_get_variable_value(), and pbx_substitute_variables_helper_full().
02969 { 02970 struct ast_str *str = ast_str_create(16); 02971 const char *cret; 02972 02973 cret = ast_str_retrieve_variable(&str, 0, c, headp, var); 02974 ast_copy_string(workspace, ast_str_buffer(str), workspacelen); 02975 *ret = cret ? workspace : NULL; 02976 ast_free(str); 02977 }
| 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 5046 of file pbx.c.
References autofallthrough.
Referenced by pbx_load_module().
05047 { 05048 int oldval = autofallthrough; 05049 autofallthrough = newval; 05050 return oldval; 05051 }
| 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 5053 of file pbx.c.
References extenpatternmatchnew.
Referenced by handle_set_extenpatternmatchnew(), handle_unset_extenpatternmatchnew(), and pbx_load_module().
05054 { 05055 int oldval = extenpatternmatchnew; 05056 extenpatternmatchnew = newval; 05057 return oldval; 05058 }
| 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 5060 of file pbx.c.
References ast_free, ast_strdup, ast_strlen_zero(), and overrideswitch.
Referenced by pbx_load_module().
05061 { 05062 if (overrideswitch) { 05063 ast_free(overrideswitch); 05064 } 05065 if (!ast_strlen_zero(newval)) { 05066 overrideswitch = ast_strdup(newval); 05067 } else { 05068 overrideswitch = NULL; 05069 } 05070 }
| void pbx_substitute_variables_helper | ( | struct ast_channel * | c, | |
| const char * | cp1, | |||
| char * | cp2, | |||
| int | count | |||
| ) |
Definition at line 3965 of file pbx.c.
References pbx_substitute_variables_helper_full(), and ast_channel::varshead.
Referenced by add_extensions(), ast_add_extension2_lockopt(), function_eval(), get_manager_event_info(), get_mapping_weight(), import_helper(), launch_monitor_thread(), manager_log(), pbx_builtin_importvar(), pbx_find_extension(), pbx_load_config(), pbx_substitute_variables(), realtime_exec(), rotate_file(), rpt_do_lstats(), rpt_exec(), substituted(), try_calling(), and write_cdr().
03966 { 03967 size_t used; 03968 pbx_substitute_variables_helper_full(c, (c) ? &c->varshead : NULL, cp1, cp2, count, &used); 03969 }
| 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 3769 of file pbx.c.
References ast_channel_release(), ast_copy_string(), ast_debug, ast_dummy_channel_alloc(), ast_expr(), ast_func_read(), ast_log(), ast_strlen_zero(), len(), LOG_ERROR, LOG_WARNING, parse_variable_name(), pbx_retrieve_variable(), pbx_substitute_variables_helper_full(), substring(), var, VAR_BUF_SIZE, and ast_channel::varshead.
Referenced by pbx_substitute_variables_helper(), pbx_substitute_variables_helper_full(), and pbx_substitute_variables_varshead().
03770 { 03771 /* Substitutes variables into cp2, based on string cp1, cp2 NO LONGER NEEDS TO BE ZEROED OUT!!!! */ 03772 char *cp4 = NULL; 03773 const char *tmp, *whereweare, *orig_cp2 = cp2; 03774 int length, offset, offset2, isfunction; 03775 char *workspace = NULL; 03776 char *ltmp = NULL, *var = NULL; 03777 char *nextvar, *nextexp, *nextthing; 03778 char *vars, *vare; 03779 int pos, brackets, needsub, len; 03780 03781 *cp2 = 0; /* just in case nothing ends up there */ 03782 whereweare=tmp=cp1; 03783 while (!ast_strlen_zero(whereweare) && count) { 03784 /* Assume we're copying the whole remaining string */ 03785 pos = strlen(whereweare); 03786 nextvar = NULL; 03787 nextexp = NULL; 03788 nextthing = strchr(whereweare, '$'); 03789 if (nextthing) { 03790 switch (nextthing[1]) { 03791 case '{': 03792 nextvar = nextthing; 03793 pos = nextvar - whereweare; 03794 break; 03795 case '[': 03796 nextexp = nextthing; 03797 pos = nextexp - whereweare; 03798 break; 03799 default: 03800 pos = 1; 03801 } 03802 } 03803 03804 if (pos) { 03805 /* Can't copy more than 'count' bytes */ 03806 if (pos > count) 03807 pos = count; 03808 03809 /* Copy that many bytes */ 03810 memcpy(cp2, whereweare, pos); 03811 03812 count -= pos; 03813 cp2 += pos; 03814 whereweare += pos; 03815 *cp2 = 0; 03816 } 03817 03818 if (nextvar) { 03819 /* We have a variable. Find the start and end, and determine 03820 if we are going to have to recursively call ourselves on the 03821 contents */ 03822 vars = vare = nextvar + 2; 03823 brackets = 1; 03824 needsub = 0; 03825 03826 /* Find the end of it */ 03827 while (brackets && *vare) { 03828 if ((vare[0] == '$') && (vare[1] == '{')) { 03829 needsub++; 03830 } else if (vare[0] == '{') { 03831 brackets++; 03832 } else if (vare[0] == '}') { 03833 brackets--; 03834 } else if ((vare[0] == '$') && (vare[1] == '[')) 03835 needsub++; 03836 vare++; 03837 } 03838 if (brackets) 03839 ast_log(LOG_WARNING, "Error in extension logic (missing '}')\n"); 03840 len = vare - vars - 1; 03841 03842 /* Skip totally over variable string */ 03843 whereweare += (len + 3); 03844 03845 if (!var) 03846 var = alloca(VAR_BUF_SIZE); 03847 03848 /* Store variable name (and truncate) */ 03849 ast_copy_string(var, vars, len + 1); 03850 03851 /* Substitute if necessary */ 03852 if (needsub) { 03853 size_t used; 03854 if (!ltmp) 03855 ltmp = alloca(VAR_BUF_SIZE); 03856 03857 pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, &used); 03858 vars = ltmp; 03859 } else { 03860 vars = var; 03861 } 03862 03863 if (!workspace) 03864 workspace = alloca(VAR_BUF_SIZE); 03865 03866 workspace[0] = '\0'; 03867 03868 parse_variable_name(vars, &offset, &offset2, &isfunction); 03869 if (isfunction) { 03870 /* Evaluate function */ 03871 if (c || !headp) 03872 cp4 = ast_func_read(c, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace; 03873 else { 03874 struct varshead old; 03875 struct ast_channel *c = ast_dummy_channel_alloc(); 03876 if (c) { 03877 memcpy(&old, &c->varshead, sizeof(old)); 03878 memcpy(&c->varshead, headp, sizeof(c->varshead)); 03879 cp4 = ast_func_read(c, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace; 03880 /* Don't deallocate the varshead that was passed in */ 03881 memcpy(&c->varshead, &old, sizeof(c->varshead)); 03882 c = ast_channel_release(c); 03883 } else { 03884 ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution. Function results may be blank.\n"); 03885 } 03886 } 03887 ast_debug(2, "Function result is '%s'\n", cp4 ? cp4 : "(null)"); 03888 } else { 03889 /* Retrieve variable value */ 03890 pbx_retrieve_variable(c, vars, &cp4, workspace, VAR_BUF_SIZE, headp); 03891 } 03892 if (cp4) { 03893 cp4 = substring(cp4, offset, offset2, workspace, VAR_BUF_SIZE); 03894 03895 length = strlen(cp4); 03896 if (length > count) 03897 length = count; 03898 memcpy(cp2, cp4, length); 03899 count -= length; 03900 cp2 += length; 03901 *cp2 = 0; 03902 } 03903 } else if (nextexp) { 03904 /* We have an expression. Find the start and end, and determine 03905 if we are going to have to recursively call ourselves on the 03906 contents */ 03907 vars = vare = nextexp + 2; 03908 brackets = 1; 03909 needsub = 0; 03910 03911 /* Find the end of it */ 03912 while (brackets && *vare) { 03913 if ((vare[0] == '$') && (vare[1] == '[')) { 03914 needsub++; 03915 brackets++; 03916 vare++; 03917 } else if (vare[0] == '[') { 03918 brackets++; 03919 } else if (vare[0] == ']') { 03920 brackets--; 03921 } else if ((vare[0] == '$') && (vare[1] == '{')) { 03922 needsub++; 03923 vare++; 03924 } 03925 vare++; 03926 } 03927 if (brackets) 03928 ast_log(LOG_WARNING, "Error in extension logic (missing ']')\n"); 03929 len = vare - vars - 1; 03930 03931 /* Skip totally over expression */ 03932 whereweare += (len + 3); 03933 03934 if (!var) 03935 var = alloca(VAR_BUF_SIZE); 03936 03937 /* Store variable name (and truncate) */ 03938 ast_copy_string(var, vars, len + 1); 03939 03940 /* Substitute if necessary */ 03941 if (needsub) { 03942 size_t used; 03943 if (!ltmp) 03944 ltmp = alloca(VAR_BUF_SIZE); 03945 03946 pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, &used); 03947 vars = ltmp; 03948 } else { 03949 vars = var; 03950 } 03951 03952 length = ast_expr(vars, cp2, count, c); 03953 03954 if (length) { 03955 ast_debug(1, "Expression result is '%s'\n", cp2); 03956 count -= length; 03957 cp2 += length; 03958 *cp2 = 0; 03959 } 03960 } 03961 } 03962 *used = cp2 - orig_cp2; 03963 }
| void pbx_substitute_variables_varshead | ( | struct varshead * | headp, | |
| const char * | cp1, | |||
| char * | cp2, | |||
| int | count | |||
| ) |
Definition at line 3971 of file pbx.c.
References pbx_substitute_variables_helper_full().
Referenced by do_say(), dundi_lookup_local(), and loopback_subst().
03972 { 03973 size_t used; 03974 pbx_substitute_variables_helper_full(NULL, headp, cp1, cp2, count, &used); 03975 }
1.5.9