@ -77,20 +77,20 @@ AST_MUTEX_DEFINE_STATIC(permsconfiglock);
static AST_RWLIST_HEAD_STATIC ( cli_perms , usergroup_cli_perm ) ;
static AST_RWLIST_HEAD_STATIC ( cli_perms , usergroup_cli_perm ) ;
/*!
/*!
* \ brief map a debug or verbose value to a file name
* \ brief map a debug or verbose level to a module name
*/
*/
struct ast_debug_file {
struct module_level {
unsigned int level ;
unsigned int level ;
AST_RWLIST_ENTRY ( ast_debug_file ) entry ;
AST_RWLIST_ENTRY ( module_level ) entry ;
char filena me[ 0 ] ;
char modul e[ 0 ] ;
} ;
} ;
AST_RWLIST_HEAD ( debug_file_list, ast_debug_file ) ;
AST_RWLIST_HEAD ( module_level_list, module_level ) ;
/*! list of filenames and their debug setting s */
/*! list of module names and their debug level s */
static struct debug_file_list debug_fi les;
static struct module_level_list debug_modu les;
/*! list of filenames and their verbose setting s */
/*! list of module names and their verbose level s */
static struct debug_file_list verbose_fi les;
static struct module_level_list verbose_modu les;
AST_THREADSTORAGE ( ast_cli_buf ) ;
AST_THREADSTORAGE ( ast_cli_buf ) ;
@ -115,36 +115,36 @@ void ast_cli(int fd, const char *fmt, ...)
}
}
}
}
unsigned int ast_debug_get_by_ file( const char * fi le)
unsigned int ast_debug_get_by_ module( const char * modu le)
{
{
struct ast_debug_file * adf ;
struct module_level * ml ;
unsigned int res = 0 ;
unsigned int res = 0 ;
AST_RWLIST_RDLOCK ( & debug_ fi les) ;
AST_RWLIST_RDLOCK ( & debug_ modu les) ;
AST_LIST_TRAVERSE ( & debug_ files, adf , entry ) {
AST_LIST_TRAVERSE ( & debug_ modules, ml , entry ) {
if ( ! str ncasecmp( adf - > filename , file , strlen ( adf - > filename ) ) ) {
if ( ! str casecmp( ml - > module , module ) ) {
res = adf - > level ;
res = ml - > level ;
break ;
break ;
}
}
}
}
AST_RWLIST_UNLOCK ( & debug_ fi les) ;
AST_RWLIST_UNLOCK ( & debug_ modu les) ;
return res ;
return res ;
}
}
unsigned int ast_verbose_get_by_ file( const char * fi le)
unsigned int ast_verbose_get_by_ module( const char * modu le)
{
{
struct ast_debug_file * adf ;
struct module_level * ml ;
unsigned int res = 0 ;
unsigned int res = 0 ;
AST_RWLIST_RDLOCK ( & verbose_ fi les) ;
AST_RWLIST_RDLOCK ( & verbose_ modu les) ;
AST_LIST_TRAVERSE ( & verbose_ files, adf , entry ) {
AST_LIST_TRAVERSE ( & verbose_ modules, ml , entry ) {
if ( ! str ncasecmp( adf - > filename , file , strlen ( file ) ) ) {
if ( ! str casecmp( ml - > module , module ) ) {
res = adf - > level ;
res = ml - > level ;
break ;
break ;
}
}
}
}
AST_RWLIST_UNLOCK ( & verbose_ fi les) ;
AST_RWLIST_UNLOCK ( & verbose_ modu les) ;
return res ;
return res ;
}
}
@ -305,17 +305,17 @@ static char *handle_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args
* \ brief Find the debug or verbose file setting
* \ brief Find the debug or verbose file setting
* \ arg debug 1 for debug , 0 for verbose
* \ arg debug 1 for debug , 0 for verbose
*/
*/
static struct ast_debug_file * find_debug_file ( const char * fn , unsigned int debug )
static struct module_level * find_module_level ( const char * module , unsigned int debug )
{
{
struct ast_debug_file * df = NULL ;
struct module_level * ml ;
struct debug_file_list * dfl = debug ? & debug_files : & verbose_fi les;
struct module_level_list * mll = debug ? & debug_modules : & verbose_modu les;
AST_LIST_TRAVERSE ( dfl, df , entry ) {
AST_LIST_TRAVERSE ( mll, ml , entry ) {
if ( ! strcasecmp ( df- > filename , fn ) )
if ( ! strcasecmp ( ml- > module , module ) )
break ;
return ml ;
}
}
return df ;
return NULL ;
}
}
static char * complete_number ( const char * partial , unsigned int min , unsigned int max , int n )
static char * complete_number ( const char * partial , unsigned int min , unsigned int max , int n )
@ -369,23 +369,22 @@ static char *handle_verbose(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
const char * argv3 = a - > argv ? S_OR ( a - > argv [ 3 ] , " " ) : " " ;
const char * argv3 = a - > argv ? S_OR ( a - > argv [ 3 ] , " " ) : " " ;
int * dst ;
int * dst ;
char * what ;
char * what ;
struct debug_file_list * dfl ;
struct module_level_list * mll ;
struct ast_debug_file * adf ;
struct module_level * ml ;
const char * fn ;
switch ( cmd ) {
switch ( cmd ) {
case CLI_INIT :
case CLI_INIT :
e - > command = " core set {debug|verbose} " ;
e - > command = " core set {debug|verbose} " ;
e - > usage =
e - > usage =
# if !defined(LOW_MEMORY)
# if !defined(LOW_MEMORY)
" Usage: core set {debug|verbose} [atleast] <level> [ filena me]\n "
" Usage: core set {debug|verbose} [atleast] <level> [ modul e]\n "
# else
# else
" Usage: core set {debug|verbose} [atleast] <level> \n "
" Usage: core set {debug|verbose} [atleast] <level> \n "
# endif
# endif
" core set {debug|verbose} off \n "
" core set {debug|verbose} off \n "
# if !defined(LOW_MEMORY)
# if !defined(LOW_MEMORY)
" Sets level of debug or verbose messages to be displayed or \n "
" Sets level of debug or verbose messages to be displayed or \n "
" sets a file name to display debug messages from.\n "
" sets a module name to display debug messages from.\n "
# else
# else
" Sets level of debug or verbose messages to be displayed. \n "
" Sets level of debug or verbose messages to be displayed. \n "
# endif
# endif
@ -440,13 +439,14 @@ static char *handle_verbose(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
unsigned int debug = ( * what = = ' C ' ) ;
unsigned int debug = ( * what = = ' C ' ) ;
newlevel = 0 ;
newlevel = 0 ;
dfl = debug ? & debug_files : & verbose_fi les;
mll = debug ? & debug_modules : & verbose_modu les;
AST_RWLIST_WRLOCK ( dfl ) ;
AST_RWLIST_WRLOCK ( mll ) ;
while ( ( adf = AST_RWLIST_REMOVE_HEAD ( dfl , entry ) ) )
while ( ( ml = AST_RWLIST_REMOVE_HEAD ( mll , entry ) ) ) {
ast_free ( adf ) ;
ast_free ( ml ) ;
ast_clear_flag ( & ast_options , debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE ) ;
}
AST_RWLIST_UNLOCK ( dfl ) ;
ast_clear_flag ( & ast_options , debug ? AST_OPT_FLAG_DEBUG_MODULE : AST_OPT_FLAG_VERBOSE_MODULE ) ;
AST_RWLIST_UNLOCK ( mll ) ;
goto done ;
goto done ;
}
}
@ -458,43 +458,47 @@ static char *handle_verbose(struct ast_cli_entry *e, int cmd, struct ast_cli_arg
return CLI_SHOWUSAGE ;
return CLI_SHOWUSAGE ;
if ( argc = = e - > args + atleast + 2 ) {
if ( argc = = e - > args + atleast + 2 ) {
unsigned int debug = ( * what = = ' C ' ) ;
unsigned int debug = ( * what = = ' C ' ) ;
dfl = debug ? & debug_files : & verbose_files ;
char * mod = ast_strdupa ( argv [ e - > args + atleast + 1 ] ) ;
fn = argv [ e - > args + atleast + 1 ] ;
mll = debug ? & debug_modules : & verbose_modules ;
if ( ( strlen ( mod ) > 3 ) & & ! strcasecmp ( mod + strlen ( mod ) - 3 , " .so " ) ) {
mod [ strlen ( mod ) - 3 ] = ' \0 ' ;
}
AST_RWLIST_WRLOCK ( dfl ) ;
AST_RWLIST_WRLOCK ( ml l) ;
if ( ( adf = find_debug_file ( fn , debug ) ) & & ! newlevel ) {
if ( ( ml = find_module_level ( mod , debug ) ) & & ! newlevel ) {
AST_RWLIST_REMOVE ( dfl, adf , entry ) ;
AST_RWLIST_REMOVE ( mll, ml , entry ) ;
if ( AST_RWLIST_EMPTY ( df l) )
if ( AST_RWLIST_EMPTY ( ml l) )
ast_clear_flag ( & ast_options , debug ? AST_OPT_FLAG_DEBUG_ FILE : AST_OPT_FLAG_VERBOSE_FI LE) ;
ast_clear_flag ( & ast_options , debug ? AST_OPT_FLAG_DEBUG_ MODULE : AST_OPT_FLAG_VERBOSE_MODU LE) ;
AST_RWLIST_UNLOCK ( df l) ;
AST_RWLIST_UNLOCK ( ml l) ;
ast_cli ( fd , " %s was %d and has been set to 0 for '%s' \n " , what , adf- > level , fn ) ;
ast_cli ( fd , " %s was %d and has been set to 0 for '%s' \n " , what , ml- > level , mod ) ;
ast_free ( adf ) ;
ast_free ( ml ) ;
return CLI_SUCCESS ;
return CLI_SUCCESS ;
}
}
if ( adf ) {
if ( ml ) {
if ( ( atleast & & newlevel < adf- > level ) | | adf - > level = = newlevel ) {
if ( ( atleast & & newlevel < ml- > level ) | | ml - > level = = newlevel ) {
ast_cli ( fd , " %s is %d for '%s' \n " , what , adf- > level , fn ) ;
ast_cli ( fd , " %s is %d for '%s' \n " , what , ml- > level , mod ) ;
AST_RWLIST_UNLOCK ( df l) ;
AST_RWLIST_UNLOCK ( ml l) ;
return CLI_SUCCESS ;
return CLI_SUCCESS ;
}
}
} else if ( ! ( adf = ast_calloc ( 1 , sizeof ( * adf ) + strlen ( fn ) + 1 ) ) ) {
} else if ( ! ( ml = ast_calloc ( 1 , sizeof ( * ml ) + strlen ( mod ) + 1 ) ) ) {
AST_RWLIST_UNLOCK ( df l) ;
AST_RWLIST_UNLOCK ( ml l) ;
return CLI_FAILURE ;
return CLI_FAILURE ;
}
}
oldval = adf - > level ;
oldval = ml - > level ;
adf - > level = newlevel ;
ml - > level = newlevel ;
strcpy ( adf- > filename , fn ) ;
strcpy ( ml- > module , mod ) ;
ast_set_flag ( & ast_options , debug ? AST_OPT_FLAG_DEBUG_ FILE : AST_OPT_FLAG_VERBOSE_FI LE) ;
ast_set_flag ( & ast_options , debug ? AST_OPT_FLAG_DEBUG_ MODULE : AST_OPT_FLAG_VERBOSE_MODU LE) ;
AST_RWLIST_INSERT_TAIL ( dfl, adf , entry ) ;
AST_RWLIST_INSERT_TAIL ( mll, ml , entry ) ;
AST_RWLIST_UNLOCK ( df l) ;
AST_RWLIST_UNLOCK ( ml l) ;
ast_cli ( fd , " %s was %d and has been set to %d for '%s' \n " , what , oldval , adf- > level , adf - > filenam e) ;
ast_cli ( fd , " %s was %d and has been set to %d for '%s' \n " , what , oldval , ml- > level , ml - > modul e) ;
return CLI_SUCCESS ;
return CLI_SUCCESS ;
}
}