Skip to content
Snippets Groups Projects
pbx.c 164 KiB
Newer Older
Russell Bryant's avatar
Russell Bryant committed
/*
 * Asterisk -- An open source telephony toolkit.
Mark Spencer's avatar
Mark Spencer committed
 *
 * Copyright (C) 1999 - 2006, Digium, Inc.
Mark Spencer's avatar
Mark Spencer committed
 *
 * Mark Spencer <markster@digium.com>
Mark Spencer's avatar
Mark Spencer committed
 *
 * See http://www.asterisk.org for more information about
 * the Asterisk project. Please do not directly contact
 * any of the maintainers of this project for assistance;
 * the project provides a web site, mailing lists and IRC
 * channels for your use.
 *
Mark Spencer's avatar
Mark Spencer committed
 * This program is free software, distributed under the terms of
 * the GNU General Public License Version 2. See the LICENSE file
 * at the top of the source tree.
 */

 * \brief Core PBX routines.
Luigi Rizzo's avatar
Luigi Rizzo committed
 * \author Mark Spencer <markster@digium.com>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>

#include "asterisk.h"

Kevin P. Fleming's avatar
Kevin P. Fleming committed
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/lock.h"
#include "asterisk/cli.h"
#include "asterisk/pbx.h"
#include "asterisk/channel.h"
#include "asterisk/options.h"
#include "asterisk/logger.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"
#define	SAY_STUBS	/* generate declarations and stubs for say methods */
#include "asterisk/say.h"
#include "asterisk/utils.h"
#include "asterisk/causes.h"
#include "asterisk/musiconhold.h"
#include "asterisk/app.h"
#include "asterisk/compat.h"
#include "asterisk/stringfields.h"
/*!
 * \note I M P O R T A N T :
Mark Spencer's avatar
Mark Spencer committed
 *
 *		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 #
Luigi Rizzo's avatar
Luigi Rizzo committed
 * of priorities, but a constant search time here would be great ;-)
#ifdef LOW_MEMORY
#define EXT_DATA_SIZE 256
#else
#define EXT_DATA_SIZE 8192
#endif
#define VAR_BUF_SIZE 4096
#define	VAR_NORMAL		1
#define	VAR_SOFTTRAN	2
#define	VAR_HARDTRAN	3

#define BACKGROUND_SKIP		(1 << 0)
#define BACKGROUND_NOANSWER	(1 << 1)
#define BACKGROUND_MATCHEXTEN	(1 << 2)
#define BACKGROUND_PLAYBACK	(1 << 3)
AST_APP_OPTIONS(background_opts, {
	AST_APP_OPTION('s', BACKGROUND_SKIP),
	AST_APP_OPTION('n', BACKGROUND_NOANSWER),
	AST_APP_OPTION('m', BACKGROUND_MATCHEXTEN),
	AST_APP_OPTION('p', BACKGROUND_PLAYBACK),
AST_APP_OPTIONS(waitexten_opts, {
	AST_APP_OPTION_ARG('m', WAITEXTEN_MOH, 1),
Mark Spencer's avatar
Mark Spencer committed
struct ast_context;

Russell Bryant's avatar
Russell Bryant committed
/*!
Luigi Rizzo's avatar
Luigi Rizzo committed
   \brief 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.
*/
Mark Spencer's avatar
Mark Spencer committed
struct ast_exten {
Russell Bryant's avatar
Russell Bryant committed
	char *exten;			/*!< Extension name */
	int matchcid;			/*!< Match caller id ? */
	const char *cidmatch;		/*!< Caller id to match for this extension */
Russell Bryant's avatar
Russell Bryant committed
	int priority;			/*!< Priority */
Russell Bryant's avatar
Russell Bryant committed
	struct ast_context *parent;	/*!< The context this extension belongs to  */
	const char *app; 		/*!< Application to execute */
Russell Bryant's avatar
Russell Bryant committed
	void *data;			/*!< Data to use (arguments) */
	void (*datad)(void *);		/*!< Data destructor */
	struct ast_exten *peer;		/*!< Next higher priority with our extension */
	const char *registrar;		/*!< Registrar */
	struct ast_exten *next;		/*!< Extension with a greater ID */
/*! \brief ast_include: include= support in extensions.conf */
Mark Spencer's avatar
Mark Spencer committed
struct ast_include {
Luigi Rizzo's avatar
Luigi Rizzo committed
	const char *name;
	const char *rname;			/*!< Context to include */
Russell Bryant's avatar
Russell Bryant committed
	const char *registrar;			/*!< Registrar */
	int hastime;				/*!< If time construct exists */
	struct ast_timing timing;               /*!< time construct */
	struct ast_include *next;		/*!< Link them together */
/*! \brief ast_sw: Switch statement in extensions.conf */
Mark Spencer's avatar
Mark Spencer committed
struct ast_sw {
Russell Bryant's avatar
Russell Bryant committed
	const char *registrar;			/*!< Registrar */
	char *data;				/*!< Data load */
/*! \brief ast_ignorepat: Ignore patterns in dial plan */
Mark Spencer's avatar
Mark Spencer committed
struct ast_ignorepat {
	const char *registrar;
Mark Spencer's avatar
Mark Spencer committed
	struct ast_ignorepat *next;
/*! \brief ast_context: An extension context */
Mark Spencer's avatar
Mark Spencer committed
struct ast_context {
	ast_mutex_t lock; 			/*!< A lock to prevent multiple threads from clobbering the context */
	struct ast_exten *root;			/*!< The root of the list of extensions */
	struct ast_context *next;		/*!< Link them together */
	struct ast_include *includes;		/*!< Include other contexts */
	struct ast_ignorepat *ignorepats;	/*!< Patterns for which to continue playing dialtone */
	const char *registrar;			/*!< Registrar */
	AST_LIST_HEAD_NOLOCK(, ast_sw) alts;	/*!< Alternative switches */
	char name[0];				/*!< Name of the context */
/*! \brief ast_app: A registered application */
Mark Spencer's avatar
Mark Spencer committed
struct ast_app {
	int (*execute)(struct ast_channel *chan, void *data);
Russell Bryant's avatar
Russell Bryant committed
	const char *synopsis;			/*!< Synopsis text for 'show applications' */
Kevin P. Fleming's avatar
Kevin P. Fleming committed
	const char *description;		/*!< Description (help text) for 'show application &lt;name&gt;' */
	AST_LIST_ENTRY(ast_app) list;		/*!< Next app in list */
	struct module *module;			/*!< Module this app belongs to */
Russell Bryant's avatar
Russell Bryant committed
	char name[0];				/*!< Name of the application */
/*! \brief ast_state_cb: An extension state notify register item */
Russell Bryant's avatar
Russell Bryant committed
	int id;
	void *data;
	ast_state_cb_type callback;
	struct ast_state_cb *next;
/*! \brief Structure for dial plan hints

  Hints are pointers from an extension in the dialplan to one or
  more devices (tech/name) */
	struct ast_exten *exten;	/*!< Extension */
	int laststate; 			/*!< Last known state */
	struct ast_state_cb *callbacks;	/*!< Callback list for this extension */
	AST_LIST_ENTRY(ast_hint) list;	/*!< Pointer to next hint in list */
Loading
Loading full blame...