Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
extconf.c File Reference
#include "asterisk.h"
#include "asterisk/compat.h"
#include "asterisk/paths.h"
#include <errno.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <stdarg.h>
#include <string.h>
#include <locale.h>
#include <ctype.h>
#include <err.h>
#include <regex.h>
#include <limits.h>
#include <pthread.h>
#include <netdb.h>
#include <sys/param.h>
#include <signal.h>
#include "asterisk/inline_api.h"
#include "asterisk/endian.h"
#include "asterisk/ast_expr.h"
#include "asterisk/extconf.h"
#include "asterisk/hashtab.h"
#include "asterisk/ael_structs.h"
#include "asterisk/pval.h"

Go to the source code of this file.

Data Structures

struct  ast_app
 ast_app: A registered application More...
 
struct  ast_category
 
struct  ast_channel
 Main Channel structure associated with a channel. More...
 
struct  ast_comment
 Structure to keep comments for rewriting configuration files. More...
 
struct  ast_config
 
struct  ast_config_engine
 Configuration engine structure, used to define realtime drivers. More...
 
struct  ast_config_include
 
struct  ast_config_map
 
struct  ast_context
 ast_context: An extension context More...
 
struct  ast_custom_function
 Data structure associated with a custom dialplan function. 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_flags
 Structure used to handle boolean flags. 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  ast_switch
 
struct  ast_timing
 
struct  ast_var_t
 
struct  ast_variable
 Structure for variables, used for configurations and for channel variables. More...
 
struct  hints
 
struct  store_hint
 
struct  store_hints
 
struct  varshead
 

Macros

#define __AST_MUTEX_DEFINE(scope, mutex)   scope ast_mutex_t mutex = AST_MUTEX_INIT_VALUE
 
#define __AST_RWLOCK_DEFINE(scope, rwlock)   scope ast_rwlock_t rwlock = AST_RWLOCK_INIT_VALUE
 
#define __LOG_DEBUG   0
 
#define __LOG_DTMF   6
 
#define __LOG_ERROR   4
 
#define __LOG_EVENT   1
 
#define __LOG_NOTICE   2
 
#define __LOG_VERBOSE   5
 
#define __LOG_WARNING   3
 
#define __MTX_PROF(a)   return pthread_mutex_lock((a))
 
#define _A_   __FILE__, __LINE__, __PRETTY_FUNCTION__
 
#define _ASTERISK_LOCK_H   /* A small indication that this is horribly wrong. */
 
#define AST_API_MODULE   1 /* gimme the inline defs! */
 
#define AST_CACHE_DIR_LEN   512
 
#define AST_DEFAULT_OPTIONS   AST_OPT_FLAG_TRANSCODE_VIA_SLIN
 
#define AST_FILENAME_MAX   80
 
#define ast_fully_booted   ast_test_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED)
 
#define AST_LIST_APPEND_LIST(head, list, field)
 Appends a whole list to the tail of a list. More...
 
#define AST_LIST_EMPTY(head)   (AST_LIST_FIRST(head) == NULL)
 Checks whether the specified list contains any entries. More...
 
#define AST_LIST_ENTRY(type)
 Declare a forward link structure inside a list entry. More...
 
#define AST_LIST_FIRST(head)   ((head)->first)
 Returns the first entry contained in a list. More...
 
#define AST_LIST_HEAD(name, type)
 Defines a structure to be used to hold a list of specified type. More...
 
#define AST_LIST_HEAD_INIT(head)
 Initializes a list head structure. More...
 
#define AST_LIST_HEAD_INIT_NOLOCK(head)
 Initializes a list head structure. More...
 
#define AST_LIST_HEAD_INIT_VALUE
 Defines initial values for a declaration of AST_LIST_HEAD. More...
 
#define AST_LIST_HEAD_NOLOCK(name, type)
 Defines a structure to be used to hold a list of specified type (with no lock). More...
 
#define AST_LIST_HEAD_NOLOCK_INIT_VALUE
 Defines initial values for a declaration of AST_LIST_HEAD_NOLOCK. More...
 
#define AST_LIST_HEAD_NOLOCK_STATIC(name, type)
 Defines a structure to be used to hold a list of specified type, statically initialized. More...
 
#define AST_LIST_HEAD_SET(head, entry)
 Initializes a list head structure with a specified first entry. More...
 
#define AST_LIST_HEAD_SET_NOLOCK(head, entry)
 Initializes a list head structure with a specified first entry. More...
 
#define AST_LIST_HEAD_STATIC(name, type)
 Defines a structure to be used to hold a list of specified type, statically initialized. More...
 
#define AST_LIST_INSERT_AFTER(head, listelm, elm, field)
 Inserts a list entry after a given entry. More...
 
#define AST_LIST_INSERT_BEFORE_CURRENT(head, elm, field)
 Inserts a list entry before the current entry during a traversal. More...
 
#define AST_LIST_INSERT_HEAD(head, elm, field)
 Inserts a list entry at the head of a list. More...
 
#define AST_LIST_INSERT_TAIL(head, elm, field)
 Appends a list entry to the tail of a list. More...
 
#define AST_LIST_LAST(head)   ((head)->last)
 Returns the last entry contained in a list. More...
 
#define AST_LIST_NEXT(elm, field)   ((elm)->field.next)
 Returns the next entry in the list after the given entry. More...
 
#define AST_LIST_REMOVE(head, elm, field)
 Removes a specific entry from a list. More...
 
#define AST_LIST_REMOVE_CURRENT(head, field)
 Removes the current entry from a list during a traversal. More...
 
#define AST_LIST_REMOVE_HEAD(head, field)
 Removes and returns the head entry from a list. More...
 
#define AST_LIST_TRAVERSE(head, var, field)   for((var) = (head)->first; (var); (var) = (var)->field.next)
 Loops over (traverses) the entries in a list. More...
 
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
 Loops safely over (traverses) the entries in a list. More...
 
#define AST_LIST_TRAVERSE_SAFE_END   }
 Closes a safe loop traversal block.
 
#define AST_MAX_EXTENSION   80
 
#define AST_MUTEX_DEFINE_STATIC(mutex)   __AST_MUTEX_DEFINE(static, mutex)
 
#define AST_MUTEX_INIT_VALUE   ((ast_mutex_t) PTHREAD_MUTEX_INIT_VALUE)
 
#define AST_MUTEX_INITIALIZER   __use_AST_MUTEX_DEFINE_STATIC_rather_than_AST_MUTEX_INITIALIZER__
 
#define AST_MUTEX_KIND   PTHREAD_MUTEX_RECURSIVE
 
#define ast_opt_always_fork   ast_test_flag(&ast_options, AST_OPT_FLAG_ALWAYS_FORK)
 
#define ast_opt_cache_record_files   ast_test_flag(&ast_options, AST_OPT_FLAG_CACHE_RECORD_FILES)
 
#define ast_opt_console   ast_test_flag(&ast_options, AST_OPT_FLAG_CONSOLE)
 
#define ast_opt_dont_warn   ast_test_flag(&ast_options, AST_OPT_FLAG_DONT_WARN)
 
#define ast_opt_dump_core   ast_test_flag(&ast_options, AST_OPT_FLAG_DUMP_CORE)
 
#define ast_opt_exec   ast_test_flag(&ast_options, AST_OPT_FLAG_EXEC)
 
#define ast_opt_exec_includes   ast_test_flag(&ast_options, AST_OPT_FLAG_EXEC_INCLUDES)
 
#define ast_opt_high_priority   ast_test_flag(&ast_options, AST_OPT_FLAG_HIGH_PRIORITY)
 
#define ast_opt_init_keys   ast_test_flag(&ast_options, AST_OPT_FLAG_INIT_KEYS)
 
#define ast_opt_mute   ast_test_flag(&ast_options, AST_OPT_FLAG_MUTE)
 
#define ast_opt_no_color   ast_test_flag(&ast_options, AST_OPT_FLAG_NO_COLOR)
 
#define ast_opt_no_fork   ast_test_flag(&ast_options, AST_OPT_FLAG_NO_FORK)
 
#define ast_opt_override_config   ast_test_flag(&ast_options, AST_OPT_FLAG_OVERRIDE_CONFIG)
 
#define ast_opt_priority_jumping   ast_test_flag(&ast_options, AST_OPT_FLAG_PRIORITY_JUMPING)
 
#define ast_opt_quiet   ast_test_flag(&ast_options, AST_OPT_FLAG_QUIET)
 
#define ast_opt_reconnect   ast_test_flag(&ast_options, AST_OPT_FLAG_RECONNECT)
 
#define ast_opt_remote   ast_test_flag(&ast_options, AST_OPT_FLAG_REMOTE)
 
#define ast_opt_timestamp   ast_test_flag(&ast_options, AST_OPT_FLAG_TIMESTAMP)
 
#define ast_opt_transcode_via_slin   ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSCODE_VIA_SLIN)
 
#define ast_opt_transmit_silence   ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSMIT_SILENCE)
 
#define ast_pthread_mutex_init(pmutex, a)   pthread_mutex_init(pmutex,a)
 
#define AST_PTHREADT_NULL   (pthread_t) -1
 
#define AST_PTHREADT_STOP   (pthread_t) -2
 
#define AST_RWLIST_APPEND_LIST   AST_LIST_APPEND_LIST
 
#define AST_RWLIST_EMPTY   AST_LIST_EMPTY
 
#define AST_RWLIST_ENTRY   AST_LIST_ENTRY
 
#define AST_RWLIST_FIRST   AST_LIST_FIRST
 
#define AST_RWLIST_HEAD(name, type)
 Defines a structure to be used to hold a read/write list of specified type. More...
 
#define AST_RWLIST_HEAD_DESTROY(head)
 Destroys an rwlist head structure. More...
 
#define AST_RWLIST_HEAD_INIT(head)
 Initializes an rwlist head structure. More...
 
#define AST_RWLIST_HEAD_INIT_VALUE
 Defines initial values for a declaration of AST_RWLIST_HEAD. More...
 
#define AST_RWLIST_HEAD_SET(head, entry)
 Initializes an rwlist head structure with a specified first entry. More...
 
#define AST_RWLIST_HEAD_STATIC(name, type)
 Defines a structure to be used to hold a read/write list of specified type, statically initialized. More...
 
#define AST_RWLIST_INSERT_AFTER   AST_LIST_INSERT_AFTER
 
#define AST_RWLIST_INSERT_BEFORE_CURRENT   AST_LIST_INSERT_BEFORE_CURRENT
 
#define AST_RWLIST_INSERT_HEAD   AST_LIST_INSERT_HEAD
 
#define AST_RWLIST_INSERT_TAIL   AST_LIST_INSERT_TAIL
 
#define AST_RWLIST_LAST   AST_LIST_LAST
 
#define AST_RWLIST_NEXT   AST_LIST_NEXT
 
#define AST_RWLIST_RDLOCK(head)    ast_rwlock_rdlock(&(head)->lock)
 Read locks a list. More...
 
#define AST_RWLIST_REMOVE   AST_LIST_REMOVE
 
#define AST_RWLIST_REMOVE_CURRENT   AST_LIST_REMOVE_CURRENT
 
#define AST_RWLIST_REMOVE_HEAD   AST_LIST_REMOVE_HEAD
 
#define AST_RWLIST_TRAVERSE   AST_LIST_TRAVERSE
 
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN   AST_LIST_TRAVERSE_SAFE_BEGIN
 
#define AST_RWLIST_TRAVERSE_SAFE_END   AST_LIST_TRAVERSE_SAFE_END
 
#define AST_RWLIST_UNLOCK(head)    ast_rwlock_unlock(&(head)->lock)
 Attempts to unlock a read/write based list. More...
 
#define AST_RWLIST_WRLOCK(head)    ast_rwlock_wrlock(&(head)->lock)
 Write locks a list. More...
 
#define AST_RWLOCK_DEFINE_STATIC(rwlock)   __AST_RWLOCK_DEFINE(static, rwlock)
 
#define AST_RWLOCK_INIT_VALUE   PTHREAD_RWLOCK_INITIALIZER
 
#define ast_set2_flag(p, value, flag)
 
#define ast_test_flag(p, flag)
 
#define ASTMM_LIBC   ASTMM_IGNORE
 
#define BACKGROUND_MATCHEXTEN   (1 << 2)
 
#define BACKGROUND_NOANSWER   (1 << 1)
 
#define BACKGROUND_PLAYBACK   (1 << 3)
 
#define BACKGROUND_SKIP   (1 << 0)
 
#define CB_INCR   250
 
#define COMMENT_END   "--;"
 
#define COMMENT_META   ';'
 
#define COMMENT_START   ";--"
 
#define COMMENT_TAG   '-'
 
#define DEBUG_M(a)
 
#define EVENTLOG   "event_log"
 
#define EXT_DATA_SIZE   8192
 
#define gethostbyname   __gethostbyname__is__not__reentrant__use__ast_gethostbyname__instead__
 
#define LOG_DEBUG   __LOG_DEBUG, _A_
 
#define LOG_DTMF   __LOG_DTMF, _A_
 
#define LOG_ERROR   __LOG_ERROR, _A_
 
#define LOG_EVENT   __LOG_EVENT, _A_
 
#define LOG_NOTICE   __LOG_NOTICE, _A_
 
#define LOG_VERBOSE   __LOG_VERBOSE, _A_
 
#define LOG_WARNING   __LOG_WARNING, _A_
 
#define MAX_INCLUDE_LEVEL   10
 
#define MAX_NESTED_COMMENTS   128
 
#define ONE_MILLION   1000000
 
#define PRIORITY_HINT   -1
 
#define pthread_cond_t   use_ast_cond_t_instead_of_pthread_cond_t
 
#define pthread_create   __use_ast_pthread_create_instead__
 
#define pthread_mutex_init   use_ast_mutex_init_instead_of_pthread_mutex_init
 
#define PTHREAD_MUTEX_INIT_VALUE   PTHREAD_MUTEX_INITIALIZER
 
#define pthread_mutex_t   use_ast_mutex_t_instead_of_pthread_mutex_t
 
#define QUEUELOG   "queue_log"
 
#define S_OR(a, b)   (!ast_strlen_zero(a) ? (a) : (b))
 
#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 VERBOSE_PREFIX_1   " "
 
#define VERBOSE_PREFIX_2   " == "
 
#define VERBOSE_PREFIX_3   " -- "
 
#define VERBOSE_PREFIX_4   " > "
 

Typedefs

typedef pthread_cond_t ast_cond_t
 
typedef pthread_mutex_t ast_mutex_t
 
typedef pthread_rwlock_t ast_rwlock_t
 
typedef int(* ast_state_cb_type) (char *context, char *id, enum ast_extension_states state, void *data)
 
typedef int( ast_switch_f) (struct ast_channel *chan, const char *context, const char *exten, int priority, const char *callerid, const char *data)
 
typedef struct ast_configconfig_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config, int withcomments, const char *suggested_include_file)
 
typedef struct ast_configrealtime_multi_get(const char *database, const char *table, va_list ap)
 
typedef int realtime_update(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap)
 
typedef struct ast_variablerealtime_var_get(const char *database, const char *table, va_list ap)
 

Enumerations

enum  ast_extension_states {
  AST_EXTENSION_REMOVED = -2, AST_EXTENSION_DEACTIVATED = -1, AST_EXTENSION_NOT_INUSE = 0, AST_EXTENSION_INUSE = 1 << 0,
  AST_EXTENSION_BUSY = 1 << 1, AST_EXTENSION_UNAVAILABLE = 1 << 2, AST_EXTENSION_RINGING = 1 << 3, AST_EXTENSION_ONHOLD = 1 << 4,
  AST_EXTENSION_REMOVED = -2, AST_EXTENSION_DEACTIVATED = -1, AST_EXTENSION_NOT_INUSE = 0, AST_EXTENSION_INUSE = 1 << 0,
  AST_EXTENSION_BUSY = 1 << 1, AST_EXTENSION_UNAVAILABLE = 1 << 2, AST_EXTENSION_RINGING = 1 << 3, AST_EXTENSION_ONHOLD = 1 << 4
}
 
enum  ast_option_flags {
  AST_OPT_FLAG_EXEC_INCLUDES = (1 << 0), AST_OPT_FLAG_NO_FORK = (1 << 1), AST_OPT_FLAG_QUIET = (1 << 2), AST_OPT_FLAG_CONSOLE = (1 << 3),
  AST_OPT_FLAG_HIGH_PRIORITY = (1 << 4), AST_OPT_FLAG_INIT_KEYS = (1 << 5), AST_OPT_FLAG_REMOTE = (1 << 6), AST_OPT_FLAG_EXEC = (1 << 7),
  AST_OPT_FLAG_NO_COLOR = (1 << 8), AST_OPT_FLAG_FULLY_BOOTED = (1 << 9), AST_OPT_FLAG_TRANSCODE_VIA_SLIN = (1 << 10), AST_OPT_FLAG_STDEXTEN_MACRO = (1 << 11),
  AST_OPT_FLAG_DUMP_CORE = (1 << 12), AST_OPT_FLAG_CACHE_RECORD_FILES = (1 << 13), AST_OPT_FLAG_TIMESTAMP = (1 << 14), AST_OPT_FLAG_CACHE_MEDIA_FRAMES = (1 << 15),
  AST_OPT_FLAG_RECONNECT = (1 << 16), AST_OPT_FLAG_TRANSMIT_SILENCE = (1 << 17), AST_OPT_FLAG_DONT_WARN = (1 << 18), AST_OPT_FLAG_SOUNDS_SEARCH_CUSTOM = (1 << 19),
  AST_OPT_FLAG_REF_DEBUG = (1 << 20), AST_OPT_FLAG_ALWAYS_FORK = (1 << 21), AST_OPT_FLAG_MUTE = (1 << 22), AST_OPT_FLAG_DEBUG_MODULE = (1 << 23),
  AST_OPT_FLAG_TRACE_MODULE = (1 << 24), AST_OPT_FLAG_LIGHT_BACKGROUND = (1 << 25), AST_OPT_FLAG_HIDE_MESSAGING_AMI_EVENTS = (1 << 26), AST_OPT_FLAG_FORCE_BLACK_BACKGROUND = (1 << 27),
  AST_OPT_FLAG_HIDE_CONSOLE_CONNECT = (1 << 28), AST_OPT_FLAG_LOCK_CONFIG_DIR = (1 << 29), AST_OPT_FLAG_GENERIC_PLC = (1 << 30), AST_OPT_FLAG_GENERIC_PLC_ON_EQUAL_CODECS = (1 << 31),
  AST_OPT_FLAG_EXEC_INCLUDES = (1 << 0), AST_OPT_FLAG_NO_FORK = (1 << 1), AST_OPT_FLAG_QUIET = (1 << 2), AST_OPT_FLAG_CONSOLE = (1 << 3),
  AST_OPT_FLAG_HIGH_PRIORITY = (1 << 4), AST_OPT_FLAG_INIT_KEYS = (1 << 5), AST_OPT_FLAG_REMOTE = (1 << 6), AST_OPT_FLAG_EXEC = (1 << 7),
  AST_OPT_FLAG_NO_COLOR = (1 << 8), AST_OPT_FLAG_FULLY_BOOTED = (1 << 9), AST_OPT_FLAG_TRANSCODE_VIA_SLIN = (1 << 10), AST_OPT_FLAG_DUMP_CORE = (1 << 12),
  AST_OPT_FLAG_CACHE_RECORD_FILES = (1 << 13), AST_OPT_FLAG_TIMESTAMP = (1 << 14), AST_OPT_FLAG_OVERRIDE_CONFIG = (1 << 15), AST_OPT_FLAG_RECONNECT = (1 << 16),
  AST_OPT_FLAG_TRANSMIT_SILENCE = (1 << 17), AST_OPT_FLAG_DONT_WARN = (1 << 18), AST_OPT_FLAG_ALWAYS_FORK = (1 << 21), AST_OPT_FLAG_MUTE = (1 << 22),
  AST_OPT_FLAG_DEBUG_FILE = (1 << 23), AST_OPT_FLAG_LIGHT_BACKGROUND = (1 << 25), AST_OPT_FLAG_FORCE_BLACK_BACKGROUND = (1 << 27)
}
 

Functions

static struct ast_context__ast_context_create (struct ast_context **extcontexts, const char *name, const char *registrar, int existsokay)
 
static void __ast_context_destroy (struct ast_context *con, const char *registrar)
 
static int _extension_match_core (const char *pattern, const char *data, enum ext_match_t mode)
 
static void _null_sig_handler (int sig)
 NULL handler so we can collect the child exit status.
 
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. returns 0 on success, -1 on failure
 
static struct ast_commentALLOC_COMMENT (const char *buffer)
 
static 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. More...
 
static int ast_add_hint (struct ast_exten *e)
 ast_add_hint: Add hint to hint list, check initial extension state
 
static unsigned int ast_app_separate_args (char *buf, char delim, char **array, int arraylen)
 
int ast_atomic_dec_and_test (volatile int *p)
 decrement *p by 1 and return true if the variable has reached 0. Useful e.g. to check if a refcount has reached 0.
 
int ast_atomic_fetchadd_int (volatile int *p, int v)
 Atomically add v to *p and return * the previous value of *p. This can be used to handle reference counts, and the return value can be used to generate unique identifiers.
 
int ast_build_timing (struct ast_timing *i, const char *info_in)
 Construct a timing bitmap, for use in time-based conditionals. More...
 
static void ast_category_append (struct ast_config *config, struct ast_category *category)
 
static char * ast_category_browse (struct ast_config *config, const char *prev)
 
static void ast_category_destroy (struct ast_category *cat)
 
static struct ast_categoryast_category_get (const struct ast_config *config, const char *category_name)
 
static struct ast_categoryast_category_new (const char *name, const char *in_file, int lineno)
 
static int ast_change_hint (struct ast_exten *oe, struct ast_exten *ne)
 ast_change_hint: 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. More...
 
static void ast_config_destroy (struct ast_config *cfg)
 
struct ast_categoryast_config_get_current_category (const struct ast_config *cfg)
 Retrieve the current category name being built. More...
 
static struct ast_configast_config_internal_load (const char *filename, struct ast_config *cfg, int withcomments, const char *suggested_incl_file)
 
static struct ast_configast_config_new (void)
 
void ast_config_set_current_category (struct ast_config *cfg, const struct ast_category *cat)
 Set the category within the configuration as being current. More...
 
void ast_console_puts (const char *string)
 write the string to the root console, and all attached network console clients
 
static int ast_context_add_ignorepat2 (struct ast_context *con, const char *value, const char *registrar)
 
static int ast_context_add_include2 (struct ast_context *con, const char *value, const char *registrar)
 
static int ast_context_add_switch2 (struct ast_context *con, const char *value, const char *data, int eval, const char *registrar)
 
static struct ast_contextast_context_find (const char *name)
 
static struct ast_contextast_context_find_or_create (struct ast_context **extcontexts, void *tab, const char *name, const char *registrar)
 
int ast_context_ignorepats_count (struct ast_context *con)
 
int ast_context_includes_count (struct ast_context *con)
 
int ast_context_switches_count (struct ast_context *con)
 
static int ast_context_verify_includes (struct ast_context *con)
 
void ast_copy_string (char *dst, const char *src, size_t size)
 
static int ast_extension_match (const char *pattern, const char *data)
 
static int ast_findlabel_extension2 (struct ast_channel *c, struct ast_context *con, const char *exten, const char *label, const char *callerid)
 
static int ast_func_read (struct ast_channel *chan, const char *function, char *workspace, size_t len)
 
static int ast_func_write (struct ast_channel *chan, const char *function, const char *value)
 
static const char * ast_get_context_name (struct ast_context *con)
 
static const char * ast_get_extension_app (struct ast_exten *e)
 
static const char * ast_get_extension_name (struct ast_exten *exten)
 
static struct ast_config_includeast_include_find (struct ast_config *conf, const char *included_file)
 
static struct ast_config_includeast_include_new (struct ast_config *conf, const char *from_file, const char *included_file, int is_exec, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size)
 
static void ast_includes_destroy (struct ast_config_include *incls)
 
static void ast_log (int level, const char *file, int line, const char *function, const char *fmt,...)
 
void ast_log_backtrace (void)
 Log a backtrace of the current thread's execution stack to the Asterisk log.
 
void ast_mark_lock_failed (void *lock_addr)
 
static void ast_merge_contexts_and_delete (struct ast_context **extcontexts, const char *registrar)
 
static int ast_mutex_init (ast_mutex_t *pmutex)
 
static char * ast_process_quotes_and_slashes (char *start, char find, char replace_with)
 
void ast_queue_log (const char *queuename, const char *callid, const char *agent, const char *event, const char *fmt,...)
 
static int ast_remove_hint (struct ast_exten *e)
 ast_remove_hint: Remove hint from extension
 
void ast_replace_sigchld (void)
 Replace the SIGCHLD handler. More...
 
static int ast_rwlock_destroy (ast_rwlock_t *prwlock)
 
static int ast_rwlock_init (ast_rwlock_t *prwlock)
 
static int ast_rwlock_rdlock (ast_rwlock_t *prwlock)
 
static int ast_rwlock_unlock (ast_rwlock_t *prwlock)
 
static int ast_rwlock_wrlock (ast_rwlock_t *prwlock)
 
int ast_safe_system (const char *s)
 Safely spawn an OS shell command while closing file descriptors. More...
 
static void ast_shrink_phone_number (char *n)
 Clean up phone string remove '(', ' ', ')', non-trailing '.', and '-' not in square brackets. Basically, remove anything that could be invalid in a pattern.
 
char * ast_skip_blanks (const char *str)
 
char * ast_strip (char *s)
 Strip leading/trailing whitespace from a string. More...
 
static force_inline int ast_strlen_zero (const char *s)
 
char * ast_trim_blanks (char *str)
 Trims trailing whitespace characters from a string. More...
 
static int ast_true (const char *s)
 
struct timeval ast_tvadd (struct timeval a, struct timeval b)
 Returns the sum of two timevals a + b.
 
struct timeval ast_tvnow (void)
 
struct timeval ast_tvsub (struct timeval a, struct timeval b)
 Returns the difference of two timevals a - b.
 
static int ast_unlock_context (struct ast_context *con)
 
static int ast_unlock_contexts (void)
 
void ast_unreplace_sigchld (void)
 Restore the SIGCHLD handler. More...
 
static struct ast_var_tast_var_assign (const char *name, const char *value)
 
static void ast_var_delete (struct ast_var_t *var)
 
static const char * ast_var_name (const struct ast_var_t *var)
 
static const char * ast_var_value (const struct ast_var_t *var)
 
static void ast_variable_append (struct ast_category *category, struct ast_variable *variable)
 
static struct ast_variableast_variable_browse (const struct ast_config *config, const char *category)
 
static struct ast_variableast_variable_new (const char *name, const char *value, const char *filename)
 
static const char * ast_variable_retrieve (const struct ast_config *config, const char *category, const char *variable)
 
static void ast_variables_destroy (struct ast_variable *v)
 
void ast_verbose (const char *fmt,...)
 
static struct ast_extenast_walk_context_extensions (struct ast_context *con, struct ast_exten *exten)
 
static struct ast_ignorepatast_walk_context_ignorepats (struct ast_context *con, struct ast_ignorepat *ip)
 
static struct ast_includeast_walk_context_includes (struct ast_context *con, struct ast_include *inc)
 
static struct ast_swast_walk_context_switches (struct ast_context *con, struct ast_sw *sw)
 
static struct ast_contextast_walk_contexts (struct ast_context *con)
 
static struct ast_extenast_walk_extension_priorities (struct ast_exten *exten, struct ast_exten *priority)
 
static int ast_wrlock_context (struct ast_context *con)
 
static int ast_wrlock_contexts (void)
 
static struct ast_categorycategory_get (const struct ast_config *config, const char *category_name, int ignored)
 
static void CB_ADD (char *str)
 
static void CB_ADD_LEN (char *str, int len)
 
static void CB_INIT (void)
 
static void CB_RESET (void)
 
static struct ast_configconfig_text_file_load (const char *database, const char *table, const char *filename, struct ast_config *cfg, int withcomments, const char *suggested_include_file)
 
static void destroy_exten (struct ast_exten *e)
 
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)
 helper functions to sort extensions and patterns in the desired way, so that more specific patterns appear first. More...
 
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_config_enginefind_engine (const char *family, char *database, int dbsiz, char *table, int tabsiz)
 Find realtime engine for realtime family.
 
static void gen_header (FILE *f1, const char *configfile, const char *fn, const char *generator)
 
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 2 minute
 
static int include_valid (struct ast_include *i)
 
static void inherit_category (struct ast_category *new, const struct ast_category *base)
 
static void LLB_ADD (char *str)
 
int localized_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)
 
void localized_ast_include_rename (struct ast_config *conf, const char *from_file, const char *to_file)
 
struct ast_categorylocalized_category_get (const struct ast_config *config, const char *category_name)
 
struct ast_configlocalized_config_load (const char *filename)
 
struct ast_configlocalized_config_load_with_comments (const char *filename)
 
int localized_config_text_file_save (const char *configfile, const struct ast_config *cfg, const char *generator)
 
int localized_context_add_ignorepat2 (struct ast_context *con, const char *value, const char *registrar)
 
int localized_context_add_include2 (struct ast_context *con, const char *value, const char *registrar)
 
int localized_context_add_switch2 (struct ast_context *con, const char *value, const char *data, int eval, const char *registrar)
 
void localized_context_destroy (struct ast_context *con, const char *registrar)
 
struct ast_contextlocalized_context_find_or_create (struct ast_context **extcontexts, void *tab, const char *name, const char *registrar)
 
int localized_context_verify_includes (struct ast_context *con)
 
struct ast_extenlocalized_find_extension (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)
 
void localized_merge_contexts_and_delete (struct ast_context **extcontexts, void *tab, const char *registrar)
 
int localized_pbx_builtin_setvar (struct ast_channel *chan, const void *data)
 
int localized_pbx_load_module (void)
 
void localized_use_conf_dir (void)
 
void localized_use_local_dir (void)
 
struct ast_extenlocalized_walk_context_extensions (struct ast_context *con, struct ast_exten *exten)
 
struct ast_includelocalized_walk_context_includes (struct ast_context *con, struct ast_include *inc)
 
struct ast_swlocalized_walk_context_switches (struct ast_context *con, struct ast_sw *sw)
 
struct ast_contextlocalized_walk_contexts (struct ast_context *con)
 
struct ast_extenlocalized_walk_extension_priorities (struct ast_exten *exten, struct ast_exten *priority)
 
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 int matchcid (const char *cidpattern, const char *callerid)
 
static void move_variables (struct ast_category *old, struct ast_category *new)
 
static struct ast_categorynext_available_category (struct ast_category *cat)
 
static void null_datad (void *foo)
 
static int parse_variable_name (char *var, int *offset, int *length, int *isfunc)
 extract offset:length from variable name. Returns 1 if there is a offset:length part, which is trimmed off (values go into variables)
 
static int pbx_builtin_setvar (struct ast_channel *chan, const void *data)
 
static void pbx_builtin_setvar_helper (struct ast_channel *chan, const char *name, const char *value)
 
static int pbx_extension_helper (struct ast_channel *c, struct ast_context *con, const char *context, const char *exten, int priority, const char *label, const char *callerid, enum ext_match_t action)
 The return value depends on the action: More...
 
static struct ast_extenpbx_find_extension (struct ast_channel *chan, struct ast_context *bypass, struct pbx_find_info *q, const char *context, const char *exten, int priority, const char *label, const char *callerid, enum ext_match_t action)
 
static int pbx_load_config (const char *config_file)
 
static 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. More...
 
static void pbx_substitute_variables_helper (struct ast_channel *c, const char *cp1, char *cp2, int count)
 
static void pbx_substitute_variables_helper_full (struct ast_channel *c, struct varshead *headp, const char *cp1, char *cp2, int count)
 
static int process_text_line (struct ast_config *cfg, struct ast_category **cat, char *buf, int lineno, const char *configfile, int withcomments, const char *suggested_include_file)
 
static void set_fn (char *fn, int fn_size, const char *file, const char *configfile)
 
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. More...
 
static struct timeval tvfix (struct timeval a)
 
static struct ast_variablevariable_clone (const struct ast_variable *old)
 

Variables

char ast_defaultlanguage []
 
int ast_language_is_prefix
 The following variable controls the layout of localized sound files. If 0, use the historical layout with prefix just before the filename (i.e. digits/en/1.gsm , digits/it/1.gsm or default to digits/1.gsm), if 1 put the prefix at the beginning of the filename (i.e. en/digits/1.gsm, it/digits/1.gsm or default to digits/1.gsm). The latter permits a language to be entirely in one directory. More...
 
pid_t ast_mainpid
 
int ast_option_maxcalls
 
double ast_option_maxload
 
struct ast_flags ast_options = { AST_DEFAULT_OPTIONS }
 
static int autofallthrough_config = 0
 
static int clearglobalvars_config = 0
 
static char * comment_buffer
 
static int comment_buffer_size
 
static struct ast_config_engineconfig_engine_list
 
static char * config_filename = "extensions.conf"
 
static struct ast_config_mapconfig_maps = NULL
 
static ast_rwlock_t conlock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} }
 
static struct ast_contextcontexts = NULL
 
char * days []
 
char debug_filename [AST_FILENAME_MAX]
 
static char * extconfig_conf = "extconfig.conf"
 
static char * global_registrar = "conf2ael"
 
static struct varshead globals = AST_LIST_HEAD_NOLOCK_INIT_VALUE
 
static ast_rwlock_t globalslock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} }
 
static struct hints hints = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
static char * lline_buffer
 
static int lline_buffer_size
 
static struct ast_contextlocal_contexts = NULL
 
char * months []
 
static struct sigaction null_sig_handler
 
int option_debug
 
int option_verbose
 
char record_cache_dir [AST_CACHE_DIR_LEN]
 
static unsigned int safe_system_level = 0
 Keep track of how many threads are currently trying to wait*() on a child process.
 
static struct sigaction safe_system_prev_handler
 
static int static_config = 0
 
static struct ast_config_engine text_file_engine
 
static int use_local_dir = 1
 
static char userscontext [AST_MAX_EXTENSION] = "default"
 
static int write_protect_config = 1
 

Detailed Description

A condensation of the pbx_config stuff, to read into extensions.conf, and provide an interface to the data there, for operations outside of asterisk. A huge, awful hack.

Definition in file extconf.c.

Macro Definition Documentation

#define AST_DEFAULT_OPTIONS   AST_OPT_FLAG_TRANSCODE_VIA_SLIN

These are the options that set by default when Asterisk starts

Definition at line 1362 of file extconf.c.

#define AST_LIST_APPEND_LIST (   head,
  list,
  field 
)

Appends a whole list to the tail of a list.

Parameters
headThis is a pointer to the list head structure
listThis is a pointer to the list to be appended.
fieldThis is the name of the field (declared using AST_LIST_ENTRY()) used to link entries of this list together.

Definition at line 1995 of file extconf.c.

#define AST_LIST_EMPTY (   head)    (AST_LIST_FIRST(head) == NULL)

Checks whether the specified list contains any entries.

Parameters
headThis is a pointer to the list head structure

Returns non-zero if the list has entries, zero if not.

Definition at line 1733 of file extconf.c.

#define AST_LIST_ENTRY (   type)
Value:
struct { \
struct type *next; \
}

Declare a forward link structure inside a list entry.

Parameters
typeThis is the type of each list entry.

This macro declares a structure to be used to link list entries together. It must be used inside the definition of the structure named in type, as follows:

1 struct list_entry {
2  ...
3  AST_LIST_ENTRY(list_entry) list;
4 }

The field name list here is arbitrary, and can be anything you wish.

Definition at line 1694 of file extconf.c.

#define AST_LIST_FIRST (   head)    ((head)->first)

Returns the first entry contained in a list.

Parameters
headThis is a pointer to the list head structure

Definition at line 1705 of file extconf.c.

#define AST_LIST_HEAD (   name,
  type 
)
Value:
struct name { \
struct type *first; \
struct type *last; \
ast_mutex_t lock; \
}
ast_mutex_t lock

Defines a structure to be used to hold a list of specified type.

Parameters
nameThis will be the name of the defined structure.
typeThis is the type of each list entry.

This macro creates a structure definition that can be used to hold a list of the entries of type type. It does not actually declare (allocate) a structure; to do that, either follow this macro with the desired name of the instance you wish to declare, or use the specified name to declare instances elsewhere.

Example usage:

1 static AST_LIST_HEAD(entry_list, entry) entries;

This would define struct entry_list, and declare an instance of it named entries, all intended to hold a list of type struct entry.

Definition at line 1457 of file extconf.c.

#define AST_LIST_HEAD_INIT (   head)
Value:
{ \
(head)->first = NULL; \
(head)->last = NULL; \
ast_mutex_init(&(head)->lock); \
}
ast_mutex_t lock

Initializes a list head structure.

Parameters
headThis is a pointer to the list head structure

This macro initializes a list head structure by setting the head entry to NULL (empty list) and recreating the embedded lock.

Definition at line 1885 of file extconf.c.

#define AST_LIST_HEAD_INIT_NOLOCK (   head)
Value:
{ \
(head)->first = NULL; \
(head)->last = NULL; \
}

Initializes a list head structure.

Parameters
headThis is a pointer to the list head structure

This macro initializes a list head structure by setting the head entry to NULL (empty list). There is no embedded lock handling with this macro.

Definition at line 1926 of file extconf.c.

#define AST_LIST_HEAD_INIT_VALUE
Value:
{ \
.first = NULL, \
.last = NULL, \
.lock = AST_MUTEX_INIT_VALUE, \
}

Defines initial values for a declaration of AST_LIST_HEAD.

Definition at line 1518 of file extconf.c.

#define AST_LIST_HEAD_NOLOCK (   name,
  type 
)
Value:
struct name { \
struct type *first; \
struct type *last; \
}

Defines a structure to be used to hold a list of specified type (with no lock).

Parameters
nameThis will be the name of the defined structure.
typeThis is the type of each list entry.

This macro creates a structure definition that can be used to hold a list of the entries of type type. It does not actually declare (allocate) a structure; to do that, either follow this macro with the desired name of the instance you wish to declare, or use the specified name to declare instances elsewhere.

Example usage:

1 static AST_LIST_HEAD_NOLOCK(entry_list, entry) entries;

This would define struct entry_list, and declare an instance of it named entries, all intended to hold a list of type struct entry.

Definition at line 1509 of file extconf.c.

#define AST_LIST_HEAD_NOLOCK_INIT_VALUE
Value:
{ \
.first = NULL, \
.last = NULL, \
}

Defines initial values for a declaration of AST_LIST_HEAD_NOLOCK.

Definition at line 1536 of file extconf.c.

#define AST_LIST_HEAD_NOLOCK_STATIC (   name,
  type 
)
Value:
struct name { \
struct type *first; \
struct type *last; \
#define AST_LIST_HEAD_NOLOCK_INIT_VALUE
Defines initial values for a declaration of AST_LIST_HEAD_NOLOCK.
Definition: extconf.c:1536

Defines a structure to be used to hold a list of specified type, statically initialized.

This is the same as AST_LIST_HEAD_STATIC, except without the lock included.

Definition at line 1630 of file extconf.c.

#define AST_LIST_HEAD_SET (   head,
  entry 
)
Value:
do { \
(head)->first = (entry); \
(head)->last = (entry); \
ast_mutex_init(&(head)->lock); \
} while (0)
ast_mutex_t lock
Definition: search.h:40

Initializes a list head structure with a specified first entry.

Parameters
headThis is a pointer to the list head structure
entrypointer to the list entry that will become the head of the list

This macro initializes a list head structure by setting the head entry to the supplied value and recreating the embedded lock.

Definition at line 1644 of file extconf.c.

#define AST_LIST_HEAD_SET_NOLOCK (   head,
  entry 
)
Value:
do { \
(head)->first = (entry); \
(head)->last = (entry); \
} while (0)
Definition: search.h:40

Initializes a list head structure with a specified first entry.

Parameters
headThis is a pointer to the list head structure
entrypointer to the list entry that will become the head of the list

This macro initializes a list head structure by setting the head entry to the supplied value.

Definition at line 1672 of file extconf.c.

#define AST_LIST_HEAD_STATIC (   name,
  type 
)
Value:
struct name { \
struct type *first; \
struct type *last; \
ast_mutex_t lock; \
#define AST_LIST_HEAD_INIT_VALUE
Defines initial values for a declaration of AST_LIST_HEAD.
Definition: extconf.c:1518
ast_mutex_t lock

Defines a structure to be used to hold a list of specified type, statically initialized.

Parameters
nameThis will be the name of the defined structure.
typeThis is the type of each list entry.

This macro creates a structure definition that can be used to hold a list of the entries of type type, and allocates an instance of it, initialized to be empty.

Example usage:

1 static AST_LIST_HEAD_STATIC(entry_list, entry);

This would define struct entry_list, intended to hold a list of type struct entry.

Definition at line 1575 of file extconf.c.

#define AST_LIST_INSERT_AFTER (   head,
  listelm,
  elm,
  field 
)

Inserts a list entry after a given entry.

Parameters
headThis is a pointer to the list head structure
listelmThis is a pointer to the entry after which the new entry should be inserted.
elmThis is a pointer to the entry to be inserted.
fieldThis is the name of the field (declared using AST_LIST_ENTRY()) used to link entries of this list together.

Definition at line 1940 of file extconf.c.

#define AST_LIST_INSERT_BEFORE_CURRENT (   head,
  elm,
  field 
)

Inserts a list entry before the current entry during a traversal.

Parameters
headThis is a pointer to the list head structure
elmThis is a pointer to the entry to be inserted.
fieldThis is the name of the field (declared using AST_LIST_ENTRY()) used to link entries of this list together.
Note
This macro can only be used inside an AST_LIST_TRAVERSE_SAFE_BEGIN() block.

Definition at line 1858 of file extconf.c.

#define AST_LIST_INSERT_HEAD (   head,
  elm,
  field 
)

Inserts a list entry at the head of a list.

Parameters
headThis is a pointer to the list head structure
elmThis is a pointer to the entry to be inserted.
fieldThis is the name of the field (declared using AST_LIST_ENTRY()) used to link entries of this list together.

Definition at line 1956 of file extconf.c.

#define AST_LIST_INSERT_TAIL (   head,
  elm,
  field 
)

Appends a list entry to the tail of a list.

Parameters
headThis is a pointer to the list head structure
elmThis is a pointer to the entry to be appended.
fieldThis is the name of the field (declared using AST_LIST_ENTRY()) used to link entries of this list together.

Note: The link field in the appended entry is not modified, so if it is actually the head of a list itself, the entire list will be appended temporarily (until the next AST_LIST_INSERT_TAIL is performed).

Definition at line 1976 of file extconf.c.

#define AST_LIST_LAST (   head)    ((head)->last)

Returns the last entry contained in a list.

Parameters
headThis is a pointer to the list head structure

Definition at line 1713 of file extconf.c.

#define AST_LIST_NEXT (   elm,
  field 
)    ((elm)->field.next)

Returns the next entry in the list after the given entry.

Parameters
elmThis is a pointer to the current entry.
fieldThis is the name of the field (declared using AST_LIST_ENTRY()) used to link entries of this list together.

Definition at line 1723 of file extconf.c.

#define AST_LIST_REMOVE (   head,
  elm,
  field 
)

Removes a specific entry from a list.

Parameters
headThis is a pointer to the list head structure
elmThis is a pointer to the entry to be removed.
fieldThis is the name of the field (declared using AST_LIST_ENTRY()) used to link entries of this list together.
Warning
The removed entry is not freed nor modified in any way.

Definition at line 2037 of file extconf.c.

#define AST_LIST_REMOVE_CURRENT (   head,
  field 
)

Removes the current entry from a list during a traversal.

Parameters
headThis is a pointer to the list head structure
fieldThis is the name of the field (declared using AST_LIST_ENTRY()) used to link entries of this list together.
Note
This macro can only be used inside an AST_LIST_TRAVERSE_SAFE_BEGIN() block; it is used to unlink the current entry from the list without affecting the list traversal (and without having to re-traverse the list to modify the previous entry, if any).

Definition at line 1836 of file extconf.c.

#define AST_LIST_REMOVE_HEAD (   head,
  field 
)

Removes and returns the head entry from a list.

Parameters
headThis is a pointer to the list head structure
fieldThis is the name of the field (declared using AST_LIST_ENTRY()) used to link entries of this list together.

Removes the head entry from the list, and returns a pointer to it. This macro is safe to call on an empty list.

Definition at line 2016 of file extconf.c.

#define AST_LIST_TRAVERSE (   head,
  var,
  field 
)    for((var) = (head)->first; (var); (var) = (var)->field.next)

Loops over (traverses) the entries in a list.

Parameters
headThis is a pointer to the list head structure
varThis is the name of the variable that will hold a pointer to the current list entry on each iteration. It must be declared before calling this macro.
fieldThis is the name of the field (declared using AST_LIST_ENTRY()) used to link entries of this list together.

This macro is use to loop over (traverse) the entries in a list. It uses a for loop, and supplies the enclosed code with a pointer to each list entry as it loops. It is typically used as follows:

1 static AST_LIST_HEAD(entry_list, list_entry) entries;
2 ...
3 struct list_entry {
4  ...
5  AST_LIST_ENTRY(list_entry) list;
6 }
7 ...
8 struct list_entry *current;
9 ...
10 AST_LIST_TRAVERSE(&entries, current, list) {
11  (do something with current here)
12 }
Warning
If you modify the forward-link pointer contained in the current entry while inside the loop, the behavior will be unpredictable. At a minimum, the following macros will modify the forward-link pointer, and should not be used inside AST_LIST_TRAVERSE() against the entry pointed to by the current pointer without careful consideration of their consequences:

Definition at line 1773 of file extconf.c.

Referenced by pbx_retrieve_variable().

#define AST_LIST_TRAVERSE_SAFE_BEGIN (   head,
  var,
  field 
)

Loops safely over (traverses) the entries in a list.

Parameters
headThis is a pointer to the list head structure
varThis is the name of the variable that will hold a pointer to the current list entry on each iteration. It must be declared before calling this macro.
fieldThis is the name of the field (declared using AST_LIST_ENTRY()) used to link entries of this list together.

This macro is used to safely loop over (traverse) the entries in a list. It uses a for loop, and supplies the enclosed code with a pointer to each list entry as it loops. It is typically used as follows:

1 static AST_LIST_HEAD(entry_list, list_entry) entries;
2 ...
3 struct list_entry {
4  ...
5  AST_LIST_ENTRY(list_entry) list;
6 }
7 ...
8 struct list_entry *current;
9 ...
10 AST_LIST_TRAVERSE_SAFE_BEGIN(&entries, current, list) {
11  (do something with current here)
12 }
13 AST_LIST_TRAVERSE_SAFE_END;

It differs from AST_LIST_TRAVERSE() in that the code inside the loop can modify (or even free, after calling AST_LIST_REMOVE_CURRENT()) the entry pointed to by the current pointer without affecting the loop traversal.

Definition at line 1811 of file extconf.c.

#define AST_MAX_EXTENSION   80

Max length of an extension

Definition at line 2078 of file extconf.c.

#define AST_RWLIST_HEAD (   name,
  type 
)
Value:
struct name { \
struct type *first; \
struct type *last; \
ast_rwlock_t lock; \
}
ast_mutex_t lock

Defines a structure to be used to hold a read/write list of specified type.

Parameters
nameThis will be the name of the defined structure.
typeThis is the type of each list entry.

This macro creates a structure definition that can be used to hold a list of the entries of type type. It does not actually declare (allocate) a structure; to do that, either follow this macro with the desired name of the instance you wish to declare, or use the specified name to declare instances elsewhere.

Example usage:

1 static AST_RWLIST_HEAD(entry_list, entry) entries;

This would define struct entry_list, and declare an instance of it named entries, all intended to hold a list of type struct entry.

Definition at line 1483 of file extconf.c.

#define AST_RWLIST_HEAD_DESTROY (   head)
Value:
{ \
(head)->first = NULL; \
(head)->last = NULL; \
ast_rwlock_destroy(&(head)->lock); \
}
ast_mutex_t lock

Destroys an rwlist head structure.

Parameters
headThis is a pointer to the list head structure

This macro destroys a list head structure by setting the head entry to NULL (empty list) and destroying the embedded lock. It does not free the structure from memory.

Definition at line 1912 of file extconf.c.

#define AST_RWLIST_HEAD_INIT (   head)
Value:
{ \
(head)->first = NULL; \
(head)->last = NULL; \
ast_rwlock_init(&(head)->lock); \
}
ast_mutex_t lock

Initializes an rwlist head structure.

Parameters
headThis is a pointer to the list head structure

This macro initializes a list head structure by setting the head entry to NULL (empty list) and recreating the embedded lock.

Definition at line 1898 of file extconf.c.

#define AST_RWLIST_HEAD_INIT_VALUE
Value:
{ \
.first = NULL, \
.last = NULL, \
.lock = AST_RWLOCK_INIT_VALUE, \
}

Defines initial values for a declaration of AST_RWLIST_HEAD.

Definition at line 1527 of file extconf.c.

#define AST_RWLIST_HEAD_SET (   head,
  entry 
)
Value:
do { \
(head)->first = (entry); \
(head)->last = (entry); \
ast_rwlock_init(&(head)->lock); \
} while (0)
ast_mutex_t lock
Definition: search.h:40

Initializes an rwlist head structure with a specified first entry.

Parameters
headThis is a pointer to the list head structure
entrypointer to the list entry that will become the head of the list

This macro initializes a list head structure by setting the head entry to the supplied value and recreating the embedded lock.

Definition at line 1658 of file extconf.c.

#define AST_RWLIST_HEAD_STATIC (   name,
  type 
)
Value:
struct name { \
struct type *first; \
struct type *last; \
ast_rwlock_t lock; \
ast_mutex_t lock
#define AST_RWLIST_HEAD_INIT_VALUE
Defines initial values for a declaration of AST_RWLIST_HEAD.
Definition: extconf.c:1527

Defines a structure to be used to hold a read/write list of specified type, statically initialized.

Parameters
nameThis will be the name of the defined structure.
typeThis is the type of each list entry.

This macro creates a structure definition that can be used to hold a list of the entries of type type, and allocates an instance of it, initialized to be empty.

Example usage:

1 static AST_RWLIST_HEAD_STATIC(entry_list, entry);

This would define struct entry_list, intended to hold a list of type struct entry.

Definition at line 1617 of file extconf.c.

#define AST_RWLIST_RDLOCK (   head)    ast_rwlock_rdlock(&(head)->lock)

Read locks a list.

Parameters
headThis is a pointer to the list head structure

This macro attempts to place a read lock in the list head structure pointed to by head. Returns non-zero on success, 0 on failure

Definition at line 1424 of file extconf.c.

#define AST_RWLIST_UNLOCK (   head)    ast_rwlock_unlock(&(head)->lock)

Attempts to unlock a read/write based list.

Parameters
headThis is a pointer to the list head structure

This macro attempts to remove a read or write lock from the list head structure pointed to by head. If the list was not locked by this thread, this macro has no effect.

Definition at line 1435 of file extconf.c.

#define AST_RWLIST_WRLOCK (   head)    ast_rwlock_wrlock(&(head)->lock)

Write locks a list.

Parameters
headThis is a pointer to the list head structure

This macro attempts to place an exclusive write lock in the list head structure pointed to by head. Returns non-zero on success, 0 on failure

Definition at line 1413 of file extconf.c.

#define DEBUG_M (   a)
Value:
{ \
a; \
}

Definition at line 96 of file extconf.c.

#define PRIORITY_HINT   -1

Special Priority for a hint

Definition at line 2082 of file extconf.c.

Referenced by add_pri(), and ast_add_extension2().

Enumeration Type Documentation

Enumerator
AST_EXTENSION_REMOVED 

Extension removed

AST_EXTENSION_DEACTIVATED 

Extension hint removed

AST_EXTENSION_NOT_INUSE 

No device INUSE or BUSY

AST_EXTENSION_INUSE 

One or more devices INUSE

AST_EXTENSION_BUSY 

All devices BUSY

AST_EXTENSION_UNAVAILABLE 

All devices UNAVAILABLE/UNREGISTERED

AST_EXTENSION_RINGING 

All devices RINGING

AST_EXTENSION_ONHOLD 

All devices ONHOLD

AST_EXTENSION_REMOVED 

Extension removed

AST_EXTENSION_DEACTIVATED 

Extension hint removed

AST_EXTENSION_NOT_INUSE 

No device INUSE or BUSY

AST_EXTENSION_INUSE 

One or more devices INUSE

AST_EXTENSION_BUSY 

All devices BUSY

AST_EXTENSION_UNAVAILABLE 

All devices UNAVAILABLE/UNREGISTERED

AST_EXTENSION_RINGING 

All devices RINGING

AST_EXTENSION_ONHOLD 

All devices ONHOLD

Definition at line 2084 of file extconf.c.

2084  {
2085  AST_EXTENSION_REMOVED = -2, /*!< Extension removed */
2086  AST_EXTENSION_DEACTIVATED = -1, /*!< Extension hint removed */
2087  AST_EXTENSION_NOT_INUSE = 0, /*!< No device INUSE or BUSY */
2088  AST_EXTENSION_INUSE = 1 << 0, /*!< One or more devices INUSE */
2089  AST_EXTENSION_BUSY = 1 << 1, /*!< All devices BUSY */
2090  AST_EXTENSION_UNAVAILABLE = 1 << 2, /*!< All devices UNAVAILABLE/UNREGISTERED */
2091  AST_EXTENSION_RINGING = 1 << 3, /*!< All devices RINGING */
2092  AST_EXTENSION_ONHOLD = 1 << 4, /*!< All devices ONHOLD */
2093 };
Enumerator
AST_OPT_FLAG_EXEC_INCLUDES 

Allow #exec in config files

AST_OPT_FLAG_NO_FORK 

Do not fork()

AST_OPT_FLAG_QUIET 

Keep quiet

AST_OPT_FLAG_CONSOLE 

Console mode

AST_OPT_FLAG_HIGH_PRIORITY 

Run in realtime Linux priority

AST_OPT_FLAG_INIT_KEYS 

Initialize keys for RSA authentication

AST_OPT_FLAG_REMOTE 

Remote console

AST_OPT_FLAG_EXEC 

Execute an asterisk CLI command upon startup

AST_OPT_FLAG_NO_COLOR 

Don't use termcap colors

AST_OPT_FLAG_FULLY_BOOTED 

Are we fully started yet?

AST_OPT_FLAG_TRANSCODE_VIA_SLIN 

Trascode via signed linear

AST_OPT_FLAG_STDEXTEN_MACRO 

Invoke the stdexten using the legacy macro method.

AST_OPT_FLAG_DUMP_CORE 

Dump core on a seg fault

AST_OPT_FLAG_CACHE_RECORD_FILES 

Cache sound files

AST_OPT_FLAG_TIMESTAMP 

Display timestamp in CLI verbose output

AST_OPT_FLAG_CACHE_MEDIA_FRAMES 

Cache media frames for performance

AST_OPT_FLAG_RECONNECT 

Reconnect

AST_OPT_FLAG_TRANSMIT_SILENCE 

Transmit Silence during Record() and DTMF Generation

AST_OPT_FLAG_DONT_WARN 

Suppress some warnings

AST_OPT_FLAG_SOUNDS_SEARCH_CUSTOM 

Search custom directory for sounds first

AST_OPT_FLAG_REF_DEBUG 

Reference Debugging

AST_OPT_FLAG_ALWAYS_FORK 

Always fork, even if verbose or debug settings are non-zero

AST_OPT_FLAG_MUTE 

Disable log/verbose output to remote consoles

AST_OPT_FLAG_DEBUG_MODULE 

There is a per-module debug setting

AST_OPT_FLAG_TRACE_MODULE 

There is a per-module trace setting

AST_OPT_FLAG_LIGHT_BACKGROUND 

Terminal colors should be adjusted for a light-colored background

AST_OPT_FLAG_HIDE_MESSAGING_AMI_EVENTS 

Make the global Message channel an internal channel to suppress AMI events

AST_OPT_FLAG_FORCE_BLACK_BACKGROUND 

Force black background

AST_OPT_FLAG_HIDE_CONSOLE_CONNECT 

Hide remote console connect messages on console

AST_OPT_FLAG_LOCK_CONFIG_DIR 

Protect the configuration file path with a lock

AST_OPT_FLAG_GENERIC_PLC 

Generic PLC

AST_OPT_FLAG_GENERIC_PLC_ON_EQUAL_CODECS 

Generic PLC onm equal codecs

AST_OPT_FLAG_EXEC_INCLUDES 

Allow #exec in config files

AST_OPT_FLAG_NO_FORK 

Do not fork()

AST_OPT_FLAG_QUIET 

Keep quiet

AST_OPT_FLAG_CONSOLE 

Console mode

AST_OPT_FLAG_HIGH_PRIORITY 

Run in realtime Linux priority

AST_OPT_FLAG_INIT_KEYS 

Initialize keys for RSA authentication

AST_OPT_FLAG_REMOTE 

Remote console

AST_OPT_FLAG_EXEC 

Execute an asterisk CLI command upon startup

AST_OPT_FLAG_NO_COLOR 

Don't use termcap colors

AST_OPT_FLAG_FULLY_BOOTED 

Are we fully started yet?

AST_OPT_FLAG_TRANSCODE_VIA_SLIN 

Trascode via signed linear

AST_OPT_FLAG_DUMP_CORE 

Dump core on a seg fault

AST_OPT_FLAG_CACHE_RECORD_FILES 

Cache sound files

AST_OPT_FLAG_TIMESTAMP 

Display timestamp in CLI verbose output

AST_OPT_FLAG_OVERRIDE_CONFIG 

Override config

AST_OPT_FLAG_RECONNECT 

Reconnect

AST_OPT_FLAG_TRANSMIT_SILENCE 

Transmit Silence during Record() and DTMF Generation

AST_OPT_FLAG_DONT_WARN 

Suppress some warnings

AST_OPT_FLAG_ALWAYS_FORK 

Always fork, even if verbose or debug settings are non-zero

AST_OPT_FLAG_MUTE 

Disable log/verbose output to remote consoles

AST_OPT_FLAG_DEBUG_FILE 

There is a per-file debug setting

AST_OPT_FLAG_LIGHT_BACKGROUND 

Terminal colors should be adjusted for a light-colored background

AST_OPT_FLAG_FORCE_BLACK_BACKGROUND 

Force black background

Definition at line 1308 of file extconf.c.

1308  {
1309  /*! Allow \#exec in config files */
1310  AST_OPT_FLAG_EXEC_INCLUDES = (1 << 0),
1311  /*! Do not fork() */
1312  AST_OPT_FLAG_NO_FORK = (1 << 1),
1313  /*! Keep quiet */
1314  AST_OPT_FLAG_QUIET = (1 << 2),
1315  /*! Console mode */
1316  AST_OPT_FLAG_CONSOLE = (1 << 3),
1317  /*! Run in realtime Linux priority */
1318  AST_OPT_FLAG_HIGH_PRIORITY = (1 << 4),
1319  /*! Initialize keys for RSA authentication */
1320  AST_OPT_FLAG_INIT_KEYS = (1 << 5),
1321  /*! Remote console */
1322  AST_OPT_FLAG_REMOTE = (1 << 6),
1323  /*! Execute an asterisk CLI command upon startup */
1324  AST_OPT_FLAG_EXEC = (1 << 7),
1325  /*! Don't use termcap colors */
1326  AST_OPT_FLAG_NO_COLOR = (1 << 8),
1327  /*! Are we fully started yet? */
1328  AST_OPT_FLAG_FULLY_BOOTED = (1 << 9),
1329  /*! Trascode via signed linear */
1330  AST_OPT_FLAG_TRANSCODE_VIA_SLIN = (1 << 10),
1331  /*! Dump core on a seg fault */
1332  AST_OPT_FLAG_DUMP_CORE = (1 << 12),
1333  /*! Cache sound files */
1334  AST_OPT_FLAG_CACHE_RECORD_FILES = (1 << 13),
1335  /*! Display timestamp in CLI verbose output */
1336  AST_OPT_FLAG_TIMESTAMP = (1 << 14),
1337  /*! Override config */
1338  AST_OPT_FLAG_OVERRIDE_CONFIG = (1 << 15),
1339  /*! Reconnect */
1340  AST_OPT_FLAG_RECONNECT = (1 << 16),
1341  /*! Transmit Silence during Record() and DTMF Generation */
1342  AST_OPT_FLAG_TRANSMIT_SILENCE = (1 << 17),
1343  /*! Suppress some warnings */
1344  AST_OPT_FLAG_DONT_WARN = (1 << 18),
1345  /*! Always fork, even if verbose or debug settings are non-zero */
1346  AST_OPT_FLAG_ALWAYS_FORK = (1 << 21),
1347  /*! Disable log/verbose output to remote consoles */
1348  AST_OPT_FLAG_MUTE = (1 << 22),
1349  /*! There is a per-file debug setting */
1350  AST_OPT_FLAG_DEBUG_FILE = (1 << 23),
1351  /*! Terminal colors should be adjusted for a light-colored background */
1352  AST_OPT_FLAG_LIGHT_BACKGROUND = (1 << 25),
1353  /*! Force black background */
1355 };

Function Documentation

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

Main interface to add extensions to the list for out 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 4773 of file extconf.c.

References add_pri(), ast_exten::app, ast_add_hint(), ast_calloc, ast_exten::cidmatch, ast_exten::data, ast_exten::datad, ext_cmp(), ext_strncpy(), ast_exten::exten, ast_exten::label, ast_exten::matchcid, ast_context::name, ast_exten::next, ast_exten::parent, ast_exten::priority, PRIORITY_HINT, ast_exten::registrar, and ast_context::root.

4777 {
4778  /*
4779  * Sort extensions (or patterns) according to the rules indicated above.
4780  * These are implemented by the function ext_cmp()).
4781  * All priorities for the same ext/pattern/cid are kept in a list,
4782  * using the 'peer' field as a link field..
4783  */
4784  struct ast_exten *tmp, *e, *el = NULL;
4785  int res;
4786  int length;
4787  char *p;
4788 
4789  /* if we are adding a hint, and there are global variables, and the hint
4790  contains variable references, then expand them --- NOT In this situation!!!
4791  */
4792 
4793  length = sizeof(struct ast_exten);
4794  length += strlen(extension) + 1;
4795  length += strlen(application) + 1;
4796  if (label)
4797  length += strlen(label) + 1;
4798  if (callerid)
4799  length += strlen(callerid) + 1;
4800  else
4801  length ++; /* just the '\0' */
4802 
4803  /* Be optimistic: Build the extension structure first */
4804  if (datad == NULL)
4805  datad = null_datad;
4806  if (!(tmp = ast_calloc(1, length)))
4807  return -1;
4808 
4809  /* use p as dst in assignments, as the fields are const char * */
4810  p = tmp->stuff;
4811  if (label) {
4812  tmp->label = p;
4813  strcpy(p, label);
4814  p += strlen(label) + 1;
4815  }
4816  tmp->exten = p;
4817  p += ext_strncpy(p, extension, strlen(extension) + 1) + 1;
4818  tmp->priority = priority;
4819  tmp->cidmatch = p; /* but use p for assignments below */
4820  if (callerid) {
4821  p += ext_strncpy(p, callerid, strlen(callerid) + 1) + 1;
4822  tmp->matchcid = 1;
4823  } else {
4824  *p++ = '\0';
4825  tmp->matchcid = 0;
4826  }
4827  tmp->app = p;
4828  strcpy(p, application);
4829  tmp->parent = con;
4830  tmp->data = data;
4831  tmp->datad = datad;
4832  tmp->registrar = registrar;
4833 
4834  res = 0; /* some compilers will think it is uninitialized otherwise */
4835  for (e = con->root; e; el = e, e = e->next) { /* scan the extension list */
4836  res = ext_cmp(e->exten, extension);
4837  if (res == 0) { /* extension match, now look at cidmatch */
4838  if (!e->matchcid && !tmp->matchcid)
4839  res = 0;
4840  else if (tmp->matchcid && !e->matchcid)
4841  res = 1;
4842  else if (e->matchcid && !tmp->matchcid)
4843  res = -1;
4844  else
4845  res = strcasecmp(e->cidmatch, tmp->cidmatch);
4846  }
4847  if (res >= 0)
4848  break;
4849  }
4850  if (e && res == 0) { /* exact match, insert in the pri chain */
4851  res = add_pri(con, tmp, el, e, replace);
4852  if (res < 0) {
4853  errno = EEXIST; /* XXX do we care ? */
4854  return 0; /* XXX should we return -1 maybe ? */
4855  }
4856  } else {
4857  /*
4858  * not an exact match, this is the first entry with this pattern,
4859  * so insert in the main list right before 'e' (if any)
4860  */
4861  tmp->next = e;
4862  if (el)
4863  el->next = tmp;
4864  else
4865  con->root = tmp;
4866  if (tmp->priority == PRIORITY_HINT)
4867  ast_add_hint(tmp);
4868  }
4869  if (option_debug) {
4870  if (tmp->matchcid) {
4871  ast_log(LOG_DEBUG, "Added extension '%s' priority %d (CID match '%s') to %s\n",
4872  tmp->exten, tmp->priority, tmp->cidmatch, con->name);
4873  } else {
4874  ast_log(LOG_DEBUG, "Added extension '%s' priority %d to %s\n",
4875  tmp->exten, tmp->priority, con->name);
4876  }
4877  }
4878  if (option_verbose > 2) {
4879  if (tmp->matchcid) {
4880  ast_verbose( VERBOSE_PREFIX_3 "Added extension '%s' priority %d (CID match '%s')to %s\n",
4881  tmp->exten, tmp->priority, tmp->cidmatch, con->name);
4882  } else {
4883  ast_verbose( VERBOSE_PREFIX_3 "Added extension '%s' priority %d to %s\n",
4884  tmp->exten, tmp->priority, con->name);
4885  }
4886  }
4887  return 0;
4888 }
const char * label
Definition: pbx.c:244
ast_exten: An extension The dialplan is saved as a linked list with each context having it's own link...
Definition: pbx.c:237
struct ast_exten * root
Definition: pbx.c:289
int option_debug
Definition: options.c:69
int option_verbose
Definition: options.c:67
const char * registrar
Definition: pbx.c:253
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. returns 0 on success, -1 on failure
Definition: extconf.c:3675
int matchcid
Definition: pbx.c:240
struct ast_exten * next
Definition: pbx.c:256
int priority
Definition: pbx.c:243
structure to hold extensions
static int ast_add_hint(struct ast_exten *e)
ast_add_hint: Add hint to hint list, check initial extension state
Definition: extconf.c:3642
void(* datad)(void *)
Definition: pbx.c:249
char * exten
Definition: pbx.c:238
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
const char * cidmatch
Definition: pbx.c:241
static int ext_strncpy(char *dst, const char *src, int len)
copy a string skipping whitespace
Definition: extconf.c:3971
const char * name
Definition: pbx.c:285
static int ext_cmp(const char *a, const char *b)
the full routine to compare extensions in rules.
Definition: extconf.c:3944
const char * app
Definition: pbx.c:246
struct ast_context * parent
Definition: pbx.c:245
#define PRIORITY_HINT
Definition: extconf.c:2082
void * data
Definition: pbx.c:248
int ast_build_timing ( struct ast_timing i,
const char *  info_in 
)

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

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

Definition at line 3806 of file extconf.c.

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

Referenced by include_alloc().

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

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

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

Definition at line 4000 of file extconf.c.

4001 {
4002  /* sorry, but this feature will NOT be available
4003  in the standalone version */
4004  return 0;
4005 }
struct ast_category* ast_config_get_current_category ( const struct ast_config cfg)

Retrieve the current category name being built.

API for backend configuration engines while building a configuration set.

Definition at line 2781 of file extconf.c.

2782 {
2783  return cfg->current;
2784 }
void ast_config_set_current_category ( struct ast_config cfg,
const struct ast_category cat 
)

Set the category within the configuration as being current.

API for backend configuration engines while building a configuration set.

Definition at line 3362 of file extconf.c.

3363 {
3364  /* cast below is just to silence compiler warning about dropping "const" */
3365  cfg->current = (struct ast_category *) cat;
3366 }
void ast_replace_sigchld ( void  )

Replace the SIGCHLD handler.

Normally, Asterisk has a SIGCHLD handler that is cleaning up all zombie processes from forking elsewhere in Asterisk. However, if you want to wait*() on the process to retrieve information about it's exit status, then this signal handler needs to be temporarily replaced.

Code that executes this function must call ast_unreplace_sigchld() after it is finished doing the wait*().

Definition at line 801 of file extconf.c.

Referenced by ast_safe_fork(), and ast_safe_system().

802 {
803  unsigned int level;
804 
805  level = safe_system_level++;
806 
807  /* only replace the handler if it has not already been done */
808  if (level == 0) {
809  sigaction(SIGCHLD, &null_sig_handler, &safe_system_prev_handler);
810  }
811 }
static unsigned int safe_system_level
Keep track of how many threads are currently trying to wait*() on a child process.
Definition: extconf.c:785
int ast_safe_system ( const char *  s)

Safely spawn an OS shell command while closing file descriptors.

Note
This replaces the system call in all Asterisk modules
Parameters
s- OS shell command string to execute.
Warning
Command injection can happen using this call if the passed in string is created using untrusted data from an external source. It is best not to use untrusted data. However, the caller could filter out dangerous characters to avoid command injection.

Definition at line 829 of file extconf.c.

References ast_replace_sigchld(), and ast_unreplace_sigchld().

Referenced by alarmreceiver_exec(), and notify_message().

830 {
831  pid_t pid;
832 #ifdef HAVE_WORKING_FORK
833  int x;
834 #endif
835  int res;
836  int status;
837 
838 #if defined(HAVE_WORKING_FORK) || defined(HAVE_WORKING_VFORK)
840 
841 #ifdef HAVE_WORKING_FORK
842  pid = fork();
843 #else
844  pid = vfork();
845 #endif
846 
847  if (pid == 0) {
848 #ifdef HAVE_WORKING_FORK
849  /* Close file descriptors and launch system command */
850  for (x = STDERR_FILENO + 1; x < 4096; x++)
851  close(x);
852 #endif
853  execl("/bin/sh", "/bin/sh", "-c", s, (char *) NULL);
854  _exit(1);
855  } else if (pid > 0) {
856  for(;;) {
857  res = waitpid(pid, &status, 0);
858  if (res > -1) {
859  res = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
860  break;
861  } else if (errno != EINTR)
862  break;
863  }
864  } else {
865  ast_log(LOG_WARNING, "Fork failed: %s\n", strerror(errno));
866  res = -1;
867  }
868 
870 #else
871  res = -1;
872 #endif
873 
874  return res;
875 }
void ast_unreplace_sigchld(void)
Restore the SIGCHLD handler.
Definition: extconf.c:815
void ast_replace_sigchld(void)
Replace the SIGCHLD handler.
Definition: extconf.c:801
char* ast_strip ( char *  s)

Strip leading/trailing whitespace from a string.

Parameters
sThe string to be stripped (will be modified).
Returns
The stripped string.

This functions strips all leading and trailing whitespace characters from the input string, and returns a pointer to the resulting string. The string is modified in place.

Definition at line 1023 of file extconf.c.

References ast_variable::next, and ast_variable::stuff.

1028 {
char* ast_trim_blanks ( char *  str)

Trims trailing whitespace characters from a string.

Parameters
strthe input string
Returns
a pointer to the modified string

Definition at line 1004 of file extconf.c.

References ast_skip_blanks().

1017 {
void ast_unreplace_sigchld ( void  )

Restore the SIGCHLD handler.

This function is called after a call to ast_replace_sigchld. It restores the SIGCHLD handler that cleans up any zombie processes.

Definition at line 815 of file extconf.c.

References safe_system_level.

Referenced by ast_safe_fork_cleanup(), and ast_safe_system().

816 {
817  unsigned int level;
818 
819  level = --safe_system_level;
820 
821  /* only restore the handler if we are the last one */
822  if (level == 0) {
823  sigaction(SIGCHLD, &safe_system_prev_handler, NULL);
824  }
825 }
static unsigned int safe_system_level
Keep track of how many threads are currently trying to wait*() on a child process.
Definition: extconf.c:785
static int ext_cmp1 ( const char **  p)
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.

Definition at line 3872 of file extconf.c.

Referenced by ext_cmp().

3873 {
3874  uint32_t chars[8];
3875  int c, cmin = 0xff, count = 0;
3876  const char *end;
3877 
3878  /* load, sign extend and advance pointer until we find
3879  * a valid character.
3880  */
3881  while ( (c = *(*p)++) && (c == ' ' || c == '-') )
3882  ; /* ignore some characters */
3883 
3884  /* always return unless we have a set of chars */
3885  switch (c) {
3886  default: /* ordinary character */
3887  return 0x0000 | (c & 0xff);
3888 
3889  case 'N': /* 2..9 */
3890  return 0x0700 | '2' ;
3891 
3892  case 'X': /* 0..9 */
3893  return 0x0900 | '0';
3894 
3895  case 'Z': /* 1..9 */
3896  return 0x0800 | '1';
3897 
3898  case '.': /* wildcard */
3899  return 0x10000;
3900 
3901  case '!': /* earlymatch */
3902  return 0x20000; /* less specific than NULL */
3903 
3904  case '\0': /* empty string */
3905  *p = NULL;
3906  return 0x30000;
3907 
3908  case '[': /* pattern */
3909  break;
3910  }
3911  /* locate end of set */
3912  end = strchr(*p, ']');
3913 
3914  if (end == NULL) {
3915  ast_log(LOG_WARNING, "Wrong usage of [] in the extension\n");
3916  return 0x40000; /* XXX make this entry go last... */
3917  }
3918 
3919  memset(chars, '\0', sizeof(chars)); /* clear all chars in the set */
3920  for (; *p < end ; (*p)++) {
3921  unsigned char c1, c2; /* first-last char in range */
3922  c1 = (unsigned char)((*p)[0]);
3923  if (*p + 2 < end && (*p)[1] == '-') { /* this is a range */
3924  c2 = (unsigned char)((*p)[2]);
3925  *p += 2; /* skip a total of 3 chars */
3926  } else /* individual character */
3927  c2 = c1;
3928  if (c1 < cmin)
3929  cmin = c1;
3930  for (; c1 <= c2; c1++) {
3931  uint32_t mask = 1 << (c1 % 32);
3932  if ( (chars[ c1 / 32 ] & mask) == 0)
3933  count += 0x100;
3934  chars[ c1 / 32 ] |= mask;
3935  }
3936  }
3937  (*p)++;
3938  return count == 0 ? 0x30000 : (count | cmin);
3939 }
struct ast_context* localized_context_find_or_create ( struct ast_context **  extcontexts,
void *  tab,
const char *  name,
const char *  registrar 
)
Version
1.6.1 added tab parameter
1.6.1 renamed function from localized_context_create to localized_context_find_or_create

Definition at line 4986 of file extconf.c.

4987 {
4988  return __ast_context_create(extcontexts, name, registrar, 1);
4989 }
void localized_merge_contexts_and_delete ( struct ast_context **  extcontexts,
void *  tab,
const char *  registrar 
)
Version
1.6.1 added tab parameter

Definition at line 5615 of file extconf.c.

References ast_merge_contexts_and_delete().

5616 {
5617  ast_merge_contexts_and_delete(extcontexts, registrar);
5618 }
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 tha...
Definition: pbx.c:6426
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 
)
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, and return 0 on success, -1 on failure.

Definition at line 4914 of file extconf.c.

References ast_switch::name, and ast_exten::priority.

Referenced by ast_findlabel_extension2().

4917 {
4918  struct ast_exten *e;
4919  int res;
4920  struct pbx_find_info q = { .stacklen = 0 }; /* the rest is reset in pbx_find_extension */
4921 
4922  int matching_action = (action == E_MATCH || action == E_CANMATCH || action == E_MATCHMORE);
4923 
4924  e = pbx_find_extension(NULL, con, &q, context, exten, priority, label, callerid, action);
4925  if (e) {
4926  if (matching_action) {
4927  return -1; /* success, we found it */
4928  } else if (action == E_FINDLABEL) { /* map the label to a priority */
4929  res = e->priority;
4930  return res; /* the priority we were looking for */
4931  } else { /* spawn */
4932 
4933  /* NOT!!!!! */
4934  return 0;
4935  }
4936  } else if (q.swo) { /* not found here, but in another switch */
4937  if (matching_action)
4938  return -1;
4939  else {
4940  if (!q.swo->exec) {
4941  ast_log(LOG_WARNING, "No execution engine for switch %s\n", q.swo->name);
4942  res = -1;
4943  }
4944  return q.swo->exec(c, q.foundcontext ? q.foundcontext : context, exten, priority, callerid, q.data);
4945  }
4946  } else { /* not found anywhere, see what happened */
4947  switch (q.status) {
4948  case STATUS_NO_CONTEXT:
4949  if (!matching_action)
4950  ast_log(LOG_NOTICE, "Cannot find extension context '%s'\n", context);
4951  break;
4952  case STATUS_NO_EXTENSION:
4953  if (!matching_action)
4954  ast_log(LOG_NOTICE, "Cannot find extension '%s' in context '%s'\n", exten, context);
4955  break;
4956  case STATUS_NO_PRIORITY:
4957  if (!matching_action)
4958  ast_log(LOG_NOTICE, "No such priority %d in extension '%s' in context '%s'\n", priority, exten, context);
4959  break;
4960  case STATUS_NO_LABEL:
4961  if (context)
4962  ast_log(LOG_NOTICE, "No such label '%s' in extension '%s' in context '%s'\n", label, exten, context);
4963  break;
4964  default:
4965  if (option_debug)
4966  ast_log(LOG_DEBUG, "Shouldn't happen!\n");
4967  }
4968 
4969  return (matching_action) ? 0 : -1;
4970  }
4971 }
ast_exten: An extension The dialplan is saved as a linked list with each context having it's own link...
Definition: pbx.c:237
int option_debug
Definition: options.c:69
const char * name
Definition: pbx.h:162
int priority
Definition: pbx.c:243
static void pbx_retrieve_variable ( struct ast_channel c,
const char *  var,
char **  ret,
char *  workspace,
int  workspacelen,
struct varshead headp 
)
static

Support for Asterisk built-in variables in the dialplan.

Note
See also

Definition at line 5079 of file extconf.c.

References ast_copy_string(), AST_LIST_TRAVERSE, ast_strdupa, parse_variable_name(), and substring().

5080 {
5081  const char not_found = '\0';
5082  char *tmpvar;
5083  const char *s; /* the result */
5084  int offset, length;
5085  int i, need_substring;
5086  struct varshead *places[2] = { headp, &globals }; /* list of places where we may look */
5087 
5088  /*
5089  * Make a copy of var because parse_variable_name() modifies the string.
5090  * Then if called directly, we might need to run substring() on the result;
5091  * remember this for later in 'need_substring', 'offset' and 'length'
5092  */
5093  tmpvar = ast_strdupa(var); /* parse_variable_name modifies the string */
5094  need_substring = parse_variable_name(tmpvar, &offset, &length, &i /* ignored */);
5095 
5096  /*
5097  * Look first into predefined variables, then into variable lists.
5098  * Variable 's' points to the result, according to the following rules:
5099  * s == &not_found (set at the beginning) means that we did not find a
5100  * matching variable and need to look into more places.
5101  * If s != &not_found, s is a valid result string as follows:
5102  * s = NULL if the variable does not have a value;
5103  * you typically do this when looking for an unset predefined variable.
5104  * s = workspace if the result has been assembled there;
5105  * typically done when the result is built e.g. with an snprintf(),
5106  * so we don't need to do an additional copy.
5107  * s != workspace in case we have a string, that needs to be copied
5108  * (the ast_copy_string is done once for all at the end).
5109  * Typically done when the result is already available in some string.
5110  */
5111  s = &not_found; /* default value */
5112  if (s == &not_found) { /* look for more */
5113  if (!strcmp(var, "EPOCH")) {
5114  snprintf(workspace, workspacelen, "%u",(int)time(NULL));
5115  }
5116 
5117  s = workspace;
5118  }
5119  /* if not found, look into chanvars or global vars */
5120  for (i = 0; s == &not_found && i < (sizeof(places) / sizeof(places[0])); i++) {
5121  struct ast_var_t *variables;
5122  if (!places[i])
5123  continue;
5124  if (places[i] == &globals)
5125  ast_rwlock_rdlock(&globalslock);
5126  AST_LIST_TRAVERSE(places[i], variables, entries) {
5127  if (strcasecmp(ast_var_name(variables), var)==0) {
5128  s = ast_var_value(variables);
5129  break;
5130  }
5131  }
5132  if (places[i] == &globals)
5133  ast_rwlock_unlock(&globalslock);
5134  }
5135  if (s == &not_found || s == NULL)
5136  *ret = NULL;
5137  else {
5138  if (s != workspace)
5139  ast_copy_string(workspace, s, workspacelen);
5140  *ret = workspace;
5141  if (need_substring)
5142  *ret = substring(*ret, offset, length, workspace, workspacelen);
5143  }
5144 }
static char * substring(const char *value, int offset, int length, char *workspace, size_t workspace_len)
takes a substring. It is ok to call with value == workspace.
Definition: extconf.c:5038
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: extconf.c:1773
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
static int parse_variable_name(char *var, int *offset, int *length, int *isfunc)
extract offset:length from variable name. Returns 1 if there is a offset:length part, which is trimmed off (values go into variables)
Definition: extconf.c:5003
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
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.

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. Always return a copy in workspace.

Definition at line 5038 of file extconf.c.

References ast_copy_string().

Referenced by pbx_retrieve_variable().

5039 {
5040  char *ret = workspace;
5041  int lr; /* length of the input string after the copy */
5042 
5043  ast_copy_string(workspace, value, workspace_len); /* always make a copy */
5044 
5045  lr = strlen(ret); /* compute length after copy, so we never go out of the workspace */
5046 
5047  /* Quick check if no need to do anything */
5048  if (offset == 0 && length >= lr) /* take the whole string */
5049  return ret;
5050 
5051  if (offset < 0) { /* translate negative offset into positive ones */
5052  offset = lr + offset;
5053  if (offset < 0) /* If the negative offset was greater than the length of the string, just start at the beginning */
5054  offset = 0;
5055  }
5056 
5057  /* too large offset result in empty string so we know what to return */
5058  if (offset >= lr)
5059  return ret + lr; /* the final '\0' */
5060 
5061  ret += offset; /* move to the start position */
5062  if (length >= 0 && length < lr - offset) /* truncate if necessary */
5063  ret[length] = '\0';
5064  else if (length < 0) {
5065  if (lr > offset - length) /* After we remove from the front and from the rear, is there anything left? */
5066  ret[lr + length - offset] = '\0';
5067  else
5068  ret[0] = '\0';
5069  }
5070 
5071  return ret;
5072 }
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425

Variable Documentation

int ast_language_is_prefix

The following variable controls the layout of localized sound files. If 0, use the historical layout with prefix just before the filename (i.e. digits/en/1.gsm , digits/it/1.gsm or default to digits/1.gsm), if 1 put the prefix at the beginning of the filename (i.e. en/digits/1.gsm, it/digits/1.gsm or default to digits/1.gsm). The latter permits a language to be entirely in one directory.

This is settable in asterisk.conf.

Definition at line 67 of file file.c.

Referenced by fileexists_test().

char* comment_buffer
static

Growable string buffer this will be a comment collector.

Definition at line 705 of file extconf.c.

Referenced by config_text_file_load().

int comment_buffer_size
static

the amount of storage so far alloc'd for the comment_buffer

Definition at line 706 of file extconf.c.

ast_rwlock_t conlock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} }
static

Lock for the ast_context list

Definition at line 4482 of file extconf.c.

char* lline_buffer
static

A buffer for stuff behind the ;

Definition at line 708 of file extconf.c.

Referenced by config_text_file_load().

struct sigaction null_sig_handler
static
Initial value:
= {
.sa_handler = _null_sig_handler,
.sa_flags = SA_RESTART,
}
static void _null_sig_handler(int sig)
NULL handler so we can collect the child exit status.
Definition: extconf.c:789

Definition at line 794 of file extconf.c.

struct ast_config_engine text_file_engine
static
Initial value:
= {
.name = "text",
.load_func = config_text_file_load,
}
static struct ast_config * config_text_file_load(const char *database, const char *table, const char *filename, struct ast_config *cfg, struct ast_flags flags, const char *suggested_include_file, const char *who_asked)
Definition: main/config.c:2212

Definition at line 2854 of file extconf.c.