Skip to content
Snippets Groups Projects
asterisk.c 67.3 KiB
Newer Older
Mark Spencer's avatar
Mark Spencer committed
/*
 * Asterisk -- An open source telephony toolkit.
Mark Spencer's avatar
Mark Spencer committed
 *
 * Copyright (C) 1999 - 2005, 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.
 */


/* Doxygenified Copyright Header */
/*!
 * \mainpage Asterisk -- An Open Source Telephony Toolkit
 *
 * \par Developer Documentation for Asterisk
 * This is the main developer documentation for Asterisk. It is 
 * generated by running "make progdocs".
 * \par Additional documentation
 * \arg \ref DevDoc 
 * \arg \ref ConfigFiles
 *
 * \section copyright Copyright and author
 *
 * Copyright (C) 1999 - 2005, Digium, Inc.
 * Asterisk is a trade mark registered by Digium, Inc.
 *
 * \author Mark Spencer <markster@digium.com>
 * Also see \ref AstCREDITS
 *
 * \section license License
 * 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.
 * 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.
 *
 * \verbinclude LICENSE
 *
 */

/*! \file
  \brief Top level source file for Asterisk  - the Open Source PBX. Implementation
  of PBX core functions and CLI interface.
  
Mark Spencer's avatar
Mark Spencer committed
 */

#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <stdio.h>
#include <signal.h>
#include <sched.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <sys/resource.h>
#include <grp.h>
#include <pwd.h>
#include <sys/stat.h>
#include <regex.h>
BJ Weschke's avatar
BJ Weschke committed
#ifdef linux
#include <sys/prctl.h>
#endif

#if  defined(__FreeBSD__) || defined( __NetBSD__ ) || defined(SOLARIS)
#include <netdb.h>
#endif

Kevin P. Fleming's avatar
Kevin P. Fleming committed
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/logger.h"
#include "asterisk/options.h"
#include "asterisk/cli.h"
#include "asterisk/channel.h"
#include "asterisk/ulaw.h"
#include "asterisk/alaw.h"
#include "asterisk/callerid.h"
#include "asterisk/module.h"
#include "asterisk/image.h"
#include "asterisk/tdd.h"
#include "asterisk/term.h"
#include "asterisk/manager.h"
#include "asterisk/pbx.h"
#include "asterisk/enum.h"
#include "asterisk/rtp.h"
#if defined(T38_SUPPORT)
#include "asterisk/udptl.h"
#endif
#include "asterisk/app.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/file.h"
#include "asterisk/io.h"
#include "asterisk/lock.h"
Mark Spencer's avatar
Mark Spencer committed
#include "editline/histedit.h"
#include "asterisk/linkedlists.h"
#include "asterisk/compat.h"
#include "asterisk/doxyref.h"		/* Doxygen documentation */

#ifndef AF_LOCAL
#define AF_LOCAL AF_UNIX
#define PF_LOCAL PF_UNIX
#endif

Mark Spencer's avatar
Mark Spencer committed
#define AST_MAX_CONNECTS 128
#define NUM_MSGS 64

/*! \brief Welcome message when starting a CLI interface */
#define WELCOME_MESSAGE \
	ast_verbose("Asterisk " ASTERISK_VERSION ", Copyright (C) 1999 - 2006 Digium, Inc. and others.\n"); \
	ast_verbose("Created by Mark Spencer <markster@digium.com>\n"); \
	ast_verbose("Asterisk comes with ABSOLUTELY NO WARRANTY; type 'show warranty' for details.\n"); \
	ast_verbose("This is free software, with components licensed under the GNU General Public\n"); \
	ast_verbose("License version 2 and other licenses; you are welcome to redistribute it under\n"); \
	ast_verbose("certain conditions. Type 'show license' for details.\n"); \
	ast_verbose("=========================================================================\n")
Mark Spencer's avatar
Mark Spencer committed

/*! \defgroup main_options 
 \brief Main configuration options from \ref Config_ast "asterisk.conf" or 
  the operating system command line when starting Asterisk 
  Some of them can be changed in the CLI 
 */
/*! @{ */
struct ast_flags ast_options = { AST_OPT_FLAG_TRANSCODE_VIA_SLIN };

int option_verbose = 0;				/*!< Verbosity level */
int option_debug = 0;				/*!< Debug level */

double option_maxload = 0.0;			/*!< Max load avg on system */
int option_maxcalls = 0;			/*!< Max number of active calls */
char record_cache_dir[AST_CACHE_DIR_LEN] = AST_TMP_DIR;
char debug_filename[AST_FILENAME_MAX] = "";
static int ast_socket = -1;		/*!< UNIX Socket for allowing remote control */
static int ast_consock = -1;		/*!< UNIX Socket for controlling another asterisk */
Mark Spencer's avatar
Mark Spencer committed
struct console {
	int fd;				/*!< File descriptor */
	int p[2];			/*!< Pipe */
	pthread_t t;			/*!< Thread of handler */
static AST_LIST_HEAD_STATIC(atexits, ast_atexit);
Mark Spencer's avatar
Mark Spencer committed
time_t ast_startuptime;
time_t ast_lastreloadtime;

Mark Spencer's avatar
Mark Spencer committed
static History *el_hist = NULL;
static EditLine *el = NULL;
static char *remotehostname;

Mark Spencer's avatar
Mark Spencer committed
struct console consoles[AST_MAX_CONNECTS];

Mark Spencer's avatar
Mark Spencer committed
char defaultlanguage[MAX_LANGUAGE] = DEFAULT_LANGUAGE;

Mark Spencer's avatar
Mark Spencer committed
static int ast_el_add_history(char *);
static int ast_el_read_history(char *);
static int ast_el_write_history(char *);

char ast_config_AST_CONFIG_DIR[AST_CONFIG_MAX_PATH];
char ast_config_AST_CONFIG_FILE[AST_CONFIG_MAX_PATH];
char ast_config_AST_MODULE_DIR[AST_CONFIG_MAX_PATH];
char ast_config_AST_SPOOL_DIR[AST_CONFIG_MAX_PATH];
char ast_config_AST_MONITOR_DIR[AST_CONFIG_MAX_PATH];
Loading
Loading full blame...