#include "asterisk.h"
#include <unistd.h>
#include <stdlib.h>
#include <sys/signal.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <ctype.h>
#include <regex.h>
#include "asterisk/logger.h"
#include "asterisk/options.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 "editline/readline/readline.h"
#include "asterisk/threadstorage.h"
Go to the source code of this file.
Data Structures | |
struct | cli_iterator |
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\n" |
#define | DAY (HOUR*24) |
#define | ESS(x) ((x == 1) ? "" : "s") |
#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) |
void | ast_builtins_init (void) |
initialize the _full_cmd string in * each of the builtins. | |
void | ast_cli (int fd, char *fmt,...) |
int | ast_cli_command (int fd, const char *s) |
Interprets a command Interpret a command s, sending output to fd Returns 0 on succes, -1 on failure. | |
int | ast_cli_command_multiple (int fd, size_t size, const char *s) |
Executes multiple CLI commands Interpret strings separated by '' and execute each one, sending output to fd. | |
char * | ast_cli_complete (const char *word, char *const choices[], int state) |
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 ** | 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 Returns 0 on success, -1 on failure. | |
int | ast_cli_generatornummatches (const char *text, const char *word) |
Return the number of unique matches for the generator. | |
int | ast_cli_register (struct ast_cli_entry *e) |
Registers a command or an array of commands. | |
void | 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. | |
void | 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. | |
static | AST_LIST_HEAD_STATIC (helpers, ast_cli_entry) |
AST_MUTEX_DEFINE_STATIC (climodentrylock) | |
AST_THREADSTORAGE (ast_cli_buf, ast_cli_buf_init) | |
static struct ast_cli_entry * | cli_next (struct cli_iterator *i) |
static char * | complete_ch_3 (const char *line, const char *word, int pos, int state) |
static char * | complete_ch_4 (const char *line, const char *word, int pos, int state) |
static char * | complete_ch_5 (const char *line, const char *word, int pos, int state) |
static char * | complete_fn_2 (const char *line, const char *word, int pos, int state) |
static char * | complete_fn_3 (const char *line, const char *word, int pos, int state) |
static char * | complete_help (const char *text, const char *word, int pos, int state) |
static char * | complete_mod_2 (const char *line, const char *word, int pos, int state) |
static char * | complete_mod_3 (const char *line, const char *word, int pos, int state) |
static char * | complete_mod_3_nr (const char *line, const char *word, int pos, int state) |
static char * | complete_mod_4 (const char *line, const char *word, int pos, int state) |
static char * | complete_show_channels (const char *line, const char *word, int pos, int state) |
static char * | complete_show_channels_deprecated (const char *line, const char *word, int pos, int state) |
static char * | find_best (char *argv[]) |
static struct ast_cli_entry * | find_cli (char *const cmds[], int match_type) |
locate a cli command in the 'helpers' list (which must be locked). exact has 3 values: 0 returns if the search key is equal or longer than the entry. -1 true if the mismatch is on the last word XXX not true! 1 true only on complete, exact match. | |
static int | group_show_channels (int fd, int argc, char *argv[]) |
static int | handle_chanlist (int fd, int argc, char *argv[]) |
static int | handle_chanlist_deprecated (int fd, int argc, char *argv[]) |
static int | handle_commandcomplete (int fd, int argc, char *argv[]) |
static int | handle_commandmatchesarray (int fd, int argc, char *argv[]) |
static int | handle_commandnummatches (int fd, int argc, char *argv[]) |
static int | handle_core_set_debug_channel (int fd, int argc, char *argv[]) |
static int | handle_debugchan_deprecated (int fd, int argc, char *argv[]) |
static int | handle_debuglevel_deprecated (int fd, int argc, char *argv[]) |
static int | handle_help (int fd, int argc, char *argv[]) |
static int | handle_load (int fd, int argc, char *argv[]) |
static int | handle_load_deprecated (int fd, int argc, char *argv[]) |
static int | handle_logger_mute (int fd, int argc, char *argv[]) |
static int | handle_modlist (int fd, int argc, char *argv[]) |
static int | handle_nodebug (int fd, int argc, char *argv[]) |
static int | handle_nodebugchan_deprecated (int fd, int argc, char *argv[]) |
static int | handle_reload (int fd, int argc, char *argv[]) |
static int | handle_reload_deprecated (int fd, int argc, char *argv[]) |
static int | handle_set_debug (int fd, int argc, char *argv[]) |
static int | handle_set_debug_deprecated (int fd, int argc, char *argv[]) |
static int | handle_set_verbose_deprecated (int fd, int argc, char *argv[]) |
static int | handle_showchan (int fd, int argc, char *argv[]) |
static int | handle_showchan_deprecated (int fd, int argc, char *argv[]) |
static int | handle_showuptime (int fd, int argc, char *argv[]) |
static int | handle_showuptime_deprecated (int fd, int argc, char *argv[]) |
static int | handle_softhangup (int fd, int argc, char *argv[]) |
static int | handle_unload (int fd, int argc, char *argv[]) |
static int | handle_unload_deprecated (int fd, int argc, char *argv[]) |
static int | handle_verbose (int fd, int argc, char *argv[]) |
static int | help1 (int fd, char *match[], int locked) |
helper for help_workhorse and final part of handle_help if locked = 0 it's just help_workhorse, otherwise assume the list is already locked. | |
static int | help_workhorse (int fd, char *match[]) |
static int | modlist_modentry (const char *module, const char *description, int usecnt, const char *like) |
static char * | parse_args (const char *s, int *argc, char *argv[], int max, int *trailingwhitespace) |
static void | print_uptimestr (int fd, time_t timeval, const char *prefix, int printsec) |
Variables | |
static struct ast_cli_entry | builtins [] |
static char | chanlist_help [] |
static struct ast_cli_entry | cli_cli [] |
static struct ast_cli_entry | cli_debug_channel_deprecated |
static struct ast_cli_entry | cli_debug_level_deprecated |
static struct ast_cli_entry | cli_module_load_deprecated |
static struct ast_cli_entry | cli_module_reload_deprecated |
static struct ast_cli_entry | cli_module_unload_deprecated |
static struct ast_cli_entry | cli_set_debug_deprecated |
static struct ast_cli_entry | cli_set_verbose_deprecated |
static struct ast_cli_entry | cli_show_channel_deprecated |
static struct ast_cli_entry | cli_show_channels_deprecated |
static struct ast_cli_entry | cli_show_modules_deprecated |
static struct ast_cli_entry | cli_show_modules_like_deprecated |
static struct ast_cli_entry | cli_show_uptime_deprecated |
static int | climodentryfd = -1 |
static char | commandcomplete_help [] |
static char | commandmatchesarray_help [] |
static char | commandnummatches_help [] |
static char | debug_help [] |
static char | debugchan_help [] |
unsigned long | global_fin |
unsigned long | global_fout |
static char | group_show_channels_help [] |
static char | help_help [] |
static char | load_help [] |
static char | logger_mute_help [] |
static char | modlist_help [] |
static char | nodebug_help [] |
static char | reload_help [] |
static char | showchan_help [] |
static char | softhangup_help [] |
static char | unload_help [] |
static char | uptime_help [] |
static char | verbose_help [] |
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\n" |
Definition at line 601 of file cli.c.
Referenced by handle_chanlist(), and handle_chanlist_deprecated().
#define DAY (HOUR*24) |
Referenced by print_uptimestr().
#define ESS | ( | x | ) | ((x == 1) ? "" : "s") |
Referenced by handle_chanlist(), handle_chanlist_deprecated(), and print_uptimestr().
#define FORMAT_STRING "%-20.20s %-20.20s %-7.7s %-30.30s\n" |
Definition at line 599 of file cli.c.
Referenced by group_show_channels(), handle_chanlist(), and handle_chanlist_deprecated().
#define FORMAT_STRING2 "%-20.20s %-20.20s %-7.7s %-30.30s\n" |
Definition at line 600 of file cli.c.
Referenced by handle_chanlist(), and handle_chanlist_deprecated().
#define HOUR (MINUTE*60) |
Referenced by print_uptimestr().
#define MINUTE (SECOND*60) |
Referenced by print_uptimestr().
#define MODLIST_FORMAT "%-30s %-40.40s %-10d\n" |
#define MODLIST_FORMAT2 "%-30s %-40.40s %-10s\n" |
#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" |
Definition at line 602 of file cli.c.
Referenced by handle_chanlist(), and handle_chanlist_deprecated().
#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" |
Definition at line 603 of file cli.c.
Referenced by handle_chanlist(), and handle_chanlist_deprecated().
#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 1924 of file cli.c.
References ast_cli_entry::_full_cmd, ast_join(), AST_LIST_LOCK, AST_LIST_UNLOCK, AST_MAX_ARGS, ast_strlen_zero(), cli_next(), ast_cli_entry::cmda, free, ast_cli_entry::generator, cli_iterator::helpers, parse_args(), and strdup.
Referenced by ast_cli_generator(), complete_help(), and handle_commandcomplete().
01925 { 01926 char *argv[AST_MAX_ARGS]; 01927 struct ast_cli_entry *e; 01928 struct cli_iterator i = { NULL, NULL }; 01929 int x = 0, argindex, matchlen; 01930 int matchnum=0; 01931 char *ret = NULL; 01932 char matchstr[80] = ""; 01933 int tws = 0; 01934 char *dup = parse_args(text, &x, argv, sizeof(argv) / sizeof(argv[0]), &tws); 01935 01936 if (!dup) /* error */ 01937 return NULL; 01938 argindex = (!ast_strlen_zero(word) && x>0) ? x-1 : x; 01939 /* rebuild the command, ignore tws */ 01940 ast_join(matchstr, sizeof(matchstr)-1, argv); 01941 matchlen = strlen(matchstr); 01942 if (tws) { 01943 strcat(matchstr, " "); /* XXX */ 01944 if (matchlen) 01945 matchlen++; 01946 } 01947 if (lock) 01948 AST_LIST_LOCK(&helpers); 01949 while( !ret && (e = cli_next(&i)) ) { 01950 int lc = strlen(e->_full_cmd); 01951 if (e->_full_cmd[0] != '_' && lc > 0 && matchlen <= lc && 01952 !strncasecmp(matchstr, e->_full_cmd, matchlen)) { 01953 /* Found initial part, return a copy of the next word... */ 01954 if (e->cmda[argindex] && ++matchnum > state) 01955 ret = strdup(e->cmda[argindex]); /* we need a malloced string */ 01956 } else if (e->generator && !strncasecmp(matchstr, e->_full_cmd, lc) && matchstr[lc] < 33) { 01957 /* We have a command in its entirity within us -- theoretically only one 01958 command can have this occur */ 01959 ret = e->generator(matchstr, word, argindex, state); 01960 } 01961 } 01962 if (lock) 01963 AST_LIST_UNLOCK(&helpers); 01964 free(dup); 01965 return ret; 01966 }
static int __ast_cli_register | ( | struct ast_cli_entry * | e, | |
struct ast_cli_entry * | ed | |||
) | [static] |
Definition at line 1637 of file cli.c.
References ast_cli_entry::_deprecated_by, ast_cli_entry::_full_cmd, ast_join(), AST_LIST_INSERT_BEFORE_CURRENT, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, AST_LIST_UNLOCK, ast_log(), ast_strdup, ast_cli_entry::cmda, ast_cli_entry::deprecate_cmd, ast_cli_entry::deprecated, find_cli(), len, LOG_WARNING, S_OR, ast_cli_entry::summary, and ast_cli_entry::usage.
Referenced by ast_cli_register().
01638 { 01639 struct ast_cli_entry *cur; 01640 char fulle[80] =""; 01641 int lf, ret = -1; 01642 01643 ast_join(fulle, sizeof(fulle), e->cmda); 01644 AST_LIST_LOCK(&helpers); 01645 01646 if (find_cli(e->cmda, 1)) { 01647 ast_log(LOG_WARNING, "Command '%s' already registered (or something close enough)\n", fulle); 01648 goto done; 01649 } 01650 e->_full_cmd = ast_strdup(fulle); 01651 if (!e->_full_cmd) 01652 goto done; 01653 01654 if (ed) { 01655 e->deprecated = 1; 01656 e->summary = ed->summary; 01657 e->usage = ed->usage; 01658 /* XXX If command A deprecates command B, and command B deprecates command C... 01659 Do we want to show command A or command B when telling the user to use new syntax? 01660 This currently would show command A. 01661 To show command B, you just need to always use ed->_full_cmd. 01662 */ 01663 e->_deprecated_by = S_OR(ed->_deprecated_by, ed->_full_cmd); 01664 } else { 01665 e->deprecated = 0; 01666 } 01667 01668 lf = strlen(fulle); 01669 AST_LIST_TRAVERSE_SAFE_BEGIN(&helpers, cur, list) { 01670 int len = strlen(cur->_full_cmd); 01671 if (lf < len) 01672 len = lf; 01673 if (strncasecmp(fulle, cur->_full_cmd, len) < 0) { 01674 AST_LIST_INSERT_BEFORE_CURRENT(&helpers, e, list); 01675 break; 01676 } 01677 } 01678 AST_LIST_TRAVERSE_SAFE_END; 01679 01680 if (!cur) 01681 AST_LIST_INSERT_TAIL(&helpers, e, list); 01682 ret = 0; /* success */ 01683 01684 done: 01685 AST_LIST_UNLOCK(&helpers); 01686 01687 if (e->deprecate_cmd) { 01688 /* This command deprecates another command. Register that one also. */ 01689 __ast_cli_register(e->deprecate_cmd, e); 01690 } 01691 01692 return ret; 01693 }
static int __ast_cli_unregister | ( | struct ast_cli_entry * | e, | |
struct ast_cli_entry * | ed | |||
) | [static] |
Definition at line 1621 of file cli.c.
References ast_cli_entry::_full_cmd, AST_LIST_LOCK, AST_LIST_REMOVE, AST_LIST_UNLOCK, ast_log(), ast_cli_entry::deprecate_cmd, free, cli_iterator::helpers, ast_cli_entry::inuse, and LOG_WARNING.
Referenced by ast_cli_unregister().
01622 { 01623 if (e->deprecate_cmd) { 01624 __ast_cli_unregister(e->deprecate_cmd, e); 01625 } 01626 if (e->inuse) { 01627 ast_log(LOG_WARNING, "Can't remove command that is in use\n"); 01628 } else { 01629 AST_LIST_LOCK(&helpers); 01630 AST_LIST_REMOVE(&helpers, e, list); 01631 AST_LIST_UNLOCK(&helpers); 01632 free(e->_full_cmd); 01633 } 01634 return 0; 01635 }
void ast_builtins_init | ( | void | ) |
initialize the _full_cmd string in * each of the builtins.
Provided by cli.c
Definition at line 1505 of file cli.c.
References ast_cli_entry::_full_cmd, ast_cli_register_multiple(), ast_join(), ast_log(), ast_cli_entry::cmda, LOG_WARNING, and strdup.
Referenced by main().
01506 { 01507 struct ast_cli_entry *e; 01508 01509 for (e = builtins; e->cmda[0] != NULL; e++) { 01510 char buf[80]; 01511 ast_join(buf, sizeof(buf), e->cmda); 01512 e->_full_cmd = strdup(buf); 01513 if (!e->_full_cmd) 01514 ast_log(LOG_WARNING, "-- cannot allocate <%s>\n", buf); 01515 } 01516 01517 ast_cli_register_multiple(cli_cli, sizeof(cli_cli) / sizeof(struct ast_cli_entry)); 01518 }
void ast_cli | ( | int | fd, | |
char * | fmt, | |||
... | ||||
) |
Definition at line 59 of file cli.c.
References ast_carefulwrite(), AST_CLI_INITLEN, and ast_dynamic_str_thread_set_va.
Referenced by __iax2_show_peers(), __queues_show(), __say_init(), __sip_show_channels(), _sip_show_peer(), _sip_show_peers(), action_originate(), agent_logoff_cmd(), agents_show(), agents_show_online(), agi_do_debug(), agi_no_debug(), agi_no_debug_deprecated(), aji_do_debug(), aji_do_reload(), aji_no_debug(), aji_show_clients(), aji_test(), ast_cli_command(), ast_cli_netstats(), ast_console_toggle_mute(), ast_httpd_helper_thread(), cli_audio_convert(), cli_audio_convert_deprecated(), cli_files_show(), cli_funcdevstate_list(), cli_realtime_load(), cli_realtime_update(), config_command(), console_active(), console_active_deprecated(), console_answer(), console_answer_deprecated(), console_autoanswer(), console_autoanswer_deprecated(), console_dial(), console_dial_deprecated(), console_flash(), console_flash_deprecated(), console_hangup(), console_hangup_deprecated(), console_sendtext(), console_sendtext_deprecated(), console_transfer(), console_transfer_deprecated(), database_del(), database_deltree(), database_get(), database_put(), database_show(), database_showkey(), do_boost(), dundi_do_debug(), dundi_do_lookup(), dundi_do_precache(), dundi_do_query(), dundi_do_store_history(), dundi_flush(), dundi_no_debug(), dundi_no_store_history(), dundi_show_entityid(), dundi_show_mappings(), dundi_show_peer(), dundi_show_peers(), dundi_show_precache(), dundi_show_requests(), dundi_show_trans(), features_show(), group_show_channels(), gtalk_show_channels(), h323_do_debug(), h323_do_trace(), h323_no_debug(), h323_no_trace(), handle_agidumphtml(), handle_autoanswer(), handle_chanlist(), handle_chanlist_deprecated(), handle_cli_status(), handle_cli_submit(), handle_commandcomplete(), handle_commandmatchesarray(), handle_commandnummatches(), handle_context_add_extension(), handle_context_add_extension_deprecated(), handle_context_add_ignorepat(), handle_context_add_ignorepat_deprecated(), handle_context_add_include(), handle_context_add_include_deprecated(), handle_context_dont_include_deprecated(), handle_context_remove_extension(), handle_context_remove_extension_deprecated(), handle_context_remove_ignorepat(), handle_context_remove_ignorepat_deprecated(), handle_context_remove_include(), handle_core_set_debug_channel(), handle_debugchan_deprecated(), handle_debuglevel_deprecated(), handle_help(), handle_load(), handle_load_deprecated(), handle_logger_reload(), handle_logger_rotate(), handle_logger_show_channels(), handle_modlist(), handle_nodebug(), handle_nodebugchan_deprecated(), handle_parkedcalls(), handle_queue_add_member(), handle_queue_remove_member(), handle_reload(), handle_reload_deprecated(), handle_reload_extensions(), handle_restart_when_convenient(), handle_save_dialplan(), handle_set_debug(), handle_set_debug_deprecated(), handle_set_global(), handle_set_global_deprecated(), handle_set_verbose_deprecated(), handle_show_application(), handle_show_application_deprecated(), handle_show_applications(), handle_show_applications_deprecated(), handle_show_dialplan(), handle_show_function(), handle_show_function_deprecated(), handle_show_functions(), handle_show_functions_deprecated(), handle_show_globals(), handle_show_hints(), handle_show_http(), handle_show_indications(), handle_show_profile(), handle_show_profile_deprecated(), handle_show_switches(), handle_show_threads(), handle_show_version_files(), handle_show_version_files_deprecated(), handle_showagi(), handle_showchan(), handle_showchan_deprecated(), handle_showfeatures(), handle_showmanager(), handle_showmanagers(), handle_showmancmd(), handle_showmancmds(), handle_showmanconn(), handle_showmaneventq(), handle_shutdown_when_convenient(), handle_softhangup(), handle_unload(), handle_unload_deprecated(), handle_verbose(), handle_version(), handle_version_deprecated(), handle_voicemail_show_users(), handle_voicemail_show_zones(), handle_zap_show_cadences(), help1(), help_workhorse(), iax2_do_debug(), iax2_do_jb_debug(), iax2_do_trunk_debug(), iax2_no_debug(), iax2_no_jb_debug(), iax2_no_trunk_debug(), iax2_prov_cmd(), iax2_prune_realtime(), iax2_show_cache(), iax2_show_channels(), iax2_show_firmware(), iax2_show_netstats(), iax2_show_peer(), iax2_show_registry(), iax2_show_stats(), iax2_show_threads(), iax2_show_users(), iax_show_provisioning(), locals_show(), meetme_cmd(), mgcp_audit_endpoint(), mgcp_do_debug(), mgcp_no_debug(), mgcp_show_endpoints(), misdn_reload(), misdn_send_cd(), misdn_send_digit(), misdn_send_display(), misdn_set_debug(), misdn_show_cls(), misdn_show_config(), misdn_show_port(), misdn_show_ports_stats(), misdn_show_stacks(), misdn_toggle_echocancel(), mixmonitor_cli(), modlist_modentry(), moh_classes_show(), odbc_show_command(), orig_app(), orig_exten(), osp_show(), print_bc_info(), print_codec_to_cli(), print_group(), print_uptimestr(), realtime_pgsql_status(), rpt_do_debug(), rpt_do_dump(), rpt_do_fun(), rpt_do_lstats(), rpt_do_nodes(), rpt_do_stats(), rtcp_do_debug(), rtcp_do_debug_deprecated(), rtcp_do_debug_ip(), rtcp_do_debug_ip_deprecated(), rtcp_do_stats(), rtcp_do_stats_deprecated(), rtcp_no_debug(), rtcp_no_debug_deprecated(), rtcp_no_stats(), rtcp_no_stats_deprecated(), rtp_do_debug(), rtp_do_debug_ip(), rtp_no_debug(), show_channeltype(), show_channeltype_deprecated(), show_channeltypes(), show_codec_n(), show_codec_n_deprecated(), show_codecs(), show_codecs_deprecated(), show_config_description(), show_dialplan_helper(), show_file_formats(), show_file_formats_deprecated(), show_image_formats(), show_image_formats_deprecated(), show_keys(), show_license(), show_translation(), show_translation_deprecated(), show_warranty(), sip_do_debug(), sip_do_debug_deprecated(), sip_do_debug_ip(), sip_do_debug_peer(), sip_do_history(), sip_no_debug(), sip_no_debug_deprecated(), sip_no_history(), sip_notify(), sip_prune_realtime(), sip_show_channel(), sip_show_domains(), sip_show_history(), sip_show_inuse(), sip_show_objects(), sip_show_registry(), sip_show_settings(), sip_show_user(), sip_show_users(), skinny_do_debug(), skinny_no_debug(), skinny_show_devices(), skinny_show_lines(), sla_show_stations(), sla_show_trunks(), stun_do_debug(), stun_no_debug(), transcoder_show(), udptl_do_debug(), udptl_do_debug_ip(), udptl_nodebug(), zap_show_channel(), zap_show_channels(), and zap_show_status().
00060 { 00061 int res; 00062 struct ast_dynamic_str *buf; 00063 va_list ap; 00064 00065 if (!(buf = ast_dynamic_str_thread_get(&ast_cli_buf, AST_CLI_INITLEN))) 00066 return; 00067 00068 va_start(ap, fmt); 00069 res = ast_dynamic_str_thread_set_va(&buf, 0, &ast_cli_buf, fmt, ap); 00070 va_end(ap); 00071 00072 if (res != AST_DYNSTR_BUILD_FAILED) 00073 ast_carefulwrite(fd, buf->str, strlen(buf->str), 100); 00074 }
int ast_cli_command | ( | int | fd, | |
const char * | s | |||
) |
Interprets a command Interpret a command s, sending output to fd Returns 0 on succes, -1 on failure.
Definition at line 1973 of file cli.c.
References ast_cli_entry::_deprecated_by, ast_cli_entry::_full_cmd, ast_cli(), AST_LIST_LOCK, AST_LIST_UNLOCK, AST_MAX_ARGS, ast_cli_entry::deprecated, find_best(), find_cli(), free, ast_cli_entry::handler, ast_cli_entry::inuse, parse_args(), RESULT_SHOWUSAGE, and ast_cli_entry::usage.
Referenced by action_command(), ast_cli_command_multiple(), cli_activate(), consolehandler(), exit_completely(), and rpt_exec().
01974 { 01975 char *argv[AST_MAX_ARGS]; 01976 struct ast_cli_entry *e; 01977 int x; 01978 char *dup; 01979 int tws; 01980 01981 if (!(dup = parse_args(s, &x, argv, sizeof(argv) / sizeof(argv[0]), &tws))) 01982 return -1; 01983 01984 /* We need at least one entry, or ignore */ 01985 if (x > 0) { 01986 AST_LIST_LOCK(&helpers); 01987 e = find_cli(argv, 0); 01988 if (e) 01989 e->inuse++; 01990 AST_LIST_UNLOCK(&helpers); 01991 if (e) { 01992 switch(e->handler(fd, x, argv)) { 01993 case RESULT_SHOWUSAGE: 01994 if (e->usage) 01995 ast_cli(fd, "%s", e->usage); 01996 else 01997 ast_cli(fd, "Invalid usage, but no usage information available.\n"); 01998 AST_LIST_LOCK(&helpers); 01999 if (e->deprecated) 02000 ast_cli(fd, "The '%s' command is deprecated and will be removed in a future release. Please use '%s' instead.\n", e->_full_cmd, e->_deprecated_by); 02001 AST_LIST_UNLOCK(&helpers); 02002 break; 02003 default: 02004 AST_LIST_LOCK(&helpers); 02005 if (e->deprecated == 1) { 02006 ast_cli(fd, "The '%s' command is deprecated and will be removed in a future release. Please use '%s' instead.\n", e->_full_cmd, e->_deprecated_by); 02007 e->deprecated = 2; 02008 } 02009 AST_LIST_UNLOCK(&helpers); 02010 break; 02011 } 02012 } else 02013 ast_cli(fd, "No such command '%s' (type 'help %s' for other possible commands)\n", s, find_best(argv)); 02014 if (e) 02015 ast_atomic_fetchadd_int(&e->inuse, -1); 02016 } 02017 free(dup); 02018 02019 return 0; 02020 }
int ast_cli_command_multiple | ( | int | fd, | |
size_t | size, | |||
const char * | s | |||
) |
Executes multiple CLI commands Interpret strings separated by '' and execute each one, sending output to fd.
size | is the total size of the string |
number | of commands executed |
Definition at line 2022 of file cli.c.
References ast_cli_command().
Referenced by netconsole().
02023 { 02024 char cmd[512]; 02025 int x, y = 0, count = 0; 02026 02027 for (x = 0; x < size; x++) { 02028 cmd[y] = s[x]; 02029 y++; 02030 if (s[x] == '\0') { 02031 ast_cli_command(fd, cmd); 02032 y = 0; 02033 count++; 02034 } 02035 } 02036 return count; 02037 }
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 1167 of file cli.c.
References ast_strdup, ast_strlen_zero(), and len.
Referenced by autoanswer_complete(), autoanswer_complete_deprecated(), complete_meetmecmd(), complete_orig(), complete_show_applications(), complete_show_applications_deprecated(), complete_show_channels(), and complete_show_channels_deprecated().
01168 { 01169 int i, which = 0, len; 01170 len = ast_strlen_zero(word) ? 0 : strlen(word); 01171 01172 for (i = 0; choices[i]; i++) { 01173 if ((!len || !strncasecmp(word, choices[i], len)) && ++which > state) 01174 return ast_strdup(choices[i]); 01175 } 01176 return NULL; 01177 }
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, followe by a NULL. All strings and the array itself are malloc'ed and must be freed by the caller.
Definition at line 1877 of file cli.c.
References ast_cli_generator(), ast_malloc, and ast_realloc.
Referenced by cli_complete(), and handle_commandmatchesarray().
01878 { 01879 char **match_list = NULL, *retstr, *prevstr; 01880 size_t match_list_len, max_equal, which, i; 01881 int matches = 0; 01882 01883 /* leave entry 0 free for the longest common substring */ 01884 match_list_len = 1; 01885 while ((retstr = ast_cli_generator(text, word, matches)) != NULL) { 01886 if (matches + 1 >= match_list_len) { 01887 match_list_len <<= 1; 01888 if (!(match_list = ast_realloc(match_list, match_list_len * sizeof(*match_list)))) 01889 return NULL; 01890 } 01891 match_list[++matches] = retstr; 01892 } 01893 01894 if (!match_list) 01895 return match_list; /* NULL */ 01896 01897 /* Find the longest substring that is common to all results 01898 * (it is a candidate for completion), and store a copy in entry 0. 01899 */ 01900 prevstr = match_list[1]; 01901 max_equal = strlen(prevstr); 01902 for (which = 2; which <= matches; which++) { 01903 for (i = 0; i < max_equal && toupper(prevstr[i]) == toupper(match_list[which][i]); i++) 01904 continue; 01905 max_equal = i; 01906 } 01907 01908 if (!(retstr = ast_malloc(max_equal + 1))) 01909 return NULL; 01910 01911 ast_copy_string(retstr, match_list[1], max_equal + 1); 01912 match_list[0] = retstr; 01913 01914 /* ensure that the array is NULL terminated */ 01915 if (matches + 1 >= match_list_len) { 01916 if (!(match_list = ast_realloc(match_list, (match_list_len + 1) * sizeof(*match_list)))) 01917 return NULL; 01918 } 01919 match_list[matches + 1] = NULL; 01920 01921 return match_list; 01922 }
char* ast_cli_generator | ( | const char * | text, | |
const char * | word, | |||
int | state | |||
) |
Readline madness Useful for readline, that's about it Returns 0 on success, -1 on failure.
Definition at line 1968 of file cli.c.
References __ast_cli_generator().
Referenced by ast_cli_completion_matches(), and ast_cli_generatornummatches().
01969 { 01970 return __ast_cli_generator(text, word, state, 1); 01971 }
int ast_cli_generatornummatches | ( | const char * | text, | |
const char * | word | |||
) |
Return the number of unique matches for the generator.
Definition at line 1860 of file cli.c.
References ast_cli_generator(), and free.
Referenced by handle_commandnummatches().
01861 { 01862 int matches = 0, i = 0; 01863 char *buf = NULL, *oldbuf = NULL; 01864 01865 while ((buf = ast_cli_generator(text, word, i++))) { 01866 if (!oldbuf || strcmp(buf,oldbuf)) 01867 matches++; 01868 if (oldbuf) 01869 free(oldbuf); 01870 oldbuf = buf; 01871 } 01872 if (oldbuf) 01873 free(oldbuf); 01874 return matches; 01875 }
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 Returns 0 on success, -1 on failure |
Definition at line 1702 of file cli.c.
References __ast_cli_register().
Referenced by ast_cdr_engine_init(), ast_cli_register_multiple(), dnsmgr_init(), do_reload(), and load_module().
01703 { 01704 return __ast_cli_register(e, NULL); 01705 }
void 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 1710 of file cli.c.
References ast_cli_register().
Referenced by __ast_register_translator(), ast_builtins_init(), ast_channels_init(), ast_file_init(), ast_http_init(), ast_image_init(), ast_rtp_init(), ast_udptl_init(), ast_utils_init(), astdb_init(), astobj2_init(), crypto_init(), iax_provision_init(), init_framer(), init_logger(), init_manager(), load_module(), load_pbx(), main(), and register_config_cli().
01711 { 01712 int i; 01713 01714 for (i = 0; i < len; i++) 01715 ast_cli_register(e + i); 01716 }
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 Returns 0. |
Definition at line 1696 of file cli.c.
References __ast_cli_unregister().
Referenced by __unload_module(), ast_cli_unregister_multiple(), do_reload(), load_module(), and unload_module().
01697 { 01698 return __ast_cli_unregister(e, NULL); 01699 }
void 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 1718 of file cli.c.
References ast_cli_unregister().
Referenced by __unload_module(), iax_provision_unload(), load_module(), and unload_module().
01719 { 01720 int i; 01721 01722 for (i = 0; i < len; i++) 01723 ast_cli_unregister(e + i); 01724 }
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 1193 of file cli.c.
References ast_channel_unlock, ast_channel_walk_locked(), and ast_strdup.
Referenced by complete_ch_3(), complete_ch_4(), complete_ch_5(), and complete_mixmonitor_cli().
01194 { 01195 struct ast_channel *c = NULL; 01196 int which = 0; 01197 int wordlen; 01198 char notfound = '\0'; 01199 char *ret = ¬found; /* so NULL can break the loop */ 01200 01201 if (pos != rpos) 01202 return NULL; 01203 01204 wordlen = strlen(word); 01205 01206 while (ret == ¬found && (c = ast_channel_walk_locked(c))) { 01207 if (!strncasecmp(word, c->name, wordlen) && ++which > state) 01208 ret = ast_strdup(c->name); 01209 ast_channel_unlock(c); 01210 } 01211 return ret == ¬found ? NULL : ret; 01212 }
static AST_LIST_HEAD_STATIC | ( | helpers | , | |
ast_cli_entry | ||||
) | [static] |
AST_MUTEX_DEFINE_STATIC | ( | climodentrylock | ) |
AST_THREADSTORAGE | ( | ast_cli_buf | , | |
ast_cli_buf_init | ||||
) |
static struct ast_cli_entry* cli_next | ( | struct cli_iterator * | i | ) | [static, read] |
Definition at line 1534 of file cli.c.
References ast_cli_entry::_full_cmd, AST_LIST_FIRST, AST_LIST_NEXT, cli_iterator::builtins, ast_cli_entry::cmda, and cli_iterator::helpers.
Referenced by __ast_cli_generator(), find_cli(), and help1().
01535 { 01536 struct ast_cli_entry *e; 01537 01538 if (i->builtins == NULL && i->helpers == NULL) { 01539 /* initialize */ 01540 i->builtins = builtins; 01541 i->helpers = AST_LIST_FIRST(&helpers); 01542 } 01543 e = i->builtins; /* temporary */ 01544 if (!e->cmda[0] || (i->helpers && 01545 strcmp(i->helpers->_full_cmd, e->_full_cmd) < 0)) { 01546 /* Use helpers */ 01547 e = i->helpers; 01548 if (e) 01549 i->helpers = AST_LIST_NEXT(e, list); 01550 } else { /* use builtin. e is already set */ 01551 (i->builtins)++; /* move to next */ 01552 } 01553 return e; 01554 }
static char* complete_ch_3 | ( | const char * | line, | |
const char * | word, | |||
int | pos, | |||
int | state | |||
) | [static] |
Definition at line 1214 of file cli.c.
References ast_complete_channels().
01215 { 01216 return ast_complete_channels(line, word, pos, state, 2); 01217 }
static char* complete_ch_4 | ( | const char * | line, | |
const char * | word, | |||
int | pos, | |||
int | state | |||
) | [static] |
Definition at line 1219 of file cli.c.
References ast_complete_channels().
01220 { 01221 return ast_complete_channels(line, word, pos, state, 3); 01222 }
static char* complete_ch_5 | ( | const char * | line, | |
const char * | word, | |||
int | pos, | |||
int | state | |||
) | [static] |
Definition at line 1224 of file cli.c.
References ast_complete_channels().
01225 { 01226 return ast_complete_channels(line, word, pos, state, 4); 01227 }
static char* complete_fn_2 | ( | const char * | line, | |
const char * | word, | |||
int | pos, | |||
int | state | |||
) | [static] |
Definition at line 1249 of file cli.c.
References ast_config_AST_MODULE_DIR, free, and strdup.
01250 { 01251 char *c, *d; 01252 char filename[256]; 01253 01254 if (pos != 1) 01255 return NULL; 01256 01257 if (word[0] == '/') 01258 ast_copy_string(filename, word, sizeof(filename)); 01259 else 01260 snprintf(filename, sizeof(filename), "%s/%s", ast_config_AST_MODULE_DIR, word); 01261 01262 c = d = filename_completion_function(filename, state); 01263 01264 if (c && word[0] != '/') 01265 c += (strlen(ast_config_AST_MODULE_DIR) + 1); 01266 if (c) 01267 c = strdup(c); 01268 free(d); 01269 01270 return c; 01271 }
static char* complete_fn_3 | ( | const char * | line, | |
const char * | word, | |||
int | pos, | |||
int | state | |||
) | [static] |
Definition at line 1273 of file cli.c.
References ast_config_AST_MODULE_DIR, free, and strdup.
01274 { 01275 char *c, *d; 01276 char filename[256]; 01277 01278 if (pos != 2) 01279 return NULL; 01280 01281 if (word[0] == '/') 01282 ast_copy_string(filename, word, sizeof(filename)); 01283 else 01284 snprintf(filename, sizeof(filename), "%s/%s", ast_config_AST_MODULE_DIR, word); 01285 01286 c = d = filename_completion_function(filename, state); 01287 01288 if (c && word[0] != '/') 01289 c += (strlen(ast_config_AST_MODULE_DIR) + 1); 01290 if (c) 01291 c = strdup(c); 01292 free(d); 01293 01294 return c; 01295 }
static char* complete_help | ( | const char * | text, | |
const char * | word, | |||
int | pos, | |||
int | state | |||
) | [static] |
Definition at line 1340 of file cli.c.
References __ast_cli_generator().
01341 { 01342 /* skip first 4 or 5 chars, "help "*/ 01343 int l = strlen(text); 01344 01345 if (l > 5) 01346 l = 5; 01347 text += l; 01348 /* XXX watch out, should stop to the non-generator parts */ 01349 return __ast_cli_generator(text, word, state, 0); 01350 }
static char* complete_mod_2 | ( | const char * | line, | |
const char * | word, | |||
int | pos, | |||
int | state | |||
) | [static] |
Definition at line 1229 of file cli.c.
References ast_module_helper().
01230 { 01231 return ast_module_helper(line, word, pos, state, 1, 1); 01232 }
static char* complete_mod_3 | ( | const char * | line, | |
const char * | word, | |||
int | pos, | |||
int | state | |||
) | [static] |
Definition at line 1239 of file cli.c.
References ast_module_helper().
01240 { 01241 return ast_module_helper(line, word, pos, state, 2, 1); 01242 }
static char* complete_mod_3_nr | ( | const char * | line, | |
const char * | word, | |||
int | pos, | |||
int | state | |||
) | [static] |
Definition at line 1234 of file cli.c.
References ast_module_helper().
01235 { 01236 return ast_module_helper(line, word, pos, state, 2, 0); 01237 }
static char* complete_mod_4 | ( | const char * | line, | |
const char * | word, | |||
int | pos, | |||
int | state | |||
) | [static] |
Definition at line 1244 of file cli.c.
References ast_module_helper().
01245 { 01246 return ast_module_helper(line, word, pos, state, 3, 0); 01247 }
static char* complete_show_channels | ( | const char * | line, | |
const char * | word, | |||
int | pos, | |||
int | state | |||
) | [static] |
Definition at line 1186 of file cli.c.
References ast_cli_complete().
01187 { 01188 static char *choices[] = { "concise", "verbose", NULL }; 01189 01190 return (pos != 3) ? NULL : ast_cli_complete(word, choices, state); 01191 }
static char* complete_show_channels_deprecated | ( | const char * | line, | |
const char * | word, | |||
int | pos, | |||
int | state | |||
) | [static] |
Definition at line 1179 of file cli.c.
References ast_cli_complete().
01180 { 01181 static char *choices[] = { "concise", "verbose", NULL }; 01182 01183 return (pos != 2) ? NULL : ast_cli_complete(word, choices, state); 01184 }
static char* find_best | ( | char * | argv[] | ) | [static] |
Definition at line 1602 of file cli.c.
References ast_join(), AST_LIST_LOCK, AST_LIST_UNLOCK, AST_MAX_CMD_LEN, find_cli(), and cli_iterator::helpers.
Referenced by ast_cli_command(), ring_one(), and store_next().
01603 { 01604 static char cmdline[80]; 01605 int x; 01606 /* See how close we get, then print the candidate */ 01607 char *myargv[AST_MAX_CMD_LEN]; 01608 for (x=0;x<AST_MAX_CMD_LEN;x++) 01609 myargv[x]=NULL; 01610 AST_LIST_LOCK(&helpers); 01611 for (x=0;argv[x];x++) { 01612 myargv[x] = argv[x]; 01613 if (!find_cli(myargv, -1)) 01614 break; 01615 } 01616 AST_LIST_UNLOCK(&helpers); 01617 ast_join(cmdline, sizeof(cmdline), myargv); 01618 return cmdline; 01619 }
static struct ast_cli_entry* find_cli | ( | char *const | cmds[], | |
int | match_type | |||
) | [static, read] |
locate a cli command in the 'helpers' list (which must be locked). exact has 3 values: 0 returns if the search key is equal or longer than the entry. -1 true if the mismatch is on the last word XXX not true! 1 true only on complete, exact match.
Definition at line 1563 of file cli.c.
References cli_next().
Referenced by __ast_cli_register(), ast_cli_command(), find_best(), and handle_help().
01564 { 01565 int matchlen = -1; /* length of longest match so far */ 01566 struct ast_cli_entry *cand = NULL, *e=NULL; 01567 struct cli_iterator i = { NULL, NULL}; 01568 01569 while( (e = cli_next(&i)) ) { 01570 int y; 01571 for (y = 0 ; cmds[y] && e->cmda[y]; y++) { 01572 if (strcasecmp(e->cmda[y], cmds[y])) 01573 break; 01574 } 01575 if (e->cmda[y] == NULL) { /* no more words in candidate */ 01576 if (cmds[y] == NULL) /* this is an exact match, cannot do better */ 01577 break; 01578 /* here the search key is longer than the candidate */ 01579 if (match_type != 0) /* but we look for almost exact match... */ 01580 continue; /* so we skip this one. */ 01581 /* otherwise we like it (case 0) */ 01582 } else { /* still words in candidate */ 01583 if (cmds[y] == NULL) /* search key is shorter, not good */ 01584 continue; 01585 /* if we get here, both words exist but there is a mismatch */ 01586 if (match_type == 0) /* not the one we look for */ 01587 continue; 01588 if (match_type == 1) /* not the one we look for */ 01589 continue; 01590 if (cmds[y+1] != NULL || e->cmda[y+1] != NULL) /* not the one we look for */ 01591 continue; 01592 /* we are in case match_type == -1 and mismatch on last word */ 01593 } 01594 if (y > matchlen) { /* remember the candidate */ 01595 matchlen = y; 01596 cand = e; 01597 } 01598 } 01599 return e ? e : cand; 01600 }
static int group_show_channels | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 1297 of file cli.c.
References ast_app_group_list_head(), ast_app_group_list_lock(), ast_app_group_list_unlock(), ast_cli(), AST_LIST_NEXT, ast_strlen_zero(), ast_group_info::category, ast_group_info::chan, FORMAT_STRING, ast_group_info::group, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
01298 { 01299 #define FORMAT_STRING "%-25s %-20s %-20s\n" 01300 01301 struct ast_group_info *gi = NULL; 01302 int numchans = 0; 01303 regex_t regexbuf; 01304 int havepattern = 0; 01305 01306 if (argc < 3 || argc > 4) 01307 return RESULT_SHOWUSAGE; 01308 01309 if (argc == 4) { 01310 if (regcomp(®exbuf, argv[3], REG_EXTENDED | REG_NOSUB)) 01311 return RESULT_SHOWUSAGE; 01312 havepattern = 1; 01313 } 01314 01315 ast_cli(fd, FORMAT_STRING, "Channel", "Group", "Category"); 01316 01317 ast_app_group_list_lock(); 01318 01319 gi = ast_app_group_list_head(); 01320 while (gi) { 01321 if (!havepattern || !regexec(®exbuf, gi->group, 0, NULL, 0)) { 01322 ast_cli(fd, FORMAT_STRING, gi->chan->name, gi->group, (ast_strlen_zero(gi->category) ? "(default)" : gi->category)); 01323 numchans++; 01324 } 01325 gi = AST_LIST_NEXT(gi, list); 01326 } 01327 01328 ast_app_group_list_unlock(); 01329 01330 if (havepattern) 01331 regfree(®exbuf); 01332 01333 ast_cli(fd, "%d active channel%s\n", numchans, (numchans != 1) ? "s" : ""); 01334 return RESULT_SUCCESS; 01335 #undef FORMAT_STRING 01336 }
static int handle_chanlist | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 685 of file cli.c.
References ast_channel::_state, ast_channel::amaflags, ast_channel::appl, ast_active_calls(), ast_bridged_channel(), ast_channel_unlock, ast_channel_walk_locked(), ast_cli(), ast_state2str(), ast_strlen_zero(), ast_channel::cdr, ast_channel::cid, ast_callerid::cid_num, CONCISE_FORMAT_STRING, ast_channel::context, ast_channel::data, ESS, ast_channel::exten, FORMAT_STRING, FORMAT_STRING2, option_maxcalls, ast_channel::priority, RESULT_SHOWUSAGE, RESULT_SUCCESS, S_OR, ast_cdr::start, VERBOSE_FORMAT_STRING, and VERBOSE_FORMAT_STRING2.
00686 { 00687 struct ast_channel *c = NULL; 00688 char durbuf[10] = "-"; 00689 char locbuf[40]; 00690 char appdata[40]; 00691 int duration; 00692 int durh, durm, durs; 00693 int numchans = 0, concise = 0, verbose = 0; 00694 00695 concise = (argc == 4 && (!strcasecmp(argv[3],"concise"))); 00696 verbose = (argc == 4 && (!strcasecmp(argv[3],"verbose"))); 00697 00698 if (argc < 3 || argc > 4 || (argc == 4 && !concise && !verbose)) 00699 return RESULT_SHOWUSAGE; 00700 00701 if (!concise && !verbose) 00702 ast_cli(fd, FORMAT_STRING2, "Channel", "Location", "State", "Application(Data)"); 00703 else if (verbose) 00704 ast_cli(fd, VERBOSE_FORMAT_STRING2, "Channel", "Context", "Extension", "Priority", "State", "Application", "Data", 00705 "CallerID", "Duration", "Accountcode", "BridgedTo"); 00706 00707 while ((c = ast_channel_walk_locked(c)) != NULL) { 00708 struct ast_channel *bc = ast_bridged_channel(c); 00709 if ((concise || verbose) && c->cdr && !ast_tvzero(c->cdr->start)) { 00710 duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000); 00711 if (verbose) { 00712 durh = duration / 3600; 00713 durm = (duration % 3600) / 60; 00714 durs = duration % 60; 00715 snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs); 00716 } else { 00717 snprintf(durbuf, sizeof(durbuf), "%d", duration); 00718 } 00719 } else { 00720 durbuf[0] = '\0'; 00721 } 00722 if (concise) { 00723 ast_cli(fd, CONCISE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state), 00724 c->appl ? c->appl : "(None)", 00725 S_OR(c->data, ""), /* XXX different from verbose ? */ 00726 S_OR(c->cid.cid_num, ""), 00727 S_OR(c->accountcode, ""), 00728 c->amaflags, 00729 durbuf, 00730 bc ? bc->name : "(None)"); 00731 } else if (verbose) { 00732 ast_cli(fd, VERBOSE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state), 00733 c->appl ? c->appl : "(None)", 00734 c->data ? S_OR(c->data, "(Empty)" ): "(None)", 00735 S_OR(c->cid.cid_num, ""), 00736 durbuf, 00737 S_OR(c->accountcode, ""), 00738 bc ? bc->name : "(None)"); 00739 } else { 00740 if (!ast_strlen_zero(c->context) && !ast_strlen_zero(c->exten)) 00741 snprintf(locbuf, sizeof(locbuf), "%s@%s:%d", c->exten, c->context, c->priority); 00742 else 00743 strcpy(locbuf, "(None)"); 00744 if (c->appl) 00745 snprintf(appdata, sizeof(appdata), "%s(%s)", c->appl, c->data ? c->data : ""); 00746 else 00747 strcpy(appdata, "(None)"); 00748 ast_cli(fd, FORMAT_STRING, c->name, locbuf, ast_state2str(c->_state), appdata); 00749 } 00750 numchans++; 00751 ast_channel_unlock(c); 00752 } 00753 if (!concise) { 00754 ast_cli(fd, "%d active channel%s\n", numchans, ESS(numchans)); 00755 if (option_maxcalls) 00756 ast_cli(fd, "%d of %d max active call%s (%5.2f%% of capacity)\n", 00757 ast_active_calls(), option_maxcalls, ESS(ast_active_calls()), 00758 ((double)ast_active_calls() / (double)option_maxcalls) * 100.0); 00759 else 00760 ast_cli(fd, "%d active call%s\n", ast_active_calls(), ESS(ast_active_calls())); 00761 } 00762 return RESULT_SUCCESS; 00763 }
static int handle_chanlist_deprecated | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 605 of file cli.c.
References ast_channel::_state, ast_channel::amaflags, ast_channel::appl, ast_active_calls(), ast_bridged_channel(), ast_channel_unlock, ast_channel_walk_locked(), ast_cli(), ast_state2str(), ast_strlen_zero(), ast_channel::cdr, ast_channel::cid, ast_callerid::cid_num, CONCISE_FORMAT_STRING, ast_channel::context, ast_channel::data, ESS, ast_channel::exten, FORMAT_STRING, FORMAT_STRING2, option_maxcalls, ast_channel::priority, RESULT_SHOWUSAGE, RESULT_SUCCESS, S_OR, ast_cdr::start, VERBOSE_FORMAT_STRING, and VERBOSE_FORMAT_STRING2.
00606 { 00607 struct ast_channel *c = NULL; 00608 char durbuf[10] = "-"; 00609 char locbuf[40]; 00610 char appdata[40]; 00611 int duration; 00612 int durh, durm, durs; 00613 int numchans = 0, concise = 0, verbose = 0; 00614 00615 concise = (argc == 3 && (!strcasecmp(argv[2],"concise"))); 00616 verbose = (argc == 3 && (!strcasecmp(argv[2],"verbose"))); 00617 00618 if (argc < 2 || argc > 3 || (argc == 3 && !concise && !verbose)) 00619 return RESULT_SHOWUSAGE; 00620 00621 if (!concise && !verbose) 00622 ast_cli(fd, FORMAT_STRING2, "Channel", "Location", "State", "Application(Data)"); 00623 else if (verbose) 00624 ast_cli(fd, VERBOSE_FORMAT_STRING2, "Channel", "Context", "Extension", "Priority", "State", "Application", "Data", 00625 "CallerID", "Duration", "Accountcode", "BridgedTo"); 00626 00627 while ((c = ast_channel_walk_locked(c)) != NULL) { 00628 struct ast_channel *bc = ast_bridged_channel(c); 00629 if ((concise || verbose) && c->cdr && !ast_tvzero(c->cdr->start)) { 00630 duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000); 00631 if (verbose) { 00632 durh = duration / 3600; 00633 durm = (duration % 3600) / 60; 00634 durs = duration % 60; 00635 snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs); 00636 } else { 00637 snprintf(durbuf, sizeof(durbuf), "%d", duration); 00638 } 00639 } else { 00640 durbuf[0] = '\0'; 00641 } 00642 if (concise) { 00643 ast_cli(fd, CONCISE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state), 00644 c->appl ? c->appl : "(None)", 00645 S_OR(c->data, ""), /* XXX different from verbose ? */ 00646 S_OR(c->cid.cid_num, ""), 00647 S_OR(c->accountcode, ""), 00648 c->amaflags, 00649 durbuf, 00650 bc ? bc->name : "(None)"); 00651 } else if (verbose) { 00652 ast_cli(fd, VERBOSE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state), 00653 c->appl ? c->appl : "(None)", 00654 c->data ? S_OR(c->data, "(Empty)" ): "(None)", 00655 S_OR(c->cid.cid_num, ""), 00656 durbuf, 00657 S_OR(c->accountcode, ""), 00658 bc ? bc->name : "(None)"); 00659 } else { 00660 if (!ast_strlen_zero(c->context) && !ast_strlen_zero(c->exten)) 00661 snprintf(locbuf, sizeof(locbuf), "%s@%s:%d", c->exten, c->context, c->priority); 00662 else 00663 strcpy(locbuf, "(None)"); 00664 if (c->appl) 00665 snprintf(appdata, sizeof(appdata), "%s(%s)", c->appl, c->data ? c->data : ""); 00666 else 00667 strcpy(appdata, "(None)"); 00668 ast_cli(fd, FORMAT_STRING, c->name, locbuf, ast_state2str(c->_state), appdata); 00669 } 00670 numchans++; 00671 ast_channel_unlock(c); 00672 } 00673 if (!concise) { 00674 ast_cli(fd, "%d active channel%s\n", numchans, ESS(numchans)); 00675 if (option_maxcalls) 00676 ast_cli(fd, "%d of %d max active call%s (%5.2f%% of capacity)\n", 00677 ast_active_calls(), option_maxcalls, ESS(ast_active_calls()), 00678 ((double)ast_active_calls() / (double)option_maxcalls) * 100.0); 00679 else 00680 ast_cli(fd, "%d active call%s\n", ast_active_calls(), ESS(ast_active_calls())); 00681 } 00682 return RESULT_SUCCESS; 00683 }
static int handle_commandcomplete | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 868 of file cli.c.
References __ast_cli_generator(), ast_cli(), free, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00869 { 00870 char *buf; 00871 00872 if (argc != 5) 00873 return RESULT_SHOWUSAGE; 00874 buf = __ast_cli_generator(argv[2], argv[3], atoi(argv[4]), 0); 00875 if (buf) { 00876 ast_cli(fd, buf); 00877 free(buf); 00878 } else 00879 ast_cli(fd, "NULL\n"); 00880 return RESULT_SUCCESS; 00881 }
static int handle_commandmatchesarray | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 811 of file cli.c.
References ast_cli(), AST_CLI_COMPLETE_EOF, ast_cli_completion_matches(), ast_malloc, ast_realloc, free, len, RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00812 { 00813 char *buf, *obuf; 00814 int buflen = 2048; 00815 int len = 0; 00816 char **matches; 00817 int x, matchlen; 00818 00819 if (argc != 4) 00820 return RESULT_SHOWUSAGE; 00821 if (!(buf = ast_malloc(buflen))) 00822 return RESULT_FAILURE; 00823 buf[len] = '\0'; 00824 matches = ast_cli_completion_matches(argv[2], argv[3]); 00825 if (matches) { 00826 for (x=0; matches[x]; x++) { 00827 matchlen = strlen(matches[x]) + 1; 00828 if (len + matchlen >= buflen) { 00829 buflen += matchlen * 3; 00830 obuf = buf; 00831 if (!(buf = ast_realloc(obuf, buflen))) 00832 /* Memory allocation failure... Just free old buffer and be done */ 00833 free(obuf); 00834 } 00835 if (buf) 00836 len += sprintf( buf + len, "%s ", matches[x]); 00837 free(matches[x]); 00838 matches[x] = NULL; 00839 } 00840 free(matches); 00841 } 00842 00843 if (buf) { 00844 ast_cli(fd, "%s%s",buf, AST_CLI_COMPLETE_EOF); 00845 free(buf); 00846 } else 00847 ast_cli(fd, "NULL\n"); 00848 00849 return RESULT_SUCCESS; 00850 }
static int handle_commandnummatches | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 854 of file cli.c.
References ast_cli(), ast_cli_generatornummatches(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00855 { 00856 int matches = 0; 00857 00858 if (argc != 4) 00859 return RESULT_SHOWUSAGE; 00860 00861 matches = ast_cli_generatornummatches(argv[2], argv[3]); 00862 00863 ast_cli(fd, "%d", matches); 00864 00865 return RESULT_SUCCESS; 00866 }
static int handle_core_set_debug_channel | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 917 of file cli.c.
References ast_channel_unlock, ast_channel_walk_locked(), ast_cli(), ast_get_channel_by_name_locked(), DEBUGCHAN_FLAG, ast_channel::fin, ast_channel::fout, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00918 { 00919 struct ast_channel *c = NULL; 00920 int is_all, is_off = 0; 00921 00922 /* 'core set debug channel {all|chan_id}' */ 00923 if (argc == 6 && strcmp(argv[5], "off") == 0) 00924 is_off = 1; 00925 else if (argc != 5) 00926 return RESULT_SHOWUSAGE; 00927 00928 is_all = !strcasecmp("all", argv[4]); 00929 if (is_all) { 00930 if (is_off) { 00931 global_fin &= ~DEBUGCHAN_FLAG; 00932 global_fout &= ~DEBUGCHAN_FLAG; 00933 } else { 00934 global_fin |= DEBUGCHAN_FLAG; 00935 global_fout |= DEBUGCHAN_FLAG; 00936 } 00937 c = ast_channel_walk_locked(NULL); 00938 } else { 00939 c = ast_get_channel_by_name_locked(argv[4]); 00940 if (c == NULL) 00941 ast_cli(fd, "No such channel %s\n", argv[4]); 00942 } 00943 while (c) { 00944 if (!(c->fin & DEBUGCHAN_FLAG) || !(c->fout & DEBUGCHAN_FLAG)) { 00945 if (is_off) { 00946 c->fin &= ~DEBUGCHAN_FLAG; 00947 c->fout &= ~DEBUGCHAN_FLAG; 00948 } else { 00949 c->fin |= DEBUGCHAN_FLAG; 00950 c->fout |= DEBUGCHAN_FLAG; 00951 } 00952 ast_cli(fd, "Debugging %s on channel %s\n", is_off ? "disabled" : "enabled", c->name); 00953 } 00954 ast_channel_unlock(c); 00955 if (!is_all) 00956 break; 00957 c = ast_channel_walk_locked(c); 00958 } 00959 ast_cli(fd, "Debugging on new channels is %s\n", is_off ? "disabled" : "enabled"); 00960 return RESULT_SUCCESS; 00961 }
static int handle_debugchan_deprecated | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 883 of file cli.c.
References ast_channel_unlock, ast_channel_walk_locked(), ast_cli(), ast_get_channel_by_name_locked(), DEBUGCHAN_FLAG, ast_channel::fin, ast_channel::fout, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00884 { 00885 struct ast_channel *c=NULL; 00886 int is_all; 00887 00888 /* 'debug channel {all|chan_id}' */ 00889 if (argc != 3) 00890 return RESULT_SHOWUSAGE; 00891 00892 is_all = !strcasecmp("all", argv[2]); 00893 if (is_all) { 00894 global_fin |= DEBUGCHAN_FLAG; 00895 global_fout |= DEBUGCHAN_FLAG; 00896 c = ast_channel_walk_locked(NULL); 00897 } else { 00898 c = ast_get_channel_by_name_locked(argv[2]); 00899 if (c == NULL) 00900 ast_cli(fd, "No such channel %s\n", argv[2]); 00901 } 00902 while (c) { 00903 if (!(c->fin & DEBUGCHAN_FLAG) || !(c->fout & DEBUGCHAN_FLAG)) { 00904 c->fin |= DEBUGCHAN_FLAG; 00905 c->fout |= DEBUGCHAN_FLAG; 00906 ast_cli(fd, "Debugging enabled on channel %s\n", c->name); 00907 } 00908 ast_channel_unlock(c); 00909 if (!is_all) 00910 break; 00911 c = ast_channel_walk_locked(c); 00912 } 00913 ast_cli(fd, "Debugging on new channels is enabled\n"); 00914 return RESULT_SUCCESS; 00915 }
static int handle_debuglevel_deprecated | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 384 of file cli.c.
References ast_cli(), debug_filename, option_debug, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00385 { 00386 int newlevel; 00387 char *filename = "<any>"; 00388 if ((argc < 3) || (argc > 4)) 00389 return RESULT_SHOWUSAGE; 00390 if (sscanf(argv[2], "%d", &newlevel) != 1) 00391 return RESULT_SHOWUSAGE; 00392 option_debug = newlevel; 00393 if (argc == 4) { 00394 filename = argv[3]; 00395 ast_copy_string(debug_filename, filename, sizeof(debug_filename)); 00396 } else { 00397 debug_filename[0] = '\0'; 00398 } 00399 ast_cli(fd, "Debugging level set to %d, file '%s'\n", newlevel, filename); 00400 return RESULT_SUCCESS; 00401 }
static int handle_help | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 1769 of file cli.c.
References ast_cli(), ast_join(), AST_LIST_LOCK, AST_LIST_UNLOCK, find_cli(), help1(), help_workhorse(), RESULT_SHOWUSAGE, RESULT_SUCCESS, and ast_cli_entry::usage.
01770 { 01771 char fullcmd[80]; 01772 struct ast_cli_entry *e; 01773 int res = RESULT_SUCCESS; 01774 01775 if (argc < 1) 01776 return RESULT_SHOWUSAGE; 01777 if (argc == 1) 01778 return help_workhorse(fd, NULL); 01779 01780 AST_LIST_LOCK(&helpers); 01781 e = find_cli(argv + 1, 1); /* try exact match first */ 01782 if (!e) { 01783 res = help1(fd, argv + 1, 1 /* locked */); 01784 AST_LIST_UNLOCK(&helpers); 01785 return res; 01786 } 01787 if (e->usage) 01788 ast_cli(fd, "%s", e->usage); 01789 else { 01790 ast_join(fullcmd, sizeof(fullcmd), argv+1); 01791 ast_cli(fd, "No help text available for '%s'.\n", fullcmd); 01792 } 01793 AST_LIST_UNLOCK(&helpers); 01794 return res; 01795 }
static int handle_load | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 152 of file cli.c.
References ast_cli(), ast_load_resource(), RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00153 { 00154 if (argc != 3) 00155 return RESULT_SHOWUSAGE; 00156 if (ast_load_resource(argv[2])) { 00157 ast_cli(fd, "Unable to load module %s\n", argv[2]); 00158 return RESULT_FAILURE; 00159 } 00160 return RESULT_SUCCESS; 00161 }
static int handle_load_deprecated | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 141 of file cli.c.
References ast_cli(), ast_load_resource(), RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00142 { 00143 if (argc != 2) 00144 return RESULT_SHOWUSAGE; 00145 if (ast_load_resource(argv[1])) { 00146 ast_cli(fd, "Unable to load module %s\n", argv[1]); 00147 return RESULT_FAILURE; 00148 } 00149 return RESULT_SUCCESS; 00150 }
static int handle_logger_mute | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 403 of file cli.c.
References ast_console_toggle_mute(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00404 { 00405 if (argc < 2 || argc > 3) 00406 return RESULT_SHOWUSAGE; 00407 if (argc == 3 && !strcasecmp(argv[2], "silent")) 00408 ast_console_toggle_mute(fd, 1); 00409 else 00410 ast_console_toggle_mute(fd, 0); 00411 return RESULT_SUCCESS; 00412 }
static int handle_modlist | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 577 of file cli.c.
References ast_cli(), ast_mutex_lock(), ast_mutex_unlock(), ast_update_module_list(), MODLIST_FORMAT2, modlist_modentry(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00578 { 00579 char *like = ""; 00580 if (argc == 3) 00581 return RESULT_SHOWUSAGE; 00582 else if (argc >= 4) { 00583 if (strcmp(argv[2],"like")) 00584 return RESULT_SHOWUSAGE; 00585 like = argv[3]; 00586 } 00587 00588 ast_mutex_lock(&climodentrylock); 00589 climodentryfd = fd; /* global, protected by climodentrylock */ 00590 ast_cli(fd, MODLIST_FORMAT2, "Module", "Description", "Use Count"); 00591 ast_cli(fd,"%d modules loaded\n", ast_update_module_list(modlist_modentry, like)); 00592 climodentryfd = -1; 00593 ast_mutex_unlock(&climodentrylock); 00594 return RESULT_SUCCESS; 00595 }
static int handle_nodebug | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 370 of file cli.c.
References ast_cli(), debug_filename, option_debug, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00371 { 00372 int oldval = option_debug; 00373 if (argc != 4) 00374 return RESULT_SHOWUSAGE; 00375 00376 option_debug = 0; 00377 debug_filename[0] = '\0'; 00378 00379 if (oldval > 0) 00380 ast_cli(fd, "Core debug is now OFF\n"); 00381 return RESULT_SUCCESS; 00382 }
static int handle_nodebugchan_deprecated | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 963 of file cli.c.
References ast_channel_unlock, ast_channel_walk_locked(), ast_cli(), ast_get_channel_by_name_locked(), DEBUGCHAN_FLAG, ast_channel::fin, ast_channel::fout, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00964 { 00965 struct ast_channel *c=NULL; 00966 int is_all; 00967 /* 'no debug channel {all|chan_id}' */ 00968 if (argc != 4) 00969 return RESULT_SHOWUSAGE; 00970 is_all = !strcasecmp("all", argv[3]); 00971 if (is_all) { 00972 global_fin &= ~DEBUGCHAN_FLAG; 00973 global_fout &= ~DEBUGCHAN_FLAG; 00974 c = ast_channel_walk_locked(NULL); 00975 } else { 00976 c = ast_get_channel_by_name_locked(argv[3]); 00977 if (c == NULL) 00978 ast_cli(fd, "No such channel %s\n", argv[3]); 00979 } 00980 while(c) { 00981 if ((c->fin & DEBUGCHAN_FLAG) || (c->fout & DEBUGCHAN_FLAG)) { 00982 c->fin &= ~DEBUGCHAN_FLAG; 00983 c->fout &= ~DEBUGCHAN_FLAG; 00984 ast_cli(fd, "Debugging disabled on channel %s\n", c->name); 00985 } 00986 ast_channel_unlock(c); 00987 if (!is_all) 00988 break; 00989 c = ast_channel_walk_locked(c); 00990 } 00991 ast_cli(fd, "Debugging on new channels is disabled\n"); 00992 return RESULT_SUCCESS; 00993 }
static int handle_reload | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 186 of file cli.c.
References ast_cli(), ast_module_reload(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00187 { 00188 int x; 00189 int res; 00190 if (argc < 2) 00191 return RESULT_SHOWUSAGE; 00192 if (argc > 2) { 00193 for (x = 2; x < argc; x++) { 00194 res = ast_module_reload(argv[x]); 00195 switch(res) { 00196 case 0: 00197 ast_cli(fd, "No such module '%s'\n", argv[x]); 00198 break; 00199 case 1: 00200 ast_cli(fd, "Module '%s' does not support reload\n", argv[x]); 00201 break; 00202 } 00203 } 00204 } else 00205 ast_module_reload(NULL); 00206 return RESULT_SUCCESS; 00207 }
static int handle_reload_deprecated | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 163 of file cli.c.
References ast_cli(), ast_module_reload(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00164 { 00165 int x; 00166 int res; 00167 if (argc < 1) 00168 return RESULT_SHOWUSAGE; 00169 if (argc > 1) { 00170 for (x = 1; x < argc; x++) { 00171 res = ast_module_reload(argv[x]); 00172 switch(res) { 00173 case 0: 00174 ast_cli(fd, "No such module '%s'\n", argv[x]); 00175 break; 00176 case 1: 00177 ast_cli(fd, "Module '%s' does not support reload\n", argv[x]); 00178 break; 00179 } 00180 } 00181 } else 00182 ast_module_reload(NULL); 00183 return RESULT_SUCCESS; 00184 }
static int handle_set_debug | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 300 of file cli.c.
References ast_cli(), debug_filename, option_debug, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00301 { 00302 int oldval = option_debug; 00303 int newlevel; 00304 int atleast = 0; 00305 char *filename = '\0'; 00306 00307 /* 'core set debug <level>' 00308 * 'core set debug <level> <fn>' 00309 * 'core set debug atleast <level>' 00310 * 'core set debug atleast <level> <fn>' 00311 */ 00312 if ((argc < 4) || (argc > 6)) 00313 return RESULT_SHOWUSAGE; 00314 00315 if (!strcasecmp(argv[3], "atleast")) 00316 atleast = 1; 00317 00318 if (!atleast) { 00319 if (argc > 5) 00320 return RESULT_SHOWUSAGE; 00321 00322 if (sscanf(argv[3], "%d", &newlevel) != 1) 00323 return RESULT_SHOWUSAGE; 00324 00325 if (argc == 4) { 00326 debug_filename[0] = '\0'; 00327 } else { 00328 filename = argv[4]; 00329 ast_copy_string(debug_filename, filename, sizeof(debug_filename)); 00330 } 00331 00332 option_debug = newlevel; 00333 } else { 00334 if (argc < 5 || argc > 6) 00335 return RESULT_SHOWUSAGE; 00336 00337 if (sscanf(argv[4], "%d", &newlevel) != 1) 00338 return RESULT_SHOWUSAGE; 00339 00340 if (argc == 5) { 00341 debug_filename[0] = '\0'; 00342 } else { 00343 filename = argv[5]; 00344 ast_copy_string(debug_filename, filename, sizeof(debug_filename)); 00345 } 00346 00347 if (newlevel > option_debug) 00348 option_debug = newlevel; 00349 } 00350 00351 if (oldval > 0 && option_debug == 0) 00352 ast_cli(fd, "Core debug is now OFF\n"); 00353 else if (option_debug > 0) { 00354 if (filename) { 00355 if (oldval == option_debug) 00356 ast_cli(fd, "Core debug is at least %d, file '%s'\n", option_debug, filename); 00357 else 00358 ast_cli(fd, "Core debug was %d and is now %d, file '%s'\n", oldval, option_debug, filename); 00359 } else { 00360 if (oldval == option_debug) 00361 ast_cli(fd, "Core debug is at least %d\n", option_debug); 00362 else 00363 ast_cli(fd, "Core debug was %d and is now %d\n", oldval, option_debug); 00364 } 00365 } 00366 00367 return RESULT_SUCCESS; 00368 }
static int handle_set_debug_deprecated | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 273 of file cli.c.
References ast_cli(), option_debug, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00274 { 00275 int val = 0; 00276 int oldval = option_debug; 00277 00278 /* "set debug [atleast] N" */ 00279 if (argc == 3) 00280 option_debug = atoi(argv[2]); 00281 else if (argc == 4) { 00282 if (strcasecmp(argv[2], "atleast")) 00283 return RESULT_SHOWUSAGE; 00284 val = atoi(argv[3]); 00285 if (val > option_debug) 00286 option_debug = val; 00287 } else 00288 return RESULT_SHOWUSAGE; 00289 00290 if (oldval != option_debug && option_debug > 0) 00291 ast_cli(fd, "Core debug was %d and is now %d\n", oldval, option_debug); 00292 else if (oldval > 0 && option_debug > 0) 00293 ast_cli(fd, "Core debug is at least %d\n", option_debug); 00294 else if (oldval > 0 && option_debug == 0) 00295 ast_cli(fd, "Core debug is now OFF\n"); 00296 00297 return RESULT_SUCCESS; 00298 }
static int handle_set_verbose_deprecated | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 209 of file cli.c.
References ast_cli(), option_verbose, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00210 { 00211 int val = 0; 00212 int oldval = option_verbose; 00213 00214 /* "set verbose [atleast] N" */ 00215 if (argc == 3) 00216 option_verbose = atoi(argv[2]); 00217 else if (argc == 4) { 00218 if (strcasecmp(argv[2], "atleast")) 00219 return RESULT_SHOWUSAGE; 00220 val = atoi(argv[3]); 00221 if (val > option_verbose) 00222 option_verbose = val; 00223 } else 00224 return RESULT_SHOWUSAGE; 00225 00226 if (oldval != option_verbose && option_verbose > 0) 00227 ast_cli(fd, "Verbosity was %d and is now %d\n", oldval, option_verbose); 00228 else if (oldval > 0 && option_verbose > 0) 00229 ast_cli(fd, "Verbosity is at least %d\n", option_verbose); 00230 else if (oldval > 0 && option_verbose == 0) 00231 ast_cli(fd, "Verbosity is now OFF\n"); 00232 00233 return RESULT_SUCCESS; 00234 }
static int handle_showchan | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 1079 of file cli.c.
References ast_channel::_bridge, ast_channel::_state, ast_channel::appl, ast_bridged_channel(), ast_cdr_serialize_variables(), ast_channel_unlock, ast_cli(), AST_FLAG_BLOCKING, ast_get_channel_by_name_locked(), ast_getformatname_multiple(), ast_state2str(), ast_test_flag, ast_channel::blockproc, ast_channel::callgroup, ast_channel::cdr, ast_channel::cid, ast_callerid::cid_dnid, ast_callerid::cid_name, ast_callerid::cid_num, ast_channel::context, ast_channel::data, DEBUGCHAN_FLAG, ast_channel::exten, ast_channel::fds, ast_channel::fin, ast_channel::fout, name, ast_channel::nativeformats, pbx_builtin_serialize_variables(), ast_channel::pickupgroup, ast_channel::priority, ast_channel::readformat, ast_channel::readtrans, RESULT_SHOWUSAGE, RESULT_SUCCESS, ast_channel::rings, S_OR, ast_cdr::start, ast_channel::tech, ast_channel_tech::type, ast_channel::whentohangup, ast_channel::writeformat, and ast_channel::writetrans.
01080 { 01081 struct ast_channel *c=NULL; 01082 struct timeval now; 01083 char buf[2048]; 01084 char cdrtime[256]; 01085 char nf[256], wf[256], rf[256]; 01086 long elapsed_seconds=0; 01087 int hour=0, min=0, sec=0; 01088 01089 if (argc != 4) 01090 return RESULT_SHOWUSAGE; 01091 now = ast_tvnow(); 01092 c = ast_get_channel_by_name_locked(argv[3]); 01093 if (!c) { 01094 ast_cli(fd, "%s is not a known channel\n", argv[3]); 01095 return RESULT_SUCCESS; 01096 } 01097 if(c->cdr) { 01098 elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec; 01099 hour = elapsed_seconds / 3600; 01100 min = (elapsed_seconds % 3600) / 60; 01101 sec = elapsed_seconds % 60; 01102 snprintf(cdrtime, sizeof(cdrtime), "%dh%dm%ds", hour, min, sec); 01103 } else 01104 strcpy(cdrtime, "N/A"); 01105 ast_cli(fd, 01106 " -- General --\n" 01107 " Name: %s\n" 01108 " Type: %s\n" 01109 " UniqueID: %s\n" 01110 " Caller ID: %s\n" 01111 " Caller ID Name: %s\n" 01112 " DNID Digits: %s\n" 01113 " State: %s (%d)\n" 01114 " Rings: %d\n" 01115 " NativeFormats: %s\n" 01116 " WriteFormat: %s\n" 01117 " ReadFormat: %s\n" 01118 " WriteTranscode: %s\n" 01119 " ReadTranscode: %s\n" 01120 "1st File Descriptor: %d\n" 01121 " Frames in: %d%s\n" 01122 " Frames out: %d%s\n" 01123 " Time to Hangup: %ld\n" 01124 " Elapsed Time: %s\n" 01125 " Direct Bridge: %s\n" 01126 "Indirect Bridge: %s\n" 01127 " -- PBX --\n" 01128 " Context: %s\n" 01129 " Extension: %s\n" 01130 " Priority: %d\n" 01131 " Call Group: %llu\n" 01132 " Pickup Group: %llu\n" 01133 " Application: %s\n" 01134 " Data: %s\n" 01135 " Blocking in: %s\n", 01136 c->name, c->tech->type, c->uniqueid, 01137 S_OR(c->cid.cid_num, "(N/A)"), 01138 S_OR(c->cid.cid_name, "(N/A)"), 01139 S_OR(c->cid.cid_dnid, "(N/A)"), ast_state2str(c->_state), c->_state, c->rings, 01140 ast_getformatname_multiple(nf, sizeof(nf), c->nativeformats), 01141 ast_getformatname_multiple(wf, sizeof(wf), c->writeformat), 01142 ast_getformatname_multiple(rf, sizeof(rf), c->readformat), 01143 c->writetrans ? "Yes" : "No", 01144 c->readtrans ? "Yes" : "No", 01145 c->fds[0], 01146 c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "", 01147 c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "", 01148 (long)c->whentohangup, 01149 cdrtime, c->_bridge ? c->_bridge->name : "<none>", ast_bridged_channel(c) ? ast_bridged_channel(c)->name : "<none>", 01150 c->context, c->exten, c->priority, c->callgroup, c->pickupgroup, ( c->appl ? c->appl : "(N/A)" ), 01151 ( c-> data ? S_OR(c->data, "(Empty)") : "(None)"), 01152 (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)")); 01153 01154 if(pbx_builtin_serialize_variables(c,buf,sizeof(buf))) 01155 ast_cli(fd," Variables:\n%s\n",buf); 01156 if(c->cdr && ast_cdr_serialize_variables(c->cdr,buf, sizeof(buf), '=', '\n', 1)) 01157 ast_cli(fd," CDR Variables:\n%s\n",buf); 01158 01159 ast_channel_unlock(c); 01160 return RESULT_SUCCESS; 01161 }
static int handle_showchan_deprecated | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 995 of file cli.c.
References ast_channel::_bridge, ast_channel::_state, ast_channel::appl, ast_bridged_channel(), ast_cdr_serialize_variables(), ast_channel_unlock, ast_cli(), AST_FLAG_BLOCKING, ast_get_channel_by_name_locked(), ast_getformatname_multiple(), ast_state2str(), ast_test_flag, ast_channel::blockproc, ast_channel::callgroup, ast_channel::cdr, ast_channel::cid, ast_callerid::cid_dnid, ast_callerid::cid_name, ast_callerid::cid_num, ast_channel::context, ast_channel::data, DEBUGCHAN_FLAG, ast_channel::exten, ast_channel::fds, ast_channel::fin, ast_channel::fout, name, ast_channel::nativeformats, pbx_builtin_serialize_variables(), ast_channel::pickupgroup, ast_channel::priority, ast_channel::readformat, ast_channel::readtrans, RESULT_SHOWUSAGE, RESULT_SUCCESS, ast_channel::rings, S_OR, ast_cdr::start, ast_channel::tech, ast_channel_tech::type, ast_channel::whentohangup, ast_channel::writeformat, and ast_channel::writetrans.
00996 { 00997 struct ast_channel *c=NULL; 00998 struct timeval now; 00999 char buf[2048]; 01000 char cdrtime[256]; 01001 char nf[256], wf[256], rf[256]; 01002 long elapsed_seconds=0; 01003 int hour=0, min=0, sec=0; 01004 01005 if (argc != 3) 01006 return RESULT_SHOWUSAGE; 01007 now = ast_tvnow(); 01008 c = ast_get_channel_by_name_locked(argv[2]); 01009 if (!c) { 01010 ast_cli(fd, "%s is not a known channel\n", argv[2]); 01011 return RESULT_SUCCESS; 01012 } 01013 if(c->cdr) { 01014 elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec; 01015 hour = elapsed_seconds / 3600; 01016 min = (elapsed_seconds % 3600) / 60; 01017 sec = elapsed_seconds % 60; 01018 snprintf(cdrtime, sizeof(cdrtime), "%dh%dm%ds", hour, min, sec); 01019 } else 01020 strcpy(cdrtime, "N/A"); 01021 ast_cli(fd, 01022 " -- General --\n" 01023 " Name: %s\n" 01024 " Type: %s\n" 01025 " UniqueID: %s\n" 01026 " Caller ID: %s\n" 01027 " Caller ID Name: %s\n" 01028 " DNID Digits: %s\n" 01029 " State: %s (%d)\n" 01030 " Rings: %d\n" 01031 " NativeFormats: %s\n" 01032 " WriteFormat: %s\n" 01033 " ReadFormat: %s\n" 01034 " WriteTranscode: %s\n" 01035 " ReadTranscode: %s\n" 01036 "1st File Descriptor: %d\n" 01037 " Frames in: %d%s\n" 01038 " Frames out: %d%s\n" 01039 " Time to Hangup: %ld\n" 01040 " Elapsed Time: %s\n" 01041 " Direct Bridge: %s\n" 01042 "Indirect Bridge: %s\n" 01043 " -- PBX --\n" 01044 " Context: %s\n" 01045 " Extension: %s\n" 01046 " Priority: %d\n" 01047 " Call Group: %llu\n" 01048 " Pickup Group: %llu\n" 01049 " Application: %s\n" 01050 " Data: %s\n" 01051 " Blocking in: %s\n", 01052 c->name, c->tech->type, c->uniqueid, 01053 S_OR(c->cid.cid_num, "(N/A)"), 01054 S_OR(c->cid.cid_name, "(N/A)"), 01055 S_OR(c->cid.cid_dnid, "(N/A)"), ast_state2str(c->_state), c->_state, c->rings, 01056 ast_getformatname_multiple(nf, sizeof(nf), c->nativeformats), 01057 ast_getformatname_multiple(wf, sizeof(wf), c->writeformat), 01058 ast_getformatname_multiple(rf, sizeof(rf), c->readformat), 01059 c->writetrans ? "Yes" : "No", 01060 c->readtrans ? "Yes" : "No", 01061 c->fds[0], 01062 c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "", 01063 c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "", 01064 (long)c->whentohangup, 01065 cdrtime, c->_bridge ? c->_bridge->name : "<none>", ast_bridged_channel(c) ? ast_bridged_channel(c)->name : "<none>", 01066 c->context, c->exten, c->priority, c->callgroup, c->pickupgroup, ( c->appl ? c->appl : "(N/A)" ), 01067 ( c-> data ? S_OR(c->data, "(Empty)") : "(None)"), 01068 (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)")); 01069 01070 if(pbx_builtin_serialize_variables(c,buf,sizeof(buf))) 01071 ast_cli(fd," Variables:\n%s\n",buf); 01072 if(c->cdr && ast_cdr_serialize_variables(c->cdr,buf, sizeof(buf), '=', '\n', 1)) 01073 ast_cli(fd," CDR Variables:\n%s\n",buf); 01074 01075 ast_channel_unlock(c); 01076 return RESULT_SUCCESS; 01077 }
static int handle_showuptime | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 562 of file cli.c.
References ast_lastreloadtime, ast_startuptime, print_uptimestr(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00563 { 00564 /* 'core show uptime [seconds]' */ 00565 time_t curtime = time(NULL); 00566 int printsec = (argc == 4 && !strcasecmp(argv[3],"seconds")); 00567 00568 if (argc != 3 && !printsec) 00569 return RESULT_SHOWUSAGE; 00570 if (ast_startuptime) 00571 print_uptimestr(fd, curtime - ast_startuptime, "System uptime", printsec); 00572 if (ast_lastreloadtime) 00573 print_uptimestr(fd, curtime - ast_lastreloadtime, "Last reload", printsec); 00574 return RESULT_SUCCESS; 00575 }
static int handle_showuptime_deprecated | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 547 of file cli.c.
References ast_lastreloadtime, ast_startuptime, print_uptimestr(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00548 { 00549 /* 'show uptime [seconds]' */ 00550 time_t curtime = time(NULL); 00551 int printsec = (argc == 3 && !strcasecmp(argv[2],"seconds")); 00552 00553 if (argc != 2 && !printsec) 00554 return RESULT_SHOWUSAGE; 00555 if (ast_startuptime) 00556 print_uptimestr(fd, curtime - ast_startuptime, "System uptime", printsec); 00557 if (ast_lastreloadtime) 00558 print_uptimestr(fd, curtime - ast_lastreloadtime, "Last reload", printsec); 00559 return RESULT_SUCCESS; 00560 }
static int handle_softhangup | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 794 of file cli.c.
References ast_channel_unlock, ast_cli(), ast_get_channel_by_name_locked(), ast_softhangup(), AST_SOFTHANGUP_EXPLICIT, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00795 { 00796 struct ast_channel *c=NULL; 00797 if (argc != 3) 00798 return RESULT_SHOWUSAGE; 00799 c = ast_get_channel_by_name_locked(argv[2]); 00800 if (c) { 00801 ast_cli(fd, "Requested Hangup on channel '%s'\n", c->name); 00802 ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT); 00803 ast_channel_unlock(c); 00804 } else 00805 ast_cli(fd, "%s is not a known channel\n", argv[2]); 00806 return RESULT_SUCCESS; 00807 }
static int handle_unload | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 442 of file cli.c.
References ast_cli(), AST_FORCE_FIRM, AST_FORCE_HARD, AST_FORCE_SOFT, ast_unload_resource(), RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00443 { 00444 int x; 00445 int force = AST_FORCE_SOFT; 00446 if (argc < 3) 00447 return RESULT_SHOWUSAGE; 00448 for (x = 2; x < argc; x++) { 00449 if (argv[x][0] == '-') { 00450 switch(argv[x][1]) { 00451 case 'f': 00452 force = AST_FORCE_FIRM; 00453 break; 00454 case 'h': 00455 force = AST_FORCE_HARD; 00456 break; 00457 default: 00458 return RESULT_SHOWUSAGE; 00459 } 00460 } else if (x != argc - 1) 00461 return RESULT_SHOWUSAGE; 00462 else if (ast_unload_resource(argv[x], force)) { 00463 ast_cli(fd, "Unable to unload resource %s\n", argv[x]); 00464 return RESULT_FAILURE; 00465 } 00466 } 00467 return RESULT_SUCCESS; 00468 }
static int handle_unload_deprecated | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 414 of file cli.c.
References ast_cli(), AST_FORCE_FIRM, AST_FORCE_HARD, AST_FORCE_SOFT, ast_unload_resource(), RESULT_FAILURE, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00415 { 00416 int x; 00417 int force = AST_FORCE_SOFT; 00418 if (argc < 2) 00419 return RESULT_SHOWUSAGE; 00420 for (x = 1; x < argc; x++) { 00421 if (argv[x][0] == '-') { 00422 switch(argv[x][1]) { 00423 case 'f': 00424 force = AST_FORCE_FIRM; 00425 break; 00426 case 'h': 00427 force = AST_FORCE_HARD; 00428 break; 00429 default: 00430 return RESULT_SHOWUSAGE; 00431 } 00432 } else if (x != argc - 1) 00433 return RESULT_SHOWUSAGE; 00434 else if (ast_unload_resource(argv[x], force)) { 00435 ast_cli(fd, "Unable to unload resource %s\n", argv[x]); 00436 return RESULT_FAILURE; 00437 } 00438 } 00439 return RESULT_SUCCESS; 00440 }
static int handle_verbose | ( | int | fd, | |
int | argc, | |||
char * | argv[] | |||
) | [static] |
Definition at line 236 of file cli.c.
References ast_cli(), option_verbose, RESULT_SHOWUSAGE, and RESULT_SUCCESS.
00237 { 00238 int oldval = option_verbose; 00239 int newlevel; 00240 int atleast = 0; 00241 00242 if ((argc < 4) || (argc > 5)) 00243 return RESULT_SHOWUSAGE; 00244 00245 if (!strcasecmp(argv[3], "atleast")) 00246 atleast = 1; 00247 00248 if (!atleast) { 00249 if (argc > 4) 00250 return RESULT_SHOWUSAGE; 00251 00252 option_verbose = atoi(argv[3]); 00253 } else { 00254 if (argc < 5) 00255 return RESULT_SHOWUSAGE; 00256 00257 newlevel = atoi(argv[4]); 00258 if (newlevel > option_verbose) 00259 option_verbose = newlevel; 00260 } 00261 if (oldval > 0 && option_verbose == 0) 00262 ast_cli(fd, "Verbosity is now OFF\n"); 00263 else if (option_verbose > 0) { 00264 if (oldval == option_verbose) 00265 ast_cli(fd, "Verbosity is at least %d\n", option_verbose); 00266 else 00267 ast_cli(fd, "Verbosity was %d and is now %d\n", oldval, option_verbose); 00268 } 00269 00270 return RESULT_SUCCESS; 00271 }
static int help1 | ( | int | fd, | |
char * | match[], | |||
int | locked | |||
) | [static] |
helper for help_workhorse and final part of handle_help if locked = 0 it's just help_workhorse, otherwise assume the list is already locked.
Definition at line 1731 of file cli.c.
References ast_cli_entry::_full_cmd, ast_cli(), ast_join(), AST_LIST_LOCK, AST_LIST_UNLOCK, cli_next(), ast_cli_entry::deprecated, cli_iterator::helpers, len, RESULT_SUCCESS, S_OR, and ast_cli_entry::summary.
Referenced by handle_help(), and help_workhorse().
01732 { 01733 char matchstr[80] = ""; 01734 struct ast_cli_entry *e; 01735 int len = 0; 01736 int found = 0; 01737 struct cli_iterator i = { NULL, NULL}; 01738 01739 if (match) { 01740 ast_join(matchstr, sizeof(matchstr), match); 01741 len = strlen(matchstr); 01742 } 01743 if (!locked) 01744 AST_LIST_LOCK(&helpers); 01745 while ( (e = cli_next(&i)) ) { 01746 /* Hide commands that start with '_' */ 01747 if (e->_full_cmd[0] == '_') 01748 continue; 01749 /* Hide commands that are marked as deprecated. */ 01750 if (e->deprecated) 01751 continue; 01752 if (match && strncasecmp(matchstr, e->_full_cmd, len)) 01753 continue; 01754 ast_cli(fd, "%25.25s %s\n", e->_full_cmd, S_OR(e->summary, "")); 01755 found++; 01756 } 01757 if (!locked) 01758 AST_LIST_UNLOCK(&helpers); 01759 if (!found && matchstr[0]) 01760 ast_cli(fd, "No such command '%s'.\n", matchstr); 01761 return RESULT_SUCCESS; 01762 }
static int help_workhorse | ( | int | fd, | |
char * | match[] | |||
) | [static] |
Definition at line 1764 of file cli.c.
References help1().
Referenced by handle_help(), and handle_showagi().
static int modlist_modentry | ( | const char * | module, | |
const char * | description, | |||
int | usecnt, | |||
const char * | like | |||
) | [static] |
Definition at line 476 of file cli.c.
References ast_cli(), MODLIST_FORMAT, and strcasestr().
Referenced by handle_modlist().
00477 { 00478 /* Comparing the like with the module */ 00479 if (strcasestr(module, like) ) { 00480 ast_cli(climodentryfd, MODLIST_FORMAT, module, description, usecnt); 00481 return 1; 00482 } 00483 return 0; 00484 }
static char* parse_args | ( | const char * | s, | |
int * | argc, | |||
char * | argv[], | |||
int | max, | |||
int * | trailingwhitespace | |||
) | [static] |
Definition at line 1797 of file cli.c.
References ast_log(), ast_strdup, and LOG_WARNING.
Referenced by __ast_cli_generator(), agi_handle_command(), and ast_cli_command().
01798 { 01799 char *dup, *cur; 01800 int x = 0; 01801 int quoted = 0; 01802 int escaped = 0; 01803 int whitespace = 1; 01804 01805 *trailingwhitespace = 0; 01806 if (s == NULL) /* invalid, though! */ 01807 return NULL; 01808 /* make a copy to store the parsed string */ 01809 if (!(dup = ast_strdup(s))) 01810 return NULL; 01811 01812 cur = dup; 01813 /* scan the original string copying into cur when needed */ 01814 for (; *s ; s++) { 01815 if (x >= max - 1) { 01816 ast_log(LOG_WARNING, "Too many arguments, truncating at %s\n", s); 01817 break; 01818 } 01819 if (*s == '"' && !escaped) { 01820 quoted = !quoted; 01821 if (quoted && whitespace) { 01822 /* start a quoted string from previous whitespace: new argument */ 01823 argv[x++] = cur; 01824 whitespace = 0; 01825 } 01826 } else if ((*s == ' ' || *s == '\t') && !(quoted || escaped)) { 01827 /* If we are not already in whitespace, and not in a quoted string or 01828 processing an escape sequence, and just entered whitespace, then 01829 finalize the previous argument and remember that we are in whitespace 01830 */ 01831 if (!whitespace) { 01832 *cur++ = '\0'; 01833 whitespace = 1; 01834 } 01835 } else if (*s == '\\' && !escaped) { 01836 escaped = 1; 01837 } else { 01838 if (whitespace) { 01839 /* we leave whitespace, and are not quoted. So it's a new argument */ 01840 argv[x++] = cur; 01841 whitespace = 0; 01842 } 01843 *cur++ = *s; 01844 escaped = 0; 01845 } 01846 } 01847 /* Null terminate */ 01848 *cur++ = '\0'; 01849 /* XXX put a NULL in the last argument, because some functions that take 01850 * the array may want a null-terminated array. 01851 * argc still reflects the number of non-NULL entries. 01852 */ 01853 argv[x] = NULL; 01854 *argc = x; 01855 *trailingwhitespace = whitespace; 01856 return dup; 01857 }
static void print_uptimestr | ( | int | fd, | |
time_t | timeval, | |||
const char * | prefix, | |||
int | printsec | |||
) | [static] |
Definition at line 495 of file cli.c.
References ast_build_string(), ast_cli(), DAY, ESS, HOUR, MINUTE, NEEDCOMMA, s, WEEK, and YEAR.
Referenced by handle_showuptime(), and handle_showuptime_deprecated().
00496 { 00497 int x; /* the main part - years, weeks, etc. */ 00498 char timestr[256]="", *s = timestr; 00499 size_t maxbytes = sizeof(timestr); 00500 00501 #define SECOND (1) 00502 #define MINUTE (SECOND*60) 00503 #define HOUR (MINUTE*60) 00504 #define DAY (HOUR*24) 00505 #define WEEK (DAY*7) 00506 #define YEAR (DAY*365) 00507 #define ESS(x) ((x == 1) ? "" : "s") /* plural suffix */ 00508 #define NEEDCOMMA(x) ((x)? ",": "") /* define if we need a comma */ 00509 if (timeval < 0) /* invalid, nothing to show */ 00510 return; 00511 if (printsec) { /* plain seconds output */ 00512 ast_build_string(&s, &maxbytes, "%lu", (u_long)timeval); 00513 timeval = 0; /* bypass the other cases */ 00514 } 00515 if (timeval > YEAR) { 00516 x = (timeval / YEAR); 00517 timeval -= (x * YEAR); 00518 ast_build_string(&s, &maxbytes, "%d year%s%s ", x, ESS(x),NEEDCOMMA(timeval)); 00519 } 00520 if (timeval > WEEK) { 00521 x = (timeval / WEEK); 00522 timeval -= (x * WEEK); 00523 ast_build_string(&s, &maxbytes, "%d week%s%s ", x, ESS(x),NEEDCOMMA(timeval)); 00524 } 00525 if (timeval > DAY) { 00526 x = (timeval / DAY); 00527 timeval -= (x * DAY); 00528 ast_build_string(&s, &maxbytes, "%d day%s%s ", x, ESS(x),NEEDCOMMA(timeval)); 00529 } 00530 if (timeval > HOUR) { 00531 x = (timeval / HOUR); 00532 timeval -= (x * HOUR); 00533 ast_build_string(&s, &maxbytes, "%d hour%s%s ", x, ESS(x),NEEDCOMMA(timeval)); 00534 } 00535 if (timeval > MINUTE) { 00536 x = (timeval / MINUTE); 00537 timeval -= (x * MINUTE); 00538 ast_build_string(&s, &maxbytes, "%d minute%s%s ", x, ESS(x),NEEDCOMMA(timeval)); 00539 } 00540 x = timeval; 00541 if (x > 0) 00542 ast_build_string(&s, &maxbytes, "%d second%s ", x, ESS(x)); 00543 if (timestr[0] != '\0') 00544 ast_cli(fd, "%s: %s\n", prefix, timestr); 00545 }
struct ast_cli_entry builtins[] [static] |
char chanlist_help[] [static] |
struct ast_cli_entry cli_cli[] [static] |
struct ast_cli_entry cli_debug_channel_deprecated [static] |
Initial value:
{ { "debug", "channel", NULL }, handle_debugchan_deprecated, NULL, NULL, complete_ch_3 }
struct ast_cli_entry cli_debug_level_deprecated [static] |
Initial value:
{ { "debug", "level", NULL }, handle_debuglevel_deprecated, NULL, NULL }
struct ast_cli_entry cli_module_load_deprecated [static] |
Initial value:
{ { "load", NULL }, handle_load_deprecated, NULL, NULL, complete_fn_2 }
struct ast_cli_entry cli_module_reload_deprecated [static] |
Initial value:
{ { "reload", NULL }, handle_reload_deprecated, NULL, NULL, complete_mod_2 }
struct ast_cli_entry cli_module_unload_deprecated [static] |
Initial value:
{ { "unload", NULL }, handle_unload_deprecated, NULL, NULL, complete_mod_2 }
struct ast_cli_entry cli_set_debug_deprecated [static] |
Initial value:
{ { "set", "debug", NULL }, handle_set_debug_deprecated, NULL, NULL, NULL, &cli_debug_level_deprecated }
struct ast_cli_entry cli_set_verbose_deprecated [static] |
Initial value:
{ { "set", "verbose", NULL }, handle_set_verbose_deprecated, NULL, NULL }
struct ast_cli_entry cli_show_channel_deprecated [static] |
Initial value:
{ { "show", "channel", NULL }, handle_showchan_deprecated, NULL, NULL, complete_ch_3 }
struct ast_cli_entry cli_show_channels_deprecated [static] |
Initial value:
{ { "show", "channels", NULL }, handle_chanlist_deprecated, NULL, NULL, complete_show_channels_deprecated }
struct ast_cli_entry cli_show_modules_deprecated [static] |
Initial value:
{ { "show", "modules", NULL }, handle_modlist, NULL, NULL }
struct ast_cli_entry cli_show_modules_like_deprecated [static] |
Initial value:
{ { "show", "modules", "like", NULL }, handle_modlist, NULL, NULL, complete_mod_4 }
struct ast_cli_entry cli_show_uptime_deprecated [static] |
Initial value:
{ { "show", "uptime", NULL }, handle_showuptime_deprecated, "Show uptime information", NULL }
int climodentryfd = -1 [static] |
char commandcomplete_help[] [static] |
char commandmatchesarray_help[] [static] |
char commandnummatches_help[] [static] |
char debug_help[] [static] |
char debugchan_help[] [static] |
unsigned long global_fin |
unsigned long global_fout |
char group_show_channels_help[] [static] |
char help_help[] [static] |
char load_help[] [static] |
char logger_mute_help[] [static] |
char modlist_help[] [static] |
char nodebug_help[] [static] |
char reload_help[] [static] |
char showchan_help[] [static] |
char softhangup_help[] [static] |
char unload_help[] [static] |
char uptime_help[] [static] |
char verbose_help[] [static] |