Standard Command Line Interface. More...
#include "asterisk.h"#include "asterisk/_private.h"#include "asterisk/paths.h"#include <sys/signal.h>#include <signal.h>#include <ctype.h>#include <regex.h>#include <pwd.h>#include <grp.h>#include <readline.h>#include "asterisk/cli.h"#include "asterisk/linkedlists.h"#include "asterisk/module.h"#include "asterisk/pbx.h"#include "asterisk/channel.h"#include "asterisk/utils.h"#include "asterisk/app.h"#include "asterisk/lock.h"#include "asterisk/threadstorage.h"
Go to the source code of this file.
Data Structures | |
| struct | ast_debug_file |
| map a debug or verbose value to a filename More... | |
| struct | cli_perm |
| List of restrictions per user. More... | |
| struct | cli_perm_head |
| struct | cli_perms |
| List of users and permissions. More... | |
| struct | debug_file_list |
| struct | helpers |
| struct | usergroup_cli_perm |
| list of users to apply restrictions. More... | |
Defines | |
| #define | AST_CLI_INITLEN 256 |
| Initial buffer size for resulting strings in ast_cli(). | |
| #define | CONCISE_FORMAT_STRING "%s!%s!%s!%d!%s!%s!%s!%s!%s!%d!%s!%s!%s\n" |
| #define | DAY (HOUR*24) |
| #define | FORMAT_STRING "%-25s %-20s %-20s\n" |
| #define | FORMAT_STRING "%-20.20s %-20.20s %-7.7s %-30.30s\n" |
| #define | FORMAT_STRING2 "%-20.20s %-20.20s %-7.7s %-30.30s\n" |
| #define | HOUR (MINUTE*60) |
| #define | MINUTE (SECOND*60) |
| #define | MODLIST_FORMAT "%-30s %-40.40s %-10d\n" |
| #define | MODLIST_FORMAT2 "%-30s %-40.40s %-10s\n" |
| #define | NEEDCOMMA(x) ((x)? ",": "") |
| #define | SECOND (1) |
| #define | VERBOSE_FORMAT_STRING "%-20.20s %-20.20s %-16.16s %4d %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n" |
| #define | VERBOSE_FORMAT_STRING2 "%-20.20s %-20.20s %-16.16s %-4.4s %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n" |
| #define | WEEK (DAY*7) |
| #define | YEAR (DAY*365) |
Functions | |
| static char * | __ast_cli_generator (const char *text, const char *word, int state, int lock) |
| static int | __ast_cli_register (struct ast_cli_entry *e, struct ast_cli_entry *ed) |
| static int | __ast_cli_unregister (struct ast_cli_entry *e, struct ast_cli_entry *ed) |
| static void | __init_ast_cli_buf (void) |
| void | ast_builtins_init (void) |
| initialize the _full_cmd string in * each of the builtins. | |
| void | ast_cli (int fd, const char *fmt,...) |
| int | ast_cli_command_full (int uid, int gid, int fd, const char *s) |
| Interprets a command Interpret a command s, sending output to fd if uid:gid has permissions to run this command. uid = CLI_NO_PERMS to avoid checking user permissions gid = CLI_NO_PERMS to avoid checking group permissions. | |
| int | ast_cli_command_multiple_full (int uid, int gid, int fd, size_t size, const char *s) |
| Executes multiple CLI commands Interpret strings separated by NULL and execute each one, sending output to fd if uid has permissions, uid = CLI_NO_PERMS to avoid checking users permissions. gid = CLI_NO_PERMS to avoid checking group permissions. | |
| char * | ast_cli_complete (const char *word, char *const choices[], int state) |
| char ** | ast_cli_completion_matches (const char *text, const char *word) |
| Generates a NULL-terminated array of strings that 1) begin with the string in the second parameter, and 2) are valid in a command after the string in the first parameter. | |
| char * | ast_cli_generator (const char *text, const char *word, int state) |
| Readline madness Useful for readline, that's about it. | |
| int | ast_cli_generatornummatches (const char *text, const char *word) |
| Return the number of unique matches for the generator. | |
| int | ast_cli_perms_init (int reload) |
| int | ast_cli_register (struct ast_cli_entry *e) |
| Registers a command or an array of commands. | |
| int | ast_cli_register_multiple (struct ast_cli_entry *e, int len) |
| Register multiple commands. | |
| int | ast_cli_unregister (struct ast_cli_entry *e) |
| Unregisters a command or an array of commands. | |
| int | ast_cli_unregister_multiple (struct ast_cli_entry *e, int len) |
| Unregister multiple commands. | |
| char * | ast_complete_channels (const char *line, const char *word, int pos, int state, int rpos) |
| Command completion for the list of active channels. | |
| unsigned int | ast_debug_get_by_file (const char *file) |
| Get the debug level for a file. | |
| unsigned int | ast_verbose_get_by_file (const char *file) |
| Get the debug level for a file. | |
| static int | cli_has_permissions (int uid, int gid, const char *command) |
| static struct ast_cli_entry * | cli_next (struct ast_cli_entry *e) |
| static char * | complete_fn (const char *word, int state) |
| static char * | complete_number (const char *partial, unsigned int min, unsigned int max, int n) |
| static void | destroy_user_perms (void) |
| cleanup (free) cli_perms linkedlist. | |
| static char * | find_best (char *argv[]) |
| static struct ast_cli_entry * | find_cli (char *const cmds[], int match_type) |
| static struct ast_debug_file * | find_debug_file (const char *fn, unsigned int debug) |
| Find the debug or verbose file setting. | |
| static char * | group_show_channels (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_chanlist (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_cli_check_permissions (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| handles CLI command 'cli check permissions' | |
| static char * | handle_cli_reload_permissions (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| handles CLI command 'cli reload permissions' | |
| static char * | handle_cli_show_permissions (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| handles CLI command 'cli show permissions' | |
| static char * | handle_cli_wait_fullybooted (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_commandcomplete (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_commandmatchesarray (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_commandnummatches (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_core_set_debug_channel (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_help (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_load (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_logger_mute (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_modlist (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_nodebugchan_deprecated (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_reload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_showcalls (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_showchan (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_showuptime (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_softhangup (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_unload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | handle_verbose (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | help1 (int fd, char *match[], int locked) |
| helper for final part of handle_help if locked = 1, assume the list is already locked | |
| static char * | is_prefix (const char *word, const char *token, int pos, int *actual) |
| if word is a valid prefix for token, returns the pos-th match as a malloced string, or NULL otherwise. Always tell in *actual how many matches we got. | |
| static int | modlist_modentry (const char *module, const char *description, int usecnt, const char *like) |
| static int | more_words (char *const *dst) |
| returns true if there are more words to match | |
| static char * | parse_args (const char *s, int *argc, char *argv[], int max, int *trailingwhitespace) |
| static void | print_uptimestr (int fd, struct timeval timeval, const char *prefix, int printsec) |
| static int | set_full_cmd (struct ast_cli_entry *e) |
| static int | word_match (const char *cmd, const char *cli_word) |
Variables | |
| static struct ast_threadstorage | ast_cli_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_ast_cli_buf , .custom_init = NULL , } |
| static struct ast_cli_entry | cli_cli [] |
| static int | cli_default_perm = 1 |
| Default permissions value 1=Permit 0=Deny. | |
| static const char | cli_rsvd [] = "[]{}|*%" |
| static int | climodentryfd = -1 |
| static ast_mutex_t | climodentrylock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) |
| static struct debug_file_list | debug_files |
| static const char | perms_config [] = "cli_permissions.conf" |
| CLI permissions config file. | |
| static ast_mutex_t | permsconfiglock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) |
| mutex used to prevent a user from running the 'cli reload permissions' command while it is already running. | |
| static struct debug_file_list | verbose_files |
Standard Command Line Interface.
Definition in file cli.c.
| #define AST_CLI_INITLEN 256 |
| #define CONCISE_FORMAT_STRING "%s!%s!%s!%d!%s!%s!%s!%s!%s!%d!%s!%s!%s\n" |
Referenced by handle_chanlist().
| #define DAY (HOUR*24) |
Referenced by print_uptimestr().
| #define FORMAT_STRING "%-25s %-20s %-20s\n" |
| #define FORMAT_STRING "%-20.20s %-20.20s %-7.7s %-30.30s\n" |
Referenced by group_show_channels(), and handle_chanlist().
| #define FORMAT_STRING2 "%-20.20s %-20.20s %-7.7s %-30.30s\n" |
Referenced by handle_chanlist().
| #define HOUR (MINUTE*60) |
Referenced by print_uptimestr().
| #define MINUTE (SECOND*60) |
Referenced by print_uptimestr().
| #define MODLIST_FORMAT "%-30s %-40.40s %-10d\n" |
Definition at line 593 of file cli.c.
Referenced by modlist_modentry().
| #define MODLIST_FORMAT2 "%-30s %-40.40s %-10s\n" |
Definition at line 594 of file cli.c.
Referenced by handle_modlist().
| #define NEEDCOMMA | ( | x | ) | ((x)? ",": "") |
Referenced by print_uptimestr().
| #define SECOND (1) |
| #define VERBOSE_FORMAT_STRING "%-20.20s %-20.20s %-16.16s %4d %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n" |
Referenced by handle_chanlist().
| #define VERBOSE_FORMAT_STRING2 "%-20.20s %-20.20s %-16.16s %-4.4s %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n" |
Referenced by handle_chanlist().
| #define WEEK (DAY*7) |
Referenced by print_uptimestr().
| #define YEAR (DAY*365) |
Referenced by print_uptimestr().
| static char * __ast_cli_generator | ( | const char * | text, | |
| const char * | word, | |||
| int | state, | |||
| int | lock | |||
| ) | [static] |
Definition at line 2198 of file cli.c.
References ARRAY_LEN, ast_free, ast_join(), AST_MAX_ARGS, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_strlen_zero(), CLI_GENERATE, cli_next(), ast_cli_entry::cmda, ast_cli_entry::command, ast_cli_entry::handler, is_prefix(), ast_cli_args::line, more_words(), parse_args(), and word_match().
Referenced by ast_cli_generator(), handle_commandcomplete(), and handle_help().
02199 { 02200 char *argv[AST_MAX_ARGS]; 02201 struct ast_cli_entry *e = NULL; 02202 int x = 0, argindex, matchlen; 02203 int matchnum=0; 02204 char *ret = NULL; 02205 char matchstr[80] = ""; 02206 int tws = 0; 02207 /* Split the argument into an array of words */ 02208 char *duplicate = parse_args(text, &x, argv, ARRAY_LEN(argv), &tws); 02209 02210 if (!duplicate) /* malloc error */ 02211 return NULL; 02212 02213 /* Compute the index of the last argument (could be an empty string) */ 02214 argindex = (!ast_strlen_zero(word) && x>0) ? x-1 : x; 02215 02216 /* rebuild the command, ignore terminating white space and flatten space */ 02217 ast_join(matchstr, sizeof(matchstr)-1, argv); 02218 matchlen = strlen(matchstr); 02219 if (tws) { 02220 strcat(matchstr, " "); /* XXX */ 02221 if (matchlen) 02222 matchlen++; 02223 } 02224 if (lock) 02225 AST_RWLIST_RDLOCK(&helpers); 02226 while ( (e = cli_next(e)) ) { 02227 /* XXX repeated code */ 02228 int src = 0, dst = 0, n = 0; 02229 02230 if (e->command[0] == '_') 02231 continue; 02232 02233 /* 02234 * Try to match words, up to and excluding the last word, which 02235 * is either a blank or something that we want to extend. 02236 */ 02237 for (;src < argindex; dst++, src += n) { 02238 n = word_match(argv[src], e->cmda[dst]); 02239 if (n < 0) 02240 break; 02241 } 02242 02243 if (src != argindex && more_words(e->cmda + dst)) /* not a match */ 02244 continue; 02245 ret = is_prefix(argv[src], e->cmda[dst], state - matchnum, &n); 02246 matchnum += n; /* this many matches here */ 02247 if (ret) { 02248 /* 02249 * argv[src] is a valid prefix of the next word in this 02250 * command. If this is also the correct entry, return it. 02251 */ 02252 if (matchnum > state) 02253 break; 02254 ast_free(ret); 02255 ret = NULL; 02256 } else if (ast_strlen_zero(e->cmda[dst])) { 02257 /* 02258 * This entry is a prefix of the command string entered 02259 * (only one entry in the list should have this property). 02260 * Run the generator if one is available. In any case we are done. 02261 */ 02262 if (e->handler) { /* new style command */ 02263 struct ast_cli_args a = { 02264 .line = matchstr, .word = word, 02265 .pos = argindex, 02266 .n = state - matchnum, 02267 .argv = argv, 02268 .argc = x}; 02269 ret = e->handler(e, CLI_GENERATE, &a); 02270 } 02271 if (ret) 02272 break; 02273 } 02274 } 02275 if (lock) 02276 AST_RWLIST_UNLOCK(&helpers); 02277 ast_free(duplicate); 02278 return ret; 02279 }
| static int __ast_cli_register | ( | struct ast_cli_entry * | e, | |
| struct ast_cli_entry * | ed | |||
| ) | [static] |
Definition at line 1885 of file cli.c.
References ast_cli_entry::_full_cmd, ast_log(), AST_MAX_CMD_LEN, AST_RWLIST_INSERT_BEFORE_CURRENT, AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE_SAFE_BEGIN, AST_RWLIST_TRAVERSE_SAFE_END, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_skip_blanks(), ast_skip_nonblanks(), ast_strdup, ast_strlen_zero(), CLI_INIT, ast_cli_entry::cmda, ast_cli_entry::cmdlen, ast_cli_entry::command, find_cli(), ast_cli_entry::handler, len(), LOG_WARNING, s, S_OR, and set_full_cmd().
Referenced by ast_cli_register().
01886 { 01887 struct ast_cli_entry *cur; 01888 int i, lf, ret = -1; 01889 01890 struct ast_cli_args a; /* fake argument */ 01891 char **dst = (char **)e->cmda; /* need to cast as the entry is readonly */ 01892 char *s; 01893 01894 memset(&a, '\0', sizeof(a)); 01895 e->handler(e, CLI_INIT, &a); 01896 /* XXX check that usage and command are filled up */ 01897 s = ast_skip_blanks(e->command); 01898 s = e->command = ast_strdup(s); 01899 for (i=0; !ast_strlen_zero(s) && i < AST_MAX_CMD_LEN-1; i++) { 01900 *dst++ = s; /* store string */ 01901 s = ast_skip_nonblanks(s); 01902 if (*s == '\0') /* we are done */ 01903 break; 01904 *s++ = '\0'; 01905 s = ast_skip_blanks(s); 01906 } 01907 *dst++ = NULL; 01908 01909 AST_RWLIST_WRLOCK(&helpers); 01910 01911 if (find_cli(e->cmda, 1)) { 01912 ast_log(LOG_WARNING, "Command '%s' already registered (or something close enough)\n", S_OR(e->_full_cmd, e->command)); 01913 goto done; 01914 } 01915 if (set_full_cmd(e)) 01916 goto done; 01917 01918 lf = e->cmdlen; 01919 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&helpers, cur, list) { 01920 int len = cur->cmdlen; 01921 if (lf < len) 01922 len = lf; 01923 if (strncasecmp(e->_full_cmd, cur->_full_cmd, len) < 0) { 01924 AST_RWLIST_INSERT_BEFORE_CURRENT(e, list); 01925 break; 01926 } 01927 } 01928 AST_RWLIST_TRAVERSE_SAFE_END; 01929 01930 if (!cur) 01931 AST_RWLIST_INSERT_TAIL(&helpers, e, list); 01932 ret = 0; /* success */ 01933 01934 done: 01935 AST_RWLIST_UNLOCK(&helpers); 01936 01937 return ret; 01938 }
| static int __ast_cli_unregister | ( | struct ast_cli_entry * | e, | |
| struct ast_cli_entry * | ed | |||
| ) | [static] |
Definition at line 1863 of file cli.c.
References ast_cli_entry::_full_cmd, ast_free, ast_log(), AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_cli_entry::cmda, ast_cli_entry::command, ast_cli_entry::handler, ast_cli_entry::inuse, LOG_WARNING, and ast_cli_entry::usage.
Referenced by ast_cli_unregister().
01864 { 01865 if (e->inuse) { 01866 ast_log(LOG_WARNING, "Can't remove command that is in use\n"); 01867 } else { 01868 AST_RWLIST_WRLOCK(&helpers); 01869 AST_RWLIST_REMOVE(&helpers, e, list); 01870 AST_RWLIST_UNLOCK(&helpers); 01871 ast_free(e->_full_cmd); 01872 e->_full_cmd = NULL; 01873 if (e->handler) { 01874 /* this is a new-style entry. Reset fields and free memory. */ 01875 char *cmda = (char *) e->cmda; 01876 memset(cmda, '\0', sizeof(e->cmda)); 01877 ast_free(e->command); 01878 e->command = NULL; 01879 e->usage = NULL; 01880 } 01881 } 01882 return 0; 01883 }
| void ast_builtins_init | ( | void | ) |
initialize the _full_cmd string in * each of the builtins.
Provided by cli.c
Definition at line 1705 of file cli.c.
References ARRAY_LEN, and ast_cli_register_multiple().
Referenced by main().
01706 { 01707 ast_cli_register_multiple(cli_cli, ARRAY_LEN(cli_cli)); 01708 }
| void ast_cli | ( | int | fd, | |
| const char * | fmt, | |||
| ... | ||||
| ) |
Definition at line 101 of file cli.c.
References ast_carefulwrite(), AST_CLI_INITLEN, AST_DYNSTR_BUILD_FAILED, ast_str_buffer(), ast_str_set_va(), ast_str_strlen(), ast_str_thread_get(), and buf.
Referenced by __iax2_show_peers(), __say_cli_init(), _sip_qualify_peer(), _sip_show_peer(), _sip_show_peers(), _skinny_show_device(), _skinny_show_devices(), _skinny_show_line(), _skinny_show_lines(), agent_logoff_cmd(), agents_show(), agents_show_online(), ais_clm_show_members(), ais_evt_show_event_channels(), aji_do_reload(), aji_do_set_debug(), aji_show_buddies(), aji_show_clients(), aji_test(), alias_show(), ast_cli_command_full(), ast_cli_netstats(), ast_console_toggle_mute(), cli_console_active(), cli_console_answer(), cli_console_autoanswer(), cli_console_dial(), cli_console_flash(), cli_console_hangup(), cli_console_mute(), cli_console_sendtext(), cli_list_available(), cli_list_devices(), cli_match_char_tree(), cli_odbc_read(), cli_odbc_write(), cli_realtime_destroy(), cli_realtime_load(), cli_realtime_store(), cli_realtime_update(), cli_realtime_update2(), cli_tps_ping(), cli_tps_report(), console_active(), console_answer(), console_autoanswer(), console_boost(), console_cmd(), console_dial(), console_do_answer(), console_flash(), console_hangup(), console_mute(), console_sendtext(), console_transfer(), dahdi_set_dnd(), dahdi_set_hwgain(), dahdi_set_swgain(), dahdi_show_channel(), dahdi_show_channels(), dahdi_show_status(), dahdi_show_version(), dialog_dump_func(), do_print(), dundi_do_lookup(), dundi_do_precache(), dundi_do_query(), dundi_flush(), dundi_set_debug(), dundi_show_entityid(), dundi_show_mappings(), dundi_show_peer(), dundi_show_peers(), dundi_show_precache(), dundi_show_requests(), dundi_show_trans(), dundi_store_history(), group_show_channels(), gtalk_show_channels(), handle_chanlist(), handle_cli_agi_debug(), handle_cli_agi_dump_html(), handle_cli_agi_show(), handle_cli_check_permissions(), handle_cli_config_list(), handle_cli_core_show_channeltype(), handle_cli_core_show_channeltypes(), handle_cli_core_show_config_mappings(), handle_cli_core_show_file_formats(), handle_cli_core_show_translation(), handle_cli_database_del(), handle_cli_database_deltree(), handle_cli_database_get(), handle_cli_database_put(), handle_cli_database_show(), handle_cli_database_showkey(), handle_cli_devstate_change(), handle_cli_devstate_list(), handle_cli_dialplan_add_extension(), handle_cli_dialplan_add_ignorepat(), handle_cli_dialplan_add_include(), handle_cli_dialplan_reload(), handle_cli_dialplan_remove_extension(), handle_cli_dialplan_remove_ignorepat(), handle_cli_dialplan_remove_include(), handle_cli_dialplan_save(), handle_cli_file_convert(), handle_cli_h323_set_debug(), handle_cli_h323_set_trace(), handle_cli_iax2_provision(), handle_cli_iax2_prune_realtime(), handle_cli_iax2_set_debug(), handle_cli_iax2_set_debug_jb(), handle_cli_iax2_set_debug_trunk(), handle_cli_iax2_set_mtu(), handle_cli_iax2_show_cache(), handle_cli_iax2_show_callno_limits(), handle_cli_iax2_show_channels(), handle_cli_iax2_show_firmware(), handle_cli_iax2_show_netstats(), handle_cli_iax2_show_peer(), handle_cli_iax2_show_registry(), handle_cli_iax2_show_stats(), handle_cli_iax2_show_threads(), handle_cli_iax2_show_users(), handle_cli_iax2_unregister(), handle_cli_indication_show(), handle_cli_keys_show(), handle_cli_misdn_reload(), handle_cli_misdn_send_digit(), handle_cli_misdn_send_display(), handle_cli_misdn_set_debug(), handle_cli_misdn_show_channels(), handle_cli_misdn_show_config(), handle_cli_misdn_show_port(), handle_cli_misdn_show_ports_stats(), handle_cli_misdn_show_stacks(), handle_cli_misdn_toggle_echocancel(), handle_cli_mixmonitor(), handle_cli_moh_show_classes(), handle_cli_moh_show_files(), handle_cli_odbc_show(), handle_cli_osp_show(), handle_cli_realtime_pgsql_cache(), handle_cli_realtime_pgsql_status(), handle_cli_refresh(), handle_cli_rtcp_set_debug(), handle_cli_rtcp_set_stats(), handle_cli_rtp_set_debug(), handle_cli_show_permissions(), handle_cli_show_sqlite_status(), handle_cli_sqlite_show_tables(), handle_cli_status(), handle_cli_stun_set_debug(), handle_cli_submit(), handle_cli_transcoder_show(), handle_cli_udptl_set_debug(), handle_cli_ulimit(), handle_cli_wait_fullybooted(), handle_commandcomplete(), handle_commandmatchesarray(), handle_commandnummatches(), handle_core_set_debug_channel(), handle_core_show_image_formats(), handle_dahdi_show_cadences(), handle_debug_dialplan(), handle_feature_show(), handle_help(), handle_load(), handle_logger_reload(), handle_logger_rotate(), handle_logger_set_level(), handle_logger_show_channels(), handle_mandebug(), handle_memory_show(), handle_memory_show_summary(), handle_mgcp_audit_endpoint(), handle_mgcp_set_debug(), handle_mgcp_show_endpoints(), handle_minivm_list_templates(), handle_minivm_reload(), handle_minivm_show_settings(), handle_minivm_show_stats(), handle_minivm_show_users(), handle_minivm_show_zones(), handle_modlist(), handle_parkedcalls(), handle_queue_add_member(), handle_queue_pause_member(), handle_queue_remove_member(), handle_queue_rule_show(), handle_queue_set_member_penalty(), handle_redirect(), handle_reload(), handle_restart_when_convenient(), handle_set_chanvar(), handle_set_extenpatternmatchnew(), handle_set_global(), handle_show_application(), handle_show_applications(), handle_show_chanvar(), handle_show_dialplan(), handle_show_function(), handle_show_functions(), handle_show_globals(), handle_show_hint(), handle_show_hints(), handle_show_http(), handle_show_profile(), handle_show_routes(), handle_show_settings(), handle_show_switches(), handle_show_sysinfo(), handle_show_threads(), handle_show_version_files(), handle_showcalls(), handle_showchan(), handle_showmanager(), handle_showmanagers(), handle_showmancmd(), handle_showmancmds(), handle_showmanconn(), handle_showmaneventq(), handle_skinny_set_debug(), handle_skinny_show_settings(), handle_softhangup(), handle_stop_when_convenient(), handle_unload(), handle_unset_extenpatternmatchnew(), handle_verbose(), handle_version(), handle_voicemail_reload(), handle_voicemail_show_users(), handle_voicemail_show_zones(), help1(), help_workhorse(), iax_show_provisioning(), jingle_show_channels(), locals_show(), meetme_cmd(), meetme_show_cmd(), modlist_modentry(), orig_app(), orig_exten(), peer_dump_func(), print_app_docs(), print_bc_info(), print_codec_to_cli(), print_group(), print_uptimestr(), radio_active(), radio_set_debug(), radio_set_debug_off(), radio_set_xpmr_debug(), radio_tune(), realtime_ldap_status(), rpt_do_cmd(), rpt_do_debug(), rpt_do_dump(), rpt_do_fun(), rpt_do_local_nodes(), rpt_do_lstats(), rpt_do_nodes(), rpt_do_stats(), rtcp_do_debug_ip(), rtp_do_debug_ip(), show_channels_cb(), show_chanstats_cb(), show_codec_n(), show_codecs(), show_config_description(), show_debug_helper(), show_dialplan_helper(), show_license(), show_users_realtime(), show_warranty(), sip_cli_notify(), sip_do_debug(), sip_do_debug_ip(), sip_do_debug_peer(), sip_prune_realtime(), sip_set_history(), sip_show_channel(), sip_show_channels(), sip_show_channelstats(), sip_show_domains(), sip_show_history(), sip_show_inuse(), sip_show_mwi(), sip_show_objects(), sip_show_registry(), sip_show_sched(), sip_show_settings(), sip_show_tcp(), sip_show_user(), sip_show_users(), sip_unregister(), sla_show_stations(), sla_show_trunks(), timing_test(), tune_rxctcss(), tune_rxinput(), tune_rxvoice(), tune_txoutput(), unistim_do_debug(), unistim_info(), and unistim_sp().
00102 { 00103 int res; 00104 struct ast_str *buf; 00105 va_list ap; 00106 00107 if (!(buf = ast_str_thread_get(&ast_cli_buf, AST_CLI_INITLEN))) 00108 return; 00109 00110 va_start(ap, fmt); 00111 res = ast_str_set_va(&buf, 0, fmt, ap); 00112 va_end(ap); 00113 00114 if (res != AST_DYNSTR_BUILD_FAILED) { 00115 ast_carefulwrite(fd, ast_str_buffer(buf), ast_str_strlen(buf), 100); 00116 } 00117 }
| int ast_cli_command_full | ( | int | uid, | |
| int | gid, | |||
| int | fd, | |||
| const char * | s | |||
| ) |
Interprets a command Interpret a command s, sending output to fd if uid:gid has permissions to run this command. uid = CLI_NO_PERMS to avoid checking user permissions gid = CLI_NO_PERMS to avoid checking group permissions.
| uid | User ID that is trying to run the command. | |
| gid | Group ID that is trying to run the command. | |
| fd | pipe | |
| s | incoming string |
| 0 | on success | |
| -1 | on failure |
Definition at line 2286 of file cli.c.
References ast_atomic_fetchadd_int(), ast_cli(), ast_free, ast_join(), AST_MAX_ARGS, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, CLI_FAILURE, CLI_HANDLER, cli_has_permissions(), CLI_SHOWUSAGE, ast_cli_args::fd, find_best(), find_cli(), ast_cli_entry::handler, ast_cli_entry::inuse, parse_args(), S_OR, and ast_cli_entry::usage.
Referenced by ast_cli_command_multiple_full().
02287 { 02288 char *args[AST_MAX_ARGS + 1]; 02289 struct ast_cli_entry *e; 02290 int x; 02291 char *duplicate = parse_args(s, &x, args + 1, AST_MAX_ARGS, NULL); 02292 char tmp[AST_MAX_ARGS + 1]; 02293 char *retval = NULL; 02294 struct ast_cli_args a = { 02295 .fd = fd, .argc = x, .argv = args+1 }; 02296 02297 if (duplicate == NULL) 02298 return -1; 02299 02300 if (x < 1) /* We need at least one entry, otherwise ignore */ 02301 goto done; 02302 02303 AST_RWLIST_RDLOCK(&helpers); 02304 e = find_cli(args + 1, 0); 02305 if (e) 02306 ast_atomic_fetchadd_int(&e->inuse, 1); 02307 AST_RWLIST_UNLOCK(&helpers); 02308 if (e == NULL) { 02309 ast_cli(fd, "No such command '%s' (type 'core show help %s' for other possible commands)\n", s, find_best(args + 1)); 02310 goto done; 02311 } 02312 02313 ast_join(tmp, sizeof(tmp), args + 1); 02314 /* Check if the user has rights to run this command. */ 02315 if (!cli_has_permissions(uid, gid, tmp)) { 02316 ast_cli(fd, "You don't have permissions to run '%s' command\n", tmp); 02317 ast_free(duplicate); 02318 return 0; 02319 } 02320 02321 /* 02322 * Within the handler, argv[-1] contains a pointer to the ast_cli_entry. 02323 * Remember that the array returned by parse_args is NULL-terminated. 02324 */ 02325 args[0] = (char *)e; 02326 02327 retval = e->handler(e, CLI_HANDLER, &a); 02328 02329 if (retval == CLI_SHOWUSAGE) { 02330 ast_cli(fd, "%s", S_OR(e->usage, "Invalid usage, but no usage information available.\n")); 02331 } else { 02332 if (retval == CLI_FAILURE) 02333 ast_cli(fd, "Command '%s' failed.\n", s); 02334 } 02335 ast_atomic_fetchadd_int(&e->inuse, -1); 02336 done: 02337 ast_free(duplicate); 02338 return 0; 02339 }
| int ast_cli_command_multiple_full | ( | int | uid, | |
| int | gid, | |||
| int | fd, | |||
| size_t | size, | |||
| const char * | s | |||
| ) |
Executes multiple CLI commands Interpret strings separated by NULL and execute each one, sending output to fd if uid has permissions, uid = CLI_NO_PERMS to avoid checking users permissions. gid = CLI_NO_PERMS to avoid checking group permissions.
| uid | User ID that is trying to run the command. | |
| gid | Group ID that is trying to run the command. | |
| fd | pipe | |
| size | is the total size of the string | |
| s | incoming string |
| number | of commands executed |
Definition at line 2341 of file cli.c.
References ast_cli_command_full().
Referenced by netconsole().
02342 { 02343 char cmd[512]; 02344 int x, y = 0, count = 0; 02345 02346 for (x = 0; x < size; x++) { 02347 cmd[y] = s[x]; 02348 y++; 02349 if (s[x] == '\0') { 02350 ast_cli_command_full(uid, gid, fd, cmd); 02351 y = 0; 02352 count++; 02353 } 02354 } 02355 return count; 02356 }
| char* ast_cli_complete | ( | const char * | word, | |
| char *const | choices[], | |||
| int | pos | |||
| ) |
Helper function to generate cli entries from a NULL-terminated array. Returns the n-th matching entry from the array, or NULL if not found. Can be used to implement generate() for static entries as below (in this example we complete the word in position 2):
char *my_generate(const char *line, const char *word, int pos, int n) { static char *choices = { "one", "two", "three", NULL }; if (pos == 2) return ast_cli_complete(word, choices, n); else return NULL; }
Definition at line 1382 of file cli.c.
References ast_strdup, ast_strlen_zero(), and len().
Referenced by complete_meetmecmd(), handle_cli_devstate_change(), handle_cli_iax2_prune_realtime(), handle_orig(), handle_show_applications(), and sip_prune_realtime().
01383 { 01384 int i, which = 0, len; 01385 len = ast_strlen_zero(word) ? 0 : strlen(word); 01386 01387 for (i = 0; choices[i]; i++) { 01388 if ((!len || !strncasecmp(word, choices[i], len)) && ++which > state) 01389 return ast_strdup(choices[i]); 01390 } 01391 return NULL; 01392 }
| char** ast_cli_completion_matches | ( | const char * | , | |
| const char * | ||||
| ) |
Generates a NULL-terminated array of strings that 1) begin with the string in the second parameter, and 2) are valid in a command after the string in the first parameter.
The first entry (offset 0) of the result is the longest common substring in the results, useful to extend the string that has been completed. Subsequent entries are all possible values, followed by a NULL. All strings and the array itself are malloc'ed and must be freed by the caller.
Definition at line 2137 of file cli.c.
References ast_cli_generator(), ast_copy_string(), ast_malloc, and ast_realloc.
Referenced by cli_complete(), and handle_commandmatchesarray().
02138 { 02139 char **match_list = NULL, *retstr, *prevstr; 02140 size_t match_list_len, max_equal, which, i; 02141 int matches = 0; 02142 02143 /* leave entry 0 free for the longest common substring */ 02144 match_list_len = 1; 02145 while ((retstr = ast_cli_generator(text, word, matches)) != NULL) { 02146 if (matches + 1 >= match_list_len) { 02147 match_list_len <<= 1; 02148 if (!(match_list = ast_realloc(match_list, match_list_len * sizeof(*match_list)))) 02149 return NULL; 02150 } 02151 match_list[++matches] = retstr; 02152 } 02153 02154 if (!match_list) 02155 return match_list; /* NULL */ 02156 02157 /* Find the longest substring that is common to all results 02158 * (it is a candidate for completion), and store a copy in entry 0. 02159 */ 02160 prevstr = match_list[1]; 02161 max_equal = strlen(prevstr); 02162 for (which = 2; which <= matches; which++) { 02163 for (i = 0; i < max_equal && toupper(prevstr[i]) == toupper(match_list[which][i]); i++) 02164 continue; 02165 max_equal = i; 02166 } 02167 02168 if (!(retstr = ast_malloc(max_equal + 1))) 02169 return NULL; 02170 02171 ast_copy_string(retstr, match_list[1], max_equal + 1); 02172 match_list[0] = retstr; 02173 02174 /* ensure that the array is NULL terminated */ 02175 if (matches + 1 >= match_list_len) { 02176 if (!(match_list = ast_realloc(match_list, (match_list_len + 1) * sizeof(*match_list)))) 02177 return NULL; 02178 } 02179 match_list[matches + 1] = NULL; 02180 02181 return match_list; 02182 }
| char* ast_cli_generator | ( | const char * | , | |
| const char * | , | |||
| int | ||||
| ) |
Readline madness Useful for readline, that's about it.
| 0 | on success | |
| -1 | on failure |
Definition at line 2281 of file cli.c.
References __ast_cli_generator().
Referenced by ast_cli_completion_matches(), ast_cli_generatornummatches(), cli_alias_passthrough(), and handle_cli_check_permissions().
02282 { 02283 return __ast_cli_generator(text, word, state, 1); 02284 }
| int ast_cli_generatornummatches | ( | const char * | text, | |
| const char * | word | |||
| ) |
Return the number of unique matches for the generator.
Definition at line 2120 of file cli.c.
References ast_cli_generator(), ast_free, and buf.
Referenced by handle_commandnummatches().
02121 { 02122 int matches = 0, i = 0; 02123 char *buf = NULL, *oldbuf = NULL; 02124 02125 while ((buf = ast_cli_generator(text, word, i++))) { 02126 if (!oldbuf || strcmp(buf,oldbuf)) 02127 matches++; 02128 if (oldbuf) 02129 ast_free(oldbuf); 02130 oldbuf = buf; 02131 } 02132 if (oldbuf) 02133 ast_free(oldbuf); 02134 return matches; 02135 }
| int ast_cli_perms_init | ( | int | reload | ) |
Provided by cli.c
Definition at line 1582 of file cli.c.
References ast_calloc, ast_category_browse(), ast_config_destroy(), ast_config_load2(), ast_free, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_log(), ast_mutex_trylock(), ast_mutex_unlock(), AST_RWLIST_INSERT_TAIL, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strdup, ast_strlen_zero(), ast_variable_browse(), cli_perm::command, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEUNCHANGED, destroy_user_perms(), usergroup_cli_perm::gid, LOG_NOTICE, LOG_WARNING, ast_variable::name, ast_variable::next, cli_perm::permit, usergroup_cli_perm::perms, perms_config, usergroup_cli_perm::uid, and ast_variable::value.
Referenced by handle_cli_reload_permissions(), and main().
01583 { 01584 struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 }; 01585 struct ast_config *cfg; 01586 char *cat = NULL; 01587 struct ast_variable *v; 01588 struct usergroup_cli_perm *user_group, *cp_entry; 01589 struct cli_perm *perm = NULL; 01590 struct passwd *pw; 01591 struct group *gr; 01592 01593 if (ast_mutex_trylock(&permsconfiglock)) { 01594 ast_log(LOG_NOTICE, "You must wait until last 'cli reload permissions' command finish\n"); 01595 return 1; 01596 } 01597 01598 cfg = ast_config_load2(perms_config, "" /* core, can't reload */, config_flags); 01599 if (!cfg) { 01600 ast_mutex_unlock(&permsconfiglock); 01601 return 1; 01602 } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) { 01603 ast_mutex_unlock(&permsconfiglock); 01604 return 0; 01605 } 01606 01607 /* free current structures. */ 01608 destroy_user_perms(); 01609 01610 while ((cat = ast_category_browse(cfg, cat))) { 01611 if (!strcasecmp(cat, "general")) { 01612 /* General options */ 01613 for (v = ast_variable_browse(cfg, cat); v; v = v->next) { 01614 if (!strcasecmp(v->name, "default_perm")) { 01615 cli_default_perm = (!strcasecmp(v->value, "permit")) ? 1: 0; 01616 } 01617 } 01618 continue; 01619 } 01620 01621 /* users or groups */ 01622 gr = NULL, pw = NULL; 01623 if (cat[0] == '@') { 01624 /* This is a group */ 01625 gr = getgrnam(&cat[1]); 01626 if (!gr) { 01627 ast_log (LOG_WARNING, "Unknown group '%s'\n", &cat[1]); 01628 continue; 01629 } 01630 } else { 01631 /* This is a user */ 01632 pw = getpwnam(cat); 01633 if (!pw) { 01634 ast_log (LOG_WARNING, "Unknown user '%s'\n", cat); 01635 continue; 01636 } 01637 } 01638 user_group = NULL; 01639 /* Check for duplicates */ 01640 AST_RWLIST_WRLOCK(&cli_perms); 01641 AST_LIST_TRAVERSE(&cli_perms, cp_entry, list) { 01642 if ((pw && cp_entry->uid == pw->pw_uid) || (gr && cp_entry->gid == gr->gr_gid)) { 01643 /* if it is duplicated, just added this new settings, to 01644 the current list. */ 01645 user_group = cp_entry; 01646 break; 01647 } 01648 } 01649 AST_RWLIST_UNLOCK(&cli_perms); 01650 01651 if (!user_group) { 01652 /* alloc space for the new user config. */ 01653 user_group = ast_calloc(1, sizeof(*user_group)); 01654 if (!user_group) { 01655 continue; 01656 } 01657 user_group->uid = (pw ? pw->pw_uid : -1); 01658 user_group->gid = (gr ? gr->gr_gid : -1); 01659 user_group->perms = ast_calloc(1, sizeof(*user_group->perms)); 01660 if (!user_group->perms) { 01661 ast_free(user_group); 01662 continue; 01663 } 01664 } 01665 for (v = ast_variable_browse(cfg, cat); v; v = v->next) { 01666 if (ast_strlen_zero(v->value)) { 01667 /* we need to check this condition cause it could break security. */ 01668 ast_log(LOG_WARNING, "Empty permit/deny option in user '%s'\n", cat); 01669 continue; 01670 } 01671 if (!strcasecmp(v->name, "permit")) { 01672 perm = ast_calloc(1, sizeof(*perm)); 01673 if (perm) { 01674 perm->permit = 1; 01675 perm->command = ast_strdup(v->value); 01676 } 01677 } else if (!strcasecmp(v->name, "deny")) { 01678 perm = ast_calloc(1, sizeof(*perm)); 01679 if (perm) { 01680 perm->permit = 0; 01681 perm->command = ast_strdup(v->value); 01682 } 01683 } else { 01684 /* up to now, only 'permit' and 'deny' are possible values. */ 01685 ast_log(LOG_WARNING, "Unknown '%s' option\n", v->name); 01686 continue; 01687 } 01688 if (perm) { 01689 /* Added the permission to the user's list. */ 01690 AST_LIST_INSERT_TAIL(user_group->perms, perm, list); 01691 perm = NULL; 01692 } 01693 } 01694 AST_RWLIST_WRLOCK(&cli_perms); 01695 AST_RWLIST_INSERT_TAIL(&cli_perms, user_group, list); 01696 AST_RWLIST_UNLOCK(&cli_perms); 01697 } 01698 01699 ast_config_destroy(cfg); 01700 ast_mutex_unlock(&permsconfiglock); 01701 return 0; 01702 }
| int ast_cli_register | ( | struct ast_cli_entry * | e | ) |
Registers a command or an array of commands.
| e | which cli entry to register. Register your own command |
| 0 | on success | |
| -1 | on failure |
Definition at line 1947 of file cli.c.
References __ast_cli_register().
Referenced by ast_cdr_engine_init(), ast_cli_register_multiple(), dnsmgr_init(), do_reload(), load_config(), and load_module().
01948 { 01949 return __ast_cli_register(e, NULL); 01950 }
| int ast_cli_register_multiple | ( | struct ast_cli_entry * | e, | |
| int | len | |||
| ) |
Register multiple commands.
| e | pointer to first cli entry to register | |
| len | number of entries to register |
Definition at line 1955 of file cli.c.
References ast_cli_register().
Referenced by __ast_mm_init(), __ast_register_translator(), __init_manager(), ast_ais_clm_load_module(), ast_ais_evt_load_module(), ast_builtins_init(), ast_channels_init(), ast_features_init(), ast_file_init(), ast_http_init(), ast_image_init(), ast_indications_init(), ast_rtp_init(), ast_test_init(), ast_timing_init(), ast_tps_init(), ast_udptl_init(), ast_utils_init(), astdb_init(), astobj2_init(), crypto_init(), iax_provision_init(), init_framer(), init_logger(), load_module(), load_pbx(), main(), and register_config_cli().
01956 { 01957 int i, res = 0; 01958 01959 for (i = 0; i < len; i++) 01960 res |= ast_cli_register(e + i); 01961 01962 return res; 01963 }
| int ast_cli_unregister | ( | struct ast_cli_entry * | e | ) |
Unregisters a command or an array of commands.
| e | which cli entry to unregister Unregister your own command. You must pass a completed ast_cli_entry structure |
Definition at line 1941 of file cli.c.
References __ast_cli_unregister().
Referenced by alias_destroy(), ast_cli_unregister_multiple(), do_reload(), load_module(), and unload_module().
01942 { 01943 return __ast_cli_unregister(e, NULL); 01944 }
| int ast_cli_unregister_multiple | ( | struct ast_cli_entry * | e, | |
| int | len | |||
| ) |
Unregister multiple commands.
| e | pointer to first cli entry to unregister | |
| len | number of entries to unregister |
Definition at line 1965 of file cli.c.
References ast_cli_unregister().
Referenced by __unload_module(), ast_ais_clm_unload_module(), iax_provision_unload(), load_module(), and unload_module().
01966 { 01967 int i, res = 0; 01968 01969 for (i = 0; i < len; i++) 01970 res |= ast_cli_unregister(e + i); 01971 01972 return res; 01973 }
| char* ast_complete_channels | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state, | |||
| int | rpos | |||
| ) |
Command completion for the list of active channels.
This can be called from a CLI command completion function that wants to complete from the list of active channels. 'rpos' is the required position in the command. This function will return NULL immediately if 'rpos' is not the same as the current position, 'pos'.
Definition at line 1394 of file cli.c.
References ast_channel_unlock, ast_channel_walk_locked(), and ast_strdup.
Referenced by complete_ch(), handle_cli_agi_add_cmd(), handle_cli_mixmonitor(), handle_core_set_debug_channel(), handle_redirect(), handle_set_chanvar(), handle_show_chanvar(), handle_showchan(), and handle_softhangup().
01395 { 01396 struct ast_channel *c = NULL; 01397 int which = 0; 01398 int wordlen; 01399 char notfound = '\0'; 01400 char *ret = ¬found; /* so NULL can break the loop */ 01401 01402 if (pos != rpos) 01403 return NULL; 01404 01405 wordlen = strlen(word); 01406 01407 while (ret == ¬found && (c = ast_channel_walk_locked(c))) { 01408 if (!strncasecmp(word, c->name, wordlen) && ++which > state) 01409 ret = ast_strdup(c->name); 01410 ast_channel_unlock(c); 01411 } 01412 return ret == ¬found ? NULL : ret; 01413 }
| unsigned int ast_debug_get_by_file | ( | const char * | file | ) |
Get the debug level for a file.
| file | the filename |
Definition at line 119 of file cli.c.
References AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_debug_file::filename, and ast_debug_file::level.
00120 { 00121 struct ast_debug_file *adf; 00122 unsigned int res = 0; 00123 00124 AST_RWLIST_RDLOCK(&debug_files); 00125 AST_LIST_TRAVERSE(&debug_files, adf, entry) { 00126 if (!strncasecmp(adf->filename, file, strlen(adf->filename))) { 00127 res = adf->level; 00128 break; 00129 } 00130 } 00131 AST_RWLIST_UNLOCK(&debug_files); 00132 00133 return res; 00134 }
| unsigned int ast_verbose_get_by_file | ( | const char * | file | ) |
Get the debug level for a file.
| file | the filename |
Definition at line 136 of file cli.c.
References AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_debug_file::filename, and ast_debug_file::level.
00137 { 00138 struct ast_debug_file *adf; 00139 unsigned int res = 0; 00140 00141 AST_RWLIST_RDLOCK(&verbose_files); 00142 AST_LIST_TRAVERSE(&verbose_files, adf, entry) { 00143 if (!strncasecmp(adf->filename, file, strlen(file))) { 00144 res = adf->level; 00145 break; 00146 } 00147 } 00148 AST_RWLIST_UNLOCK(&verbose_files); 00149 00150 return res; 00151 }
| static int cli_has_permissions | ( | int | uid, | |
| int | gid, | |||
| const char * | command | |||
| ) | [static] |
Definition at line 166 of file cli.c.
References AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, CLI_NO_PERMS, cli_perm::command, usergroup_cli_perm::gid, cli_perm::permit, usergroup_cli_perm::perms, and usergroup_cli_perm::uid.
Referenced by ast_cli_command_full(), and handle_cli_check_permissions().
00167 { 00168 struct usergroup_cli_perm *user_perm; 00169 struct cli_perm *perm; 00170 /* set to the default permissions general option. */ 00171 int isallowg = cli_default_perm, isallowu = -1, ispattern; 00172 regex_t regexbuf; 00173 00174 /* if uid == -1 or gid == -1 do not check permissions. 00175 if uid == -2 and gid == -2 is because rasterisk client didn't send 00176 the credentials, so the cli_default_perm will be applied. */ 00177 if ((uid == CLI_NO_PERMS && gid == CLI_NO_PERMS) || command[0] == '_') { 00178 return 1; 00179 } 00180 00181 if (gid < 0 && uid < 0) { 00182 return cli_default_perm; 00183 } 00184 00185 AST_RWLIST_RDLOCK(&cli_perms); 00186 AST_LIST_TRAVERSE(&cli_perms, user_perm, list) { 00187 if (user_perm->gid != gid && user_perm->uid != uid) { 00188 continue; 00189 } 00190 AST_LIST_TRAVERSE(user_perm->perms, perm, list) { 00191 if (strcasecmp(perm->command, "all") && strncasecmp(perm->command, command, strlen(perm->command))) { 00192 /* if the perm->command is a pattern, check it against command. */ 00193 ispattern = !regcomp(®exbuf, perm->command, REG_EXTENDED | REG_NOSUB | REG_ICASE); 00194 if (ispattern && regexec(®exbuf, command, 0, NULL, 0)) { 00195 regfree(®exbuf); 00196 continue; 00197 } 00198 if (!ispattern) { 00199 continue; 00200 } 00201 regfree(®exbuf); 00202 } 00203 if (user_perm->uid == uid) { 00204 /* this is a user definition. */ 00205 isallowu = perm->permit; 00206 } else { 00207 /* otherwise is a group definition. */ 00208 isallowg = perm->permit; 00209 } 00210 } 00211 } 00212 AST_RWLIST_UNLOCK(&cli_perms); 00213 if (isallowu > -1) { 00214 /* user definition override group definition. */ 00215 isallowg = isallowu; 00216 } 00217 00218 return isallowg; 00219 }
| static struct ast_cli_entry* cli_next | ( | struct ast_cli_entry * | e | ) | [static, read] |
Definition at line 660 of file cli.c.
References AST_LIST_FIRST, and AST_LIST_NEXT.
Referenced by __ast_cli_generator(), find_cli(), handle_cli_check_permissions(), and help1().
00661 { 00662 if (e) { 00663 return AST_LIST_NEXT(e, list); 00664 } else { 00665 return AST_LIST_FIRST(&helpers); 00666 } 00667 }
| static char* complete_fn | ( | const char * | word, | |
| int | state | |||
| ) | [static] |
Definition at line 223 of file cli.c.
References ast_config_AST_MODULE_DIR, ast_copy_string(), ast_strdup, and free.
Referenced by handle_load().
00224 { 00225 char *c, *d; 00226 char filename[PATH_MAX]; 00227 00228 if (word[0] == '/') 00229 ast_copy_string(filename, word, sizeof(filename)); 00230 else 00231 snprintf(filename, sizeof(filename), "%s/%s", ast_config_AST_MODULE_DIR, word); 00232 00233 c = d = filename_completion_function(filename, state); 00234 00235 if (c && word[0] != '/') 00236 c += (strlen(ast_config_AST_MODULE_DIR) + 1); 00237 if (c) 00238 c = ast_strdup(c); 00239 00240 free(d); 00241 00242 return c; 00243 }
| static char* complete_number | ( | const char * | partial, | |
| unsigned int | min, | |||
| unsigned int | max, | |||
| int | n | |||
| ) | [static] |
Definition at line 323 of file cli.c.
References ast_strdup, ast_strlen_zero(), and cli_perm::next.
Referenced by handle_verbose().
00324 { 00325 int i, count = 0; 00326 unsigned int prospective[2]; 00327 unsigned int part = strtoul(partial, NULL, 10); 00328 char next[12]; 00329 00330 if (part < min || part > max) { 00331 return NULL; 00332 } 00333 00334 for (i = 0; i < 21; i++) { 00335 if (i == 0) { 00336 prospective[0] = prospective[1] = part; 00337 } else if (part == 0 && !ast_strlen_zero(partial)) { 00338 break; 00339 } else if (i < 11) { 00340 prospective[0] = prospective[1] = part * 10 + (i - 1); 00341 } else { 00342 prospective[0] = (part * 10 + (i - 11)) * 10; 00343 prospective[1] = prospective[0] + 9; 00344 } 00345 if (i < 11 && (prospective[0] < min || prospective[0] > max)) { 00346 continue; 00347 } else if (prospective[1] < min || prospective[0] > max) { 00348 continue; 00349 } 00350 00351 if (++count > n) { 00352 if (i < 11) { 00353 snprintf(next, sizeof(next), "%u", prospective[0]); 00354 } else { 00355 snprintf(next, sizeof(next), "%u...", prospective[0] / 10); 00356 } 00357 return ast_strdup(next); 00358 } 00359 } 00360 return NULL; 00361 }
| static void destroy_user_perms | ( | void | ) | [static] |
cleanup (free) cli_perms linkedlist.
Definition at line 1566 of file cli.c.
References ast_free, AST_LIST_REMOVE_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, cli_perm::command, and usergroup_cli_perm::perms.
Referenced by ast_cli_perms_init().
01567 { 01568 struct cli_perm *perm; 01569 struct usergroup_cli_perm *user_perm; 01570 01571 AST_RWLIST_WRLOCK(&cli_perms); 01572 while ((user_perm = AST_LIST_REMOVE_HEAD(&cli_perms, list))) { 01573 while ((perm = AST_LIST_REMOVE_HEAD(user_perm->perms, list))) { 01574 ast_free(perm->command); 01575 ast_free(perm); 01576 } 01577 ast_free(user_perm); 01578 } 01579 AST_RWLIST_UNLOCK(&cli_perms); 01580 }
| static char* find_best | ( | char * | argv[] | ) | [static] |
Definition at line 1844 of file cli.c.
References ast_join(), AST_MAX_CMD_LEN, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, and find_cli().
Referenced by ast_cli_command_full().
01845 { 01846 static char cmdline[80]; 01847 int x; 01848 /* See how close we get, then print the candidate */ 01849 char *myargv[AST_MAX_CMD_LEN]; 01850 for (x=0;x<AST_MAX_CMD_LEN;x++) 01851 myargv[x]=NULL; 01852 AST_RWLIST_RDLOCK(&helpers); 01853 for (x=0;argv[x];x++) { 01854 myargv[x] = argv[x]; 01855 if (!find_cli(myargv, -1)) 01856 break; 01857 } 01858 AST_RWLIST_UNLOCK(&helpers); 01859 ast_join(cmdline, sizeof(cmdline), myargv); 01860 return cmdline; 01861 }
| static struct ast_cli_entry* find_cli | ( | char *const | cmds[], | |
| int | match_type | |||
| ) | [static, read] |
Definition at line 1800 of file cli.c.
References ast_strlen_zero(), cli_next(), ast_cli_entry::cmda, and word_match().
Referenced by __ast_cli_register(), ast_cli_command_full(), find_best(), and handle_help().
01801 { 01802 int matchlen = -1; /* length of longest match so far */ 01803 struct ast_cli_entry *cand = NULL, *e=NULL; 01804 01805 while ( (e = cli_next(e)) ) { 01806 /* word-by word regexp comparison */ 01807 char * const *src = cmds; 01808 char * const *dst = e->cmda; 01809 int n = 0; 01810 for (;; dst++, src += n) { 01811 n = word_match(*src, *dst); 01812 if (n < 0) 01813 break; 01814 } 01815 if (ast_strlen_zero(*dst) || ((*dst)[0] == '[' && ast_strlen_zero(dst[1]))) { 01816 /* no more words in 'e' */ 01817 if (ast_strlen_zero(*src)) /* exact match, cannot do better */ 01818 break; 01819 /* Here, cmds has more words than the entry 'e' */ 01820 if (match_type != 0) /* but we look for almost exact match... */ 01821 continue; /* so we skip this one. */ 01822 /* otherwise we like it (case 0) */ 01823 } else { /* still words in 'e' */ 01824 if (ast_strlen_zero(*src)) 01825 continue; /* cmds is shorter than 'e', not good */ 01826 /* Here we have leftover words in cmds and 'e', 01827 * but there is a mismatch. We only accept this one if match_type == -1 01828 * and this is the last word for both. 01829 */ 01830 if (match_type != -1 || !ast_strlen_zero(src[1]) || 01831 !ast_strlen_zero(dst[1])) /* not the one we look for */ 01832 continue; 01833 /* good, we are in case match_type == -1 and mismatch on last word */ 01834 } 01835 if (src - cmds > matchlen) { /* remember the candidate */ 01836 matchlen = src - cmds; 01837 cand = e; 01838 } 01839 } 01840 01841 return e ? e : cand; 01842 }
| static struct ast_debug_file* find_debug_file | ( | const char * | fn, | |
| unsigned int | debug | |||
| ) | [static, read] |
Find the debug or verbose file setting.
Definition at line 310 of file cli.c.
References AST_LIST_TRAVERSE, and ast_debug_file::filename.
Referenced by handle_verbose().
00311 { 00312 struct ast_debug_file *df = NULL; 00313 struct debug_file_list *dfl = debug ? &debug_files : &verbose_files; 00314 00315 AST_LIST_TRAVERSE(dfl, df, entry) { 00316 if (!strcasecmp(df->filename, fn)) 00317 break; 00318 } 00319 00320 return df; 00321 }
| static char* group_show_channels | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 1415 of file cli.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_app_group_list_head(), ast_app_group_list_rdlock(), ast_app_group_list_unlock(), ast_cli(), AST_LIST_NEXT, ast_strlen_zero(), ast_group_info::category, ast_group_info::chan, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ESS, ast_cli_args::fd, FORMAT_STRING, ast_group_info::group, and ast_cli_entry::usage.
01416 { 01417 #define FORMAT_STRING "%-25s %-20s %-20s\n" 01418 01419 struct ast_group_info *gi = NULL; 01420 int numchans = 0; 01421 regex_t regexbuf; 01422 int havepattern = 0; 01423 01424 switch (cmd) { 01425 case CLI_INIT: 01426 e->command = "group show channels"; 01427 e->usage = 01428 "Usage: group show channels [pattern]\n" 01429 " Lists all currently active channels with channel group(s) specified.\n" 01430 " Optional regular expression pattern is matched to group names for each\n" 01431 " channel.\n"; 01432 return NULL; 01433 case CLI_GENERATE: 01434 return NULL; 01435 } 01436 01437 if (a->argc < 3 || a->argc > 4) 01438 return CLI_SHOWUSAGE; 01439 01440 if (a->argc == 4) { 01441 if (regcomp(®exbuf, a->argv[3], REG_EXTENDED | REG_NOSUB)) 01442 return CLI_SHOWUSAGE; 01443 havepattern = 1; 01444 } 01445 01446 ast_cli(a->fd, FORMAT_STRING, "Channel", "Group", "Category"); 01447 01448 ast_app_group_list_rdlock(); 01449 01450 gi = ast_app_group_list_head(); 01451 while (gi) { 01452 if (!havepattern || !regexec(®exbuf, gi->group, 0, NULL, 0)) { 01453 ast_cli(a->fd, FORMAT_STRING, gi->chan->name, gi->group, (ast_strlen_zero(gi->category) ? "(default)" : gi->category)); 01454 numchans++; 01455 } 01456 gi = AST_LIST_NEXT(gi, group_list); 01457 } 01458 01459 ast_app_group_list_unlock(); 01460 01461 if (havepattern) 01462 regfree(®exbuf); 01463 01464 ast_cli(a->fd, "%d active channel%s\n", numchans, ESS(numchans)); 01465 return CLI_SUCCESS; 01466 #undef FORMAT_STRING 01467 }
| static char* handle_chanlist | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 794 of file cli.c.
References ast_channel::_state, ast_channel::amaflags, ast_channel::appl, ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_active_calls(), ast_bridged_channel(), ast_channel_unlock, ast_channel_walk_locked(), ast_cli(), ast_processed_calls(), ast_state2str(), ast_strlen_zero(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), ast_channel::cdr, ast_channel::cid, ast_callerid::cid_num, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, CONCISE_FORMAT_STRING, ast_channel::context, ast_channel::data, ESS, ast_channel::exten, ast_cli_args::fd, FORMAT_STRING, FORMAT_STRING2, option_maxcalls, ast_channel::priority, S_OR, ast_cdr::start, ast_cli_entry::usage, VERBOSE_FORMAT_STRING, and VERBOSE_FORMAT_STRING2.
00795 { 00796 #define FORMAT_STRING "%-20.20s %-20.20s %-7.7s %-30.30s\n" 00797 #define FORMAT_STRING2 "%-20.20s %-20.20s %-7.7s %-30.30s\n" 00798 #define CONCISE_FORMAT_STRING "%s!%s!%s!%d!%s!%s!%s!%s!%s!%d!%s!%s!%s\n" 00799 #define VERBOSE_FORMAT_STRING "%-20.20s %-20.20s %-16.16s %4d %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n" 00800 #define VERBOSE_FORMAT_STRING2 "%-20.20s %-20.20s %-16.16s %-4.4s %-7.7s %-12.12s %-25.25s %-15.15s %8.8s %-11.11s %-20.20s\n" 00801 00802 struct ast_channel *c = NULL; 00803 int numchans = 0, concise = 0, verbose = 0, count = 0; 00804 int fd, argc; 00805 char **argv; 00806 00807 switch (cmd) { 00808 case CLI_INIT: 00809 e->command = "core show channels [concise|verbose|count]"; 00810 e->usage = 00811 "Usage: core show channels [concise|verbose|count]\n" 00812 " Lists currently defined channels and some information about them. If\n" 00813 " 'concise' is specified, the format is abridged and in a more easily\n" 00814 " machine parsable format. If 'verbose' is specified, the output includes\n" 00815 " more and longer fields. If 'count' is specified only the channel and call\n" 00816 " count is output.\n" 00817 " The 'concise' option is deprecated and will be removed from future versions\n" 00818 " of Asterisk.\n"; 00819 return NULL; 00820 00821 case CLI_GENERATE: 00822 return NULL; 00823 } 00824 fd = a->fd; 00825 argc = a->argc; 00826 argv = a->argv; 00827 00828 if (a->argc == e->args) { 00829 if (!strcasecmp(argv[e->args-1],"concise")) 00830 concise = 1; 00831 else if (!strcasecmp(argv[e->args-1],"verbose")) 00832 verbose = 1; 00833 else if (!strcasecmp(argv[e->args-1],"count")) 00834 count = 1; 00835 else 00836 return CLI_SHOWUSAGE; 00837 } else if (a->argc != e->args - 1) 00838 return CLI_SHOWUSAGE; 00839 00840 if (!count) { 00841 if (!concise && !verbose) 00842 ast_cli(fd, FORMAT_STRING2, "Channel", "Location", "State", "Application(Data)"); 00843 else if (verbose) 00844 ast_cli(fd, VERBOSE_FORMAT_STRING2, "Channel", "Context", "Extension", "Priority", "State", "Application", "Data", 00845 "CallerID", "Duration", "Accountcode", "BridgedTo"); 00846 } 00847 00848 while ((c = ast_channel_walk_locked(c)) != NULL) { 00849 struct ast_channel *bc = ast_bridged_channel(c); 00850 char durbuf[10] = "-"; 00851 00852 if (!count) { 00853 if ((concise || verbose) && c->cdr && !ast_tvzero(c->cdr->start)) { 00854 int duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000); 00855 if (verbose) { 00856 int durh = duration / 3600; 00857 int durm = (duration % 3600) / 60; 00858 int durs = duration % 60; 00859 snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs); 00860 } else { 00861 snprintf(durbuf, sizeof(durbuf), "%d", duration); 00862 } 00863 } 00864 if (concise) { 00865 ast_cli(fd, CONCISE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state), 00866 c->appl ? c->appl : "(None)", 00867 S_OR(c->data, ""), /* XXX different from verbose ? */ 00868 S_OR(c->cid.cid_num, ""), 00869 S_OR(c->accountcode, ""), 00870 c->amaflags, 00871 durbuf, 00872 bc ? bc->name : "(None)", 00873 c->uniqueid); 00874 } else if (verbose) { 00875 ast_cli(fd, VERBOSE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state), 00876 c->appl ? c->appl : "(None)", 00877 c->data ? S_OR(c->data, "(Empty)" ): "(None)", 00878 S_OR(c->cid.cid_num, ""), 00879 durbuf, 00880 S_OR(c->accountcode, ""), 00881 bc ? bc->name : "(None)"); 00882 } else { 00883 char locbuf[40] = "(None)"; 00884 char appdata[40] = "(None)"; 00885 00886 if (!ast_strlen_zero(c->context) && !ast_strlen_zero(c->exten)) 00887 snprintf(locbuf, sizeof(locbuf), "%s@%s:%d", c->exten, c->context, c->priority); 00888 if (c->appl) 00889 snprintf(appdata, sizeof(appdata), "%s(%s)", c->appl, S_OR(c->data, "")); 00890 ast_cli(fd, FORMAT_STRING, c->name, locbuf, ast_state2str(c->_state), appdata); 00891 } 00892 } 00893 numchans++; 00894 ast_channel_unlock(c); 00895 } 00896 if (!concise) { 00897 ast_cli(fd, "%d active channel%s\n", numchans, ESS(numchans)); 00898 if (option_maxcalls) 00899 ast_cli(fd, "%d of %d max active call%s (%5.2f%% of capacity)\n", 00900 ast_active_calls(), option_maxcalls, ESS(ast_active_calls()), 00901 ((double)ast_active_calls() / (double)option_maxcalls) * 100.0); 00902 else 00903 ast_cli(fd, "%d active call%s\n", ast_active_calls(), ESS(ast_active_calls())); 00904 00905 ast_cli(fd, "%d call%s processed\n", ast_processed_calls(), ESS(ast_processed_calls())); 00906 } 00907 return CLI_SUCCESS; 00908 00909 #undef FORMAT_STRING 00910 #undef FORMAT_STRING2 00911 #undef CONCISE_FORMAT_STRING 00912 #undef VERBOSE_FORMAT_STRING 00913 #undef VERBOSE_FORMAT_STRING2 00914 }
| static char* handle_cli_check_permissions | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
handles CLI command 'cli check permissions'
Definition at line 1008 of file cli.c.
References ast_cli_entry::_full_cmd, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_cli_generator(), ast_join(), AST_MAX_ARGS, ast_strdupa, ast_strlen_zero(), CLI_FAILURE, CLI_GENERATE, cli_has_permissions(), CLI_INIT, cli_next(), CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, cli_perm::command, ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, S_OR, ast_cli_entry::summary, ast_cli_entry::usage, and ast_cli_args::word.
01009 { 01010 struct passwd *pw = NULL; 01011 struct group *gr; 01012 int gid = -1, uid = -1; 01013 char command[AST_MAX_ARGS] = ""; 01014 struct ast_cli_entry *ce = NULL; 01015 int found = 0; 01016 char *group, *tmp; 01017 01018 switch (cmd) { 01019 case CLI_INIT: 01020 e->command = "cli check permissions"; 01021 e->usage = 01022 "Usage: cli check permissions {<username>|@<groupname>|<username>@<groupname>} [<command>]\n" 01023 " Check permissions config for a user@group or list the allowed commands for the specified user.\n" 01024 " The username or the groupname may be omitted.\n"; 01025 return NULL; 01026 case CLI_GENERATE: 01027 if (a->pos >= 4) { 01028 return ast_cli_generator(a->line + strlen("cli check permissions") + strlen(a->argv[3]) + 1, a->word, a->n); 01029 } 01030 return NULL; 01031 } 01032 01033 if (a->argc < 4) { 01034 return CLI_SHOWUSAGE; 01035 } 01036 01037 tmp = ast_strdupa(a->argv[3]); 01038 group = strchr(tmp, '@'); 01039 if (group) { 01040 gr = getgrnam(&group[1]); 01041 if (!gr) { 01042 ast_cli(a->fd, "Unknown group '%s'\n", &group[1]); 01043 return CLI_FAILURE; 01044 } 01045 group[0] = '\0'; 01046 gid = gr->gr_gid; 01047 } 01048 01049 if (!group && ast_strlen_zero(tmp)) { 01050 ast_cli(a->fd, "You didn't supply a username\n"); 01051 } else if (!ast_strlen_zero(tmp) && !(pw = getpwnam(tmp))) { 01052 ast_cli(a->fd, "Unknown user '%s'\n", tmp); 01053 return CLI_FAILURE; 01054 } else if (pw) { 01055 uid = pw->pw_uid; 01056 } 01057 01058 if (a->argc == 4) { 01059 while ((ce = cli_next(ce))) { 01060 /* Hide commands that start with '_' */ 01061 if (ce->_full_cmd[0] == '_') { 01062 continue; 01063 } 01064 if (cli_has_permissions(uid, gid, ce->_full_cmd)) { 01065 ast_cli(a->fd, "%30.30s %s\n", ce->_full_cmd, S_OR(ce->summary, "<no description available>")); 01066 found++; 01067 } 01068 } 01069 if (!found) { 01070 ast_cli(a->fd, "You are not allowed to run any command on Asterisk\n"); 01071 } 01072 } else { 01073 ast_join(command, sizeof(command), a->argv + 4); 01074 ast_cli(a->fd, "%s '%s%s%s' is %s to run command: '%s'\n", uid >= 0 ? "User" : "Group", tmp, 01075 group && uid >= 0 ? "@" : "", 01076 group ? &group[1] : "", 01077 cli_has_permissions(uid, gid, command) ? "allowed" : "not allowed", command); 01078 } 01079 01080 return CLI_SUCCESS; 01081 }
| static char* handle_cli_reload_permissions | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
handles CLI command 'cli reload permissions'
Definition at line 989 of file cli.c.
References ast_cli_perms_init(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, and ast_cli_entry::usage.
00990 { 00991 switch (cmd) { 00992 case CLI_INIT: 00993 e->command = "cli reload permissions"; 00994 e->usage = 00995 "Usage: cli reload permissions\n" 00996 " Reload the 'cli_permissions.conf' file.\n"; 00997 return NULL; 00998 case CLI_GENERATE: 00999 return NULL; 01000 } 01001 01002 ast_cli_perms_init(1); 01003 01004 return CLI_SUCCESS; 01005 }
| static char* handle_cli_show_permissions | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
handles CLI command 'cli show permissions'
Definition at line 944 of file cli.c.
References ast_cli(), AST_LIST_TRAVERSE, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, cli_perm::command, ast_cli_entry::command, ast_cli_args::fd, usergroup_cli_perm::gid, cli_perm::permit, usergroup_cli_perm::perms, usergroup_cli_perm::uid, and ast_cli_entry::usage.
00945 { 00946 struct usergroup_cli_perm *cp; 00947 struct cli_perm *perm; 00948 struct passwd *pw = NULL; 00949 struct group *gr = NULL; 00950 00951 switch (cmd) { 00952 case CLI_INIT: 00953 e->command = "cli show permissions"; 00954 e->usage = 00955 "Usage: cli show permissions\n" 00956 " Shows CLI configured permissions.\n"; 00957 return NULL; 00958 case CLI_GENERATE: 00959 return NULL; 00960 } 00961 00962 AST_RWLIST_RDLOCK(&cli_perms); 00963 AST_LIST_TRAVERSE(&cli_perms, cp, list) { 00964 if (cp->uid >= 0) { 00965 pw = getpwuid(cp->uid); 00966 if (pw) { 00967 ast_cli(a->fd, "user: %s [uid=%d]\n", pw->pw_name, cp->uid); 00968 } 00969 } else { 00970 gr = getgrgid(cp->gid); 00971 if (gr) { 00972 ast_cli(a->fd, "group: %s [gid=%d]\n", gr->gr_name, cp->gid); 00973 } 00974 } 00975 ast_cli(a->fd, "Permissions:\n"); 00976 if (cp->perms) { 00977 AST_LIST_TRAVERSE(cp->perms, perm, list) { 00978 ast_cli(a->fd, "\t%s -> %s\n", perm->permit ? "permit" : "deny", perm->command); 00979 } 00980 } 00981 ast_cli(a->fd, "\n"); 00982 } 00983 AST_RWLIST_UNLOCK(&cli_perms); 00984 00985 return CLI_SUCCESS; 00986 }
| static char* handle_cli_wait_fullybooted | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 1469 of file cli.c.
References ast_cli(), AST_OPT_FLAG_FULLY_BOOTED, ast_options, ast_test_flag, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.
01470 { 01471 switch (cmd) { 01472 case CLI_INIT: 01473 e->command = "core waitfullybooted"; 01474 e->usage = 01475 "Usage: core waitfullybooted\n" 01476 " Wait until Asterisk has fully booted.\n"; 01477 return NULL; 01478 case CLI_GENERATE: 01479 return NULL; 01480 } 01481 01482 while (!ast_test_flag(&ast_options, AST_OPT_FLAG_FULLY_BOOTED)) { 01483 usleep(100); 01484 } 01485 01486 ast_cli(a->fd, "Asterisk has fully booted.\n"); 01487 01488 return CLI_SUCCESS; 01489 }
| static char* handle_commandcomplete | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 1166 of file cli.c.
References __ast_cli_generator(), ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_free, buf, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.
01167 { 01168 char *buf; 01169 switch (cmd) { 01170 case CLI_INIT: 01171 e->command = "_command complete"; 01172 e->usage = 01173 "Usage: _command complete \"<line>\" text state\n" 01174 " This function is used internally to help with command completion and should.\n" 01175 " never be called by the user directly.\n"; 01176 return NULL; 01177 case CLI_GENERATE: 01178 return NULL; 01179 } 01180 if (a->argc != 5) 01181 return CLI_SHOWUSAGE; 01182 buf = __ast_cli_generator(a->argv[2], a->argv[3], atoi(a->argv[4]), 0); 01183 if (buf) { 01184 ast_cli(a->fd, "%s", buf); 01185 ast_free(buf); 01186 } else 01187 ast_cli(a->fd, "NULL\n"); 01188 return CLI_SUCCESS; 01189 }
| static char* handle_commandmatchesarray | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 1085 of file cli.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_CLI_COMPLETE_EOF, ast_cli_completion_matches(), ast_free, ast_malloc, ast_realloc, buf, CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, len(), and ast_cli_entry::usage.
01086 { 01087 char *buf, *obuf; 01088 int buflen = 2048; 01089 int len = 0; 01090 char **matches; 01091 int x, matchlen; 01092 01093 switch (cmd) { 01094 case CLI_INIT: 01095 e->command = "_command matchesarray"; 01096 e->usage = 01097 "Usage: _command matchesarray \"<line>\" text \n" 01098 " This function is used internally to help with command completion and should.\n" 01099 " never be called by the user directly.\n"; 01100 return NULL; 01101 case CLI_GENERATE: 01102 return NULL; 01103 } 01104 01105 if (a->argc != 4) 01106 return CLI_SHOWUSAGE; 01107 if (!(buf = ast_malloc(buflen))) 01108 return CLI_FAILURE; 01109 buf[len] = '\0'; 01110 matches = ast_cli_completion_matches(a->argv[2], a->argv[3]); 01111 if (matches) { 01112 for (x=0; matches[x]; x++) { 01113 matchlen = strlen(matches[x]) + 1; 01114 if (len + matchlen >= buflen) { 01115 buflen += matchlen * 3; 01116 obuf = buf; 01117 if (!(buf = ast_realloc(obuf, buflen))) 01118 /* Memory allocation failure... Just free old buffer and be done */ 01119 ast_free(obuf); 01120 } 01121 if (buf) 01122 len += sprintf( buf + len, "%s ", matches[x]); 01123 ast_free(matches[x]); 01124 matches[x] = NULL; 01125 } 01126 ast_free(matches); 01127 } 01128 01129 if (buf) { 01130 ast_cli(a->fd, "%s%s",buf, AST_CLI_COMPLETE_EOF); 01131 ast_free(buf); 01132 } else 01133 ast_cli(a->fd, "NULL\n"); 01134 01135 return CLI_SUCCESS; 01136 }
| static char* handle_commandnummatches | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 1140 of file cli.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_cli_generatornummatches(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.
01141 { 01142 int matches = 0; 01143 01144 switch (cmd) { 01145 case CLI_INIT: 01146 e->command = "_command nummatches"; 01147 e->usage = 01148 "Usage: _command nummatches \"<line>\" text \n" 01149 " This function is used internally to help with command completion and should.\n" 01150 " never be called by the user directly.\n"; 01151 return NULL; 01152 case CLI_GENERATE: 01153 return NULL; 01154 } 01155 01156 if (a->argc != 4) 01157 return CLI_SHOWUSAGE; 01158 01159 matches = ast_cli_generatornummatches(a->argv[2], a->argv[3]); 01160 01161 ast_cli(a->fd, "%d", matches); 01162 01163 return CLI_SUCCESS; 01164 }
| static char* handle_core_set_debug_channel | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 1191 of file cli.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_channel_unlock, ast_channel_walk_locked(), ast_cli(), ast_complete_channels(), ast_get_channel_by_name_locked(), ast_strdup, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, DEBUGCHAN_FLAG, ast_cli_args::fd, ast_channel::fin, ast_channel::fout, global_fin, global_fout, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.
Referenced by handle_nodebugchan_deprecated().
01192 { 01193 struct ast_channel *c = NULL; 01194 int is_all, is_off = 0; 01195 01196 switch (cmd) { 01197 case CLI_INIT: 01198 e->command = "core set debug channel"; 01199 e->usage = 01200 "Usage: core set debug channel <all|channel> [off]\n" 01201 " Enables/disables debugging on all or on a specific channel.\n"; 01202 return NULL; 01203 01204 case CLI_GENERATE: 01205 /* XXX remember to handle the optional "off" */ 01206 if (a->pos != e->args) 01207 return NULL; 01208 return a->n == 0 ? ast_strdup("all") : ast_complete_channels(a->line, a->word, a->pos, a->n - 1, e->args); 01209 } 01210 /* 'core set debug channel {all|chan_id}' */ 01211 if (a->argc == e->args + 2) { 01212 if (!strcasecmp(a->argv[e->args + 1], "off")) 01213 is_off = 1; 01214 else 01215 return CLI_SHOWUSAGE; 01216 } else if (a->argc != e->args + 1) 01217 return CLI_SHOWUSAGE; 01218 01219 is_all = !strcasecmp("all", a->argv[e->args]); 01220 if (is_all) { 01221 if (is_off) { 01222 global_fin &= ~DEBUGCHAN_FLAG; 01223 global_fout &= ~DEBUGCHAN_FLAG; 01224 } else { 01225 global_fin |= DEBUGCHAN_FLAG; 01226 global_fout |= DEBUGCHAN_FLAG; 01227 } 01228 c = ast_channel_walk_locked(NULL); 01229 } else { 01230 c = ast_get_channel_by_name_locked(a->argv[e->args]); 01231 if (c == NULL) 01232 ast_cli(a->fd, "No such channel %s\n", a->argv[e->args]); 01233 } 01234 while (c) { 01235 if (!(c->fin & DEBUGCHAN_FLAG) || !(c->fout & DEBUGCHAN_FLAG)) { 01236 if (is_off) { 01237 c->fin &= ~DEBUGCHAN_FLAG; 01238 c->fout &= ~DEBUGCHAN_FLAG; 01239 } else { 01240 c->fin |= DEBUGCHAN_FLAG; 01241 c->fout |= DEBUGCHAN_FLAG; 01242 } 01243 ast_cli(a->fd, "Debugging %s on channel %s\n", is_off ? "disabled" : "enabled", c->name); 01244 } 01245 ast_channel_unlock(c); 01246 if (!is_all) 01247 break; 01248 c = ast_channel_walk_locked(c); 01249 } 01250 ast_cli(a->fd, "Debugging on new channels is %s\n", is_off ? "disabled" : "enabled"); 01251 return CLI_SUCCESS; 01252 }
| static char * handle_help | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 2008 of file cli.c.
References __ast_cli_generator(), ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), ast_join(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, find_cli(), help1(), ast_cli_args::line, ast_cli_args::n, ast_cli_entry::usage, and ast_cli_args::word.
02009 { 02010 char fullcmd[80]; 02011 struct ast_cli_entry *my_e; 02012 char *res = CLI_SUCCESS; 02013 02014 if (cmd == CLI_INIT) { 02015 e->command = "core show help"; 02016 e->usage = 02017 "Usage: core show help [topic]\n" 02018 " When called with a topic as an argument, displays usage\n" 02019 " information on the given command. If called without a\n" 02020 " topic, it provides a list of commands.\n"; 02021 return NULL; 02022 02023 } else if (cmd == CLI_GENERATE) { 02024 /* skip first 14 or 15 chars, "core show help " */ 02025 int l = strlen(a->line); 02026 02027 if (l > 15) { 02028 l = 15; 02029 } 02030 /* XXX watch out, should stop to the non-generator parts */ 02031 return __ast_cli_generator(a->line + l, a->word, a->n, 0); 02032 } 02033 if (a->argc == e->args) { 02034 return help1(a->fd, NULL, 0); 02035 } 02036 02037 AST_RWLIST_RDLOCK(&helpers); 02038 my_e = find_cli(a->argv + 3, 1); /* try exact match first */ 02039 if (!my_e) { 02040 res = help1(a->fd, a->argv + 3, 1 /* locked */); 02041 AST_RWLIST_UNLOCK(&helpers); 02042 return res; 02043 } 02044 if (my_e->usage) 02045 ast_cli(a->fd, "%s", my_e->usage); 02046 else { 02047 ast_join(fullcmd, sizeof(fullcmd), a->argv + 3); 02048 ast_cli(a->fd, "No help text available for '%s'.\n", fullcmd); 02049 } 02050 AST_RWLIST_UNLOCK(&helpers); 02051 return res; 02052 }
| static char* handle_load | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 245 of file cli.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), ast_load_resource(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_fn(), ast_cli_args::fd, ast_cli_args::n, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.
00246 { 00247 /* "module load <mod>" */ 00248 switch (cmd) { 00249 case CLI_INIT: 00250 e->command = "module load"; 00251 e->usage = 00252 "Usage: module load <module name>\n" 00253 " Loads the specified module into Asterisk.\n"; 00254 return NULL; 00255 00256 case CLI_GENERATE: 00257 if (a->pos != e->args) 00258 return NULL; 00259 return complete_fn(a->word, a->n); 00260 } 00261 if (a->argc != e->args + 1) 00262 return CLI_SHOWUSAGE; 00263 if (ast_load_resource(a->argv[e->args])) { 00264 ast_cli(a->fd, "Unable to load module %s\n", a->argv[e->args]); 00265 return CLI_FAILURE; 00266 } 00267 ast_cli(a->fd, "Loaded %s\n", a->argv[e->args]); 00268 return CLI_SUCCESS; 00269 }
| static char* handle_logger_mute | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 519 of file cli.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_console_toggle_mute(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.
00520 { 00521 switch (cmd) { 00522 case CLI_INIT: 00523 e->command = "logger mute"; 00524 e->usage = 00525 "Usage: logger mute\n" 00526 " Disables logging output to the current console, making it possible to\n" 00527 " gather information without being disturbed by scrolling lines.\n"; 00528 return NULL; 00529 case CLI_GENERATE: 00530 return NULL; 00531 } 00532 00533 if (a->argc < 2 || a->argc > 3) 00534 return CLI_SHOWUSAGE; 00535 00536 if (a->argc == 3 && !strcasecmp(a->argv[2], "silent")) 00537 ast_console_toggle_mute(a->fd, 1); 00538 else 00539 ast_console_toggle_mute(a->fd, 0); 00540 00541 return CLI_SUCCESS; 00542 }
| static char* handle_modlist | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 700 of file cli.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), ast_module_helper(), ast_mutex_lock(), ast_mutex_unlock(), ast_update_module_list(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, climodentrylock, ast_cli_entry::command, ast_cli_args::fd, ast_cli_args::line, MODLIST_FORMAT2, modlist_modentry(), ast_cli_args::n, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.
00701 { 00702 char *like; 00703 00704 switch (cmd) { 00705 case CLI_INIT: 00706 e->command = "module show [like]"; 00707 e->usage = 00708 "Usage: module show [like keyword]\n" 00709 " Shows Asterisk modules currently in use, and usage statistics.\n"; 00710 return NULL; 00711 00712 case CLI_GENERATE: 00713 if (a->pos == e->args) 00714 return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, 0); 00715 else 00716 return NULL; 00717 } 00718 /* all the above return, so we proceed with the handler. 00719 * we are guaranteed to have argc >= e->args 00720 */ 00721 if (a->argc == e->args - 1) 00722 like = ""; 00723 else if (a->argc == e->args + 1 && !strcasecmp(a->argv[e->args-1], "like") ) 00724 like = a->argv[e->args]; 00725 else 00726 return CLI_SHOWUSAGE; 00727 00728 ast_mutex_lock(&climodentrylock); 00729 climodentryfd = a->fd; /* global, protected by climodentrylock */ 00730 ast_cli(a->fd, MODLIST_FORMAT2, "Module", "Description", "Use Count"); 00731 ast_cli(a->fd,"%d modules loaded\n", ast_update_module_list(modlist_modentry, like)); 00732 climodentryfd = -1; 00733 ast_mutex_unlock(&climodentrylock); 00734 return CLI_SUCCESS; 00735 }
| static char* handle_nodebugchan_deprecated | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 1254 of file cli.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, CLI_HANDLER, CLI_INIT, CLI_SHOWUSAGE, ast_cli_entry::command, and handle_core_set_debug_channel().
01255 { 01256 char *res; 01257 if (cmd == CLI_HANDLER) { 01258 if (a->argc != e->args + 1) 01259 return CLI_SHOWUSAGE; 01260 /* pretend we have an extra "off" at the end. We can do this as the array 01261 * is NULL terminated so we overwrite that entry. 01262 */ 01263 a->argv[e->args+1] = "off"; 01264 a->argc++; 01265 } 01266 res = handle_core_set_debug_channel(e, cmd, a); 01267 if (cmd == CLI_INIT) 01268 e->command = "no debug channel"; 01269 return res; 01270 }
| static char* handle_reload | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 271 of file cli.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), ast_module_helper(), ast_module_reload(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.
00272 { 00273 int x; 00274 00275 switch (cmd) { 00276 case CLI_INIT: 00277 e->command = "module reload"; 00278 e->usage = 00279 "Usage: module reload [module ...]\n" 00280 " Reloads configuration files for all listed modules which support\n" 00281 " reloading, or for all supported modules if none are listed.\n"; 00282 return NULL; 00283 00284 case CLI_GENERATE: 00285 return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, 1); 00286 } 00287 if (a->argc == e->args) { 00288 ast_module_reload(NULL); 00289 return CLI_SUCCESS; 00290 } 00291 for (x = e->args; x < a->argc; x++) { 00292 int res = ast_module_reload(a->argv[x]); 00293 /* XXX reload has multiple error returns, including -1 on error and 2 on success */ 00294 switch (res) { 00295 case 0: 00296 ast_cli(a->fd, "No such module '%s'\n", a->argv[x]); 00297 break; 00298 case 1: 00299 ast_cli(a->fd, "Module '%s' does not support reload\n", a->argv[x]); 00300 break; 00301 } 00302 } 00303 return CLI_SUCCESS; 00304 }
| static char* handle_showcalls | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 739 of file cli.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_active_calls(), ast_cli(), ast_processed_calls(), ast_startuptime, ast_strdup, ast_tvnow(), ast_tvsub(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, ast_cli_entry::command, ESS, ast_cli_args::fd, ast_cli_args::n, option_maxcalls, ast_cli_args::pos, print_uptimestr(), RESULT_SUCCESS, and ast_cli_entry::usage.
00740 { 00741 struct timeval curtime = ast_tvnow(); 00742 int showuptime, printsec; 00743 00744 switch (cmd) { 00745 case CLI_INIT: 00746 e->command = "core show calls [uptime]"; 00747 e->usage = 00748 "Usage: core show calls [uptime] [seconds]\n" 00749 " Lists number of currently active calls and total number of calls\n" 00750 " processed through PBX since last restart. If 'uptime' is specified\n" 00751 " the system uptime is also displayed. If 'seconds' is specified in\n" 00752 " addition to 'uptime', the system uptime is displayed in seconds.\n"; 00753 return NULL; 00754 00755 case CLI_GENERATE: 00756 if (a->pos != e->args) 00757 return NULL; 00758 return a->n == 0 ? ast_strdup("seconds") : NULL; 00759 } 00760 00761 /* regular handler */ 00762 if (a->argc >= e->args && !strcasecmp(a->argv[e->args-1],"uptime")) { 00763 showuptime = 1; 00764 00765 if (a->argc == e->args+1 && !strcasecmp(a->argv[e->args],"seconds")) 00766 printsec = 1; 00767 else if (a->argc == e->args) 00768 printsec = 0; 00769 else 00770 return CLI_SHOWUSAGE; 00771 } else if (a->argc == e->args-1) { 00772 showuptime = 0; 00773 printsec = 0; 00774 } else 00775 return CLI_SHOWUSAGE; 00776 00777 if (option_maxcalls) { 00778 ast_cli(a->fd, "%d of %d max active call%s (%5.2f%% of capacity)\n", 00779 ast_active_calls(), option_maxcalls, ESS(ast_active_calls()), 00780 ((double)ast_active_calls() / (double)option_maxcalls) * 100.0); 00781 } else { 00782 ast_cli(a->fd, "%d active call%s\n", ast_active_calls(), ESS(ast_active_calls())); 00783 } 00784 00785 ast_cli(a->fd, "%d call%s processed\n", ast_processed_calls(), ESS(ast_processed_calls())); 00786 00787 if (ast_startuptime.tv_sec && showuptime) { 00788 print_uptimestr(a->fd, ast_tvsub(curtime, ast_startuptime), "System uptime", printsec); 00789 } 00790 00791 return RESULT_SUCCESS; 00792 }
| static char* handle_showchan | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 1272 of file cli.c.
References ast_channel::_bridge, ast_channel::_state, ast_channel::appl, ast_cli_args::argc, ast_cli_args::argv, ast_bridged_channel(), ast_cdr_serialize_variables(), ast_channel_unlock, ast_cli(), ast_complete_channels(), AST_FLAG_BLOCKING, ast_get_channel_by_name_locked(), ast_getformatname_multiple(), ast_state2str(), ast_str_buffer(), ast_str_thread_get(), ast_test_flag, ast_tvnow(), ast_channel::blockproc, ast_channel::callgroup, ast_channel::cdr, ast_channel::cid, ast_callerid::cid_dnid, ast_callerid::cid_name, ast_callerid::cid_num, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_channel::context, ast_channel::data, DEBUGCHAN_FLAG, ast_channel::exten, ast_cli_args::fd, ast_channel::fds, ast_channel::fin, ast_channel::fout, ast_cli_args::line, ast_cli_args::n, name, ast_channel::nativeformats, pbx_builtin_serialize_variables(), ast_channel::pickupgroup, ast_cli_args::pos, ast_channel::priority, ast_channel::readformat, ast_channel::readtrans, ast_channel::rings, S_OR, sec, ast_cdr::start, ast_channel::tech, ast_channel_tech::type, ast_cli_entry::usage, ast_channel::whentohangup, ast_cli_args::word, ast_channel::writeformat, and ast_channel::writetrans.
01273 { 01274 struct ast_channel *c=NULL; 01275 struct timeval now; 01276 struct ast_str *out = ast_str_thread_get(&ast_str_thread_global_buf, 16); 01277 char cdrtime[256]; 01278 char nf[256], wf[256], rf[256]; 01279 long elapsed_seconds=0; 01280 int hour=0, min=0, sec=0; 01281 #ifdef CHANNEL_TRACE 01282 int trace_enabled; 01283 #endif 01284 01285 switch (cmd) { 01286 case CLI_INIT: 01287 e->command = "core show channel"; 01288 e->usage = 01289 "Usage: core show channel <channel>\n" 01290 " Shows lots of information about the specified channel.\n"; 01291 return NULL; 01292 case CLI_GENERATE: 01293 return ast_complete_channels(a->line, a->word, a->pos, a->n, 3); 01294 } 01295 01296 if (a->argc != 4) 01297 return CLI_SHOWUSAGE; 01298 now = ast_tvnow(); 01299 c = ast_get_channel_by_name_locked(a->argv[3]); 01300 if (!c) { 01301 ast_cli(a->fd, "%s is not a known channel\n", a->argv[3]); 01302 return CLI_SUCCESS; 01303 } 01304 if (c->cdr) { 01305 elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec; 01306 hour = elapsed_seconds / 3600; 01307 min = (elapsed_seconds % 3600) / 60; 01308 sec = elapsed_seconds % 60; 01309 snprintf(cdrtime, sizeof(cdrtime), "%dh%dm%ds", hour, min, sec); 01310 } else 01311 strcpy(cdrtime, "N/A"); 01312 ast_cli(a->fd, 01313 " -- General --\n" 01314 " Name: %s\n" 01315 " Type: %s\n" 01316 " UniqueID: %s\n" 01317 " Caller ID: %s\n" 01318 " Caller ID Name: %s\n" 01319 " DNID Digits: %s\n" 01320 " Language: %s\n" 01321 " State: %s (%d)\n" 01322 " Rings: %d\n" 01323 " NativeFormats: %s\n" 01324 " WriteFormat: %s\n" 01325 " ReadFormat: %s\n" 01326 " WriteTranscode: %s\n" 01327 " ReadTranscode: %s\n" 01328 "1st File Descriptor: %d\n" 01329 " Frames in: %d%s\n" 01330 " Frames out: %d%s\n" 01331 " Time to Hangup: %ld\n" 01332 " Elapsed Time: %s\n" 01333 " Direct Bridge: %s\n" 01334 "Indirect Bridge: %s\n" 01335 " -- PBX --\n" 01336 " Context: %s\n" 01337 " Extension: %s\n" 01338 " Priority: %d\n" 01339 " Call Group: %llu\n" 01340 " Pickup Group: %llu\n" 01341 " Application: %s\n" 01342 " Data: %s\n" 01343 " Blocking in: %s\n", 01344 c->name, c->tech->type, c->uniqueid, 01345 S_OR(c->cid.cid_num, "(N/A)"), 01346 S_OR(c->cid.cid_name, "(N/A)"), 01347 S_OR(c->cid.cid_dnid, "(N/A)"), 01348 c->language, 01349 ast_state2str(c->_state), c->_state, c->rings, 01350 ast_getformatname_multiple(nf, sizeof(nf), c->nativeformats), 01351 ast_getformatname_multiple(wf, sizeof(wf), c->writeformat), 01352 ast_getformatname_multiple(rf, sizeof(rf), c->readformat), 01353 c->writetrans ? "Yes" : "No", 01354 c->readtrans ? "Yes" : "No", 01355 c->fds[0], 01356 c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "", 01357 c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "", 01358 (long)c->whentohangup.tv_sec, 01359 cdrtime, c->_bridge ? c->_bridge->name : "<none>", ast_bridged_channel(c) ? ast_bridged_channel(c)->name : "<none>", 01360 c->context, c->exten, c->priority, c->callgroup, c->pickupgroup, ( c->appl ? c->appl : "(N/A)" ), 01361 ( c-> data ? S_OR(c->data, "(Empty)") : "(None)"), 01362 (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)")); 01363 01364 if (pbx_builtin_serialize_variables(c, &out)) 01365 ast_cli(a->fd," Variables:\n%s\n", ast_str_buffer(out)); 01366 if (c->cdr && ast_cdr_serialize_variables(c->cdr, &out, '=', '\n', 1)) 01367 ast_cli(a->fd," CDR Variables:\n%s\n", ast_str_buffer(out)); 01368 #ifdef CHANNEL_TRACE 01369 trace_enabled = ast_channel_trace_is_enabled(c); 01370 ast_cli(a->fd, " Context Trace: %s\n", trace_enabled ? "Enabled" : "Disabled"); 01371 if (trace_enabled && ast_channel_trace_serialize(c, &out)) 01372 ast_cli(a->fd, " Trace:\n%s\n", ast_str_buffer(out)); 01373 #endif 01374 ast_channel_unlock(c); 01375 return CLI_SUCCESS; 01376 }
| static char* handle_showuptime | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 669 of file cli.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_lastreloadtime, ast_startuptime, ast_tvnow(), ast_tvsub(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, print_uptimestr(), and ast_cli_entry::usage.
00670 { 00671 struct timeval curtime = ast_tvnow(); 00672 int printsec; 00673 00674 switch (cmd) { 00675 case CLI_INIT: 00676 e->command = "core show uptime [seconds]"; 00677 e->usage = 00678 "Usage: core show uptime [seconds]\n" 00679 " Shows Asterisk uptime information.\n" 00680 " The seconds word returns the uptime in seconds only.\n"; 00681 return NULL; 00682 00683 case CLI_GENERATE: 00684 return NULL; 00685 } 00686 /* regular handler */ 00687 if (a->argc == e->args && !strcasecmp(a->argv[e->args-1],"seconds")) 00688 printsec = 1; 00689 else if (a->argc == e->args-1) 00690 printsec = 0; 00691 else 00692 return CLI_SHOWUSAGE; 00693 if (ast_startuptime.tv_sec) 00694 print_uptimestr(a->fd, ast_tvsub(curtime, ast_startuptime), "System uptime", printsec); 00695 if (ast_lastreloadtime.tv_sec) 00696 print_uptimestr(a->fd, ast_tvsub(curtime, ast_lastreloadtime), "Last reload", printsec); 00697 return CLI_SUCCESS; 00698 }
| static char* handle_softhangup | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 916 of file cli.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_channel_unlock, ast_cli(), ast_complete_channels(), ast_get_channel_by_name_locked(), ast_softhangup(), AST_SOFTHANGUP_EXPLICIT, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.
00917 { 00918 struct ast_channel *c=NULL; 00919 00920 switch (cmd) { 00921 case CLI_INIT: 00922 e->command = "channel request hangup"; 00923 e->usage = 00924 "Usage: channel request hangup <channel>\n" 00925 " Request that a channel be hung up. The hangup takes effect\n" 00926 " the next time the driver reads or writes from the channel\n"; 00927 return NULL; 00928 case CLI_GENERATE: 00929 return ast_complete_channels(a->line, a->word, a->pos, a->n, e->args); 00930 } 00931 if (a->argc != 4) 00932 return CLI_SHOWUSAGE; 00933 c = ast_get_channel_by_name_locked(a->argv[3]); 00934 if (c) { 00935 ast_cli(a->fd, "Requested Hangup on channel '%s'\n", c->name); 00936 ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT); 00937 ast_channel_unlock(c); 00938 } else 00939 ast_cli(a->fd, "%s is not a known channel\n", a->argv[3]); 00940 return CLI_SUCCESS; 00941 }
| static char* handle_unload | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 544 of file cli.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), AST_FORCE_FIRM, AST_FORCE_HARD, AST_FORCE_SOFT, ast_module_helper(), ast_unload_resource(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, s, ast_cli_entry::usage, and ast_cli_args::word.
00545 { 00546 /* "module unload mod_1 [mod_2 .. mod_N]" */ 00547 int x; 00548 int force = AST_FORCE_SOFT; 00549 char *s; 00550 00551 switch (cmd) { 00552 case CLI_INIT: 00553 e->command = "module unload"; 00554 e->usage = 00555 "Usage: module unload [-f|-h] <module_1> [<module_2> ... ]\n" 00556 " Unloads the specified module from Asterisk. The -f\n" 00557 " option causes the module to be unloaded even if it is\n" 00558 " in use (may cause a crash) and the -h module causes the\n" 00559 " module to be unloaded even if the module says it cannot, \n" 00560 " which almost always will cause a crash.\n"; 00561 return NULL; 00562 00563 case CLI_GENERATE: 00564 return ast_module_helper(a->line, a->word, a->pos, a->n, a->pos, 0); 00565 } 00566 if (a->argc < e->args + 1) 00567 return CLI_SHOWUSAGE; 00568 x = e->args; /* first argument */ 00569 s = a->argv[x]; 00570 if (s[0] == '-') { 00571 if (s[1] == 'f') 00572 force = AST_FORCE_FIRM; 00573 else if (s[1] == 'h') 00574 force = AST_FORCE_HARD; 00575 else 00576 return CLI_SHOWUSAGE; 00577 if (a->argc < e->args + 2) /* need at least one module name */ 00578 return CLI_SHOWUSAGE; 00579 x++; /* skip this argument */ 00580 } 00581 00582 for (; x < a->argc; x++) { 00583 if (ast_unload_resource(a->argv[x], force)) { 00584 ast_cli(a->fd, "Unable to unload resource %s\n", a->argv[x]); 00585 return CLI_FAILURE; 00586 } 00587 ast_cli(a->fd, "Unloaded %s\n", a->argv[x]); 00588 } 00589 00590 return CLI_SUCCESS; 00591 }
| static char* handle_verbose | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 363 of file cli.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_calloc, ast_clear_flag, ast_cli(), ast_complete_source_filename(), ast_free, AST_OPT_FLAG_DEBUG_FILE, AST_OPT_FLAG_VERBOSE_FILE, ast_options, AST_RWLIST_EMPTY, AST_RWLIST_INSERT_TAIL, AST_RWLIST_REMOVE, AST_RWLIST_REMOVE_HEAD, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_set_flag, ast_strdup, ast_strlen_zero(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_number(), debug, ast_cli_args::fd, ast_debug_file::filename, find_debug_file(), ast_debug_file::level, ast_cli_args::n, option_debug, option_verbose, ast_cli_args::pos, S_OR, and ast_cli_entry::usage.
00364 { 00365 int oldval; 00366 int newlevel; 00367 int atleast = 0; 00368 int fd = a->fd; 00369 int argc = a->argc; 00370 char **argv = a->argv; 00371 char *argv3 = a->argv ? S_OR(a->argv[3], "") : ""; 00372 int *dst; 00373 char *what; 00374 struct debug_file_list *dfl; 00375 struct ast_debug_file *adf; 00376 char *fn; 00377 00378 switch (cmd) { 00379 case CLI_INIT: 00380 e->command = "core set {debug|verbose}"; 00381 e->usage = 00382 #if !defined(LOW_MEMORY) 00383 "Usage: core set {debug|verbose} [atleast] <level> [filename]\n" 00384 #else 00385 "Usage: core set {debug|verbose} [atleast] <level>\n" 00386 #endif 00387 " core set {debug|verbose} off\n" 00388 #if !defined(LOW_MEMORY) 00389 " Sets level of debug or verbose messages to be displayed or \n" 00390 " sets a filename to display debug messages from.\n" 00391 #else 00392 " Sets level of debug or verbose messages to be displayed.\n" 00393 #endif 00394 " 0 or off means no messages should be displayed.\n" 00395 " Equivalent to -d[d[...]] or -v[v[v...]] on startup\n"; 00396 return NULL; 00397 00398 case CLI_GENERATE: 00399 if (a->pos == 3 || (a->pos == 4 && !strcasecmp(a->argv[3], "atleast"))) { 00400 char *pos = a->pos == 3 ? argv3 : S_OR(a->argv[4], ""); 00401 int numbermatch = (ast_strlen_zero(pos) || strchr("123456789", pos[0])) ? 0 : 21; 00402 if (a->n < 21 && numbermatch == 0) { 00403 return complete_number(pos, 0, 0x7fffffff, a->n); 00404 } else if (pos[0] == '0') { 00405 if (a->n == 0) { 00406 return ast_strdup("0"); 00407 } else { 00408 return NULL; 00409 } 00410 } else if (a->n == (21 - numbermatch)) { 00411 if (a->pos == 3 && !strncasecmp(argv3, "off", strlen(argv3))) { 00412 return ast_strdup("off"); 00413 } else if (a->pos == 3 && !strncasecmp(argv3, "atleast", strlen(argv3))) { 00414 return ast_strdup("atleast"); 00415 } 00416 } else if (a->n == (22 - numbermatch) && a->pos == 3 && ast_strlen_zero(argv3)) { 00417 return ast_strdup("atleast"); 00418 } 00419 #if !defined(LOW_MEMORY) 00420 } else if (a->pos == 4 || (a->pos == 5 && !strcasecmp(argv3, "atleast"))) { 00421 return ast_complete_source_filename(a->pos == 4 ? S_OR(a->argv[4], "") : S_OR(a->argv[5], ""), a->n); 00422 #endif 00423 } 00424 return NULL; 00425 } 00426 /* all the above return, so we proceed with the handler. 00427 * we are guaranteed to be called with argc >= e->args; 00428 */ 00429 00430 if (argc <= e->args) 00431 return CLI_SHOWUSAGE; 00432 if (!strcasecmp(argv[e->args - 1], "debug")) { 00433 dst = &option_debug; 00434 oldval = option_debug; 00435 what = "Core debug"; 00436 } else { 00437 dst = &option_verbose; 00438 oldval = option_verbose; 00439 what = "Verbosity"; 00440 } 00441 if (argc == e->args + 1 && !strcasecmp(argv[e->args], "off")) { 00442 unsigned int debug = (*what == 'C'); 00443 newlevel = 0; 00444 00445 dfl = debug ? &debug_files : &verbose_files; 00446 00447 AST_RWLIST_WRLOCK(dfl); 00448 while ((adf = AST_RWLIST_REMOVE_HEAD(dfl, entry))) 00449 ast_free(adf); 00450 ast_clear_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE); 00451 AST_RWLIST_UNLOCK(dfl); 00452 00453 goto done; 00454 } 00455 if (!strcasecmp(argv[e->args], "atleast")) 00456 atleast = 1; 00457 if (argc != e->args + atleast + 1 && argc != e->args + atleast + 2) 00458 return CLI_SHOWUSAGE; 00459 if (sscanf(argv[e->args + atleast], "%30d", &newlevel) != 1) 00460 return CLI_SHOWUSAGE; 00461 if (argc == e->args + atleast + 2) { 00462 unsigned int debug = (*what == 'C'); 00463 dfl = debug ? &debug_files : &verbose_files; 00464 00465 fn = argv[e->args + atleast + 1]; 00466 00467 AST_RWLIST_WRLOCK(dfl); 00468 00469 if ((adf = find_debug_file(fn, debug)) && !newlevel) { 00470 AST_RWLIST_REMOVE(dfl, adf, entry); 00471 if (AST_RWLIST_EMPTY(dfl)) 00472 ast_clear_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE); 00473 AST_RWLIST_UNLOCK(dfl); 00474 ast_cli(fd, "%s was %d and has been set to 0 for '%s'\n", what, adf->level, fn); 00475 ast_free(adf); 00476 return CLI_SUCCESS; 00477 } 00478 00479 if (adf) { 00480 if ((atleast && newlevel < adf->level) || adf->level == newlevel) { 00481 ast_cli(fd, "%s is %d for '%s'\n", what, adf->level, fn); 00482 AST_RWLIST_UNLOCK(dfl); 00483 return CLI_SUCCESS; 00484 } 00485 } else if (!(adf = ast_calloc(1, sizeof(*adf) + strlen(fn) + 1))) { 00486 AST_RWLIST_UNLOCK(dfl); 00487 return CLI_FAILURE; 00488 } 00489 00490 oldval = adf->level; 00491 adf->level = newlevel; 00492 strcpy(adf->filename, fn); 00493 00494 ast_set_flag(&ast_options, debug ? AST_OPT_FLAG_DEBUG_FILE : AST_OPT_FLAG_VERBOSE_FILE); 00495 00496 AST_RWLIST_INSERT_TAIL(dfl, adf, entry); 00497 AST_RWLIST_UNLOCK(dfl); 00498 00499 ast_cli(fd, "%s was %d and has been set to %d for '%s'\n", what, oldval, adf->level, adf->filename); 00500 00501 return CLI_SUCCESS; 00502 } 00503 00504 done: 00505 if (!atleast || newlevel > *dst) 00506 *dst = newlevel; 00507 if (oldval > 0 && *dst == 0) 00508 ast_cli(fd, "%s is now OFF\n", what); 00509 else if (*dst > 0) { 00510 if (oldval == *dst) 00511 ast_cli(fd, "%s is at least %d\n", what, *dst); 00512 else 00513 ast_cli(fd, "%s was %d and is now %d\n", what, oldval, *dst); 00514 } 00515 00516 return CLI_SUCCESS; 00517 }
| static char* help1 | ( | int | fd, | |
| char * | match[], | |||
| int | locked | |||
| ) | [static] |
helper for final part of handle_help if locked = 1, assume the list is already locked
Definition at line 1979 of file cli.c.
References ast_cli_entry::_full_cmd, ast_cli(), ast_join(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, cli_next(), CLI_SUCCESS, len(), S_OR, and ast_cli_entry::summary.
Referenced by handle_help().
01980 { 01981 char matchstr[80] = ""; 01982 struct ast_cli_entry *e = NULL; 01983 int len = 0; 01984 int found = 0; 01985 01986 if (match) { 01987 ast_join(matchstr, sizeof(matchstr), match); 01988 len = strlen(matchstr); 01989 } 01990 if (!locked) 01991 AST_RWLIST_RDLOCK(&helpers); 01992 while ( (e = cli_next(e)) ) { 01993 /* Hide commands that start with '_' */ 01994 if (e->_full_cmd[0] == '_') 01995 continue; 01996 if (match && strncasecmp(matchstr, e->_full_cmd, len)) 01997 continue; 01998 ast_cli(fd, "%30.30s %s\n", e->_full_cmd, S_OR(e->summary, "<no description available>")); 01999 found++; 02000 } 02001 if (!locked) 02002 AST_RWLIST_UNLOCK(&helpers); 02003 if (!found && matchstr[0]) 02004 ast_cli(fd, "No such command '%s'.\n", matchstr); 02005 return CLI_SUCCESS; 02006 }
| static char* is_prefix | ( | const char * | word, | |
| const char * | token, | |||
| int | pos, | |||
| int * | actual | |||
| ) | [static] |
if word is a valid prefix for token, returns the pos-th match as a malloced string, or NULL otherwise. Always tell in *actual how many matches we got.
Definition at line 1750 of file cli.c.
References ast_strdup, ast_strdupa, ast_strlen_zero(), s, and strsep().
Referenced by __ast_cli_generator().
01752 { 01753 int lw; 01754 char *s, *t1; 01755 01756 *actual = 0; 01757 if (ast_strlen_zero(token)) 01758 return NULL; 01759 if (ast_strlen_zero(word)) 01760 word = ""; /* dummy */ 01761 lw = strlen(word); 01762 if (strcspn(word, cli_rsvd) != lw) 01763 return NULL; /* no match if word has reserved chars */ 01764 if (strchr(cli_rsvd, token[0]) == NULL) { /* regular match */ 01765 if (strncasecmp(token, word, lw)) /* no match */ 01766 return NULL; 01767 *actual = 1; 01768 return (pos != 0) ? NULL : ast_strdup(token); 01769 } 01770 /* now handle regexp match */ 01771 01772 /* Wildcard always matches, so we never do is_prefix on them */ 01773 01774 t1 = ast_strdupa(token + 1); /* copy, skipping first char */ 01775 while (pos >= 0 && (s = strsep(&t1, cli_rsvd)) && *s) { 01776 if (*s == '%') /* wildcard */ 01777 continue; 01778 if (strncasecmp(s, word, lw)) /* no match */ 01779 continue; 01780 (*actual)++; 01781 if (pos-- == 0) 01782 return ast_strdup(s); 01783 } 01784 return NULL; 01785 }
| static int modlist_modentry | ( | const char * | module, | |
| const char * | description, | |||
| int | usecnt, | |||
| const char * | like | |||
| ) | [static] |
Definition at line 599 of file cli.c.
References ast_cli(), MODLIST_FORMAT, and strcasestr().
Referenced by handle_modlist().
00600 { 00601 /* Comparing the like with the module */ 00602 if (strcasestr(module, like) ) { 00603 ast_cli(climodentryfd, MODLIST_FORMAT, module, description, usecnt); 00604 return 1; 00605 } 00606 return 0; 00607 }
| static int more_words | ( | char *const * | dst | ) | [static] |
returns true if there are more words to match
Definition at line 2185 of file cli.c.
Referenced by __ast_cli_generator().
| static char* parse_args | ( | const char * | s, | |
| int * | argc, | |||
| char * | argv[], | |||
| int | max, | |||
| int * | trailingwhitespace | |||
| ) | [static] |
Definition at line 2054 of file cli.c.
References ast_log(), ast_strdup, dummy(), and LOG_WARNING.
Referenced by __ast_cli_generator(), and ast_cli_command_full().
02055 { 02056 char *duplicate, *cur; 02057 int x = 0; 02058 int quoted = 0; 02059 int escaped = 0; 02060 int whitespace = 1; 02061 int dummy = 0; 02062 02063 if (trailingwhitespace == NULL) 02064 trailingwhitespace = &dummy; 02065 *trailingwhitespace = 0; 02066 if (s == NULL) /* invalid, though! */ 02067 return NULL; 02068 /* make a copy to store the parsed string */ 02069 if (!(duplicate = ast_strdup(s))) 02070 return NULL; 02071 02072 cur = duplicate; 02073 /* scan the original string copying into cur when needed */ 02074 for (; *s ; s++) { 02075 if (x >= max - 1) { 02076 ast_log(LOG_WARNING, "Too many arguments, truncating at %s\n", s); 02077 break; 02078 } 02079 if (*s == '"' && !escaped) { 02080 quoted = !quoted; 02081 if (quoted && whitespace) { 02082 /* start a quoted string from previous whitespace: new argument */ 02083 argv[x++] = cur; 02084 whitespace = 0; 02085 } 02086 } else if ((*s == ' ' || *s == '\t') && !(quoted || escaped)) { 02087 /* If we are not already in whitespace, and not in a quoted string or 02088 processing an escape sequence, and just entered whitespace, then 02089 finalize the previous argument and remember that we are in whitespace 02090 */ 02091 if (!whitespace) { 02092 *cur++ = '\0'; 02093 whitespace = 1; 02094 } 02095 } else if (*s == '\\' && !escaped) { 02096 escaped = 1; 02097 } else { 02098 if (whitespace) { 02099 /* we leave whitespace, and are not quoted. So it's a new argument */ 02100 argv[x++] = cur; 02101 whitespace = 0; 02102 } 02103 *cur++ = *s; 02104 escaped = 0; 02105 } 02106 } 02107 /* Null terminate */ 02108 *cur++ = '\0'; 02109 /* XXX put a NULL in the last argument, because some functions that take 02110 * the array may want a null-terminated array. 02111 * argc still reflects the number of non-NULL entries. 02112 */ 02113 argv[x] = NULL; 02114 *argc = x; 02115 *trailingwhitespace = whitespace; 02116 return duplicate; 02117 }
| static void print_uptimestr | ( | int | fd, | |
| struct timeval | timeval, | |||
| const char * | prefix, | |||
| int | printsec | |||
| ) | [static] |
Definition at line 609 of file cli.c.
References ast_cli(), ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_str_strlen(), DAY, ESS, HOUR, MINUTE, NEEDCOMMA, WEEK, and YEAR.
Referenced by handle_showcalls(), and handle_showuptime().
00610 { 00611 int x; /* the main part - years, weeks, etc. */ 00612 struct ast_str *out; 00613 00614 #define SECOND (1) 00615 #define MINUTE (SECOND*60) 00616 #define HOUR (MINUTE*60) 00617 #define DAY (HOUR*24) 00618 #define WEEK (DAY*7) 00619 #define YEAR (DAY*365) 00620 #define NEEDCOMMA(x) ((x)? ",": "") /* define if we need a comma */ 00621 if (timeval.tv_sec < 0) /* invalid, nothing to show */ 00622 return; 00623 00624 if (printsec) { /* plain seconds output */ 00625 ast_cli(fd, "%s: %lu\n", prefix, (u_long)timeval.tv_sec); 00626 return; 00627 } 00628 out = ast_str_alloca(256); 00629 if (timeval.tv_sec > YEAR) { 00630 x = (timeval.tv_sec / YEAR); 00631 timeval.tv_sec -= (x * YEAR); 00632 ast_str_append(&out, 0, "%d year%s%s ", x, ESS(x),NEEDCOMMA(timeval.tv_sec)); 00633 } 00634 if (timeval.tv_sec > WEEK) { 00635 x = (timeval.tv_sec / WEEK); 00636 timeval.tv_sec -= (x * WEEK); 00637 ast_str_append(&out, 0, "%d week%s%s ", x, ESS(x),NEEDCOMMA(timeval.tv_sec)); 00638 } 00639 if (timeval.tv_sec > DAY) { 00640 x = (timeval.tv_sec / DAY); 00641 timeval.tv_sec -= (x * DAY); 00642 ast_str_append(&out, 0, "%d day%s%s ", x, ESS(x),NEEDCOMMA(timeval.tv_sec)); 00643 } 00644 if (timeval.tv_sec > HOUR) { 00645 x = (timeval.tv_sec / HOUR); 00646 timeval.tv_sec -= (x * HOUR); 00647 ast_str_append(&out, 0, "%d hour%s%s ", x, ESS(x),NEEDCOMMA(timeval.tv_sec)); 00648 } 00649 if (timeval.tv_sec > MINUTE) { 00650 x = (timeval.tv_sec / MINUTE); 00651 timeval.tv_sec -= (x * MINUTE); 00652 ast_str_append(&out, 0, "%d minute%s%s ", x, ESS(x),NEEDCOMMA(timeval.tv_sec)); 00653 } 00654 x = timeval.tv_sec; 00655 if (x > 0 || ast_str_strlen(out) == 0) /* if there is nothing, print 0 seconds */ 00656 ast_str_append(&out, 0, "%d second%s ", x, ESS(x)); 00657 ast_cli(fd, "%s: %s\n", prefix, ast_str_buffer(out)); 00658 }
| static int set_full_cmd | ( | struct ast_cli_entry * | e | ) | [static] |
initialize the _full_cmd string and related parameters, return 0 on success, -1 on error.
Definition at line 1547 of file cli.c.
References ast_cli_entry::_full_cmd, ast_cli_entry::args, ast_join(), ast_log(), ast_strdup, buf, ast_cli_entry::cmda, ast_cli_entry::cmdlen, and LOG_WARNING.
Referenced by __ast_cli_register().
01548 { 01549 int i; 01550 char buf[80]; 01551 01552 ast_join(buf, sizeof(buf), e->cmda); 01553 e->_full_cmd = ast_strdup(buf); 01554 if (!e->_full_cmd) { 01555 ast_log(LOG_WARNING, "-- cannot allocate <%s>\n", buf); 01556 return -1; 01557 } 01558 e->cmdlen = strcspn(e->_full_cmd, cli_rsvd); 01559 for (i = 0; e->cmda[i]; i++) 01560 ; 01561 e->args = i; 01562 return 0; 01563 }
| static int word_match | ( | const char * | cmd, | |
| const char * | cli_word | |||
| ) | [static] |
match a word in the CLI entry. returns -1 on mismatch, 0 on match of an optional word, 1 on match of a full word.
The pattern can be any_word match for equal [foo|bar|baz] optionally, one of these words {foo|bar|baz} exactly, one of these words % any word
Definition at line 1721 of file cli.c.
References ast_strlen_zero(), and strcasestr().
Referenced by __ast_cli_generator(), and find_cli().
01722 { 01723 int l; 01724 char *pos; 01725 01726 if (ast_strlen_zero(cmd) || ast_strlen_zero(cli_word)) 01727 return -1; 01728 if (!strchr(cli_rsvd, cli_word[0])) /* normal match */ 01729 return (strcasecmp(cmd, cli_word) == 0) ? 1 : -1; 01730 /* regexp match, takes [foo|bar] or {foo|bar} */ 01731 l = strlen(cmd); 01732 /* wildcard match - will extend in the future */ 01733 if (l > 0 && cli_word[0] == '%') { 01734 return 1; /* wildcard */ 01735 } 01736 pos = strcasestr(cli_word, cmd); 01737 if (pos == NULL) /* not found, say ok if optional */ 01738 return cli_word[0] == '[' ? 0 : -1; 01739 if (pos == cli_word) /* no valid match at the beginning */ 01740 return -1; 01741 if (strchr(cli_rsvd, pos[-1]) && strchr(cli_rsvd, pos[l])) 01742 return 1; /* valid match */ 01743 return -1; /* not found */ 01744 }
struct ast_threadstorage ast_cli_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_ast_cli_buf , .custom_init = NULL , } [static] |
struct ast_cli_entry cli_cli[] [static] |
int cli_default_perm = 1 [static] |
const char cli_rsvd[] = "[]{}|*%" [static] |
int climodentryfd = -1 [static] |
ast_mutex_t climodentrylock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) [static] |
Definition at line 596 of file cli.c.
Referenced by handle_modlist().
struct debug_file_list debug_files [static] |
const char perms_config[] = "cli_permissions.conf" [static] |
CLI permissions config file.
Definition at line 70 of file cli.c.
Referenced by ast_cli_perms_init().
ast_mutex_t permsconfiglock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) [static] |
struct debug_file_list verbose_files [static] |
1.6.1