#include "editline/readline/readline.h"
#include "asterisk/threadstorage.h"
+/*!
+ * \brief map a debug or verbose value to a filename
+ */
+struct ast_debug_file {
+ unsigned int level;
+ AST_RWLIST_ENTRY(ast_debug_file) entry;
+ char filename[0];
+};
+
+AST_RWLIST_HEAD(debug_file_list, ast_debug_file);
+
+/*! list of filenames and their debug settings */
+static struct debug_file_list debug_files;
+/*! list of filenames and their verbose settings */
+static struct debug_file_list verbose_files;
+
AST_THREADSTORAGE(ast_cli_buf);
/*! \brief Initial buffer size for resulting strings in ast_cli() */
ast_carefulwrite(fd, buf->str, strlen(buf->str), 100);
}
+unsigned int ast_debug_get_by_file(const char *file)
+{
+ struct ast_debug_file *adf;
+ unsigned int res = 0;
+
+ AST_RWLIST_RDLOCK(&debug_files);
+ AST_LIST_TRAVERSE(&debug_files, adf, entry) {
+ if (!strncasecmp(adf->filename, file, strlen(adf->filename))) {
+ res = adf->level;
+ break;
+ }
+ }
+ AST_RWLIST_UNLOCK(&debug_files);
+
+ return res;
+}
+
+unsigned int ast_verbose_get_by_file(const char *file)
+{
+ struct ast_debug_file *adf;
+ unsigned int res = 0;
+
+ AST_RWLIST_RDLOCK(&verbose_files);
+ AST_LIST_TRAVERSE(&verbose_files, adf, entry) {
+ if (!strncasecmp(adf->filename, file, strlen(file))) {
+ res = adf->level;
+ break;
+ }
+ }
+ AST_RWLIST_UNLOCK(&verbose_files);
+
+ return res;
+}
+
static AST_LIST_HEAD_STATIC(helpers, ast_cli_entry);
static const char logger_mute_help[] =
return s;
}
+/*!
+ * \brief Find the debug or verbose file setting
+ * \arg debug 1 for debug, 0 for verbose
+ */
+static struct ast_debug_file *find_debug_file(const char *fn, unsigned int debug)
+{
+ struct ast_debug_file *df = NULL;
+ struct debug_file_list *dfl = debug ? &debug_files : &verbose_files;
+
+ AST_LIST_TRAVERSE(dfl, df, entry) {
+ if (!strcasecmp(df->filename, fn))
+ break;
+ }
+
+ return df;
+}
+
static char *handle_verbose(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
{
int oldval;
char **argv = a->argv;
int *dst;
char *what;
+ struct debug_file_list *dfl;
+ struct ast_debug_file *adf;
+ char *fn;
switch (cmd) {
case CLI_INIT:
e->command = "core set {debug|verbose} [off|atleast]";
e->usage =
- "Usage: core set {debug|verbose} [atleast] <level>\n"
+ "Usage: core set {debug|verbose} [atleast] <level> [filename]\n"
" core set {debug|verbose} off\n"
- " Sets level of debug or verbose messages to be displayed.\n"
+ " Sets level of debug or verbose messages to be displayed or \n"
+ " sets a filename to display debug messages from.\n"
" 0 or off means no messages should be displayed.\n"
" Equivalent to -d[d[...]] or -v[v[v...]] on startup\n";
return NULL;
what = "Verbosity";
}
if (argc == e->args && !strcasecmp(argv[e->args - 1], "off")) {
+ unsigned int debug = (*what == 'C');
newlevel = 0;
+
+ dfl = debug ? &debug_files : &verbose_files;
+
+ AST_RWLIST_WRLOCK(dfl);
+ while ((adf = AST_RWLIST_REMOVE_HEAD(dfl, entry)))
+ ast_free(adf);
+ ast_clear_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE);
+ AST_RWLIST_UNLOCK(dfl);
+
goto done;
}
if (!strcasecmp(argv[e->args-1], "atleast"))
atleast = 1;
- if (argc != e->args + atleast)
+ if (argc != e->args + atleast && argc != e->args + atleast + 1)
return CLI_SHOWUSAGE;
if (sscanf(argv[e->args + atleast - 1], "%d", &newlevel) != 1)
return CLI_SHOWUSAGE;
+ if (argc == e->args + atleast + 1) {
+ unsigned int debug = (*what == 'C');
+ dfl = debug ? &debug_files : &verbose_files;
+
+ fn = argv[e->args + atleast];
+
+ AST_RWLIST_WRLOCK(dfl);
+
+ if ((adf = find_debug_file(fn, debug)) && !newlevel) {
+ AST_RWLIST_REMOVE(dfl, adf, entry);
+ if (AST_RWLIST_EMPTY(dfl))
+ ast_clear_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE);
+ AST_RWLIST_UNLOCK(dfl);
+ ast_cli(fd, "%s was %d and has been set to 0 for '%s'\n", what, adf->level, fn);
+ ast_free(adf);
+ return CLI_SUCCESS;
+ }
+
+ if (adf) {
+ if ((atleast && newlevel < adf->level) || adf->level == newlevel) {
+ ast_cli(fd, "%s is %d for '%s'\n", what, adf->level, fn);
+ AST_RWLIST_UNLOCK(dfl);
+ return CLI_SUCCESS;
+ }
+ } else if (!(adf = ast_calloc(1, sizeof(*adf) + strlen(fn) + 1))) {
+ AST_RWLIST_UNLOCK(dfl);
+ return CLI_FAILURE;
+ }
+
+ oldval = adf->level;
+ adf->level = newlevel;
+ strcpy(adf->filename, fn);
+
+ ast_set_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE);
+
+ AST_RWLIST_INSERT_TAIL(dfl, adf, entry);
+ AST_RWLIST_UNLOCK(dfl);
+
+ ast_cli(fd, "%s was %d and has been set to %d for '%s'\n", what, oldval, adf->level, adf->filename);
+
+ return CLI_SUCCESS;
+ }
done:
if (!atleast || newlevel > *dst)
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&acf_root, cur, acflist) {
if (cur == acf) {
AST_RWLIST_REMOVE_CURRENT(&acf_root, acflist);
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Unregistered custom function %s\n", acf->name);
+ ast_verb(2, "Unregistered custom function %s\n", acf->name);
break;
}
}
AST_RWLIST_UNLOCK(&acf_root);
- if (option_verbose > 1)
- ast_verbose(VERBOSE_PREFIX_2 "Registered custom function %s\n", acf->name);
+ ast_verb(2, "Registered custom function %s\n", acf->name);
return 0;
}
}
if (option_verbose > 2) {
char tmp[80], tmp2[80], tmp3[EXT_DATA_SIZE];
- ast_verbose( VERBOSE_PREFIX_3 "Executing [%s@%s:%d] %s(\"%s\", \"%s\") %s\n",
+ ast_verb(3, "Executing [%s@%s:%d] %s(\"%s\", \"%s\") %s\n",
exten, context, priority,
term_color(tmp, app->name, COLOR_BRCYAN, 0, sizeof(tmp)),
term_color(tmp2, c->name, COLOR_BRMAGENTA, 0, sizeof(tmp2)),
/* Start by trying whatever the channel is set to */
if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
/* If not successful fall back to 's' */
- if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Starting %s at %s,%s,%d failed so falling back to exten 's'\n", c->name, c->context, c->exten, c->priority);
+ ast_verb(2, "Starting %s at %s,%s,%d failed so falling back to exten 's'\n", c->name, c->context, c->exten, c->priority);
/* XXX the original code used the existing priority in the call to
* ast_exists_extension(), and reset it to 1 afterwards.
* I believe the correct thing is to set it to 1 immediately.
set_ext_pri(c, "s", 1);
if (!ast_exists_extension(c, c->context, c->exten, c->priority, c->cid.cid_num)) {
/* JK02: And finally back to default if everything else failed */
- if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Starting %s at %s,%s,%d still failed so falling back to context 'default'\n", c->name, c->context, c->exten, c->priority);
+ ast_verb(2, "Starting %s at %s,%s,%d still failed so falling back to context 'default'\n", c->name, c->context, c->exten, c->priority);
ast_copy_string(c->context, "default", sizeof(c->context));
}
}
}
if (res == AST_PBX_KEEPALIVE) {
ast_debug(1, "Spawn extension (%s,%s,%d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
- if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
+ ast_verb(2, "Spawn extension (%s, %s, %d) exited KEEPALIVE on '%s'\n", c->context, c->exten, c->priority, c->name);
error = 1;
break;
}
ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
- if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
+ ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
if (c->_softhangup == AST_SOFTHANGUP_ASYNCGOTO) {
c->_softhangup =0;
} else if (c->_softhangup == AST_SOFTHANGUP_TIMEOUT) {
* Try to continue at "i", 1 or exit if the latter does not exist.
*/
if (ast_exists_extension(c, c->context, "i", 1, c->cid.cid_num)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Sent into invalid extension '%s' in context '%s' on %s\n", c->exten, c->context, c->name);
+ ast_verb(3, "Sent into invalid extension '%s' in context '%s' on %s\n", c->exten, c->context, c->name);
pbx_builtin_setvar_helper(c, "INVALID_EXTEN", c->exten);
set_ext_pri(c, "i", 1);
} else {
const char *status = pbx_builtin_getvar_helper(c, "DIALSTATUS");
if (!status)
status = "UNKNOWN";
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_2 "Auto fallthrough, channel '%s' status is '%s'\n", c->name, status);
+ ast_verb(3, "Auto fallthrough, channel '%s' status is '%s'\n", c->name, status);
if (!strcasecmp(status, "CONGESTION"))
res = pbx_builtin_congestion(c, "10");
else if (!strcasecmp(status, "CHANUNAVAIL"))
if (!ast_strlen_zero(dst_exten)) {
/* An invalid extension */
if (ast_exists_extension(c, c->context, "i", 1, c->cid.cid_num)) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Invalid extension '%s' in context '%s' on %s\n", dst_exten, c->context, c->name);
+ ast_verb(3, "Invalid extension '%s' in context '%s' on %s\n", dst_exten, c->context, c->name);
pbx_builtin_setvar_helper(c, "INVALID_EXTEN", dst_exten);
set_ext_pri(c, "i", 1);
} else {
} else {
/* A simple timeout */
if (ast_exists_extension(c, c->context, "t", 1, c->cid.cid_num)) {
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Timeout on %s\n", c->name);
+ ast_verb(3, "Timeout on %s\n", c->name);
set_ext_pri(c, "t", 1);
} else {
ast_log(LOG_WARNING, "Timeout, but no rule 't' in context '%s'\n", c->context);
}
}
if (c->cdr) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_2 "CDR updated on %s\n",c->name);
+ ast_verb(2, "CDR updated on %s\n",c->name);
ast_cdr_update(c);
}
}
if ((res = ast_spawn_extension(c, c->context, c->exten, c->priority, c->cid.cid_num))) {
/* Something bad happened, or a hangup has been requested. */
ast_debug(1, "Spawn extension (%s,%s,%d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
- if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
+ ast_verb(2, "Spawn extension (%s, %s, %d) exited non-zero on '%s'\n", c->context, c->exten, c->priority, c->name);
break;
}
c->priority++;
if (!cur)
AST_RWLIST_INSERT_TAIL(&apps, tmp, list);
- if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Registered application '%s'\n", term_color(tmps, tmp->name, COLOR_BRCYAN, 0, sizeof(tmps)));
+ ast_verb(2, "Registered application '%s'\n", term_color(tmps, tmp->name, COLOR_BRCYAN, 0, sizeof(tmps)));
AST_RWLIST_UNLOCK(&apps);
if (!strcasecmp(app, tmp->name)) {
unreference_cached_app(tmp);
AST_RWLIST_REMOVE_CURRENT(&apps, list);
- if (option_verbose > 1)
- ast_verbose( VERBOSE_PREFIX_2 "Unregistered application '%s'\n", tmp->name);
+ ast_verb(2, "Unregistered application '%s'\n", tmp->name);
ast_free(tmp);
break;
}
tmp->ignorepats = NULL;
*local_contexts = tmp;
ast_debug(1, "Registered context '%s'\n", tmp->name);
- if (option_verbose > 2)
- ast_verbose( VERBOSE_PREFIX_3 "Registered extension context '%s'\n", tmp->name);
+ ast_verb(3, "Registered extension context '%s'\n", tmp->name);
}
if (!extcontexts)
il->next = new_include;
else
con->includes = new_include;
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Including context '%s' in context '%s'\n", new_include->name, ast_get_context_name(con));
+ ast_verb(3, "Including context '%s' in context '%s'\n", new_include->name, ast_get_context_name(con));
ast_unlock_context(con);
/* ... sw new context into context list, unlock, return */
AST_LIST_INSERT_TAIL(&con->alts, new_sw, list);
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Including switch '%s/%s' in context '%s'\n", new_sw->name, new_sw->data, ast_get_context_name(con));
+ ast_verb(3, "Including switch '%s/%s' in context '%s'\n", new_sw->name, new_sw->data, ast_get_context_name(con));
ast_unlock_context(con);
tmp->exten, tmp->priority, con->name);
}
}
- if (option_verbose > 2) {
- if (tmp->matchcid) {
- ast_verbose( VERBOSE_PREFIX_3 "Added extension '%s' priority %d (CID match '%s')to %s\n",
- tmp->exten, tmp->priority, tmp->cidmatch, con->name);
- } else {
- ast_verbose( VERBOSE_PREFIX_3 "Added extension '%s' priority %d to %s\n",
- tmp->exten, tmp->priority, con->name);
- }
+
+ if (tmp->matchcid) {
+ ast_verb(3, "Added extension '%s' priority %d (CID match '%s')to %s\n",
+ tmp->exten, tmp->priority, tmp->cidmatch, con->name);
+ } else {
+ ast_verb(3, "Added extension '%s' priority %d to %s\n",
+ tmp->exten, tmp->priority, con->name);
}
+
return 0;
}
if (!ast_strlen_zero(as->app)) {
app = pbx_findapp(as->app);
if (app) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Launching %s(%s) on %s\n", as->app, as->appdata, chan->name);
+ ast_verb(3, "Launching %s(%s) on %s\n", as->app, as->appdata, chan->name);
pbx_exec(chan, app, as->appdata);
} else
ast_log(LOG_WARNING, "No such application '%s'\n", as->app);
if (chan) {
if (chan->_state == AST_STATE_UP) {
res = 0;
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Channel %s was answered.\n", chan->name);
+ ast_verb(4, "Channel %s was answered.\n", chan->name);
if (sync > 1) {
if (channel)
}
}
} else {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Channel %s was never answered.\n", chan->name);
+ ast_verb(4, "Channel %s was never answered.\n", chan->name);
if (chan->cdr) { /* update the cdr */
/* here we update the status of the call, which sould be busy.
struct ast_app *app;
app = pbx_findapp(tmp->app);
if (app) {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Launching %s(%s) on %s\n", tmp->app, tmp->data, tmp->chan->name);
+ ast_verb(4, "Launching %s(%s) on %s\n", tmp->app, tmp->data, tmp->chan->name);
pbx_exec(tmp->chan, app, tmp->data);
} else
ast_log(LOG_WARNING, "No such application '%s'\n", tmp->app);
ast_cdr_setaccount(chan, account);
if (chan->_state == AST_STATE_UP) {
res = 0;
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Channel %s was answered.\n", chan->name);
+ ast_verb(4, "Channel %s was answered.\n", chan->name);
tmp = ast_calloc(1, sizeof(*tmp));
if (!tmp)
res = -1;
}
}
} else {
- if (option_verbose > 3)
- ast_verbose(VERBOSE_PREFIX_4 "Channel %s was never answered.\n", chan->name);
+ ast_verb(4, "Channel %s was never answered.\n", chan->name);
if (chan->cdr) { /* update the cdr */
/* here we update the status of the call, which sould be busy.
* if that fails then we set the status to failed */
res = ast_waitfordigit(chan, ms);
if (!res) {
if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 1, chan->cid.cid_num)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Timeout on %s, continuing...\n", chan->name);
+ ast_verb(3, "Timeout on %s, continuing...\n", chan->name);
} else if (ast_exists_extension(chan, chan->context, "t", 1, chan->cid.cid_num)) {
- if (option_verbose > 2)
- ast_verbose(VERBOSE_PREFIX_3 "Timeout on %s, going to 't'\n", chan->name);
+ ast_verb(3, "Timeout on %s, going to 't'\n", chan->name);
set_ext_pri(chan, "t", 0); /* XXX is the 0 correct ? */
} else {
ast_log(LOG_WARNING, "Timeout but no rule 't' in context '%s'\n", chan->context);
static int pbx_builtin_goto(struct ast_channel *chan, void *data)
{
int res = ast_parseable_goto(chan, data);
- if (!res && (option_verbose > 2))
- ast_verbose( VERBOSE_PREFIX_3 "Goto (%s,%s,%d)\n", chan->context,chan->exten, chan->priority+1);
+ if (!res)
+ ast_verb(3, "Goto (%s,%s,%d)\n", chan->context,chan->exten, chan->priority+1);
return res;
}
headp = (chan) ? &chan->varshead : &globals;
if (value) {
- if ((option_verbose > 1) && (headp == &globals))
- ast_verbose(VERBOSE_PREFIX_2 "Setting global variable '%s' to '%s'\n", name, value);
+ if (headp == &globals)
+ ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
newvariable = ast_var_assign(name, value);
if (headp == &globals)
ast_rwlock_wrlock(&globalslock);
}
if (value) {
- if ((option_verbose > 1) && (headp == &globals))
- ast_verbose(VERBOSE_PREFIX_2 "Setting global variable '%s' to '%s'\n", name, value);
+ if (headp == &globals)
+ ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
newvariable = ast_var_assign(name, value);
AST_LIST_INSERT_HEAD(headp, newvariable, entries);
manager_event(EVENT_FLAG_CALL, "VarSet",
int x;
/* Initialize the PBX */
- if (option_verbose) {
- ast_verbose( "Asterisk PBX Core Initializing\n");
- ast_verbose( "Registering builtin applications:\n");
- }
+ ast_verb(1, "Asterisk PBX Core Initializing\n");
+ ast_verb(1, "Registering builtin applications:\n");
+
ast_cli_register_multiple(pbx_cli, sizeof(pbx_cli) / sizeof(struct ast_cli_entry));
/* Register builtin applications */
for (x=0; x<sizeof(builtins) / sizeof(struct pbx_builtin); x++) {
- if (option_verbose)
- ast_verbose( VERBOSE_PREFIX_1 "[%s]\n", builtins[x].name);
+ ast_verb(1, "[%s]\n", builtins[x].name);
if (ast_register_application2(builtins[x].name, builtins[x].execute, builtins[x].synopsis, builtins[x].description, NULL)) {
ast_log(LOG_ERROR, "Unable to register builtin application '%s'\n", builtins[x].name);
return -1;