Wed Aug 11 01:09:31 2010

Asterisk developer's documentation


pbx.c File Reference

Core PBX routines. More...

#include "asterisk.h"
#include "asterisk/_private.h"
#include "asterisk/paths.h"
#include <ctype.h>
#include <time.h>
#include <sys/time.h>
#include <sys/sysinfo.h>
#include "asterisk/lock.h"
#include "asterisk/cli.h"
#include "asterisk/pbx.h"
#include "asterisk/channel.h"
#include "asterisk/file.h"
#include "asterisk/callerid.h"
#include "asterisk/cdr.h"
#include "asterisk/config.h"
#include "asterisk/term.h"
#include "asterisk/manager.h"
#include "asterisk/ast_expr.h"
#include "asterisk/linkedlists.h"
#include "asterisk/say.h"
#include "asterisk/utils.h"
#include "asterisk/causes.h"
#include "asterisk/musiconhold.h"
#include "asterisk/app.h"
#include "asterisk/devicestate.h"
#include "asterisk/event.h"
#include "asterisk/hashtab.h"
#include "asterisk/module.h"
#include "asterisk/indications.h"
#include "asterisk/taskprocessor.h"
#include "asterisk/xmldoc.h"

Include dependency graph for pbx.c:

Go to the source code of this file.

Data Structures

struct  acf_root
struct  app_tmp
struct  apps
struct  ast_app
 ast_app: A registered application More...
struct  ast_context
 ast_context: An extension context More...
struct  ast_exten
 ast_exten: An extension The dialplan is saved as a linked list with each context having it's own linked list of extensions - one item per priority. More...
struct  ast_hint
 Structure for dial plan hints. More...
struct  ast_ignorepat
 ast_ignorepat: Ignore patterns in dial plan More...
struct  ast_include
 ast_include: include= support in extensions.conf More...
struct  ast_state_cb
 ast_state_cb: An extension state notify register item More...
struct  ast_sw
 ast_sw: Switch statement in extensions.conf More...
struct  async_stat
struct  cfextension_states
struct  dialplan_counters
 Counters for the show dialplan manager command. More...
struct  fake_context
struct  hints
struct  match_char
 match_char: forms a syntax tree for quick matching of extension patterns More...
struct  pbx_builtin
 Declaration of builtin applications. More...
struct  pbx_exception
struct  scoreboard
struct  statecbs
struct  statechange
struct  store_hint
struct  store_hints
struct  switches

Defines

#define AST_PBX_MAX_STACK   128
#define BACKGROUND_MATCHEXTEN   (1 << 2)
#define BACKGROUND_NOANSWER   (1 << 1)
#define BACKGROUND_PLAYBACK   (1 << 3)
#define BACKGROUND_SKIP   (1 << 0)
#define EXT_DATA_SIZE   8192
#define NEW_MATCHER_CHK_MATCH
#define NEW_MATCHER_RECURSE
#define SAY_STUBS
#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 SWITCH_DATA_LENGTH   256
#define VAR_BUF_SIZE   4096
#define VAR_HARDTRAN   3
#define VAR_NORMAL   1
#define VAR_SOFTTRAN   2
#define WAITEXTEN_DIALTONE   (1 << 1)
#define WAITEXTEN_MOH   (1 << 0)

Functions

void __ast_context_destroy (struct ast_context *list, struct ast_hashtab *contexttab, struct ast_context *con, const char *registrar)
int __ast_custom_function_register (struct ast_custom_function *acf, struct ast_module *mod)
 Register a custom function.
static int __ast_goto_if_exists (struct ast_channel *chan, const char *context, const char *exten, int priority, int async)
static void __ast_internal_context_destroy (struct ast_context *con)
static enum ast_pbx_result __ast_pbx_run (struct ast_channel *c, struct ast_pbx_args *args)
static void __init_extensionstate_buf (void)
static void __init_switch_data (void)
static int _extension_match_core (const char *pattern, const char *data, enum ext_match_t mode)
static int acf_exception_read (struct ast_channel *chan, const char *name, char *data, char *buf, size_t buflen)
static int acf_retrieve_docs (struct ast_custom_function *acf)
static struct match_char * add_exten_to_pattern_tree (struct ast_context *con, struct ast_exten *e1, int findonly)
static struct match_char * add_pattern_node (struct ast_context *con, struct match_char *current, char *pattern, int is_pattern, int already, int specificity, struct match_char **parent)
static int add_pri (struct ast_context *con, struct ast_exten *tmp, struct ast_exten *el, struct ast_exten *e, int replace)
 add the extension in the priority chain.
static int add_pri_lockopt (struct ast_context *con, struct ast_exten *tmp, struct ast_exten *el, struct ast_exten *e, int replace, int lockhints)
 add the extension in the priority chain.
static struct match_char * already_in_tree (struct match_char *current, char *pat)
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)
 Main interface to add extensions to the list for out context.
static int ast_add_extension2_lockopt (struct ast_context *con, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar, int lockconts, int lockhints)
 Does all the work of ast_add_extension2, but adds two args, to determine if context and hint locking should be done. In merge_and_delete, we need to do this without locking, as the locks are already held.
static int ast_add_extension_nolock (const char *context, int replace, const char *extension, int priority, const char *label, const char *callerid, const char *application, void *data, void(*datad)(void *), const char *registrar)
static int ast_add_hint (struct ast_exten *e)
 Add hint to hint list, check initial extension state.
static int ast_add_hint_nolock (struct ast_exten *e)
 Add hint to hint list, check initial extension state; the hints had better be WRLOCKED already!
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 *channame, 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_in)
 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.
static int ast_change_hint (struct ast_exten *oe, struct ast_exten *ne)
 Change hint for an extension.
int ast_check_timing (const struct ast_timing *i)
 Evaluate a pre-constructed bitmap as to whether the current time falls within the range specified.
int ast_context_add_ignorepat (const char *context, const char *value, const char *registrar)
 Add an ignorepat.
int ast_context_add_ignorepat2 (struct ast_context *con, const char *value, 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 *value, 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 *value, 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 *context)
 locks the macrolock in the given given context
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 matchcallerid, const char *registrar)
int ast_context_remove_extension_callerid2 (struct ast_context *con, const char *extension, int priority, const char *callerid, int matchcallerid, const char *registrar, int already_locked)
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 included contexts. This function locks contexts list by &conlist, search for the right context structure, leave context list locked and call ast_context_remove_include2 which removes include, unlock contexts list and return ...
int ast_context_remove_include2 (struct ast_context *con, const char *include, const char *registrar)
 Locks context, remove included contexts, unlocks context. When we call this function, &conlock lock must be locked, because when we giving *con argument, some process can remove/change this context and after that there can be segfault.
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 *context)
 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 *data)
 Determine if a given extension matches a given pattern (in NXX format).
int ast_extension_state (struct ast_channel *c, const char *context, const char *exten)
 Check extension state for an extension by using hint.
static int ast_extension_state2 (struct ast_exten *e)
 Check state of extension by using hints.
const char * ast_extension_state2str (int extension_state)
 Return extension_state as string.
int ast_extension_state_add (const char *context, const char *exten, ast_state_cb_type callback, void *data)
 Add watcher for extension states.
int ast_extension_state_del (int id, ast_state_cb_type callback)
 Remove a watcher from the callback list.
int ast_findlabel_extension (struct ast_channel *c, const char *context, const char *exten, const char *label, const char *callerid)
 Find the priority of an extension that has the specified label.
int ast_findlabel_extension2 (struct ast_channel *c, struct ast_context *con, const char *exten, const char *label, const char *callerid)
 Find the priority of an extension that has the specified label.
int ast_func_read (struct ast_channel *chan, const char *function, char *workspace, size_t len)
 executes a read operation on a function
int ast_func_write (struct ast_channel *chan, const char *function, const char *value)
 executes a write operation on a function
const char * ast_get_context_name (struct ast_context *con)
const char * ast_get_context_registrar (struct ast_context *c)
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)
struct ast_context * ast_get_extension_context (struct ast_exten *exten)
const char * ast_get_extension_label (struct ast_exten *exten)
int ast_get_extension_matchcid (struct ast_exten *e)
const char * ast_get_extension_name (struct ast_exten *exten)
int ast_get_extension_priority (struct ast_exten *exten)
const char * ast_get_extension_registrar (struct ast_exten *e)
int ast_get_hint (char *hint, int hintsize, char *name, int namesize, struct ast_channel *c, const char *context, const char *exten)
 Get hint for channel.
const char * ast_get_ignorepat_name (struct ast_ignorepat *ip)
const char * ast_get_ignorepat_registrar (struct ast_ignorepat *ip)
const char * ast_get_include_name (struct ast_include *inc)
const char * ast_get_include_registrar (struct ast_include *i)
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)
const char * ast_get_switch_registrar (struct ast_sw *sw)
int ast_goto_if_exists (struct ast_channel *chan, const char *context, const char *exten, int priority)
int ast_hashtab_compare_contexts (const void *ah_a, const void *ah_b)
unsigned int ast_hashtab_hash_contexts (const void *obj)
static struct ast_exten * ast_hint_extension (struct ast_channel *c, const char *context, const char *exten)
static struct ast_exten * ast_hint_extension_nolock (struct ast_channel *c, const char *context, const char *exten)
 Find hint for given extension in context.
int ast_ignore_pattern (const char *context, const char *pattern)
 Checks to see if a number should be ignored.
int ast_matchmore_extension (struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
 Looks to see if adding anything to this extension might match something. (exists ^ canmatch).
void ast_merge_contexts_and_delete (struct ast_context **extcontexts, struct ast_hashtab *exttable, const char *registrar)
 Merge the temporary contexts into a global contexts list and delete from the global list the ones that are being added.
int ast_parseable_goto (struct ast_channel *chan, const char *goto_string)
int ast_pbx_outgoing_app (const char *type, int format, void *data, int timeout, const char *app, const char *appdata, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **locked_channel)
static int ast_pbx_outgoing_cdr_failed (void)
 Function to post an empty cdr after a spool call fails.
int ast_pbx_outgoing_exten (const char *type, int format, void *data, int timeout, const char *context, const char *exten, int priority, int *reason, int synchronous, const char *cid_num, const char *cid_name, struct ast_variable *vars, const char *account, struct ast_channel **channel)
enum ast_pbx_result ast_pbx_run (struct ast_channel *c)
 Execute the PBX in the current thread.
static void * ast_pbx_run_app (void *data)
 run the application and free the descriptor once done
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 ()
 Read locks the context list.
int ast_register_application2 (const char *app, int(*execute)(struct ast_channel *, void *), const char *synopsis, const char *description, void *mod)
 Dynamically register a new dial plan application.
int ast_register_switch (struct ast_switch *sw)
 Register an alternative dialplan switch.
static int ast_remove_hint (struct ast_exten *e)
 Remove hint from extension.
int ast_spawn_extension (struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid, int *found, int combined_find_spawn)
 Launch a new extension (i.e. new stack).
int ast_unlock_context (struct ast_context *con)
int ast_unlock_contexts ()
 Unlocks contexts.
int ast_unregister_application (const char *app)
 Unregister an application.
void ast_unregister_switch (struct ast_switch *sw)
 Unregister an alternative switch.
struct ast_exten * ast_walk_context_extensions (struct ast_context *con, struct ast_exten *exten)
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)
int ast_wrlock_context (struct ast_context *con)
 Write locks a given context.
int ast_wrlock_contexts ()
 Write locks the context list.
int ast_wrlock_contexts_version (void)
static void * async_wait (void *data)
static void cli_match_char_tree (struct match_char *node, char *prefix, int fd)
static int collect_digits (struct ast_channel *c, int waittime, char *buf, int buflen, int pos)
 collect digits from the channel into the buffer.
static int compare_char (const void *a, const void *b)
static char * complete_core_show_hint (const char *line, const char *word, int pos, int state)
 autocomplete for CLI command 'core show hint'
static char * complete_show_dialplan_context (const char *line, const char *word, int pos, int state)
static void context_merge (struct ast_context **extcontexts, struct ast_hashtab *exttable, struct ast_context *context, const char *registrar)
static void context_merge_incls_swits_igps_other_registrars (struct ast_context *new, struct ast_context *old, const char *registrar)
static void create_match_char_tree (struct ast_context *con)
static void decrease_call_count (void)
static void destroy_exten (struct ast_exten *e)
static void destroy_pattern_tree (struct match_char *pattern_tree)
static void device_state_cb (const struct ast_event *event, void *unused)
static void exception_store_free (void *data)
static int ext_cmp (const char *a, const char *b)
 the full routine to compare extensions in rules.
static int ext_cmp1 (const char **p, unsigned char *bitwise)
 helper functions to sort extensions and patterns in the desired way, so that more specific patterns appear first.
static int ext_strncpy (char *dst, const char *src, int len)
 copy a string skipping whitespace
static int extension_match_core (const char *pattern, const char *data, enum ext_match_t mode)
static struct ast_context * find_context (const char *context)
 lookup for a context with a given name,
static struct ast_context * find_context_locked (const char *context)
 lookup for a context with a given name,
static char * func_args (char *function)
 return a pointer to the arguments of the function, and terminates the function name with '\0'
static struct ast_exten * get_canmatch_exten (struct match_char *node)
static unsigned get_range (char *src, int max, char *const names[], const char *msg)
 helper function to return a range up to max (7, 12, 31 respectively). names, if supplied, is an array of names that should be mapped to numbers.
static void get_timerange (struct ast_timing *i, char *times)
 store a bitmask of valid times, one bit each 1 minute
static char * handle_debug_dialplan (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Send ack once.
static char * handle_set_chanvar (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_set_extenpatternmatchnew (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_set_global (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_show_application (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_show_applications (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_show_chanvar (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI support for listing chanvar's variables in a parseable way.
static char * handle_show_dialplan (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_show_function (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_show_functions (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static char * handle_show_globals (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI support for listing global variables in a parseable way.
static char * handle_show_hint (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 handle_show_hint: CLI support for listing registered dial plan hint
static char * handle_show_hints (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 handle_show_hints: CLI support for listing registered dial plan hints
static char * handle_show_switches (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 handle_show_switches: CLI support for listing registered dial plan switches
static int handle_statechange (void *datap)
static char * handle_unset_extenpatternmatchnew (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int hashtab_compare_exten_labels (const void *ah_a, const void *ah_b)
static int hashtab_compare_exten_numbers (const void *ah_a, const void *ah_b)
static int hashtab_compare_extens (const void *ha_a, const void *ah_b)
static unsigned int hashtab_hash_extens (const void *obj)
static unsigned int hashtab_hash_labels (const void *obj)
static unsigned int hashtab_hash_priority (const void *obj)
static int include_valid (struct ast_include *i)
static int increase_call_count (const struct ast_channel *c)
 Increase call count for channel.
static void insert_in_next_chars_alt_char_list (struct match_char **parent_ptr, struct match_char *node)
int load_pbx (void)
void log_match_char_tree (struct match_char *node, char *prefix)
static int lookup_name (const char *s, char *const names[], int max)
 Helper for get_range. return the index of the matching entry, starting from 1. If names is not supplied, try numeric values.
static void manager_dpsendack (struct mansession *s, const struct message *m)
 Send ack once.
static int manager_show_dialplan (struct mansession *s, const struct message *m)
 Manager listing of dial plan.
static int manager_show_dialplan_helper (struct mansession *s, const struct message *m, const char *actionidtext, const char *context, const char *exten, struct dialplan_counters *dpc, struct ast_include *rinclude)
 Show dialplan extensions XXX this function is similar but not exactly the same as the CLI's show dialplan. Must check whether the difference is intentional or not.
static int matchcid (const char *cidpattern, const char *callerid)
static void new_find_extension (const char *str, struct scoreboard *score, struct match_char *tree, int length, int spec, const char *callerid, const char *label, enum ext_match_t action)
static int parse_variable_name (char *var, int *offset, int *length, int *isfunc)
 extract offset:length from variable name.
static int pbx_builtin_answer (struct ast_channel *, void *)
static int pbx_builtin_background (struct ast_channel *, void *)
static int pbx_builtin_busy (struct ast_channel *, void *)
void pbx_builtin_clear_globals (void)
static int pbx_builtin_congestion (struct ast_channel *, void *)
static int pbx_builtin_execiftime (struct ast_channel *, 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.
static int pbx_builtin_goto (struct ast_channel *, void *)
static int pbx_builtin_gotoif (struct ast_channel *, void *)
static int pbx_builtin_gotoiftime (struct ast_channel *, void *)
static int pbx_builtin_hangup (struct ast_channel *, void *)
static int pbx_builtin_importvar (struct ast_channel *, void *)
static int pbx_builtin_incomplete (struct ast_channel *, void *)
static int pbx_builtin_noop (struct ast_channel *, void *)
static int pbx_builtin_proceeding (struct ast_channel *, void *)
static int pbx_builtin_progress (struct ast_channel *, void *)
void pbx_builtin_pushvar_helper (struct ast_channel *chan, const char *name, const char *value)
 Add a variable to the channel variable stack, without removing any previously set value.
int pbx_builtin_raise_exception (struct ast_channel *chan, void *vreason)
static int pbx_builtin_resetcdr (struct ast_channel *, void *)
static int pbx_builtin_ringing (struct ast_channel *, void *)
static int pbx_builtin_saycharacters (struct ast_channel *, void *)
static int pbx_builtin_saydigits (struct ast_channel *, void *)
static int pbx_builtin_saynumber (struct ast_channel *, void *)
static int pbx_builtin_sayphonetic (struct ast_channel *, void *)
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.
static int pbx_builtin_setamaflags (struct ast_channel *, void *)
int pbx_builtin_setvar (struct ast_channel *, void *)
void pbx_builtin_setvar_helper (struct ast_channel *chan, const char *name, const char *value)
 Add a variable to the channel variable stack, removing the most recently set value for the same name.
int pbx_builtin_setvar_multiple (struct ast_channel *, void *)
static int pbx_builtin_wait (struct ast_channel *, void *)
static int pbx_builtin_waitexten (struct ast_channel *, void *)
int pbx_checkcondition (const char *condition)
 Evaluate a condition.
static void pbx_destroy (struct ast_pbx *p)
int pbx_exec (struct ast_channel *c, struct ast_app *app, void *data)
 Execute an application.
static int pbx_extension_helper (struct ast_channel *c, struct ast_context *con, const char *context, const char *exten, int priority, const char *label, const char *callerid, enum ext_match_t action, int *found, int combined_find_spawn)
 The return value depends on the action:.
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)
 Find application handle in linked list.
static struct ast_switch * pbx_findswitch (const char *sw)
static int pbx_parseable_goto (struct ast_channel *chan, const char *goto_string, int async)
void pbx_retrieve_variable (struct ast_channel *c, const char *var, char **ret, char *workspace, int workspacelen, struct varshead *headp)
 Support for Asterisk built-in variables in the dialplan.
int pbx_set_autofallthrough (int newval)
int pbx_set_extenpatternmatchnew (int newval)
void pbx_set_overrideswitch (const char *newval)
static void pbx_substitute_variables (char *passdata, int datalen, struct ast_channel *c, struct ast_exten *e)
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 count, size_t *used)
void pbx_substitute_variables_varshead (struct varshead *headp, const char *cp1, char *cp2, int count)
static void * pbx_thread (void *data)
static void print_app_docs (struct ast_app *aa, int fd)
static void print_ext (struct ast_exten *e, char *buf, int buflen)
 helper function to print an extension
static void set_ext_pri (struct ast_channel *c, const char *exten, int pri)
static int show_debug_helper (int fd, const char *context, const char *exten, struct dialplan_counters *dpc, struct ast_include *rinclude, int includecount, const char *includes[])
static int show_dialplan_helper (int fd, const char *context, const char *exten, struct dialplan_counters *dpc, struct ast_include *rinclude, int includecount, const char *includes[])
static char * substring (const char *value, int offset, int length, char *workspace, size_t workspace_len)
 takes a substring. It is ok to call with value == workspace.
static struct ast_exten * trie_find_next_match (struct match_char *node)
static void unreference_cached_app (struct ast_app *app)
static void update_scoreboard (struct scoreboard *board, int length, int spec, struct ast_exten *exten, char last, const char *callerid, int deleted, struct match_char *node)
static void wait_for_hangup (struct ast_channel *chan, void *data)

Variables

static int autofallthrough = 1
static struct ast_app_option background_opts [128] = { [ 's' ] = { .flag = (1 << 0) }, [ 'n' ] = { .flag = (1 << 1) }, [ 'm' ] = { .flag = (1 << 2) }, [ 'p' ] = { .flag = (1 << 3) },}
static struct pbx_builtin builtins []
 Declaration of builtin applications.
static ast_rwlock_t conlock = PTHREAD_RWLOCK_INITIALIZER
static int conlock_wrlock_version = 0
static struct ast_context * contexts
static struct ast_hashtab * contexts_table = NULL
static int countcalls
static char * days []
static struct ast_event_sub * device_state_sub
 Subscription for device state change events.
static struct ast_taskprocessor * device_state_tps
static struct ast_custom_function exception_function
static struct ast_datastore_info exception_store_info
static int extenpatternmatchnew = 0
static struct cfextension_states extension_states []
static struct ast_threadstorage extensionstate_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_extensionstate_buf , .custom_init = NULL , }
static struct varshead globals = AST_LIST_HEAD_NOLOCK_INIT_VALUE
static ast_rwlock_t globalslock = PTHREAD_RWLOCK_INITIALIZER
static char mandescr_show_dialplan []
static ast_mutex_t maxcalllock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP )
static char * months []
static char * overrideswitch = NULL
static struct ast_cli_entry pbx_cli []
static struct ast_app_option resetcdr_opts [128] = { [ 'w' ] = { .flag = (1 << 1) }, [ 'a' ] = { .flag = (1 << 2) }, [ 'v' ] = { .flag = (1 << 0) }, [ 'e' ] = { .flag = (1 << 10) },}
static int stateid = 1
static struct ast_threadstorage switch_data = { .once = PTHREAD_ONCE_INIT , .key_init = __init_switch_data , .custom_init = NULL , }
static int totalcalls
static struct ast_app_option waitexten_opts [128] = { [ 'm' ] = { .flag = (1 << 0) , .arg_index = 0 + 1 }, [ 'd' ] = { .flag = (1 << 1) , .arg_index = 0 + 1 },}


Detailed Description

Core PBX routines.

Author:
Mark Spencer <markster@digium.com>

Definition in file pbx.c.


Define Documentation

#define AST_PBX_MAX_STACK   128

Go no deeper than this through includes (not counting loops)

Definition at line 1359 of file pbx.c.

#define BACKGROUND_MATCHEXTEN   (1 << 2)

Definition at line 737 of file pbx.c.

Referenced by pbx_builtin_background().

#define BACKGROUND_NOANSWER   (1 << 1)

Definition at line 736 of file pbx.c.

Referenced by pbx_builtin_background().

#define BACKGROUND_PLAYBACK   (1 << 3)

Definition at line 738 of file pbx.c.

Referenced by pbx_builtin_background().

#define BACKGROUND_SKIP   (1 << 0)

Definition at line 735 of file pbx.c.

Referenced by pbx_builtin_background().

#define EXT_DATA_SIZE   8192

Note:
I M P O R T A N T :
The speed of extension handling will likely be among the most important aspects of this PBX. The switching scheme as it exists right now isn't terribly bad (it's O(N+M), where N is the # of extensions and M is the avg # of priorities, but a constant search time here would be great ;-)

A new algorithm to do searching based on a 'compiled' pattern tree is introduced here, and shows a fairly flat (constant) search time, even for over 10000 patterns.

Also, using a hash table for context/priority name lookup can help prevent the find_extension routines from absorbing exponential cpu cycles as the number of contexts/priorities grow. I've previously tested find_extension with red-black trees, which have O(log2(n)) speed. Right now, I'm using hash tables, which do searches (ideally) in O(1) time. While these techniques do not yield much speed in small dialplans, they are worth the trouble in large dialplans.

Definition at line 724 of file pbx.c.

Referenced by pbx_extension_helper(), and realtime_exec().

#define NEW_MATCHER_CHK_MATCH

Referenced by new_find_extension().

#define NEW_MATCHER_RECURSE

Referenced by new_find_extension().

#define SAY_STUBS

Definition at line 54 of file pbx.c.

#define STATUS_NO_CONTEXT   1

Definition at line 2451 of file pbx.c.

#define STATUS_NO_EXTENSION   2

Definition at line 2452 of file pbx.c.

#define STATUS_NO_LABEL   4

Definition at line 2454 of file pbx.c.

#define STATUS_NO_PRIORITY   3

Definition at line 2453 of file pbx.c.

#define STATUS_SUCCESS   5

Definition at line 2455 of file pbx.c.

#define SWITCH_DATA_LENGTH   256

Definition at line 727 of file pbx.c.

#define VAR_BUF_SIZE   4096

#define VAR_HARDTRAN   3

Definition at line 733 of file pbx.c.

#define VAR_NORMAL   1

Definition at line 731 of file pbx.c.

#define VAR_SOFTTRAN   2

Definition at line 732 of file pbx.c.

#define WAITEXTEN_DIALTONE   (1 << 1)

Definition at line 748 of file pbx.c.

Referenced by pbx_builtin_waitexten().

#define WAITEXTEN_MOH   (1 << 0)

Definition at line 747 of file pbx.c.

Referenced by pbx_builtin_waitexten().


Function Documentation

void __ast_context_destroy ( struct ast_context *  list,
struct ast_hashtab *  contexttab,
struct ast_context *  con,
const char *  registrar 
)

Definition at line 8288 of file pbx.c.

References __ast_internal_context_destroy(), ast_context::alts, ast_context_remove_extension_callerid2(), ast_debug, ast_free, ast_hashtab_end_traversal(), ast_hashtab_next(), ast_hashtab_remove_this_object(), ast_hashtab_start_traversal(), AST_LIST_EMPTY, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_unlock_context(), ast_verb, ast_wrlock_context(), ast_exten::cidmatch, contexts, ast_exten::exten, ast_context::ignorepats, ast_context::includes, ast_context::name, ast_include::next, ast_ignorepat::next, ast_context::next, ast_sw::next, ast_exten::peer_table, ast_exten::priority, ast_context::refcount, ast_exten::registrar, ast_sw::registrar, ast_include::registrar, ast_ignorepat::registrar, ast_context::registrar, ast_context::root, and ast_context::root_table.

Referenced by ast_context_destroy().

08289 {
08290    struct ast_context *tmp, *tmpl=NULL;
08291    struct ast_exten *exten_item, *prio_item;
08292 
08293    for (tmp = list; tmp; ) {
08294       struct ast_context *next = NULL; /* next starting point */
08295          /* The following code used to skip forward to the next
08296             context with matching registrar, but this didn't
08297             make sense; individual priorities registrar'd to
08298             the matching registrar could occur in any context! */
08299       ast_debug(1, "Investigate ctx %s %s\n", tmp->name, tmp->registrar);
08300       if (con) {
08301          for (; tmp; tmpl = tmp, tmp = tmp->next) { /* skip to the matching context */
08302             ast_debug(1, "check ctx %s %s\n", tmp->name, tmp->registrar);
08303             if ( !strcasecmp(tmp->name, con->name) ) {
08304                break;   /* found it */
08305             }
08306          }
08307       }
08308 
08309       if (!tmp)   /* not found, we are done */
08310          break;
08311       ast_wrlock_context(tmp);
08312 
08313       if (registrar) {
08314          /* then search thru and remove any extens that match registrar. */
08315          struct ast_hashtab_iter *exten_iter;
08316          struct ast_hashtab_iter *prio_iter;
08317          struct ast_ignorepat *ip, *ipl = NULL, *ipn = NULL;
08318          struct ast_include *i, *pi = NULL, *ni = NULL;
08319          struct ast_sw *sw = NULL;
08320 
08321          /* remove any ignorepats whose registrar matches */
08322          for (ip = tmp->ignorepats; ip; ip = ipn) {
08323             ipn = ip->next;
08324             if (!strcmp(ip->registrar, registrar)) {
08325                if (ipl) {
08326                   ipl->next = ip->next;
08327                   ast_free(ip);
08328                   continue; /* don't change ipl */
08329                } else {
08330                   tmp->ignorepats = ip->next;
08331                   ast_free(ip);
08332                   continue; /* don't change ipl */
08333                }
08334             }
08335             ipl = ip;
08336          }
08337          /* remove any includes whose registrar matches */
08338          for (i = tmp->includes; i; i = ni) {
08339             ni = i->next;
08340             if (strcmp(i->registrar, registrar) == 0) {
08341                /* remove from list */
08342                if (pi) {
08343                   pi->next = i->next;
08344                   /* free include */
08345                   ast_free(i);
08346                   continue; /* don't change pi */
08347                } else {
08348                   tmp->includes = i->next;
08349                   /* free include */
08350                   ast_free(i);
08351                   continue; /* don't change pi */
08352                }
08353             }
08354             pi = i;
08355          }
08356          /* remove any switches whose registrar matches */
08357          AST_LIST_TRAVERSE_SAFE_BEGIN(&tmp->alts, sw, list) {
08358             if (strcmp(sw->registrar,registrar) == 0) {
08359                AST_LIST_REMOVE_CURRENT(list);
08360                ast_free(sw);
08361             }
08362          }
08363          AST_LIST_TRAVERSE_SAFE_END;
08364 
08365          if (tmp->root_table) { /* it is entirely possible that the context is EMPTY */
08366             exten_iter = ast_hashtab_start_traversal(tmp->root_table);
08367             while ((exten_item=ast_hashtab_next(exten_iter))) {
08368                prio_iter = ast_hashtab_start_traversal(exten_item->peer_table);
08369                while ((prio_item=ast_hashtab_next(prio_iter))) {
08370                   if (!prio_item->registrar || strcmp(prio_item->registrar, registrar) != 0) {
08371                      continue;
08372                   }
08373                   ast_verb(3, "Remove %s/%s/%d, registrar=%s; con=%s(%p); con->root=%p\n",
08374                          tmp->name, prio_item->exten, prio_item->priority, registrar, con? con->name : "<nil>", con, con? con->root_table: NULL);
08375                   /* set matchcid to 1 to insure we get a direct match, and NULL registrar to make sure no wildcarding is done */
08376                   ast_context_remove_extension_callerid2(tmp, prio_item->exten, prio_item->priority, prio_item->cidmatch, 1, NULL, 1);
08377                }
08378                ast_hashtab_end_traversal(prio_iter);
08379             }
08380             ast_hashtab_end_traversal(exten_iter);
08381          }
08382 
08383          /* delete the context if it's registrar matches, is empty, has refcount of 1, */
08384          /* it's not empty, if it has includes, ignorepats, or switches that are registered from
08385             another registrar. It's not empty if there are any extensions */
08386          if (strcmp(tmp->registrar, registrar) == 0 && tmp->refcount < 2 && !tmp->root && !tmp->ignorepats && !tmp->includes && AST_LIST_EMPTY(&tmp->alts)) {
08387             ast_debug(1, "delete ctx %s %s\n", tmp->name, tmp->registrar);
08388             ast_hashtab_remove_this_object(contexttab, tmp);
08389 
08390             next = tmp->next;
08391             if (tmpl)
08392                tmpl->next = next;
08393             else
08394                contexts = next;
08395             /* Okay, now we're safe to let it go -- in a sense, we were
08396                ready to let it go as soon as we locked it. */
08397             ast_unlock_context(tmp);
08398             __ast_internal_context_destroy(tmp);
08399          } else {
08400             ast_debug(1,"Couldn't delete ctx %s/%s; refc=%d; tmp.root=%p\n", tmp->name, tmp->registrar,
08401                     tmp->refcount, tmp->root);
08402             ast_unlock_context(tmp);
08403             next = tmp->next;
08404             tmpl = tmp;
08405          }
08406       } else if (con) {
08407          ast_verb(3, "Deleting context %s registrar=%s\n", tmp->name, tmp->registrar);
08408          ast_debug(1, "delete ctx %s %s\n", tmp->name, tmp->registrar);
08409          ast_hashtab_remove_this_object(contexttab, tmp);
08410 
08411          next = tmp->next;
08412          if (tmpl)
08413             tmpl->next = next;
08414          else
08415             contexts = next;
08416          /* Okay, now we're safe to let it go -- in a sense, we were
08417             ready to let it go as soon as we locked it. */
08418          ast_unlock_context(tmp);
08419          __ast_internal_context_destroy(tmp);
08420       }
08421 
08422       /* if we have a specific match, we are done, otherwise continue */
08423       tmp = con ? NULL : next;
08424    }
08425 }

int __ast_custom_function_register ( struct ast_custom_function *  acf,
struct ast_module *  mod 
)

Register a custom function.

Definition at line 3289 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().

03290 {
03291    struct ast_custom_function *cur;
03292    char tmps[80];
03293 
03294    if (!acf) {
03295       return -1;
03296    }
03297 
03298    acf->mod = mod;
03299    acf->docsrc = AST_STATIC_DOC;
03300 
03301    if (acf_retrieve_docs(acf)) {
03302       return -1;
03303    }
03304 
03305    AST_RWLIST_WRLOCK(&acf_root);
03306 
03307    AST_RWLIST_TRAVERSE(&acf_root, cur, acflist) {
03308       if (!strcmp(acf->name, cur->name)) {
03309          ast_log(LOG_ERROR, "Function %s already registered.\n", acf->name);
03310          AST_RWLIST_UNLOCK(&acf_root);
03311          return -1;
03312       }
03313    }
03314 
03315    /* Store in alphabetical order */
03316    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&acf_root, cur, acflist) {
03317       if (strcasecmp(acf->name, cur->name) < 0) {
03318          AST_RWLIST_INSERT_BEFORE_CURRENT(acf, acflist);
03319          break;
03320       }
03321    }
03322    AST_RWLIST_TRAVERSE_SAFE_END;
03323 
03324    if (!cur) {
03325       AST_RWLIST_INSERT_TAIL(&acf_root, acf, acflist);
03326    }
03327 
03328    AST_RWLIST_UNLOCK(&acf_root);
03329 
03330    ast_verb(2, "Registered custom function '%s'\n", term_color(tmps, acf->name, COLOR_BRCYAN, 0, sizeof(tmps)));
03331 
03332    return 0;
03333 }

static int __ast_goto_if_exists ( struct ast_channel *  chan,
const char *  context,
const char *  exten,
int  priority,
int  async 
) [static]

Definition at line 9563 of file pbx.c.

References ast_async_goto(), ast_exists_extension(), ast_explicit_goto(), ast_channel::cid, ast_callerid::cid_num, ast_channel::context, and ast_channel::exten.

Referenced by ast_async_goto_if_exists(), and ast_goto_if_exists().

09564 {
09565    int (*goto_func)(struct ast_channel *chan, const char *context, const char *exten, int priority);
09566 
09567    if (!chan)
09568       return -2;
09569 
09570    if (context == NULL)
09571       context = chan->context;
09572    if (exten == NULL)
09573       exten = chan->exten;
09574 
09575    goto_func = (async) ? ast_async_goto : ast_explicit_goto;
09576    if (ast_exists_extension(chan, context, exten, priority, chan->cid.cid_num))
09577       return goto_func(chan, context, exten, priority);
09578    else
09579       return -3;
09580 }

static void __ast_internal_context_destroy ( struct ast_context *  con  )  [static]

Definition at line 8241 of file pbx.c.

References ast_context::alts, ast_free, ast_hashtab_destroy(), AST_LIST_REMOVE_HEAD, ast_rwlock_destroy(), destroy_exten(), destroy_pattern_tree(), el, ast_context::ignorepats, ast_context::includes, ast_context::lock, ast_exten::next, ast_ignorepat::next, ast_include::next, ast_context::pattern_tree, ast_exten::peer, ast_context::registrar, ast_context::root, and ast_context::root_table.

Referenced by __ast_context_destroy(), and ast_merge_contexts_and_delete().

08242 {
08243    struct ast_include *tmpi;
08244    struct ast_sw *sw;
08245    struct ast_exten *e, *el, *en;
08246    struct ast_ignorepat *ipi;
08247    struct ast_context *tmp = con;
08248 
08249    for (tmpi = tmp->includes; tmpi; ) { /* Free includes */
08250       struct ast_include *tmpil = tmpi;
08251       tmpi = tmpi->next;
08252       ast_free(tmpil);
08253    }
08254    for (ipi = tmp->ignorepats; ipi; ) { /* Free ignorepats */
08255       struct ast_ignorepat *ipl = ipi;
08256       ipi = ipi->next;
08257       ast_free(ipl);
08258    }
08259    if (tmp->registrar)
08260       ast_free(tmp->registrar);
08261 
08262    /* destroy the hash tabs */
08263    if (tmp->root_table) {
08264       ast_hashtab_destroy(tmp->root_table, 0);
08265    }
08266    /* and destroy the pattern tree */
08267    if (tmp->pattern_tree)
08268       destroy_pattern_tree(tmp->pattern_tree);
08269 
08270    while ((sw = AST_LIST_REMOVE_HEAD(&tmp->alts, list)))
08271       ast_free(sw);
08272    for (e = tmp->root; e;) {
08273       for (en = e->peer; en;) {
08274          el = en;
08275          en = en->peer;
08276          destroy_exten(el);
08277       }
08278       el = e;
08279       e = e->next;
08280       destroy_exten(el);
08281    }
08282    tmp->root = NULL;
08283    ast_rwlock_destroy(&tmp->lock);
08284    ast_free(tmp);
08285 }

static enum ast_pbx_result __ast_pbx_run ( struct ast_channel *  c,
struct ast_pbx_args *  args 
) [static]

Note:
We get here on a failure of some kind: non-existing extension or hangup. We have options, here. We can either catch the failure and continue, or we can drop out entirely.

If there is no match at priority 1, it is not a valid extension anymore. Try to continue at "i" (for invalid) or "e" (for exception) or exit if neither exist.

Definition at line 4226 of file pbx.c.

References ast_channel::_softhangup, ast_calloc, ast_cdr_end(), ast_cdr_update(), ast_check_hangup(), ast_clear_flag, ast_copy_string(), ast_debug, ast_exists_extension(), AST_FLAG_BRIDGE_HANGUP_RUN, AST_FLAG_IN_AUTOLOOP, ast_free, ast_hangup(), ast_log(), ast_matchmore_extension(), ast_opt_end_cdr_before_h_exten, AST_PBX_ERROR, AST_PBX_INCOMPLETE, ast_set2_flag, ast_set_flag, ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, AST_SOFTHANGUP_ASYNCGOTO, AST_SOFTHANGUP_TIMEOUT, ast_spawn_extension(), ast_strlen_zero(), ast_test_flag, ast_verb, autofallthrough, ast_channel::cdr, ast_channel::cid, ast_callerid::cid_num, collect_digits(), ast_channel::context, ast_pbx::dtimeoutms, ast_channel::exten, LOG_WARNING, ast_channel::name, ast_pbx_args::no_hangup_chan, ast_channel::pbx, pbx_builtin_busy(), pbx_builtin_congestion(), pbx_builtin_getvar_helper(), pbx_builtin_raise_exception(), pbx_builtin_setvar_helper(), pbx_destroy(), ast_channel::priority, ast_pbx::rtimeoutms, set_ext_pri(), status, and ast_channel::whentohangup.

Referenced by ast_pbx_run_args(), and pbx_thread().

04228 {
04229    int found = 0; /* set if we find at least one match */
04230    int res = 0;
04231    int autoloopflag;
04232    int error = 0;    /* set an error conditions */
04233 
04234    /* A little initial setup here */
04235    if (c->pbx) {
04236       ast_log(LOG_WARNING, "%s already has PBX structure??\n", c->name);
04237       /* XXX and now what ? */
04238       ast_free(c->pbx);
04239    }
04240    if (!(c->pbx = ast_calloc(1, sizeof(*c->pbx))))
04241       return -1;
04242    /* Set reasonable defaults */
04243    c->pbx->rtimeoutms = 10000;
04244    c->pbx->dtimeoutms = 5000;
04245 
04246    autoloopflag = ast_test_flag(c, AST_FLAG_IN_AUTOLOOP);   /* save value to restore at the end */
04247    ast_set_flag(c, AST_FLAG_IN_AUTOLOOP);
04248 
04249    /* Start by trying whatever the channel is set to */
04250    if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
04251       /* If not successful fall back to 's' */
04252       ast_verb(2, "Starting %s at %s,%s,%d failed so falling back to exten 's'\n", c->name, c->context, c->exten, c->priority);
04253       /* XXX the original code used the existing priority in the call to
04254        * ast_exists_extension(), and reset it to 1 afterwards.
04255        * I believe the correct thing is to set it to 1 immediately.
04256        */
04257       set_ext_pri(c, "s", 1);
04258       if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
04259          /* JK02: And finally back to default if everything else failed */
04260          ast_verb(2, "Starting %s at %s,%s,%d still failed so falling back to context 'default'\n", c->name, c->context, c->exten, c->priority);
04261          ast_copy_string(c->context, "default", sizeof(c->context));
04262       }
04263    }
04264    if (c->cdr) {
04265       /* allow CDR variables that have been collected after channel was created to be visible during call */
04266       ast_cdr_update(c);
04267    }
04268    for (;;) {
04269       char dst_exten[256]; /* buffer to accumulate digits */
04270       int pos = 0;      /* XXX should check bounds */
04271       int digit = 0;
04272       int invalid = 0;
04273       int timeout = 0;
04274 
04275       /* loop on priorities in this context/exten */
04276       while ( !(res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num, &found,1))) {
04277          if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT && ast_exists_extension(c, c->context, "T", 1, c->cid.cid_num)) {
04278             set_ext_pri(c, "T", 0); /* 0 will become 1 with the c->priority++; at the end */
04279             /* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
04280             memset(&c->whentohangup, 0, sizeof(c->whentohangup));
04281             c->_softhangup &= ~AST_SOFTHANGUP_TIMEOUT;
04282          } else if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT && ast_exists_extension(c, c->context, "e", 1, c->cid.cid_num)) {
04283             pbx_builtin_raise_exception(c, "ABSOLUTETIMEOUT");
04284             /* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
04285             memset(&c->whentohangup, 0, sizeof(c->whentohangup));
04286             c->_softhangup &= ~AST_SOFTHANGUP_TIMEOUT;
04287          } else if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
04288             c->_softhangup = 0;
04289             continue;
04290          } else if (ast_check_hangup(c)) {
04291             ast_debug(1, "Extension %s, priority %d returned normally even though call was hung up\n",
04292                c->exten, c->priority);
04293             error = 1;
04294             break;
04295          }
04296          c->priority++;
04297       } /* end while  - from here on we can use 'break' to go out */
04298       if (found && res) {
04299          /* Something bad happened, or a hangup has been requested. */
04300          if (strchr("0123456789ABCDEF*#", res)) {
04301             ast_debug(1, "Oooh, got something to jump out with ('%c')!\n", res);
04302             pos = 0;
04303             dst_exten[pos++] = digit = res;
04304             dst_exten[pos] = '\0';
04305          } else if (res == AST_PBX_INCOMPLETE) {
04306             ast_debug(1, "Spawn extension (%s,%s,%d) exited INCOMPLETE on '%s'\n", c->context, c->exten, c->priority, c->name);
04307             ast_verb(2, "Spawn extension (%s, %s, %d) exited INCOMPLETE on '%s'\n", c->context, c->exten, c->priority, c->name);
04308 
04309             /* Don't cycle on incomplete - this will happen if the only extension that matches is our "incomplete" extension */
04310             if (!ast_matchmore_extension(c, c->context, c->exten, 1, c->cid.cid_num)) {
04311                invalid = 1;
04312             } else {
04313                ast_copy_string(dst_exten, c->exten, sizeof(dst_exten));
04314                digit = 1;
04315                pos = strlen(dst_exten);
04316             }
04317          } else {
04318             ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
04319             ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
04320 
04321             if ((res == AST_PBX_ERROR) && ast_exists_extension(c, c->context, "e", 1, c->cid.cid_num)) {
04322                /* if we are already on the 'e' exten, don't jump to it again */
04323                if (!strcmp(c->exten, "e")) {
04324                   ast_verb(2, "Spawn extension (%s, %s, %d) exited ERROR while already on 'e' exten on '%s'\n", c->context, c->exten, c->priority, c->name);
04325                   error = 1;
04326                } else {
04327                   pbx_builtin_raise_exception(c, "ERROR");
04328                   continue;
04329                }
04330             }
04331 
04332             if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
04333                c->_softhangup = 0;
04334                continue;
04335             } else if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT && ast_exists_extension(c, c->context, "T", 1, c->cid.cid_num)) {
04336                set_ext_pri(c, "T", 1);
04337                /* If the AbsoluteTimeout is not reset to 0, we'll get an infinite loop */
04338                memset(&c->whentohangup, 0, sizeof(c->whentohangup));
04339                c->_softhangup &= ~AST_SOFTHANGUP_TIMEOUT;
04340                continue;
04341             } else {
04342                if (c->cdr)
04343                   ast_cdr_update(c);
04344                error = 1;
04345                break;
04346             }
04347          }
04348       }
04349       if (error)
04350          break;
04351 
04352       /*!\note
04353        * We get here on a failure of some kind:  non-existing extension or
04354        * hangup.  We have options, here.  We can either catch the failure
04355        * and continue, or we can drop out entirely. */
04356 
04357       if (invalid || !ast_exists_extension(c, c->context, c->exten, 1, c->cid.cid_num)) {
04358          /*!\note
04359           * If there is no match at priority 1, it is not a valid extension anymore.
04360           * Try to continue at "i" (for invalid) or "e" (for exception) or exit if
04361           * neither exist.
04362           */
04363          if (ast_exists_extension(c, c->context, "i", 1, c->cid.cid_num)) {
04364             ast_verb(3, "Sent into invalid extension '%s' in context '%s' on %s\n", c->exten, c->context, c->name);
04365             pbx_builtin_setvar_helper(c, "INVALID_EXTEN", c->exten);
04366             set_ext_pri(c, "i", 1);
04367          } else if (ast_exists_extension(c, c->context, "e", 1, c->cid.cid_num)) {
04368             pbx_builtin_raise_exception(c, "INVALID");
04369          } else {
04370             ast_log(LOG_WARNING, "Channel '%s' sent into invalid extension '%s' in context '%s', but no invalid handler\n",
04371                c->name, c->exten, c->context);
04372             error = 1; /* we know what to do with it */
04373             break;
04374          }
04375       } else if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT) {
04376          /* If we get this far with AST_SOFTHANGUP_TIMEOUT, then we know that the "T" extension is next. */
04377          c->_softhangup = 0;
04378       } else { /* keypress received, get more digits for a full extension */
04379          int waittime = 0;
04380          if (digit)
04381             waittime = c->pbx->dtimeoutms;
04382          else if (!autofallthrough)
04383             waittime = c->pbx->rtimeoutms;
04384          if (!waittime) {
04385             const char *status = pbx_builtin_getvar_helper(c, "DIALSTATUS");
04386             if (!status)
04387                status = "UNKNOWN";
04388             ast_verb(3, "Auto fallthrough, channel '%s' status is '%s'\n", c->name, status);
04389             if (!strcasecmp(status, "CONGESTION"))
04390                res = pbx_builtin_congestion(c, "10");
04391             else if (!strcasecmp(status, "CHANUNAVAIL"))
04392                res = pbx_builtin_congestion(c, "10");
04393             else if (!strcasecmp(status, "BUSY"))
04394                res = pbx_builtin_busy(c, "10");
04395             error = 1; /* XXX disable message */
04396             break;   /* exit from the 'for' loop */
04397          }
04398 
04399          if (collect_digits(c, waittime, dst_exten, sizeof(dst_exten), pos))
04400             break;
04401          if (res == AST_PBX_INCOMPLETE && ast_strlen_zero(&dst_exten[pos]))
04402             timeout = 1;
04403          if (!timeout && ast_exists_extension(c, c->context, dst_exten, 1, c->cid.cid_num)) /* Prepare the next cycle */
04404             set_ext_pri(c, dst_exten, 1);
04405          else {
04406             /* No such extension */
04407             if (!timeout && !ast_strlen_zero(dst_exten)) {
04408                /* An invalid extension */
04409                if (ast_exists_extension(c, c->context, "i", 1, c->cid.cid_num)) {
04410                   ast_verb(3, "Invalid extension '%s' in context '%s' on %s\n", dst_exten, c->context, c->name);
04411                   pbx_builtin_setvar_helper(c, "INVALID_EXTEN", dst_exten);
04412                   set_ext_pri(c, "i", 1);
04413                } else if (ast_exists_extension(c, c->context, "e", 1, c->cid.cid_num)) {
04414                   pbx_builtin_raise_exception(c, "INVALID");
04415                } else {
04416                   ast_log(LOG_WARNING, "Invalid extension '%s', but no rule 'i' in context '%s'\n", dst_exten, c->context);
04417                   found = 1; /* XXX disable message */
04418                   break;
04419                }
04420             } else {
04421                /* A simple timeout */
04422                if (ast_exists_extension(c, c->context, "t", 1, c->cid.cid_num)) {
04423                   ast_verb(3, "Timeout on %s\n", c->name);
04424                   set_ext_pri(c, "t", 1);
04425                } else if (ast_exists_extension(c, c->context, "e", 1, c->cid.cid_num)) {
04426                   pbx_builtin_raise_exception(c, "RESPONSETIMEOUT");
04427                } else {
04428                   ast_log(LOG_WARNING, "Timeout, but no rule 't' in context '%s'\n", c->context);
04429                   found = 1; /* XXX disable message */
04430                   break;
04431                }
04432             }
04433          }
04434          if (c->cdr) {
04435             ast_verb(2, "CDR updated on %s\n",c->name);
04436             ast_cdr_update(c);
04437          }
04438       }
04439    }
04440 
04441    if (!found && !error) {
04442       ast_log(LOG_WARNING, "Don't know what to do with '%s'\n", c->name);
04443    }
04444 
04445    if (!args || !args->no_hangup_chan) {
04446       ast_softhangup(c, AST_SOFTHANGUP_APPUNLOAD);
04447    }
04448 
04449    if ((!args || !args->no_hangup_chan) &&
04450          !ast_test_flag(c, AST_FLAG_BRIDGE_HANGUP_RUN) &&
04451          ast_exists_extension(c, c->context, "h", 1, c->cid.cid_num)) {
04452       set_ext_pri(c, "h", 1);
04453       if (c->cdr && ast_opt_end_cdr_before_h_exten) {
04454          ast_cdr_end(c->cdr);
04455       }
04456       while ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num, &found, 1)) == 0) {
04457          c->priority++;
04458       }
04459       if (found && res) {
04460          /* Something bad happened, or a hangup has been requested. */
04461          ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
04462          ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
04463       }
04464    }
04465    ast_set2_flag(c, autoloopflag, AST_FLAG_IN_AUTOLOOP);
04466    ast_clear_flag(c, AST_FLAG_BRIDGE_HANGUP_RUN); /* from one round to the next, make sure this gets cleared */
04467    pbx_destroy(c->pbx);
04468    c->pbx = NULL;
04469 
04470    if (!args || !args->no_hangup_chan) {
04471       ast_hangup(c);
04472    }
04473 
04474    return 0;
04475 }

static void __init_extensionstate_buf ( void   )  [static]

Definition at line 761 of file pbx.c.

00764 : An extension

static void __init_switch_data ( void   )  [static]

Definition at line 760 of file pbx.c.

00764 : An extension

static int _extension_match_core ( const char *  pattern,
const char *  data,
enum ext_match_t  mode 
) [static]

Definition at line 2226 of file pbx.c.

References ast_log(), E_MATCH, E_MATCH_MASK, E_MATCHMORE, LOG_NOTICE, and LOG_WARNING.

Referenced by extension_match_core().

02227 {
02228    mode &= E_MATCH_MASK;   /* only consider the relevant bits */
02229 
02230 #ifdef NEED_DEBUG_HERE
02231    ast_log(LOG_NOTICE,"match core: pat: '%s', dat: '%s', mode=%d\n", pattern, data, (int)mode);
02232 #endif
02233 
02234    if ( (mode == E_MATCH) && (pattern[0] == '_') && (!strcasecmp(pattern,data)) ) { /* note: if this test is left out, then _x. will not match _x. !!! */
02235 #ifdef NEED_DEBUG_HERE
02236       ast_log(LOG_NOTICE,"return (1) - pattern matches pattern\n");
02237 #endif
02238       return 1;
02239    }
02240 
02241    if (pattern[0] != '_') { /* not a pattern, try exact or partial match */
02242       int ld = strlen(data), lp = strlen(pattern);
02243 
02244       if (lp < ld) {    /* pattern too short, cannot match */
02245 #ifdef NEED_DEBUG_HERE
02246          ast_log(LOG_NOTICE,"return (0) - pattern too short, cannot match\n");
02247 #endif
02248          return 0;
02249       }
02250       /* depending on the mode, accept full or partial match or both */
02251       if (mode == E_MATCH) {
02252 #ifdef NEED_DEBUG_HERE
02253          ast_log(LOG_NOTICE,"return (!strcmp(%s,%s) when mode== E_MATCH)\n", pattern, data);
02254 #endif
02255          return !strcmp(pattern, data); /* 1 on match, 0 on fail */
02256       }
02257       if (ld == 0 || !strncasecmp(pattern, data, ld)) { /* partial or full match */
02258 #ifdef NEED_DEBUG_HERE
02259          ast_log(LOG_NOTICE,"return (mode(%d) == E_MATCHMORE ? lp(%d) > ld(%d) : 1)\n", mode, lp, ld);
02260 #endif
02261          return (mode == E_MATCHMORE) ? lp > ld : 1; /* XXX should consider '!' and '/' ? */
02262       } else {
02263 #ifdef NEED_DEBUG_HERE
02264          ast_log(LOG_NOTICE,"return (0) when ld(%d) > 0 && pattern(%s) != data(%s)\n", ld, pattern, data);
02265 #endif
02266          return 0;
02267       }
02268    }
02269    pattern++; /* skip leading _ */
02270    /*
02271     * XXX below we stop at '/' which is a separator for the CID info. However we should
02272     * not store '/' in the pattern at all. When we insure it, we can remove the checks.
02273     */
02274    while (*data && *pattern && *pattern != '/') {
02275       const char *end;
02276 
02277       if (*data == '-') { /* skip '-' in data (just a separator) */
02278          data++;
02279          continue;
02280       }
02281       switch (toupper(*pattern)) {
02282       case '[':   /* a range */
02283          end = strchr(pattern+1, ']'); /* XXX should deal with escapes ? */
02284          if (end == NULL) {
02285             ast_log(LOG_WARNING, "Wrong usage of [] in the extension\n");
02286             return 0;   /* unconditional failure */
02287          }
02288          for (pattern++; pattern != end; pattern++) {
02289             if (pattern+2 < end && pattern[1] == '-') { /* this is a range */
02290                if (*data >= pattern[0] && *data <= pattern[2])
02291                   break;   /* match found */
02292                else {
02293                   pattern += 2; /* skip a total of 3 chars */
02294                   continue;
02295                }
02296             } else if (*data == pattern[0])
02297                break;   /* match found */
02298          }
02299          if (pattern == end) {
02300 #ifdef NEED_DEBUG_HERE
02301             ast_log(LOG_NOTICE,"return (0) when pattern==end\n");
02302 #endif
02303             return 0;
02304          }
02305          pattern = end; /* skip and continue */
02306          break;
02307       case 'N':
02308          if (*data < '2' || *data > '9') {
02309 #ifdef NEED_DEBUG_HERE
02310             ast_log(LOG_NOTICE,"return (0) N is matched\n");
02311 #endif
02312             return 0;
02313          }
02314          break;
02315       case 'X':
02316          if (*data < '0' || *data > '9') {
02317 #ifdef NEED_DEBUG_HERE
02318             ast_log(LOG_NOTICE,"return (0) X is matched\n");
02319 #endif
02320             return 0;
02321          }
02322          break;
02323       case 'Z':
02324          if (*data < '1' || *data > '9') {
02325 #ifdef NEED_DEBUG_HERE
02326             ast_log(LOG_NOTICE,"return (0) Z is matched\n");
02327 #endif
02328             return 0;
02329          }
02330          break;
02331       case '.':   /* Must match, even with more digits */
02332 #ifdef NEED_DEBUG_HERE
02333          ast_log(LOG_NOTICE, "return (1) when '.' is matched\n");
02334 #endif
02335          return 1;
02336       case '!':   /* Early match */
02337 #ifdef NEED_DEBUG_HERE
02338          ast_log(LOG_NOTICE, "return (2) when '!' is matched\n");
02339 #endif
02340          return 2;
02341       case ' ':
02342       case '-':   /* Ignore these in patterns */
02343          data--; /* compensate the final data++ */
02344          break;
02345       default:
02346          if (*data != *pattern) {
02347 #ifdef NEED_DEBUG_HERE
02348             ast_log(LOG_NOTICE, "return (0) when *data(%c) != *pattern(%c)\n", *data, *pattern);
02349 #endif
02350             return 0;
02351          }
02352       }
02353       data++;
02354       pattern++;
02355    }
02356    if (*data)        /* data longer than pattern, no match */ {
02357 #ifdef NEED_DEBUG_HERE
02358       ast_log(LOG_NOTICE, "return (0) when data longer than pattern\n");
02359 #endif
02360       return 0;
02361    }
02362 
02363    /*
02364     * match so far, but ran off the end of the data.
02365     * Depending on what is next, determine match or not.
02366     */
02367    if (*pattern == '\0' || *pattern == '/') {   /* exact match */
02368 #ifdef NEED_DEBUG_HERE
02369       ast_log(LOG_NOTICE, "at end, return (%d) in 'exact match'\n", (mode==E_MATCHMORE) ? 0 : 1);
02370 #endif
02371       return (mode == E_MATCHMORE) ? 0 : 1;  /* this is a failure for E_MATCHMORE */
02372    } else if (*pattern == '!')   {     /* early match */
02373 #ifdef NEED_DEBUG_HERE
02374       ast_log(LOG_NOTICE, "at end, return (2) when '!' is matched\n");
02375 #endif
02376       return 2;
02377    } else {                /* partial match */
02378 #ifdef NEED_DEBUG_HERE
02379       ast_log(LOG_NOTICE, "at end, return (%d) which deps on E_MATCH\n", (mode == E_MATCH) ? 0 : 1);
02380 #endif
02381       return (mode == E_MATCH) ? 0 : 1;   /* this is a failure for E_MATCH */
02382    }
02383 }

static int acf_exception_read ( struct ast_channel *  chan,
const char *  name,
char *  data,
char *  buf,
size_t  buflen 
) [static]

Definition at line 3028 of file pbx.c.

References ast_channel_datastore_find(), ast_copy_string(), pbx_exception::context, ast_datastore::data, exception_store_info, pbx_exception::exten, pbx_exception::priority, and pbx_exception::reason.

03029 {
03030    struct ast_datastore *ds = ast_channel_datastore_find(chan, &exception_store_info, NULL);
03031    struct pbx_exception *exception = NULL;
03032    if (!ds || !ds->data)
03033       return -1;
03034    exception = ds->data;
03035    if (!strcasecmp(data, "REASON"))
03036       ast_copy_string(buf, exception->reason, buflen);
03037    else if (!strcasecmp(data, "CONTEXT"))
03038       ast_copy_string(buf, exception->context, buflen);
03039    else if (!strncasecmp(data, "EXTEN", 5))
03040       ast_copy_string(buf, exception->exten, buflen);
03041    else if (!strcasecmp(data, "PRIORITY"))
03042       snprintf(buf, buflen, "%d", exception->priority);
03043    else
03044       return -1;
03045    return 0;
03046 }

static int acf_retrieve_docs ( struct ast_custom_function *  acf  )  [static]

Definition at line 3244 of file pbx.c.

References ast_custom_function::arguments, ast_free, ast_string_field_init, ast_string_field_set, ast_strlen_zero(), AST_XML_DOC, ast_xmldoc_build_arguments(), ast_xmldoc_build_description(), ast_xmldoc_build_seealso(), ast_xmldoc_build_synopsis(), ast_xmldoc_build_syntax(), desc, ast_custom_function::desc, ast_custom_function::docsrc, ast_custom_function::name, ast_custom_function::seealso, synopsis, ast_custom_function::synopsis, and ast_custom_function::syntax.

Referenced by __ast_custom_function_register().

03245 {
03246 #ifdef AST_XML_DOCS
03247    char *tmpxml;
03248 
03249    /* Let's try to find it in the Documentation XML */
03250    if (!ast_strlen_zero(acf->desc) || !ast_strlen_zero(acf->synopsis)) {
03251       return 0;
03252    }
03253 
03254    if (ast_string_field_init(acf, 128)) {
03255       return -1;
03256    }
03257 
03258    /* load synopsis */
03259    tmpxml = ast_xmldoc_build_synopsis("function", acf->name);
03260    ast_string_field_set(acf, synopsis, tmpxml);
03261    ast_free(tmpxml);
03262 
03263    /* load description */
03264    tmpxml = ast_xmldoc_build_description("function", acf->name);
03265    ast_string_field_set(acf, desc, tmpxml);
03266    ast_free(tmpxml);
03267 
03268    /* load syntax */
03269    tmpxml = ast_xmldoc_build_syntax("function", acf->name);
03270    ast_string_field_set(acf, syntax, tmpxml);
03271    ast_free(tmpxml);
03272 
03273    /* load arguments */
03274    tmpxml = ast_xmldoc_build_arguments("function", acf->name);
03275    ast_string_field_set(acf, arguments, tmpxml);
03276    ast_free(tmpxml);
03277 
03278    /* load seealso */
03279    tmpxml = ast_xmldoc_build_seealso("function", acf->name);
03280    ast_string_field_set(acf, seealso, tmpxml);
03281    ast_free(tmpxml);
03282 
03283    acf->docsrc = AST_XML_DOC;
03284 #endif
03285 
03286    return 0;
03287 }

static struct match_char * add_exten_to_pattern_tree ( struct ast_context *  con,
struct ast_exten *  e1,
int  findonly 
) [static, read]

Definition at line 1873 of file pbx.c.

References add_pattern_node(), already_in_tree(), ast_copy_string(), ast_log(), buf, ast_exten::cidmatch, compare_char(), match_char::deleted, match_char::exten, ast_exten::exten, LOG_DEBUG, LOG_ERROR, LOG_WARNING, m1, m2, ast_exten::matchcid, match_char::next_char, and ast_context::pattern_tree.

Referenced by add_pri_lockopt(), ast_add_extension2_lockopt(), ast_context_remove_extension_callerid2(), and create_match_char_tree().

01874 {
01875    struct match_char *m1 = NULL, *m2 = NULL, **m0;
01876    int specif;
01877    int already;
01878    int pattern = 0;
01879    char buf[256];
01880    char extenbuf[512];
01881    char *s1 = extenbuf;
01882    int l1 = strlen(e1->exten) + strlen(e1->cidmatch) + 2;
01883 
01884 
01885    ast_copy_string(extenbuf, e1->exten, sizeof(extenbuf));
01886 
01887    if (e1->matchcid &&  l1 <= sizeof(extenbuf)) {
01888       strcat(extenbuf, "/");
01889       strcat(extenbuf, e1->cidmatch);
01890    } else if (l1 > sizeof(extenbuf)) {
01891       ast_log(LOG_ERROR, "The pattern %s/%s is too big to deal with: it will be ignored! Disaster!\n", e1->exten, e1->cidmatch);
01892       return 0;
01893    }
01894 #ifdef NEED_DEBUG
01895    ast_log(LOG_DEBUG, "Adding exten %s%c%s to tree\n", s1, e1->matchcid ? '/' : ' ', e1->matchcid ? e1->cidmatch : "");
01896 #endif
01897    m1 = con->pattern_tree; /* each pattern starts over at the root of the pattern tree */
01898    m0 = &con->pattern_tree;
01899    already = 1;
01900 
01901    if ( *s1 == '_') {
01902       pattern = 1;
01903       s1++;
01904    }
01905    while( *s1 ) {
01906       if (pattern && *s1 == '[' && *(s1-1) != '\\') {
01907          char *s2 = buf;
01908          buf[0] = 0;
01909          s1++; /* get past the '[' */
01910          while (*s1 != ']' && *(s1 - 1) != '\\' ) {
01911             if (*s1 == '\\') {
01912                if (*(s1 + 1) == ']') {
01913                   *s2++ = ']';
01914                   s1++; s1++;
01915                } else if (*(s1 + 1) == '\\') {
01916                   *s2++ = '\\';
01917                   s1++; s1++;
01918                } else if (*(s1 + 1) == '-') {
01919                   *s2++ = '-';
01920                   s1++; s1++;
01921                } else if (*(s1 + 1) == '[') {
01922                   *s2++ = '[';
01923                   s1++; s1++;
01924                }
01925             } else if (*s1 == '-') { /* remember to add some error checking to all this! */
01926                char s3 = *(s1 - 1);
01927                char s4 = *(s1 + 1);
01928                for (s3++; s3 <= s4; s3++) {
01929                   *s2++ = s3;
01930                }
01931                s1++; s1++;
01932             } else if (*s1 == '\0') {
01933                ast_log(LOG_WARNING, "A matching ']' was not found for '[' in pattern string '%s'\n", extenbuf);
01934                break;
01935             } else {
01936                *s2++ = *s1++;
01937             }
01938          }
01939          *s2 = 0; /* null terminate the exploded range */
01940          /* sort the characters */
01941 
01942          specif = strlen(buf);
01943          qsort(buf, specif, 1, compare_char);
01944          specif <<= 8;
01945          specif += buf[0];
01946       } else {
01947 
01948          if (*s1 == '\\') {
01949             s1++;
01950             buf[0] = *s1;
01951          } else {
01952             if (pattern) {
01953                if (*s1 == 'n') /* make sure n,x,z patterns are canonicalized to N,X,Z */
01954                   *s1 = 'N';
01955                else if (*s1 == 'x')
01956                   *s1 = 'X';
01957                else if (*s1 == 'z')
01958                   *s1 = 'Z';
01959             }
01960             buf[0] = *s1;
01961          }
01962          buf[1] = 0;
01963          specif = 1;
01964       }
01965       m2 = 0;
01966       if (already && (m2 = already_in_tree(m1,buf)) && m2->next_char) {
01967          if (!(*(s1 + 1))) {  /* if this is the end of the pattern, but not the end of the tree, then mark this node with the exten...
01968                           * a shorter pattern might win if the longer one doesn't match */
01969             m2->exten = e1;
01970             m2->deleted = 0;
01971          }
01972          m1 = m2->next_char; /* m1 points to the node to compare against */
01973          m0 = &m2->next_char; /* m0 points to the ptr that points to m1 */
01974       } else { /* not already OR not m2 OR nor m2->next_char */
01975          if (m2) {
01976             if (findonly) {
01977                return m2;
01978             }
01979             m1 = m2; /* while m0 stays the same */
01980          } else {
01981             if (findonly) {
01982                return m1;
01983             }
01984             m1 = add_pattern_node(con, m1, buf, pattern, already,specif, m0); /* m1 is the node just added */
01985             m0 = &m1->next_char;
01986          }
01987 
01988          if (!(*(s1 + 1))) {
01989             m1->deleted = 0;
01990             m1->exten = e1;
01991          }
01992 
01993          already = 0;
01994       }
01995       s1++; /* advance to next char */
01996    }
01997    return m1;
01998 }

static struct match_char * add_pattern_node ( struct ast_context *  con,
struct match_char *  current,
char *  pattern,
int  is_pattern,
int  already,
int  specificity,
struct match_char **  parent 
) [static, read]

Definition at line 1831 of file pbx.c.

References ast_calloc, ast_free, ast_strdup, insert_in_next_chars_alt_char_list(), match_char::is_pattern, match_char::next_char, ast_context::pattern_tree, match_char::specificity, and match_char::x.

Referenced by add_exten_to_pattern_tree().

01832 {
01833    struct match_char *m;
01834 
01835    if (!(m = ast_calloc(1, sizeof(*m)))) {
01836       return NULL;
01837    }
01838 
01839    if (!(m->x = ast_strdup(pattern))) {
01840       ast_free(m);
01841       return NULL;
01842    }
01843 
01844    /* the specificity scores are the same as used in the old
01845       pattern matcher. */
01846    m->is_pattern = is_pattern;
01847    if (specificity == 1 && is_pattern && pattern[0] == 'N')
01848       m->specificity = 0x0802;
01849    else if (specificity == 1 && is_pattern && pattern[0] == 'Z')
01850       m->specificity = 0x0901;
01851    else if (specificity == 1 && is_pattern && pattern[0] == 'X')
01852       m->specificity = 0x0a00;
01853    else if (specificity == 1 && is_pattern && pattern[0] == '.')
01854       m->specificity = 0x10000;
01855    else if (specificity == 1 && is_pattern && pattern[0] == '!')
01856       m->specificity = 0x20000;
01857    else
01858       m->specificity = specificity;
01859 
01860    if (!con->pattern_tree) {
01861       insert_in_next_chars_alt_char_list(&con->pattern_tree, m);
01862    } else {
01863       if (already) { /* switch to the new regime (traversing vs appending)*/
01864          insert_in_next_chars_alt_char_list(nextcharptr, m);
01865       } else {
01866          insert_in_next_chars_alt_char_list(&current->next_char, m);
01867       }
01868    }
01869 
01870    return m;
01871 }

static int add_pri ( struct ast_context *  con,
struct ast_exten *  tmp,
struct ast_exten *  el,
struct ast_exten *  e,
int  replace 
) [static]

add the extension in the priority chain.

Return values:
0 on success.
-1 on failure.

Definition at line 7452 of file pbx.c.

References add_pri_lockopt().

Referenced by ast_add_extension2_lockopt().

07454 {
07455    return add_pri_lockopt(con, tmp, el, e, replace, 1);
07456 }

static int add_pri_lockopt ( struct ast_context *  con,
struct ast_exten *  tmp,
struct ast_exten *  el,
struct ast_exten *  e,
int  replace,
int  lockhints 
) [static]

add the extension in the priority chain.

Return values:
0 on success.
-1 on failure.

Definition at line 7463 of file pbx.c.

References add_exten_to_pattern_tree(), ast_add_hint(), ast_add_hint_nolock(), ast_change_hint(), ast_free, ast_hashtab_insert_safe(), ast_hashtab_remove_object_via_lookup(), ast_log(), ast_exten::data, ast_exten::datad, match_char::exten, ast_exten::exten, ast_exten::label, LOG_ERROR, LOG_WARNING, ast_context::name, ast_exten::next, ast_exten::peer, ast_exten::peer_label_table, ast_exten::peer_table, ast_exten::priority, PRIORITY_HINT, ast_context::root, ast_context::root_table, and match_char::x.

Referenced by add_pri().

07465 {
07466    struct ast_exten *ep;
07467    struct ast_exten *eh=e;
07468 
07469    for (ep = NULL; e ; ep = e, e = e->peer) {
07470       if (e->priority >= tmp->priority)
07471          break;
07472    }
07473    if (!e) {   /* go at the end, and ep is surely set because the list is not empty */
07474       ast_hashtab_insert_safe(eh->peer_table, tmp);
07475 
07476       if (tmp->label) {
07477          ast_hashtab_insert_safe(eh->peer_label_table, tmp);
07478       }
07479       ep->peer = tmp;
07480       return 0;   /* success */
07481    }
07482    if (e->priority == tmp->priority) {
07483       /* Can't have something exactly the same.  Is this a
07484          replacement?  If so, replace, otherwise, bonk. */
07485       if (!replace) {
07486          ast_log(LOG_WARNING, "Unable to register extension '%s', priority %d in '%s', already in use\n", tmp->exten, tmp->priority, con->name);
07487          if (tmp->datad) {
07488             tmp->datad(tmp->data);
07489             /* if you free this, null it out */
07490             tmp->data = NULL;
07491          }
07492 
07493          ast_free(tmp);
07494          return -1;
07495       }
07496       /* we are replacing e, so copy the link fields and then update
07497        * whoever pointed to e to point to us
07498        */
07499       tmp->next = e->next; /* not meaningful if we are not first in the peer list */
07500       tmp->peer = e->peer; /* always meaningful */
07501       if (ep)  {     /* We're in the peer list, just insert ourselves */
07502          ast_hashtab_remove_object_via_lookup(eh->peer_table,e);
07503 
07504          if (e->label) {
07505             ast_hashtab_remove_object_via_lookup(eh->peer_label_table,e);
07506          }
07507 
07508          ast_hashtab_insert_safe(eh->peer_table,tmp);
07509          if (tmp->label) {
07510             ast_hashtab_insert_safe(eh->peer_label_table,tmp);
07511          }
07512 
07513          ep->peer = tmp;
07514       } else if (el) {     /* We're the first extension. Take over e's functions */
07515          struct match_char *x = add_exten_to_pattern_tree(con, e, 1);
07516          tmp->peer_table = e->peer_table;
07517          tmp->peer_label_table = e->peer_label_table;
07518          ast_hashtab_remove_object_via_lookup(tmp->peer_table,e);
07519          ast_hashtab_insert_safe(tmp->peer_table,tmp);
07520          if (e->label) {
07521             ast_hashtab_remove_object_via_lookup(tmp->peer_label_table, e);
07522          }
07523          if (tmp->label) {
07524             ast_hashtab_insert_safe(tmp->peer_label_table, tmp);
07525          }
07526 
07527          ast_hashtab_remove_object_via_lookup(con->root_table, e);
07528          ast_hashtab_insert_safe(con->root_table, tmp);
07529          el->next = tmp;
07530          /* The pattern trie points to this exten; replace the pointer,
07531             and all will be well */
07532          if (x) { /* if the trie isn't formed yet, don't sweat this */
07533             if (x->exten) { /* this test for safety purposes */
07534                x->exten = tmp; /* replace what would become a bad pointer */
07535             } else {
07536                ast_log(LOG_ERROR,"Trying to delete an exten from a context, but the pattern tree node returned isn't an extension\n");
07537             }
07538          }
07539       } else {       /* We're the very first extension.  */
07540          struct match_char *x = add_exten_to_pattern_tree(con, e, 1);
07541          ast_hashtab_remove_object_via_lookup(con->root_table, e);
07542          ast_hashtab_insert_safe(con->root_table, tmp);
07543          tmp->peer_table = e->peer_table;
07544          tmp->peer_label_table = e->peer_label_table;
07545          ast_hashtab_remove_object_via_lookup(tmp->peer_table, e);
07546          ast_hashtab_insert_safe(tmp->peer_table, tmp);
07547          if (e->label) {
07548             ast_hashtab_remove_object_via_lookup(tmp->peer_label_table, e);
07549          }
07550          if (tmp->label) {
07551             ast_hashtab_insert_safe(tmp->peer_label_table, tmp);
07552          }
07553 
07554          ast_hashtab_remove_object_via_lookup(con->root_table, e);
07555          ast_hashtab_insert_safe(con->root_table, tmp);
07556          con->root = tmp;
07557          /* The pattern trie points to this exten; replace the pointer,
07558             and all will be well */
07559          if (x) { /* if the trie isn't formed yet; no problem */
07560             if (x->exten) { /* this test for safety purposes */
07561                x->exten = tmp; /* replace what would become a bad pointer */
07562             } else {
07563                ast_log(LOG_ERROR,"Trying to delete an exten from a context, but the pattern tree node returned isn't an extension\n");
07564             }
07565          }
07566       }
07567       if (tmp->priority == PRIORITY_HINT)
07568          ast_change_hint(e,tmp);
07569       /* Destroy the old one */
07570       if (e->datad)
07571          e->datad(e->data);
07572       ast_free(e);
07573    } else { /* Slip ourselves in just before e */
07574       tmp->peer = e;
07575       tmp->next = e->next; /* extension chain, or NULL if e is not the first extension */
07576       if (ep) {         /* Easy enough, we're just in the peer list */
07577          if (tmp->label) {
07578             ast_hashtab_insert_safe(eh->peer_label_table, tmp);
07579          }
07580          ast_hashtab_insert_safe(eh->peer_table, tmp);
07581          ep->peer = tmp;
07582       } else {       /* we are the first in some peer list, so link in the ext list */
07583          tmp->peer_table = e->peer_table;
07584          tmp->peer_label_table = e->peer_label_table;
07585          e->peer_table = 0;
07586          e->peer_label_table = 0;
07587          ast_hashtab_insert_safe(tmp->peer_table, tmp);
07588          if (tmp->label) {
07589             ast_hashtab_insert_safe(tmp->peer_label_table, tmp);
07590          }
07591          ast_hashtab_remove_object_via_lookup(con->root_table, e);
07592          ast_hashtab_insert_safe(con->root_table, tmp);
07593          if (el)
07594             el->next = tmp;   /* in the middle... */
07595          else
07596             con->root = tmp; /* ... or at the head */
07597          e->next = NULL;   /* e is no more at the head, so e->next must be reset */
07598       }
07599       /* And immediately return success. */
07600       if (tmp->priority == PRIORITY_HINT) {
07601          if (lockhints) {
07602             ast_add_hint(tmp);
07603          } else {
07604             ast_add_hint_nolock(tmp);
07605          }
07606       }
07607    }
07608    return 0;
07609 }

static struct match_char * already_in_tree ( struct match_char *  current,
char *  pat 
) [static, read]

Definition at line 1778 of file pbx.c.

References match_char::alt_char, and match_char::x.

Referenced by add_exten_to_pattern_tree().

01779 {
01780    struct match_char *t;
01781 
01782    if (!current) {
01783       return 0;
01784    }
01785 
01786    for (t = current; t; t = t->alt_char) {
01787       if (!strcmp(pat, t->x)) { /* uh, we may want to sort exploded [] contents to make matching easy */
01788          return t;
01789       }
01790    }
01791 
01792    return 0;
01793 }

int ast_active_calls ( void   ) 

Retrieve the number of active calls.

Definition at line 4613 of file pbx.c.

References countcalls.

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

04614 {
04615    return countcalls;
04616 }

int ast_add_extension ( const char *  context,
int  replace,
const char *  extension,
int  priority,
const char *  label,
const char *  callerid,
const char *  application,
void *  data,
void(*)(void *)  datad,
const char *  registrar 
)

Add and extension to an extension context.

Parameters:
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
Return values:
0 success
-1 failure

Definition at line 7317 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().

07320 {
07321    int ret = -1;
07322    struct ast_context *c = find_context_locked(context);
07323 
07324    if (c) {
07325       ret = ast_add_extension2(c, replace, extension, priority, label, callerid,
07326          application, data, datad, registrar);
07327       ast_unlock_contexts();
07328    }
07329 
07330    return ret;
07331 }

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 
)

Main interface to add extensions to the list for out context.

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

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

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

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

Definition at line 7636 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().

07640 {
07641    return ast_add_extension2_lockopt(con, replace, extension, priority, label, callerid, application, data, datad, registrar, 1, 1);
07642 }

static int ast_add_extension2_lockopt ( struct ast_context *  con,
int  replace,
const char *  extension,
int  priority,
const char *  label,
const char *  callerid,
const char *  application,
void *  data,
void(*)(void *)  datad,
const char *  registrar,
int  lockconts,
int  lockhints 
) [static]

Does all the work of ast_add_extension2, but adds two args, to determine if context and hint locking should be done. In merge_and_delete, we need to do this without locking, as the locks are already held.

Definition at line 7649 of file pbx.c.

References add_exten_to_pattern_tree(), add_pri(), ast_exten::app, ast_add_hint(), ast_add_hint_nolock(), ast_calloc, ast_copy_string(), ast_debug, ast_hashtab_create(), ast_hashtab_insert_safe(), ast_hashtab_lookup(), ast_hashtab_newsize_java(), ast_hashtab_resize_java(), ast_log(), ast_strlen_zero(), ast_unlock_context(), ast_verb, ast_wrlock_context(), ast_exten::cidmatch, ast_channel::context, ast_exten::data, ast_exten::datad, el, errno, ext_cmp(), ext_strncpy(), ast_exten::exten, ast_channel::exten, hashtab_compare_exten_labels(), hashtab_compare_exten_numbers(), hashtab_compare_extens(), hashtab_hash_extens(), hashtab_hash_labels(), hashtab_hash_priority(), ast_exten::label, LOG_ERROR, ast_exten::matchcid, ast_context::name, ast_exten::next, option_debug, ast_exten::parent, ast_context::pattern_tree, pbx_substitute_variables_helper(), ast_exten::peer_label_table, ast_exten::peer_table, ast_exten::priority, PRIORITY_HINT, ast_exten::registrar, ast_context::root, ast_context::root_table, ast_exten::stuff, and VAR_BUF_SIZE.

Referenced by ast_add_extension2(), and ast_add_extension_nolock().

07653 {
07654    /*
07655     * Sort extensions (or patterns) according to the rules indicated above.
07656     * These are implemented by the function ext_cmp()).
07657     * All priorities for the same ext/pattern/cid are kept in a list,
07658     * using the 'peer' field  as a link field..
07659     */
07660    struct ast_exten *tmp, *tmp2, *e, *el = NULL;
07661    int res;
07662    int length;
07663    char *p;
07664    char expand_buf[VAR_BUF_SIZE];
07665    struct ast_exten dummy_exten = {0};
07666    char dummy_name[1024];
07667 
07668    if (ast_strlen_zero(extension)) {
07669       ast_log(LOG_ERROR,"You have to be kidding-- add exten '' to context %s? Figure out a name and call me back. Action ignored.\n",
07670             con->name);
07671       return -1;
07672    }
07673 
07674    /* If we are adding a hint evalulate in variables and global variables */
07675    if (priority == PRIORITY_HINT && strstr(application, "${") && !strstr(extension, "_")) {
07676       struct ast_channel c = {0, };
07677 
07678       ast_copy_string(c.exten, extension, sizeof(c.exten));
07679       ast_copy_string(c.context, con->name, sizeof(c.context));
07680       pbx_substitute_variables_helper(&c, application, expand_buf, sizeof(expand_buf));
07681       application = expand_buf;
07682    }
07683 
07684    length = sizeof(struct ast_exten);
07685    length += strlen(extension) + 1;
07686    length += strlen(application) + 1;
07687    if (label)
07688       length += strlen(label) + 1;
07689    if (callerid)
07690       length += strlen(callerid) + 1;
07691    else
07692       length ++;  /* just the '\0' */
07693 
07694    /* Be optimistic:  Build the extension structure first */
07695    if (!(tmp = ast_calloc(1, length)))
07696       return -1;
07697 
07698    if (ast_strlen_zero(label)) /* let's turn empty labels to a null ptr */
07699       label = 0;
07700 
07701    /* use p as dst in assignments, as the fields are const char * */
07702    p = tmp->stuff;
07703    if (label) {
07704       tmp->label = p;
07705       strcpy(p, label);
07706       p += strlen(label) + 1;
07707    }
07708    tmp->exten = p;
07709    p += ext_strncpy(p, extension, strlen(extension) + 1) + 1;
07710    tmp->priority = priority;
07711    tmp->cidmatch = p;   /* but use p for assignments below */
07712 
07713    /* Blank callerid and NULL callerid are two SEPARATE things.  Do NOT confuse the two!!! */
07714    if (callerid) {
07715       p += ext_strncpy(p, callerid, strlen(callerid) + 1) + 1;
07716       tmp->matchcid = 1;
07717    } else {
07718       *p++ = '\0';
07719       tmp->matchcid = 0;
07720    }
07721    tmp->app = p;
07722    strcpy(p, application);
07723    tmp->parent = con;
07724    tmp->data = data;
07725    tmp->datad = datad;
07726    tmp->registrar = registrar;
07727 
07728    if (lockconts) {
07729       ast_wrlock_context(con);
07730    }
07731 
07732    if (con->pattern_tree) { /* usually, on initial load, the pattern_tree isn't formed until the first find_exten; so if we are adding
07733                         an extension, and the trie exists, then we need to incrementally add this pattern to it. */
07734       ast_copy_string(dummy_name, extension, sizeof(dummy_name));
07735       dummy_exten.exten = dummy_name;
07736       dummy_exten.matchcid = 0;
07737       dummy_exten.cidmatch = 0;
07738       tmp2 = ast_hashtab_lookup(con->root_table, &dummy_exten);
07739       if (!tmp2) {
07740          /* hmmm, not in the trie; */
07741          add_exten_to_pattern_tree(con, tmp, 0);
07742          ast_hashtab_insert_safe(con->root_table, tmp); /* for the sake of completeness */
07743       }
07744    }
07745    res = 0; /* some compilers will think it is uninitialized otherwise */
07746    for (e = con->root; e; el = e, e = e->next) {   /* scan the extension list */
07747       res = ext_cmp(e->exten, tmp->exten);
07748       if (res == 0) { /* extension match, now look at cidmatch */
07749          if (!e->matchcid && !tmp->matchcid)
07750             res = 0;
07751          else if (tmp->matchcid && !e->matchcid)
07752             res = 1;
07753          else if (e->matchcid && !tmp->matchcid)
07754             res = -1;
07755          else
07756             res = ext_cmp(e->cidmatch, tmp->cidmatch);
07757       }
07758       if (res >= 0)
07759          break;
07760    }
07761    if (e && res == 0) { /* exact match, insert in the pri chain */
07762       res = add_pri(con, tmp, el, e, replace);
07763       if (lockconts) {
07764          ast_unlock_context(con);
07765       }
07766       if (res < 0) {
07767          errno = EEXIST;   /* XXX do we care ? */
07768          return 0; /* XXX should we return -1 maybe ? */
07769       }
07770    } else {
07771       /*
07772        * not an exact match, this is the first entry with this pattern,
07773        * so insert in the main list right before 'e' (if any)
07774        */
07775       tmp->next = e;
07776       if (el) {  /* there is another exten already in this context */
07777          el->next = tmp;
07778          tmp->peer_table = ast_hashtab_create(13,
07779                      hashtab_compare_exten_numbers,
07780                      ast_hashtab_resize_java,
07781                      ast_hashtab_newsize_java,
07782                      hashtab_hash_priority,
07783                      0);
07784          tmp->peer_label_table = ast_hashtab_create(7,
07785                         hashtab_compare_exten_labels,
07786                         ast_hashtab_resize_java,
07787                         ast_hashtab_newsize_java,
07788                         hashtab_hash_labels,
07789                         0);
07790          if (label) {
07791             ast_hashtab_insert_safe(tmp->peer_label_table, tmp);
07792          }
07793          ast_hashtab_insert_safe(tmp->peer_table, tmp);
07794       } else {  /* this is the first exten in this context */
07795          if (!con->root_table)
07796             con->root_table = ast_hashtab_create(27,
07797                                        hashtab_compare_extens,
07798                                        ast_hashtab_resize_java,
07799                                        ast_hashtab_newsize_java,
07800                                        hashtab_hash_extens,
07801                                        0);
07802          con->root = tmp;
07803          con->root->peer_table = ast_hashtab_create(13,
07804                         hashtab_compare_exten_numbers,
07805                         ast_hashtab_resize_java,
07806                         ast_hashtab_newsize_java,
07807                         hashtab_hash_priority,
07808                         0);
07809          con->root->peer_label_table = ast_hashtab_create(7,
07810                            hashtab_compare_exten_labels,
07811                            ast_hashtab_resize_java,
07812                            ast_hashtab_newsize_java,
07813                            hashtab_hash_labels,
07814                            0);
07815          if (label) {
07816             ast_hashtab_insert_safe(con->root->peer_label_table, tmp);
07817          }
07818          ast_hashtab_insert_safe(con->root->peer_table, tmp);
07819 
07820       }
07821       ast_hashtab_insert_safe(con->root_table, tmp);
07822       if (lockconts) {
07823          ast_unlock_context(con);
07824       }
07825       if (tmp->priority == PRIORITY_HINT) {
07826          if (lockhints) {
07827             ast_add_hint(tmp);
07828          } else {
07829             ast_add_hint_nolock(tmp);
07830          }
07831       }
07832    }
07833    if (option_debug) {
07834       if (tmp->matchcid) {
07835          ast_debug(1, "Added extension '%s' priority %d (CID match '%s') to %s (%p)\n",
07836                  tmp->exten, tmp->priority, tmp->cidmatch, con->name, con);
07837       } else {
07838          ast_debug(1, "Added extension '%s' priority %d to %s (%p)\n",
07839                  tmp->exten, tmp->priority, con->name, con);
07840       }
07841    }
07842 
07843    if (tmp->matchcid) {
07844       ast_verb(3, "Added extension '%s' priority %d (CID match '%s') to %s (%p)\n",
07845              tmp->exten, tmp->priority, tmp->cidmatch, con->name, con);
07846    } else {
07847       ast_verb(3, "Added extension '%s' priority %d to %s (%p)\n",
07848              tmp->exten, tmp->priority, con->name, con);
07849    }
07850 
07851    return 0;
07852 }

static int ast_add_extension_nolock ( const char *  context,
int  replace,
const char *  extension,
int  priority,
const char *  label,
const char *  callerid,
const char *  application,
void *  data,
void(*)(void *)  datad,
const char *  registrar 
) [static]

Definition at line 7298 of file pbx.c.

References ast_add_extension2_lockopt(), and find_context().

Referenced by ast_merge_contexts_and_delete().

07301 {
07302    int ret = -1;
07303    struct ast_context *c = find_context(context);
07304 
07305    if (c) {
07306       ret = ast_add_extension2_lockopt(c, replace, extension, priority, label, callerid,
07307          application, data, datad, registrar, 0, 0);
07308    }
07309 
07310    return ret;
07311 }

static int ast_add_hint ( struct ast_exten *  e  )  [static]

Add hint to hint list, check initial extension state.

Definition at line 4072 of file pbx.c.

References ast_add_hint_nolock(), AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

Referenced by add_pri_lockopt(), and ast_add_extension2_lockopt().

04073 {
04074    int ret;
04075 
04076    AST_RWLIST_WRLOCK(&hints);
04077    ret = ast_add_hint_nolock(e);
04078    AST_RWLIST_UNLOCK(&hints);
04079 
04080    return ret;
04081 }

static int ast_add_hint_nolock ( struct ast_exten *  e  )  [static]

Add hint to hint list, check initial extension state; the hints had better be WRLOCKED already!

Definition at line 4043 of file pbx.c.

References ast_calloc, ast_debug, ast_extension_state2(), ast_get_extension_app(), ast_get_extension_name(), AST_RWLIST_INSERT_HEAD, AST_RWLIST_TRAVERSE, ast_hint::exten, and ast_hint::laststate.

Referenced by add_pri_lockopt(), ast_add_extension2_lockopt(), and ast_add_hint().

04044 {
04045    struct ast_hint *hint;
04046 
04047    if (!e)
04048       return -1;
04049 
04050    /* Search if hint exists, do nothing */
04051    AST_RWLIST_TRAVERSE(&hints, hint, list) {
04052       if (hint->exten == e) {
04053          ast_debug(2, "HINTS: Not re-adding existing hint %s: %s\n", ast_get_extension_name(e), ast_get_extension_app(e));
04054          return -1;
04055       }
04056    }
04057 
04058    ast_debug(2, "HINTS: Adding hint %s: %s\n", ast_get_extension_name(e), ast_get_extension_app(e));
04059 
04060    if (!(hint = ast_calloc(1, sizeof(*hint)))) {
04061       return -1;
04062    }
04063    /* Initialize and insert new item at the top */
04064    hint->exten = e;
04065    hint->laststate = ast_extension_state2(e);
04066    AST_RWLIST_INSERT_HEAD(&hints, hint, list);
04067 
04068    return 0;
04069 }

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

Set the channel to next execute the specified dialplan location.

See also:
ast_async_parseable_goto, ast_async_goto_if_exists

Definition at line 7356 of file pbx.c.

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

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

07357 {
07358    int res = 0;
07359 
07360    ast_channel_lock(chan);
07361 
07362    if (chan->pbx) { /* This channel is currently in the PBX */
07363       ast_explicit_goto(chan, context, exten, priority + 1);
07364       ast_softhangup_nolock(chan, AST_SOFTHANGUP_ASYNCGOTO);
07365    } else {
07366       /* In order to do it when the channel doesn't really exist within
07367          the PBX, we have to make a new channel, masquerade, and start the PBX
07368          at the new location */
07369       struct ast_channel *tmpchan = ast_channel_alloc(0, chan->_state, 0, 0, chan->accountcode, chan->exten, chan->context, chan->amaflags, "AsyncGoto/%s", chan->name);
07370       if (!tmpchan) {
07371          res = -1;
07372       } else {
07373          if (chan->cdr) {
07374             ast_cdr_discard(tmpchan->cdr);
07375             tmpchan->cdr = ast_cdr_dup(chan->cdr);  /* share the love */
07376          }
07377          /* Make formats okay */
07378          tmpchan->readformat = chan->readformat;
07379          tmpchan->writeformat = chan->writeformat;
07380          /* Setup proper location */
07381          ast_explicit_goto(tmpchan,
07382             S_OR(context, chan->context), S_OR(exten, chan->exten), priority);
07383 
07384          /* Masquerade into temp channel */
07385          if (ast_channel_masquerade(tmpchan, chan)) {
07386             /* Failed to set up the masquerade.  It's probably chan_local
07387              * in the middle of optimizing itself out.  Sad. :( */
07388             ast_hangup(tmpchan);
07389             tmpchan = NULL;
07390             res = -1;
07391          } else {
07392             /* Grab the locks and get going */
07393             ast_channel_lock(tmpchan);
07394             ast_do_masquerade(tmpchan);
07395             ast_channel_unlock(tmpchan);
07396             /* Start the PBX going on our stolen channel */
07397             if (ast_pbx_start(tmpchan)) {
07398                ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmpchan->name);
07399                ast_hangup(tmpchan);
07400                res = -1;
07401             }
07402          }
07403       }
07404    }
07405    ast_channel_unlock(chan);
07406    return res;
07407 }

int ast_async_goto_by_name ( const char *  channame,
const char *  context,
const char *  exten,
int  priority 
)

Set the channel to next execute the specified dialplan location.

Definition at line 7409 of file pbx.c.

References ast_async_goto(), ast_channel_unlock, and ast_get_channel_by_name_locked().

07410 {
07411    struct ast_channel *chan;
07412    int res = -1;
07413 
07414    chan = ast_get_channel_by_name_locked(channame);
07415    if (chan) {
07416       res = ast_async_goto(chan, context, exten, priority);
07417       ast_channel_unlock(chan);
07418    }
07419    return res;
07420 }

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

Note:
This function will handle locking the channel as needed.

Definition at line 9587 of file pbx.c.

References __ast_goto_if_exists().

09588 {
09589    return __ast_goto_if_exists(chan, context, exten, priority, 1);
09590 }

int ast_async_parseable_goto ( struct ast_channel *  chan,
const char *  goto_string 
)

Note:
This function will handle locking the channel as needed.

Definition at line 9650 of file pbx.c.

References pbx_parseable_goto().

Referenced by asyncgoto_exec(), and handle_redirect().

09651 {
09652    return pbx_parseable_goto(chan, goto_string, 1);
09653 }

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

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

Parameters:
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.
Return values:
Returns 1 on success or 0 on failure.

Definition at line 6951 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().

06952 {
06953    char *info_save, *info;
06954    int j, num_fields, last_sep = -1;
06955 
06956    /* Check for empty just in case */
06957    if (ast_strlen_zero(info_in)) {
06958       return 0;
06959    }
06960 
06961    /* make a copy just in case we were passed a static string */
06962    info_save = info = ast_strdupa(info_in);
06963 
06964    /* count the number of fields in the timespec */
06965    for (j = 0, num_fields = 1; info[j] != '\0'; j++) {
06966       if (info[j] == ',') {
06967          last_sep = j;
06968          num_fields++;
06969       }
06970    }
06971 
06972    /* save the timezone, if it is specified */
06973    if (num_fields == 5) {
06974       i->timezone = ast_strdup(info + last_sep + 1);
06975    } else {
06976       i->timezone = NULL;
06977    }
06978 
06979    /* Assume everything except time */
06980    i->monthmask = 0xfff;   /* 12 bits */
06981    i->daymask = 0x7fffffffU; /* 31 bits */
06982    i->dowmask = 0x7f; /* 7 bits */
06983    /* on each call, use strsep() to move info to the next argument */
06984    get_timerange(i, strsep(&info, "|,"));
06985    if (info)
06986       i->dowmask = get_range(strsep(&info, "|,"), 7, days, "day of week");
06987    if (info)
06988       i->daymask = get_range(strsep(&info, "|,"), 31, NULL, "day");
06989    if (info)
06990       i->monthmask = get_range(strsep(&info, "|,"), 12, months, "month");
06991    return 1;
06992 }

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

Looks for a valid matching extension.

Parameters:
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
Note:
It is possible for autoservice to be started and stopped on c during this function call, it is important that c is not locked prior to calling this. Otherwise a deadlock may occur
Returns:
If "exten" *could be* a valid extension in this context with or without some more digits, return non-zero. Basically, when this returns 0, no matter what you add to exten, it's not going to be a valid extension anymore

Definition at line 4170 of file pbx.c.

References E_CANMATCH, and pbx_extension_helper().

Referenced by background_detect_exec(), cb_events(), do_immediate_setup(), dp_lookup(), dundi_lookup_local(), get_also_info(), get_destination(), handle_link_data(), handle_link_phone_dtmf(), leave_voicemail(), local_dtmf_helper(), loopback_canmatch(), mgcp_ss(), pbx_builtin_background(), phone_check_exception(), pri_dchannel(), skinny_ss(), ss_thread(), and valid_exit().

04171 {
04172    return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_CANMATCH, 0, 0);
04173 }

static int ast_change_hint ( struct ast_exten *  oe,
struct ast_exten *  ne 
) [static]

Change hint for an extension.

Definition at line 4084 of file pbx.c.

References AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and ast_hint::exten.

Referenced by add_pri_lockopt().

04085 {
04086    struct ast_hint *hint;
04087    int res = -1;
04088 
04089    AST_RWLIST_WRLOCK(&hints);
04090    AST_RWLIST_TRAVERSE(&hints, hint, list) {
04091       if (hint->exten == oe) {
04092          hint->exten = ne;
04093          res = 0;
04094          break;
04095       }
04096    }
04097    AST_RWLIST_UNLOCK(&hints);
04098 
04099    return res;
04100 }

int ast_check_timing ( const struct ast_timing *  i  ) 

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

Parameters:
i Pointer to an ast_timing structure.
Return values:
Returns 1, if the time matches or 0, if the current time falls outside of the specified range.

Definition at line 6994 of file pbx.c.

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

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

06995 {
06996    struct ast_tm tm;
06997    struct timeval now = ast_tvnow();
06998 
06999    ast_localtime(&now, &tm, i->timezone);
07000 
07001    /* If it's not the right month, return */
07002    if (!(i->monthmask & (1 << tm.tm_mon)))
07003       return 0;
07004 
07005    /* If it's not that time of the month.... */
07006    /* Warning, tm_mday has range 1..31! */
07007    if (!(i->daymask & (1 << (tm.tm_mday-1))))
07008       return 0;
07009 
07010    /* If it's not the right day of the week */
07011    if (!(i->dowmask & (1 << tm.tm_wday)))
07012       return 0;
07013 
07014    /* Sanity check the hour just to be safe */
07015    if ((tm.tm_hour < 0) || (tm.tm_hour > 23)) {
07016       ast_log(LOG_WARNING, "Insane time...\n");
07017       return 0;
07018    }
07019 
07020    /* Now the tough part, we calculate if it fits
07021       in the right time based on min/hour */
07022    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))))
07023       return 0;
07024 
07025    /* If we got this far, then we're good */
07026    return 1;
07027 }

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

Add an ignorepat.

Parameters:
context which context to add the ignorpattern to
ignorepat ignorepattern to set up for the extension
registrar registrar of the ignore pattern
Adds an ignore pattern to a particular context.

Return values:
0 on success
-1 on failure

Definition at line 7229 of file pbx.c.

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

Referenced by handle_cli_dialplan_add_ignorepat().

07230 {
07231    int ret = -1;
07232    struct ast_context *c = find_context_locked(context);
07233 
07234    if (c) {
07235       ret = ast_context_add_ignorepat2(c, value, registrar);
07236       ast_unlock_contexts();
07237    }
07238    return ret;
07239 }

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

Definition at line 7241 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().

07242 {
07243    struct ast_ignorepat *ignorepat, *ignorepatc, *ignorepatl = NULL;
07244    int length;
07245    char *pattern;
07246    length = sizeof(struct ast_ignorepat);
07247    length += strlen(value) + 1;
07248    if (!(ignorepat = ast_calloc(1, length)))
07249       return -1;
07250    /* The cast to char * is because we need to write the initial value.
07251     * The field is not supposed to be modified otherwise.  Also, gcc 4.2
07252     * sees the cast as dereferencing a type-punned pointer and warns about
07253     * it.  This is the workaround (we're telling gcc, yes, that's really
07254     * what we wanted to do).
07255     */
07256    pattern = (char *) ignorepat->pattern;
07257    strcpy(pattern, value);
07258    ignorepat->next = NULL;
07259    ignorepat->registrar = registrar;
07260    ast_wrlock_context(con);
07261    for (ignorepatc = con->ignorepats; ignorepatc; ignorepatc = ignorepatc->next) {
07262       ignorepatl = ignorepatc;
07263       if (!strcasecmp(ignorepatc->pattern, value)) {
07264          /* Already there */
07265          ast_unlock_context(con);
07266          errno = EEXIST;
07267          return -1;
07268       }
07269    }
07270    if (ignorepatl)
07271       ignorepatl->next = ignorepat;
07272    else
07273       con->ignorepats = ignorepat;
07274    ast_unlock_context(con);
07275    return 0;
07276 
07277 }

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

Add a context include.

Parameters:
context context to add include to
include new include to add
registrar who's registering it
Adds an include taking a char * string as the context parameter

Return values:
0 on success
-1 on error

Definition at line 6780 of file pbx.c.

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

Referenced by handle_cli_dialplan_add_include().

06781 {
06782    int ret = -1;
06783    struct ast_context *c = find_context_locked(context);
06784 
06785    if (c) {
06786       ret = ast_context_add_include2(c, include, registrar);
06787       ast_unlock_contexts();
06788    }
06789    return ret;
06790 }

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

Add a context include.

Parameters:
con context to add the include to
include include to add
registrar who registered the context
Adds an include taking a struct ast_context as the first parameter

Return values:
0 on success
-1 on failure

Definition at line 7044 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().

07046 {
07047    struct ast_include *new_include;
07048    char *c;
07049    struct ast_include *i, *il = NULL; /* include, include_last */
07050    int length;
07051    char *p;
07052 
07053    length = sizeof(struct ast_include);
07054    length += 2 * (strlen(value) + 1);
07055 
07056    /* allocate new include structure ... */
07057    if (!(new_include = ast_calloc(1, length)))
07058       return -1;
07059    /* Fill in this structure. Use 'p' for assignments, as the fields
07060     * in the structure are 'const char *'
07061     */
07062    p = new_include->stuff;
07063    new_include->name = p;
07064    strcpy(p, value);
07065    p += strlen(value) + 1;
07066    new_include->rname = p;
07067    strcpy(p, value);
07068    /* Strip off timing info, and process if it is there */
07069    if ( (c = strchr(p, ',')) ) {
07070       *c++ = '\0';
07071       new_include->hastime = ast_build_timing(&(new_include->timing), c);
07072    }
07073    new_include->next      = NULL;
07074    new_include->registrar = registrar;
07075 
07076    ast_wrlock_context(con);
07077 
07078    /* ... go to last include and check if context is already included too... */
07079    for (i = con->includes; i; i = i->next) {
07080       if (!strcasecmp(i->name, new_include->name)) {
07081          ast_destroy_timing(&(new_include->timing));
07082          ast_free(new_include);
07083          ast_unlock_context(con);
07084          errno = EEXIST;
07085          return -1;
07086       }
07087       il = i;
07088    }
07089 
07090    /* ... include new context into context list, unlock, return */
07091    if (il)
07092       il->next = new_include;
07093    else
07094       con->includes = new_include;
07095    ast_verb(3, "Including context '%s' in context '%s'\n", new_include->name, ast_get_context_name(con));
07096 
07097    ast_unlock_context(con);
07098 
07099    return 0;
07100 }

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

Add a switch.

Parameters:
context context to which to add the switch
sw switch to add
data data to pass to switch
eval whether to evaluate variables when running switch
registrar whoever registered the switch
This function registers a switch with the asterisk switch architecture

Return values:
0 on success
-1 on failure

Definition at line 7107 of file pbx.c.

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

07108 {
07109    int ret = -1;
07110    struct ast_context *c = find_context_locked(context);
07111 
07112    if (c) { /* found, add switch to this context */
07113       ret = ast_context_add_switch2(c, sw, data, eval, registrar);
07114       ast_unlock_contexts();
07115    }
07116    return ret;
07117 }

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

Adds a switch (first param is a ast_context).

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

Definition at line 7126 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().

07128 {
07129    struct ast_sw *new_sw;
07130    struct ast_sw *i;
07131    int length;
07132    char *p;
07133 
07134    length = sizeof(struct ast_sw);
07135    length += strlen(value) + 1;
07136    if (data)
07137       length += strlen(data);
07138    length++;
07139 
07140    /* allocate new sw structure ... */
07141    if (!(new_sw = ast_calloc(1, length)))
07142       return -1;
07143    /* ... fill in this structure ... */
07144    p = new_sw->stuff;
07145    new_sw->name = p;
07146    strcpy(new_sw->name, value);
07147    p += strlen(value) + 1;
07148    new_sw->data = p;
07149    if (data) {
07150       strcpy(new_sw->data, data);
07151       p += strlen(data) + 1;
07152    } else {
07153       strcpy(new_sw->data, "");
07154       p++;
07155    }
07156    new_sw->eval     = eval;
07157    new_sw->registrar = registrar;
07158 
07159    /* ... try to lock this context ... */
07160    ast_wrlock_context(con);
07161 
07162    /* ... go to last sw and check if context is already swd too... */
07163    AST_LIST_TRAVERSE(&con->alts, i, list) {
07164       if (!strcasecmp(i->name, new_sw->name) && !strcasecmp(i->data, new_sw->data)) {
07165          ast_free(new_sw);
07166          ast_unlock_context(con);
07167          errno = EEXIST;
07168          return -1;
07169       }
07170    }
07171 
07172    /* ... sw new context into context list, unlock, return */
07173    AST_LIST_INSERT_TAIL(&con->alts, new_sw, list);
07174 
07175    ast_verb(3, "Including switch '%s/%s' in context '%s'\n", new_sw->name, new_sw->data, ast_get_context_name(con));
07176 
07177    ast_unlock_context(con);
07178 
07179    return 0;
07180 }

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

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

Parameters:
con context to destroy
registrar who registered it
You can optionally leave out either parameter. It will find it based on either the ast_context or the registrar name.

Returns:
nothing

Definition at line 8427 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().

struct ast_context* ast_context_find ( const char *  name  )  [read]

Find a context.

Parameters:
name name of the context to find
Will search for the context with the given name.

Returns:
the ast_context on success, NULL on failure.

Definition at line 2430 of file pbx.c.

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

Referenced by __unload_module(), _macro_exec(), ast_context_verify_includes(), ast_ignore_pattern(), cleanup_stale_contexts(), isexten_function_read(), load_config(), manage_parkinglot(), park_exec_full(), parkinglot_destroy(), register_exten(), register_peer_exten(), unload_module(), and unregister_exten().

02431 {
02432    struct ast_context *tmp = NULL;
02433    struct fake_context item;
02434 
02435    ast_copy_string(item.name, name, sizeof(item.name));
02436 
02437    ast_rdlock_contexts();
02438    if( contexts_table ) {
02439       tmp = ast_hashtab_lookup(contexts_table,&item);
02440    } else {
02441       while ( (tmp = ast_walk_contexts(tmp)) ) {
02442          if (!name || !strcasecmp(name, tmp->name)) {
02443             break;
02444          }
02445       }
02446    }
02447    ast_unlock_contexts();
02448    return tmp;
02449 }

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.

Parameters:
extcontexts pointer to the ast_context structure pointer
exttable pointer to the hashtable that contains all the elements in extcontexts
name name of the new context
registrar registrar of the context
This function allows you to play in two environments: the global contexts (active dialplan) or an external context set of your choosing. To act on the external set, make sure extcontexts and exttable are set; for the globals, make sure both extcontexts and exttable are NULL.

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

Returns:
NULL on failure, and an ast_context structure on success

Definition at line 6436 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().

06437 {
06438    struct ast_context *tmp, **local_contexts;
06439    struct fake_context search;
06440    int length = sizeof(struct ast_context) + strlen(name) + 1;
06441 
06442    if (!contexts_table) {
06443       contexts_table = ast_hashtab_create(17,
06444                                  ast_hashtab_compare_contexts,
06445                                  ast_hashtab_resize_java,
06446                                  ast_hashtab_newsize_java,
06447                                  ast_hashtab_hash_contexts,
06448                                  0);
06449    }
06450 
06451    ast_copy_string(search.name, name, sizeof(search.name));
06452    if (!extcontexts) {
06453       ast_rdlock_contexts();
06454       local_contexts = &contexts;
06455       tmp = ast_hashtab_lookup(contexts_table, &search);
06456       ast_unlock_contexts();
06457       if (tmp) {
06458          tmp->refcount++;
06459          return tmp;
06460       }
06461    } else { /* local contexts just in a linked list; search there for the new context; slow, linear search, but not frequent */
06462       local_contexts = extcontexts;
06463       tmp = ast_hashtab_lookup(exttable, &search);
06464       if (tmp) {
06465          tmp->refcount++;
06466          return tmp;
06467       }
06468    }
06469 
06470    if ((tmp = ast_calloc(1, length))) {
06471       ast_rwlock_init(&tmp->lock);
06472       ast_mutex_init(&tmp->macrolock);
06473       strcpy(tmp->name, name);
06474       tmp->root = NULL;
06475       tmp->root_table = NULL;
06476       tmp->registrar = ast_strdup(registrar);
06477       tmp->includes = NULL;
06478       tmp->ignorepats = NULL;
06479       tmp->refcount = 1;
06480    } else {
06481       ast_log(LOG_ERROR, "Danger! We failed to allocate a context for %s!\n", name);
06482       return NULL;
06483    }
06484 
06485    if (!extcontexts) {
06486       ast_wrlock_contexts();
06487       tmp->next = *local_contexts;
06488       *local_contexts = tmp;
06489       ast_hashtab_insert_safe(contexts_table, tmp); /*put this context into the tree */
06490       ast_unlock_contexts();
06491       ast_debug(1, "Registered context '%s'(%p) in table %p registrar: %s\n", tmp->name, tmp, contexts_table, registrar);
06492       ast_verb(3, "Registered extension context '%s' (%p) in table %p; registrar: %s\n", tmp->name, tmp, contexts_table, registrar);
06493    } else {
06494       tmp->next = *local_contexts;
06495       if (exttable)
06496          ast_hashtab_insert_immediate(exttable, tmp); /*put this context into the tree */
06497 
06498       *local_contexts = tmp;
06499       ast_debug(1, "Registered context '%s'(%p) in local table %p; registrar: %s\n", tmp->name, tmp, exttable, registrar);
06500       ast_verb(3, "Registered extension context '%s' (%p) in local table %p; registrar: %s\n", tmp->name, tmp, exttable, registrar);
06501    }
06502    return tmp;
06503 }

int ast_context_lockmacro ( const char *  context  ) 

locks the macrolock in the given given context

Note:
This function locks contexts list by &conlist, searches for the right context structure, and locks the macrolock mutex in that context. macrolock is used to limit a macro to be executed by one call at a time.

Definition at line 5000 of file pbx.c.

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

Referenced by _macro_exec().

05001 {
05002    struct ast_context *c = NULL;
05003    int ret = -1;
05004    struct fake_context item;
05005 
05006    ast_rdlock_contexts();
05007 
05008    ast_copy_string(item.name, context, sizeof(item.name));
05009 
05010    c = ast_hashtab_lookup(contexts_table,&item);
05011    if (c)
05012       ret = 0;
05013 
05014 
05015 #ifdef NOTNOW
05016 
05017    while ((c = ast_walk_contexts(c))) {
05018       if (!strcmp(ast_get_context_name(c), context)) {
05019          ret = 0;
05020          break;
05021       }
05022    }
05023 
05024 #endif
05025    ast_unlock_contexts();
05026 
05027    /* if we found context, lock macrolock */
05028    if (ret == 0) {
05029       ret = ast_mutex_lock(&c->macrolock);
05030    }
05031 
05032    return ret;
05033 }

int ast_context_remove_extension ( const char *  context,
const char *  extension,
int  priority,
const char *  registrar 
)

Simply remove extension from context.

Parameters:
context context to remove extension from
extension which extension to remove
priority priority of extension to remove (0 to remove all)
callerid NULL to remove all; non-NULL to match a single record per priority
matchcid non-zero to match callerid element (if non-NULL); 0 to match default case
registrar registrar of the extension
This function removes an extension from a given context.

Return values:
0 on success
-1 on failure

Definition at line 4808 of file pbx.c.

References ast_context_remove_extension_callerid().

Referenced by destroy_station(), destroy_trunk(), register_peer_exten(), unregister_exten(), and UnregisterExtension().

04809 {
04810    return ast_context_remove_extension_callerid(context, extension, priority, NULL, 0, registrar);
04811 }

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

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

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

Definition at line 4835 of file pbx.c.

References ast_context_remove_extension_callerid2().

Referenced by load_config(), manage_parkinglot(), park_exec_full(), and unload_module().

04836 {
04837    return ast_context_remove_extension_callerid2(con, extension, priority, NULL, 0, registrar, already_locked);
04838 }

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

Definition at line 4813 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().

04814 {
04815    int ret = -1; /* default error return */
04816    struct ast_context *c = find_context_locked(context);
04817 
04818    if (c) { /* ... remove extension ... */
04819       ret = ast_context_remove_extension_callerid2(c, extension, priority, callerid, matchcallerid, registrar, 1);
04820       ast_unlock_contexts();
04821    }
04822    return ret;
04823 }

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

Definition at line 4840 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_match_char_tree(), LOG_NOTICE, LOG_WARNING, ast_exten::matchcid, ast_context::name, ast_exten::next, ast_context::pattern_tree, ast_exten::peer, ast_exten::peer_label_table, ast_exten::peer_table, ast_exten::priority, ast_exten::registrar, ast_context::root, ast_context::root_table, and match_char::x.

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

04841 {
04842    struct ast_exten *exten, *prev_exten = NULL;
04843    struct ast_exten *peer;
04844    struct ast_exten ex, *exten2, *exten3;
04845    char dummy_name[1024];
04846    struct ast_exten *previous_peer = NULL;
04847    struct ast_exten *next_peer = NULL;
04848    int found = 0;
04849 
04850    if (!already_locked)
04851       ast_wrlock_context(con);
04852 
04853    /* Handle this is in the new world */
04854 
04855    /* FIXME For backwards compatibility, if callerid==NULL, then remove ALL
04856     * peers, not just those matching the callerid. */
04857 #ifdef NEED_DEBUG
04858    ast_verb(3,"Removing %s/%s/%d%s%s from trees, registrar=%s\n", con->name, extension, priority, matchcallerid ? "/" : "", matchcallerid ? callerid : "", registrar);
04859 #endif
04860 #ifdef CONTEXT_DEBUG
04861    check_contexts(__FILE__, __LINE__);
04862 #endif
04863    /* find this particular extension */
04864    ex.exten = dummy_name;
04865    ex.matchcid = matchcallerid && !ast_strlen_zero(callerid); /* don't say match if there's no callerid */
04866    ex.cidmatch = callerid;
04867    ast_copy_string(dummy_name, extension, sizeof(dummy_name));
04868    exten = ast_hashtab_lookup(con->root_table, &ex);
04869    if (exten) {
04870       if (priority == 0) {
04871          exten2 = ast_hashtab_remove_this_object(con->root_table, exten);
04872          if (!exten2)
04873             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);
04874          if (con->pattern_tree) {
04875             struct match_char *x = add_exten_to_pattern_tree(con, exten, 1);
04876 
04877             if (x->exten) { /* this test for safety purposes */
04878                x->deleted = 1; /* with this marked as deleted, it will never show up in the scoreboard, and therefore never be found */
04879                x->exten = 0; /* get rid of what will become a bad pointer */
04880             } else {
04881                ast_log(LOG_WARNING,"Trying to delete an exten from a context, but the pattern tree node returned isn't a full extension\n");
04882             }
04883          }
04884       } else {
04885          ex.priority = priority;
04886          exten2 = ast_hashtab_lookup(exten->peer_table, &ex);
04887          if (exten2) {
04888 
04889             if (exten2->label) { /* if this exten has a label, remove that, too */
04890                exten3 = ast_hashtab_remove_this_object(exten->peer_label_table,exten2);
04891                if (!exten3)
04892                   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);
04893             }
04894 
04895             exten3 = ast_hashtab_remove_this_object(exten->peer_table, exten2);
04896             if (!exten3)
04897                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);
04898             if (exten2 == exten && exten2->peer) {
04899                exten2 = ast_hashtab_remove_this_object(con->root_table, exten);
04900                ast_hashtab_insert_immediate(con->root_table, exten2->peer);
04901             }
04902             if (ast_hashtab_size(exten->peer_table) == 0) {
04903                /* well, if the last priority of an exten is to be removed,
04904                   then, the extension is removed, too! */
04905                exten3 = ast_hashtab_remove_this_object(con->root_table, exten);
04906                if (!exten3)
04907                   ast_log(LOG_ERROR,"Did not remove this exten (%s) from the context root_table (%s) (priority %d)\n", exten->exten, con->name, priority);
04908                if (con->pattern_tree) {
04909                   struct match_char *x = add_exten_to_pattern_tree(con, exten, 1);
04910                   if (x->exten) { /* this test for safety purposes */
04911                      x->deleted = 1; /* with this marked as deleted, it will never show up in the scoreboard, and therefore never be found */
04912                      x->exten = 0; /* get rid of what will become a bad pointer */
04913                   }
04914                }
04915             }
04916          } else {
04917             ast_log(LOG_ERROR,"Could not find priority %d of exten %s in context %s!\n",
04918                   priority, exten->exten, con->name);
04919          }
04920       }
04921    } else {
04922       /* hmmm? this exten is not in this pattern tree? */
04923       ast_log(LOG_WARNING,"Cannot find extension %s in root_table in context %s\n",
04924             extension, con->name);
04925    }
04926 #ifdef NEED_DEBUG
04927    if (con->pattern_tree) {
04928       ast_log(LOG_NOTICE,"match char tree after exten removal:\n");
04929       log_match_char_tree(con->pattern_tree, " ");
04930    }
04931 #endif
04932 
04933    /* scan the extension list to find first matching extension-registrar */
04934    for (exten = con->root; exten; prev_exten = exten, exten = exten->next) {
04935       if (!strcmp(exten->exten, extension) &&
04936          (!registrar || !strcmp(exten->registrar, registrar)) &&
04937          (!matchcallerid || (!ast_strlen_zero(callerid) && !ast_strlen_zero(exten->cidmatch) && !strcmp(exten->cidmatch, callerid)) || (ast_strlen_zero(callerid) && ast_strlen_zero(exten->cidmatch))))
04938          break;
04939    }
04940    if (!exten) {
04941       /* we can't find right extension */
04942       if (!already_locked)
04943          ast_unlock_context(con);
04944       return -1;
04945    }
04946 
04947    /* scan the priority list to remove extension with exten->priority == priority */
04948    for (peer = exten, next_peer = exten->peer ? exten->peer : exten->next;
04949        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)));
04950          peer = next_peer, next_peer = next_peer ? (next_peer->peer ? next_peer->peer : next_peer->next) : NULL) {
04951       if ((priority == 0 || peer->priority == priority) &&
04952             (!callerid || !matchcallerid || (matchcallerid && !strcmp(peer->cidmatch, callerid))) &&
04953             (!registrar || !strcmp(peer->registrar, registrar) )) {
04954          found = 1;
04955 
04956          /* we are first priority extension? */
04957          if (!previous_peer) {
04958             /*
04959              * We are first in the priority chain, so must update the extension chain.
04960              * The next node is either the next priority or the next extension
04961              */
04962             struct ast_exten *next_node = peer->peer ? peer->peer : peer->next;
04963             if (peer->peer) {
04964                /* move the peer_table and peer_label_table down to the next peer, if
04965                   it is there */
04966                peer->peer->peer_table = peer->peer_table;
04967                peer->peer->peer_label_table = peer->peer_label_table;
04968                peer->peer_table = NULL;
04969                peer->peer_label_table = NULL;
04970             }
04971             if (!prev_exten) {   /* change the root... */
04972                con->root = next_node;
04973             } else {
04974                prev_exten->next = next_node; /* unlink */
04975             }
04976             if (peer->peer)   { /* update the new head of the pri list */
04977                peer->peer->next = peer->next;
04978             }
04979          } else { /* easy, we are not first priority in extension */
04980             previous_peer->peer = peer->peer;
04981          }
04982 
04983          /* now, free whole priority extension */
04984          destroy_exten(peer);
04985       } else {
04986          previous_peer = peer;
04987       }
04988    }
04989    if (!already_locked)
04990       ast_unlock_context(con);
04991    return found ? 0 : -1;
04992 }

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

Definition at line 7186 of file pbx.c.

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

Referenced by handle_cli_dialplan_remove_ignorepat().

07187 {
07188    int ret = -1;
07189    struct ast_context *c = find_context_locked(context);
07190 
07191    if (c) {
07192       ret = ast_context_remove_ignorepat2(c, ignorepat, registrar);
07193       ast_unlock_contexts();
07194    }
07195    return ret;
07196 }

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

Definition at line 7198 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().

07199 {
07200    struct ast_ignorepat *ip, *ipl = NULL;
07201 
07202    ast_wrlock_context(con);
07203 
07204    for (ip = con->ignorepats; ip; ip = ip->next) {
07205       if (!strcmp(ip->pattern, ignorepat) &&
07206          (!registrar || (registrar == ip->registrar))) {
07207          if (ipl) {
07208             ipl->next = ip->next;
07209             ast_free(ip);
07210          } else {
07211             con->ignorepats = ip->next;
07212             ast_free(ip);
07213          }
07214          ast_unlock_context(con);
07215          return 0;
07216       }
07217       ipl = ip;
07218    }
07219 
07220    ast_unlock_context(con);
07221    errno = EINVAL;
07222    return -1;
07223 }

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

Remove included contexts. This function locks contexts list by &conlist, search for the right context structure, leave context list locked and call ast_context_remove_include2 which removes include, unlock contexts list and return ...

Remove a context include.

Definition at line 4699 of file pbx.c.

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

Referenced by handle_cli_dialplan_remove_include().

04700 {
04701    int ret = -1;
04702    struct ast_context *c = find_context_locked(context);
04703 
04704    if (c) {
04705       /* found, remove include from this context ... */
04706       ret = ast_context_remove_include2(c, include, registrar);
04707       ast_unlock_contexts();
04708    }
04709    return ret;
04710 }

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

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

Removes an include by an ast_context structure.

Return values:
0 on success.
-1 on failure.

Definition at line 4721 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().

04722 {
04723    struct ast_include *i, *pi = NULL;
04724    int ret = -1;
04725 
04726    ast_wrlock_context(con);
04727 
04728    /* find our include */
04729    for (i = con->includes; i; pi = i, i = i->next) {
04730       if (!strcmp(i->name, include) &&
04731             (!registrar || !strcmp(i->registrar, registrar))) {
04732          /* remove from list */
04733          ast_verb(3, "Removing inclusion of context '%s' in context '%s; registrar=%s'\n", include, ast_get_context_name(con), registrar);
04734          if (pi)
04735             pi->next = i->next;
04736          else
04737             con->includes = i->next;
04738          /* free include and return */
04739          ast_destroy_timing(&(i->timing));
04740          ast_free(i);
04741          ret = 0;
04742          break;
04743       }
04744    }
04745 
04746    ast_unlock_context(con);
04747 
04748    return ret;
04749 }

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

Remove a switch.

Note:
This function locks contexts list by &conlist, search for the rigt context structure, leave context list locked and call ast_context_remove_switch2 which removes switch, unlock contexts list and return ...

Definition at line 4756 of file pbx.c.

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

04757 {
04758    int ret = -1; /* default error return */
04759    struct ast_context *c = find_context_locked(context);
04760 
04761    if (c) {
04762       /* remove switch from this context ... */
04763       ret = ast_context_remove_switch2(c, sw, data, registrar);
04764       ast_unlock_contexts();
04765    }
04766    return ret;
04767 }

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

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

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

Definition at line 4777 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().

04778 {
04779    struct ast_sw *i;
04780    int ret = -1;
04781 
04782    ast_wrlock_context(con);
04783 
04784    /* walk switches */
04785    AST_LIST_TRAVERSE_SAFE_BEGIN(&con->alts, i, list) {
04786       if (!strcmp(i->name, sw) && !strcmp(i->data, data) &&
04787          (!registrar || !strcmp(i->registrar, registrar))) {
04788          /* found, remove from list */
04789          ast_verb(3, "Removing switch '%s' from context '%s; registrar=%s'\n", sw, ast_get_context_name(con), registrar);
04790          AST_LIST_REMOVE_CURRENT(list);
04791          ast_free(i); /* free switch and return */
04792          ret = 0;
04793          break;
04794       }
04795    }
04796    AST_LIST_TRAVERSE_SAFE_END;
04797 
04798    ast_unlock_context(con);
04799 
04800    return ret;
04801 }

int ast_context_unlockmacro ( const char *  context  ) 

Unlocks the macrolock in the given context.

Note:
This function locks contexts list by &conlist, searches for the right context structure, and unlocks the macrolock mutex in that context. macrolock is used to limit a macro to be executed by one call at a time.

Definition at line 5040 of file pbx.c.

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

Referenced by _macro_exec().

05041 {
05042    struct ast_context *c = NULL;
05043    int ret = -1;
05044    struct fake_context item;
05045 
05046    ast_rdlock_contexts();
05047 
05048    ast_copy_string(item.name, context, sizeof(item.name));
05049 
05050    c = ast_hashtab_lookup(contexts_table,&item);
05051    if (c)
05052       ret = 0;
05053 #ifdef NOTNOW
05054 
05055    while ((c = ast_walk_contexts(c))) {
05056       if (!strcmp(ast_get_context_name(c), context)) {
05057          ret = 0;
05058          break;
05059       }
05060    }
05061 
05062 #endif
05063    ast_unlock_contexts();
05064 
05065    /* if we found context, unlock macrolock */
05066    if (ret == 0) {
05067       ret = ast_mutex_unlock(&c->macrolock);
05068    }
05069 
05070    return ret;
05071 }

int ast_context_verify_includes ( struct ast_context *  con  ) 

Verifies includes in an ast_contect structure.

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

Definition at line 9544 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().

09545 {
09546    struct ast_include *inc = NULL;
09547    int res = 0;
09548 
09549    while ( (inc = ast_walk_context_includes(con, inc)) ) {
09550       if (ast_context_find(inc->rname))
09551          continue;
09552 
09553       res = -1;
09554       ast_log(LOG_WARNING, "Context '%s' tries to include nonexistent context '%s'\n",
09555          ast_get_context_name(con), inc->rname);
09556       break;
09557    }
09558 
09559    return res;
09560 }

struct ast_custom_function* ast_custom_function_find ( const char *  name  )  [read]

int ast_custom_function_unregister ( struct ast_custom_function *  acf  ) 

Unregister a custom function.

Definition at line 3216 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().

03217 {
03218    struct ast_custom_function *cur;
03219 
03220    if (!acf) {
03221       return -1;
03222    }
03223 
03224    AST_RWLIST_WRLOCK(&acf_root);
03225    if ((cur = AST_RWLIST_REMOVE(&acf_root, acf, acflist))) {
03226       if (cur->docsrc == AST_XML_DOC) {
03227          ast_string_field_free_memory(acf);
03228       }
03229       ast_verb(2, "Unregistered custom function %s\n", cur->name);
03230    }
03231    AST_RWLIST_UNLOCK(&acf_root);
03232 
03233    return cur ? 0 : -1;
03234 }

int ast_destroy_timing ( struct ast_timing *  i  ) 

Deallocates memory structures associated with a timing bitmap.

Parameters:
i Pointer to an ast_timing structure.
Return values:
0 success
non-zero failure (number suitable to pass to
See also:
strerror)

Definition at line 7029 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().

07030 {
07031    if (i->timezone) {
07032       ast_free(i->timezone);
07033       i->timezone = NULL;
07034    }
07035    return 0;
07036 }

enum ast_extension_states ast_devstate_to_extenstate ( enum ast_device_state  devstate  ) 

Map devstate to an extension state.

Parameters:
[in] device state
Returns:
the extension state mapping.

Definition at line 3770 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().

03771 {
03772    switch (devstate) {
03773    case AST_DEVICE_ONHOLD:
03774       return AST_EXTENSION_ONHOLD;
03775    case AST_DEVICE_BUSY:
03776       return AST_EXTENSION_BUSY;
03777    case AST_DEVICE_UNKNOWN:
03778       return AST_EXTENSION_NOT_INUSE;
03779    case AST_DEVICE_UNAVAILABLE:
03780    case AST_DEVICE_INVALID:
03781       return AST_EXTENSION_UNAVAILABLE;
03782    case AST_DEVICE_RINGINUSE:
03783       return (AST_EXTENSION_INUSE | AST_EXTENSION_RINGING);
03784    case AST_DEVICE_RINGING:
03785       return AST_EXTENSION_RINGING;
03786    case AST_DEVICE_INUSE:
03787       return AST_EXTENSION_INUSE;
03788    case AST_DEVICE_NOT_INUSE:
03789       return AST_EXTENSION_NOT_INUSE;
03790    case AST_DEVICE_TOTAL: /* not a device state, included for completeness */
03791       break;
03792    }
03793 
03794    return AST_EXTENSION_NOT_INUSE;
03795 }

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

Determine whether an extension exists.

Parameters:
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
Note:
It is possible for autoservice to be started and stopped on c during this function call, it is important that c is not locked prior to calling this. Otherwise a deadlock may occur
Returns:
If an extension within the given context(or callerid) with the given priority is found a non zero value will be returned. Otherwise, 0 is returned.

Definition at line 4155 of file pbx.c.

References E_MATCH, and pbx_extension_helper().

Referenced by __ast_goto_if_exists(), __ast_pbx_run(), _macro_exec(), acf_isexten_exec(), answer_call(), ast_app_dtget(), ast_bridge_call(), ast_pbx_outgoing_exten(), 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(), park_space_reserve(), parkandannounce_exec(), pbx_builtin_waitexten(), phone_check_exception(), pri_dchannel(), privacy_exec(), process_ast_dsp(), process_sdp(), readexten_exec(), register_peer_exten(), rpt_exec(), show_debug_helper(), sip_read(), skinny_ss(), socket_process(), ss7_linkset(), ss_thread(), and waitstream_core().

04156 {
04157    return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCH, 0, 0);
04158 }

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

Note:
This function will handle locking the channel as needed.

Definition at line 7333 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().

07334 {
07335    if (!chan)
07336       return -1;
07337 
07338    ast_channel_lock(chan);
07339 
07340    if (!ast_strlen_zero(context))
07341       ast_copy_string(chan->context, context, sizeof(chan->context));
07342    if (!ast_strlen_zero(exten))
07343       ast_copy_string(chan->exten, exten, sizeof(chan->exten));
07344    if (priority > -1) {
07345       chan->priority = priority;
07346       /* see flag description in channel.h for explanation */
07347       if (ast_test_flag(chan, AST_FLAG_IN_AUTOLOOP))
07348          chan->priority--;
07349    }
07350 
07351    ast_channel_unlock(chan);
07352 
07353    return 0;
07354 }

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

Definition at line 2407 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().

02408 {
02409    if (needmore != E_MATCHMORE && needmore != E_CANMATCH)
02410       ast_log(LOG_WARNING, "invalid argument %d\n", needmore);
02411    return extension_match_core(pattern, data, needmore);
02412 }

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

Determine if one extension should match before another.

Parameters:
a extension to compare with b
b extension to compare with a
Checks whether or extension a should match before extension b

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

Definition at line 2209 of file pbx.c.

References ext_cmp().

Referenced by lua_extension_cmp().

02210 {
02211    return ext_cmp(a, b);
02212 }

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

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

Parameters:
pattern pattern to match
extension extension to check against the pattern.
Checks whether or not the given extension matches the given pattern.

Return values:
1 on match
0 on failure

Definition at line 2402 of file pbx.c.

References E_MATCH, and extension_match_core().

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

02403 {
02404    return extension_match_core(pattern, data, E_MATCH);
02405 }

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

Check extension state for an extension by using hint.

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

Definition at line 3833 of file pbx.c.

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

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

03834 {
03835    struct ast_exten *e;
03836 
03837    if (!(e = ast_hint_extension(c, context, exten))) {  /* Do we have a hint for this extension ? */
03838       return -1;                   /* No hint, return -1 */
03839    }
03840 
03841    if (e->exten[0] == '_') {
03842       /* Create this hint on-the-fly */
03843       ast_add_extension(e->parent->name, 0, exten, e->priority, e->label,
03844          e->matchcid ? e->cidmatch : NULL, e->app, ast_strdup(e->data), ast_free_ptr,
03845          e->registrar);
03846       if (!(e = ast_hint_extension(c, context, exten))) {
03847          /* Improbable, but not impossible */
03848          return -1;
03849       }
03850    }
03851 
03852    return ast_extension_state2(e);  /* Check all devices in the hint */
03853 }

static int ast_extension_state2 ( struct ast_exten *  e  )  [static]

Check state of extension by using hints.

Definition at line 3798 of file pbx.c.

References ast_devstate_aggregate_add(), ast_devstate_aggregate_init(), ast_devstate_aggregate_result(), ast_devstate_to_extenstate(), ast_get_extension_app(), ast_str_buffer(), ast_str_set(), ast_str_thread_get(), extensionstate_buf, and strsep().

Referenced by ast_add_hint_nolock(), ast_extension_state(), and handle_statechange().

03799 {
03800    struct ast_str *hint = ast_str_thread_get(&extensionstate_buf, 16);
03801    char *cur, *rest;
03802    struct ast_devstate_aggregate agg;
03803 
03804    if (!e)
03805       return -1;
03806 
03807    ast_devstate_aggregate_init(&agg);
03808 
03809    ast_str_set(&hint, 0, "%s", ast_get_extension_app(e));
03810 
03811    rest = ast_str_buffer(hint);  /* One or more devices separated with a & character */
03812 
03813    while ( (cur = strsep(&rest, "&")) ) {
03814       ast_devstate_aggregate_add(&agg, ast_device_state(cur));
03815    }
03816 
03817    return ast_devstate_to_extenstate(ast_devstate_aggregate_result(&agg));
03818 }

const char* ast_extension_state2str ( int  extension_state  ) 

Return extension_state as string.

Return string representation of the state of an extension.

Definition at line 3821 of file pbx.c.

References ARRAY_LEN, extension_states, and cfextension_states::text.

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

03822 {
03823    int i;
03824 
03825    for (i = 0; (i < ARRAY_LEN(extension_states)); i++) {
03826       if (extension_states[i].extension_state == extension_state)
03827          return extension_states[i].text;
03828    }
03829    return "Unknown";
03830 }

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

Add watcher for extension states.

Registers a state change callback.

Definition at line 3908 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(), and skinny_register().

03910 {
03911    struct ast_hint *hint;
03912    struct ast_state_cb *cblist;
03913    struct ast_exten *e;
03914 
03915    /* If there's no context and extension:  add callback to statecbs list */
03916    if (!context && !exten) {
03917       AST_RWLIST_WRLOCK(&hints);
03918 
03919       AST_LIST_TRAVERSE(&statecbs, cblist, entry) {
03920          if (cblist->callback == callback) {
03921             cblist->data = data;
03922             AST_RWLIST_UNLOCK(&hints);
03923             return 0;
03924          }
03925       }
03926 
03927       /* Now insert the callback */
03928       if (!(cblist = ast_calloc(1, sizeof(*cblist)))) {
03929          AST_RWLIST_UNLOCK(&hints);
03930          return -1;
03931       }
03932       cblist->id = 0;
03933       cblist->callback = callback;
03934       cblist->data = data;
03935 
03936       AST_LIST_INSERT_HEAD(&statecbs, cblist, entry);
03937 
03938       AST_RWLIST_UNLOCK(&hints);
03939 
03940       return 0;
03941    }
03942 
03943    if (!context || !exten)
03944       return -1;
03945 
03946    /* This callback type is for only one hint, so get the hint */
03947    e = ast_hint_extension(NULL, context, exten);
03948    if (!e) {
03949       return -1;
03950    }
03951 
03952    /* If this is a pattern, dynamically create a new extension for this
03953     * particular match.  Note that this will only happen once for each
03954     * individual extension, because the pattern will no longer match first.
03955     */
03956    if (e->exten[0] == '_') {
03957       ast_add_extension(e->parent->name, 0, exten, e->priority, e->label,
03958          e->matchcid ? e->cidmatch : NULL, e->app, ast_strdup(e->data), ast_free_ptr,
03959          e->registrar);
03960       e = ast_hint_extension(NULL, context, exten);
03961       if (!e || e->exten[0] == '_') {
03962          return -1;
03963       }
03964    }
03965 
03966    /* Find the hint in the list of hints */
03967    AST_RWLIST_WRLOCK(&hints);
03968 
03969    AST_RWLIST_TRAVERSE(&hints, hint, list) {
03970       if (hint->exten == e)
03971          break;
03972    }
03973 
03974    if (!hint) {
03975       /* We have no hint, sorry */
03976       AST_RWLIST_UNLOCK(&hints);
03977       return -1;
03978    }
03979 
03980    /* Now insert the callback in the callback list  */
03981    if (!(cblist = ast_calloc(1, sizeof(*cblist)))) {
03982       AST_RWLIST_UNLOCK(&hints);
03983       return -1;
03984    }
03985 
03986    cblist->id = stateid++;    /* Unique ID for this callback */
03987    cblist->callback = callback;  /* Pointer to callback routine */
03988    cblist->data = data;    /* Data for the callback */
03989 
03990    AST_LIST_INSERT_HEAD(&hint->callbacks, cblist, entry);
03991 
03992    AST_RWLIST_UNLOCK(&hints);
03993 
03994    return cblist->id;
03995 }

int ast_extension_state_del ( int  id,
ast_state_cb_type  callback 
)

Remove a watcher from the callback list.

Deletes a registered state change callback by ID.

Definition at line 3998 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(), and skinny_unregister().

03999 {
04000    struct ast_state_cb *p_cur = NULL;
04001    int ret = -1;
04002 
04003    if (!id && !callback)
04004       return -1;
04005 
04006    AST_RWLIST_WRLOCK(&hints);
04007 
04008    if (!id) {  /* id == 0 is a callback without extension */
04009       AST_LIST_TRAVERSE_SAFE_BEGIN(&statecbs, p_cur, entry) {
04010          if (p_cur->callback == callback) {
04011             AST_LIST_REMOVE_CURRENT(entry);
04012             break;
04013          }
04014       }
04015       AST_LIST_TRAVERSE_SAFE_END;
04016    } else { /* callback with extension, find the callback based on ID */
04017       struct ast_hint *hint;
04018       AST_RWLIST_TRAVERSE(&hints, hint, list) {
04019          AST_LIST_TRAVERSE_SAFE_BEGIN(&hint->callbacks, p_cur, entry) {
04020             if (p_cur->id == id) {
04021                AST_LIST_REMOVE_CURRENT(entry);
04022                break;
04023             }
04024          }
04025          AST_LIST_TRAVERSE_SAFE_END;
04026 
04027          if (p_cur)
04028             break;
04029       }
04030    }
04031 
04032    if (p_cur) {
04033       ast_free(p_cur);
04034    }
04035 
04036    AST_RWLIST_UNLOCK(&hints);
04037 
04038    return ret;
04039 }

int ast_findlabel_extension ( struct ast_channel *  c,
const char *  context,
const char *  exten,
const char *  label,
const char *  callerid 
)

Find the priority of an extension that has the specified label.

Parameters:
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
Note:
It is possible for autoservice to be started and stopped on c during this function call, it is important that c is not locked prior to calling this. Otherwise a deadlock may occur
Return values:
the priority which matches the given label in the extension
-1 if not found.

Definition at line 4160 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().

04161 {
04162    return pbx_extension_helper(c, NULL, context, exten, 0, label, callerid, E_FINDLABEL, 0, 0);
04163 }

int ast_findlabel_extension2 ( struct ast_channel *  c,
struct ast_context *  con,
const char *  exten,
const char *  label,
const char *  callerid 
)

Find the priority of an extension that has the specified label.

Note:
It is possible for autoservice to be started and stopped on c during this function call, it is important that c is not locked prior to calling this. Otherwise a deadlock may occur

This function is the same as ast_findlabel_extension, except that it accepts a pointer to an ast_context structure to specify the context instead of the name of the context. Otherwise, the functions behave the same.

Definition at line 4165 of file pbx.c.

References E_FINDLABEL, and pbx_extension_helper().

Referenced by pbx_load_config().

04166 {
04167    return pbx_extension_helper(c, con, NULL, exten, 0, label, callerid, E_FINDLABEL, 0, 0);
04168 }

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

executes a read operation on a function

Parameters:
chan Channel to execute on
function Data containing the function call string (will be modified)
workspace A pointer to safe memory to use for a return value
len the number of bytes in workspace
This application executes a function in read mode on a given channel.

Return values:
0 success
non-zero failure

Definition at line 3356 of file pbx.c.

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

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

03357 {
03358    char *copy = ast_strdupa(function);
03359    char *args = func_args(copy);
03360    struct ast_custom_function *acfptr = ast_custom_function_find(copy);
03361 
03362    if (acfptr == NULL)
03363       ast_log(LOG_ERROR, "Function %s not registered\n", copy);
03364    else if (!acfptr->read)
03365       ast_log(LOG_ERROR, "Function %s cannot be read\n", copy);
03366    else {
03367       int res;
03368       struct ast_module_user *u = NULL;
03369       if (acfptr->mod)
03370          u = __ast_module_user_add(acfptr->mod, chan);
03371       res = acfptr->read(chan, copy, args, workspace, len);
03372       if (acfptr->mod && u)
03373          __ast_module_user_remove(acfptr->mod, u);
03374       return res;
03375    }
03376    return -1;
03377 }

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

executes a write operation on a function

Parameters:
chan Channel to execute on
function Data containing the function call string (will be modified)
value A value parameter to pass for writing
This application executes a function in write mode on a given channel.

Return values:
0 success
non-zero failure

Definition at line 3379 of file pbx.c.

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

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

03380 {
03381    char *copy = ast_strdupa(function);
03382    char *args = func_args(copy);
03383    struct ast_custom_function *acfptr = ast_custom_function_find(copy);
03384 
03385    if (acfptr == NULL)
03386       ast_log(LOG_ERROR, "Function %s not registered\n", copy);
03387    else if (!acfptr->write)
03388       ast_log(LOG_ERROR, "Function %s cannot be written to\n", copy);
03389    else {
03390       int res;
03391       struct ast_module_user *u = NULL;
03392       if (acfptr->mod)
03393          u = __ast_module_user_add(acfptr->mod, chan);
03394       res = acfptr->write(chan, copy, args, value);
03395       if (acfptr->mod && u)
03396          __ast_module_user_remove(acfptr->mod, u);
03397       return res;
03398    }
03399 
03400    return -1;
03401 }

const char* ast_get_context_name ( struct ast_context *  con  ) 

const char* ast_get_context_registrar ( struct ast_context *  c  ) 

Definition at line 9434 of file pbx.c.

References ast_context::registrar.

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

09435 {
09436    return c ? c->registrar : NULL;
09437 }

const char* ast_get_extension_app ( struct ast_exten *  e  ) 

void* ast_get_extension_app_data ( struct ast_exten *  e  ) 

Definition at line 9469 of file pbx.c.

References ast_exten::data.

Referenced by _macro_exec(), ast_get_hint(), handle_cli_dialplan_save(), manager_show_dialplan_helper(), and print_ext().

09470 {
09471    return e ? e->data : NULL;
09472 }

const char* ast_get_extension_cidmatch ( struct ast_exten *  e  ) 

Definition at line 9459 of file pbx.c.

References ast_exten::cidmatch.

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

09460 {
09461    return e ? e->cidmatch : NULL;
09462 }

struct ast_context* ast_get_extension_context ( struct ast_exten *  exten  )  [read]

Definition at line 9401 of file pbx.c.

References ast_exten::parent.

Referenced by handle_show_hint(), and handle_show_hints().

09402 {
09403    return exten ? exten->parent : NULL;
09404 }

const char* ast_get_extension_label ( struct ast_exten *  exten  ) 

Definition at line 9411 of file pbx.c.

References ast_exten::label.

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

09412 {
09413    return exten ? exten->label : NULL;
09414 }

int ast_get_extension_matchcid ( struct ast_exten *  e  ) 

Definition at line 9454 of file pbx.c.

References ast_exten::matchcid.

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

09455 {
09456    return e ? e->matchcid : 0;
09457 }

const char* ast_get_extension_name ( struct ast_exten *  exten  ) 

int ast_get_extension_priority ( struct ast_exten *  exten  ) 

Definition at line 9426 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().

09427 {
09428    return exten ? exten->priority : -1;
09429 }

const char* ast_get_extension_registrar ( struct ast_exten *  e  ) 

Definition at line 9439 of file pbx.c.

References ast_exten::registrar.

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

09440 {
09441    return e ? e->registrar : NULL;
09442 }

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

Get hint for channel.

If an extension hint exists, return non-zero.

Definition at line 4138 of file pbx.c.

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

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

04139 {
04140    struct ast_exten *e = ast_hint_extension(c, context, exten);
04141 
04142    if (e) {
04143       if (hint)
04144          ast_copy_string(hint, ast_get_extension_app(e), hintsize);
04145       if (name) {
04146          const char *tmp = ast_get_extension_app_data(e);
04147          if (tmp)
04148             ast_copy_string(name, tmp, namesize);
04149       }
04150       return -1;
04151    }
04152    return 0;
04153 }

const char* ast_get_ignorepat_name ( struct ast_ignorepat *  ip  ) 

const char* ast_get_ignorepat_registrar ( struct ast_ignorepat *  ip  ) 

Definition at line 9449 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().

09450 {
09451    return ip ? ip->registrar : NULL;
09452 }

const char* ast_get_include_name ( struct ast_include *  inc  ) 

const char* ast_get_include_registrar ( struct ast_include *  i  ) 

Definition at line 9444 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().

09445 {
09446    return i ? i->registrar : NULL;
09447 }

const char* ast_get_switch_data ( struct ast_sw *  sw  ) 

Definition at line 9479 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().

09480 {
09481    return sw ? sw->data : NULL;
09482 }

int ast_get_switch_eval ( struct ast_sw *  sw  ) 

Definition at line 9484 of file pbx.c.

References ast_sw::eval.

Referenced by context_merge_incls_swits_igps_other_registrars().

09485 {
09486    return sw->eval;
09487 }

const char* ast_get_switch_name ( struct ast_sw *  sw  ) 

Definition at line 9474 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().

09475 {
09476    return sw ? sw->name : NULL;
09477 }

const char* ast_get_switch_registrar ( struct ast_sw *  sw  ) 

Definition at line 9489 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().

09490 {
09491    return sw ? sw->registrar : NULL;
09492 }

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

Note:
This function will handle locking the channel as needed.

Definition at line 9582 of file pbx.c.

References __ast_goto_if_exists().

Referenced by background_detect_exec(), channel_spy(), common_exec(), conf_run(), goto_exten(), onedigit_goto(), priority_jump(), select_entry(), and valid_exit().

09583 {
09584    return __ast_goto_if_exists(chan, context, exten, priority, 0);
09585 }

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

unsigned int ast_hashtab_hash_contexts ( const void *  obj  ) 

static struct ast_exten* ast_hint_extension ( struct ast_channel *  c,
const char *  context,
const char *  exten 
) [static, read]

Definition at line 3761 of file pbx.c.

References ast_hint_extension_nolock(), ast_rdlock_contexts(), and ast_unlock_contexts().

Referenced by ast_extension_state(), ast_extension_state_add(), and ast_get_hint().

03762 {
03763    struct ast_exten *e;
03764    ast_rdlock_contexts();
03765    e = ast_hint_extension_nolock(c, context, exten);
03766    ast_unlock_contexts();
03767    return e;
03768 }

static struct ast_exten* ast_hint_extension_nolock ( struct ast_channel *  c,
const char *  context,
const char *  exten 
) [static, read]

Find hint for given extension in context.

Definition at line 3755 of file pbx.c.

References E_MATCH, pbx_find_extension(), PRIORITY_HINT, and pbx_find_info::stacklen.

Referenced by ast_hint_extension(), and ast_merge_contexts_and_delete().

03756 {
03757    struct pbx_find_info q = { .stacklen = 0 }; /* the rest is set in pbx_find_context */
03758    return pbx_find_extension(c, NULL, &q, context, exten, PRIORITY_HINT, NULL, "", E_MATCH);
03759 }

int ast_ignore_pattern ( const char *  context,
const char *  pattern 
)

Checks to see if a number should be ignored.

Parameters:
context context to search within
pattern to check whether it should be ignored or not
Check if a number should be ignored with respect to dialtone cancellation.

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

Definition at line 7279 of file pbx.c.

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

Referenced by ast_app_dtget(), disa_exec(), dp_lookup(), dundi_lookup_local(), handle_enbloc_call_message(), handle_soft_key_event_message(), handle_stimulus_message(), mgcp_ss(), skinny_ss(), and ss_thread().

07280 {
07281    struct ast_context *con = ast_context_find(context);
07282    if (con) {
07283       struct ast_ignorepat *pat;
07284       for (pat = con->ignorepats; pat; pat = pat->next) {
07285          if (ast_extension_match(pat->pattern, pattern))
07286             return 1;
07287       }
07288    }
07289 
07290    return 0;
07291 }

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

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

Parameters:
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
Note:
It is possible for autoservice to be started and stopped on c during this function call, it is important that c is not locked prior to calling this. Otherwise a deadlock may occur
Returns:
If "exten" *could match* a valid extension in this context with some more digits, return non-zero. Does NOT return non-zero if this is an exact-match only. Basically, when this returns 0, no matter what you add to exten, it's not going to be a valid extension anymore

Definition at line 4175 of file pbx.c.

References E_MATCHMORE, and pbx_extension_helper().

Referenced by __ast_pbx_run(), 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(), readexten_exec(), skinny_ss(), and ss_thread().

04176 {
04177    return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_MATCHMORE, 0, 0);
04178 }

void ast_merge_contexts_and_delete ( struct ast_context **  extcontexts,
struct ast_hashtab *  exttable,
const char *  registrar 
)

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

Parameters:
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 6635 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_log(), 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_wrlock_contexts(), ast_wrlock_contexts_version(), 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, LOG_WARNING, 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().

06636 {
06637    double ft;
06638    struct ast_context *tmp, *oldcontextslist;
06639    struct ast_hashtab *oldtable;
06640    struct store_hints store = AST_LIST_HEAD_INIT_VALUE;
06641    struct store_hint *this;
06642    struct ast_hint *hint;
06643    struct ast_exten *exten;
06644    int length;
06645    struct ast_state_cb *thiscb;
06646    struct ast_hashtab_iter *iter;
06647 
06648    /* it is very important that this function hold the hint list lock _and_ the conlock
06649       during its operation; not only do we need to ensure that the list of contexts
06650       and extensions does not change, but also that no hint callbacks (watchers) are
06651       added or removed during the merge/delete process
06652 
06653       in addition, the locks _must_ be taken in this order, because there are already
06654       other code paths that use this order
06655    */
06656 
06657    struct timeval begintime, writelocktime, endlocktime, enddeltime;
06658    int wrlock_ver;
06659 
06660    begintime = ast_tvnow();
06661    ast_rdlock_contexts();
06662    iter = ast_hashtab_start_traversal(contexts_table);
06663    while ((tmp = ast_hashtab_next(iter))) {
06664       context_merge(extcontexts, exttable, tmp, registrar);
06665    }
06666    ast_hashtab_end_traversal(iter);
06667    wrlock_ver = ast_wrlock_contexts_version();
06668 
06669    ast_unlock_contexts(); /* this feels real retarded, but you must do
06670                        what you must do If this isn't done, the following 
06671                         wrlock is a guraranteed deadlock */
06672    ast_wrlock_contexts();
06673    if (ast_wrlock_contexts_version() > wrlock_ver+1) {
06674       ast_log(LOG_WARNING,"==================!!!!!!!!!!!!!!!Something changed the contexts in the middle of merging contexts!\n");
06675    }
06676 
06677    AST_RWLIST_WRLOCK(&hints);
06678    writelocktime = ast_tvnow();
06679 
06680    /* preserve all watchers for hints */
06681    AST_RWLIST_TRAVERSE(&hints, hint, list) {
06682       if (!AST_LIST_EMPTY(&hint->callbacks)) {
06683          length = strlen(hint->exten->exten) + strlen(hint->exten->parent->name) + 2 + sizeof(*this);
06684          if (!(this = ast_calloc(1, length)))
06685             continue;
06686          /* this removes all the callbacks from the hint into this. */
06687          AST_LIST_APPEND_LIST(&this->callbacks, &hint->callbacks, entry);
06688          this->laststate = hint->laststate;
06689          this->context = this->data;
06690          strcpy(this->data, hint->exten->parent->name);
06691          this->exten = this->data + strlen(this->context) + 1;
06692          strcpy(this->exten, hint->exten->exten);
06693          AST_LIST_INSERT_HEAD(&store, this, list);
06694       }
06695    }
06696 
06697    /* save the old table and list */
06698    oldtable = contexts_table;
06699    oldcontextslist = contexts;
06700 
06701    /* move in the new table and list */
06702    contexts_table = exttable;
06703    contexts = *extcontexts;
06704 
06705    /* restore the watchers for hints that can be found; notify those that
06706       cannot be restored
06707    */
06708    while ((this = AST_LIST_REMOVE_HEAD(&store, list))) {
06709       struct pbx_find_info q = { .stacklen = 0 };
06710       exten = pbx_find_extension(NULL, NULL, &q, this->context, this->exten, PRIORITY_HINT, NULL, "", E_MATCH);
06711       /* If this is a pattern, dynamically create a new extension for this
06712        * particular match.  Note that this will only happen once for each
06713        * individual extension, because the pattern will no longer match first.
06714        */
06715       if (exten && exten->exten[0] == '_') {
06716          ast_add_extension_nolock(exten->parent->name, 0, this->exten, PRIORITY_HINT, NULL,
06717             0, exten->app, ast_strdup(exten->data), ast_free_ptr, exten->registrar);
06718          /* rwlocks are not recursive locks */
06719          exten = ast_hint_extension_nolock(NULL, this->context, this->exten);
06720       }
06721 
06722       /* Find the hint in the list of hints */
06723       AST_RWLIST_TRAVERSE(&hints, hint, list) {
06724          if (hint->exten == exten)
06725             break;
06726       }
06727       if (!exten || !hint) {
06728          /* this hint has been removed, notify the watchers */
06729          while ((thiscb = AST_LIST_REMOVE_HEAD(&this->callbacks, entry))) {
06730             thiscb->callback(this->context, this->exten, AST_EXTENSION_REMOVED, thiscb->data);
06731             ast_free(thiscb);
06732          }
06733       } else {
06734          AST_LIST_APPEND_LIST(&hint->callbacks, &this->callbacks, entry);
06735          hint->laststate = this->laststate;
06736       }
06737       ast_free(this);
06738    }
06739 
06740    AST_RWLIST_UNLOCK(&hints);
06741    ast_unlock_contexts();
06742    endlocktime = ast_tvnow();
06743 
06744    /* the old list and hashtab no longer are relevant, delete them while the rest of asterisk
06745       is now freely using the new stuff instead */
06746 
06747    ast_hashtab_destroy(oldtable, NULL);
06748 
06749    for (tmp = oldcontextslist; tmp; ) {
06750       struct ast_context *next;  /* next starting point */
06751       next = tmp->next;
06752       __ast_internal_context_destroy(tmp);
06753       tmp = next;
06754    }
06755    enddeltime = ast_tvnow();
06756 
06757    ft = ast_tvdiff_us(writelocktime, begintime);
06758    ft /= 1000000.0;
06759    ast_verb(3,"Time to scan old dialplan and merge leftovers back into the new: %8.6f sec\n", ft);
06760 
06761    ft = ast_tvdiff_us(endlocktime, writelocktime);
06762    ft /= 1000000.0;
06763    ast_verb(3,"Time to restore hints and swap in new dialplan: %8.6f sec\n", ft);
06764 
06765    ft = ast_tvdiff_us(enddeltime, endlocktime);
06766    ft /= 1000000.0;
06767    ast_verb(3,"Time to delete the old dialplan: %8.6f sec\n", ft);
06768 
06769    ft = ast_tvdiff_us(enddeltime, begintime);
06770    ft /= 1000000.0;
06771    ast_verb(3,"Total time merge_contexts_delete: %8.6f sec\n", ft);
06772    return;
06773 }

int ast_parseable_goto ( struct ast_channel *  chan,
const char *  goto_string 
)

Note:
This function will handle locking the channel as needed.

Definition at line 9645 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().

09646 {
09647    return pbx_parseable_goto(chan, goto_string, 0);
09648 }

int ast_pbx_outgoing_app ( const char *  type,
int  format,
void *  data,
int  timeout,
const char *  app,
const char *  appdata,
int *  reason,
int  sync,
const char *  cid_num,
const char *  cid_name,
struct ast_variable *  vars,
const char *  account,
struct ast_channel **  locked_channel 
)

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

Definition at line 8118 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().

08119 {
08120    struct ast_channel *chan;
08121    struct app_tmp *tmp;
08122    int res = -1, cdr_res = -1;
08123    struct outgoing_helper oh;
08124 
08125    memset(&oh, 0, sizeof(oh));
08126    oh.vars = vars;
08127    oh.account = account;
08128 
08129    if (locked_channel)
08130       *locked_channel = NULL;
08131    if (ast_strlen_zero(app)) {
08132       res = -1;
08133       goto outgoing_app_cleanup;
08134    }
08135    if (synchronous) {
08136       chan = __ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name, &oh);
08137       if (chan) {
08138          ast_set_variables(chan, vars);
08139          if (account)
08140             ast_cdr_setaccount(chan, account);
08141          if (chan->_state == AST_STATE_UP) {
08142             res = 0;
08143             ast_verb(4, "Channel %s was answered.\n", chan->name);
08144             tmp = ast_calloc(1, sizeof(*tmp));
08145             if (!tmp)
08146                res = -1;
08147             else {
08148                ast_copy_string(tmp->app, app, sizeof(tmp->app));
08149                if (appdata)
08150                   ast_copy_string(tmp->data, appdata, sizeof(tmp->data));
08151                tmp->chan = chan;
08152                if (synchronous > 1) {
08153                   if (locked_channel)
08154                      ast_channel_unlock(chan);
08155                   ast_pbx_run_app(tmp);
08156                } else {
08157                   if (locked_channel)
08158                      ast_channel_lock(chan);
08159                   if (ast_pthread_create_detached(&tmp->t, NULL, ast_pbx_run_app, tmp)) {
08160                      ast_log(LOG_WARNING, "Unable to spawn execute thread on %s: %s\n", chan->name, strerror(errno));
08161                      ast_free(tmp);
08162                      if (locked_channel)
08163                         ast_channel_unlock(chan);
08164                      ast_hangup(chan);
08165                      res = -1;
08166                   } else {
08167                      if (locked_channel)
08168                         *locked_channel = chan;
08169                   }
08170                }
08171             }
08172          } else {
08173             ast_verb(4, "Channel %s was never answered.\n", chan->name);
08174             if (chan->cdr) { /* update the cdr */
08175                /* here we update the status of the call, which sould be busy.
08176                 * if that fails then we set the status to failed */
08177                if (ast_cdr_disposition(chan->cdr, chan->hangupcause))
08178                   ast_cdr_failed(chan->cdr);
08179             }
08180             ast_hangup(chan);
08181          }
08182       }
08183 
08184       if (res < 0) { /* the call failed for some reason */
08185          if (*reason == 0) { /* if the call failed (not busy or no answer)
08186                         * update the cdr with the failed message */
08187             cdr_res = ast_pbx_outgoing_cdr_failed();
08188             if (cdr_res != 0) {
08189                res = cdr_res;
08190                goto outgoing_app_cleanup;
08191             }
08192          }
08193       }
08194 
08195    } else {
08196       struct async_stat *as;
08197       if (!(as = ast_calloc(1, sizeof(*as)))) {
08198          res = -1;
08199          goto outgoing_app_cleanup;
08200       }
08201       chan = __ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name, &oh);
08202       if (!chan) {
08203          ast_free(as);
08204          res = -1;
08205          goto outgoing_app_cleanup;
08206       }
08207       as->chan = chan;
08208       ast_copy_string(as->app, app, sizeof(as->app));
08209       if (appdata)
08210          ast_copy_string(as->appdata,  appdata, sizeof(as->appdata));
08211       as->timeout = timeout;
08212       ast_set_variables(chan, vars);
08213       if (account)
08214          ast_cdr_setaccount(chan, account);
08215       /* Start a new thread, and get something handling this channel. */
08216       if (locked_channel)
08217          ast_channel_lock(chan);
08218       if (ast_pthread_create_detached(&as->p, NULL, async_wait, as)) {
08219          ast_log(LOG_WARNING, "Failed to start async wait\n");
08220          ast_free(as);
08221          if (locked_channel)
08222             ast_channel_unlock(chan);
08223          ast_hangup(chan);
08224          res = -1;
08225          goto outgoing_app_cleanup;
08226       } else {
08227          if (locked_channel)
08228             *locked_channel = chan;
08229       }
08230       res = 0;
08231    }
08232 outgoing_app_cleanup:
08233    ast_variables_destroy(vars);
08234    return res;
08235 }

static int ast_pbx_outgoing_cdr_failed ( void   )  [static]

Function to post an empty cdr after a spool call fails.

Note:
This function posts an empty cdr for a failed spool call

Definition at line 7926 of file pbx.c.

References ast_cdr_detach(), ast_cdr_end(), ast_cdr_failed(), ast_cdr_init(), ast_cdr_start(), ast_channel_alloc, ast_channel_free(), AST_STATE_DOWN, and ast_channel::cdr.

Referenced by ast_pbx_outgoing_app(), and ast_pbx_outgoing_exten().

07927 {
07928    /* allocate a channel */
07929    struct ast_channel *chan = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", 0, "%s", "");
07930 
07931    if (!chan)
07932       return -1;  /* failure */
07933 
07934    if (!chan->cdr) {
07935       /* allocation of the cdr failed */
07936       ast_channel_free(chan);   /* free the channel */
07937       return -1;                /* return failure */
07938    }
07939 
07940    /* allocation of the cdr was successful */
07941    ast_cdr_init(chan->cdr, chan);  /* initialize our channel's cdr */
07942    ast_cdr_start(chan->cdr);       /* record the start and stop time */
07943    ast_cdr_end(chan->cdr);
07944    ast_cdr_failed(chan->cdr);      /* set the status to failed */
07945    ast_cdr_detach(chan->cdr);      /* post and free the record */
07946    chan->cdr = NULL;
07947    ast_channel_free(chan);         /* free the channel */
07948 
07949    return 0;  /* success */
07950 }

int ast_pbx_outgoing_exten ( const char *  type,
int  format,
void *  data,
int  timeout,
const char *  context,
const char *  exten,
int  priority,
int *  reason,
int  sync,
const char *  cid_num,
const char *  cid_name,
struct ast_variable *  vars,
const char *  account,
struct ast_channel **  locked_channel 
)

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

Definition at line 7952 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().

07953 {
07954    struct ast_channel *chan;
07955    struct async_stat *as;
07956    int res = -1, cdr_res = -1;
07957    struct outgoing_helper oh;
07958 
07959    if (synchronous) {
07960       oh.context = context;
07961       oh.exten = exten;
07962       oh.priority = priority;
07963       oh.cid_num = cid_num;
07964       oh.cid_name = cid_name;
07965       oh.account = account;
07966       oh.vars = vars;
07967       oh.parent_channel = NULL;
07968 
07969       chan = __ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name, &oh);
07970       if (channel) {
07971          *channel = chan;
07972          if (chan)
07973             ast_channel_lock(chan);
07974       }
07975       if (chan) {
07976          if (chan->_state == AST_STATE_UP) {
07977                res = 0;
07978             ast_verb(4, "Channel %s was answered.\n", chan->name);
07979 
07980             if (synchronous > 1) {
07981                if (channel)
07982                   ast_channel_unlock(chan);
07983                if (ast_pbx_run(chan)) {
07984                   ast_log(LOG_ERROR, "Unable to run PBX on %s\n", chan->name);
07985                   if (channel)
07986                      *channel = NULL;
07987                   ast_hangup(chan);
07988                   chan = NULL;
07989                   res = -1;
07990                }
07991             } else {
07992                if (ast_pbx_start(chan)) {
07993                   ast_log(LOG_ERROR, "Unable to start PBX on %s\n", chan->name);
07994                   if (channel) {
07995                      *channel = NULL;
07996                      ast_channel_unlock(chan);
07997                   }
07998                   ast_hangup(chan);
07999                   res = -1;
08000                }
08001                chan = NULL;
08002             }
08003          } else {
08004             ast_verb(4, "Channel %s was never answered.\n", chan->name);
08005 
08006             if (chan->cdr) { /* update the cdr */
08007                /* here we update the status of the call, which sould be busy.
08008                 * if that fails then we set the status to failed */
08009                if (ast_cdr_disposition(chan->cdr, chan->hangupcause))
08010                   ast_cdr_failed(chan->cdr);
08011             }
08012 
08013             if (channel) {
08014                *channel = NULL;
08015                ast_channel_unlock(chan);
08016             }
08017             ast_hangup(chan);
08018             chan = NULL;
08019          }
08020       }
08021 
08022       if (res < 0) { /* the call failed for some reason */
08023          if (*reason == 0) { /* if the call failed (not busy or no answer)
08024                         * update the cdr with the failed message */
08025             cdr_res = ast_pbx_outgoing_cdr_failed();
08026             if (cdr_res != 0) {
08027                res = cdr_res;
08028                goto outgoing_exten_cleanup;
08029             }
08030          }
08031 
08032          /* create a fake channel and execute the "failed" extension (if it exists) within the requested context */
08033          /* check if "failed" exists */
08034          if (ast_exists_extension(chan, context, "failed", 1, NULL)) {
08035             chan = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", 0, "OutgoingSpoolFailed");
08036             if (chan) {
08037                char failed_reason[4] = "";
08038                if (!ast_strlen_zero(context))
08039                   ast_copy_string(chan->context, context, sizeof(chan->context));
08040                set_ext_pri(chan, "failed", 1);
08041                ast_set_variables(chan, vars);
08042                snprintf(failed_reason, sizeof(failed_reason), "%d", *reason);
08043                pbx_builtin_setvar_helper(chan, "REASON", failed_reason);
08044                if (account)
08045                   ast_cdr_setaccount(chan, account);
08046                if (ast_pbx_run(chan)) {
08047                   ast_log(LOG_ERROR, "Unable to run PBX on %s\n", chan->name);
08048                   ast_hangup(chan);
08049                }
08050                chan = NULL;
08051             }
08052          }
08053       }
08054    } else {
08055       if (!(as = ast_calloc(1, sizeof(*as)))) {
08056          res = -1;
08057          goto outgoing_exten_cleanup;
08058       }
08059       chan = ast_request_and_dial(type, format, data, timeout, reason, cid_num, cid_name);
08060       if (channel) {
08061          *channel = chan;
08062          if (chan)
08063             ast_channel_lock(chan);
08064       }
08065       if (!chan) {
08066          ast_free(as);
08067          res = -1;
08068          goto outgoing_exten_cleanup;
08069       }
08070       as->chan = chan;
08071       ast_copy_string(as->context, context, sizeof(as->context));
08072       set_ext_pri(as->chan,  exten, priority);
08073       as->timeout = timeout;
08074       ast_set_variables(chan, vars);
08075       if (account)
08076          ast_cdr_setaccount(chan, account);
08077       if (ast_pthread_create_detached(&as->p, NULL, async_wait, as)) {
08078          ast_log(LOG_WARNING, "Failed to start async wait\n");
08079          ast_free(as);
08080          if (channel) {
08081             *channel = NULL;
08082             ast_channel_unlock(chan);
08083          }
08084          ast_hangup(chan);
08085          res = -1;
08086          goto outgoing_exten_cleanup;
08087       }
08088       res = 0;
08089    }
08090 outgoing_exten_cleanup:
08091    ast_variables_destroy(vars);
08092    return res;
08093 }

enum ast_pbx_result ast_pbx_run ( struct ast_channel *  c  ) 

Execute the PBX in the current thread.

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

Return values:
Zero on success
non-zero on failure

Definition at line 4608 of file pbx.c.

References ast_pbx_run_args().

Referenced by ast_pbx_outgoing_exten(), async_wait(), do_idle_thread(), mgcp_ss(), skinny_newcall(), ss_thread(), and unistim_ss().

04609 {
04610    return ast_pbx_run_args(c, NULL);
04611 }

static void* ast_pbx_run_app ( void *  data  )  [static]

run the application and free the descriptor once done

Definition at line 8103 of file pbx.c.

References app_tmp::app, ast_free, ast_hangup(), ast_log(), ast_verb, app_tmp::chan, app_tmp::data, LOG_WARNING, ast_channel::name, pbx_exec(), and pbx_findapp().

Referenced by ast_pbx_outgoing_app().

08104 {
08105    struct app_tmp *tmp = data;
08106    struct ast_app *app;
08107    app = pbx_findapp(tmp->app);
08108    if (app) {
08109       ast_verb(4, "Launching %s(%s) on %s\n", tmp->app, tmp->data, tmp->chan->name);
08110       pbx_exec(tmp->chan, app, tmp->data);
08111    } else
08112       ast_log(LOG_WARNING, "No such application '%s'\n", tmp->app);
08113    ast_hangup(tmp->chan);
08114    ast_free(tmp);
08115    return NULL;
08116 }

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

Execute the PBX in the current thread.

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

Return values:
Zero on success
non-zero on failure

Definition at line 4593 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().

04594 {
04595    enum ast_pbx_result res = AST_PBX_SUCCESS;
04596 
04597    if (increase_call_count(c)) {
04598       return AST_PBX_CALL_LIMIT;
04599    }
04600 
04601    res = __ast_pbx_run(c, args);
04602 
04603    decrease_call_count();
04604 
04605    return res;
04606 }

enum ast_pbx_result ast_pbx_start ( struct ast_channel *  c  ) 

Create a new thread and start the PBX.

Parameters:
c channel to start the pbx on
See also:
ast_pbx_run for a synchronous function to run the PBX in the current thread, as opposed to starting a new one.
Return values:
Zero on success
non-zero on failure

Definition at line 4571 of file pbx.c.

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

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

04572 {
04573    pthread_t t;
04574 
04575    if (!c) {
04576       ast_log(LOG_WARNING, "Asked to start thread on NULL channel?\n");
04577       return AST_PBX_FAILED;
04578    }
04579 
04580    if (increase_call_count(c))
04581       return AST_PBX_CALL_LIMIT;
04582 
04583    /* Start a new thread, and get something handling this channel. */
04584    if (ast_pthread_create_detached(&t, NULL, pbx_thread, c)) {
04585       ast_log(LOG_WARNING, "Failed to create new channel thread\n");
04586       decrease_call_count();
04587       return AST_PBX_FAILED;
04588    }
04589 
04590    return AST_PBX_SUCCESS;
04591 }

int ast_processed_calls ( void   ) 

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

Definition at line 4618 of file pbx.c.

References totalcalls.

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

04619 {
04620    return totalcalls;
04621 }

int ast_rdlock_context ( struct ast_context *  con  ) 

Read locks a given context.

Parameters:
con context to lock
Return values:
0 on success
-1 on failure

Definition at line 9383 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().

09384 {
09385    return ast_rwlock_rdlock(&con->lock);
09386 }

int ast_rdlock_contexts ( void   ) 

int ast_register_application2 ( const char *  app,
int(*)(struct ast_channel *, void *)  execute,
const char *  synopsis,
const char *  description,
void *  mod 
)

Dynamically register a new dial plan application.

Register an application.

Definition at line 5074 of file pbx.c.

References ast_app::arguments, ast_calloc, ast_free, 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_string_field_init, ast_string_field_set, ast_strlen_zero(), ast_verb, AST_XML_DOC, ast_xmldoc_build_arguments(), ast_xmldoc_build_description(), ast_xmldoc_build_seealso(), ast_xmldoc_build_synopsis(), ast_xmldoc_build_syntax(), COLOR_BRCYAN, ast_app::docsrc, ast_app::execute, LOG_WARNING, ast_app::module, ast_app::name, ast_app::seealso, ast_app::syntax, and term_color().

Referenced by ast_features_init(), and load_pbx().

05075 {
05076    struct ast_app *tmp, *cur = NULL;
05077    char tmps[80];
05078    int length, res;
05079 #ifdef AST_XML_DOCS
05080    char *tmpxml;
05081 #endif
05082 
05083    AST_RWLIST_WRLOCK(&apps);
05084    AST_RWLIST_TRAVERSE(&apps, tmp, list) {
05085       if (!(res = strcasecmp(app, tmp->name))) {
05086          ast_log(LOG_WARNING, "Already have an application '%s'\n", app);
05087          AST_RWLIST_UNLOCK(&apps);
05088          return -1;
05089       } else if (res < 0)
05090          break;
05091    }
05092 
05093    length = sizeof(*tmp) + strlen(app) + 1;
05094 
05095    if (!(tmp = ast_calloc(1, length))) {
05096       AST_RWLIST_UNLOCK(&apps);
05097       return -1;
05098    }
05099 
05100    if (ast_string_field_init(tmp, 128)) {
05101       AST_RWLIST_UNLOCK(&apps);
05102       ast_free(tmp);
05103       return -1;
05104    }
05105 
05106 #ifdef AST_XML_DOCS
05107    /* Try to lookup the docs in our XML documentation database */
05108    if (ast_strlen_zero(synopsis) && ast_strlen_zero(description)) {
05109       /* load synopsis */
05110       tmpxml = ast_xmldoc_build_synopsis("application", app);
05111       ast_string_field_set(tmp, synopsis, tmpxml);
05112       ast_free(tmpxml);
05113 
05114       /* load description */
05115       tmpxml = ast_xmldoc_build_description("application", app);
05116       ast_string_field_set(tmp, description, tmpxml);
05117       ast_free(tmpxml);
05118 
05119       /* load syntax */
05120       tmpxml = ast_xmldoc_build_syntax("application", app);
05121       ast_string_field_set(tmp, syntax, tmpxml);
05122       ast_free(tmpxml);
05123 
05124       /* load arguments */
05125       tmpxml = ast_xmldoc_build_arguments("application", app);
05126       ast_string_field_set(tmp, arguments, tmpxml);
05127       ast_free(tmpxml);
05128 
05129       /* load seealso */
05130       tmpxml = ast_xmldoc_build_seealso("application", app);
05131       ast_string_field_set(tmp, seealso, tmpxml);
05132       ast_free(tmpxml);
05133       tmp->docsrc = AST_XML_DOC;
05134    } else {
05135 #endif
05136       ast_string_field_set(tmp, synopsis, synopsis);
05137       ast_string_field_set(tmp, description, description);
05138       tmp->docsrc = AST_STATIC_DOC;
05139 #ifdef AST_XML_DOCS
05140    }
05141 #endif
05142 
05143    strcpy(tmp->name, app);
05144    tmp->execute = execute;
05145    tmp->module = mod;
05146 
05147    /* Store in alphabetical order */
05148    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, cur, list) {
05149       if (strcasecmp(tmp->name, cur->name) < 0) {
05150          AST_RWLIST_INSERT_BEFORE_CURRENT(tmp, list);
05151          break;
05152       }
05153    }
05154    AST_RWLIST_TRAVERSE_SAFE_END;
05155    if (!cur)
05156       AST_RWLIST_INSERT_TAIL(&apps, tmp, list);
05157 
05158    ast_verb(2, "Registered application '%s'\n", term_color(tmps, tmp->name, COLOR_BRCYAN, 0, sizeof(tmps)));
05159 
05160    AST_RWLIST_UNLOCK(&apps);
05161 
05162    return 0;
05163 }

int ast_register_switch ( struct ast_switch *  sw  ) 

Register an alternative dialplan switch.

Parameters:
sw switch to register
This function registers a populated ast_switch structure with the asterisk switching architecture.

Return values:
0 success
non-zero failure

Definition at line 5169 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().

05170 {
05171    struct ast_switch *tmp;
05172 
05173    AST_RWLIST_WRLOCK(&switches);
05174    AST_RWLIST_TRAVERSE(&switches, tmp, list) {
05175       if (!strcasecmp(tmp->name, sw->name)) {
05176          AST_RWLIST_UNLOCK(&switches);
05177          ast_log(LOG_WARNING, "Switch '%s' already found\n", sw->name);
05178          return -1;
05179       }
05180    }
05181    AST_RWLIST_INSERT_TAIL(&switches, sw, list);
05182    AST_RWLIST_UNLOCK(&switches);
05183 
05184    return 0;
05185 }

static int ast_remove_hint ( struct ast_exten *  e  )  [static]

Remove hint from extension.

Definition at line 4103 of file pbx.c.

References AST_EXTENSION_DEACTIVATED, ast_free, AST_LIST_REMOVE_HEAD, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, ast_state_cb::callback, ast_hint::callbacks, ast_state_cb::data, ast_exten::exten, ast_hint::exten, ast_context::name, and ast_exten::parent.

Referenced by destroy_exten().

04104 {
04105    /* Cleanup the Notifys if hint is removed */
04106    struct ast_hint *hint;
04107    struct ast_state_cb *cblist;
04108    int res = -1;
04109 
04110    if (!e)
04111       return -1;
04112 
04113    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&hints, hint, list) {
04114       if (hint->exten != e)
04115          continue;
04116 
04117       while ((cblist = AST_LIST_REMOVE_HEAD(&hint->callbacks, entry))) {
04118          /* Notify with -1 and remove all callbacks */
04119          cblist->callback(hint->exten->parent->name, hint->exten->exten,
04120             AST_EXTENSION_DEACTIVATED, cblist->data);
04121          ast_free(cblist);
04122       }
04123 
04124       AST_RWLIST_REMOVE_CURRENT(list);
04125       ast_free(hint);
04126 
04127       res = 0;
04128 
04129       break;
04130    }
04131    AST_RWLIST_TRAVERSE_SAFE_END;
04132 
04133    return res;
04134 }

int ast_spawn_extension ( struct ast_channel *  c,
const char *  context,
const char *  exten,
int  priority,
const char *  callerid,
int *  found,
int  combined_find_spawn 
)

Launch a new extension (i.e. new stack).

Parameters:
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.

Note:
It is possible for autoservice to be started and stopped on c during this function call, it is important that c is not locked prior to calling this. Otherwise a deadlock may occur
Return values:
0 on success
-1 on failure.

Definition at line 4180 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().

04181 {
04182    return pbx_extension_helper(c, NULL, context, exten, priority, NULL, callerid, E_SPAWN, found, combined_find_spawn);
04183 }

int ast_unlock_context ( struct ast_context *  con  ) 

int ast_unlock_contexts ( void   ) 

int ast_unregister_application ( const char *  app  ) 

Unregister an application.

Parameters:
app name of the application (does not have to be the same string as the one that was registered)
This unregisters an application from Asterisk's internal application list.

Return values:
0 success
-1 failure

Definition at line 6415 of file pbx.c.

References ast_free, AST_RWLIST_REMOVE_CURRENT, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_string_field_free_memory, ast_verb, ast_app::name, and unreference_cached_app().

Referenced by __unload_module(), load_module(), and unload_module().

06416 {
06417    struct ast_app *tmp;
06418 
06419    AST_RWLIST_WRLOCK(&apps);
06420    AST_RWLIST_TRAVERSE_SAFE_BEGIN(&apps, tmp, list) {
06421       if (!strcasecmp(app, tmp->name)) {
06422          unreference_cached_app(tmp);
06423          AST_RWLIST_REMOVE_CURRENT(list);
06424          ast_verb(2, "Unregistered application '%s'\n", tmp->name);
06425          ast_string_field_free_memory(tmp);
06426          ast_free(tmp);
06427          break;
06428       }
06429    }
06430    AST_RWLIST_TRAVERSE_SAFE_END;
06431    AST_RWLIST_UNLOCK(&apps);
06432 
06433    return tmp ? 0 : -1;
06434 }

void ast_unregister_switch ( struct ast_switch *  sw  ) 

Unregister an alternative switch.

Parameters:
sw switch to unregister
Unregisters a switch from asterisk.

Returns:
nothing

Definition at line 5187 of file pbx.c.

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, and AST_RWLIST_WRLOCK.

Referenced by __unload_module(), and unload_module().

05188 {
05189    AST_RWLIST_WRLOCK(&switches);
05190    AST_RWLIST_REMOVE(&switches, sw, list);
05191    AST_RWLIST_UNLOCK(&switches);
05192 }

struct ast_exten* ast_walk_context_extensions ( struct ast_context *  con,
struct ast_exten *  exten 
) [read]

Definition at line 9502 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().

09504 {
09505    if (!exten)
09506       return con ? con->root : NULL;
09507    else
09508       return exten->next;
09509 }

struct ast_ignorepat* ast_walk_context_ignorepats ( struct ast_context *  con,
struct ast_ignorepat *  ip 
) [read]

Definition at line 9535 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().

09537 {
09538    if (!ip)
09539       return con ? con->ignorepats : NULL;
09540    else
09541       return ip->next;
09542 }

struct ast_include* ast_walk_context_includes ( struct ast_context *  con,
struct ast_include *  inc 
) [read]

struct ast_sw* ast_walk_context_switches ( struct ast_context *  con,
struct ast_sw *  sw 
) [read]

Definition at line 9511 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().

09513 {
09514    if (!sw)
09515       return con ? AST_LIST_FIRST(&con->alts) : NULL;
09516    else
09517       return AST_LIST_NEXT(sw, list);
09518 }

struct ast_context* ast_walk_contexts ( struct ast_context *  con  )  [read]

struct ast_exten* ast_walk_extension_priorities ( struct ast_exten *  exten,
struct ast_exten *  priority 
) [read]

int ast_wrlock_context ( struct ast_context *  con  ) 

Write locks a given context.

Parameters:
con context to lock
Return values:
0 on success
-1 on failure

Definition at line 9378 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().

09379 {
09380    return ast_rwlock_wrlock(&con->lock);
09381 }

int ast_wrlock_contexts ( void   ) 

Write locks the context list.

Return values:
0 on success
-1 on error

Definition at line 9357 of file pbx.c.

References ast_atomic_fetchadd_int(), ast_rwlock_wrlock(), conlock, and conlock_wrlock_version.

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

09358 {
09359    int res = ast_rwlock_wrlock(&conlock);
09360    if (!res)
09361       ast_atomic_fetchadd_int(&conlock_wrlock_version, 1);
09362    return res;
09363 }

int ast_wrlock_contexts_version ( void   ) 

Definition at line 9349 of file pbx.c.

References conlock_wrlock_version.

Referenced by ast_merge_contexts_and_delete().

09350 {
09351    return conlock_wrlock_version;
09352 }

static void* async_wait ( void *  data  )  [static]

Definition at line 7865 of file pbx.c.

References ast_channel::_state, async_stat::app, async_stat::appdata, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, ast_copy_string(), AST_FRAME_CONTROL, ast_free, ast_frfree, ast_hangup(), ast_log(), ast_pbx_run(), ast_read(), AST_STATE_UP, ast_strlen_zero(), ast_verb, ast_waitfor(), async_stat::chan, ast_channel::context, async_stat::context, ast_channel::exten, async_stat::exten, f, ast_frame::frametype, LOG_ERROR, LOG_WARNING, ast_channel::name, pbx_exec(), pbx_findapp(), ast_channel::priority, async_stat::priority, ast_frame::subclass, and async_stat::timeout.

Referenced by ast_pbx_outgoing_app(), and ast_pbx_outgoing_exten().

07866 {
07867    struct async_stat *as = data;
07868    struct ast_channel *chan = as->chan;
07869    int timeout = as->timeout;
07870    int res;
07871    struct ast_frame *f;
07872    struct ast_app *app;
07873 
07874    while (timeout && (chan->_state != AST_STATE_UP)) {
07875       res = ast_waitfor(chan, timeout);
07876       if (res < 1)
07877          break;
07878       if (timeout > -1)
07879          timeout = res;
07880       f = ast_read(chan);
07881       if (!f)
07882          break;
07883       if (f->frametype == AST_FRAME_CONTROL) {
07884          if ((f->subclass == AST_CONTROL_BUSY)  ||
07885              (f->subclass == AST_CONTROL_CONGESTION) ) {
07886             ast_frfree(f);
07887             break;
07888          }
07889       }
07890       ast_frfree(f);
07891    }
07892    if (chan->_state == AST_STATE_UP) {
07893       if (!ast_strlen_zero(as->app)) {
07894          app = pbx_findapp(as->app);
07895          if (app) {
07896             ast_verb(3, "Launching %s(%s) on %s\n", as->app, as->appdata, chan->name);
07897             pbx_exec(chan, app, as->appdata);
07898          } else
07899             ast_log(LOG_WARNING, "No such application '%s'\n", as->app);
07900       } else {
07901          if (!ast_strlen_zero(as->context))
07902             ast_copy_string(chan->context, as->context, sizeof(chan->context));
07903          if (!ast_strlen_zero(as->exten))
07904             ast_copy_string(chan->exten, as->exten, sizeof(chan->exten));
07905          if (as->priority > 0)
07906             chan->priority = as->priority;
07907          /* Run the PBX */
07908          if (ast_pbx_run(chan)) {
07909             ast_log(LOG_ERROR, "Failed to start PBX on %s\n", chan->name);
07910          } else {
07911             /* PBX will have taken care of this */
07912             chan = NULL;
07913          }
07914       }
07915    }
07916    ast_free(as);
07917    if (chan)
07918       ast_hangup(chan);
07919    return NULL;
07920 }

static void cli_match_char_tree ( struct match_char *  node,
char *  prefix,
int  fd 
) [static]

Definition at line 1523 of file pbx.c.

References match_char::alt_char, ast_cli(), ast_str_alloca, ast_str_buffer(), ast_str_set(), match_char::deleted, ast_exten::exten, match_char::exten, match_char::is_pattern, match_char::next_char, match_char::specificity, and match_char::x.

Referenced by show_debug_helper().

01524 {
01525    char extenstr[40];
01526    struct ast_str *my_prefix = ast_str_alloca(1024);
01527 
01528    extenstr[0] = '\0';
01529 
01530    if (node && node->exten && node->exten)
01531       snprintf(extenstr, sizeof(extenstr), "(%p)", node->exten);
01532 
01533    if (strlen(node->x) > 1) {
01534       ast_cli(fd, "%s[%s]:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y' : 'N',
01535          node->deleted ? 'D' : '-', node->specificity, node->exten? "EXTEN:" : "",
01536          node->exten ? node->exten->exten : "", extenstr);
01537    } else {
01538       ast_cli(fd, "%s%s:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y' : 'N',
01539          node->deleted ? 'D' : '-', node->specificity, node->exten? "EXTEN:" : "",
01540          node->exten ? node->exten->exten : "", extenstr);
01541    }
01542 
01543    ast_str_set(&my_prefix, 0, "%s+       ", prefix);
01544 
01545    if (node->next_char)
01546       cli_match_char_tree(node->next_char, ast_str_buffer(my_prefix), fd);
01547 
01548    if (node->alt_char)
01549       cli_match_char_tree(node->alt_char, prefix, fd);
01550 }

static int collect_digits ( struct ast_channel *  c,
int  waittime,
char *  buf,
int  buflen,
int  pos 
) [static]

collect digits from the channel into the buffer.

Parameters:
waittime is in milliseconds
Return values:
0 on timeout or done.
-1 on error.

Definition at line 4200 of file pbx.c.

References ast_channel::_softhangup, ast_matchmore_extension(), AST_SOFTHANGUP_ASYNCGOTO, ast_waitfordigit(), ast_channel::cid, ast_callerid::cid_num, ast_channel::context, ast_pbx::dtimeoutms, and ast_channel::pbx.

Referenced by __ast_pbx_run().

04201 {
04202    int digit;
04203 
04204    buf[pos] = '\0';  /* make sure it is properly terminated */
04205    while (ast_matchmore_extension(c, c->context, buf, 1, c->cid.cid_num)) {
04206       /* As long as we're willing to wait, and as long as it's not defined,
04207          keep reading digits until we can't possibly get a right answer anymore.  */
04208       digit = ast_waitfordigit(c, waittime);
04209       if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
04210          c->_softhangup = 0;
04211       } else {
04212          if (!digit) /* No entry */
04213             break;
04214          if (digit < 0) /* Error, maybe a  hangup */
04215             return -1;
04216          if (pos < buflen - 1) { /* XXX maybe error otherwise ? */
04217             buf[pos++] = digit;
04218             buf[pos] = '\0';
04219          }
04220          waittime = c->pbx->dtimeoutms;
04221       }
04222    }
04223    return 0;
04224 }

static int compare_char ( const void *  a,
const void *  b 
) [static]

Definition at line 981 of file pbx.c.

Referenced by add_exten_to_pattern_tree().

00982 {
00983    const char *ac = a;
00984    const char *bc = b;
00985    if ((*ac) < (*bc))
00986       return -1;
00987    else if ((*ac) == (*bc))
00988       return 0;
00989    else
00990       return 1;
00991 }

static char* complete_core_show_hint ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

autocomplete for CLI command 'core show hint'

Definition at line 5383 of file pbx.c.

References ast_get_extension_name(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, and ast_hint::exten.

Referenced by handle_show_hint().

05384 {
05385    struct ast_hint *hint;
05386    char *ret = NULL;
05387    int which = 0;
05388    int wordlen;
05389 
05390    if (pos != 3)
05391       return NULL;
05392 
05393    wordlen = strlen(word);
05394 
05395    AST_RWLIST_RDLOCK(&hints);
05396    /* walk through all hints */
05397    AST_RWLIST_TRAVERSE(&hints, hint, list) {
05398       if (!strncasecmp(word, ast_get_extension_name(hint->exten), wordlen) && ++which > state) {
05399          ret = ast_strdup(ast_get_extension_name(hint->exten));
05400          break;
05401       }
05402    }
05403    AST_RWLIST_UNLOCK(&hints);
05404 
05405    return ret;
05406 }

static char* complete_show_dialplan_context ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 5579 of file pbx.c.

References ast_get_context_name(), ast_rdlock_contexts(), ast_strdup, ast_unlock_contexts(), and ast_walk_contexts().

Referenced by handle_debug_dialplan(), and handle_show_dialplan().

05581 {
05582    struct ast_context *c = NULL;
05583    char *ret = NULL;
05584    int which = 0;
05585    int wordlen;
05586 
05587    /* we are do completion of [exten@]context on second position only */
05588    if (pos != 2)
05589       return NULL;
05590 
05591    ast_rdlock_contexts();
05592 
05593    wordlen = strlen(word);
05594 
05595    /* walk through all contexts and return the n-th match */
05596    while ( (c = ast_walk_contexts(c)) ) {
05597       if (!strncasecmp(word, ast_get_context_name(c), wordlen) && ++which > state) {
05598          ret = ast_strdup(ast_get_context_name(c));
05599          break;
05600       }
05601    }
05602 
05603    ast_unlock_contexts();
05604 
05605    return ret;
05606 }

static void context_merge ( struct ast_context **  extcontexts,
struct ast_hashtab *  exttable,
struct ast_context *  context,
const char *  registrar 
) [static]

Definition at line 6551 of file pbx.c.

References ast_exten::app, ast_add_extension2(), ast_context_find_or_create(), ast_hashtab_end_traversal(), ast_hashtab_lookup(), ast_hashtab_next(), ast_hashtab_start_traversal(), ast_log(), ast_strdup, ast_verb, ast_exten::cidmatch, context_merge_incls_swits_igps_other_registrars(), ast_exten::data, ast_exten::datad, ast_exten::exten, first, ast_exten::label, LOG_ERROR, ast_exten::matchcid, ast_context::name, ast_exten::peer_table, ast_exten::priority, ast_context::refcount, ast_context::registrar, ast_exten::registrar, and ast_context::root_table.

Referenced by ast_merge_contexts_and_delete().

06552 {
06553    struct ast_context *new = ast_hashtab_lookup(exttable, context); /* is there a match in the new set? */
06554    struct ast_exten *exten_item, *prio_item, *new_exten_item, *new_prio_item;
06555    struct ast_hashtab_iter *exten_iter;
06556    struct ast_hashtab_iter *prio_iter;
06557    int insert_count = 0;
06558    int first = 1;
06559 
06560    /* We'll traverse all the extensions/prios, and see which are not registrar'd with
06561       the current registrar, and copy them to the new context. If the new context does not
06562       exist, we'll create it "on demand". If no items are in this context to copy, then we'll
06563       only create the empty matching context if the old one meets the criteria */
06564 
06565    if (context->root_table) {
06566       exten_iter = ast_hashtab_start_traversal(context->root_table);
06567       while ((exten_item=ast_hashtab_next(exten_iter))) {
06568          if (new) {
06569             new_exten_item = ast_hashtab_lookup(new->root_table, exten_item);
06570          } else {
06571             new_exten_item = NULL;
06572          }
06573          prio_iter = ast_hashtab_start_traversal(exten_item->peer_table);
06574          while ((prio_item=ast_hashtab_next(prio_iter))) {
06575             int res1;
06576             char *dupdstr;
06577 
06578             if (new_exten_item) {
06579                new_prio_item = ast_hashtab_lookup(new_exten_item->peer_table, prio_item);
06580             } else {
06581                new_prio_item = NULL;
06582             }
06583             if (strcmp(prio_item->registrar,registrar) == 0) {
06584                continue;
06585             }
06586             /* make sure the new context exists, so we have somewhere to stick this exten/prio */
06587             if (!new) {
06588                new = ast_context_find_or_create(extcontexts, exttable, context->name, prio_item->registrar); /* a new context created via priority from a different context in the old dialplan, gets its registrar from the prio's registrar */
06589             }
06590 
06591             /* copy in the includes, switches, and ignorepats */
06592             if (first) { /* but, only need to do this once */
06593                context_merge_incls_swits_igps_other_registrars(new, context, registrar);
06594                first = 0;
06595             }
06596 
06597             if (!new) {
06598                ast_log(LOG_ERROR,"Could not allocate a new context for %s in merge_and_delete! Danger!\n", context->name);
06599                return; /* no sense continuing. */
06600             }
06601             /* we will not replace existing entries in the new context with stuff from the old context.
06602                but, if this is because of some sort of registrar conflict, we ought to say something... */
06603 
06604             dupdstr = ast_strdup(prio_item->data);
06605 
06606             res1 = ast_add_extension2(new, 0, prio_item->exten, prio_item->priority, prio_item->label, 
06607                                 prio_item->matchcid ? prio_item->cidmatch : NULL, prio_item->app, dupdstr, prio_item->datad, prio_item->registrar);
06608             if (!res1 && new_exten_item && new_prio_item){
06609                ast_verb(3,"Dropping old dialplan item %s/%s/%d [%s(%s)] (registrar=%s) due to conflict with new dialplan\n",
06610                      context->name, prio_item->exten, prio_item->priority, prio_item->app, (char*)prio_item->data, prio_item->registrar);
06611             } else {
06612                /* we do NOT pass the priority data from the old to the new -- we pass a copy of it, so no changes to the current dialplan take place,
06613                 and no double frees take place, either! */
06614                insert_count++;
06615             }
06616          }
06617          ast_hashtab_end_traversal(prio_iter);
06618       }
06619       ast_hashtab_end_traversal(exten_iter);
06620    }
06621 
06622    if (!insert_count && !new && (strcmp(context->registrar, registrar) != 0 ||
06623         (strcmp(context->registrar, registrar) == 0 && context->refcount > 1))) {
06624       /* we could have given it the registrar of the other module who incremented the refcount,
06625          but that's not available, so we give it the registrar we know about */
06626       new = ast_context_find_or_create(extcontexts, exttable, context->name, context->registrar);
06627 
06628       /* copy in the includes, switches, and ignorepats */
06629       context_merge_incls_swits_igps_other_registrars(new, context, registrar);
06630    }
06631 }

static void context_merge_incls_swits_igps_other_registrars ( struct ast_context *  new,
struct ast_context *  old,
const char *  registrar 
) [static]

Definition at line 6518 of file pbx.c.

References ast_context_add_ignorepat2(), ast_context_add_include2(), ast_context_add_switch2(), ast_get_context_name(), ast_get_ignorepat_name(), ast_get_ignorepat_registrar(), ast_get_include_name(), ast_get_include_registrar(), ast_get_switch_data(), ast_get_switch_eval(), ast_get_switch_name(), ast_get_switch_registrar(), ast_verb, ast_walk_context_ignorepats(), ast_walk_context_includes(), and ast_walk_context_switches().

Referenced by context_merge().

06519 {
06520    struct ast_include *i;
06521    struct ast_ignorepat *ip;
06522    struct ast_sw *sw;
06523 
06524    ast_verb(3, "merging incls/swits/igpats from old(%s) to new(%s) context, registrar = %s\n", ast_get_context_name(old), ast_get_context_name(new), registrar);
06525    /* copy in the includes, switches, and ignorepats */
06526    /* walk through includes */
06527    for (i = NULL; (i = ast_walk_context_includes(old, i)) ; ) {
06528       if (strcmp(ast_get_include_registrar(i), registrar) == 0)
06529          continue; /* not mine */
06530       ast_context_add_include2(new, ast_get_include_name(i), ast_get_include_registrar(i));
06531    }
06532 
06533    /* walk through switches */
06534    for (sw = NULL; (sw = ast_walk_context_switches(old, sw)) ; ) {
06535       if (strcmp(ast_get_switch_registrar(sw), registrar) == 0)
06536          continue; /* not mine */
06537       ast_context_add_switch2(new, ast_get_switch_name(sw), ast_get_switch_data(sw), ast_get_switch_eval(sw), ast_get_switch_registrar(sw));
06538    }
06539 
06540    /* walk thru ignorepats ... */
06541    for (ip = NULL; (ip = ast_walk_context_ignorepats(old, ip)); ) {
06542       if (strcmp(ast_get_ignorepat_registrar(ip), registrar) == 0)
06543          continue; /* not mine */
06544       ast_context_add_ignorepat2(new, ast_get_ignorepat_name(ip), ast_get_ignorepat_registrar(ip));
06545    }
06546 }

static void create_match_char_tree ( struct ast_context *  con  )  [static]

Definition at line 2000 of file pbx.c.

References add_exten_to_pattern_tree(), ast_hashtab_end_traversal(), ast_hashtab_get_stats(), ast_hashtab_next(), ast_hashtab_start_traversal(), ast_log(), ast_exten::exten, LOG_DEBUG, LOG_ERROR, ast_context::name, and ast_context::root_table.

Referenced by pbx_find_extension().

02001 {
02002    struct ast_hashtab_iter *t1;
02003    struct ast_exten *e1;
02004 #ifdef NEED_DEBUG
02005    int biggest_bucket, resizes, numobjs, numbucks;
02006 
02007    ast_log(LOG_DEBUG,"Creating Extension Trie for context %s\n", con->name);
02008    ast_hashtab_get_stats(con->root_table, &biggest_bucket, &resizes, &numobjs, &numbucks);
02009    ast_log(LOG_DEBUG,"This tree has %d objects in %d bucket lists, longest list=%d objects, and has resized %d times\n",
02010          numobjs, numbucks, biggest_bucket, resizes);
02011 #endif
02012    t1 = ast_hashtab_start_traversal(con->root_table);
02013    while ((e1 = ast_hashtab_next(t1))) {
02014       if (e1->exten) {
02015          add_exten_to_pattern_tree(con, e1, 0);
02016       } else {
02017          ast_log(LOG_ERROR, "Attempt to create extension with no extension name.\n");
02018       }
02019    }
02020    ast_hashtab_end_traversal(t1);
02021 }

static void decrease_call_count ( void   )  [static]

Definition at line 4529 of file pbx.c.

References ast_mutex_lock(), ast_mutex_unlock(), countcalls, and maxcalllock.

Referenced by ast_pbx_run_args(), ast_pbx_start(), and pbx_thread().

04530 {
04531    ast_mutex_lock(&maxcalllock);
04532    if (countcalls > 0)
04533       countcalls--;
04534    ast_mutex_unlock(&maxcalllock);
04535 }

static void destroy_exten ( struct ast_exten *  e  )  [static]

static void destroy_pattern_tree ( struct match_char *  pattern_tree  )  [static]

Definition at line 2023 of file pbx.c.

References match_char::alt_char, match_char::exten, free, match_char::next_char, and match_char::x.

Referenced by __ast_internal_context_destroy().

02024 {
02025    /* destroy all the alternates */
02026    if (pattern_tree->alt_char) {
02027       destroy_pattern_tree(pattern_tree->alt_char);
02028       pattern_tree->alt_char = 0;
02029    }
02030    /* destroy all the nexts */
02031    if (pattern_tree->next_char) {
02032       destroy_pattern_tree(pattern_tree->next_char);
02033       pattern_tree->next_char = 0;
02034    }
02035    pattern_tree->exten = 0; /* never hurts to make sure there's no pointers laying around */
02036    if (pattern_tree->x) {
02037       free(pattern_tree->x);
02038    }
02039    free(pattern_tree);
02040 }

static void device_state_cb ( const struct ast_event *  event,
void *  unused 
) [static]

Definition at line 9295 of file pbx.c.

References ast_calloc, ast_event_get_ie_str(), AST_EVENT_IE_DEVICE, ast_free, ast_log(), ast_strlen_zero(), ast_taskprocessor_push(), statechange::dev, handle_statechange(), and LOG_ERROR.

Referenced by load_pbx().

09296 {
09297    const char *device;
09298    struct statechange *sc;
09299 
09300    device = ast_event_get_ie_str(event, AST_EVENT_IE_DEVICE);
09301    if (ast_strlen_zero(device)) {
09302       ast_log(LOG_ERROR, "Received invalid event that had no device IE\n");
09303       return;
09304    }
09305 
09306    if (!(sc = ast_calloc(1, sizeof(*sc) + strlen(device) + 1)))
09307       return;
09308    strcpy(sc->dev, device);
09309    if (ast_taskprocessor_push(device_state_tps, handle_statechange, sc) < 0) {
09310       ast_free(sc);
09311    }
09312 }

static void exception_store_free ( void *  data  )  [static]

Definition at line 2983 of file pbx.c.

References ast_free, and ast_string_field_free_memory.

02984 {
02985    struct pbx_exception *exception = data;
02986    ast_string_field_free_memory(exception);
02987    ast_free(exception);
02988 }

static int ext_cmp ( const char *  a,
const char *  b 
) [static]

the full routine to compare extensions in rules.

Definition at line 2176 of file pbx.c.

References ext_cmp1().

Referenced by ast_add_extension2_lockopt(), and ast_extension_cmp().

02177 {
02178    /* make sure non-patterns come first.
02179     * If a is not a pattern, it either comes first or
02180     * we do a more complex pattern comparison.
02181     */
02182    int ret = 0;
02183 
02184    if (a[0] != '_')
02185       return (b[0] == '_') ? -1 : strcmp(a, b);
02186 
02187    /* Now we know a is a pattern; if b is not, a comes first */
02188    if (b[0] != '_')
02189       return 1;
02190 
02191    /* ok we need full pattern sorting routine.
02192     * skip past the underscores */
02193    ++a; ++b;
02194    do {
02195       unsigned char bitwise[2][32] = { { 0, } };
02196       ret = ext_cmp1(&a, bitwise[0]) - ext_cmp1(&b, bitwise[1]);
02197       if (ret == 0) {
02198          /* Are the classes different, even though they score the same? */
02199          ret = memcmp(bitwise[0], bitwise[1], 32);
02200       }
02201    } while (!ret && a && b);
02202    if (ret == 0) {
02203       return 0;
02204    } else {
02205       return (ret > 0) ? 1 : -1;
02206    }
02207 }

static int ext_cmp1 ( const char **  p,
unsigned char *  bitwise 
) [static]

helper functions to sort extensions and patterns in the desired way, so that more specific patterns appear first.

ext_cmp1 compares individual characters (or sets of), returning an int where bits 0-7 are the ASCII code of the first char in the set, while bit 8-15 are the cardinality of the set minus 1. This way more specific patterns (smaller cardinality) appear first. Wildcards have a special value, so that we can directly compare them to sets by subtracting the two values. In particular: 0x000xx one character, xx 0x0yyxx yy character set starting with xx 0x10000 '.' (one or more of anything) 0x20000 '!' (zero or more of anything) 0x30000 NUL (end of string) 0x40000 error in set. The pointer to the string is advanced according to needs. NOTES: 1. the empty set is equivalent to NUL. 2. given that a full set has always 0 as the first element, we could encode the special cases as 0xffXX where XX is 1, 2, 3, 4 as used above.

Note:
If two patterns score the same, the one with the lowest ascii values will compare as coming first.

Definition at line 2096 of file pbx.c.

References ast_log(), and LOG_WARNING.

Referenced by ext_cmp().

02097 {
02098    int c, cmin = 0xff, count = 0;
02099    const char *end;
02100 
02101    /* load value and advance pointer */
02102    c = *(*p)++;
02103 
02104    /* always return unless we have a set of chars */
02105    switch (toupper(c)) {
02106    default: /* ordinary character */
02107       bitwise[c / 8] = 1 << (c % 8);
02108       return 0x0100 | (c & 0xff);
02109 
02110    case 'N':   /* 2..9 */
02111       bitwise[6] = 0xfc;
02112       bitwise[7] = 0x03;
02113       return 0x0800 | '2';
02114 
02115    case 'X':   /* 0..9 */
02116       bitwise[6] = 0xff;
02117       bitwise[7] = 0x03;
02118       return 0x0A00 | '0';
02119 
02120    case 'Z':   /* 1..9 */
02121       bitwise[6] = 0xfe;
02122       bitwise[7] = 0x03;
02123       return 0x0900 | '1';
02124 
02125    case '.':   /* wildcard */
02126       return 0x10000;
02127 
02128    case '!':   /* earlymatch */
02129       return 0x20000;   /* less specific than NULL */
02130 
02131    case '\0':  /* empty string */
02132       *p = NULL;
02133       return 0x30000;
02134 
02135    case '[':   /* pattern */
02136       break;
02137    }
02138    /* locate end of set */
02139    end = strchr(*p, ']');
02140 
02141    if (end == NULL) {
02142       ast_log(LOG_WARNING, "Wrong usage of [] in the extension\n");
02143       return 0x40000;   /* XXX make this entry go last... */
02144    }
02145 
02146    for (; *p < end  ; (*p)++) {
02147       unsigned char c1, c2;   /* first-last char in range */
02148       c1 = (unsigned char)((*p)[0]);
02149       if (*p + 2 < end && (*p)[1] == '-') { /* this is a range */
02150          c2 = (unsigned char)((*p)[2]);
02151          *p += 2;    /* skip a total of 3 chars */
02152       } else {        /* individual character */
02153          c2 = c1;
02154       }
02155       if (c1 < cmin) {
02156          cmin = c1;
02157       }
02158       for (; c1 <= c2; c1++) {
02159          unsigned char mask = 1 << (c1 % 8);
02160          /*!\note If two patterns score the same, the one with the lowest
02161           * ascii values will compare as coming first. */
02162          /* Flag the character as included (used) and count it. */
02163          if (!(bitwise[ c1 / 8 ] & mask)) {
02164             bitwise[ c1 / 8 ] |= mask;
02165             count += 0x100;
02166          }
02167       }
02168    }
02169    (*p)++;
02170    return count == 0 ? 0x30000 : (count | cmin);
02171 }

static int ext_strncpy ( char *  dst,
const char *  src,
int  len 
) [static]

copy a string skipping whitespace

Definition at line 7423 of file pbx.c.

Referenced by ast_add_extension2_lockopt().

07424 {
07425    int count = 0;
07426    int insquares = 0;
07427 
07428    while (*src && (count < len - 1)) {
07429       if (*src == '[') {
07430          insquares = 1;
07431       } else if (*src == ']') {
07432          insquares = 0;
07433       } else if (*src == ' ' && !insquares) {
07434          src++;
07435          continue;
07436       }
07437       *dst = *src;
07438       dst++;
07439       src++;
07440       count++;
07441    }
07442    *dst = '\0';
07443 
07444    return count;
07445 }

static int extension_match_core ( const char *  pattern,
const char *  data,
enum ext_match_t  mode 
) [static]

Definition at line 2389 of file pbx.c.

References _extension_match_core(), ast_add_profile(), and ast_mark().

Referenced by ast_extension_close(), ast_extension_match(), and pbx_find_extension().

02390 {
02391    int i;
02392    static int prof_id = -2;   /* marker for 'unallocated' id */
02393    if (prof_id == -2) {
02394       prof_id = ast_add_profile("ext_match", 0);
02395    }
02396    ast_mark(prof_id, 1);
02397    i = _extension_match_core(pattern, data, mode);
02398    ast_mark(prof_id, 0);
02399    return i;
02400 }

static struct ast_context* find_context ( const char *  context  )  [static, read]

lookup for a context with a given name,

Return values:
found context or NULL if not found.

Definition at line 4653 of file pbx.c.

References ast_copy_string(), ast_hashtab_lookup(), contexts_table, and fake_context::name.

04654 {
04655    struct ast_context *c = NULL;
04656    struct fake_context item;
04657 
04658    ast_copy_string(item.name, context, sizeof(item.name));
04659 
04660    c = ast_hashtab_lookup(contexts_table,&item);
04661 
04662    return c;
04663 }

static struct ast_context* find_context_locked ( const char *  context  )  [static, read]

lookup for a context with a given name,

Return values:
with conlock held if found.
NULL if not found.

Definition at line 4670 of file pbx.c.

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

Referenced by ast_add_extension(), ast_context_add_ignorepat(), ast_context_add_include(), ast_context_add_switch(), ast_context_remove_extension_callerid(), ast_context_remove_ignorepat(), ast_context_remove_include(), and ast_context_remove_switch().

04671 {
04672    struct ast_context *c = NULL;
04673    struct fake_context item;
04674 
04675    ast_copy_string(item.name, context, sizeof(item.name));
04676 
04677    ast_rdlock_contexts();
04678    c = ast_hashtab_lookup(contexts_table,&item);
04679 
04680 #ifdef NOTNOW
04681 
04682    while ( (c = ast_walk_contexts(c)) ) {
04683       if (!strcmp(ast_get_context_name(c), context))
04684          return c;
04685    }
04686 #endif
04687    if (!c)
04688       ast_unlock_contexts();
04689 
04690    return c;
04691 }

static char* func_args ( char *  function  )  [static]

return a pointer to the arguments of the function, and terminates the function name with '\0'

Definition at line 3338 of file pbx.c.

References ast_log(), and LOG_WARNING.

Referenced by ast_func_read(), and ast_func_write().

03339 {
03340    char *args = strchr(function, '(');
03341 
03342    if (!args) {
03343       ast_log(LOG_WARNING, "Function '%s' doesn't contain parentheses.  Assuming null argument.\n", function);
03344    } else {
03345       char *p;
03346       *args++ = '\0';
03347       if ((p = strrchr(args, ')'))) {
03348          *p = '\0';
03349       } else {
03350          ast_log(LOG_WARNING, "Can't find trailing parenthesis for function '%s(%s'?\n", function, args);
03351       }
03352    }
03353    return args;
03354 }

static struct ast_exten * get_canmatch_exten ( struct match_char *  node  )  [static, read]

Definition at line 1552 of file pbx.c.

References ast_log(), ast_exten::exten, match_char::exten, LOG_NOTICE, match_char::next_char, and match_char::x.

01553 {
01554    /* find the exten at the end of the rope */
01555    struct match_char *node2 = node;
01556 
01557    for (node2 = node; node2; node2 = node2->next_char) {
01558       if (node2->exten) {
01559 #ifdef NEED_DEBUG_HERE
01560          ast_log(LOG_NOTICE,"CanMatch_exten returns exten %s(%p)\n", node2->exten->exten, node2->exten);
01561 #endif
01562          return node2->exten;
01563       }
01564    }
01565 #ifdef NEED_DEBUG_HERE
01566    ast_log(LOG_NOTICE,"CanMatch_exten returns NULL, match_char=%s\n", node->x);
01567 #endif
01568    return 0;
01569 }

static unsigned get_range ( char *  src,
int  max,
char *const   names[],
const char *  msg 
) [static]

helper function to return a range up to max (7, 12, 31 respectively). names, if supplied, is an array of names that should be mapped to numbers.

Definition at line 6819 of file pbx.c.

References ast_log(), ast_strlen_zero(), LOG_WARNING, lookup_name(), and strsep().

Referenced by ast_build_timing().

06820 {
06821    int start, end; /* start and ending position */
06822    unsigned int mask = 0;
06823    char *part;
06824 
06825    /* Check for whole range */
06826    if (ast_strlen_zero(src) || !strcmp(src, "*")) {
06827       return (1 << max) - 1;
06828    }
06829 
06830    while ((part = strsep(&src, "&"))) {
06831       /* Get start and ending position */
06832       char *endpart = strchr(part, '-');
06833       if (endpart) {
06834          *endpart++ = '\0';
06835       }
06836       /* Find the start */
06837       if ((start = lookup_name(part, names, max)) < 0) {
06838          ast_log(LOG_WARNING, "Invalid %s '%s', skipping element\n", msg, part);
06839          continue;
06840       }
06841       if (endpart) { /* find end of range */
06842          if ((end = lookup_name(endpart, names, max)) < 0) {
06843             ast_log(LOG_WARNING, "Invalid end %s '%s', skipping element\n", msg, endpart);
06844             continue;
06845          }
06846       } else {
06847          end = start;
06848       }
06849       /* Fill the mask. Remember that ranges are cyclic */
06850       mask |= (1 << end);   /* initialize with last element */
06851       while (start != end) {
06852          mask |= (1 << start);
06853          if (++start >= max) {
06854             start = 0;
06855          }
06856       }
06857    }
06858    return mask;
06859 }

static void get_timerange ( struct ast_timing *  i,
char *  times 
) [static]

store a bitmask of valid times, one bit each 1 minute

Definition at line 6862 of file pbx.c.

References ast_log(), ast_strlen_zero(), LOG_WARNING, ast_timing::minmask, and strsep().

Referenced by ast_build_timing().

06863 {
06864    char *endpart, *part;
06865    int x;
06866    int st_h, st_m;
06867    int endh, endm;
06868    int minute_start, minute_end;
06869 
06870    /* start disabling all times, fill the fields with 0's, as they may contain garbage */
06871    memset(i->minmask, 0, sizeof(i->minmask));
06872 
06873    /* 1-minute per bit */
06874    /* Star is all times */
06875    if (ast_strlen_zero(times) || !strcmp(times, "*")) {
06876       /* 48, because each hour takes 2 integers; 30 bits each */
06877       for (x = 0; x < 48; x++) {
06878          i->minmask[x] = 0x3fffffff; /* 30 bits */
06879       }
06880       return;
06881    }
06882    /* Otherwise expect a range */
06883    while ((part = strsep(&times, "&"))) {
06884       if (!(endpart = strchr(part, '-'))) {
06885          if (sscanf(part, "%2d:%2d", &st_h, &st_m) != 2 || st_h < 0 || st_h > 23 || st_m < 0 || st_m > 59) {
06886             ast_log(LOG_WARNING, "%s isn't a valid time.\n", part);
06887             continue;
06888          }
06889          i->minmask[st_h * 2 + (st_m >= 30 ? 1 : 0)] |= (1 << (st_m % 30));
06890          continue;
06891       }
06892       *endpart++ = '\0';
06893       /* why skip non digits? Mostly to skip spaces */
06894       while (*endpart && !isdigit(*endpart)) {
06895          endpart++;
06896       }
06897       if (!*endpart) {
06898          ast_log(LOG_WARNING, "Invalid time range starting with '%s-'.\n", part);
06899          continue;
06900       }
06901       if (sscanf(part, "%2d:%2d", &st_h, &st_m) != 2 || st_h < 0 || st_h > 23 || st_m < 0 || st_m > 59) {
06902          ast_log(LOG_WARNING, "'%s' isn't a valid start time.\n", part);
06903          continue;
06904       }
06905       if (sscanf(endpart, "%2d:%2d", &endh, &endm) != 2 || endh < 0 || endh > 23 || endm < 0 || endm > 59) {
06906          ast_log(LOG_WARNING, "'%s' isn't a valid end time.\n", endpart);
06907          continue;
06908       }
06909       minute_start = st_h * 60 + st_m;
06910       minute_end = endh * 60 + endm;
06911       /* Go through the time and enable each appropriate bit */
06912       for (x = minute_start; x != minute_end; x = (x + 1) % (24 * 60)) {
06913          i->minmask[x / 30] |= (1 << (x % 30));
06914       }
06915       /* Do the last one */
06916       i->minmask[x / 30] |= (1 << (x % 30));
06917    }
06918    /* All done */
06919    return;
06920 }

static char* handle_debug_dialplan ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Send ack once.

Definition at line 5904 of file pbx.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_PBX_MAX_STACK, ast_strdupa, ast_strlen_zero(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_show_dialplan_context(), dialplan_counters::context_existence, ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, show_debug_helper(), strsep(), dialplan_counters::total_context, ast_cli_entry::usage, and ast_cli_args::word.

05905 {
05906    char *exten = NULL, *context = NULL;
05907    /* Variables used for different counters */
05908    struct dialplan_counters counters;
05909    const char *incstack[AST_PBX_MAX_STACK];
05910 
05911    switch (cmd) {
05912    case CLI_INIT:
05913       e->command = "dialplan debug";
05914       e->usage =
05915          "Usage: dialplan debug [context]\n"
05916          "       Show dialplan context Trie(s). Usually only useful to folks debugging the deep internals of the fast pattern matcher\n";
05917       return NULL;
05918    case CLI_GENERATE:
05919       return complete_show_dialplan_context(a->line, a->word, a->pos, a->n);
05920    }
05921 
05922    memset(&counters, 0, sizeof(counters));
05923 
05924    if (a->argc != 2 && a->argc != 3)
05925       return CLI_SHOWUSAGE;
05926 
05927    /* we obtain [exten@]context? if yes, split them ... */
05928    /* note: we ignore the exten totally here .... */
05929    if (a->argc == 3) {
05930       if (strchr(a->argv[2], '@')) {   /* split into exten & context */
05931          context = ast_strdupa(a->argv[2]);
05932          exten = strsep(&context, "@");
05933          /* change empty strings to NULL */
05934          if (ast_strlen_zero(exten))
05935             exten = NULL;
05936       } else { /* no '@' char, only context given */
05937          context = a->argv[2];
05938       }
05939       if (ast_strlen_zero(context))
05940          context = NULL;
05941    }
05942    /* else Show complete dial plan, context and exten are NULL */
05943    show_debug_helper(a->fd, context, exten, &counters, NULL, 0, incstack);
05944 
05945    /* check for input failure and throw some error messages */
05946    if (context && !counters.context_existence) {
05947       ast_cli(a->fd, "There is no existence of '%s' context\n", context);
05948       return CLI_FAILURE;
05949    }
05950 
05951 
05952    ast_cli(a->fd,"-= %d %s. =-\n",
05953          counters.total_context, counters.total_context == 1 ? "context" : "contexts");
05954 
05955    /* everything ok */
05956    return CLI_SUCCESS;
05957 }

static char* handle_set_chanvar ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 6281 of file pbx.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_channel_unlock, ast_cli(), ast_complete_channels(), ast_get_channel_by_name_locked(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, pbx_builtin_setvar_helper(), ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.

06282 {
06283    struct ast_channel *chan;
06284    const char *chan_name, *var_name, *var_value;
06285 
06286    switch (cmd) {
06287    case CLI_INIT:
06288       e->command = "dialplan set chanvar";
06289       e->usage =
06290          "Usage: dialplan set chanvar <channel> <varname> <value>\n"
06291          "       Set channel variable <varname> to <value>\n";
06292       return NULL;
06293    case CLI_GENERATE:
06294       return ast_complete_channels(a->line, a->word, a->pos, a->n, 3);
06295    }
06296 
06297    if (a->argc != e->args + 3)
06298       return CLI_SHOWUSAGE;
06299 
06300    chan_name = a->argv[e->args];
06301    var_name = a->argv[e->args + 1];
06302    var_value = a->argv[e->args + 2];
06303 
06304    if (!(chan = ast_get_channel_by_name_locked(chan_name))) {
06305       ast_cli(a->fd, "Channel '%s' not found\n", chan_name);
06306       return CLI_FAILURE;
06307    }
06308 
06309    pbx_builtin_setvar_helper(chan, var_name, var_value);
06310    ast_channel_unlock(chan);
06311    ast_cli(a->fd, "\n    -- Channel variable '%s' set to '%s' for '%s'\n",  var_name, var_value, chan_name);
06312 
06313    return CLI_SUCCESS;
06314 }

static char* handle_set_extenpatternmatchnew ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 6316 of file pbx.c.

References ast_cli_args::argc, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, pbx_set_extenpatternmatchnew(), and ast_cli_entry::usage.

06317 {
06318    int oldval = 0;
06319 
06320    switch (cmd) {
06321    case CLI_INIT:
06322       e->command = "dialplan set extenpatternmatchnew true";
06323       e->usage =
06324          "Usage: dialplan set extenpatternmatchnew true|false\n"
06325          "       Use the NEW extension pattern matching algorithm, true or false.\n";
06326       return NULL;
06327    case CLI_GENERATE:
06328       return NULL;
06329    }
06330 
06331    if (a->argc != 4)
06332       return CLI_SHOWUSAGE;
06333 
06334    oldval =  pbx_set_extenpatternmatchnew(1);
06335 
06336    if (oldval)
06337       ast_cli(a->fd, "\n    -- Still using the NEW pattern match algorithm for extension names in the dialplan.\n");
06338    else
06339       ast_cli(a->fd, "\n    -- Switched to using the NEW pattern match algorithm for extension names in the dialplan.\n");
06340 
06341    return CLI_SUCCESS;
06342 }

static char* handle_set_global ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 6259 of file pbx.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, pbx_builtin_setvar_helper(), and ast_cli_entry::usage.

06260 {
06261    switch (cmd) {
06262    case CLI_INIT:
06263       e->command = "dialplan set global";
06264       e->usage =
06265          "Usage: dialplan set global <name> <value>\n"
06266          "       Set global dialplan variable <name> to <value>\n";
06267       return NULL;
06268    case CLI_GENERATE:
06269       return NULL;
06270    }
06271 
06272    if (a->argc != e->args + 2)
06273       return CLI_SHOWUSAGE;
06274 
06275    pbx_builtin_setvar_helper(NULL, a->argv[3], a->argv[4]);
06276    ast_cli(a->fd, "\n    -- Global variable '%s' set to '%s'\n", a->argv[3], a->argv[4]);
06277 
06278    return CLI_SUCCESS;
06279 }

static char* handle_show_application ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 5273 of file pbx.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, ast_cli_args::n, ast_app::name, print_app_docs(), ast_cli_entry::usage, and ast_cli_args::word.

05274 {
05275    struct ast_app *aa;
05276    int app, no_registered_app = 1;
05277    char *ret = NULL;
05278    int which = 0;
05279    int wordlen;
05280 
05281    switch (cmd) {
05282    case CLI_INIT:
05283       e->command = "core show application";
05284       e->usage =
05285          "Usage: core show application <application> [<application> [<application> [...]]]\n"
05286          "       Describes a particular application.\n";
05287       return NULL;
05288    case CLI_GENERATE:
05289       /*
05290        * There is a possibility to show informations about more than one
05291        * application at one time. You can type 'show application Dial Echo' and
05292        * you will see informations about these two applications ...
05293        */
05294       wordlen = strlen(a->word);
05295       /* return the n-th [partial] matching entry */
05296       AST_RWLIST_RDLOCK(&apps);
05297       AST_RWLIST_TRAVERSE(&apps, aa, list) {
05298          if (!strncasecmp(a->word, aa->name, wordlen) && ++which > a->n) {
05299             ret = ast_strdup(aa->name);
05300             break;
05301          }
05302       }
05303       AST_RWLIST_UNLOCK(&apps);
05304 
05305       return ret;
05306    }
05307 
05308    if (a->argc < 4) {
05309       return CLI_SHOWUSAGE;
05310    }
05311 
05312    AST_RWLIST_RDLOCK(&apps);
05313    AST_RWLIST_TRAVERSE(&apps, aa, list) {
05314       /* Check for each app that was supplied as an argument */
05315       for (app = 3; app < a->argc; app++) {
05316          if (strcasecmp(aa->name, a->argv[app])) {
05317             continue;
05318          }
05319 
05320          /* We found it! */
05321          no_registered_app = 0;
05322 
05323          print_app_docs(aa, a->fd);
05324       }
05325    }
05326    AST_RWLIST_UNLOCK(&apps);
05327 
05328    /* we found at least one app? no? */
05329    if (no_registered_app) {
05330       ast_cli(a->fd, "Your application(s) is (are) not registered\n");
05331       return CLI_FAILURE;
05332    }
05333 
05334    return CLI_SUCCESS;
05335 }

static char* handle_show_applications ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 5493 of file pbx.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_cli_complete(), AST_RWLIST_EMPTY, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_app::description, ast_cli_args::fd, ast_cli_args::n, ast_app::name, ast_cli_args::pos, strcasestr(), ast_app::synopsis, ast_cli_entry::usage, and ast_cli_args::word.

05494 {
05495    struct ast_app *aa;
05496    int like = 0, describing = 0;
05497    int total_match = 0;    /* Number of matches in like clause */
05498    int total_apps = 0;     /* Number of apps registered */
05499    static char* choices[] = { "like", "describing", NULL };
05500 
05501    switch (cmd) {
05502    case CLI_INIT:
05503       e->command = "core show applications [like|describing]";
05504       e->usage =
05505          "Usage: core show applications [{like|describing} <text>]\n"
05506          "       List applications which are currently available.\n"
05507          "       If 'like', <text> will be a substring of the app name\n"
05508          "       If 'describing', <text> will be a substring of the description\n";
05509       return NULL;
05510    case CLI_GENERATE:
05511       return (a->pos != 3) ? NULL : ast_cli_complete(a->word, choices, a->n);
05512    }
05513 
05514    AST_RWLIST_RDLOCK(&apps);
05515 
05516    if (AST_RWLIST_EMPTY(&apps)) {
05517       ast_cli(a->fd, "There are no registered applications\n");
05518       AST_RWLIST_UNLOCK(&apps);
05519       return CLI_SUCCESS;
05520    }
05521 
05522    /* core list applications like <keyword> */
05523    if ((a->argc == 5) && (!strcmp(a->argv[3], "like"))) {
05524       like = 1;
05525    } else if ((a->argc > 4) && (!strcmp(a->argv[3], "describing"))) {
05526       describing = 1;
05527    }
05528 
05529    /* core list applications describing <keyword1> [<keyword2>] [...] */
05530    if ((!like) && (!describing)) {
05531       ast_cli(a->fd, "    -= Registered Asterisk Applications =-\n");
05532    } else {
05533       ast_cli(a->fd, "    -= Matching Asterisk Applications =-\n");
05534    }
05535 
05536    AST_RWLIST_TRAVERSE(&apps, aa, list) {
05537       int printapp = 0;
05538       total_apps++;
05539       if (like) {
05540          if (strcasestr(aa->name, a->argv[4])) {
05541             printapp = 1;
05542             total_match++;
05543          }
05544       } else if (describing) {
05545          if (aa->description) {
05546             /* Match all words on command line */
05547             int i;
05548             printapp = 1;
05549             for (i = 4; i < a->argc; i++) {
05550                if (!strcasestr(aa->description, a->argv[i])) {
05551                   printapp = 0;
05552                } else {
05553                   total_match++;
05554                }
05555             }
05556          }
05557       } else {
05558          printapp = 1;
05559       }
05560 
05561       if (printapp) {
05562          ast_cli(a->fd,"  %20s: %s\n", aa->name, aa->synopsis ? aa->synopsis : "<Synopsis not available>");
05563       }
05564    }
05565    if ((!like) && (!describing)) {
05566       ast_cli(a->fd, "    -= %d Applications Registered =-\n",total_apps);
05567    } else {
05568       ast_cli(a->fd, "    -= %d Applications Matching =-\n",total_match);
05569    }
05570 
05571    AST_RWLIST_UNLOCK(&apps);
05572 
05573    return CLI_SUCCESS;
05574 }

static char* handle_show_chanvar ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

CLI support for listing chanvar's variables in a parseable way.

Definition at line 6227 of file pbx.c.

References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_channel_unlock, ast_cli(), ast_complete_channels(), ast_get_channel_by_name_locked(), ast_str_alloca, ast_str_buffer(), ast_str_strlen(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, pbx_builtin_serialize_variables(), ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.

06228 {
06229    struct ast_channel *chan = NULL;
06230    struct ast_str *vars = ast_str_alloca(BUFSIZ * 4); /* XXX large because we might have lots of channel vars */
06231 
06232    switch (cmd) {
06233    case CLI_INIT:
06234       e->command = "dialplan show chanvar";
06235       e->usage =
06236          "Usage: dialplan show chanvar <channel>\n"
06237          "       List current channel variables and their values\n";
06238       return NULL;
06239    case CLI_GENERATE:
06240       return ast_complete_channels(a->line, a->word, a->pos, a->n, 3);
06241    }
06242 
06243    if (a->argc != e->args + 1)
06244       return CLI_SHOWUSAGE;
06245 
06246    if (!(chan = ast_get_channel_by_name_locked(a->argv[e->args]))) {
06247       ast_cli(a->fd, "Channel '%s' not found\n", a->argv[e->args]);
06248       return CLI_FAILURE;
06249    }
06250 
06251    pbx_builtin_serialize_variables(chan, &vars);
06252    if (ast_str_strlen(vars)) {
06253       ast_cli(a->fd, "\nVariables for channel %s:\n%s\n", a->argv[e->args], ast_str_buffer(vars));
06254    }
06255    ast_channel_unlock(chan);
06256    return CLI_SUCCESS;
06257 }

static char* handle_show_dialplan ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 5837 of file pbx.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_PBX_MAX_STACK, ast_strdupa, ast_strlen_zero(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_show_dialplan_context(), dialplan_counters::context_existence, dialplan_counters::extension_existence, ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, show_dialplan_helper(), strsep(), dialplan_counters::total_context, dialplan_counters::total_exten, dialplan_counters::total_prio, ast_cli_entry::usage, and ast_cli_args::word.

05838 {
05839    char *exten = NULL, *context = NULL;
05840    /* Variables used for different counters */
05841    struct dialplan_counters counters;
05842    const char *incstack[AST_PBX_MAX_STACK];
05843 
05844    switch (cmd) {
05845    case CLI_INIT:
05846       e->command = "dialplan show";
05847       e->usage =
05848          "Usage: dialplan show [[exten@]context]\n"
05849          "       Show dialplan\n";
05850       return NULL;
05851    case CLI_GENERATE:
05852       return complete_show_dialplan_context(a->line, a->word, a->pos, a->n);
05853    }
05854 
05855    memset(&counters, 0, sizeof(counters));
05856 
05857    if (a->argc != 2 && a->argc != 3)
05858       return CLI_SHOWUSAGE;
05859 
05860    /* we obtain [exten@]context? if yes, split them ... */
05861    if (a->argc == 3) {
05862       if (strchr(a->argv[2], '@')) {   /* split into exten & context */
05863          context = ast_strdupa(a->argv[2]);
05864          exten = strsep(&context, "@");
05865          /* change empty strings to NULL */
05866          if (ast_strlen_zero(exten))
05867             exten = NULL;
05868       } else { /* no '@' char, only context given */
05869          context = a->argv[2];
05870       }
05871       if (ast_strlen_zero(context))
05872          context = NULL;
05873    }
05874    /* else Show complete dial plan, context and exten are NULL */
05875    show_dialplan_helper(a->fd, context, exten, &counters, NULL, 0, incstack);
05876 
05877    /* check for input failure and throw some error messages */
05878    if (context && !counters.context_existence) {
05879       ast_cli(a->fd, "There is no existence of '%s' context\n", context);
05880       return CLI_FAILURE;
05881    }
05882 
05883    if (exten && !counters.extension_existence) {
05884       if (context)
05885          ast_cli(a->fd, "There is no existence of %s@%s extension\n",
05886             exten, context);
05887       else
05888          ast_cli(a->fd,
05889             "There is no existence of '%s' extension in all contexts\n",
05890             exten);
05891       return CLI_FAILURE;
05892    }
05893 
05894    ast_cli(a->fd,"-= %d %s (%d %s) in %d %s. =-\n",
05895             counters.total_exten, counters.total_exten == 1 ? "extension" : "extensions",
05896             counters.total_prio, counters.total_prio == 1 ? "priority" : "priorities",
05897             counters.total_context, counters.total_context == 1 ? "context" : "contexts");
05898 
05899    /* everything ok */
05900    return CLI_SUCCESS;
05901 }

static char* handle_show_function ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 3095 of file pbx.c.

References ast_custom_function::acflist, ast_cli_args::argc, ast_custom_function::arguments, ast_cli_args::argv, ast_cli(), ast_custom_function_find(), ast_free, ast_malloc, AST_MAX_APP, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_strdup, AST_TERM_MAX_ESCAPE_CHARS, AST_XML_DOC, ast_xmldoc_printable(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, COLOR_CYAN, COLOR_MAGENTA, ast_cli_entry::command, ast_custom_function::desc, description, ast_custom_function::docsrc, ast_cli_args::fd, ast_cli_args::n, ast_custom_function::name, S_OR, ast_custom_function::seealso, ast_custom_function::synopsis, synopsis, ast_custom_function::syntax, term_color(), ast_cli_entry::usage, and ast_cli_args::word.

03096 {
03097    struct ast_custom_function *acf;
03098    /* Maximum number of characters added by terminal coloring is 22 */
03099    char infotitle[64 + AST_MAX_APP + 22], syntitle[40], destitle[40], argtitle[40], seealsotitle[40];
03100    char info[64 + AST_MAX_APP], *synopsis = NULL, *description = NULL, *seealso = NULL;
03101    char stxtitle[40], *syntax = NULL, *arguments = NULL;
03102    int syntax_size, description_size, synopsis_size, arguments_size, seealso_size;
03103    char *ret = NULL;
03104    int which = 0;
03105    int wordlen;
03106 
03107    switch (cmd) {
03108    case CLI_INIT:
03109       e->command = "core show function";
03110       e->usage =
03111          "Usage: core show function <function>\n"
03112          "       Describe a particular dialplan function.\n";
03113       return NULL;
03114    case CLI_GENERATE:
03115       wordlen = strlen(a->word);
03116       /* case-insensitive for convenience in this 'complete' function */
03117       AST_RWLIST_RDLOCK(&acf_root);
03118       AST_RWLIST_TRAVERSE(&acf_root, acf, acflist) {
03119          if (!strncasecmp(a->word, acf->name, wordlen) && ++which > a->n) {
03120             ret = ast_strdup(acf->name);
03121             break;
03122          }
03123       }
03124       AST_RWLIST_UNLOCK(&acf_root);
03125 
03126       return ret;
03127    }
03128 
03129    if (a->argc < 4) {
03130       return CLI_SHOWUSAGE;
03131    }
03132 
03133    if (!(acf = ast_custom_function_find(a->argv[3]))) {
03134       ast_cli(a->fd, "No function by that name registered.\n");
03135       return CLI_FAILURE;
03136    }
03137 
03138    syntax_size = strlen(S_OR(acf->syntax, "Not Available")) + AST_TERM_MAX_ESCAPE_CHARS;
03139    if (!(syntax = ast_malloc(syntax_size))) {
03140       ast_cli(a->fd, "Memory allocation failure!\n");
03141       return CLI_FAILURE;
03142    }
03143 
03144    snprintf(info, sizeof(info), "\n  -= Info about function '%s' =- \n\n", acf->name);
03145    term_color(infotitle, info, COLOR_MAGENTA, 0, sizeof(infotitle));
03146    term_color(syntitle, "[Synopsis]\n", COLOR_MAGENTA, 0, 40);
03147    term_color(destitle, "[Description]\n", COLOR_MAGENTA, 0, 40);
03148    term_color(stxtitle, "[Syntax]\n", COLOR_MAGENTA, 0, 40);
03149    term_color(argtitle, "[Arguments]\n", COLOR_MAGENTA, 0, 40);
03150    term_color(seealsotitle, "[See Also]\n", COLOR_MAGENTA, 0, 40);
03151    term_color(syntax, S_OR(acf->syntax, "Not available"), COLOR_CYAN, 0, syntax_size);
03152 #ifdef AST_XML_DOCS
03153    if (acf->docsrc == AST_XML_DOC) {
03154       arguments = ast_xmldoc_printable(S_OR(acf->arguments, "Not available"), 1);
03155       synopsis = ast_xmldoc_printable(S_OR(acf->synopsis, "Not available"), 1);
03156       description = ast_xmldoc_printable(S_OR(acf->desc, "Not available"), 1);
03157       seealso = ast_xmldoc_printable(S_OR(acf->seealso, "Not available"), 1);
03158    } else
03159 #endif
03160    {
03161       synopsis_size = strlen(S_OR(acf->synopsis, "Not Available")) + AST_TERM_MAX_ESCAPE_CHARS;
03162       synopsis = ast_malloc(synopsis_size);
03163 
03164       description_size = strlen(S_OR(acf->desc, "Not Available")) + AST_TERM_MAX_ESCAPE_CHARS;
03165       description = ast_malloc(description_size);
03166 
03167       arguments_size = strlen(S_OR(acf->arguments, "Not Available")) + AST_TERM_MAX_ESCAPE_CHARS;
03168       arguments = ast_malloc(arguments_size);
03169 
03170       seealso_size = strlen(S_OR(acf->seealso, "Not Available")) + AST_TERM_MAX_ESCAPE_CHARS;
03171       seealso = ast_malloc(seealso_size);
03172 
03173       /* check allocated memory. */
03174       if (!synopsis || !description || !arguments || !seealso) {
03175          ast_free(synopsis);
03176          ast_free(description);
03177          ast_free(arguments);
03178          ast_free(seealso);
03179          ast_free(syntax);
03180          return CLI_FAILURE;
03181       }
03182 
03183       term_color(arguments, S_OR(acf->arguments, "Not available"), COLOR_CYAN, 0, arguments_size);
03184       term_color(synopsis, S_OR(acf->synopsis, "Not available"), COLOR_CYAN, 0, synopsis_size);
03185       term_color(description, S_OR(acf->desc, "Not available"), COLOR_CYAN, 0, description_size);
03186       term_color(seealso, S_OR(acf->seealso, "Not available"), COLOR_CYAN, 0, seealso_size);
03187    }
03188 
03189    ast_cli(a->fd, "%s%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n",
03190          infotitle, syntitle, synopsis, destitle, description,
03191          stxtitle, syntax, argtitle, arguments, seealsotitle, seealso);
03192 
03193    ast_free(arguments);
03194    ast_free(synopsis);
03195    ast_free(description);
03196    ast_free(seealso);
03197    ast_free(syntax);
03198 
03199    return CLI_SUCCESS;
03200 }

static char* handle_show_functions ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 3053 of file pbx.c.

References ast_custom_function::acflist, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, ast_custom_function::name, S_OR, ast_custom_function::synopsis, ast_custom_function::syntax, and ast_cli_entry::usage.

03054 {
03055    struct ast_custom_function *acf;
03056    int count_acf = 0;
03057    int like = 0;
03058 
03059    switch (cmd) {
03060    case CLI_INIT:
03061       e->command = "core show functions [like]";
03062       e->usage =
03063          "Usage: core show functions [like <text>]\n"
03064          "       List builtin functions, optionally only those matching a given string\n";
03065       return NULL;
03066    case CLI_GENERATE:
03067       return NULL;
03068    }
03069 
03070    if (a->argc == 5 && (!strcmp(a->argv[3], "like")) ) {
03071       like = 1;
03072    } else if (a->argc != 3) {
03073       return CLI_SHOWUSAGE;
03074    }
03075 
03076    ast_cli(a->fd, "%s Custom Functions:\n--------------------------------------------------------------------------------\n", like ? "Matching" : "Installed");
03077 
03078    AST_RWLIST_RDLOCK(&acf_root);
03079    AST_RWLIST_TRAVERSE(&acf_root, acf, acflist) {
03080       if (!like || strstr(acf->name, a->argv[4])) {
03081          count_acf++;
03082          ast_cli(a->fd, "%-20.20s  %-35.35s  %s\n",
03083             S_OR(acf->name, ""),
03084             S_OR(acf->syntax, ""),
03085             S_OR(acf->synopsis, ""));
03086       }
03087    }
03088    AST_RWLIST_UNLOCK(&acf_root);
03089 
03090    ast_cli(a->fd, "%d %scustom functions installed.\n", count_acf, like ? "matching " : "");
03091 
03092    return CLI_SUCCESS;
03093 }

static char* handle_show_globals ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

CLI support for listing global variables in a parseable way.

Definition at line 6169 of file pbx.c.

References ast_cli(), AST_LIST_TRAVERSE, ast_rwlock_rdlock(), ast_rwlock_unlock(), ast_var_name(), ast_var_value(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_var_t::entries, ast_cli_args::fd, globals, globalslock, and ast_cli_entry::usage.

06170 {
06171    int i = 0;
06172    struct ast_var_t *newvariable;
06173 
06174    switch (cmd) {
06175    case CLI_INIT:
06176       e->command = "dialplan show globals";
06177       e->usage =
06178          "Usage: dialplan show globals\n"
06179          "       List current global dialplan variables and their values\n";
06180       return NULL;
06181    case CLI_GENERATE:
06182       return NULL;
06183    }
06184 
06185    ast_rwlock_rdlock(&globalslock);
06186    AST_LIST_TRAVERSE (&globals, newvariable, entries) {
06187       i++;
06188       ast_cli(a->fd, "   %s=%s\n", ast_var_name(newvariable), ast_var_value(newvariable));
06189    }
06190    ast_rwlock_unlock(&globalslock);
06191    ast_cli(a->fd, "\n    -- %d variable(s)\n", i);
06192 
06193    return CLI_SUCCESS;
06194 }

static char* handle_show_hint ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

handle_show_hint: CLI support for listing registered dial plan hint

Definition at line 5409 of file pbx.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_extension_state2str(), ast_get_context_name(), ast_get_extension_app(), ast_get_extension_context(), ast_get_extension_name(), AST_LIST_TRAVERSE, AST_RWLIST_EMPTY, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_hint::callbacks, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_core_show_hint(), ast_hint::exten, ast_cli_args::fd, ast_hint::laststate, ast_cli_args::line, ast_cli_args::n, num, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.

05410 {
05411    struct ast_hint *hint;
05412    int watchers;
05413    int num = 0, extenlen;
05414    struct ast_state_cb *watcher;
05415 
05416    switch (cmd) {
05417    case CLI_INIT:
05418       e->command = "core show hint";
05419       e->usage =
05420          "Usage: core show hint <exten>\n"
05421          "       List registered hint\n";
05422       return NULL;
05423    case CLI_GENERATE:
05424       return complete_core_show_hint(a->line, a->word, a->pos, a->n);
05425    }
05426 
05427    if (a->argc < 4)
05428       return CLI_SHOWUSAGE;
05429 
05430    AST_RWLIST_RDLOCK(&hints);
05431    if (AST_RWLIST_EMPTY(&hints)) {
05432       ast_cli(a->fd, "There are no registered dialplan hints\n");
05433       AST_RWLIST_UNLOCK(&hints);
05434       return CLI_SUCCESS;
05435    }
05436    extenlen = strlen(a->argv[3]);
05437    AST_RWLIST_TRAVERSE(&hints, hint, list) {
05438       if (!strncasecmp(ast_get_extension_name(hint->exten), a->argv[3], extenlen)) {
05439          watchers = 0;
05440          AST_LIST_TRAVERSE(&hint->callbacks, watcher, entry) {
05441             watchers++;
05442          }
05443          ast_cli(a->fd, "   %20s@%-20.20s: %-20.20s  State:%-15.15s Watchers %2d\n",
05444             ast_get_extension_name(hint->exten),
05445             ast_get_context_name(ast_get_extension_context(hint->exten)),
05446             ast_get_extension_app(hint->exten),
05447             ast_extension_state2str(hint->laststate), watchers);
05448          num++;
05449       }
05450    }
05451    AST_RWLIST_UNLOCK(&hints);
05452    if (!num)
05453       ast_cli(a->fd, "No hints matching extension %s\n", a->argv[3]);
05454    else
05455       ast_cli(a->fd, "%d hint%s matching extension %s\n", num, (num!=1 ? "s":""), a->argv[3]);
05456    return CLI_SUCCESS;
05457 }

static char* handle_show_hints ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

handle_show_hints: CLI support for listing registered dial plan hints

Definition at line 5338 of file pbx.c.

References ast_cli(), ast_extension_state2str(), ast_get_context_name(), ast_get_extension_app(), ast_get_extension_context(), ast_get_extension_name(), AST_LIST_TRAVERSE, AST_RWLIST_EMPTY, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_hint::callbacks, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_hint::exten, ast_cli_args::fd, ast_hint::laststate, num, and ast_cli_entry::usage.

05339 {
05340    struct ast_hint *hint;
05341    int num = 0;
05342    int watchers;
05343    struct ast_state_cb *watcher;
05344 
05345    switch (cmd) {
05346    case CLI_INIT:
05347       e->command = "core show hints";
05348       e->usage =
05349          "Usage: core show hints\n"
05350          "       List registered hints\n";
05351       return NULL;
05352    case CLI_GENERATE:
05353       return NULL;
05354    }
05355 
05356    AST_RWLIST_RDLOCK(&hints);
05357    if (AST_RWLIST_EMPTY(&hints)) {
05358       ast_cli(a->fd, "There are no registered dialplan hints\n");
05359       AST_RWLIST_UNLOCK(&hints);
05360       return CLI_SUCCESS;
05361    }
05362    /* ... we have hints ... */
05363    ast_cli(a->fd, "\n    -= Registered Asterisk Dial Plan Hints =-\n");
05364    AST_RWLIST_TRAVERSE(&hints, hint, list) {
05365       watchers = 0;
05366       AST_LIST_TRAVERSE(&hint->callbacks, watcher, entry) {
05367          watchers++;
05368       }
05369       ast_cli(a->fd, "   %20s@%-20.20s: %-20.20s  State:%-15.15s Watchers %2d\n",
05370          ast_get_extension_name(hint->exten),
05371          ast_get_context_name(ast_get_extension_context(hint->exten)),
05372          ast_get_extension_app(hint->exten),
05373          ast_extension_state2str(hint->laststate), watchers);
05374       num++;
05375    }
05376    ast_cli(a->fd, "----------------\n");
05377    ast_cli(a->fd, "- %d hints registered\n", num);
05378    AST_RWLIST_UNLOCK(&hints);
05379    return CLI_SUCCESS;
05380 }

static char* handle_show_switches ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

handle_show_switches: CLI support for listing registered dial plan switches

Definition at line 5461 of file pbx.c.

References ast_cli(), AST_RWLIST_EMPTY, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_switch::description, ast_cli_args::fd, ast_switch::name, and ast_cli_entry::usage.

05462 {
05463    struct ast_switch *sw;
05464 
05465    switch (cmd) {
05466    case CLI_INIT:
05467       e->command = "core show switches";
05468       e->usage =
05469          "Usage: core show switches\n"
05470          "       List registered switches\n";
05471       return NULL;
05472    case CLI_GENERATE:
05473       return NULL;
05474    }
05475 
05476    AST_RWLIST_RDLOCK(&switches);
05477 
05478    if (AST_RWLIST_EMPTY(&switches)) {
05479       AST_RWLIST_UNLOCK(&switches);
05480       ast_cli(a->fd, "There are no registered alternative switches\n");
05481       return CLI_SUCCESS;
05482    }
05483 
05484    ast_cli(a->fd, "\n    -= Registered Asterisk Alternative Switches =-\n");
05485    AST_RWLIST_TRAVERSE(&switches, sw, list)
05486       ast_cli(a->fd, "%s: %s\n", sw->name, sw->description);
05487 
05488    AST_RWLIST_UNLOCK(&switches);
05489 
05490    return CLI_SUCCESS;
05491 }

static int handle_statechange ( void *  datap  )  [static]

Definition at line 3855 of file pbx.c.

References ast_copy_string(), ast_extension_state2(), ast_free, ast_get_extension_app(), AST_LIST_TRAVERSE, AST_MAX_EXTENSION, ast_rdlock_contexts(), AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_unlock_contexts(), buf, ast_state_cb::callback, ast_hint::callbacks, ast_state_cb::data, statechange::dev, ast_exten::exten, ast_hint::exten, ast_hint::laststate, ast_context::name, ast_exten::parent, parse(), and strsep().

Referenced by device_state_cb().

03856 {
03857    struct ast_hint *hint;
03858    struct statechange *sc = datap;
03859 
03860    ast_rdlock_contexts();
03861    AST_RWLIST_RDLOCK(&hints);
03862 
03863    AST_RWLIST_TRAVERSE(&hints, hint, list) {
03864       struct ast_state_cb *cblist;
03865       char buf[AST_MAX_EXTENSION];
03866       char *parse = buf;
03867       char *cur;
03868       int state;
03869 
03870       ast_copy_string(buf, ast_get_extension_app(hint->exten), sizeof(buf));
03871       while ( (cur = strsep(&parse, "&")) ) {
03872          if (!strcasecmp(cur, sc->dev)) {
03873             break;
03874          }
03875       }
03876       if (!cur) {
03877          continue;
03878       }
03879 
03880       /* Get device state for this hint */
03881       state = ast_extension_state2(hint->exten);
03882 
03883       if ((state == -1) || (state == hint->laststate)) {
03884          continue;
03885       }
03886 
03887       /* Device state changed since last check - notify the watchers */
03888 
03889       /* For general callbacks */
03890       AST_LIST_TRAVERSE(&statecbs, cblist, entry) {
03891          cblist->callback(hint->exten->parent->name, hint->exten->exten, state, cblist->data);
03892       }
03893 
03894       /* For extension callbacks */
03895       AST_LIST_TRAVERSE(&hint->callbacks, cblist, entry) {
03896          cblist->callback(hint->exten->parent->name, hint->exten->exten, state, cblist->data);
03897       }
03898 
03899       hint->laststate = state;   /* record we saw the change */
03900    }
03901    AST_RWLIST_UNLOCK(&hints);
03902    ast_unlock_contexts();
03903    ast_free(sc);
03904    return 0;
03905 }

static char* handle_unset_extenpatternmatchnew ( struct ast_cli_entry *  e,
int  cmd,
struct ast_cli_args *  a 
) [static]

Definition at line 6344 of file pbx.c.

References ast_cli_args::argc, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, pbx_set_extenpatternmatchnew(), and ast_cli_entry::usage.

06345 {
06346    int oldval = 0;
06347 
06348    switch (cmd) {
06349    case CLI_INIT:
06350       e->command = "dialplan set extenpatternmatchnew false";
06351       e->usage =
06352          "Usage: dialplan set extenpatternmatchnew true|false\n"
06353          "       Use the NEW extension pattern matching algorithm, true or false.\n";
06354       return NULL;
06355    case CLI_GENERATE:
06356       return NULL;
06357    }
06358 
06359    if (a->argc != 4)
06360       return CLI_SHOWUSAGE;
06361 
06362    oldval =  pbx_set_extenpatternmatchnew(0);
06363 
06364    if (!oldval)
06365       ast_cli(a->fd, "\n    -- Still using the OLD pattern match algorithm for extension names in the dialplan.\n");
06366    else
06367       ast_cli(a->fd, "\n    -- Switched to using the OLD pattern match algorithm for extension names in the dialplan.\n");
06368 
06369    return CLI_SUCCESS;
06370 }

static int hashtab_compare_exten_labels ( const void *  ah_a,
const void *  ah_b 
) [static]

Definition at line 1030 of file pbx.c.

References ast_exten::label, and S_OR.

Referenced by ast_add_extension2_lockopt().

01031 {
01032    const struct ast_exten *ac = ah_a;
01033    const struct ast_exten *bc = ah_b;
01034    return strcmp(S_OR(ac->label, ""), S_OR(bc->label, ""));
01035 }

static int hashtab_compare_exten_numbers ( const void *  ah_a,
const void *  ah_b 
) [static]

Definition at line 1023 of file pbx.c.

References ast_exten::priority.

Referenced by ast_add_extension2_lockopt().

01024 {
01025    const struct ast_exten *ac = ah_a;
01026    const struct ast_exten *bc = ah_b;
01027    return ac->priority != bc->priority;
01028 }

static int hashtab_compare_extens ( const void *  ha_a,
const void *  ah_b 
) [static]

Definition at line 1004 of file pbx.c.

References ast_exten::cidmatch, ast_exten::exten, and ast_exten::matchcid.

Referenced by ast_add_extension2_lockopt().

01005 {
01006    const struct ast_exten *ac = ah_a;
01007    const struct ast_exten *bc = ah_b;
01008    int x = strcmp(ac->exten, bc->exten);
01009    if (x) { /* if exten names are diff, then return */
01010       return x;
01011    }
01012 
01013    /* but if they are the same, do the cidmatch values match? */
01014    if (ac->matchcid && bc->matchcid) {
01015       return strcmp(ac->cidmatch,bc->cidmatch);
01016    } else if (!ac->matchcid && !bc->matchcid) {
01017       return 0; /* if there's no matchcid on either side, then this is a match */
01018    } else {
01019       return 1; /* if there's matchcid on one but not the other, they are different */
01020    }
01021 }

static unsigned int hashtab_hash_extens ( const void *  obj  )  [static]

Definition at line 1043 of file pbx.c.

References ast_hashtab_hash_string(), ast_exten::cidmatch, ast_exten::exten, and ast_exten::matchcid.

Referenced by ast_add_extension2_lockopt().

01044 {
01045    const struct ast_exten *ac = obj;
01046    unsigned int x = ast_hashtab_hash_string(ac->exten);
01047    unsigned int y = 0;
01048    if (ac->matchcid)
01049       y = ast_hashtab_hash_string(ac->cidmatch);
01050    return x+y;
01051 }

static unsigned int hashtab_hash_labels ( const void *  obj  )  [static]

Definition at line 1059 of file pbx.c.

References ast_hashtab_hash_string(), ast_exten::label, and S_OR.

Referenced by ast_add_extension2_lockopt().

01060 {
01061    const struct ast_exten *ac = obj;
01062    return ast_hashtab_hash_string(S_OR(ac->label, ""));
01063 }

static unsigned int hashtab_hash_priority ( const void *  obj  )  [static]

Definition at line 1053 of file pbx.c.

References ast_hashtab_hash_int(), and ast_exten::priority.

Referenced by ast_add_extension2_lockopt().

01054 {
01055    const struct ast_exten *ac = obj;
01056    return ast_hashtab_hash_int(ac->priority);
01057 }

static int include_valid ( struct ast_include *  i  )  [inline, static]

Definition at line 1391 of file pbx.c.

References ast_check_timing(), ast_include::hastime, and ast_include::timing.

Referenced by pbx_find_extension().

01392 {
01393    if (!i->hastime)
01394       return 1;
01395 
01396    return ast_check_timing(&(i->timing));
01397 }

static int increase_call_count ( const struct ast_channel *  c  )  [static]

Increase call count for channel.

Return values:
0 on success
non-zero if a configured limit (maxcalls, maxload, minmemfree) was reached

Definition at line 4482 of file pbx.c.

References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), countcalls, getloadavg(), LOG_WARNING, maxcalllock, ast_channel::name, option_maxcalls, option_maxload, option_minmemfree, and totalcalls.

Referenced by ast_pbx_run_args(), and ast_pbx_start().

04483 {
04484    int failed = 0;
04485    double curloadavg;
04486 #if defined(HAVE_SYSINFO)
04487    long curfreemem;
04488    struct sysinfo sys_info;
04489 #endif
04490 
04491    ast_mutex_lock(&maxcalllock);
04492    if (option_maxcalls) {
04493       if (countcalls >= option_maxcalls) {
04494          ast_log(LOG_WARNING, "Maximum call limit of %d calls exceeded by '%s'!\n", option_maxcalls, c->name);
04495          failed = -1;
04496       }
04497    }
04498    if (option_maxload) {
04499       getloadavg(&curloadavg, 1);
04500       if (curloadavg >= option_maxload) {
04501          ast_log(LOG_WARNING, "Maximum loadavg limit of %f load exceeded by '%s' (currently %f)!\n", option_maxload, c->name, curloadavg);
04502          failed = -1;
04503       }
04504    }
04505 #if defined(HAVE_SYSINFO)
04506    if (option_minmemfree) {
04507       if (!sysinfo(&sys_info)) {
04508          /* make sure that the free system memory is above the configured low watermark
04509           * convert the amount of freeram from mem_units to MB */
04510          curfreemem = sys_info.freeram / sys_info.mem_unit;
04511          curfreemem /= 1024 * 1024;
04512          if (curfreemem < option_minmemfree) {
04513             ast_log(LOG_WARNING, "Available system memory (~%ldMB) is below the configured low watermark (%ldMB)\n", curfreemem, option_minmemfree);
04514             failed = -1;
04515          }
04516       }
04517    }
04518 #endif
04519 
04520    if (!failed) {
04521       countcalls++;
04522       totalcalls++;
04523    }
04524    ast_mutex_unlock(&maxcalllock);
04525 
04526    return failed;
04527 }

static void insert_in_next_chars_alt_char_list ( struct match_char **  parent_ptr,
struct match_char *  node 
) [static]

Definition at line 1799 of file pbx.c.

References match_char::alt_char, and match_char::specificity.

Referenced by add_pattern_node().

01800 {
01801    struct match_char *curr, *lcurr;
01802 
01803    /* insert node into the tree at "current", so the alt_char list from current is
01804       sorted in increasing value as you go to the leaves */
01805    if (!(*parent_ptr)) {
01806       *parent_ptr = node;
01807    } else {
01808       if ((*parent_ptr)->specificity > node->specificity) {
01809          /* insert at head */
01810          node->alt_char = (*parent_ptr);
01811          *parent_ptr = node;
01812       } else {
01813          lcurr = *parent_ptr;
01814          for (curr = (*parent_ptr)->alt_char; curr; curr = curr->alt_char) {
01815             if (curr->specificity > node->specificity) {
01816                node->alt_char = curr;
01817                lcurr->alt_char = node;
01818                break;
01819             }
01820             lcurr = curr;
01821          }
01822          if (!curr) {
01823             lcurr->alt_char = node;
01824          }
01825       }
01826    }
01827 }

int load_pbx ( void   ) 

Provided by pbx.c

Definition at line 9314 of file pbx.c.

References __ast_custom_function_register(), ARRAY_LEN, ast_cli_register_multiple(), AST_EVENT_DEVICE_STATE, AST_EVENT_IE_END, ast_event_subscribe(), ast_log(), ast_manager_register2(), ast_register_application2(), ast_taskprocessor_get(), ast_verb, builtins, device_state_cb(), device_state_sub, EVENT_FLAG_CONFIG, EVENT_FLAG_REPORTING, exception_function, LOG_ERROR, LOG_WARNING, manager_show_dialplan(), mandescr_show_dialplan, and pbx_cli.

Referenced by main().

09315 {
09316    int x;
09317 
09318    /* Initialize the PBX */
09319    ast_verb(1, "Asterisk PBX Core Initializing\n");
09320    if (!(device_state_tps = ast_taskprocessor_get("pbx-core", 0))) {
09321       ast_log(LOG_WARNING, "failed to create pbx-core taskprocessor\n");
09322    }
09323 
09324    ast_verb(1, "Registering builtin applications:\n");
09325    ast_cli_register_multiple(pbx_cli, ARRAY_LEN(pbx_cli));
09326    __ast_custom_function_register(&exception_function, NULL);
09327 
09328    /* Register builtin applications */
09329    for (x = 0; x < ARRAY_LEN(builtins); x++) {
09330       ast_verb(1, "[%s]\n", builtins[x].name);
09331       if (ast_register_application2(builtins[x].name, builtins[x].execute, NULL, NULL, NULL)) {
09332          ast_log(LOG_ERROR, "Unable to register builtin application '%s'\n", builtins[x].name);
09333          return -1;
09334       }
09335    }
09336 
09337    /* Register manager application */
09338    ast_manager_register2("ShowDialPlan", EVENT_FLAG_CONFIG | EVENT_FLAG_REPORTING, manager_show_dialplan, "List dialplan", mandescr_show_dialplan);
09339 
09340    if (!(device_state_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE, device_state_cb, NULL,
09341          AST_EVENT_IE_END))) {
09342       return -1;
09343    }
09344 
09345    return 0;
09346 }

void log_match_char_tree ( struct match_char *  node,
char *  prefix 
)

Definition at line 1494 of file pbx.c.

References match_char::alt_char, ast_debug, ast_str_alloca, ast_str_buffer(), ast_str_set(), match_char::deleted, ast_exten::exten, match_char::exten, match_char::is_pattern, match_char::next_char, match_char::specificity, and match_char::x.

Referenced by ast_context_remove_extension_callerid2(), and pbx_find_extension().

01495 {
01496    char extenstr[40];
01497    struct ast_str *my_prefix = ast_str_alloca(1024);
01498 
01499    extenstr[0] = '\0';
01500 
01501    if (node && node->exten && node->exten)
01502       snprintf(extenstr, sizeof(extenstr), "(%p)", node->exten);
01503 
01504    if (strlen(node->x) > 1) {
01505       ast_debug(1, "%s[%s]:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y':'N',
01506          node->deleted? 'D':'-', node->specificity, node->exten? "EXTEN:":"",
01507          node->exten ? node->exten->exten : "", extenstr);
01508    } else {
01509       ast_debug(1, "%s%s:%c:%c:%d:%s%s%s\n", prefix, node->x, node->is_pattern ? 'Y':'N',
01510          node->deleted? 'D':'-', node->specificity, node->exten? "EXTEN:":"",
01511          node->exten ? node->exten->exten : "", extenstr);
01512    }
01513 
01514    ast_str_set(&my_prefix, 0, "%s+       ", prefix);
01515 
01516    if (node->next_char)
01517       log_match_char_tree(node->next_char, ast_str_buffer(my_prefix));
01518 
01519    if (node->alt_char)
01520       log_match_char_tree(node->alt_char, prefix);
01521 }

static int lookup_name ( const char *  s,
char *const   names[],
int  max 
) [static]

Helper for get_range. return the index of the matching entry, starting from 1. If names is not supplied, try numeric values.

Definition at line 6796 of file pbx.c.

Referenced by get_range().

06797 {
06798    int i;
06799 
06800    if (names && *s > '9') {
06801       for (i = 0; names[i]; i++) {
06802          if (!strcasecmp(s, names[i])) {
06803             return i;
06804          }
06805       }
06806    }
06807 
06808    /* Allow months and weekdays to be specified as numbers, as well */
06809    if (sscanf(s, "%2d", &i) == 1 && i >= 1 && i <= max) {
06810       /* What the array offset would have been: "1" would be at offset 0 */
06811       return i - 1;
06812    }
06813    return -1; /* error return */
06814 }

static void manager_dpsendack ( struct mansession *  s,
const struct message *  m 
) [static]

Send ack once.

Definition at line 5960 of file pbx.c.

References astman_send_listack().

Referenced by manager_show_dialplan_helper().

05961 {
05962    astman_send_listack(s, m, "DialPlan list will follow", "start");
05963 }

static int manager_show_dialplan ( struct mansession *  s,
const struct message *  m 
) [static]

Manager listing of dial plan.

Definition at line 6106 of file pbx.c.

References ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_error(), dialplan_counters::context_existence, dialplan_counters::extension_existence, manager_show_dialplan_helper(), dialplan_counters::total_context, dialplan_counters::total_exten, dialplan_counters::total_items, and dialplan_counters::total_prio.

Referenced by load_pbx().

06107 {
06108    const char *exten, *context;
06109    const char *id = astman_get_header(m, "ActionID");
06110    char idtext[256];
06111    int res;
06112 
06113    /* Variables used for different counters */
06114    struct dialplan_counters counters;
06115 
06116    if (!ast_strlen_zero(id))
06117       snprintf(idtext, sizeof(idtext), "ActionID: %s\r\n", id);
06118    else
06119       idtext[0] = '\0';
06120 
06121    memset(&counters, 0, sizeof(counters));
06122 
06123    exten = astman_get_header(m, "Extension");
06124    context = astman_get_header(m, "Context");
06125 
06126    res = manager_show_dialplan_helper(s, m, idtext, context, exten, &counters, NULL);
06127 
06128    if (context && !counters.context_existence) {
06129       char errorbuf[BUFSIZ];
06130 
06131       snprintf(errorbuf, sizeof(errorbuf), "Did not find context %s", context);
06132       astman_send_error(s, m, errorbuf);
06133       return 0;
06134    }
06135    if (exten && !counters.extension_existence) {
06136       char errorbuf[BUFSIZ];
06137 
06138       if (context)
06139          snprintf(errorbuf, sizeof(errorbuf), "Did not find extension %s@%s", exten, context);
06140       else
06141          snprintf(errorbuf, sizeof(errorbuf), "Did not find extension %s in any context", exten);
06142       astman_send_error(s, m, errorbuf);
06143       return 0;
06144    }
06145 
06146    astman_append(s, "Event: ShowDialPlanComplete\r\n"
06147       "EventList: Complete\r\n"
06148       "ListItems: %d\r\n"
06149       "ListExtensions: %d\r\n"
06150       "ListPriorities: %d\r\n"
06151       "ListContexts: %d\r\n"
06152       "%s"
06153       "\r\n", counters.total_items, counters.total_exten, counters.total_prio, counters.total_context, idtext);
06154 
06155    /* everything ok */
06156    return 0;
06157 }

static int manager_show_dialplan_helper ( struct mansession *  s,
const struct message *  m,
const char *  actionidtext,
const char *  context,
const char *  exten,
struct dialplan_counters *  dpc,
struct ast_include *  rinclude 
) [static]

Show dialplan extensions XXX this function is similar but not exactly the same as the CLI's show dialplan. Must check whether the difference is intentional or not.

Definition at line 5969 of file pbx.c.

References ast_debug, ast_extension_match(), ast_get_context_name(), ast_get_extension_app(), ast_get_extension_app_data(), ast_get_extension_label(), ast_get_extension_name(), ast_get_extension_priority(), ast_get_extension_registrar(), ast_get_ignorepat_name(), ast_get_ignorepat_registrar(), ast_get_include_name(), ast_get_include_registrar(), ast_get_switch_data(), ast_get_switch_name(), ast_get_switch_registrar(), ast_log(), AST_MAX_EXTENSION, ast_rdlock_context(), ast_rdlock_contexts(), ast_strlen_zero(), ast_unlock_context(), ast_unlock_contexts(), ast_walk_context_extensions(), ast_walk_context_ignorepats(), ast_walk_context_includes(), ast_walk_context_switches(), ast_walk_contexts(), ast_walk_extension_priorities(), astman_append(), astman_send_error(), dialplan_counters::context_existence, dialplan_counters::extension_existence, LOG_WARNING, manager_dpsendack(), PRIORITY_HINT, dialplan_counters::total_context, dialplan_counters::total_exten, dialplan_counters::total_items, and dialplan_counters::total_prio.

Referenced by manager_show_dialplan().

05973 {
05974    struct ast_context *c;
05975    int res = 0, old_total_exten = dpc->total_exten;
05976 
05977    if (ast_strlen_zero(exten))
05978       exten = NULL;
05979    if (ast_strlen_zero(context))
05980       context = NULL;
05981 
05982    ast_debug(3, "manager_show_dialplan: Context: -%s- Extension: -%s-\n", context, exten);
05983 
05984    /* try to lock contexts */
05985    if (ast_rdlock_contexts()) {
05986       astman_send_error(s, m, "Failed to lock contexts");
05987       ast_log(LOG_WARNING, "Failed to lock contexts list for manager: listdialplan\n");
05988       return -1;
05989    }
05990 
05991    c = NULL;      /* walk all contexts ... */
05992    while ( (c = ast_walk_contexts(c)) ) {
05993       struct ast_exten *e;
05994       struct ast_include *i;
05995       struct ast_ignorepat *ip;
05996 
05997       if (context && strcmp(ast_get_context_name(c), context) != 0)
05998          continue;   /* not the name we want */
05999 
06000       dpc->context_existence = 1;
06001 
06002       ast_debug(3, "manager_show_dialplan: Found Context: %s \n", ast_get_context_name(c));
06003 
06004       if (ast_rdlock_context(c)) {  /* failed to lock */
06005          ast_debug(3, "manager_show_dialplan: Failed to lock context\n");
06006          continue;
06007       }
06008 
06009       /* XXX note- an empty context is not printed */
06010       e = NULL;      /* walk extensions in context  */
06011       while ( (e = ast_walk_context_extensions(c, e)) ) {
06012          struct ast_exten *p;
06013 
06014          /* looking for extension? is this our extension? */
06015          if (exten && !ast_extension_match(ast_get_extension_name(e), exten)) {
06016             /* not the one we are looking for, continue */
06017             ast_debug(3, "manager_show_dialplan: Skipping extension %s\n", ast_get_extension_name(e));
06018             continue;
06019          }
06020          ast_debug(3, "manager_show_dialplan: Found Extension: %s \n", ast_get_extension_name(e));
06021 
06022          dpc->extension_existence = 1;
06023 
06024          /* may we print context info? */
06025          dpc->total_context++;
06026          dpc->total_exten++;
06027 
06028          p = NULL;      /* walk next extension peers */
06029          while ( (p = ast_walk_extension_priorities(e, p)) ) {
06030             int prio = ast_get_extension_priority(p);
06031 
06032             dpc->total_prio++;
06033             if (!dpc->total_items++)
06034                manager_dpsendack(s, m);
06035             astman_append(s, "Event: ListDialplan\r\n%s", actionidtext);
06036             astman_append(s, "Context: %s\r\nExtension: %s\r\n", ast_get_context_name(c), ast_get_extension_name(e) );
06037 
06038             /* XXX maybe make this conditional, if p != e ? */
06039             if (ast_get_extension_label(p))
06040                astman_append(s, "ExtensionLabel: %s\r\n", ast_get_extension_label(p));
06041 
06042             if (prio == PRIORITY_HINT) {
06043                astman_append(s, "Priority: hint\r\nApplication: %s\r\n", ast_get_extension_app(p));
06044             } else {
06045                astman_append(s, "Priority: %d\r\nApplication: %s\r\nAppData: %s\r\n", prio, ast_get_extension_app(p), (char *) ast_get_extension_app_data(p));
06046             }
06047             astman_append(s, "Registrar: %s\r\n\r\n", ast_get_extension_registrar(e));
06048          }
06049       }
06050 
06051       i = NULL;      /* walk included and write info ... */
06052       while ( (i = ast_walk_context_includes(c, i)) ) {
06053          if (exten) {
06054             /* Check all includes for the requested extension */
06055             manager_show_dialplan_helper(s, m, actionidtext, ast_get_include_name(i), exten, dpc, i);
06056          } else {
06057             if (!dpc->total_items++)
06058                manager_dpsendack(s, m);
06059             astman_append(s, "Event: ListDialplan\r\n%s", actionidtext);
06060             astman_append(s, "Context: %s\r\nIncludeContext: %s\r\nRegistrar: %s\r\n", ast_get_context_name(c), ast_get_include_name(i), ast_get_include_registrar(i));
06061             astman_append(s, "\r\n");
06062             ast_debug(3, "manager_show_dialplan: Found Included context: %s \n", ast_get_include_name(i));
06063          }
06064       }
06065 
06066       ip = NULL;  /* walk ignore patterns and write info ... */
06067       while ( (ip = ast_walk_context_ignorepats(c, ip)) ) {
06068          const char *ipname = ast_get_ignorepat_name(ip);
06069          char ignorepat[AST_MAX_EXTENSION];
06070 
06071          snprintf(ignorepat, sizeof(ignorepat), "_%s.", ipname);
06072          if (!exten || ast_extension_match(ignorepat, exten)) {
06073             if (!dpc->total_items++)
06074                manager_dpsendack(s, m);
06075             astman_append(s, "Event: ListDialplan\r\n%s", actionidtext);
06076             astman_append(s, "Context: %s\r\nIgnorePattern: %s\r\nRegistrar: %s\r\n", ast_get_context_name(c), ipname, ast_get_ignorepat_registrar(ip));
06077             astman_append(s, "\r\n");
06078          }
06079       }
06080       if (!rinclude) {
06081          struct ast_sw *sw = NULL;
06082          while ( (sw = ast_walk_context_switches(c, sw)) ) {
06083             if (!dpc->total_items++)
06084                manager_dpsendack(s, m);
06085             astman_append(s, "Event: ListDialplan\r\n%s", actionidtext);
06086             astman_append(s, "Context: %s\r\nSwitch: %s/%s\r\nRegistrar: %s\r\n", ast_get_context_name(c), ast_get_switch_name(sw), ast_get_switch_data(sw), ast_get_switch_registrar(sw));  
06087             astman_append(s, "\r\n");
06088             ast_debug(3, "manager_show_dialplan: Found Switch : %s \n", ast_get_switch_name(sw));
06089          }
06090       }
06091 
06092       ast_unlock_context(c);
06093    }
06094    ast_unlock_contexts();
06095 
06096    if (dpc->total_exten == old_total_exten) {
06097       ast_debug(3, "manager_show_dialplan: Found nothing new\n");
06098       /* Nothing new under the sun */
06099       return -1;
06100    } else {
06101       return res;
06102    }
06103 }

static int matchcid ( const char *  cidpattern,
const char *  callerid 
) [static]

Definition at line 2457 of file pbx.c.

References ast_extension_match(), and ast_strlen_zero().

Referenced by pbx_find_extension().

02458 {
02459    /* If the Caller*ID pattern is empty, then we're matching NO Caller*ID, so
02460       failing to get a number should count as a match, otherwise not */
02461 
02462    if (ast_strlen_zero(callerid)) {
02463       return ast_strlen_zero(cidpattern) ? 1 : 0;
02464    }
02465 
02466    return ast_extension_match(cidpattern, callerid);
02467 }

static void new_find_extension ( const char *  str,
struct scoreboard *  score,
struct match_char *  tree,
int  length,
int  spec,
const char *  callerid,
const char *  label,
enum ext_match_t  action 
) [static]

Definition at line 1629 of file pbx.c.

References match_char::alt_char, ast_debug, ast_log(), scoreboard::canmatch, match_char::deleted, E_CANMATCH, E_MATCHMORE, ast_exten::exten, scoreboard::exten, match_char::exten, ast_exten::label, LOG_NOTICE, NEW_MATCHER_CHK_MATCH, NEW_MATCHER_RECURSE, match_char::next_char, match_char::specificity, update_scoreboard(), and match_char::x.

Referenced by pbx_find_extension().

01630 {
01631    struct match_char *p; /* note minimal stack storage requirements */
01632    struct ast_exten pattern = { .label = label };
01633 #ifdef DEBUG_THIS
01634    if (tree)
01635       ast_log(LOG_NOTICE,"new_find_extension called with %s on (sub)tree %s action=%s\n", str, tree->x, action2str(action));
01636    else
01637       ast_log(LOG_NOTICE,"new_find_extension called with %s on (sub)tree NULL action=%s\n", str, action2str(action));
01638 #endif
01639    for (p = tree; p; p = p->alt_char) {
01640       if (p->x[0] == 'N') {
01641          if (p->x[1] == 0 && *str >= '2' && *str <= '9' ) {
01642 #define NEW_MATCHER_CHK_MATCH        \
01643             if (p->exten && !(*(str + 1))) { /* if a shorter pattern matches along the way, might as well report it */           \
01644                if (action == E_MATCH || action == E_SPAWN || action == E_FINDLABEL) { /* if in CANMATCH/MATCHMORE, don't let matches get in the way */   \
01645                   update_scoreboard(score, length + 1, spec + p->specificity, p->exten, 0, callerid, p->deleted, p);           \
01646                   if (!p->deleted) {                                                                                           \
01647                      if (action == E_FINDLABEL) {                                                                             \
01648                         if (ast_hashtab_lookup(score->exten->peer_label_table, &pattern)) {                                  \
01649                            ast_debug(4, "Found label in preferred extension\n");                                            \
01650                            return;                                                                                          \
01651                         }                                                                                                    \
01652                      } else {                                                                                                 \
01653                         ast_debug(4,"returning an exact match-- first found-- %s\n", p->exten->exten);                       \
01654                         return; /* the first match, by definition, will be the best, because of the sorted tree */           \
01655                      }                                                                                                        \
01656                   }                                                                                                            \
01657                }                                                                                                                \
01658             }
01659 
01660 #define NEW_MATCHER_RECURSE              \
01661             if (p->next_char && ( *(str + 1) || (p->next_char->x[0] == '/' && p->next_char->x[1] == 0)               \
01662                                                  || p->next_char->x[0] == '!')) {                                        \
01663                if (*(str + 1) || p->next_char->x[0] == '!') {                                                       \
01664                   new_find_extension(str + 1, score, p->next_char, length + 1, spec+p->specificity, callerid, label, action); \
01665                   if (score->exten)  {                                                                             \
01666                        ast_debug(4, "returning an exact match-- %s\n", score->exten->exten);                        \
01667                      return; /* the first match is all we need */                                                 \
01668                   }                                                                                    \
01669                } else {                                                                                             \
01670                   new_find_extension("/", score, p->next_char, length + 1, spec+p->specificity, callerid, label, action);   \
01671                   if (score->exten || ((action == E_CANMATCH || action == E_MATCHMORE) && score->canmatch)) {      \
01672                        ast_debug(4,"returning a (can/more) match--- %s\n", score->exten ? score->exten->exten :     \
01673                                        "NULL");                                                                          \
01674                      return; /* the first match is all we need */                                                 \
01675                   }                                                                                    \
01676                }                                                                                                    \
01677             } else if (p->next_char && !*(str + 1)) {                                                                \
01678                score->canmatch = 1;                                                                                 \
01679                score->canmatch_exten = get_canmatch_exten(p);                                                       \
01680                if (action == E_CANMATCH || action == E_MATCHMORE) {                                                 \
01681                     ast_debug(4, "returning a canmatch/matchmore--- str=%s\n", str);                                 \
01682                   return;                                                                                          \
01683                }                                                                                        \
01684             }
01685 
01686             NEW_MATCHER_CHK_MATCH;
01687             NEW_MATCHER_RECURSE;
01688          }
01689       } else if (p->x[0] == 'Z') {
01690          if (p->x[1] == 0 && *str >= '1' && *str <= '9' ) {
01691             NEW_MATCHER_CHK_MATCH;
01692             NEW_MATCHER_RECURSE;
01693          }
01694       } else if (p->x[0] == 'X') {
01695          if (p->x[1] == 0 && *str >= '0' && *str <= '9' ) {
01696             NEW_MATCHER_CHK_MATCH;
01697             NEW_MATCHER_RECURSE;
01698          }
01699       } else if (p->x[0] == '.' && p->x[1] == 0) {
01700          /* how many chars will the . match against? */
01701          int i = 0;
01702          const char *str2 = str;
01703          while (*str2 && *str2 != '/') {
01704             str2++;
01705             i++;
01706          }
01707          if (p->exten && *str2 != '/') {
01708             update_scoreboard(score, length+i, spec+(i*p->specificity), p->exten, '.', callerid, p->deleted, p);
01709             if (score->exten) {
01710                ast_debug(4,"return because scoreboard has a match with '/'--- %s\n", score->exten->exten);
01711                return; /* the first match is all we need */
01712             }
01713          }
01714          if (p->next_char && p->next_char->x[0] == '/' && p->next_char->x[1] == 0) {
01715             new_find_extension("/", score, p->next_char, length+i, spec+(p->specificity*i), callerid, label, action);
01716             if (score->exten || ((action == E_CANMATCH || action == E_MATCHMORE) && score->canmatch)) {
01717                ast_debug(4, "return because scoreboard has exact match OR CANMATCH/MATCHMORE & canmatch set--- %s\n", score->exten ? score->exten->exten : "NULL");
01718                return; /* the first match is all we need */
01719             }
01720          }
01721       } else if (p->x[0] == '!' && p->x[1] == 0) {
01722          /* how many chars will the . match against? */
01723          int i = 1;
01724          const char *str2 = str;
01725          while (*str2 && *str2 != '/') {
01726             str2++;
01727             i++;
01728          }
01729          if (p->exten && *str2 != '/') {
01730             update_scoreboard(score, length + 1, spec+(p->specificity * i), p->exten, '!', callerid, p->deleted, p);
01731             if (score->exten) {
01732                ast_debug(4, "return because scoreboard has a '!' match--- %s\n", score->exten->exten);
01733                return; /* the first match is all we need */
01734             }
01735          }
01736          if (p->next_char && p->next_char->x[0] == '/' && p->next_char->x[1] == 0) {
01737             new_find_extension("/", score, p->next_char, length + i, spec + (p->specificity * i), callerid, label, action);
01738             if (score->exten || ((action == E_CANMATCH || action == E_MATCHMORE) && score->canmatch)) {
01739                ast_debug(4,"return because scoreboard has exact match OR CANMATCH/MATCHMORE & canmatch set with '/' and '!'--- %s\n", score->exten ? score->exten->exten : "NULL");
01740                return; /* the first match is all we need */
01741             }
01742          }
01743       } else if (p->x[0] == '/' && p->x[1] == 0) {
01744          /* the pattern in the tree includes the cid match! */
01745          if (p->next_char && callerid && *callerid) {
01746             new_find_extension(callerid, score, p->next_char, length+1, spec, callerid, label, action);
01747             if (score->exten || ((action == E_CANMATCH || action == E_MATCHMORE) && score->canmatch)) {
01748                ast_debug(4, "return because scoreboard has exact match OR CANMATCH/MATCHMORE & canmatch set with '/'--- %s\n", score->exten ? score->exten->exten : "NULL");
01749                return; /* the first match is all we need */
01750             }
01751          }
01752       } else if (strchr(p->x, *str)) {
01753          ast_debug(4, "Nothing strange about this match\n");
01754          NEW_MATCHER_CHK_MATCH;
01755          NEW_MATCHER_RECURSE;
01756       }
01757    }
01758    ast_debug(4, "return at end of func\n");
01759 }

static int parse_variable_name ( char *  var,
int *  offset,
int *  length,
int *  isfunc 
) [static]

extract offset:length from variable name.

Returns:
1 if there is a offset:length part, which is trimmed off (values go into variables)

Definition at line 2792 of file pbx.c.

Referenced by pbx_retrieve_variable(), and pbx_substitute_variables_helper_full().

02793 {
02794    int parens = 0;
02795 
02796    *offset = 0;
02797    *length = INT_MAX;
02798    *isfunc = 0;
02799    for (; *var; var++) {
02800       if (*var == '(') {
02801          (*isfunc)++;
02802          parens++;
02803       } else if (*var == ')') {
02804          parens--;
02805       } else if (*var == ':' && parens == 0) {
02806          *var++ = '\0';
02807          sscanf(var, "%30d:%30d", offset, length);
02808          return 1; /* offset:length valid */
02809       }
02810    }
02811    return 0;
02812 }

void pbx_builtin_clear_globals ( void   ) 

Definition at line 9194 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().

09195 {
09196    struct ast_var_t *vardata;
09197 
09198    ast_rwlock_wrlock(&globalslock);
09199    while ((vardata = AST_LIST_REMOVE_HEAD(&globals, entries)))
09200       ast_var_delete(vardata);
09201    ast_rwlock_unlock(&globalslock);
09202 }

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

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

Note:
Will lock the channel.

This function will return a pointer to the buffer inside the channel variable. This value should only be accessed with the channel locked. If the value needs to be kept around, it should be done by using the following thread-safe code:

      const char *var;

      ast_channel_lock(chan);
      if ((var = pbx_builtin_getvar_helper(chan, "MYVAR"))) {
         var = ast_strdupa(var);
      }
      ast_channel_unlock(chan);

Definition at line 8963 of file pbx.c.

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

Referenced by __ast_pbx_run(), _macro_exec(), _while_exec(), agent_hangup(), agent_read(), agentmonitoroutgoing_exec(), array(), ast_bridge_call(), ast_call_forward(), ast_eivr_getvariable(), ast_monitor_stop(), bridge_play_sounds(), builtin_atxfer(), builtin_automixmonitor(), builtin_automonitor(), check_goto_on_transfer(), common_exec(), conf_exec(), conf_run(), confbridge_exec(), dahdi_call(), dahdi_hangup(), dahdi_r2_answer(), dahdi_r2_get_channel_category(), dial_exec_full(), do_forward(), do_timelimit(), dundi_exec(), dundi_helper(), feature_interpret(), find_by_mark(), find_conf_realtime(), findparkinglotname(), get_also_info(), get_index(), get_refer_info(), global_read(), hash_read(), iax2_call(), iax2_exec(), import_ch(), leave_voicemail(), listfilter(), local_attended_transfer(), local_hangup(), local_read(), login_exec(), macro_fixup(), minivm_delete_exec(), minivm_notify_exec(), misdn_answer(), misdn_hangup(), morsecode_exec(), notify_new_message(), oh323_call(), oh323_hangup(), park_call_full(), park_space_reserve(), pbx_builtin_background(), queue_exec(), real_ctx(), retrydial_exec(), ring_entry(), run_agi(), set_config_flags(), set_local_info(), sip_addheader(), sla_trunk_exec(), speech_background(), try_calling(), try_suggested_sip_codec(), update_bridge_vars(), and wait_for_answer().

08964 {
08965    struct ast_var_t *variables;
08966    const char *ret = NULL;
08967    int i;
08968    struct varshead *places[2] = { NULL, &globals };
08969 
08970    if (!name)
08971       return NULL;
08972 
08973    if (chan) {
08974       ast_channel_lock(chan);
08975       places[0] = &chan->varshead;
08976    }
08977 
08978    for (i = 0; i < 2; i++) {
08979       if (!places[i])
08980          continue;
08981       if (places[i] == &globals)
08982          ast_rwlock_rdlock(&globalslock);
08983       AST_LIST_TRAVERSE(places[i], variables, entries) {
08984          if (!strcmp(name, ast_var_name(variables))) {
08985             ret = ast_var_value(variables);
08986             break;
08987          }
08988       }
08989       if (places[i] == &globals)
08990          ast_rwlock_unlock(&globalslock);
08991       if (ret)
08992          break;
08993    }
08994 
08995    if (chan)
08996       ast_channel_unlock(chan);
08997 
08998    return ret;
08999 }

static int pbx_builtin_gotoif ( struct ast_channel *  chan,
void *  data 
) [static]

Definition at line 9216 of file pbx.c.

References ast_debug, ast_log(), ast_strdupa, ast_strlen_zero(), LOG_WARNING, pbx_builtin_goto(), pbx_checkcondition(), and strsep().

09217 {
09218    char *condition, *branch1, *branch2, *branch;
09219    char *stringp;
09220 
09221    if (ast_strlen_zero(data)) {
09222       ast_log(LOG_WARNING, "Ignoring, since there is no variable to check\n");
09223       return 0;
09224    }
09225 
09226    stringp = ast_strdupa(data);
09227    condition = strsep(&stringp,"?");
09228    branch1 = strsep(&stringp,":");
09229    branch2 = strsep(&stringp,"");
09230    branch = pbx_checkcondition(condition) ? branch1 : branch2;
09231 
09232    if (ast_strlen_zero(branch)) {
09233       ast_debug(1, "Not taking any branch\n");
09234       return 0;
09235    }
09236 
09237    return pbx_builtin_goto(chan, branch);
09238 }

int pbx_builtin_importvar ( struct ast_channel *  chan,
void *  data 
) [static]

Todo:
XXX should do !ast_strlen_zero(..) of the args ?

Definition at line 9152 of file pbx.c.

References ast_channel_unlock, ast_get_channel_by_name_locked(), ast_log(), ast_strdupa, ast_strlen_zero(), LOG_WARNING, pbx_builtin_setvar_helper(), pbx_substitute_variables_helper(), s, strsep(), and VAR_BUF_SIZE.

09153 {
09154    char *name;
09155    char *value;
09156    char *channel;
09157    char tmp[VAR_BUF_SIZE];
09158    static int deprecation_warning = 0;
09159 
09160    if (ast_strlen_zero(data)) {
09161       ast_log(LOG_WARNING, "Ignoring, since there is no variable to set\n");
09162       return 0;
09163    }
09164    tmp[0] = 0;
09165    if (!deprecation_warning) {
09166       ast_log(LOG_WARNING, "ImportVar is deprecated.  Please use Set(varname=${IMPORT(channel,variable)}) instead.\n");
09167       deprecation_warning = 1;
09168    }
09169 
09170    value = ast_strdupa(data);
09171    name = strsep(&value,"=");
09172    channel = strsep(&value,",");
09173    if (channel && value && name) { /*! \todo XXX should do !ast_strlen_zero(..) of the args ? */
09174       struct ast_channel *chan2 = ast_get_channel_by_name_locked(channel);
09175       if (chan2) {
09176          char *s = alloca(strlen(value) + 4);
09177          if (s) {
09178             sprintf(s, "${%s}", value);
09179             pbx_substitute_variables_helper(chan2, s, tmp, sizeof(tmp) - 1);
09180          }
09181          ast_channel_unlock(chan2);
09182       }
09183       pbx_builtin_setvar_helper(chan, name, tmp);
09184    }
09185 
09186    return(0);
09187 }

static int pbx_builtin_incomplete ( struct ast_channel *  chan,
void *  data 
) [static]

Definition at line 8548 of file pbx.c.

References __ast_answer(), ast_channel::_state, ast_check_hangup(), AST_PBX_INCOMPLETE, AST_STATE_UP, and ast_strlen_zero().

08549 {
08550    char *options = data;
08551    int answer = 1;
08552 
08553    /* Some channels can receive DTMF in unanswered state; some cannot */
08554    if (!ast_strlen_zero(options) && strchr(options, 'n')) {
08555       answer = 0;
08556    }
08557 
08558    /* If the channel is hungup, stop waiting */
08559    if (ast_check_hangup(chan)) {
08560       return -1;
08561    } else if (chan->_state != AST_STATE_UP && answer) {
08562       __ast_answer(chan, 0, 1);
08563    }
08564 
08565    return AST_PBX_INCOMPLETE;
08566 }

static int pbx_builtin_noop ( struct ast_channel *  chan,
void *  data 
) [static]

Definition at line 9189 of file pbx.c.

09190 {
09191    return 0;
09192 }

void pbx_builtin_pushvar_helper ( struct ast_channel *  chan,
const char *  name,
const char *  value 
)

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

Note:
Will lock the channel.

Definition at line 9001 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().

09002 {
09003    struct ast_var_t *newvariable;
09004    struct varshead *headp;
09005 
09006    if (name[strlen(name)-1] == ')') {
09007       char *function = ast_strdupa(name);
09008 
09009       ast_log(LOG_WARNING, "Cannot push a value onto a function\n");
09010       ast_func_write(chan, function, value);
09011       return;
09012    }
09013 
09014    if (chan) {
09015       ast_channel_lock(chan);
09016       headp = &chan->varshead;
09017    } else {
09018       ast_rwlock_wrlock(&globalslock);
09019       headp = &globals;
09020    }
09021 
09022    if (value) {
09023       if (headp == &globals)
09024          ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
09025       newvariable = ast_var_assign(name, value);
09026       AST_LIST_INSERT_HEAD(headp, newvariable, entries);
09027    }
09028 
09029    if (chan)
09030       ast_channel_unlock(chan);
09031    else
09032       ast_rwlock_unlock(&globalslock);
09033 }

int pbx_builtin_raise_exception ( struct ast_channel *  chan,
void *  vreason 
)

Definition at line 2995 of file pbx.c.

References ast_calloc, ast_channel_datastore_add(), ast_channel_datastore_find(), ast_datastore_alloc, ast_datastore_free(), ast_free, ast_string_field_init, ast_string_field_set, ast_channel::context, ast_datastore::data, exception_store_info, ast_channel::exten, ast_channel::priority, pbx_exception::priority, and set_ext_pri().

Referenced by __ast_pbx_run().

02996 {
02997    const char *reason = vreason;
02998    struct ast_datastore *ds = ast_channel_datastore_find(chan, &exception_store_info, NULL);
02999    struct pbx_exception *exception = NULL;
03000 
03001    if (!ds) {
03002       ds = ast_datastore_alloc(&exception_store_info, NULL);
03003       if (!ds)
03004          return -1;
03005       exception = ast_calloc(1, sizeof(struct pbx_exception));
03006       if (!exception) {
03007          ast_datastore_free(ds);
03008          return -1;
03009       }
03010       if (ast_string_field_init(exception, 128)) {
03011          ast_free(exception);
03012          ast_datastore_free(ds);
03013          return -1;
03014       }
03015       ds->data = exception;
03016       ast_channel_datastore_add(chan, ds);
03017    } else
03018       exception = ds->data;
03019 
03020    ast_string_field_set(exception, reason, reason);
03021    ast_string_field_set(exception, context, chan->context);
03022    ast_string_field_set(exception, exten, chan->exten);
03023    exception->priority = chan->priority;
03024    set_ext_pri(chan, "e", 0);
03025    return 0;
03026 }

static int pbx_builtin_saycharacters ( struct ast_channel *  chan,
void *  data 
) [static]

Definition at line 9277 of file pbx.c.

References ast_say_character_str(), and ast_channel::language.

09278 {
09279    int res = 0;
09280 
09281    if (data)
09282       res = ast_say_character_str(chan, data, "", chan->language);
09283    return res;
09284 }

static int pbx_builtin_saydigits ( struct ast_channel *  chan,
void *  data 
) [static]

Definition at line 9268 of file pbx.c.

References ast_say_digit_str(), and ast_channel::language.

09269 {
09270    int res = 0;
09271 
09272    if (data)
09273       res = ast_say_digit_str(chan, data, "", chan->language);
09274    return res;
09275 }

static int pbx_builtin_saynumber ( struct ast_channel *  chan,
void *  data 
) [static]

Definition at line 9240 of file pbx.c.

References ast_copy_string(), ast_log(), ast_say_number(), ast_strlen_zero(), ast_channel::language, LOG_WARNING, and strsep().

09241 {
09242    char tmp[256];
09243    char *number = tmp;
09244    char *options;
09245 
09246    if (ast_strlen_zero(data)) {
09247       ast_log(LOG_WARNING, "SayNumber requires an argument (number)\n");
09248       return -1;
09249    }
09250    ast_copy_string(tmp, data, sizeof(tmp));
09251    strsep(&number, ",");
09252    options = strsep(&number, ",");
09253    if (options) {
09254       if ( strcasecmp(options, "f") && strcasecmp(options, "m") &&
09255          strcasecmp(options, "c") && strcasecmp(options, "n") ) {
09256          ast_log(LOG_WARNING, "SayNumber gender option is either 'f', 'm', 'c' or 'n'\n");
09257          return -1;
09258       }
09259    }
09260 
09261    if (ast_say_number(chan, atoi(tmp), "", chan->language, options)) {
09262       ast_log(LOG_WARNING, "We were unable to say the number %s, is it too large?\n", tmp);
09263    }
09264 
09265    return 0;
09266 }

static int pbx_builtin_sayphonetic ( struct ast_channel *  chan,
void *  data 
) [static]

Definition at line 9286 of file pbx.c.

References ast_say_phonetic_str(), and ast_channel::language.

09287 {
09288    int res = 0;
09289 
09290    if (data)
09291       res = ast_say_phonetic_str(chan, data, "", chan->language);
09292    return res;
09293 }

int pbx_builtin_serialize_variables ( struct ast_channel *  chan,
struct ast_str **  buf 
)

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

Parameters:
chan Channel from which to read variables
buf Dynamic string in which to place the result (should be allocated with
See also:
ast_str_create).
Note:
Will lock the channel.

Definition at line 8932 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().

08933 {
08934    struct ast_var_t *variables;
08935    const char *var, *val;
08936    int total = 0;
08937 
08938    if (!chan)
08939       return 0;
08940 
08941    ast_str_reset(*buf);
08942 
08943    ast_channel_lock(chan);
08944 
08945    AST_LIST_TRAVERSE(&chan->varshead, variables, entries) {
08946       if ((var = ast_var_name(variables)) && (val = ast_var_value(variables))
08947          /* && !ast_strlen_zero(var) && !ast_strlen_zero(val) */
08948          ) {
08949          if (ast_str_append(buf, 0, "%s=%s\n", var, val) < 0) {
08950             ast_log(LOG_ERROR, "Data Buffer Size Exceeded!\n");
08951             break;
08952          } else
08953             total++;
08954       } else
08955          break;
08956    }
08957 
08958    ast_channel_unlock(chan);
08959 
08960    return total;
08961 }

int pbx_builtin_setvar ( struct ast_channel *  chan,
void *  data 
)

void pbx_builtin_setvar_helper ( struct ast_channel *  chan,
const char *  name,
const char *  value 
)

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

Note:
Will lock the channel. May also be used to set a channel dialplan function to a particular value.
See also:
ast_func_write

Definition at line 9035 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_exec(), acf_fetch(), acf_odbc_read(), acf_odbc_write(), acf_transaction_write(), action_atxfer(), action_setvar(), admin_exec(), agi_exec_full(), aji_status_exec(), aqm_exec(), array(), ast_bridge_call(), ast_eivr_setvariable(), ast_iax2_new(), ast_monitor_start(), ast_monitor_stop(), ast_pbx_outgoing_exten(), ast_rtp_set_vars(), ast_set_variables(), asyncgoto_exec(), background_detect_exec(), bridge_exec(), bridge_play_sounds(), builtin_atxfer(), builtin_automixmonitor(), builtin_automonitor(), builtin_blindtransfer(), cb_events(), chanavail_exec(), channel_spy(), commit_exec(), conf_run(), controlplayback_exec(), count_exec(), dahdi_handle_dtmfup(), dahdi_new(), dial_exec_full(), disa_exec(), do_waiting(), end_bridge_callback(), export_aoc_vars(), export_ch(), feature_request_and_dial(), frame_set_var(), function_db_delete(), function_db_exists(), function_db_read(), function_realtime_store(), get_rdnis(), get_refer_info(), global_write(), gosub_release_frame(), handle_request_bye(), handle_request_refer(), handle_set_chanvar(), handle_set_global(), handle_setvariable(), hash_read(), hash_write(), isAnsweringMachine(), leave_voicemail(), local_hangup(), lua_set_variable(), lua_set_variable_value(), macro_fixup(), manage_parkinglot(), minivm_accmess_exec(), minivm_delete_exec(), minivm_greet_exec(), minivm_notify_exec(), minivm_record_exec(), misdn_call(), mixmonitor_exec(), originate_exec(), ospauth_exec(), ospfinished_exec(), osplookup_exec(), ospnext_exec(), park_exec_full(), parse_moved_contact(), pbx_builtin_background(), pbx_builtin_importvar(), pbx_builtin_setvar(), pbx_builtin_setvar_multiple(), pbx_load_config(), phase_e_handler(), play_message_datetime(), playback_exec(), pqm_exec(), prep_email_sub_vars(), pri_dchannel(), privacy_exec(), process_ast_dsp(), process_sdp(), read_exec(), readexten_exec(), readfile_exec(), realtimefield_read(), record_exec(), return_exec(), rollback_exec(), rotate_file(), rpt_exec(), rqm_exec(), sendimage_exec(), sendtext_exec(), sendurl_exec(), set(), set_agentbycallerid(), set_queue_result(), sip_addheader(), sip_hangup(), sip_new(), sip_read(), skinny_new(), sla_calc_trunk_timeouts(), sla_station_exec(), sla_trunk_exec(), socket_process(), speech_create(), ss7_start_call(), ss_thread(), start_monitor_exec(), system_exec_helper(), transfer_exec(), transmit(), tryexec_exec(), update_bridge_vars(), update_qe_rule(), upqm_exec(), vm_box_exists(), vm_exec(), vmauthenticate(), waituntil_exec(), and zapateller_exec().

09036 {
09037    struct ast_var_t *newvariable;
09038    struct varshead *headp;
09039    const char *nametail = name;
09040 
09041    if (name[strlen(name) - 1] == ')') {
09042       char *function = ast_strdupa(name);
09043 
09044       ast_func_write(chan, function, value);
09045       return;
09046    }
09047 
09048    if (chan) {
09049       ast_channel_lock(chan);
09050       headp = &chan->varshead;
09051    } else {
09052       ast_rwlock_wrlock(&globalslock);
09053       headp = &globals;
09054    }
09055 
09056    /* For comparison purposes, we have to strip leading underscores */
09057    if (*nametail == '_') {
09058       nametail++;
09059       if (*nametail == '_')
09060          nametail++;
09061    }
09062 
09063    AST_LIST_TRAVERSE_SAFE_BEGIN(headp, newvariable, entries) {
09064       if (strcmp(ast_var_name(newvariable), nametail) == 0) {
09065          /* there is already such a variable, delete it */
09066          AST_LIST_REMOVE_CURRENT(entries);
09067          ast_var_delete(newvariable);
09068          break;
09069       }
09070    }
09071    AST_LIST_TRAVERSE_SAFE_END;
09072 
09073    if (value) {
09074       if (headp == &globals)
09075          ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
09076       newvariable = ast_var_assign(name, value);
09077       AST_LIST_INSERT_HEAD(headp, newvariable, entries);
09078       manager_event(EVENT_FLAG_DIALPLAN, "VarSet",
09079          "Channel: %s\r\n"
09080          "Variable: %s\r\n"
09081          "Value: %s\r\n"
09082          "Uniqueid: %s\r\n",
09083          chan ? chan->name : "none", name, value,
09084          chan ? chan->uniqueid : "none");
09085    }
09086 
09087    if (chan)
09088       ast_channel_unlock(chan);
09089    else
09090       ast_rwlock_unlock(&globalslock);
09091 }

int pbx_builtin_setvar_multiple ( struct ast_channel *  chan,
void *  vdata 
)

int pbx_checkcondition ( const char *  condition  ) 

Evaluate a condition.

Return values:
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 9204 of file pbx.c.

References ast_strlen_zero().

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

09205 {
09206    int res;
09207    if (ast_strlen_zero(condition)) {                /* NULL or empty strings are false */
09208       return 0;
09209    } else if (sscanf(condition, "%30d", &res) == 1) { /* Numbers are evaluated for truth */
09210       return res;
09211    } else {                                         /* Strings are true */
09212       return 1;
09213    }
09214 }

static void pbx_destroy ( struct ast_pbx *  p  )  [static]

Definition at line 1399 of file pbx.c.

References ast_free.

Referenced by __ast_pbx_run().

01400 {
01401    ast_free(p);
01402 }

int pbx_exec ( struct ast_channel *  c,
struct ast_app *  app,
void *  data 
)

Execute an application.

Parameters:
c channel to execute on
app which app to execute
data the data passed into the app
This application executes an application on a given channel. It saves the stack and executes the given application passing in the given data.

Return values:
0 success
-1 failure
Parameters:
c Channel
app Application
data Data for execution

Definition at line 1322 of file pbx.c.

References __ast_module_user_add(), __ast_module_user_remove(), ast_channel::appl, ast_cdr_setapp(), ast_check_hangup(), ast_log(), ast_opt_dont_warn, ast_strlen_zero(), ast_channel::cdr, ast_channel::data, ast_app::execute, LOG_WARNING, ast_app::module, ast_app::name, and S_OR.

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

01325 {
01326    int res;
01327    struct ast_module_user *u = NULL;
01328    const char *saved_c_appl;
01329    const char *saved_c_data;
01330 
01331    if (c->cdr && !ast_check_hangup(c))
01332       ast_cdr_setapp(c->cdr, app->name, data);
01333 
01334    /* save channel values */
01335    saved_c_appl= c->appl;
01336    saved_c_data= c->data;
01337 
01338    c->appl = app->name;
01339    c->data = data;
01340    if (app->module)
01341       u = __ast_module_user_add(app->module, c);
01342    if (strcasecmp(app->name, "system") && !ast_strlen_zero(data) &&
01343          strchr(data, '|') && !strchr(data, ',') && !ast_opt_dont_warn) {
01344       ast_log(LOG_WARNING, "The application delimiter is now the comma, not "
01345          "the pipe.  Did you forget to convert your dialplan?  (%s(%s))\n",
01346          app->name, (char *) data);
01347    }
01348    res = app->execute(c, S_OR((char *) data, ""));
01349    if (app->module && u)
01350       __ast_module_user_remove(app->module, u);
01351    /* restore channel values */
01352    c->appl = saved_c_appl;
01353    c->data = saved_c_data;
01354    return res;
01355 }

static int pbx_extension_helper ( struct ast_channel *  c,
struct ast_context *  con,
const char *  context,
const char *  exten,
int  priority,
const char *  label,
const char *  callerid,
enum ext_match_t  action,
int *  found,
int  combined_find_spawn 
) [static]

The return value depends on the action:.

E_MATCH, E_CANMATCH, E_MATCHMORE require a real match, and return 0 on failure, -1 on match; E_FINDLABEL maps the label to a priority, and returns the priority on success, ... XXX E_SPAWN, spawn an application,

Return values:
0 on success.
-1 on failure.
Note:
The channel is auto-serviced in this function, because doing an extension match may block for a long time. For example, if the lookup has to use a network dialplan switch, such as DUNDi or IAX2, it may take a while. However, the channel auto-service code will queue up any important signalling frames to be processed after this is done.

Definition at line 3647 of file pbx.c.

References ast_exten::app, app, ast_copy_string(), ast_debug, ast_log(), ast_rdlock_contexts(), ast_unlock_contexts(), ast_verb, ast_exten::cached_app, COLOR_BRCYAN, COLOR_BRMAGENTA, ast_channel::context, pbx_find_info::data, E_CANMATCH, E_FINDLABEL, E_MATCH, E_MATCHMORE, EVENT_FLAG_DIALPLAN, ast_switch::exec, EXT_DATA_SIZE, ast_channel::exten, pbx_find_info::foundcontext, LOG_NOTICE, LOG_WARNING, manager_event, ast_switch::name, ast_channel::name, ast_app::name, pbx_exec(), pbx_find_extension(), pbx_findapp(), pbx_substitute_variables(), ast_channel::priority, ast_exten::priority, S_OR, pbx_find_info::stacklen, pbx_find_info::status, STATUS_NO_CONTEXT, STATUS_NO_EXTENSION, STATUS_NO_LABEL, STATUS_NO_PRIORITY, pbx_find_info::swo, term_color(), ast_channel::uniqueid, and VERBOSITY_ATLEAST.

Referenced by ast_canmatch_extension(), ast_exists_extension(), ast_findlabel_extension(), ast_findlabel_extension2(), ast_matchmore_extension(), and ast_spawn_extension().

03650 {
03651    struct ast_exten *e;
03652    struct ast_app *app;
03653    int res;
03654    struct pbx_find_info q = { .stacklen = 0 }; /* the rest is reset in pbx_find_extension */
03655    char passdata[EXT_DATA_SIZE];
03656 
03657    int matching_action = (action == E_MATCH || action == E_CANMATCH || action == E_MATCHMORE);
03658 
03659    ast_rdlock_contexts();
03660    if (found)
03661       *found = 0;
03662 
03663    e = pbx_find_extension(c, con, &q, context, exten, priority, label, callerid, action);
03664    if (e) {
03665       if (found)
03666          *found = 1;
03667       if (matching_action) {
03668          ast_unlock_contexts();
03669          return -1;  /* success, we found it */
03670       } else if (action == E_FINDLABEL) { /* map the label to a priority */
03671          res = e->priority;
03672          ast_unlock_contexts();
03673          return res; /* the priority we were looking for */
03674       } else { /* spawn */
03675          if (!e->cached_app)
03676             e->cached_app = pbx_findapp(e->app);
03677          app = e->cached_app;
03678          ast_unlock_contexts();
03679          if (!app) {
03680             ast_log(LOG_WARNING, "No application '%s' for extension (%s, %s, %d)\n", e->app, context, exten, priority);
03681             return -1;
03682          }
03683          if (c->context != context)
03684             ast_copy_string(c->context, context, sizeof(c->context));
03685          if (c->exten != exten)
03686             ast_copy_string(c->exten, exten, sizeof(c->exten));
03687          c->priority = priority;
03688          pbx_substitute_variables(passdata, sizeof(passdata), c, e);
03689 #ifdef CHANNEL_TRACE
03690          ast_channel_trace_update(c);
03691 #endif
03692          ast_debug(1, "Launching '%s'\n", app->name);
03693          if (VERBOSITY_ATLEAST(3)) {
03694             char tmp[80], tmp2[80], tmp3[EXT_DATA_SIZE];
03695             ast_verb(3, "Executing [%s@%s:%d] %s(\"%s\", \"%s\") %s\n",
03696                exten, context, priority,
03697                term_color(tmp, app->name, COLOR_BRCYAN, 0, sizeof(tmp)),
03698                term_color(tmp2, c->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)),
03699                term_color(tmp3, passdata, COLOR_BRMAGENTA, 0, sizeof(tmp3)),
03700                "in new stack");
03701          }
03702          manager_event(EVENT_FLAG_DIALPLAN, "Newexten",
03703                "Channel: %s\r\n"
03704                "Context: %s\r\n"
03705                "Extension: %s\r\n"
03706                "Priority: %d\r\n"
03707                "Application: %s\r\n"
03708                "AppData: %s\r\n"
03709                "Uniqueid: %s\r\n",
03710                c->name, c->context, c->exten, c->priority, app->name, passdata, c->uniqueid);
03711          return pbx_exec(c, app, passdata);  /* 0 on success, -1 on failure */
03712       }
03713    } else if (q.swo) {  /* not found here, but in another switch */
03714       if (found)
03715          *found = 1;
03716       ast_unlock_contexts();
03717       if (matching_action) {
03718          return -1;
03719       } else {
03720          if (!q.swo->exec) {
03721             ast_log(LOG_WARNING, "No execution engine for switch %s\n", q.swo->name);
03722             res = -1;
03723          }
03724          return q.swo->exec(c, q.foundcontext ? q.foundcontext : context, exten, priority, callerid, q.data);
03725       }
03726    } else { /* not found anywhere, see what happened */
03727       ast_unlock_contexts();
03728       /* Using S_OR here because Solaris doesn't like NULL being passed to ast_log */
03729       switch (q.status) {
03730       case STATUS_NO_CONTEXT:
03731          if (!matching_action && !combined_find_spawn)
03732             ast_log(LOG_NOTICE, "Cannot find extension context '%s'\n", S_OR(context, ""));
03733          break;
03734       case STATUS_NO_EXTENSION:
03735          if (!matching_action && !combined_find_spawn)
03736             ast_log(LOG_NOTICE, "Cannot find extension '%s' in context '%s'\n", exten, S_OR(context, ""));
03737          break;
03738       case STATUS_NO_PRIORITY:
03739          if (!matching_action && !combined_find_spawn)
03740             ast_log(LOG_NOTICE, "No such priority %d in extension '%s' in context '%s'\n", priority, exten, S_OR(context, ""));
03741          break;
03742       case STATUS_NO_LABEL:
03743          if (context && !combined_find_spawn)
03744             ast_log(LOG_NOTICE, "No such label '%s' in extension '%s' in context '%s'\n", label, exten, S_OR(context, ""));
03745          break;
03746       default:
03747          ast_debug(1, "Shouldn't happen!\n");
03748       }
03749 
03750       return (matching_action) ? 0 : -1;
03751    }
03752 }

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

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

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

02473 {
02474    int x, res;
02475    struct ast_context *tmp = NULL;
02476    struct ast_exten *e = NULL, *eroot = NULL;
02477    struct ast_include *i = NULL;
02478    struct ast_sw *sw = NULL;
02479    struct ast_exten pattern = {NULL, };
02480    struct scoreboard score = {0, };
02481    struct ast_str *tmpdata = NULL;
02482 
02483    pattern.label = label;
02484    pattern.priority = priority;
02485 #ifdef NEED_DEBUG_HERE
02486    ast_log(LOG_NOTICE, "Looking for cont/ext/prio/label/action = %s/%s/%d/%s/%d\n", context, exten, priority, label, (int) action);
02487 #endif
02488 
02489    /* Initialize status if appropriate */
02490    if (q->stacklen == 0) {
02491       q->status = STATUS_NO_CONTEXT;
02492       q->swo = NULL;
02493       q->data = NULL;
02494       q->foundcontext = NULL;
02495    } else if (q->stacklen >= AST_PBX_MAX_STACK) {
02496       ast_log(LOG_WARNING, "Maximum PBX stack exceeded\n");
02497       return NULL;
02498    }
02499 
02500    /* Check first to see if we've already been checked */
02501    for (x = 0; x < q->stacklen; x++) {
02502       if (!strcasecmp(q->incstack[x], context))
02503          return NULL;
02504    }
02505 
02506    if (bypass) { /* bypass means we only look there */
02507       tmp = bypass;
02508    } else {      /* look in contexts */
02509       struct fake_context item;
02510 
02511       ast_copy_string(item.name, context, sizeof(item.name));
02512 
02513       tmp = ast_hashtab_lookup(contexts_table, &item);
02514 #ifdef NOTNOW
02515       tmp = NULL;
02516       while ((tmp = ast_walk_contexts(tmp)) ) {
02517          if (!strcmp(tmp->name, context)) {
02518             break;
02519          }
02520       }
02521 #endif
02522       if (!tmp) {
02523          return NULL;
02524       }
02525    }
02526 
02527    if (q->status < STATUS_NO_EXTENSION)
02528       q->status = STATUS_NO_EXTENSION;
02529 
02530    /* Do a search for matching extension */
02531 
02532    eroot = NULL;
02533    score.total_specificity = 0;
02534    score.exten = 0;
02535    score.total_length = 0;
02536    if (!tmp->pattern_tree && tmp->root_table) {
02537       create_match_char_tree(tmp);
02538 #ifdef NEED_DEBUG
02539       ast_log(LOG_DEBUG, "Tree Created in context %s:\n", context);
02540       log_match_char_tree(tmp->pattern_tree," ");
02541 #endif
02542    }
02543 #ifdef NEED_DEBUG
02544    ast_log(LOG_NOTICE, "The Trie we are searching in:\n");
02545    log_match_char_tree(tmp->pattern_tree, "::  ");
02546 #endif
02547 
02548    do {
02549       if (!ast_strlen_zero(overrideswitch)) {
02550          char *osw = ast_strdupa(overrideswitch), *name;
02551          struct ast_switch *asw;
02552          ast_switch_f *aswf = NULL;
02553          char *datap;
02554          int eval = 0;
02555 
02556          name = strsep(&osw, "/");
02557          asw = pbx_findswitch(name);
02558 
02559          if (!asw) {
02560             ast_log(LOG_WARNING, "No such switch '%s'\n", name);
02561             break;
02562          }
02563 
02564          if (osw && strchr(osw, '$')) {
02565             eval = 1;
02566          }
02567 
02568          if (eval && !(tmpdata = ast_str_thread_get(&switch_data, 512))) {
02569             ast_log(LOG_WARNING, "Can't evaluate overrideswitch?!");
02570             break;
02571          } else if (eval) {
02572             /* Substitute variables now */
02573             pbx_substitute_variables_helper(chan, osw, ast_str_buffer(tmpdata), ast_str_size(tmpdata));
02574             datap = ast_str_buffer(tmpdata);
02575          } else {
02576             datap = osw;
02577          }
02578 
02579          /* equivalent of extension_match_core() at the switch level */
02580          if (action == E_CANMATCH)
02581             aswf = asw->canmatch;
02582          else if (action == E_MATCHMORE)
02583             aswf = asw->matchmore;
02584          else /* action == E_MATCH */
02585             aswf = asw->exists;
02586          if (!aswf) {
02587             res = 0;
02588          } else {
02589             if (chan) {
02590                ast_autoservice_start(chan);
02591             }
02592             res = aswf(chan, context, exten, priority, callerid, datap);
02593             if (chan) {
02594                ast_autoservice_stop(chan);
02595             }
02596          }
02597          if (res) {  /* Got a match */
02598             q->swo = asw;
02599             q->data = datap;
02600             q->foundcontext = context;
02601             /* XXX keep status = STATUS_NO_CONTEXT ? */
02602             return NULL;
02603          }
02604       }
02605    } while (0);
02606 
02607    if (extenpatternmatchnew) {
02608       new_find_extension(exten, &score, tmp->pattern_tree, 0, 0, callerid, label, action);
02609       eroot = score.exten;
02610 
02611       if (score.last_char == '!' && action == E_MATCHMORE) {
02612          /* We match an extension ending in '!'.
02613           * The decision in this case is final and is NULL (no match).
02614           */
02615 #ifdef NEED_DEBUG_HERE
02616          ast_log(LOG_NOTICE,"Returning MATCHMORE NULL with exclamation point.\n");
02617 #endif
02618          return NULL;
02619       }
02620 
02621       if (!eroot && (action == E_CANMATCH || action == E_MATCHMORE) && score.canmatch_exten) {
02622          q->status = STATUS_SUCCESS;
02623 #ifdef NEED_DEBUG_HERE
02624          ast_log(LOG_NOTICE,"Returning CANMATCH exten %s\n", score.canmatch_exten->exten);
02625 #endif
02626          return score.canmatch_exten;
02627       }
02628 
02629       if ((action == E_MATCHMORE || action == E_CANMATCH)  && eroot) {
02630          if (score.node) {
02631             struct ast_exten *z = trie_find_next_match(score.node);
02632             if (z) {
02633 #ifdef NEED_DEBUG_HERE
02634                ast_log(LOG_NOTICE,"Returning CANMATCH/MATCHMORE next_match exten %s\n", z->exten);
02635 #endif
02636             } else {
02637                if (score.canmatch_exten) {
02638 #ifdef NEED_DEBUG_HERE
02639                   ast_log(LOG_NOTICE,"Returning CANMATCH/MATCHMORE canmatchmatch exten %s(%p)\n", score.canmatch_exten->exten, score.canmatch_exten);
02640 #endif
02641                   return score.canmatch_exten;
02642                } else {
02643 #ifdef NEED_DEBUG_HERE
02644                   ast_log(LOG_NOTICE,"Returning CANMATCH/MATCHMORE next_match exten NULL\n");
02645 #endif
02646                }
02647             }
02648             return z;
02649          }
02650 #ifdef NEED_DEBUG_HERE
02651          ast_log(LOG_NOTICE, "Returning CANMATCH/MATCHMORE NULL (no next_match)\n");
02652 #endif
02653          return NULL;  /* according to the code, complete matches are null matches in MATCHMORE mode */
02654       }
02655 
02656       if (eroot) {
02657          /* found entry, now look for the right priority */
02658          if (q->status < STATUS_NO_PRIORITY)
02659             q->status = STATUS_NO_PRIORITY;
02660          e = NULL;
02661          if (action == E_FINDLABEL && label ) {
02662             if (q->status < STATUS_NO_LABEL)
02663                q->status = STATUS_NO_LABEL;
02664             e = ast_hashtab_lookup(eroot->peer_label_table, &pattern);
02665          } else {
02666             e = ast_hashtab_lookup(eroot->peer_table, &pattern);
02667          }
02668          if (e) { /* found a valid match */
02669             q->status = STATUS_SUCCESS;
02670             q->foundcontext = context;
02671 #ifdef NEED_DEBUG_HERE
02672             ast_log(LOG_NOTICE,"Returning complete match of exten %s\n", e->exten);
02673 #endif
02674             return e;
02675          }
02676       }
02677    } else {   /* the old/current default exten pattern match algorithm */
02678 
02679       /* scan the list trying to match extension and CID */
02680       eroot = NULL;
02681       while ( (eroot = ast_walk_context_extensions(tmp, eroot)) ) {
02682          int match = extension_match_core(eroot->exten, exten, action);
02683          /* 0 on fail, 1 on match, 2 on earlymatch */
02684 
02685          if (!match || (eroot->matchcid && !matchcid(eroot->cidmatch, callerid)))
02686             continue;   /* keep trying */
02687          if (match == 2 && action == E_MATCHMORE) {
02688             /* We match an extension ending in '!'.
02689              * The decision in this case is final and is NULL (no match).
02690              */
02691             return NULL;
02692          }
02693          /* found entry, now look for the right priority */
02694          if (q->status < STATUS_NO_PRIORITY)
02695             q->status = STATUS_NO_PRIORITY;
02696          e = NULL;
02697          if (action == E_FINDLABEL && label ) {
02698             if (q->status < STATUS_NO_LABEL)
02699                q->status = STATUS_NO_LABEL;
02700             e = ast_hashtab_lookup(eroot->peer_label_table, &pattern);
02701          } else {
02702             e = ast_hashtab_lookup(eroot->peer_table, &pattern);
02703          }
02704 #ifdef NOTNOW
02705          while ( (e = ast_walk_extension_priorities(eroot, e)) ) {
02706             /* Match label or priority */
02707             if (action == E_FINDLABEL) {
02708                if (q->status < STATUS_NO_LABEL)
02709                   q->status = STATUS_NO_LABEL;
02710                if (label && e->label && !strcmp(label, e->label))
02711                   break;   /* found it */
02712             } else if (e->priority == priority) {
02713                break;   /* found it */
02714             } /* else keep searching */
02715          }
02716 #endif
02717          if (e) { /* found a valid match */
02718             q->status = STATUS_SUCCESS;
02719             q->foundcontext = context;
02720             return e;
02721          }
02722       }
02723    }
02724 
02725    /* Check alternative switches */
02726    AST_LIST_TRAVERSE(&tmp->alts, sw, list) {
02727       struct ast_switch *asw = pbx_findswitch(sw->name);
02728       ast_switch_f *aswf = NULL;
02729       char *datap;
02730 
02731       if (!asw) {
02732          ast_log(LOG_WARNING, "No such switch '%s'\n", sw->name);
02733          continue;
02734       }
02735 
02736       /* Substitute variables now */
02737       if (sw->eval) {
02738          if (!(tmpdata = ast_str_thread_get(&switch_data, 512))) {
02739             ast_log(LOG_WARNING, "Can't evaluate switch?!");
02740             continue;
02741          }
02742          pbx_substitute_variables_helper(chan, sw->data, ast_str_buffer(tmpdata), ast_str_size(tmpdata));
02743       }
02744 
02745       /* equivalent of extension_match_core() at the switch level */
02746       if (action == E_CANMATCH)
02747          aswf = asw->canmatch;
02748       else if (action == E_MATCHMORE)
02749          aswf = asw->matchmore;
02750       else /* action == E_MATCH */
02751          aswf = asw->exists;
02752       datap = sw->eval ? ast_str_buffer(tmpdata) : sw->data;
02753       if (!aswf)
02754          res = 0;
02755       else {
02756          if (chan)
02757             ast_autoservice_start(chan);
02758          res = aswf(chan, context, exten, priority, callerid, datap);
02759          if (chan)
02760             ast_autoservice_stop(chan);
02761       }
02762       if (res) {  /* Got a match */
02763          q->swo = asw;
02764          q->data = datap;
02765          q->foundcontext = context;
02766          /* XXX keep status = STATUS_NO_CONTEXT ? */
02767          return NULL;
02768       }
02769    }
02770    q->incstack[q->stacklen++] = tmp->name;   /* Setup the stack */
02771    /* Now try any includes we have in this context */
02772    for (i = tmp->includes; i; i = i->next) {
02773       if (include_valid(i)) {
02774          if ((e = pbx_find_extension(chan, bypass, q, i->rname, exten, priority, label, callerid, action))) {
02775 #ifdef NEED_DEBUG_HERE
02776             ast_log(LOG_NOTICE,"Returning recursive match of %s\n", e->exten);
02777 #endif
02778             return e;
02779          }
02780          if (q->swo)
02781             return NULL;
02782       }
02783    }
02784    return NULL;
02785 }

struct ast_app* pbx_findapp ( const char *  app  )  [read]

static struct ast_switch* pbx_findswitch ( const char *  sw  )  [static, read]

Definition at line 1377 of file pbx.c.

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

Referenced by pbx_find_extension().

01378 {
01379    struct ast_switch *asw;
01380 
01381    AST_RWLIST_RDLOCK(&switches);
01382    AST_RWLIST_TRAVERSE(&switches, asw, list) {
01383       if (!strcasecmp(asw->name, sw))
01384          break;
01385    }
01386    AST_RWLIST_UNLOCK(&switches);
01387 
01388    return asw;
01389 }

static int pbx_parseable_goto ( struct ast_channel *  chan,
const char *  goto_string,
int  async 
) [static]

Definition at line 9592 of file pbx.c.

References ast_async_goto(), ast_explicit_goto(), ast_findlabel_extension(), ast_log(), ast_strdupa, ast_strlen_zero(), ast_channel::cid, ast_callerid::cid_num, ast_channel::context, ast_channel::exten, LOG_WARNING, ast_channel::priority, and strsep().

Referenced by ast_async_parseable_goto(), and ast_parseable_goto().

09593 {
09594    char *exten, *pri, *context;
09595    char *stringp;
09596    int ipri;
09597    int mode = 0;
09598 
09599    if (ast_strlen_zero(goto_string)) {
09600       ast_log(LOG_WARNING, "Goto requires an argument ([[context,]extension,]priority)\n");
09601       return -1;
09602    }
09603    stringp = ast_strdupa(goto_string);
09604    context = strsep(&stringp, ","); /* guaranteed non-null */
09605    exten = strsep(&stringp, ",");
09606    pri = strsep(&stringp, ",");
09607    if (!exten) {  /* Only a priority in this one */
09608       pri = context;
09609       exten = NULL;
09610       context = NULL;
09611    } else if (!pri) {   /* Only an extension and priority in this one */
09612       pri = exten;
09613       exten = context;
09614       context = NULL;
09615    }
09616    if (*pri == '+') {
09617       mode = 1;
09618       pri++;
09619    } else if (*pri == '-') {
09620       mode = -1;
09621       pri++;
09622    }
09623    if (sscanf(pri, "%30d", &ipri) != 1) {
09624       if ((ipri = ast_findlabel_extension(chan, context ? context : chan->context, exten ? exten : chan->exten,
09625          pri, chan->cid.cid_num)) < 1) {
09626          ast_log(LOG_WARNING, "Priority '%s' must be a number > 0, or valid label\n", pri);
09627          return -1;
09628       } else
09629          mode = 0;
09630    }
09631    /* At this point we have a priority and maybe an extension and a context */
09632 
09633    if (mode)
09634       ipri = chan->priority + (ipri * mode);
09635 
09636    if (async)
09637       ast_async_goto(chan, context, exten, ipri);
09638    else
09639       ast_explicit_goto(chan, context, exten, ipri);
09640 
09641    return 0;
09642 
09643 }

void pbx_retrieve_variable ( struct ast_channel *  c,
const char *  var,
char **  ret,
char *  workspace,
int  workspacelen,
struct varshead *  headp 
)

Support for Asterisk built-in variables in the dialplan.

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

Note:
See also

Definition at line 2867 of file pbx.c.

References ARRAY_LEN, ast_channel_lock, ast_channel_unlock, ast_config_AST_SYSTEM_NAME, ast_copy_string(), ast_eid_default, ast_eid_to_str(), ast_get_hint(), AST_LIST_TRAVERSE, ast_rwlock_rdlock(), ast_rwlock_unlock(), ast_strdupa, ast_var_name(), ast_var_value(), ast_channel::cid, ast_callerid::cid_ani2, ast_callerid::cid_pres, ast_callerid::cid_tns, ast_callerid::cid_ton, ast_channel::context, ast_var_t::entries, ast_channel::exten, globals, globalslock, ast_channel::hangupcause, ast_channel::name, parse_variable_name(), ast_channel::priority, s, substring(), ast_channel::uniqueid, and ast_channel::varshead.

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

02868 {
02869    const char not_found = '\0';
02870    char *tmpvar;
02871    const char *s; /* the result */
02872    int offset, length;
02873    int i, need_substring;
02874    struct varshead *places[2] = { headp, &globals };  /* list of places where we may look */
02875 
02876    if (c) {
02877       ast_channel_lock(c);
02878       places[0] = &c->varshead;
02879    }
02880    /*
02881     * Make a copy of var because parse_variable_name() modifies the string.
02882     * Then if called directly, we might need to run substring() on the result;
02883     * remember this for later in 'need_substring', 'offset' and 'length'
02884     */
02885    tmpvar = ast_strdupa(var); /* parse_variable_name modifies the string */
02886    need_substring = parse_variable_name(tmpvar, &offset, &length, &i /* ignored */);
02887 
02888    /*
02889     * Look first into predefined variables, then into variable lists.
02890     * Variable 's' points to the result, according to the following rules:
02891     * s == &not_found (set at the beginning) means that we did not find a
02892     * matching variable and need to look into more places.
02893     * If s != &not_found, s is a valid result string as follows:
02894     * s = NULL if the variable does not have a value;
02895     * you typically do this when looking for an unset predefined variable.
02896     * s = workspace if the result has been assembled there;
02897     * typically done when the result is built e.g. with an snprintf(),
02898     * so we don't need to do an additional copy.
02899     * s != workspace in case we have a string, that needs to be copied
02900     * (the ast_copy_string is done once for all at the end).
02901     * Typically done when the result is already available in some string.
02902     */
02903    s = &not_found;   /* default value */
02904    if (c) { /* This group requires a valid channel */
02905       /* Names with common parts are looked up a piece at a time using strncmp. */
02906       if (!strncmp(var, "CALL", 4)) {
02907          if (!strncmp(var + 4, "ING", 3)) {
02908             if (!strcmp(var + 7, "PRES")) {        /* CALLINGPRES */
02909                snprintf(workspace, workspacelen, "%d", c->cid.cid_pres);
02910                s = workspace;
02911             } else if (!strcmp(var + 7, "ANI2")) {    /* CALLINGANI2 */
02912                snprintf(workspace, workspacelen, "%d", c->cid.cid_ani2);
02913                s = workspace;
02914             } else if (!strcmp(var + 7, "TON")) {     /* CALLINGTON */
02915                snprintf(workspace, workspacelen, "%d", c->cid.cid_ton);
02916                s = workspace;
02917             } else if (!strcmp(var + 7, "TNS")) {     /* CALLINGTNS */
02918                snprintf(workspace, workspacelen, "%d", c->cid.cid_tns);
02919                s = workspace;
02920             }
02921          }
02922       } else if (!strcmp(var, "HINT")) {
02923          s = ast_get_hint(workspace, workspacelen, NULL, 0, c, c->context, c->exten) ? workspace : NULL;
02924       } else if (!strcmp(var, "HINTNAME")) {
02925          s = ast_get_hint(NULL, 0, workspace, workspacelen, c, c->context, c->exten) ? workspace : NULL;
02926       } else if (!strcmp(var, "EXTEN")) {
02927          s = c->exten;
02928       } else if (!strcmp(var, "CONTEXT")) {
02929          s = c->context;
02930       } else if (!strcmp(var, "PRIORITY")) {
02931          snprintf(workspace, workspacelen, "%d", c->priority);
02932          s = workspace;
02933       } else if (!strcmp(var, "CHANNEL")) {
02934          s = c->name;
02935       } else if (!strcmp(var, "UNIQUEID")) {
02936          s = c->uniqueid;
02937       } else if (!strcmp(var, "HANGUPCAUSE")) {
02938          snprintf(workspace, workspacelen, "%d", c->hangupcause);
02939          s = workspace;
02940       }
02941    }
02942    if (s == &not_found) { /* look for more */
02943       if (!strcmp(var, "EPOCH")) {
02944          snprintf(workspace, workspacelen, "%u",(int)time(NULL));
02945          s = workspace;
02946       } else if (!strcmp(var, "SYSTEMNAME")) {
02947          s = ast_config_AST_SYSTEM_NAME;
02948       } else if (!strcmp(var, "ENTITYID")) {
02949          ast_eid_to_str(workspace, workspacelen, &ast_eid_default);
02950          s = workspace;
02951       }
02952    }
02953    /* if not found, look into chanvars or global vars */
02954    for (i = 0; s == &not_found && i < ARRAY_LEN(places); i++) {
02955       struct ast_var_t *variables;
02956       if (!places[i])
02957          continue;
02958       if (places[i] == &globals)
02959          ast_rwlock_rdlock(&globalslock);
02960       AST_LIST_TRAVERSE(places[i], variables, entries) {
02961          if (!strcasecmp(ast_var_name(variables), var)) {
02962             s = ast_var_value(variables);
02963             break;
02964          }
02965       }
02966       if (places[i] == &globals)
02967          ast_rwlock_unlock(&globalslock);
02968    }
02969    if (s == &not_found || s == NULL)
02970       *ret = NULL;
02971    else {
02972       if (s != workspace)
02973          ast_copy_string(workspace, s, workspacelen);
02974       *ret = workspace;
02975       if (need_substring)
02976          *ret = substring(*ret, offset, length, workspace, workspacelen);
02977    }
02978 
02979    if (c)
02980       ast_channel_unlock(c);
02981 }

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

References autofallthrough.

Referenced by pbx_load_module().

04624 {
04625    int oldval = autofallthrough;
04626    autofallthrough = newval;
04627    return oldval;
04628 }

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

References extenpatternmatchnew.

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

04631 {
04632    int oldval = extenpatternmatchnew;
04633    extenpatternmatchnew = newval;
04634    return oldval;
04635 }

void pbx_set_overrideswitch ( const char *  newval  ) 

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

Since:
1.6.1

Definition at line 4637 of file pbx.c.

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

Referenced by pbx_load_module().

04638 {
04639    if (overrideswitch) {
04640       ast_free(overrideswitch);
04641    }
04642    if (!ast_strlen_zero(newval)) {
04643       overrideswitch = ast_strdup(newval);
04644    } else {
04645       overrideswitch = NULL;
04646    }
04647 }

static void pbx_substitute_variables ( char *  passdata,
int  datalen,
struct ast_channel *  c,
struct ast_exten *  e 
) [static]

Definition at line 3610 of file pbx.c.

References ast_copy_string(), ast_exten::data, and pbx_substitute_variables_helper().

Referenced by pbx_extension_helper().

03611 {
03612    const char *tmp;
03613 
03614    /* Nothing more to do */
03615    if (!e->data) {
03616       *passdata = '\0';
03617       return;
03618    }
03619 
03620    /* No variables or expressions in e->data, so why scan it? */
03621    if ((!(tmp = strchr(e->data, '$'))) || (!strstr(tmp, "${") && !strstr(tmp, "$["))) {
03622       ast_copy_string(passdata, e->data, datalen);
03623       return;
03624    }
03625 
03626    pbx_substitute_variables_helper(c, e->data, passdata, datalen - 1);
03627 }

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  count,
size_t *  used 
)

Definition at line 3403 of file pbx.c.

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

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

03404 {
03405    /* Substitutes variables into cp2, based on string cp1, cp2 NO LONGER NEEDS TO BE ZEROED OUT!!!!  */
03406    char *cp4;
03407    const char *tmp, *whereweare, *orig_cp2 = cp2;
03408    int length, offset, offset2, isfunction;
03409    char *workspace = NULL;
03410    char *ltmp = NULL, *var = NULL;
03411    char *nextvar, *nextexp, *nextthing;
03412    char *vars, *vare;
03413    int pos, brackets, needsub, len;
03414 
03415    *cp2 = 0; /* just in case nothing ends up there */
03416    whereweare=tmp=cp1;
03417    while (!ast_strlen_zero(whereweare) && count) {
03418       /* Assume we're copying the whole remaining string */
03419       pos = strlen(whereweare);
03420       nextvar = NULL;
03421       nextexp = NULL;
03422       nextthing = strchr(whereweare, '$');
03423       if (nextthing) {
03424          switch (nextthing[1]) {
03425          case '{':
03426             nextvar = nextthing;
03427             pos = nextvar - whereweare;
03428             break;
03429          case '[':
03430             nextexp = nextthing;
03431             pos = nextexp - whereweare;
03432             break;
03433          default:
03434             pos = 1;
03435          }
03436       }
03437 
03438       if (pos) {
03439          /* Can't copy more than 'count' bytes */
03440          if (pos > count)
03441             pos = count;
03442 
03443          /* Copy that many bytes */
03444          memcpy(cp2, whereweare, pos);
03445 
03446          count -= pos;
03447          cp2 += pos;
03448          whereweare += pos;
03449          *cp2 = 0;
03450       }
03451 
03452       if (nextvar) {
03453          /* We have a variable.  Find the start and end, and determine
03454             if we are going to have to recursively call ourselves on the
03455             contents */
03456          vars = vare = nextvar + 2;
03457          brackets = 1;
03458          needsub = 0;
03459 
03460          /* Find the end of it */
03461          while (brackets && *vare) {
03462             if ((vare[0] == '$') && (vare[1] == '{')) {
03463                needsub++;
03464             } else if (vare[0] == '{') {
03465                brackets++;
03466             } else if (vare[0] == '}') {
03467                brackets--;
03468             } else if ((vare[0] == '$') && (vare[1] == '['))
03469                needsub++;
03470             vare++;
03471          }
03472          if (brackets)
03473             ast_log(LOG_WARNING, "Error in extension logic (missing '}')\n");
03474          len = vare - vars - 1;
03475 
03476          /* Skip totally over variable string */
03477          whereweare += (len + 3);
03478 
03479          if (!var)
03480             var = alloca(VAR_BUF_SIZE);
03481 
03482          /* Store variable name (and truncate) */
03483          ast_copy_string(var, vars, len + 1);
03484 
03485          /* Substitute if necessary */
03486          if (needsub) {
03487             size_t used;
03488             if (!ltmp)
03489                ltmp = alloca(VAR_BUF_SIZE);
03490 
03491             pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, &used);
03492             vars = ltmp;
03493          } else {
03494             vars = var;
03495          }
03496 
03497          if (!workspace)
03498             workspace = alloca(VAR_BUF_SIZE);
03499 
03500          workspace[0] = '\0';
03501 
03502          parse_variable_name(vars, &offset, &offset2, &isfunction);
03503          if (isfunction) {
03504             /* Evaluate function */
03505             if (c || !headp)
03506                cp4 = ast_func_read(c, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace;
03507             else {
03508                struct varshead old;
03509                struct ast_channel *bogus = ast_channel_alloc(0, 0, "", "", "", "", "", 0, "Bogus/%p", vars);
03510                if (bogus) {
03511                   memcpy(&old, &bogus->varshead, sizeof(old));
03512                   memcpy(&bogus->varshead, headp, sizeof(bogus->varshead));
03513                   cp4 = ast_func_read(bogus, vars, workspace, VAR_BUF_SIZE) ? NULL : workspace;
03514                   /* Don't deallocate the varshead that was passed in */
03515                   memcpy(&bogus->varshead, &old, sizeof(bogus->varshead));
03516                   ast_channel_free(bogus);
03517                } else
03518                   ast_log(LOG_ERROR, "Unable to allocate bogus channel for variable substitution.  Function results may be blank.\n");
03519             }
03520             ast_debug(2, "Function result is '%s'\n", cp4 ? cp4 : "(null)");
03521          } else {
03522             /* Retrieve variable value */
03523             pbx_retrieve_variable(c, vars, &cp4, workspace, VAR_BUF_SIZE, headp);
03524          }
03525          if (cp4) {
03526             cp4 = substring(cp4, offset, offset2, workspace, VAR_BUF_SIZE);
03527 
03528             length = strlen(cp4);
03529             if (length > count)
03530                length = count;
03531             memcpy(cp2, cp4, length);
03532             count -= length;
03533             cp2 += length;
03534             *cp2 = 0;
03535          }
03536       } else if (nextexp) {
03537          /* We have an expression.  Find the start and end, and determine
03538             if we are going to have to recursively call ourselves on the
03539             contents */
03540          vars = vare = nextexp + 2;
03541          brackets = 1;
03542          needsub = 0;
03543 
03544          /* Find the end of it */
03545          while (brackets && *vare) {
03546             if ((vare[0] == '$') && (vare[1] == '[')) {
03547                needsub++;
03548                brackets++;
03549                vare++;
03550             } else if (vare[0] == '[') {
03551                brackets++;
03552             } else if (vare[0] == ']') {
03553                brackets--;
03554             } else if ((vare[0] == '$') && (vare[1] == '{')) {
03555                needsub++;
03556                vare++;
03557             }
03558             vare++;
03559          }
03560          if (brackets)
03561             ast_log(LOG_WARNING, "Error in extension logic (missing ']')\n");
03562          len = vare - vars - 1;
03563 
03564          /* Skip totally over expression */
03565          whereweare += (len + 3);
03566 
03567          if (!var)
03568             var = alloca(VAR_BUF_SIZE);
03569 
03570          /* Store variable name (and truncate) */
03571          ast_copy_string(var, vars, len + 1);
03572 
03573          /* Substitute if necessary */
03574          if (needsub) {
03575             size_t used;
03576             if (!ltmp)
03577                ltmp = alloca(VAR_BUF_SIZE);
03578 
03579             pbx_substitute_variables_helper_full(c, headp, var, ltmp, VAR_BUF_SIZE - 1, &used);
03580             vars = ltmp;
03581          } else {
03582             vars = var;
03583          }
03584 
03585          length = ast_expr(vars, cp2, count, c);
03586 
03587          if (length) {
03588             ast_debug(1, "Expression result is '%s'\n", cp2);
03589             count -= length;
03590             cp2 += length;
03591             *cp2 = 0;
03592          }
03593       }
03594    }
03595    *used = cp2 - orig_cp2;
03596 }

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

Definition at line 3604 of file pbx.c.

References pbx_substitute_variables_helper_full().

Referenced by add_user_extension(), build_user_routes(), do_say(), dundi_lookup_local(), loopback_subst(), phoneprov_callback(), pp_each_extension_exec(), and pp_each_user_exec().

03605 {
03606    size_t used;
03607    pbx_substitute_variables_helper_full(NULL, headp, cp1, cp2, count, &used);
03608 }

static void* pbx_thread ( void *  data  )  [static]

Definition at line 4551 of file pbx.c.

References __ast_pbx_run(), and decrease_call_count().

Referenced by ast_pbx_start().

04552 {
04553    /* Oh joyeous kernel, we're a new thread, with nothing to do but
04554       answer this channel and get it going.
04555    */
04556    /* NOTE:
04557       The launcher of this function _MUST_ increment 'countcalls'
04558       before invoking the function; it will be decremented when the
04559       PBX has finished running on the channel
04560     */
04561    struct ast_channel *c = data;
04562 
04563    __ast_pbx_run(c, NULL);
04564    decrease_call_count();
04565 
04566    pthread_exit(NULL);
04567 
04568    return NULL;
04569 }

static void print_app_docs ( struct ast_app *  aa,
int  fd 
) [static]

Definition at line 5198 of file pbx.c.

References ast_app::arguments, ast_cli(), ast_free, ast_malloc, AST_MAX_APP, AST_TERM_MAX_ESCAPE_CHARS, AST_XML_DOC, ast_xmldoc_printable(), COLOR_CYAN, COLOR_MAGENTA, ast_app::description, description, ast_app::docsrc, ast_app::name, S_OR, ast_app::seealso, ast_app::synopsis, synopsis, ast_app::syntax, and term_color().

Referenced by handle_show_application().

05199 {
05200    /* Maximum number of characters added by terminal coloring is 22 */
05201    char infotitle[64 + AST_MAX_APP + 22], syntitle[40], destitle[40], stxtitle[40], argtitle[40];
05202    char seealsotitle[40];
05203    char info[64 + AST_MAX_APP], *synopsis = NULL, *description = NULL, *syntax = NULL, *arguments = NULL;
05204    char *seealso = NULL;
05205    int syntax_size, synopsis_size, description_size, arguments_size, seealso_size;
05206 
05207    snprintf(info, sizeof(info), "\n  -= Info about application '%s' =- \n\n", aa->name);
05208    term_color(infotitle, info, COLOR_MAGENTA, 0, sizeof(infotitle));
05209 
05210    term_color(syntitle, "[Synopsis]\n", COLOR_MAGENTA, 0, 40);
05211    term_color(destitle, "[Description]\n", COLOR_MAGENTA, 0, 40);
05212    term_color(stxtitle, "[Syntax]\n", COLOR_MAGENTA, 0, 40);
05213    term_color(argtitle, "[Arguments]\n", COLOR_MAGENTA, 0, 40);
05214    term_color(seealsotitle, "[See Also]\n", COLOR_MAGENTA, 0, 40);
05215 
05216 #ifdef AST_XML_DOCS
05217    if (aa->docsrc == AST_XML_DOC) {
05218       description = ast_xmldoc_printable(S_OR(aa->description, "Not available"), 1);
05219       arguments = ast_xmldoc_printable(S_OR(aa->arguments, "Not available"), 1);
05220       synopsis = ast_xmldoc_printable(S_OR(aa->synopsis, "Not available"), 1);
05221       seealso = ast_xmldoc_printable(S_OR(aa->seealso, "Not available"), 1);
05222 
05223       if (!synopsis || !description || !arguments || !seealso) {
05224          goto return_cleanup;
05225       }
05226    } else
05227 #endif
05228    {
05229       synopsis_size = strlen(S_OR(aa->synopsis, "Not Available")) + AST_TERM_MAX_ESCAPE_CHARS;
05230       synopsis = ast_malloc(synopsis_size);
05231 
05232       description_size = strlen(S_OR(aa->description, "Not Available")) + AST_TERM_MAX_ESCAPE_CHARS;
05233       description = ast_malloc(description_size);
05234 
05235       arguments_size = strlen(S_OR(aa->arguments, "Not Available")) + AST_TERM_MAX_ESCAPE_CHARS;
05236       arguments = ast_malloc(arguments_size);
05237 
05238       seealso_size = strlen(S_OR(aa->seealso, "Not Available")) + AST_TERM_MAX_ESCAPE_CHARS;
05239       seealso = ast_malloc(seealso_size);
05240 
05241       if (!synopsis || !description || !arguments || !seealso) {
05242          goto return_cleanup;
05243       }
05244 
05245       term_color(synopsis, S_OR(aa->synopsis, "Not available"), COLOR_CYAN, 0, synopsis_size);
05246       term_color(description, S_OR(aa->description, "Not available"),   COLOR_CYAN, 0, description_size);
05247       term_color(arguments, S_OR(aa->arguments, "Not available"), COLOR_CYAN, 0, arguments_size);
05248       term_color(seealso, S_OR(aa->seealso, "Not available"), COLOR_CYAN, 0, seealso_size);
05249    }
05250 
05251    /* Handle the syntax the same for both XML and raw docs */
05252    syntax_size = strlen(S_OR(aa->syntax, "Not Available")) + AST_TERM_MAX_ESCAPE_CHARS;
05253    if (!(syntax = ast_malloc(syntax_size))) {
05254       goto return_cleanup;
05255    }
05256    term_color(syntax, S_OR(aa->syntax, "Not available"), COLOR_CYAN, 0, syntax_size);
05257 
05258    ast_cli(fd, "%s%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n\n%s%s\n",
05259          infotitle, syntitle, synopsis, destitle, description,
05260          stxtitle, syntax, argtitle, arguments, seealsotitle, seealso);
05261 
05262 return_cleanup:
05263    ast_free(description);
05264    ast_free(arguments);
05265    ast_free(synopsis);
05266    ast_free(seealso);
05267    ast_free(syntax);
05268 }

static void print_ext ( struct ast_exten *  e,
char *  buf,
int  buflen 
) [static]

helper function to print an extension

Definition at line 5619 of file pbx.c.

References ast_get_extension_app(), ast_get_extension_app_data(), ast_get_extension_priority(), ast_strlen_zero(), and PRIORITY_HINT.

Referenced by show_dialplan_helper().

05620 {
05621    int prio = ast_get_extension_priority(e);
05622    if (prio == PRIORITY_HINT) {
05623       snprintf(buf, buflen, "hint: %s",
05624          ast_get_extension_app(e));
05625    } else {
05626       snprintf(buf, buflen, "%d. %s(%s)",
05627          prio, ast_get_extension_app(e),
05628          (!ast_strlen_zero(ast_get_extension_app_data(e)) ? (char *)ast_get_extension_app_data(e) : ""));
05629    }
05630 }

static void set_ext_pri ( struct ast_channel *  c,
const char *  exten,
int  pri 
) [static]

helper function to set extension and priority

Definition at line 4186 of file pbx.c.

References ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_channel::exten, and ast_channel::priority.

Referenced by __ast_pbx_run(), ast_pbx_outgoing_exten(), pbx_builtin_raise_exception(), and pbx_builtin_waitexten().

04187 {
04188    ast_channel_lock(c);
04189    ast_copy_string(c->exten, exten, sizeof(c->exten));
04190    c->priority = pri;
04191    ast_channel_unlock(c);
04192 }

static int show_debug_helper ( int  fd,
const char *  context,
const char *  exten,
struct dialplan_counters *  dpc,
struct ast_include *  rinclude,
int  includecount,
const char *  includes[] 
) [static]

Definition at line 5784 of file pbx.c.

References ast_cli(), ast_exists_extension(), ast_get_context_name(), ast_get_context_registrar(), ast_rdlock_context(), ast_rdlock_contexts(), ast_unlock_context(), ast_unlock_contexts(), ast_walk_contexts(), cli_match_char_tree(), dialplan_counters::context_existence, ast_context::name, ast_context::pattern_tree, dialplan_counters::total_context, and dialplan_counters::total_exten.

Referenced by handle_debug_dialplan().

05785 {
05786    struct ast_context *c = NULL;
05787    int res = 0, old_total_exten = dpc->total_exten;
05788 
05789    ast_cli(fd,"\n     In-mem exten Trie for Fast Extension Pattern Matching:\n\n");
05790 
05791    ast_cli(fd,"\n           Explanation: Node Contents Format = <char(s) to match>:<pattern?>:<specif>:[matched extension]\n");
05792    ast_cli(fd,    "                        Where <char(s) to match> is a set of chars, any one of which should match the current character\n");
05793    ast_cli(fd,    "                              <pattern?>: Y if this a pattern match (eg. _XZN[5-7]), N otherwise\n");
05794    ast_cli(fd,    "                              <specif>: an assigned 'exactness' number for this matching char. The lower the number, the more exact the match\n");
05795    ast_cli(fd,    "                              [matched exten]: If all chars matched to this point, which extension this matches. In form: EXTEN:<exten string>\n");
05796    ast_cli(fd,    "                        In general, you match a trie node to a string character, from left to right. All possible matching chars\n");
05797    ast_cli(fd,    "                        are in a string vertically, separated by an unbroken string of '+' characters.\n\n");
05798    ast_rdlock_contexts();
05799 
05800    /* walk all contexts ... */
05801    while ( (c = ast_walk_contexts(c)) ) {
05802       int context_info_printed = 0;
05803 
05804       if (context && strcmp(ast_get_context_name(c), context))
05805          continue;   /* skip this one, name doesn't match */
05806 
05807       dpc->context_existence = 1;
05808 
05809       if (!c->pattern_tree)
05810          ast_exists_extension(NULL, c->name, "s", 1, ""); /* do this to force the trie to built, if it is not already */
05811 
05812       ast_rdlock_context(c);
05813 
05814       dpc->total_context++;
05815       ast_cli(fd, "[ Context '%s' created by '%s' ]\n",
05816          ast_get_context_name(c), ast_get_context_registrar(c));
05817       context_info_printed = 1;
05818 
05819       if (c->pattern_tree)
05820       {
05821          cli_match_char_tree(c->pattern_tree, " ", fd);
05822       } else {
05823          ast_cli(fd,"\n     No Pattern Trie present. Perhaps the context is empty...or there is trouble...\n\n");
05824       }
05825 
05826       ast_unlock_context(c);
05827 
05828       /* if we print something in context, make an empty line */
05829       if (context_info_printed)
05830          ast_cli(fd, "\n");
05831    }
05832    ast_unlock_contexts();
05833 
05834    return (dpc->total_exten == old_total_exten) ? -1 : res;
05835 }

static int show_dialplan_helper ( int  fd,
const char *  context,
const char *  exten,
struct dialplan_counters *  dpc,
struct ast_include *  rinclude,
int  includecount,
const char *  includes[] 
) [static]

Definition at line 5633 of file pbx.c.

References ast_cli(), ast_extension_match(), ast_get_context_name(), ast_get_context_registrar(), ast_get_extension_label(), ast_get_extension_name(), ast_get_extension_registrar(), ast_get_ignorepat_name(), ast_get_ignorepat_registrar(), ast_get_include_name(), ast_get_include_registrar(), ast_get_switch_data(), ast_get_switch_name(), ast_get_switch_registrar(), ast_log(), AST_MAX_EXTENSION, AST_PBX_MAX_STACK, ast_rdlock_context(), ast_rdlock_contexts(), ast_unlock_context(), ast_unlock_contexts(), ast_walk_context_extensions(), ast_walk_context_ignorepats(), ast_walk_context_includes(), ast_walk_context_switches(), ast_walk_contexts(), ast_walk_extension_priorities(), buf, buf2, ast_exten::cidmatch, dialplan_counters::context_existence, el, dialplan_counters::extension_existence, LOG_WARNING, ast_exten::matchcid, print_ext(), dialplan_counters::total_context, dialplan_counters::total_exten, and dialplan_counters::total_prio.

Referenced by handle_show_dialplan().

05634 {
05635    struct ast_context *c = NULL;
05636    int res = 0, old_total_exten = dpc->total_exten;
05637 
05638    ast_rdlock_contexts();
05639 
05640    /* walk all contexts ... */
05641    while ( (c = ast_walk_contexts(c)) ) {
05642       struct ast_exten *e;
05643       struct ast_include *i;
05644       struct ast_ignorepat *ip;
05645       char buf[256], buf2[256];
05646       int context_info_printed = 0;
05647 
05648       if (context && strcmp(ast_get_context_name(c), context))
05649          continue;   /* skip this one, name doesn't match */
05650 
05651       dpc->context_existence = 1;
05652 
05653       ast_rdlock_context(c);
05654 
05655       /* are we looking for exten too? if yes, we print context
05656        * only if we find our extension.
05657        * Otherwise print context even if empty ?
05658        * XXX i am not sure how the rinclude is handled.
05659        * I think it ought to go inside.
05660        */
05661       if (!exten) {
05662          dpc->total_context++;
05663          ast_cli(fd, "[ Context '%s' created by '%s' ]\n",
05664             ast_get_context_name(c), ast_get_context_registrar(c));
05665          context_info_printed = 1;
05666       }
05667 
05668       /* walk extensions ... */
05669       e = NULL;
05670       while ( (e = ast_walk_context_extensions(c, e)) ) {
05671          struct ast_exten *p;
05672 
05673          if (exten && !ast_extension_match(ast_get_extension_name(e), exten))
05674             continue;   /* skip, extension match failed */
05675 
05676          dpc->extension_existence = 1;
05677 
05678          /* may we print context info? */
05679          if (!context_info_printed) {
05680             dpc->total_context++;
05681             if (rinclude) { /* TODO Print more info about rinclude */
05682                ast_cli(fd, "[ Included context '%s' created by '%s' ]\n",
05683                   ast_get_context_name(c), ast_get_context_registrar(c));
05684             } else {
05685                ast_cli(fd, "[ Context '%s' created by '%s' ]\n",
05686                   ast_get_context_name(c), ast_get_context_registrar(c));
05687             }
05688             context_info_printed = 1;
05689          }
05690          dpc->total_prio++;
05691 
05692          /* write extension name and first peer */
05693          if (e->matchcid)
05694             snprintf(buf, sizeof(buf), "'%s' (CID match '%s') => ", ast_get_extension_name(e), e->cidmatch);
05695          else
05696             snprintf(buf, sizeof(buf), "'%s' =>", ast_get_extension_name(e));
05697 
05698          print_ext(e, buf2, sizeof(buf2));
05699 
05700          ast_cli(fd, "  %-17s %-45s [%s]\n", buf, buf2,
05701             ast_get_extension_registrar(e));
05702 
05703          dpc->total_exten++;
05704          /* walk next extension peers */
05705          p = e;   /* skip the first one, we already got it */
05706          while ( (p = ast_walk_extension_priorities(e, p)) ) {
05707             const char *el = ast_get_extension_label(p);
05708             dpc->total_prio++;
05709             if (el)
05710                snprintf(buf, sizeof(buf), "   [%s]", el);
05711             else
05712                buf[0] = '\0';
05713             print_ext(p, buf2, sizeof(buf2));
05714 
05715             ast_cli(fd,"  %-17s %-45s [%s]\n", buf, buf2,
05716                ast_get_extension_registrar(p));
05717          }
05718       }
05719 
05720       /* walk included and write info ... */
05721       i = NULL;
05722       while ( (i = ast_walk_context_includes(c, i)) ) {
05723          snprintf(buf, sizeof(buf), "'%s'", ast_get_include_name(i));
05724          if (exten) {
05725             /* Check all includes for the requested extension */
05726             if (includecount >= AST_PBX_MAX_STACK) {
05727                ast_log(LOG_WARNING, "Maximum include depth exceeded!\n");
05728             } else {
05729                int dupe = 0;
05730                int x;
05731                for (x = 0; x < includecount; x++) {
05732                   if (!strcasecmp(includes[x], ast_get_include_name(i))) {
05733                      dupe++;
05734                      break;
05735                   }
05736                }
05737                if (!dupe) {
05738                   includes[includecount] = ast_get_include_name(i);
05739                   show_dialplan_helper(fd, ast_get_include_name(i), exten, dpc, i, includecount + 1, includes);
05740                } else {
05741                   ast_log(LOG_WARNING, "Avoiding circular include of %s within %s\n", ast_get_include_name(i), context);
05742                }
05743             }
05744          } else {
05745             ast_cli(fd, "  Include =>        %-45s [%s]\n",
05746                buf, ast_get_include_registrar(i));
05747          }
05748       }
05749 
05750       /* walk ignore patterns and write info ... */
05751       ip = NULL;
05752       while ( (ip = ast_walk_context_ignorepats(c, ip)) ) {
05753          const char *ipname = ast_get_ignorepat_name(ip);
05754          char ignorepat[AST_MAX_EXTENSION];
05755          snprintf(buf, sizeof(buf), "'%s'", ipname);
05756          snprintf(ignorepat, sizeof(ignorepat), "_%s.", ipname);
05757          if (!exten || ast_extension_match(ignorepat, exten)) {
05758             ast_cli(fd, "  Ignore pattern => %-45s [%s]\n",
05759                buf, ast_get_ignorepat_registrar(ip));
05760          }
05761       }
05762       if (!rinclude) {
05763          struct ast_sw *sw = NULL;
05764          while ( (sw = ast_walk_context_switches(c, sw)) ) {
05765             snprintf(buf, sizeof(buf), "'%s/%s'",
05766                ast_get_switch_name(sw),
05767                ast_get_switch_data(sw));
05768             ast_cli(fd, "  Alt. Switch =>    %-45s [%s]\n",
05769                buf, ast_get_switch_registrar(sw));
05770          }
05771       }
05772 
05773       ast_unlock_context(c);
05774 
05775       /* if we print something in context, make an empty line */
05776       if (context_info_printed)
05777          ast_cli(fd, "\n");
05778    }
05779    ast_unlock_contexts();
05780 
05781    return (dpc->total_exten == old_total_exten) ? -1 : res;
05782 }

static char* substring ( const char *  value,
int  offset,
int  length,
char *  workspace,
size_t  workspace_len 
) [static]

takes a substring. It is ok to call with value == workspace.

Parameters:
value 
offset < 0 means start from the end of the string and set the beginning to be that many characters back.
length is the length of the substring, a value less than 0 means to leave that many off the end.
workspace 
workspace_len Always return a copy in workspace.

Definition at line 2825 of file pbx.c.

References ast_copy_string().

Referenced by pbx_retrieve_variable(), and pbx_substitute_variables_helper_full().

02826 {
02827    char *ret = workspace;
02828    int lr;  /* length of the input string after the copy */
02829 
02830    ast_copy_string(workspace, value, workspace_len); /* always make a copy */
02831 
02832    lr = strlen(ret); /* compute length after copy, so we never go out of the workspace */
02833 
02834    /* Quick check if no need to do anything */
02835    if (offset == 0 && length >= lr) /* take the whole string */
02836       return ret;
02837 
02838    if (offset < 0)   {  /* translate negative offset into positive ones */
02839       offset = lr + offset;
02840       if (offset < 0) /* If the negative offset was greater than the length of the string, just start at the beginning */
02841          offset = 0;
02842    }
02843 
02844    /* too large offset result in empty string so we know what to return */
02845    if (offset >= lr)
02846       return ret + lr;  /* the final '\0' */
02847 
02848    ret += offset;    /* move to the start position */
02849    if (length >= 0 && length < lr - offset)  /* truncate if necessary */
02850       ret[length] = '\0';
02851    else if (length < 0) {
02852       if (lr > offset - length) /* After we remove from the front and from the rear, is there anything left? */
02853          ret[lr + length - offset] = '\0';
02854       else
02855          ret[0] = '\0';
02856    }
02857 
02858    return ret;
02859 }

static struct ast_exten* trie_find_next_match ( struct match_char *  node  )  [static, read]

Definition at line 1571 of file pbx.c.

References match_char::alt_char, match_char::exten, match_char::next_char, and match_char::x.

Referenced by pbx_find_extension().

01572 {
01573    struct match_char *m3;
01574    struct match_char *m4;
01575    struct ast_exten *e3;
01576 
01577    if (node && node->x[0] == '.' && !node->x[1]) { /* dot and ! will ALWAYS be next match in a matchmore */
01578       return node->exten;
01579    }
01580 
01581    if (node && node->x[0] == '!' && !node->x[1]) {
01582       return node->exten;
01583    }
01584 
01585    if (!node || !node->next_char) {
01586       return NULL;
01587    }
01588 
01589    m3 = node->next_char;
01590 
01591    if (m3->exten) {
01592       return m3->exten;
01593    }
01594    for (m4 = m3->alt_char; m4; m4 = m4->alt_char) {
01595       if (m4->exten) {
01596          return m4->exten;
01597       }
01598    }
01599    for (m4 = m3; m4; m4 = m4->alt_char) {
01600       e3 = trie_find_next_match(m3);
01601       if (e3) {
01602          return e3;
01603       }
01604    }
01605    return NULL;
01606 }

static void unreference_cached_app ( struct ast_app *  app  )  [static]

Definition at line 6396 of file pbx.c.

References ast_rdlock_contexts(), ast_unlock_contexts(), ast_walk_context_extensions(), ast_walk_contexts(), and ast_walk_extension_priorities().

Referenced by ast_unregister_application().

06397 {
06398    struct ast_context *context = NULL;
06399    struct ast_exten *eroot = NULL, *e = NULL;
06400 
06401    ast_rdlock_contexts();
06402    while ((context = ast_walk_contexts(context))) {
06403       while ((eroot = ast_walk_context_extensions(context, eroot))) {
06404          while ((e = ast_walk_extension_priorities(eroot, e))) {
06405             if (e->cached_app == app)
06406                e->cached_app = NULL;
06407          }
06408       }
06409    }
06410    ast_unlock_contexts();
06411 
06412    return;
06413 }

static void update_scoreboard ( struct scoreboard *  board,
int  length,
int  spec,
struct ast_exten *  exten,
char  last,
const char *  callerid,
int  deleted,
struct match_char *  node 
) [static]

Definition at line 1478 of file pbx.c.

References ast_log(), ast_exten::exten, scoreboard::exten, scoreboard::last_char, LOG_NOTICE, scoreboard::node, scoreboard::total_length, and scoreboard::total_specificity.

Referenced by new_find_extension().

01479 {
01480    /* if this extension is marked as deleted, then skip this -- if it never shows
01481       on the scoreboard, it will never be found, nor will halt the traversal. */
01482    if (deleted)
01483       return;
01484    board->total_specificity = spec;
01485    board->total_length = length;
01486    board->exten = exten;
01487    board->last_char = last;
01488    board->node = node;
01489 #ifdef NEED_DEBUG_HERE
01490    ast_log(LOG_NOTICE,"Scoreboarding (LONGER) %s, len=%d, score=%d\n", exten->exten, length, spec);
01491 #endif
01492 }

static void wait_for_hangup ( struct ast_channel *  chan,
void *  data 
) [static]

Definition at line 8434 of file pbx.c.

References ast_frfree, ast_read(), ast_safe_sleep(), ast_strlen_zero(), ast_waitfor(), and f.

Referenced by pbx_builtin_busy(), and pbx_builtin_congestion().

08435 {
08436    int res;
08437    struct ast_frame *f;
08438    double waitsec;
08439    int waittime;
08440 
08441    if (ast_strlen_zero(data) || (sscanf(data, "%30lg", &waitsec) != 1) || (waitsec < 0))
08442       waitsec = -1;
08443    if (waitsec > -1) {
08444       waittime = waitsec * 1000.0;
08445       ast_safe_sleep(chan, waittime);
08446    } else do {
08447       res = ast_waitfor(chan, -1);
08448       if (res < 0)
08449          return;
08450       f = ast_read(chan);
08451       if (f)
08452          ast_frfree(f);
08453    } while(f);
08454 }


Variable Documentation

int autofallthrough = 1 [static]

Definition at line 1069 of file pbx.c.

Referenced by __ast_pbx_run(), and pbx_set_autofallthrough().

struct ast_app_option background_opts[128] = { [ 's' ] = { .flag = (1 << 0) }, [ 'n' ] = { .flag = (1 << 1) }, [ 'm' ] = { .flag = (1 << 2) }, [ 'p' ] = { .flag = (1 << 3) },} [static]

Definition at line 745 of file pbx.c.

Referenced by pbx_builtin_background().

struct pbx_builtin builtins[] [static]

Declaration of builtin applications.

Referenced by load_pbx().

ast_rwlock_t conlock = PTHREAD_RWLOCK_INITIALIZER [static]

Lock for the ast_context list

Definition at line 1122 of file pbx.c.

Referenced by ast_rdlock_contexts(), ast_unlock_contexts(), and ast_wrlock_contexts().

int conlock_wrlock_version = 0 [static]

Definition at line 9347 of file pbx.c.

Referenced by ast_wrlock_contexts(), and ast_wrlock_contexts_version().

struct ast_context* contexts [static]

struct ast_hashtab* contexts_table = NULL [static]

int countcalls [static]

Definition at line 1077 of file pbx.c.

Referenced by ast_active_calls(), decrease_call_count(), and increase_call_count().

char* days[] [static]

Definition at line 6922 of file pbx.c.

Referenced by ast_build_timing().

struct ast_event_sub* device_state_sub [static]

Subscription for device state change events.

Definition at line 1074 of file pbx.c.

Referenced by load_pbx().

Definition at line 758 of file pbx.c.

Initial value:

 {
   .name = "EXCEPTION",
   .read = acf_exception_read,
}

Definition at line 3048 of file pbx.c.

Referenced by load_pbx().

Initial value:

 {
   .type = "EXCEPTION",
   .destroy = exception_store_free,
}

Definition at line 2990 of file pbx.c.

Referenced by acf_exception_read(), and pbx_builtin_raise_exception().

int extenpatternmatchnew = 0 [static]

Definition at line 1070 of file pbx.c.

Referenced by pbx_find_extension(), and pbx_set_extenpatternmatchnew().

Referenced by ast_extension_state2str().

struct ast_threadstorage extensionstate_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_extensionstate_buf , .custom_init = NULL , } [static]

Definition at line 761 of file pbx.c.

Referenced by ast_extension_state2().

struct varshead globals = AST_LIST_HEAD_NOLOCK_INIT_VALUE [static]

ast_rwlock_t globalslock = PTHREAD_RWLOCK_INITIALIZER [static]

char mandescr_show_dialplan[] [static]

Definition at line 6159 of file pbx.c.

Referenced by load_pbx().

ast_mutex_t maxcalllock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) [static]

Definition at line 1076 of file pbx.c.

Referenced by decrease_call_count(), and increase_call_count().

char* months[] [static]

Definition at line 6934 of file pbx.c.

Referenced by ast_build_timing().

char* overrideswitch = NULL [static]

Definition at line 1071 of file pbx.c.

Referenced by handle_cli_dialplan_save(), pbx_find_extension(), and pbx_set_overrideswitch().

struct ast_cli_entry pbx_cli[] [static]

Definition at line 6375 of file pbx.c.

Referenced by load_pbx().

struct ast_app_option resetcdr_opts[128] = { [ 'w' ] = { .flag = (1 << 1) }, [ 'a' ] = { .flag = (1 << 2) }, [ 'v' ] = { .flag = (1 << 0) }, [ 'e' ] = { .flag = (1 << 10) },} [static]

Definition at line 8573 of file pbx.c.

Referenced by pbx_builtin_resetcdr().

int stateid = 1 [static]

Definition at line 1128 of file pbx.c.

Referenced by ast_extension_state_add().

struct ast_threadstorage switch_data = { .once = PTHREAD_ONCE_INIT , .key_init = __init_switch_data , .custom_init = NULL , } [static]

Definition at line 760 of file pbx.c.

Referenced by pbx_find_extension().

int totalcalls [static]

Definition at line 1078 of file pbx.c.

Referenced by ast_processed_calls(), increase_call_count(), and timing_read().

struct ast_app_option waitexten_opts[128] = { [ 'm' ] = { .flag = (1 << 0) , .arg_index = 0 + 1 }, [ 'd' ] = { .flag = (1 << 1) , .arg_index = 0 + 1 },} [static]

Definition at line 753 of file pbx.c.

Referenced by pbx_builtin_waitexten().


Generated on Wed Aug 11 01:09:33 2010 for Asterisk - the Open Source PBX by  doxygen 1.5.9