/* Request a video update */
ast_indicate(chan, AST_CONTROL_VIDUPDATE);
- if (option_transmit_silence_during_record)
+ if (ast_opt_transmit_silence)
silgen = ast_channel_start_silence_generator(chan);
if (x == fmtcnt) {
if (res < 1) {
pbx_builtin_setvar_helper(chan, "AVAILCHAN", "");
pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", "");
- if (priority_jump || option_priority_jumping) {
+ if (priority_jump || ast_opt_priority_jumping) {
if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) {
LOCAL_USER_REMOVE(u);
return -1;
pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "USERSTOPPED");
} else {
if (res < 0) {
- if (priority_jump || option_priority_jumping) {
+ if (priority_jump || ast_opt_priority_jumping) {
if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) {
ast_log(LOG_WARNING, "ControlPlayback tried to jump to priority n+101 as requested, but priority didn't exist\n");
}
} else {
if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "DBget: Value not found in database.\n");
- if (priority_jump || option_priority_jumping) {
+ if (priority_jump || ast_opt_priority_jumping) {
/* Send the call to n+101 priority, where n is the current priority */
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
}
strcpy(status, "CONGESTION");
else if (numnochan)
strcpy(status, "CHANUNAVAIL");
- if (option_priority_jumping || priority_jump)
+ if (ast_opt_priority_jumping || priority_jump)
ast_goto_if_exists(in, in->context, in->exten, in->priority + 101);
} else {
if (option_verbose > 2)
if ((macro_result = pbx_builtin_getvar_helper(peer, "MACRO_RESULT"))) {
if (!strcasecmp(macro_result, "BUSY")) {
ast_copy_string(status, macro_result, sizeof(status));
- if (option_priority_jumping || ast_test_flag(&opts, OPT_PRIORITY_JUMP)) {
+ if (ast_opt_priority_jumping || ast_test_flag(&opts, OPT_PRIORITY_JUMP)) {
if (!ast_goto_if_exists(chan, NULL, NULL, chan->priority + 101)) {
ast_set_flag(peerflags, OPT_GO_ON);
}
res = ast_get_enum(chan, args.d, dest, sizeof(dest), tech, sizeof(tech), NULL, NULL);
if (!res) { /* Failed to do a lookup */
- if (priority_jump || option_priority_jumping) {
+ if (priority_jump || ast_opt_priority_jumping) {
/* Look for a "busy" place */
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
}
*t = 0;
pbx_builtin_setvar_helper(chan, "ENUM", tmp);
ast_log(LOG_NOTICE, "tel: ENUM set to \"%s\"\n", tmp);
- if (priority_jump || option_priority_jumping) {
+ if (priority_jump || ast_opt_priority_jumping) {
if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 51))
res = 0;
}
count = ast_app_group_get_count(pbx_builtin_getvar_helper(chan, category), category);
if (count > max) {
pbx_builtin_setvar_helper(chan, "CHECKGROUPSTATUS", "OVERMAX");
- if (priority_jump || option_priority_jumping) {
+ if (priority_jump || ast_opt_priority_jumping) {
if (!ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101))
res = -1;
}
if (vmcount > 0) {
/* Branch to the next extension */
- if (priority_jump || option_priority_jumping) {
+ if (priority_jump || ast_opt_priority_jumping) {
if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101))
ast_log(LOG_WARNING, "VM box %s@%s has new voicemail, but extension %s, priority %d doesn't exist\n", vmbox, context, chan->exten, chan->priority + 101);
}
if (!ast_supports_images(chan)) {
/* Does not support transport */
- if (priority_jump || option_priority_jumping)
+ if (priority_jump || ast_opt_priority_jumping)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "NOSUPPORT");
LOCAL_USER_REMOVE(u);
}
if (bl) {
- if (priority_jump || option_priority_jumping)
+ if (priority_jump || ast_opt_priority_jumping)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
pbx_builtin_setvar_helper(chan, "LOOKUPBLSTATUS", "FOUND");
} else
if (option_debug > 2)
ast_log(LOG_DEBUG, "ERROR: MD5 not verified: %s -- %s\n", args.md5hash, args.string);
pbx_builtin_setvar_helper(chan, "CHECKMD5STATUS", "NOMATCH");
- if (priority_jump || option_priority_jumping) {
+ if (priority_jump || ast_opt_priority_jumping) {
if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101))
if (option_debug > 2)
ast_log(LOG_DEBUG, "ERROR: Can't jump to exten+101 (e%s,p%d), sorry\n", chan->exten,chan->priority+101);
}
if (!res) {
/* Look for a "busy" place */
- if (priority_jump || option_priority_jumping)
+ if (priority_jump || ast_opt_priority_jumping)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
} else if (res > 0)
res = 0;
}
if (!res) {
/* Look for a "busy" place */
- if (priority_jump || option_priority_jumping)
+ if (priority_jump || ast_opt_priority_jumping)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
} else if (res > 0)
res = 0;
}
if (!res) {
/* Look for a "busy" place */
- if (priority_jump || option_priority_jumping)
+ if (priority_jump || ast_opt_priority_jumping)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
} else if (res > 0)
res = 0;
ast_stopstream(chan);
} else {
ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", chan->name, (char *)data);
- if (priority_jump || option_priority_jumping)
+ if (priority_jump || ast_opt_priority_jumping)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
res = 0;
mres = 1;
ast_verbose (VERBOSE_PREFIX_3 "Changed Caller*ID to %s\n",phone);
pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "SUCCESS");
} else {
- if (priority_jump || option_priority_jumping)
+ if (priority_jump || ast_opt_priority_jumping)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
pbx_builtin_setvar_helper(chan, "PRIVACYMGRSTATUS", "FAILED");
}
if (set_member_paused(args.queuename, args.interface, 1)) {
ast_log(LOG_WARNING, "Attempt to pause interface %s, not found\n", args.interface);
- if (priority_jump || option_priority_jumping) {
+ if (priority_jump || ast_opt_priority_jumping) {
if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) {
pbx_builtin_setvar_helper(chan, "PQMSTATUS", "NOTFOUND");
LOCAL_USER_REMOVE(u);
if (set_member_paused(args.queuename, args.interface, 0)) {
ast_log(LOG_WARNING, "Attempt to unpause interface %s, not found\n", args.interface);
- if (priority_jump || option_priority_jumping) {
+ if (priority_jump || ast_opt_priority_jumping) {
if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) {
pbx_builtin_setvar_helper(chan, "UPQMSTATUS", "NOTFOUND");
LOCAL_USER_REMOVE(u);
break;
case RES_EXISTS:
ast_log(LOG_WARNING, "Unable to remove interface '%s' from queue '%s': Not there\n", args.interface, args.queuename);
- if (priority_jump || option_priority_jumping)
+ if (priority_jump || ast_opt_priority_jumping)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
pbx_builtin_setvar_helper(chan, "RQMSTATUS", "NOTINQUEUE");
res = 0;
break;
case RES_EXISTS:
ast_log(LOG_WARNING, "Unable to add interface '%s' to queue '%s': Already there\n", args.interface, args.queuename);
- if (priority_jump || option_priority_jumping)
+ if (priority_jump || ast_opt_priority_jumping)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
pbx_builtin_setvar_helper(chan, "AQMSTATUS", "MEMBERALREADY");
res = 0;
goto out;
}
- if (option_transmit_silence_during_record)
+ if (ast_opt_transmit_silence)
silgen = ast_channel_start_silence_generator(chan);
/* Request a video update */
if (!chan->tech->send_text) {
ast_mutex_unlock(&chan->lock);
/* Does not support transport */
- if (priority_jump || option_priority_jumping)
+ if (priority_jump || ast_opt_priority_jumping)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
LOCAL_USER_REMOVE(u);
return 0;
} else {
if (res < 0)
res = 0;
- if (option_priority_jumping && res)
+ if (ast_opt_priority_jumping && res)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
if (res != 0)
if (res < 0) {
status = "FAILURE";
- if (priority_jump || option_priority_jumping)
+ if (priority_jump || ast_opt_priority_jumping)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
res = 0;
} else {
}
if (!res) {
/* Look for a "busy" place */
- if (priority_jump || option_priority_jumping)
+ if (priority_jump || ast_opt_priority_jumping)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
pbx_builtin_setvar_helper(chan, "TXTCIDNAMESTATUS", "FAILED");
} else if (res > 0)
if (!ast_channel_supports_html(chan)) {
/* Does not support transport */
- if (local_option_jump || option_priority_jumping)
+ if (local_option_jump || ast_opt_priority_jumping)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
pbx_builtin_setvar_helper(chan, "SENDURLSTATUS", "UNSUPPORTED");
LOCAL_USER_REMOVE(u);
case AST_HTML_NOSUPPORT:
/* Does not support transport */
status ="UNSUPPORTED";
- if (local_option_jump || option_priority_jumping)
+ if (local_option_jump || ast_opt_priority_jumping)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
res = 0;
goto out;
if (!(vmu = find_user(&svm, context, ext))) {
ast_log(LOG_WARNING, "No entry in voicemail config file for '%s'\n", ext);
- if (ast_test_flag(options, OPT_PRIORITY_JUMP) || option_priority_jumping)
+ if (ast_test_flag(options, OPT_PRIORITY_JUMP) || ast_opt_priority_jumping)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED");
return res;
if (res == ERROR_LOCK_PATH) {
ast_log(LOG_ERROR, "Could not leave voicemail. The path is already locked.\n");
/*Send the call to n+101 priority, where n is the current priority*/
- if (ast_test_flag(&leave_options, OPT_PRIORITY_JUMP) || option_priority_jumping)
+ if (ast_test_flag(&leave_options, OPT_PRIORITY_JUMP) || ast_opt_priority_jumping)
if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101))
ast_log(LOG_WARNING, "Extension %s, priority %d doesn't exist.\n", chan->exten, chan->priority + 101);
pbx_builtin_setvar_helper(chan, "VMSTATUS", "FAILED");
if (find_user(&svm, context, args.mbox)) {
pbx_builtin_setvar_helper(chan, "VMBOXEXISTSSTATUS", "SUCCESS");
- if (priority_jump || option_priority_jumping)
+ if (priority_jump || ast_opt_priority_jumping)
if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101))
ast_log(LOG_WARNING, "VM box %s@%s exists, but extension %s, priority %d doesn't exist\n", box, context, chan->exten, chan->priority + 101);
} else
Some of them can be changed in the CLI
*/
/*! @{ */
-int option_verbose=0; /*!< Verbosity level */
-int option_debug=0; /*!< Debug level */
-int option_exec_includes=0; /*!< Allow \#exec in config files? */
-int option_nofork=0; /*!< Do not fork */
-int option_quiet=0; /*!< Keep quiet */
-int option_console=0; /*!< Console mode, no background */
-int option_highpriority=0; /*!< Run in realtime Linux priority */
-int option_remote=0; /*!< Remote CLI */
-int option_exec=0; /*!< */
-int option_initcrypto=0; /*!< Initialize crypto keys for RSA auth */
-int option_nocolor; /*!< Don't use termcap colors */
-int option_dumpcore = 0; /*!< Dump core when failing */
-int option_cache_record_files = 0; /*!< Cache sound files */
-int option_timestamp = 0; /*!< Timestamp in logging */
-int option_overrideconfig = 0; /*!< */
-int option_reconnect = 0; /*!< */
-int option_transcode_slin = 1; /*!< */
-int option_maxcalls = 0; /*!< */
+
+struct ast_flags ast_options = { AST_OPT_FLAG_TRANSCODE_VIA_SLIN | AST_OPT_FLAG_PRIORITY_JUMPING };
+
+int option_verbose = 0; /*!< Verbosity level */
+int option_debug = 0; /*!< Debug level */
+
double option_maxload = 0.0; /*!< Max load avg on system */
-int option_dontwarn = 0; /*!< */
-int option_priority_jumping = 1; /*!< Enable priority jumping as result value for apps */
-int option_transmit_silence_during_record = 0; /*!< Transmit silence during record() app */
+int option_maxcalls = 0; /*!< Max number of active calls */
/*! @} */
-int fully_booted = 0;
char record_cache_dir[AST_CACHE_DIR_LEN] = AST_TMP_DIR;
char debug_filename[AST_FILENAME_MAX] = "";
if (!nice) {
/* Begin shutdown routine, hanging up active channels */
ast_begin_shutdown(1);
- if (option_verbose && option_console)
+ if (option_verbose && ast_opt_console)
ast_verbose("Beginning asterisk %s....\n", restart ? "restart" : "shutdown");
time(&s);
for(;;) {
} else {
if (nice < 2)
ast_begin_shutdown(0);
- if (option_verbose && option_console)
+ if (option_verbose && ast_opt_console)
ast_verbose("Waiting for inactivity to perform %s...\n", restart ? "restart" : "halt");
for(;;) {
if (!ast_active_channels())
}
if (!shuttingdown) {
- if (option_verbose && option_console)
+ if (option_verbose && ast_opt_console)
ast_verbose("Asterisk %s cancelled.\n", restart ? "restart" : "shutdown");
return;
}
}
- if (option_console || option_remote) {
+ if (ast_opt_console || ast_opt_remote) {
if (getenv("HOME"))
snprintf(filename, sizeof(filename), "%s/.asterisk_history", getenv("HOME"));
if (!ast_strlen_zero(filename))
ast_verbose("Executing last minute cleanups\n");
ast_run_atexits();
/* Called on exit */
- if (option_verbose && option_console)
+ if (option_verbose && ast_opt_console)
ast_verbose("Asterisk %s ending (%d).\n", ast_active_channels() ? "uncleanly" : "cleanly", num);
else if (option_debug)
ast_log(LOG_DEBUG, "Asterisk ending (%d).\n", num);
if (ast_consock > -1)
close(ast_consock);
if (ast_socket > -1)
- unlink((char *)ast_config_AST_SOCKET);
- if (!option_remote) unlink((char *)ast_config_AST_PID);
+ unlink(ast_config_AST_SOCKET);
+ if (!ast_opt_remote)
+ unlink(ast_config_AST_PID);
printf(term_quit());
if (restart) {
- if (option_verbose || option_console)
+ if (option_verbose || ast_opt_console)
ast_verbose("Preparing for Asterisk restart...\n");
/* Mark all FD's for closing on exec */
for (x=3;x<32768;x++) {
fcntl(x, F_SETFD, FD_CLOEXEC);
}
- if (option_verbose || option_console)
+ if (option_verbose || ast_opt_console)
ast_verbose("Restarting Asterisk NOW...\n");
restartnow = 1;
fflush(stdout);
if (complete) {
/* Wake up a poll()ing console */
- if (option_console && consolethread != AST_PTHREADT_NULL)
+ if (ast_opt_console && consolethread != AST_PTHREADT_NULL)
pthread_kill(consolethread, SIGURG);
}
}
max = 1;
fds[0].fd = ast_consock;
fds[0].events = POLLIN;
- if (!option_exec) {
+ if (!ast_opt_exec) {
fds[1].fd = STDIN_FILENO;
fds[1].events = POLLIN;
max++;
break;
}
- if (!option_exec && fds[1].revents) {
+ if (!ast_opt_exec && fds[1].revents) {
num_read = read(STDIN_FILENO, cp, 1);
if (num_read < 1) {
break;
/* if the remote side disappears exit */
if (res < 1) {
fprintf(stderr, "\nDisconnected from Asterisk server\n");
- if (!option_reconnect) {
+ if (!ast_opt_reconnect) {
quit_handler(0, 0, 0, 0);
} else {
int tries;
buf[res] = '\0';
- if (!option_exec && !lastpos)
+ if (!ast_opt_exec && !lastpos)
write(STDOUT_FILENO, "\r", 1);
write(STDOUT_FILENO, buf, res);
if ((buf[res-1] == '\n') || (buf[res-2] == '\n')) {
}
break;
case '#': /* process console or remote? */
- if (! option_remote) {
+ if (!ast_opt_remote) {
strncat(p, "#", sizeof(prompt) - strlen(prompt) - 1);
} else {
strncat(p, ">", sizeof(prompt) - strlen(prompt) - 1);
len = lf->cursor - ptr;
- if (option_remote) {
+ if (ast_opt_remote) {
snprintf(buf, sizeof(buf),"_COMMAND NUMMATCHES \"%s\" \"%s\"", lf->buffer, ptr);
fdprint(ast_consock, buf);
res = read(ast_consock, buf, sizeof(buf));
if (!ast_strlen_zero(filename))
ast_el_read_history(filename);
- if (option_exec && data) { /* hack to print output then exit if asterisk -rx is used */
+ if (ast_opt_exec && data) { /* hack to print output then exit if asterisk -rx is used */
char tempchar;
struct pollfd fds[0];
fds[0].fd = ast_consock;
struct ast_variable *v;
char *config = AST_CONFIG_FILE;
- if (option_overrideconfig == 1) {
+ if (ast_opt_override_config) {
cfg = ast_config_load(ast_config_AST_CONFIG_FILE);
if (!cfg)
ast_log(LOG_WARNING, "Unable to open specified master config file '%s', using built-in defaults\n", ast_config_AST_CONFIG_FILE);
option_verbose = atoi(v->value);
/* whether or not to force timestamping. (-T at startup) */
} else if (!strcasecmp(v->name, "timestamp")) {
- option_timestamp = ast_true(v->value);
+ ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_TIMESTAMP);
/* whether or not to support #exec in config files */
} else if (!strcasecmp(v->name, "execincludes")) {
- option_exec_includes = ast_true(v->value);
+ ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_EXEC_INCLUDES);
/* debug level (-d at startup) */
} else if (!strcasecmp(v->name, "debug")) {
option_debug = 0;
}
/* Disable forking (-f at startup) */
} else if (!strcasecmp(v->name, "nofork")) {
- option_nofork = ast_true(v->value);
+ ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_NO_FORK);
/* Run quietly (-q at startup ) */
} else if (!strcasecmp(v->name, "quiet")) {
- option_quiet = ast_true(v->value);
+ ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_QUIET);
/* Run as console (-c at startup, implies nofork) */
} else if (!strcasecmp(v->name, "console")) {
- option_console = ast_true(v->value);
+ ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_CONSOLE);
/* Run with highg priority if the O/S permits (-p at startup) */
} else if (!strcasecmp(v->name, "highpriority")) {
- option_highpriority = ast_true(v->value);
+ ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_HIGH_PRIORITY);
/* Initialize RSA auth keys (IAX2) (-i at startup) */
} else if (!strcasecmp(v->name, "initcrypto")) {
- option_initcrypto = ast_true(v->value);
+ ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_INIT_KEYS);
/* Disable ANSI colors for console (-c at startup) */
} else if (!strcasecmp(v->name, "nocolor")) {
- option_nocolor = ast_true(v->value);
+ ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_NO_COLOR);
/* Disable some usage warnings for picky people :p */
} else if (!strcasecmp(v->name, "dontwarn")) {
- option_dontwarn = ast_true(v->value);
+ ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_DONT_WARN);
/* Dump core in case of crash (-g) */
} else if (!strcasecmp(v->name, "dumpcore")) {
- option_dumpcore = ast_true(v->value);
+ ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_DUMP_CORE);
/* Cache recorded sound files to another directory during recording */
} else if (!strcasecmp(v->name, "cache_record_files")) {
- option_cache_record_files = ast_true(v->value);
+ ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_CACHE_RECORD_FILES);
/* Specify cache directory */
} else if (!strcasecmp(v->name, "record_cache_dir")) {
ast_copy_string(record_cache_dir, v->value, AST_CACHE_DIR_LEN);
/* Build transcode paths via SLINEAR, instead of directly */
} else if (!strcasecmp(v->name, "transcode_via_sln")) {
- option_transcode_slin = ast_true(v->value);
+ ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_TRANSCODE_VIA_SLIN);
/* Transmit SLINEAR silence while a channel is being recorded */
} else if (!strcasecmp(v->name, "transmit_silence_during_record")) {
- option_transmit_silence_during_record = ast_true(v->value);
+ ast_set2_flag(&ast_options, ast_true(v->value), AST_OPT_FLAG_TRANSMIT_SILENCE);
} else if (!strcasecmp(v->name, "maxcalls")) {
if ((sscanf(v->value, "%d", &option_maxcalls) != 1) || (option_maxcalls < 0)) {
option_maxcalls = 0;
/* if the progname is rasterisk consider it a remote console */
if (argv[0] && (strstr(argv[0], "rasterisk")) != NULL) {
- option_remote++;
- option_nofork++;
+ ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
}
if (gethostname(hostname, sizeof(hostname)-1))
ast_copy_string(hostname, "<Unknown>", sizeof(hostname));
switch(c) {
case 'd':
option_debug++;
- option_nofork++;
+ ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
break;
case 'c':
- option_console++;
- option_nofork++;
+ ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_CONSOLE);
break;
case 'f':
- option_nofork++;
+ ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
break;
case 'n':
- option_nocolor++;
+ ast_set_flag(&ast_options, AST_OPT_FLAG_NO_COLOR);
break;
case 'r':
- option_remote++;
- option_nofork++;
+ ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE);
break;
case 'R':
- option_remote++;
- option_nofork++;
- option_reconnect++;
+ ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK | AST_OPT_FLAG_REMOTE | AST_OPT_FLAG_RECONNECT);
break;
case 'p':
- option_highpriority++;
+ ast_set_flag(&ast_options, AST_OPT_FLAG_HIGH_PRIORITY);
break;
case 'v':
option_verbose++;
- option_nofork++;
+ ast_set_flag(&ast_options, AST_OPT_FLAG_NO_FORK);
break;
case 'M':
if ((sscanf(optarg, "%d", &option_maxcalls) != 1) || (option_maxcalls < 0))
option_maxload = 0.0;
break;
case 'q':
- option_quiet++;
+ ast_set_flag(&ast_options, AST_OPT_FLAG_QUIET);
break;
case 't':
- option_cache_record_files++;
+ ast_set_flag(&ast_options, AST_OPT_FLAG_CACHE_RECORD_FILES);
break;
case 'T':
- option_timestamp++;
+ ast_set_flag(&ast_options, AST_OPT_FLAG_TIMESTAMP);
break;
case 'x':
- option_exec++;
+ ast_set_flag(&ast_options, AST_OPT_FLAG_EXEC);
xarg = optarg;
break;
case 'C':
- ast_copy_string((char *)ast_config_AST_CONFIG_FILE,optarg,sizeof(ast_config_AST_CONFIG_FILE));
- option_overrideconfig++;
+ ast_copy_string(ast_config_AST_CONFIG_FILE, optarg, sizeof(ast_config_AST_CONFIG_FILE));
+ ast_set_flag(&ast_options, AST_OPT_FLAG_OVERRIDE_CONFIG);
break;
case 'i':
- option_initcrypto++;
+ ast_set_flag(&ast_options, AST_OPT_FLAG_INIT_KEYS);
break;
case'g':
- option_dumpcore++;
+ ast_set_flag(&ast_options, AST_OPT_FLAG_DUMP_CORE);
break;
case 'h':
show_cli_help();
/* For remote connections, change the name of the remote connection.
* We do this for the benefit of init scripts (which need to know if/when
* the main asterisk process has died yet). */
- if (option_remote) {
+ if (ast_opt_remote) {
strcpy(argv[0], "rasterisk");
for (x = 1; x < argc; x++) {
argv[x] = argv[0] + 10;
}
}
- if (option_dumpcore) {
+ if (ast_opt_dump_core) {
struct rlimit l;
memset(&l, 0, sizeof(l));
l.rlim_cur = RLIM_INFINITY;
}
}
- if (option_console && !option_verbose)
+ if (ast_opt_console && !option_verbose)
ast_verbose("[ Reading Master Configuration ]");
ast_readconfig();
#ifndef __CYGWIN__
if (!is_child_of_nonroot)
- ast_set_priority(option_highpriority);
+ ast_set_priority(ast_opt_high_priority);
if (!is_child_of_nonroot && rungroup) {
struct group *gr;
printf(term_end());
fflush(stdout);
- if (option_console && !option_verbose)
+ if (ast_opt_console && !option_verbose)
ast_verbose("[ Initializing Custom Configuration Options ]");
/* custom config setup */
register_config_cli();
read_config_maps();
- if (option_console) {
+ if (ast_opt_console) {
if (el_hist == NULL || el == NULL)
ast_el_initialize();
if (ast_tryconnect()) {
/* One is already running */
- if (option_remote) {
- if (option_exec) {
+ if (ast_opt_remote) {
+ if (ast_opt_exec) {
ast_remotecontrol(xarg);
quit_handler(0, 0, 0, 0);
exit(0);
quit_handler(0, 0, 0, 0);
exit(0);
} else {
- ast_log(LOG_ERROR, "Asterisk already running on %s. Use 'asterisk -r' to connect.\n", (char *)ast_config_AST_SOCKET);
+ ast_log(LOG_ERROR, "Asterisk already running on %s. Use 'asterisk -r' to connect.\n", ast_config_AST_SOCKET);
printf(term_quit());
exit(1);
}
- } else if (option_remote || option_exec) {
+ } else if (ast_opt_remote || ast_opt_exec) {
ast_log(LOG_ERROR, "Unable to connect to remote asterisk (does %s exist?)\n",ast_config_AST_SOCKET);
printf(term_quit());
exit(1);
}
/* Blindly write pid file since we couldn't connect */
- unlink((char *)ast_config_AST_PID);
- f = fopen((char *)ast_config_AST_PID, "w");
+ unlink(ast_config_AST_PID);
+ f = fopen(ast_config_AST_PID, "w");
if (f) {
fprintf(f, "%d\n", getpid());
fclose(f);
} else
- ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", (char *)ast_config_AST_PID, strerror(errno));
+ ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", ast_config_AST_PID, strerror(errno));
- if (!option_verbose && !option_debug && !option_nofork && !option_console) {
+ if (!option_verbose && !option_debug && !ast_opt_no_fork && !ast_opt_console) {
daemon(0,0);
/* Blindly re-write pid file since we are forking */
- unlink((char *)ast_config_AST_PID);
- f = fopen((char *)ast_config_AST_PID, "w");
+ unlink(ast_config_AST_PID);
+ f = fopen(ast_config_AST_PID, "w");
if (f) {
fprintf(f, "%d\n", getpid());
fclose(f);
} else
- ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", (char *)ast_config_AST_PID, strerror(errno));
+ ast_log(LOG_WARNING, "Unable to open pid file '%s': %s\n", ast_config_AST_PID, strerror(errno));
}
/* Test recursive mutex locking. */
sigaddset(&sigs, SIGPIPE);
sigaddset(&sigs, SIGWINCH);
pthread_sigmask(SIG_BLOCK, &sigs, NULL);
- if (option_console || option_verbose || option_remote)
+ if (ast_opt_console || option_verbose || ast_opt_remote)
ast_register_verbose(console_verboser);
/* Print a welcome message if desired */
- if (option_verbose || option_console) {
+ if (option_verbose || ast_opt_console) {
WELCOME_MESSAGE;
}
- if (option_console && !option_verbose)
+ if (ast_opt_console && !option_verbose)
ast_verbose("[ Booting...");
signal(SIGURG, urg_handler);
/* We might have the option of showing a console, but for now just
do nothing... */
- if (option_console && !option_verbose)
+ if (ast_opt_console && !option_verbose)
ast_verbose(" ]\n");
- if (option_verbose || option_console)
+ if (option_verbose || ast_opt_console)
ast_verbose(term_color(tmp, "Asterisk Ready.\n", COLOR_BRWHITE, COLOR_BLACK, sizeof(tmp)));
- if (option_nofork)
+ if (ast_opt_no_fork)
consolethread = pthread_self();
- fully_booted = 1;
+ ast_set_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED);
pthread_sigmask(SIG_UNBLOCK, &sigs, NULL);
#ifdef __AST_DEBUG_MALLOC
__ast_mm_init();
#endif
time(&ast_startuptime);
ast_cli_register_multiple(core_cli, sizeof(core_cli) / sizeof(core_cli[0]));
- if (option_console) {
+ if (ast_opt_console) {
/* Console stuff now... */
/* Register our quit function */
char title[256];
/* if the best path is not 'pass through', then
transcoding is needed; if desired, force transcode path
to use SLINEAR between channels */
- if ((src != dst) && option_transcode_slin)
+ if ((src != dst) && ast_opt_transcode_via_slin)
dst = AST_FORMAT_SLINEAR;
if (ast_set_read_format(chan, dst) < 0) {
ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", chan->name, dst);
/* if the best path is not 'pass through', then
transcoding is needed; if desired, force transcode path
to use SLINEAR between channels */
- if ((src != dst) && option_transcode_slin)
+ if ((src != dst) && ast_opt_transcode_via_slin)
dst = AST_FORMAT_SLINEAR;
if (ast_set_read_format(peer, dst) < 0) {
ast_log(LOG_WARNING, "Unable to set read format on channel %s to %d\n", peer->name, dst);
do_exec = !strcasecmp(cur, "exec");
else
do_exec = 0;
- if (do_exec && !option_exec_includes) {
+ if (do_exec && !ast_opt_exec_includes) {
ast_log(LOG_WARNING, "Cannot perform #exec unless execincludes option is enabled in asterisk.conf (options section)!\n");
do_exec = 0;
}
}
}
- if (option_cache_record_files && (fd > -1)) {
+ if (ast_opt_cache_record_files && (fd > -1)) {
char *c;
fclose(bfile);
if ((argc < 2) || (argc > 3))
return RESULT_SHOWUSAGE;
- if (!option_dontwarn)
+ if (!ast_opt_dont_warn)
ast_cli(fd, "Disclaimer: this command is for informational purposes only.\n"
"\tIt does not indicate anything about your configuration.\n");
a; \
}
+#define VERBOSE_PREFIX_1 " "
+#define VERBOSE_PREFIX_2 " == "
+#define VERBOSE_PREFIX_3 " -- "
+#define VERBOSE_PREFIX_4 " > "
+
/*! Used for sending a log message */
/*!
\brief This is the standard logger function. Probably the only way you will invoke it would be something like this:
extern "C" {
#endif
-#define AST_CACHE_DIR_LEN 512
+#define AST_CACHE_DIR_LEN 512
#define AST_FILENAME_MAX 80
+enum ast_option_flags {
+ /*! Allow \#exec in config files */
+ AST_OPT_FLAG_EXEC_INCLUDES = (1 << 0),
+ /*! Do not fork() */
+ AST_OPT_FLAG_NO_FORK = (1 << 1),
+ /*! Keep quiet */
+ AST_OPT_FLAG_QUIET = (1 << 2),
+ /*! Console mode */
+ AST_OPT_FLAG_CONSOLE = (1 << 3),
+ /*! Run in realtime Linux priority */
+ AST_OPT_FLAG_HIGH_PRIORITY = (1 << 4),
+ /*! Initialize keys for RSA authentication */
+ AST_OPT_FLAG_INIT_KEYS = (1 << 5),
+ /*! Remote console */
+ AST_OPT_FLAG_REMOTE = (1 << 6),
+ /*! Execute an asterisk CLI command upon startup */
+ AST_OPT_FLAG_EXEC = (1 << 7),
+ /*! Don't use termcap colors */
+ AST_OPT_FLAG_NO_COLOR = (1 << 8),
+ /*! Are we fully started yet? */
+ AST_OPT_FLAG_FULLY_BOOTED = (1 << 9),
+ /*! Trascode via signed linear */
+ AST_OPT_FLAG_TRANSCODE_VIA_SLIN = (1 << 10),
+ /*! Enable priority jumping in applications */
+ AST_OPT_FLAG_PRIORITY_JUMPING = (1 << 11),
+ /*! Dump core on a seg fault */
+ AST_OPT_FLAG_DUMP_CORE = (1 << 12),
+ /*! Cache sound files */
+ AST_OPT_FLAG_CACHE_RECORD_FILES = (1 << 13),
+ /*! Display timestamp in log messages */
+ AST_OPT_FLAG_TIMESTAMP = (1 << 14),
+ /*! Override config */
+ AST_OPT_FLAG_OVERRIDE_CONFIG = (1 << 15),
+ /*! Reconnect */
+ AST_OPT_FLAG_RECONNECT = (1 << 16),
+ /*! Transmit Silence during Record() */
+ AST_OPT_FLAG_TRANSMIT_SILENCE = (1 << 17),
+ /*! Suppress some warnings */
+ AST_OPT_FLAG_DONT_WARN = (1 << 18)
+};
+
+#define ast_opt_exec_includes ast_test_flag(&ast_options, AST_OPT_FLAG_EXEC_INCLUDES)
+#define ast_opt_no_fork ast_test_flag(&ast_options, AST_OPT_FLAG_NO_FORK)
+#define ast_opt_quiet ast_test_flag(&ast_options, AST_OPT_FLAG_QUIET)
+#define ast_opt_console ast_test_flag(&ast_options, AST_OPT_FLAG_CONSOLE)
+#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_remote ast_test_flag(&ast_options, AST_OPT_FLAG_REMOTE)
+#define ast_opt_exec ast_test_flag(&ast_options, AST_OPT_FLAG_EXEC)
+#define ast_opt_no_color ast_test_flag(&ast_options, AST_OPT_FLAG_NO_COLOR)
+#define ast_fully_booted ast_test_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED)
+#define ast_opt_transcode_via_slin ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSCODE_VIA_SLIN)
+#define ast_opt_priority_jumping ast_test_flag(&ast_options, AST_OPT_FLAG_PRIORITY_JUMPING)
+#define ast_opt_dump_core ast_test_flag(&ast_options, AST_OPT_FLAG_DUMP_CORE)
+#define ast_opt_cache_record_files ast_test_flag(&ast_options, AST_OPT_FLAG_CACHE_RECORD_FILES)
+#define ast_opt_timestamp ast_test_flag(&ast_options, AST_OPT_FLAG_TIMESTAMP)
+#define ast_opt_override_config ast_test_flag(&ast_options, AST_OPT_FLAG_OVERRIDE_CONFIG)
+#define ast_opt_reconnect ast_test_flag(&ast_options, AST_OPT_FLAG_RECONNECT)
+#define ast_opt_transmit_silence ast_test_flag(&ast_options, AST_OPT_FLAG_TRANSMIT_SILENCE)
+#define ast_opt_dont_warn ast_test_flag(&ast_options, AST_OPT_FLAG_DONT_WARN)
+
+extern struct ast_flags ast_options;
+
extern int option_verbose;
extern int option_debug;
-extern int option_nofork;
-extern int option_quiet;
-extern int option_console;
-extern int option_initcrypto;
-extern int option_nocolor;
-extern int fully_booted;
-extern int option_exec_includes;
-extern int option_cache_record_files;
-extern int option_timestamp;
-extern int option_transcode_slin;
-extern int option_transmit_silence_during_record;
extern int option_maxcalls;
extern double option_maxload;
-extern int option_dontwarn;
-extern int option_priority_jumping;
+
extern char defaultlanguage[];
+
extern time_t ast_startuptime;
extern time_t ast_lastreloadtime;
extern int ast_mainpid;
+
extern char record_cache_dir[AST_CACHE_DIR_LEN];
extern char debug_filename[AST_FILENAME_MAX];
-#define VERBOSE_PREFIX_1 " "
-#define VERBOSE_PREFIX_2 " == "
-#define VERBOSE_PREFIX_3 " -- "
-#define VERBOSE_PREFIX_4 " > "
-
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
ast_mutex_unlock(&modlock);
return -1;
}
- if (!fully_booted) {
+ if (!ast_fully_booted) {
if (option_verbose)
ast_verbose( " => (%s)\n", term_color(tmp, m->description(), COLOR_BROWN, COLOR_BLACK, sizeof(tmp)));
- if (option_console && !option_verbose)
+ if (ast_opt_console && !option_verbose)
ast_verbose( ".");
} else {
if (option_verbose)
}
closedir(mods);
} else {
- if (!option_quiet)
+ if (!ast_opt_quiet)
ast_log(LOG_WARNING, "Unable to open modules directory %s.\n", (char *)ast_config_AST_MODULE_DIR);
}
}
if (level != __LOG_VERBOSE) {
sprintf(linestr, "%d", line);
- snprintf(buf, sizeof(buf), option_timestamp ? "[%s] %s[%ld]: %s:%s %s: " : "%s %s[%ld]: %s:%s %s: ",
+ snprintf(buf, sizeof(buf), ast_opt_timestamp ? "[%s] %s[%ld]: %s:%s %s: " : "%s %s[%ld]: %s:%s %s: ",
date,
term_color(tmp1, levels[level], colors[level], 0, sizeof(tmp1)),
(long)GETTID(),
/* File channels */
} else if ((chan->logmask & (1 << level)) && (chan->fileptr)) {
int res;
- snprintf(buf, sizeof(buf), option_timestamp ? "[%s] %s[%ld]: " : "%s %s[%ld] %s: ", date,
+ snprintf(buf, sizeof(buf), ast_opt_timestamp ? "[%s] %s[%ld]: " : "%s %s[%ld] %s: ", date,
levels[level], (long)GETTID(), file);
res = fprintf(chan->fileptr, buf);
if (res <= 0 && buf[0] != '\0') { /* Error, no characters printed */
va_list ap;
va_start(ap, fmt);
- if (option_timestamp) {
+ if (ast_opt_timestamp) {
time_t t;
struct tm tm;
char date[40];
cfg = ast_config_load(config);
if (cfg) {
/* Use existing config to populate the PBX table */
- static_config = ast_true(ast_variable_retrieve(cfg, "general",
- "static"));
- write_protect_config = ast_true(ast_variable_retrieve(cfg, "general",
- "writeprotect"));
- autofallthrough_config = ast_true(ast_variable_retrieve(cfg, "general",
- "autofallthrough"));
- clearglobalvars_config = ast_true(ast_variable_retrieve(cfg, "general",
- "clearglobalvars"));
- option_priority_jumping = !ast_false(ast_variable_retrieve(cfg, "general",
- "priorityjumping"));
-
+ static_config = ast_true(ast_variable_retrieve(cfg, "general", "static"));
+ write_protect_config = ast_true(ast_variable_retrieve(cfg, "general", "writeprotect"));
+ autofallthrough_config = ast_true(ast_variable_retrieve(cfg, "general", "autofallthrough"));
+ clearglobalvars_config = ast_true(ast_variable_retrieve(cfg, "general", "clearglobalvars"));
+ ast_set2_flag(&ast_options, !ast_false(ast_variable_retrieve(cfg, "general", "priorityjumping")), AST_OPT_FLAG_PRIORITY_JUMPING);
+
v = ast_variable_browse(cfg, "globals");
- while(v) {
+ for (; v; v = v->next) {
memset(realvalue, 0, sizeof(realvalue));
pbx_substitute_variables_helper(NULL, v->value, realvalue, sizeof(realvalue) - 1);
pbx_builtin_setvar_helper(NULL, v->name, realvalue);
- v = v->next;
}
cxt = ast_category_browse(cfg, NULL);
while(cxt) {
if (plus)
ipri += atoi(plus);
lastpri = ipri;
- if(!option_dontwarn) {
+ if (!ast_opt_dont_warn) {
if (!strcmp(realext, "_."))
ast_log(LOG_WARNING, "The use of '_.' for an extension is strongly discouraged and can have unexpected behavior. Please use '_X.' instead at line %d\n", v->lineno);
}
break;
}
}
- } else if (option_priority_jumping)
+ } else if (ast_opt_priority_jumping)
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
LOCAL_USER_REMOVE(u);
ast_log(LOG_NOTICE, "Key '%s' needs passcode.\n", key->name);
key->ktype |= KEY_NEEDS_PASSCODE;
if (!notice) {
- if (!option_initcrypto)
+ if (!ast_opt_init_keys)
ast_log(LOG_NOTICE, "Add the '-i' flag to the asterisk command line if you want to automatically initialize passcodes at launch.\n");
notice++;
}
int load_module(void)
{
crypto_init();
- if (option_initcrypto)
+ if (ast_opt_init_keys)
crypto_load(STDIN_FILENO, STDOUT_FILENO);
else
crypto_load(-1, -1);
if (!term)
return 0;
- if (!option_console || option_nocolor || !option_nofork)
+ if (!ast_opt_console || ast_opt_no_color || !ast_opt_no_fork)
return 0;
for (i=0 ;; i++) {