42 #include "../defaults.h"
45 #include <sys/resource.h>
49 #define AST_MIN_DTMF_DURATION 80
51 #define DEFAULT_MONITOR_DIR DEFAULT_SPOOL_DIR "/monitor"
52 #define DEFAULT_RECORDING_DIR DEFAULT_SPOOL_DIR "/recording"
84 #if defined(HAVE_SYSINFO)
88 int ast_option_rtpusedynamic = 1;
89 unsigned int ast_option_rtpptdynamic = 35;
96 char record_cache_dir[AST_CACHE_DIR_LEN] = DEFAULT_TMP_DIR;
98 char ast_defaultlanguage[
MAX_LANGUAGE] = DEFAULT_LANGUAGE;
101 char cache_dir[PATH_MAX];
102 char config_dir[PATH_MAX];
103 char module_dir[PATH_MAX];
104 char spool_dir[PATH_MAX];
105 char monitor_dir[PATH_MAX];
106 char recording_dir[PATH_MAX];
107 char var_dir[PATH_MAX];
108 char data_dir[PATH_MAX];
109 char log_dir[PATH_MAX];
110 char agi_dir[PATH_MAX];
111 char run_dir[PATH_MAX];
112 char key_dir[PATH_MAX];
114 char config_file[PATH_MAX];
115 char db_path[PATH_MAX];
116 char sbin_dir[PATH_MAX];
117 char pid_path[PATH_MAX];
118 char socket_path[PATH_MAX];
119 char run_user[PATH_MAX];
120 char run_group[PATH_MAX];
121 char system_name[128];
122 char ctl_perms[PATH_MAX];
123 char ctl_owner[PATH_MAX];
124 char ctl_group[PATH_MAX];
125 char ctl_file[PATH_MAX];
129 .cache_dir = DEFAULT_CACHE_DIR,
130 .config_dir = DEFAULT_CONFIG_DIR,
131 .module_dir = DEFAULT_MODULE_DIR,
132 .spool_dir = DEFAULT_SPOOL_DIR,
133 .monitor_dir = DEFAULT_MONITOR_DIR,
134 .recording_dir = DEFAULT_RECORDING_DIR,
135 .var_dir = DEFAULT_VAR_DIR,
136 .data_dir = DEFAULT_DATA_DIR,
137 .log_dir = DEFAULT_LOG_DIR,
138 .agi_dir = DEFAULT_AGI_DIR,
139 .run_dir = DEFAULT_RUN_DIR,
140 .key_dir = DEFAULT_KEY_DIR,
142 .config_file = DEFAULT_CONFIG_FILE,
143 .db_path = DEFAULT_DB,
144 .sbin_dir = DEFAULT_SBIN_DIR,
145 .pid_path = DEFAULT_PID,
146 .socket_path = DEFAULT_SOCKET,
147 .ctl_file =
"asterisk.ctl",
150 const char *ast_config_AST_CACHE_DIR = cfg_paths.cache_dir;
151 const char *ast_config_AST_CONFIG_DIR = cfg_paths.config_dir;
152 const char *ast_config_AST_CONFIG_FILE = cfg_paths.config_file;
153 const char *ast_config_AST_MODULE_DIR = cfg_paths.module_dir;
154 const char *ast_config_AST_SPOOL_DIR = cfg_paths.spool_dir;
155 const char *ast_config_AST_MONITOR_DIR = cfg_paths.monitor_dir;
156 const char *ast_config_AST_RECORDING_DIR = cfg_paths.recording_dir;
157 const char *ast_config_AST_VAR_DIR = cfg_paths.var_dir;
158 const char *ast_config_AST_DATA_DIR = cfg_paths.data_dir;
159 const char *ast_config_AST_LOG_DIR = cfg_paths.log_dir;
160 const char *ast_config_AST_AGI_DIR = cfg_paths.agi_dir;
161 const char *ast_config_AST_KEY_DIR = cfg_paths.key_dir;
162 const char *ast_config_AST_RUN_DIR = cfg_paths.run_dir;
163 const char *ast_config_AST_SBIN_DIR = cfg_paths.sbin_dir;
165 const char *ast_config_AST_DB = cfg_paths.db_path;
166 const char *ast_config_AST_PID = cfg_paths.pid_path;
167 const char *ast_config_AST_SOCKET = cfg_paths.socket_path;
168 const char *ast_config_AST_RUN_USER = cfg_paths.run_user;
169 const char *ast_config_AST_RUN_GROUP = cfg_paths.run_group;
170 const char *ast_config_AST_SYSTEM_NAME = cfg_paths.system_name;
172 const char *ast_config_AST_CTL_PERMISSIONS = cfg_paths.ctl_perms;
173 const char *ast_config_AST_CTL_OWNER = cfg_paths.ctl_owner;
174 const char *ast_config_AST_CTL_GROUP = cfg_paths.ctl_group;
175 const char *ast_config_AST_CTL = cfg_paths.ctl_file;
180 struct rlimit l = {0, 0};
183 ast_log(LOG_WARNING,
"Unable to change max files open to invalid value %i\n",value);
190 if (setrlimit(RLIMIT_NOFILE, &l)) {
191 ast_log(LOG_WARNING,
"Unable to disable core size resource limit: %s\n",strerror(errno));
195 ast_log(LOG_NOTICE,
"Setting max files open to %d\n",value);
200 void set_asterisk_conf_path(
const char *path)
202 ast_copy_string(cfg_paths.config_file, path,
sizeof(cfg_paths.config_file));
205 void set_socket_path(
const char *path)
207 ast_copy_string(cfg_paths.socket_path, path,
sizeof(cfg_paths.socket_path));
210 void load_asterisk_conf(
void)
214 char hostname[MAXHOSTNAMELEN] =
"";
217 unsigned int dbdir:1;
218 unsigned int keydir:1;
222 int option_debug_new = 0;
223 int option_trace_new = 0;
224 int option_verbose_new = 0;
242 if (cfg == CONFIG_STATUS_FILEMISSING || cfg == CONFIG_STATUS_FILEUNCHANGED || cfg == CONFIG_STATUS_FILEINVALID) {
243 fprintf(stderr,
"Unable to open specified master config file '%s', using built-in defaults\n", ast_config_AST_CONFIG_FILE);
247 for (v = ast_variable_browse(cfg,
"files"); v; v = v->
next) {
248 if (!strcasecmp(v->
name,
"astctlpermissions")) {
250 }
else if (!strcasecmp(v->
name,
"astctlowner")) {
252 }
else if (!strcasecmp(v->
name,
"astctlgroup")) {
254 }
else if (!strcasecmp(v->
name,
"astctl")) {
259 for (v = ast_variable_browse(cfg,
"directories"); v; v = v->
next) {
260 if (!strcasecmp(v->
name,
"astcachedir")) {
262 }
else if (!strcasecmp(v->
name,
"astetcdir")) {
264 }
else if (!strcasecmp(v->
name,
"astspooldir")) {
266 snprintf(cfg_paths.monitor_dir,
sizeof(cfg_paths.monitor_dir),
"%s/monitor", v->
value);
267 snprintf(cfg_paths.recording_dir,
sizeof(cfg_paths.recording_dir),
"%s/recording", v->
value);
268 }
else if (!strcasecmp(v->
name,
"astvarlibdir")) {
271 snprintf(cfg_paths.db_path,
sizeof(cfg_paths.db_path),
"%s/astdb", v->
value);
273 }
else if (!strcasecmp(v->
name,
"astdbdir")) {
274 snprintf(cfg_paths.db_path,
sizeof(cfg_paths.db_path),
"%s/astdb", v->
value);
276 }
else if (!strcasecmp(v->
name,
"astdatadir")) {
279 snprintf(cfg_paths.key_dir,
sizeof(cfg_paths.key_dir),
"%s/keys", v->
value);
281 }
else if (!strcasecmp(v->
name,
"astkeydir")) {
282 snprintf(cfg_paths.key_dir,
sizeof(cfg_paths.key_dir),
"%s/keys", v->
value);
284 }
else if (!strcasecmp(v->
name,
"astlogdir")) {
286 }
else if (!strcasecmp(v->
name,
"astagidir")) {
288 }
else if (!strcasecmp(v->
name,
"astrundir")) {
289 snprintf(cfg_paths.pid_path,
sizeof(cfg_paths.pid_path),
"%s/%s", v->
value,
"asterisk.pid");
291 }
else if (!strcasecmp(v->
name,
"astmoddir")) {
293 }
else if (!strcasecmp(v->
name,
"astsbindir")) {
299 snprintf(cfg_paths.socket_path,
sizeof(cfg_paths.socket_path),
"%s/%s",
300 ast_config_AST_RUN_DIR, ast_config_AST_CTL);
302 for (v = ast_variable_browse(cfg,
"options"); v; v = v->
next) {
304 if (!strcasecmp(v->
name,
"verbose")) {
305 option_verbose_new = atoi(v->
value);
307 }
else if (!strcasecmp(v->
name,
"timestamp")) {
310 }
else if (!strcasecmp(v->
name,
"execincludes")) {
313 }
else if (!strcasecmp(v->
name,
"debug")) {
314 option_debug_new = 0;
315 if (sscanf(v->
value,
"%30d", &option_debug_new) != 1) {
318 }
else if (!strcasecmp(v->
name,
"trace")) {
319 option_trace_new = 0;
320 if (sscanf(v->
value,
"%30d", &option_trace_new) != 1) {
323 }
else if (!strcasecmp(v->
name,
"refdebug")) {
325 #if HAVE_WORKING_FORK
327 }
else if (!strcasecmp(v->
name,
"nofork")) {
330 }
else if (!strcasecmp(v->
name,
"alwaysfork")) {
334 }
else if (!strcasecmp(v->
name,
"quiet")) {
337 }
else if (!strcasecmp(v->
name,
"console")) {
338 if (!ast_opt_remote) {
342 }
else if (!strcasecmp(v->
name,
"highpriority")) {
345 }
else if (!strcasecmp(v->
name,
"initcrypto")) {
348 }
else if (!strcasecmp(v->
name,
"nocolor")) {
351 }
else if (!strcasecmp(v->
name,
"dontwarn")) {
354 }
else if (!strcasecmp(v->
name,
"dumpcore")) {
357 }
else if (!strcasecmp(v->
name,
"cache_record_files")) {
359 #if !defined(LOW_MEMORY)
361 }
else if (!strcasecmp(v->
name,
"cache_media_frames")) {
365 }
else if (!strcasecmp(v->
name,
"record_cache_dir")) {
368 }
else if (!strcasecmp(v->
name,
"transcode_via_sln")) {
371 }
else if (!strcasecmp(v->
name,
"transmit_silence_during_record") || !strcasecmp(v->
name,
"transmit_silence")) {
373 }
else if (!strcasecmp(v->
name,
"mindtmfduration")) {
377 }
else if (!strcasecmp(v->
name,
"rtp_use_dynamic")) {
381 }
else if (!strcasecmp(v->
name,
"rtp_pt_dynamic")) {
384 }
else if (!strcasecmp(v->
name,
"maxcalls")) {
388 }
else if (!strcasecmp(v->
name,
"maxload")) {
391 if (getloadavg(test, 1) == -1) {
392 ast_log(LOG_ERROR,
"Cannot obtain load average on this system. 'maxload' option disabled.\n");
398 }
else if (!strcasecmp(v->
name,
"maxfiles")) {
400 if (!ast_opt_remote) {
404 }
else if (!strcasecmp(v->
name,
"runuser")) {
407 }
else if (!strcasecmp(v->
name,
"rungroup")) {
409 }
else if (!strcasecmp(v->
name,
"systemname")) {
411 }
else if (!strcasecmp(v->
name,
"autosystemname")) {
413 if (!gethostname(hostname,
sizeof(hostname) - 1)) {
414 ast_copy_string(cfg_paths.system_name, hostname,
sizeof(cfg_paths.system_name));
416 if (ast_strlen_zero(ast_config_AST_SYSTEM_NAME)){
417 ast_copy_string(cfg_paths.system_name,
"localhost",
sizeof(cfg_paths.system_name));
419 ast_log(LOG_ERROR,
"Cannot obtain hostname for this system. Using '%s' instead.\n", ast_config_AST_SYSTEM_NAME);
422 }
else if (!strcasecmp(v->
name,
"languageprefix")) {
424 }
else if (!strcasecmp(v->
name,
"defaultlanguage")) {
426 }
else if (!strcasecmp(v->
name,
"lockmode")) {
427 if (!strcasecmp(v->
value,
"lockfile")) {
429 }
else if (!strcasecmp(v->
value,
"flock")) {
432 ast_log(LOG_WARNING,
"'%s' is not a valid setting for the lockmode option, "
433 "defaulting to 'lockfile'\n", v->
value);
436 #if defined(HAVE_SYSINFO)
437 }
else if (!strcasecmp(v->
name,
"minmemfree")) {
444 }
else if (!strcasecmp(v->
name,
"entityid")) {
449 ast_log(LOG_WARNING,
"Invalid Entity ID '%s' provided\n", v->
value);
451 }
else if (!strcasecmp(v->
name,
"lightbackground")) {
453 }
else if (!strcasecmp(v->
name,
"forceblackbackground")) {
455 }
else if (!strcasecmp(v->
name,
"hideconnect")) {
457 }
else if (!strcasecmp(v->
name,
"lockconfdir")) {
459 }
else if (!strcasecmp(v->
name,
"stdexten")) {
461 if (!strcasecmp(v->
value,
"gosub")) {
463 }
else if (!strcasecmp(v->
value,
"macro")) {
467 "'%s' is not a valid setting for the stdexten option, defaulting to 'gosub'\n",
471 }
else if (!strcasecmp(v->
name,
"live_dangerously")) {
473 }
else if (!strcasecmp(v->
name,
"hide_messaging_ami_events")) {
475 }
else if (!strcasecmp(v->
name,
"sounds_search_custom_dir")) {
479 if (!ast_opt_remote) {
struct ast_variable * next
void astman_live_dangerously(int new_live_dangerously)
Enable/disable the inclusion of 'dangerous' configurations outside of the ast_config_AST_CONFIG_DIR.
Asterisk main include file. File version handling, generic pbx functions.
void ast_set_lock_type(enum AST_LOCK_TYPE type)
Set the type of locks used by ast_lock_path()
int ast_parse_arg(const char *arg, enum ast_parse_flags flags, void *p_result,...)
The argument parsing routine.
unsigned int option_dtmfminduration
String manipulation functions.
#define AST_DEFAULT_OPTIONS
int ast_pjproject_max_log_level
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Structure for variables, used for configurations and for channel variables.
void ast_set_default_eid(struct ast_eid *eid)
Fill in an ast_eid with the default eid of this machine.
double ast_option_maxload
#define AST_RTP_PT_FIRST_DYNAMIC
#define AST_MIN_DTMF_DURATION
An Entity ID is essentially a MAC address, brief and unique.
Configuration File Parser.
Asterisk file paths, configured in asterisk.conf.
int ast_language_is_prefix
The following variable controls the layout of localized sound files. If 0, use the historical layout ...
int ast_str_to_eid(struct ast_eid *eid, const char *s)
Convert a string into an EID.
int ast_option_pjproject_log_level
Core PBX routines and definitions.
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
int ast_option_pjproject_cache_pools
void pbx_live_dangerously(int new_live_dangerously)
Enable/disable the execution of 'dangerous' functions from external protocols (AMI, etc.).
Support for logging to various files, console and syslog Configuration in file logger.conf.
Prototypes for public functions only of internal interest,.
Structure used to handle boolean flags.
static int live_dangerously
Set to true (non-zero) to globally allow all dangerous AMI actions to run.
static void set_ulimit(int value)
Set maximum open files.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Options provided by main asterisk program.
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
Pluggable RTP Architecture.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
struct ast_eid ast_eid_default
Global EID.