#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"
Include dependency graph for cli.c:

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(), builtins, cli_cli, 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(), 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_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(), dahdi_show_channel(), dahdi_show_channels(), dahdi_show_status(), 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_chanlist(), handle_chanlist_deprecated(), handle_cli_refresh(), 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_dahdi_show_cadences(), 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_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(), 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(), and udptl_nodebug().
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(), and exit_completely().
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 a