Mon May 14 04:46:11 2007

Asterisk developer's documentation


cli.c File Reference

Standard Command Line Interface. More...

#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.
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_entrycli_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_entryfind_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 and print an error message if not found.
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 []


Detailed Description

Standard Command Line Interface.

Author:
Mark Spencer <markster@digium.com>

Definition in file cli.c.


Define Documentation

#define AST_CLI_INITLEN   256

Initial buffer size for resulting strings in ast_cli().

Definition at line 57 of file cli.c.

Referenced by ast_cli().

#define CONCISE_FORMAT_STRING   "%s!%s!%s!%d!%s!%s!%s!%s!%s!%d!%s!%s\n"

Definition at line 598 of file cli.c.

Referenced by handle_chanlist(), and handle_chanlist_deprecated().

#define DAY   (HOUR*24)

Referenced by print_uptimestr().

#define ESS (  )     ((x == 1) ? "" : "s")

Referenced by handle_chanlist(), handle_chanlist_deprecated(), and print_uptimestr().

#define FORMAT_STRING   "%-25s %-20s %-20s\n"

Definition at line 596 of file cli.c.

#define FORMAT_STRING   "%-20.20s %-20.20s %-7.7s %-30.30s\n"

Definition at line 596 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 597 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"

Definition at line 467 of file cli.c.

Referenced by modlist_modentry().

#define MODLIST_FORMAT2   "%-30s %-40.40s %-10s\n"

Definition at line 468 of file cli.c.

Referenced by handle_modlist().

#define NEEDCOMMA (  )     ((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 599 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 600 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().


Function Documentation

static char * __ast_cli_generator ( const char *  text,
const char *  word,
int  state,
int  lock 
) [static]

Definition at line 1911 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().

01912 {
01913    char *argv[AST_MAX_ARGS];
01914    struct ast_cli_entry *e;
01915    struct cli_iterator i = { NULL, NULL };
01916    int x = 0, argindex, matchlen;
01917    int matchnum=0;
01918    char *ret = NULL;
01919    char matchstr[80] = "";
01920    int tws = 0;
01921    char *dup = parse_args(text, &x, argv, sizeof(argv) / sizeof(argv[0]), &tws);
01922 
01923    if (!dup)   /* error */
01924       return NULL;
01925    argindex = (!ast_strlen_zero(word) && x>0) ? x-1 : x;
01926    /* rebuild the command, ignore tws */
01927    ast_join(matchstr, sizeof(matchstr)-1, argv);
01928    matchlen = strlen(matchstr);
01929    if (tws) {
01930       strcat(matchstr, " "); /* XXX */
01931       if (matchlen)
01932          matchlen++;
01933    }
01934    if (lock)
01935       AST_LIST_LOCK(&helpers);
01936    while( !ret && (e = cli_next(&i)) ) {
01937       int lc = strlen(e->_full_cmd);
01938       if (e->_full_cmd[0] != '_' && lc > 0 && matchlen <= lc &&
01939             !strncasecmp(matchstr, e->_full_cmd, matchlen)) {
01940          /* Found initial part, return a copy of the next word... */
01941          if (e->cmda[argindex] && ++matchnum > state)
01942             ret = strdup(e->cmda[argindex]); /* we need a malloced string */
01943       } else if (e->generator && !strncasecmp(matchstr, e->_full_cmd, lc) && matchstr[lc] < 33) {
01944          /* We have a command in its entirity within us -- theoretically only one
01945             command can have this occur */
01946          ret = e->generator(matchstr, word, argindex, state);
01947       }
01948    }
01949    if (lock)
01950       AST_LIST_UNLOCK(&helpers);
01951    free(dup);
01952    return ret;
01953 }

static int __ast_cli_register ( struct ast_cli_entry e,
struct ast_cli_entry ed 
) [static]

Definition at line 1628 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().

01629 {
01630    struct ast_cli_entry *cur;
01631    char fulle[80] ="";
01632    int lf, ret = -1;
01633    
01634    ast_join(fulle, sizeof(fulle), e->cmda);
01635    AST_LIST_LOCK(&helpers);
01636    
01637    if (find_cli(e->cmda, 1)) {
01638       ast_log(LOG_WARNING, "Command '%s' already registered (or something close enough)\n", fulle);
01639       goto done;
01640    }
01641    e->_full_cmd = ast_strdup(fulle);
01642    if (!e->_full_cmd)
01643       goto done;
01644 
01645    if (ed) {
01646       e->deprecated = 1;
01647       e->summary = ed->summary;
01648       e->usage = ed->usage;
01649       /* XXX If command A deprecates command B, and command B deprecates command C...
01650          Do we want to show command A or command B when telling the user to use new syntax?
01651          This currently would show command A.
01652          To show command B, you just need to always use ed->_full_cmd.
01653        */
01654       e->_deprecated_by = S_OR(ed->_deprecated_by, ed->_full_cmd);
01655    } else {
01656       e->deprecated = 0;
01657    }
01658 
01659    lf = strlen(fulle);
01660    AST_LIST_TRAVERSE_SAFE_BEGIN(&helpers, cur, list) {
01661       int len = strlen(cur->_full_cmd);
01662       if (lf < len)
01663          len = lf;
01664       if (strncasecmp(fulle, cur->_full_cmd, len) < 0) {
01665          AST_LIST_INSERT_BEFORE_CURRENT(&helpers, e, list); 
01666          break;
01667       }
01668    }
01669    AST_LIST_TRAVERSE_SAFE_END;
01670 
01671    if (!cur)
01672       AST_LIST_INSERT_TAIL(&helpers, e, list); 
01673    ret = 0; /* success */
01674 
01675 done:
01676    AST_LIST_UNLOCK(&helpers);
01677 
01678    if (e->deprecate_cmd) {
01679       /* This command deprecates another command.  Register that one also. */
01680       __ast_cli_register(e->deprecate_cmd, e);
01681    }
01682    
01683    return ret;
01684 }

static int __ast_cli_unregister ( struct ast_cli_entry e,
struct ast_cli_entry ed 
) [static]

Definition at line 1612 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().

01613 {
01614    if (e->deprecate_cmd) {
01615       __ast_cli_unregister(e->deprecate_cmd, e);
01616    }
01617    if (e->inuse) {
01618       ast_log(LOG_WARNING, "Can't remove command that is in use\n");
01619    } else {
01620       AST_LIST_LOCK(&helpers);
01621       AST_LIST_REMOVE(&helpers, e, list);
01622       AST_LIST_UNLOCK(&helpers);
01623       free(e->_full_cmd);
01624    }
01625    return 0;
01626 }

void ast_builtins_init ( void   ) 

initialize the _full_cmd string in * each of the builtins.

Provided by cli.c

Definition at line 1496 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().

01497 {
01498    struct ast_cli_entry *e;
01499 
01500    for (e = builtins; e->cmda[0] != NULL; e++) {
01501       char buf[80];
01502       ast_join(buf, sizeof(buf), e->cmda);
01503       e->_full_cmd = strdup(buf);
01504       if (!e->_full_cmd)
01505          ast_log(LOG_WARNING, "-- cannot allocate <%s>\n", buf);
01506    }
01507 
01508    ast_cli_register_multiple(cli_cli, sizeof(cli_cli) / sizeof(struct ast_cli_entry));
01509 }

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(), cmd_dump_start(), cmd_dump_status(), cmd_dump_stop(), cmd_link_status(), cmd_version(), 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_cdr_mysql_status(), 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_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(), 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(), moh_cli(), my_ulimit(), odbc_show_command(), orig_app(), orig_exten(), osp_show(), print_bc_info(), print_codec_to_cli(), print_group(), print_uptimestr(), realtime_mysql_status(), realtime_pgsql_status(), rpt_do_debug(), rpt_do_dump(), rpt_do_lstats(), 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(), 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 1960 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(), cli_activate(), consolehandler(), exit_completely(), and netconsole().

01961 {
01962    char *argv[AST_MAX_ARGS];
01963    struct ast_cli_entry *e;
01964    int x;
01965    char *dup;
01966    int tws;
01967    
01968    if (!(dup = parse_args(s, &x, argv, sizeof(argv) / sizeof(argv[0]), &tws)))
01969       return -1;
01970 
01971    /* We need at least one entry, or ignore */
01972    if (x > 0) {
01973       AST_LIST_LOCK(&helpers);
01974       e = find_cli(argv, 0);
01975       if (e)
01976          e->inuse++;
01977       AST_LIST_UNLOCK(&helpers);
01978       if (e) {
01979          switch(e->handler(fd, x, argv)) {
01980          case RESULT_SHOWUSAGE:
01981             if (e->usage)
01982                ast_cli(fd, "%s", e->usage);
01983             else
01984                ast_cli(fd, "Invalid usage, but no usage information available.\n");
01985             AST_LIST_LOCK(&helpers);
01986             if (e->deprecated)
01987                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);
01988             AST_LIST_UNLOCK(&helpers);
01989             break;
01990          default:
01991             AST_LIST_LOCK(&helpers);
01992             if (e->deprecated == 1) {
01993                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);
01994                e->deprecated = 2;
01995             }
01996             AST_LIST_UNLOCK(&helpers);
01997             break;
01998          }
01999       } else 
02000          ast_cli(fd, "No such command '%s' (type 'help' for help)\n", find_best(argv));
02001       if (e)
02002          ast_atomic_fetchadd_int(&e->inuse, -1);
02003    }
02004    free(dup);
02005    
02006    return 0;
02007 }

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 1164 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().

01165 {
01166    int i, which = 0, len;
01167    len = ast_strlen_zero(word) ? 0 : strlen(word);
01168 
01169    for (i = 0; choices[i]; i++) {
01170       if ((!len || !strncasecmp(word, choices[i], len)) && ++which > state)
01171          return ast_strdup(choices[i]);
01172    }
01173    return NULL;
01174 }

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 1864 of file cli.c.

References ast_cli_generator(), ast_malloc, and ast_realloc.

Referenced by cli_complete(), and handle_commandmatchesarray().

01865 {
01866    char **match_list = NULL, *retstr, *prevstr;
01867    size_t match_list_len, max_equal, which, i;
01868    int matches = 0;
01869 
01870    /* leave entry 0 free for the longest common substring */
01871    match_list_len = 1;
01872    while ((retstr = ast_cli_generator(text, word, matches)) != NULL) {
01873       if (matches + 1 >= match_list_len) {
01874          match_list_len <<= 1;
01875          if (!(match_list = ast_realloc(match_list, match_list_len * sizeof(*match_list))))
01876             return NULL;
01877       }
01878       match_list[++matches] = retstr;
01879    }
01880 
01881    if (!match_list)
01882       return match_list; /* NULL */
01883 
01884    /* Find the longest substring that is common to all results
01885     * (it is a candidate for completion), and store a copy in entry 0.
01886     */
01887    prevstr = match_list[1];
01888    max_equal = strlen(prevstr);
01889    for (which = 2; which <= matches; which++) {
01890       for (i = 0; i < max_equal && toupper(prevstr[i]) == toupper(match_list[which][i]); i++)
01891          continue;
01892       max_equal = i;
01893    }
01894 
01895    if (!(retstr = ast_malloc(max_equal + 1)))
01896       return NULL;
01897    
01898    ast_copy_string(retstr, match_list[1], max_equal + 1);
01899    match_list[0] = retstr;
01900 
01901    /* ensure that the array is NULL terminated */
01902    if (matches + 1 >= match_list_len) {
01903       if (!(match_list = ast_realloc(match_list, (match_list_len + 1) * sizeof(*match_list))))
01904          return NULL;
01905    }
01906    match_list[matches + 1] = NULL;
01907 
01908    return match_list;
01909 }

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 1955 of file cli.c.

References __ast_cli_generator().

Referenced by ast_cli_completion_matches(), and ast_cli_generatornummatches().

01956 {
01957    return __ast_cli_generator(text, word, state, 1);
01958 }

int ast_cli_generatornummatches ( const char *  text,
const char *  word 
)

Return the number of unique matches for the generator.

Definition at line 1847 of file cli.c.

References ast_cli_generator(), and free.

Referenced by handle_commandnummatches().

01848 {
01849    int matches = 0, i = 0;
01850    char *buf = NULL, *oldbuf = NULL;
01851 
01852    while ((buf = ast_cli_generator(text, word, i++))) {
01853       if (!oldbuf || strcmp(buf,oldbuf))
01854          matches++;
01855       if (oldbuf)
01856          free(oldbuf);
01857       oldbuf = buf;
01858    }
01859    if (oldbuf)
01860       free(oldbuf);
01861    return matches;
01862 }

int ast_cli_register ( struct ast_cli_entry e  ) 

Registers a command or an array of commands.

Parameters:
e which cli entry to register Register your own command Returns 0 on success, -1 on failure

Definition at line 1693 of file cli.c.

References __ast_cli_register().

Referenced by ast_cdr_engine_init(), ast_cli_register_multiple(), dnsmgr_init(), do_reload(), load_module(), and my_load_module().

01694 {
01695    return __ast_cli_register(e, NULL);
01696 }

void ast_cli_register_multiple ( struct ast_cli_entry e,
int  len 
)

Register multiple commands.

Parameters:
e pointer to first cli entry to register
len number of entries to register

Definition at line 1701 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(), astdb_init(), crypto_init(), iax_provision_init(), init_framer(), init_logger(), init_manager(), load_module(), load_pbx(), main(), and register_config_cli().

01702 {
01703    int i;
01704 
01705    for (i = 0; i < len; i++)
01706       ast_cli_register(e + i);
01707 }

int ast_cli_unregister ( struct ast_cli_entry e  ) 

Unregisters a command or an array of commands.

Parameters:
e which cli entry to unregister Unregister your own command. You must pass a completed ast_cli_entry structure Returns 0.

Definition at line 1687 of file cli.c.

References __ast_cli_unregister().

Referenced by ast_cli_unregister_multiple(), do_reload(), load_module(), my_unload_module(), and unload_module().

01688 {
01689    return __ast_cli_unregister(e, NULL);
01690 }

void ast_cli_unregister_multiple ( struct ast_cli_entry e,
int  len 
)

Unregister multiple commands.

Parameters:
e pointer to first cli entry to unregister
len number of entries to unregister

Definition at line 1709 of file cli.c.

References ast_cli_unregister().

Referenced by __unload_module(), iax_provision_unload(), load_module(), and unload_module().

01710 {
01711    int i;
01712 
01713    for (i = 0; i < len; i++)
01714       ast_cli_unregister(e + i);
01715 }

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 1190 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().

01191 {
01192    struct ast_channel *c = NULL;
01193    int which = 0;
01194    int wordlen;
01195    char notfound = '\0';
01196    char *ret = &notfound; /* so NULL can break the loop */
01197 
01198    if (pos != rpos)
01199       return NULL;
01200 
01201    wordlen = strlen(word); 
01202 
01203    while (ret == &notfound && (c = ast_channel_walk_locked(c))) {
01204       if (!strncasecmp(word, c->name, wordlen) && ++which > state)
01205          ret = ast_strdup(c->name);
01206       ast_channel_unlock(c);
01207    }
01208    return ret == &notfound ? NULL : ret;
01209 }

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]

Definition at line 1525 of file cli.c.

References ast_cli_entry::_full_cmd, AST_LIST_FIRST, AST_LIST_NEXT, builtins, cli_iterator::builtins, ast_cli_entry::cmda, and cli_iterator::helpers.

Referenced by __ast_cli_generator(), find_cli(), and help1().

01526 {
01527    struct ast_cli_entry *e;
01528 
01529    if (i->builtins == NULL && i->helpers == NULL) {
01530       /* initialize */
01531       i->builtins = builtins;
01532       i->helpers = AST_LIST_FIRST(&helpers);
01533    }
01534    e = i->builtins; /* temporary */
01535    if (!e->cmda[0] || (i->helpers &&
01536           strcmp(i->helpers->_full_cmd, e->_full_cmd) < 0)) {
01537       /* Use helpers */
01538       e = i->helpers;
01539       if (e)
01540          i->helpers = AST_LIST_NEXT(e, list);
01541    } else { /* use builtin. e is already set  */
01542       (i->builtins)++;  /* move to next */
01543    }
01544    return e;
01545 }

static char* complete_ch_3 ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 1211 of file cli.c.

References ast_complete_channels().

01212 {
01213    return ast_complete_channels(line, word, pos, state, 2);
01214 }

static char* complete_ch_4 ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 1216 of file cli.c.

References ast_complete_channels().

01217 {
01218    return ast_complete_channels(line, word, pos, state, 3);
01219 }

static char* complete_ch_5 ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 1221 of file cli.c.

References ast_complete_channels().

01222 {
01223    return ast_complete_channels(line, word, pos, state, 4);
01224 }

static char* complete_fn_2 ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 1246 of file cli.c.

References ast_config_AST_MODULE_DIR, and strdup.

01247 {
01248    char *c;
01249    char filename[256];
01250 
01251    if (pos != 1)
01252       return NULL;
01253    
01254    if (word[0] == '/')
01255       ast_copy_string(filename, word, sizeof(filename));
01256    else
01257       snprintf(filename, sizeof(filename), "%s/%s", ast_config_AST_MODULE_DIR, word);
01258    
01259    c = filename_completion_function(filename, state);
01260    
01261    if (c && word[0] != '/')
01262       c += (strlen(ast_config_AST_MODULE_DIR) + 1);
01263    
01264    return c ? strdup(c) : c;
01265 }

static char* complete_fn_3 ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 1267 of file cli.c.

References ast_config_AST_MODULE_DIR, and strdup.

01268 {
01269    char *c;
01270    char filename[256];
01271 
01272    if (pos != 2)
01273       return NULL;
01274    
01275    if (word[0] == '/')
01276       ast_copy_string(filename, word, sizeof(filename));
01277    else
01278       snprintf(filename, sizeof(filename), "%s/%s", ast_config_AST_MODULE_DIR, word);
01279    
01280    c = filename_completion_function(filename, state);
01281    
01282    if (c && word[0] != '/')
01283       c += (strlen(ast_config_AST_MODULE_DIR) + 1);
01284    
01285    return c ? strdup(c) : c;
01286 }

static char* complete_help ( const char *  text,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 1331 of file cli.c.

References __ast_cli_generator().

01332 {
01333    /* skip first 4 or 5 chars, "help "*/
01334    int l = strlen(text);
01335 
01336    if (l > 5)
01337       l = 5;
01338    text += l;
01339    /* XXX watch out, should stop to the non-generator parts */
01340    return __ast_cli_generator(text, word, state, 0);
01341 }

static char* complete_mod_2 ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 1226 of file cli.c.

References ast_module_helper().

01227 {
01228    return ast_module_helper(line, word, pos, state, 1, 1);
01229 }

static char* complete_mod_3 ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 1236 of file cli.c.

References ast_module_helper().

01237 {
01238    return ast_module_helper(line, word, pos, state, 2, 1);
01239 }

static char* complete_mod_3_nr ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 1231 of file cli.c.

References ast_module_helper().

01232 {
01233    return ast_module_helper(line, word, pos, state, 2, 0);
01234 }

static char* complete_mod_4 ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 1241 of file cli.c.

References ast_module_helper().

01242 {
01243    return ast_module_helper(line, word, pos, state, 3, 0);
01244 }

static char* complete_show_channels ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 1183 of file cli.c.

References ast_cli_complete().

01184 {
01185    static char *choices[] = { "concise", "verbose", NULL };
01186 
01187    return (pos != 3) ? NULL : ast_cli_complete(word, choices, state);
01188 }

static char* complete_show_channels_deprecated ( const char *  line,
const char *  word,
int  pos,
int  state 
) [static]

Definition at line 1176 of file cli.c.

References ast_cli_complete().

01177 {
01178    static char *choices[] = { "concise", "verbose", NULL };
01179 
01180    return (pos != 2) ? NULL : ast_cli_complete(word, choices, state);
01181 }

static char* find_best ( char *  argv[]  )  [static]

Definition at line 1593 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().

01594 {
01595    static char cmdline[80];
01596    int x;
01597    /* See how close we get, then print the candidate */
01598    char *myargv[AST_MAX_CMD_LEN];
01599    for (x=0;x<AST_MAX_CMD_LEN;x++)
01600       myargv[x]=NULL;
01601    AST_LIST_LOCK(&helpers);
01602    for (x=0;argv[x];x++) {
01603       myargv[x] = argv[x];
01604       if (!find_cli(myargv, -1))
01605          break;
01606    }
01607    AST_LIST_UNLOCK(&helpers);
01608    ast_join(cmdline, sizeof(cmdline), myargv);
01609    return cmdline;
01610 }

static struct ast_cli_entry* find_cli ( char *const   cmds[],
int  match_type 
) [static]

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 1554 of file cli.c.

References cli_next().

Referenced by __ast_cli_register(), ast_cli_command(), find_best(), and handle_help().

01555 {
01556    int matchlen = -1;   /* length of longest match so far */
01557    struct ast_cli_entry *cand = NULL, *e=NULL;
01558    struct cli_iterator i = { NULL, NULL};
01559 
01560    while( (e = cli_next(&i)) ) {
01561       int y;
01562       for (y = 0 ; cmds[y] && e->cmda[y]; y++) {
01563          if (strcasecmp(e->cmda[y], cmds[y]))
01564             break;
01565       }
01566       if (e->cmda[y] == NULL) {  /* no more words in candidate */
01567          if (cmds[y] == NULL) /* this is an exact match, cannot do better */
01568             break;
01569          /* here the search key is longer than the candidate */
01570          if (match_type != 0) /* but we look for almost exact match... */
01571             continue;   /* so we skip this one. */
01572          /* otherwise we like it (case 0) */
01573       } else {       /* still words in candidate */
01574          if (cmds[y] == NULL) /* search key is shorter, not good */
01575             continue;
01576          /* if we get here, both words exist but there is a mismatch */
01577          if (match_type == 0) /* not the one we look for */
01578             continue;
01579          if (match_type == 1) /* not the one we look for */
01580             continue;
01581          if (cmds[y+1] != NULL || e->cmda[y+1] != NULL)  /* not the one we look for */
01582             continue;
01583          /* we are in case match_type == -1 and mismatch on last word */
01584       }
01585       if (y > matchlen) {  /* remember the candidate */
01586          matchlen = y;
01587          cand = e;
01588       }
01589    }
01590    return e ? e : cand;
01591 }

static int group_show_channels ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 1288 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.

01289 {
01290 #define FORMAT_STRING  "%-25s  %-20s  %-20s\n"
01291 
01292    struct ast_group_info *gi = NULL;
01293    int numchans = 0;
01294    regex_t regexbuf;
01295    int havepattern = 0;
01296 
01297    if (argc < 3 || argc > 4)
01298       return RESULT_SHOWUSAGE;
01299    
01300    if (argc == 4) {
01301       if (regcomp(&regexbuf, argv[3], REG_EXTENDED | REG_NOSUB))
01302          return RESULT_SHOWUSAGE;
01303       havepattern = 1;
01304    }
01305 
01306    ast_cli(fd, FORMAT_STRING, "Channel", "Group", "Category");
01307 
01308    ast_app_group_list_lock();
01309    
01310    gi = ast_app_group_list_head();
01311    while (gi) {
01312       if (!havepattern || !regexec(&regexbuf, gi->group, 0, NULL, 0)) {
01313          ast_cli(fd, FORMAT_STRING, gi->chan->name, gi->group, (ast_strlen_zero(gi->category) ? "(default)" : gi->category));
01314          numchans++;
01315       }
01316       gi = AST_LIST_NEXT(gi, list);
01317    }
01318    
01319    ast_app_group_list_unlock();
01320    
01321    if (havepattern)
01322       regfree(&regexbuf);
01323 
01324    ast_cli(fd, "%d active channel%s\n", numchans, (numchans != 1) ? "s" : "");
01325    return RESULT_SUCCESS;
01326 #undef FORMAT_STRING
01327 }

static int handle_chanlist ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 682 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.

00683 {
00684    struct ast_channel *c = NULL;
00685    char durbuf[10] = "-";
00686    char locbuf[40];
00687    char appdata[40];
00688    int duration;
00689    int durh, durm, durs;
00690    int numchans = 0, concise = 0, verbose = 0;
00691 
00692    concise = (argc == 4 && (!strcasecmp(argv[3],"concise")));
00693    verbose = (argc == 4 && (!strcasecmp(argv[3],"verbose")));
00694 
00695    if (argc < 3 || argc > 4 || (argc == 4 && !concise && !verbose))
00696       return RESULT_SHOWUSAGE;
00697 
00698    if (!concise && !verbose)
00699       ast_cli(fd, FORMAT_STRING2, "Channel", "Location", "State", "Application(Data)");
00700    else if (verbose)
00701       ast_cli(fd, VERBOSE_FORMAT_STRING2, "Channel", "Context", "Extension", "Priority", "State", "Application", "Data", 
00702               "CallerID", "Duration", "Accountcode", "BridgedTo");
00703 
00704    while ((c = ast_channel_walk_locked(c)) != NULL) {
00705       struct ast_channel *bc = ast_bridged_channel(c);
00706       if ((concise || verbose)  && c->cdr && !ast_tvzero(c->cdr->start)) {
00707          duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000);
00708          if (verbose) {
00709             durh = duration / 3600;
00710             durm = (duration % 3600) / 60;
00711             durs = duration % 60;
00712             snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs);
00713          } else {
00714             snprintf(durbuf, sizeof(durbuf), "%d", duration);
00715          }           
00716       } else {
00717          durbuf[0] = '\0';
00718       }
00719       if (concise) {
00720          ast_cli(fd, CONCISE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
00721                  c->appl ? c->appl : "(None)",
00722             S_OR(c->data, ""),   /* XXX different from verbose ? */
00723                  S_OR(c->cid.cid_num, ""),
00724                  S_OR(c->accountcode, ""),
00725             c->amaflags, 
00726                  durbuf,
00727             bc ? bc->name : "(None)");
00728       } else if (verbose) {
00729          ast_cli(fd, VERBOSE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
00730                  c->appl ? c->appl : "(None)",
00731             c->data ? S_OR(c->data, "(Empty)" ): "(None)",
00732                  S_OR(c->cid.cid_num, ""),
00733             durbuf,
00734                  S_OR(c->accountcode, ""),
00735             bc ? bc->name : "(None)");
00736       } else {
00737          if (!ast_strlen_zero(c->context) && !ast_strlen_zero(c->exten)) 
00738             snprintf(locbuf, sizeof(locbuf), "%s@%s:%d", c->exten, c->context, c->priority);
00739          else
00740             strcpy(locbuf, "(None)");
00741          if (c->appl)
00742             snprintf(appdata, sizeof(appdata), "%s(%s)", c->appl, c->data ? c->data : "");
00743          else
00744             strcpy(appdata, "(None)");
00745          ast_cli(fd, FORMAT_STRING, c->name, locbuf, ast_state2str(c->_state), appdata);
00746       }
00747       numchans++;
00748       ast_channel_unlock(c);
00749    }
00750    if (!concise) {
00751       ast_cli(fd, "%d active channel%s\n", numchans, ESS(numchans));
00752       if (option_maxcalls)
00753          ast_cli(fd, "%d of %d max active call%s (%5.2f%% of capacity)\n",
00754             ast_active_calls(), option_maxcalls, ESS(ast_active_calls()),
00755             ((double)ast_active_calls() / (double)option_maxcalls) * 100.0);
00756       else
00757          ast_cli(fd, "%d active call%s\n", ast_active_calls(), ESS(ast_active_calls()));
00758    }
00759    return RESULT_SUCCESS;
00760 }

static int handle_chanlist_deprecated ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 602 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.

00603 {
00604    struct ast_channel *c = NULL;
00605    char durbuf[10] = "-";
00606    char locbuf[40];
00607    char appdata[40];
00608    int duration;
00609    int durh, durm, durs;
00610    int numchans = 0, concise = 0, verbose = 0;
00611 
00612    concise = (argc == 3 && (!strcasecmp(argv[2],"concise")));
00613    verbose = (argc == 3 && (!strcasecmp(argv[2],"verbose")));
00614 
00615    if (argc < 2 || argc > 3 || (argc == 3 && !concise && !verbose))
00616       return RESULT_SHOWUSAGE;
00617 
00618    if (!concise && !verbose)
00619       ast_cli(fd, FORMAT_STRING2, "Channel", "Location", "State", "Application(Data)");
00620    else if (verbose)
00621       ast_cli(fd, VERBOSE_FORMAT_STRING2, "Channel", "Context", "Extension", "Priority", "State", "Application", "Data", 
00622               "CallerID", "Duration", "Accountcode", "BridgedTo");
00623 
00624    while ((c = ast_channel_walk_locked(c)) != NULL) {
00625       struct ast_channel *bc = ast_bridged_channel(c);
00626       if ((concise || verbose)  && c->cdr && !ast_tvzero(c->cdr->start)) {
00627          duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000);
00628          if (verbose) {
00629             durh = duration / 3600;
00630             durm = (duration % 3600) / 60;
00631             durs = duration % 60;
00632             snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs);
00633          } else {
00634             snprintf(durbuf, sizeof(durbuf), "%d", duration);
00635          }           
00636       } else {
00637          durbuf[0] = '\0';
00638       }
00639       if (concise) {
00640          ast_cli(fd, CONCISE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
00641                  c->appl ? c->appl : "(None)",
00642             S_OR(c->data, ""),   /* XXX different from verbose ? */
00643                  S_OR(c->cid.cid_num, ""),
00644                  S_OR(c->accountcode, ""),
00645             c->amaflags, 
00646                  durbuf,
00647             bc ? bc->name : "(None)");
00648       } else if (verbose) {
00649          ast_cli(fd, VERBOSE_FORMAT_STRING, c->name, c->context, c->exten, c->priority, ast_state2str(c->_state),
00650                  c->appl ? c->appl : "(None)",
00651             c->data ? S_OR(c->data, "(Empty)" ): "(None)",
00652                  S_OR(c->cid.cid_num, ""),
00653             durbuf,
00654                  S_OR(c->accountcode, ""),
00655             bc ? bc->name : "(None)");
00656       } else {
00657          if (!ast_strlen_zero(c->context) && !ast_strlen_zero(c->exten)) 
00658             snprintf(locbuf, sizeof(locbuf), "%s@%s:%d", c->exten, c->context, c->priority);
00659          else
00660             strcpy(locbuf, "(None)");
00661          if (c->appl)
00662             snprintf(appdata, sizeof(appdata), "%s(%s)", c->appl, c->data ? c->data : "");
00663          else
00664             strcpy(appdata, "(None)");
00665          ast_cli(fd, FORMAT_STRING, c->name, locbuf, ast_state2str(c->_state), appdata);
00666       }
00667       numchans++;
00668       ast_channel_unlock(c);
00669    }
00670    if (!concise) {
00671       ast_cli(fd, "%d active channel%s\n", numchans, ESS(numchans));
00672       if (option_maxcalls)
00673          ast_cli(fd, "%d of %d max active call%s (%5.2f%% of capacity)\n",
00674             ast_active_calls(), option_maxcalls, ESS(ast_active_calls()),
00675             ((double)ast_active_calls() / (double)option_maxcalls) * 100.0);
00676       else
00677          ast_cli(fd, "%d active call%s\n", ast_active_calls(), ESS(ast_active_calls()));
00678    }
00679    return RESULT_SUCCESS;
00680 }

static int handle_commandcomplete ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 865 of file cli.c.

References __ast_cli_generator(), ast_cli(), free, RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00866 {
00867    char *buf;
00868 
00869    if (argc != 5)
00870       return RESULT_SHOWUSAGE;
00871    buf = __ast_cli_generator(argv[2], argv[3], atoi(argv[4]), 0);
00872    if (buf) {
00873       ast_cli(fd, buf);
00874       free(buf);
00875    } else
00876       ast_cli(fd, "NULL\n");
00877    return RESULT_SUCCESS;
00878 }

static int handle_commandmatchesarray ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 808 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.

00809 {
00810    char *buf, *obuf;
00811    int buflen = 2048;
00812    int len = 0;
00813    char **matches;
00814    int x, matchlen;
00815 
00816    if (argc != 4)
00817       return RESULT_SHOWUSAGE;
00818    if (!(buf = ast_malloc(buflen)))
00819       return RESULT_FAILURE;
00820    buf[len] = '\0';
00821    matches = ast_cli_completion_matches(argv[2], argv[3]);
00822    if (matches) {
00823       for (x=0; matches[x]; x++) {
00824          matchlen = strlen(matches[x]) + 1;
00825          if (len + matchlen >= buflen) {
00826             buflen += matchlen * 3;
00827             obuf = buf;
00828             if (!(buf = ast_realloc(obuf, buflen))) 
00829                /* Memory allocation failure...  Just free old buffer and be done */
00830                free(obuf);
00831          }
00832          if (buf)
00833             len += sprintf( buf + len, "%s ", matches[x]);
00834          free(matches[x]);
00835          matches[x] = NULL;
00836       }
00837       free(matches);
00838    }
00839 
00840    if (buf) {
00841       ast_cli(fd, "%s%s",buf, AST_CLI_COMPLETE_EOF);
00842       free(buf);
00843    } else
00844       ast_cli(fd, "NULL\n");
00845 
00846    return RESULT_SUCCESS;
00847 }

static int handle_commandnummatches ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 851 of file cli.c.

References ast_cli(), ast_cli_generatornummatches(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00852 {
00853    int matches = 0;
00854 
00855    if (argc != 4)
00856       return RESULT_SHOWUSAGE;
00857 
00858    matches = ast_cli_generatornummatches(argv[2], argv[3]);
00859 
00860    ast_cli(fd, "%d", matches);
00861 
00862    return RESULT_SUCCESS;
00863 }

static int handle_core_set_debug_channel ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 914 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.

00915 {
00916    struct ast_channel *c = NULL;
00917    int is_all, is_off = 0;
00918 
00919    /* 'core set debug channel {all|chan_id}' */
00920    if (argc == 6 && strcmp(argv[5], "off") == 0)
00921       is_off = 1;
00922    else if (argc != 5)
00923       return RESULT_SHOWUSAGE;
00924 
00925    is_all = !strcasecmp("all", argv[4]);
00926    if (is_all) {
00927       if (is_off) {
00928          global_fin &= ~DEBUGCHAN_FLAG;
00929          global_fout &= ~DEBUGCHAN_FLAG;
00930       } else {
00931          global_fin |= DEBUGCHAN_FLAG;
00932          global_fout |= DEBUGCHAN_FLAG;
00933       }
00934       c = ast_channel_walk_locked(NULL);
00935    } else {
00936       c = ast_get_channel_by_name_locked(argv[4]);
00937       if (c == NULL)
00938          ast_cli(fd, "No such channel %s\n", argv[4]);
00939    }
00940    while (c) {
00941       if (!(c->fin & DEBUGCHAN_FLAG) || !(c->fout & DEBUGCHAN_FLAG)) {
00942          if (is_off) {
00943             c->fin &= ~DEBUGCHAN_FLAG;
00944             c->fout &= ~DEBUGCHAN_FLAG;
00945          } else {
00946             c->fin |= DEBUGCHAN_FLAG;
00947             c->fout |= DEBUGCHAN_FLAG;
00948          }
00949          ast_cli(fd, "Debugging %s on channel %s\n", is_off ? "disabled" : "enabled", c->name);
00950       }
00951       ast_channel_unlock(c);
00952       if (!is_all)
00953          break;
00954       c = ast_channel_walk_locked(c);
00955    }
00956    ast_cli(fd, "Debugging on new channels is %s\n", is_off ? "disabled" : "enabled");
00957    return RESULT_SUCCESS;
00958 }

static int handle_debugchan_deprecated ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 880 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.

00881 {
00882    struct ast_channel *c=NULL;
00883    int is_all;
00884 
00885    /* 'debug channel {all|chan_id}' */
00886    if (argc != 3)
00887       return RESULT_SHOWUSAGE;
00888 
00889    is_all = !strcasecmp("all", argv[2]);
00890    if (is_all) {
00891       global_fin |= DEBUGCHAN_FLAG;
00892       global_fout |= DEBUGCHAN_FLAG;
00893       c = ast_channel_walk_locked(NULL);
00894    } else {
00895       c = ast_get_channel_by_name_locked(argv[2]);
00896       if (c == NULL)
00897          ast_cli(fd, "No such channel %s\n", argv[2]);
00898    }
00899    while (c) {
00900       if (!(c->fin & DEBUGCHAN_FLAG) || !(c->fout & DEBUGCHAN_FLAG)) {
00901          c->fin |= DEBUGCHAN_FLAG;
00902          c->fout |= DEBUGCHAN_FLAG;
00903          ast_cli(fd, "Debugging enabled on channel %s\n", c->name);
00904       }
00905       ast_channel_unlock(c);
00906       if (!is_all)
00907          break;
00908       c = ast_channel_walk_locked(c);
00909    }
00910    ast_cli(fd, "Debugging on new channels is enabled\n");
00911    return RESULT_SUCCESS;
00912 }

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 1760 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.

01761 {
01762    char fullcmd[80];
01763    struct ast_cli_entry *e;
01764 
01765    if (argc < 1)
01766       return RESULT_SHOWUSAGE;
01767    if (argc == 1)
01768       return help_workhorse(fd, NULL);
01769 
01770    AST_LIST_LOCK(&helpers);
01771    e = find_cli(argv + 1, 1); /* try exact match first */
01772    if (!e)
01773       return help1(fd, argv + 1, 1 /* locked */);
01774    if (e->usage)
01775       ast_cli(fd, "%s", e->usage);
01776    else {
01777       ast_join(fullcmd, sizeof(fullcmd), argv+1);
01778       ast_cli(fd, "No help text available for '%s'.\n", fullcmd);
01779    }
01780    AST_LIST_UNLOCK(&helpers);
01781    return RESULT_SUCCESS;
01782 }

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)
00406       return RESULT_SHOWUSAGE;
00407    ast_console_toggle_mute(fd);
00408    return RESULT_SUCCESS;
00409 }

static int handle_modlist ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 574 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.

00575 {
00576    char *like = "";
00577    if (argc == 3)
00578       return RESULT_SHOWUSAGE;
00579    else if (argc >= 4) {
00580       if (strcmp(argv[2],"like")) 
00581          return RESULT_SHOWUSAGE;
00582       like = argv[3];
00583    }
00584       
00585    ast_mutex_lock(&climodentrylock);
00586    climodentryfd = fd; /* global, protected by climodentrylock */
00587    ast_cli(fd, MODLIST_FORMAT2, "Module", "Description", "Use Count");
00588    ast_cli(fd,"%d modules loaded\n", ast_update_module_list(modlist_modentry, like));
00589    climodentryfd = -1;
00590    ast_mutex_unlock(&climodentrylock);
00591    return RESULT_SUCCESS;
00592 }

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 960 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.

00961 {
00962    struct ast_channel *c=NULL;
00963    int is_all;
00964    /* 'no debug channel {all|chan_id}' */
00965    if (argc != 4)
00966       return RESULT_SHOWUSAGE;
00967    is_all = !strcasecmp("all", argv[3]);
00968    if (is_all) {
00969       global_fin &= ~DEBUGCHAN_FLAG;
00970       global_fout &= ~DEBUGCHAN_FLAG;
00971       c = ast_channel_walk_locked(NULL);
00972    } else {
00973       c = ast_get_channel_by_name_locked(argv[3]);
00974       if (c == NULL)
00975          ast_cli(fd, "No such channel %s\n", argv[3]);
00976    }
00977    while(c) {
00978       if ((c->fin & DEBUGCHAN_FLAG) || (c->fout & DEBUGCHAN_FLAG)) {
00979          c->fin &= ~DEBUGCHAN_FLAG;
00980          c->fout &= ~DEBUGCHAN_FLAG;
00981          ast_cli(fd, "Debugging disabled on channel %s\n", c->name);
00982       }
00983       ast_channel_unlock(c);
00984       if (!is_all)
00985          break;
00986       c = ast_channel_walk_locked(c);
00987    }
00988    ast_cli(fd, "Debugging on new channels is disabled\n");
00989    return RESULT_SUCCESS;
00990 }

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 1076 of file cli.c.

References ast_channel::_bridge, ast_channel::_state, 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::cdr, ast_channel::cid, ast_callerid::cid_dnid, ast_callerid::cid_name, ast_callerid::cid_num, DEBUGCHAN_FLAG, ast_channel::fds, ast_channel::fin, ast_channel::fout, name, ast_channel::nativeformats, pbx_builtin_serialize_variables(), 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.

01077 {
01078    struct ast_channel *c=NULL;
01079    struct timeval now;
01080    char buf[2048];
01081    char cdrtime[256];
01082    char nf[256], wf[256], rf[256];
01083    long elapsed_seconds=0;
01084    int hour=0, min=0, sec=0;
01085    
01086    if (argc != 4)
01087       return RESULT_SHOWUSAGE;
01088    now = ast_tvnow();
01089    c = ast_get_channel_by_name_locked(argv[3]);
01090    if (!c) {
01091       ast_cli(fd, "%s is not a known channel\n", argv[3]);
01092       return RESULT_SUCCESS;
01093    }
01094    if(c->cdr) {
01095       elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
01096       hour = elapsed_seconds / 3600;
01097       min = (elapsed_seconds % 3600) / 60;
01098       sec = elapsed_seconds % 60;
01099       snprintf(cdrtime, sizeof(cdrtime), "%dh%dm%ds", hour, min, sec);
01100    } else
01101       strcpy(cdrtime, "N/A");
01102    ast_cli(fd, 
01103       " -- General --\n"
01104       "           Name: %s\n"
01105       "           Type: %s\n"
01106       "       UniqueID: %s\n"
01107       "      Caller ID: %s\n"
01108       " Caller ID Name: %s\n"
01109       "    DNID Digits: %s\n"
01110       "          State: %s (%d)\n"
01111       "          Rings: %d\n"
01112       "  NativeFormats: %s\n"
01113       "    WriteFormat: %s\n"
01114       "     ReadFormat: %s\n"
01115       " WriteTranscode: %s\n"
01116       "  ReadTranscode: %s\n"
01117       "1st File Descriptor: %d\n"
01118       "      Frames in: %d%s\n"
01119       "     Frames out: %d%s\n"
01120       " Time to Hangup: %ld\n"
01121       "   Elapsed Time: %s\n"
01122       "  Direct Bridge: %s\n"
01123       "Indirect Bridge: %s\n"
01124       " --   PBX   --\n"
01125       "        Context: %s\n"
01126       "      Extension: %s\n"
01127       "       Priority: %d\n"
01128       "     Call Group: %llu\n"
01129       "   Pickup Group: %llu\n"
01130       "    Application: %s\n"
01131       "           Data: %s\n"
01132       "    Blocking in: %s\n",
01133       c->name, c->tech->type, c->uniqueid,
01134       S_OR(c->cid.cid_num, "(N/A)"),
01135       S_OR(c->cid.cid_name, "(N/A)"),
01136       S_OR(c->cid.cid_dnid, "(N/A)"), ast_state2str(c->_state), c->_state, c->rings, 
01137       ast_getformatname_multiple(nf, sizeof(nf), c->nativeformats), 
01138       ast_getformatname_multiple(wf, sizeof(wf), c->writeformat), 
01139       ast_getformatname_multiple(rf, sizeof(rf), c->readformat),
01140       c->writetrans ? "Yes" : "No",
01141       c->readtrans ? "Yes" : "No",
01142       c->fds[0],
01143       c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
01144       c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
01145       (long)c->whentohangup,
01146       cdrtime, c->_bridge ? c->_bridge->name : "<none>", ast_bridged_channel(c) ? ast_bridged_channel(c)->name : "<none>", 
01147       c->context, c->exten, c->priority, c->callgroup, c->pickupgroup, ( c->appl ? c->appl : "(N/A)" ),
01148       ( c-> data ? S_OR(c->data, "(Empty)") : "(None)"),
01149       (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
01150    
01151    if(pbx_builtin_serialize_variables(c,buf,sizeof(buf)))
01152       ast_cli(fd,"      Variables:\n%s\n",buf);
01153    if(c->cdr && ast_cdr_serialize_variables(c->cdr,buf, sizeof(buf), '=', '\n', 1))
01154       ast_cli(fd,"  CDR Variables:\n%s\n",buf);
01155    
01156    ast_channel_unlock(c);
01157    return RESULT_SUCCESS;
01158 }

static int handle_showchan_deprecated ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 992 of file cli.c.

References ast_channel::_bridge, ast_channel::_state, 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::cdr, ast_channel::cid, ast_callerid::cid_dnid, ast_callerid::cid_name, ast_callerid::cid_num, DEBUGCHAN_FLAG, ast_channel::fds, ast_channel::fin, ast_channel::fout, name, ast_channel::nativeformats, pbx_builtin_serialize_variables(), 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.

00993 {
00994    struct ast_channel *c=NULL;
00995    struct timeval now;
00996    char buf[2048];
00997    char cdrtime[256];
00998    char nf[256], wf[256], rf[256];
00999    long elapsed_seconds=0;
01000    int hour=0, min=0, sec=0;
01001    
01002    if (argc != 3)
01003       return RESULT_SHOWUSAGE;
01004    now = ast_tvnow();
01005    c = ast_get_channel_by_name_locked(argv[2]);
01006    if (!c) {
01007       ast_cli(fd, "%s is not a known channel\n", argv[2]);
01008       return RESULT_SUCCESS;
01009    }
01010    if(c->cdr) {
01011       elapsed_seconds = now.tv_sec - c->cdr->start.tv_sec;
01012       hour = elapsed_seconds / 3600;
01013       min = (elapsed_seconds % 3600) / 60;
01014       sec = elapsed_seconds % 60;
01015       snprintf(cdrtime, sizeof(cdrtime), "%dh%dm%ds", hour, min, sec);
01016    } else
01017       strcpy(cdrtime, "N/A");
01018    ast_cli(fd, 
01019       " -- General --\n"
01020       "           Name: %s\n"
01021       "           Type: %s\n"
01022       "       UniqueID: %s\n"
01023       "      Caller ID: %s\n"
01024       " Caller ID Name: %s\n"
01025       "    DNID Digits: %s\n"
01026       "          State: %s (%d)\n"
01027       "          Rings: %d\n"
01028       "  NativeFormats: %s\n"
01029       "    WriteFormat: %s\n"
01030       "     ReadFormat: %s\n"
01031       " WriteTranscode: %s\n"
01032       "  ReadTranscode: %s\n"
01033       "1st File Descriptor: %d\n"
01034       "      Frames in: %d%s\n"
01035       "     Frames out: %d%s\n"
01036       " Time to Hangup: %ld\n"
01037       "   Elapsed Time: %s\n"
01038       "  Direct Bridge: %s\n"
01039       "Indirect Bridge: %s\n"
01040       " --   PBX   --\n"
01041       "        Context: %s\n"
01042       "      Extension: %s\n"
01043       "       Priority: %d\n"
01044       "     Call Group: %llu\n"
01045       "   Pickup Group: %llu\n"
01046       "    Application: %s\n"
01047       "           Data: %s\n"
01048       "    Blocking in: %s\n",
01049       c->name, c->tech->type, c->uniqueid,
01050       S_OR(c->cid.cid_num, "(N/A)"),
01051       S_OR(c->cid.cid_name, "(N/A)"),
01052       S_OR(c->cid.cid_dnid, "(N/A)"), ast_state2str(c->_state), c->_state, c->rings, 
01053       ast_getformatname_multiple(nf, sizeof(nf), c->nativeformats), 
01054       ast_getformatname_multiple(wf, sizeof(wf), c->writeformat), 
01055       ast_getformatname_multiple(rf, sizeof(rf), c->readformat),
01056       c->writetrans ? "Yes" : "No",
01057       c->readtrans ? "Yes" : "No",
01058       c->fds[0],
01059       c->fin & ~DEBUGCHAN_FLAG, (c->fin & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
01060       c->fout & ~DEBUGCHAN_FLAG, (c->fout & DEBUGCHAN_FLAG) ? " (DEBUGGED)" : "",
01061       (long)c->whentohangup,
01062       cdrtime, c->_bridge ? c->_bridge->name : "<none>", ast_bridged_channel(c) ? ast_bridged_channel(c)->name : "<none>", 
01063       c->context, c->exten, c->priority, c->callgroup, c->pickupgroup, ( c->appl ? c->appl : "(N/A)" ),
01064       ( c-> data ? S_OR(c->data, "(Empty)") : "(None)"),
01065       (ast_test_flag(c, AST_FLAG_BLOCKING) ? c->blockproc : "(Not Blocking)"));
01066    
01067    if(pbx_builtin_serialize_variables(c,buf,sizeof(buf)))
01068       ast_cli(fd,"      Variables:\n%s\n",buf);
01069    if(c->cdr && ast_cdr_serialize_variables(c->cdr,buf, sizeof(buf), '=', '\n', 1))
01070       ast_cli(fd,"  CDR Variables:\n%s\n",buf);
01071    
01072    ast_channel_unlock(c);
01073    return RESULT_SUCCESS;
01074 }

static int handle_showuptime ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 559 of file cli.c.

References ast_lastreloadtime, ast_startuptime, print_uptimestr(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00560 {
00561    /* 'core show uptime [seconds]' */
00562    time_t curtime = time(NULL);
00563    int printsec = (argc == 4 && !strcasecmp(argv[3],"seconds"));
00564 
00565    if (argc != 3 && !printsec)
00566       return RESULT_SHOWUSAGE;
00567    if (ast_startuptime)
00568       print_uptimestr(fd, curtime - ast_startuptime, "System uptime", printsec);
00569    if (ast_lastreloadtime)
00570       print_uptimestr(fd, curtime - ast_lastreloadtime, "Last reload", printsec);
00571    return RESULT_SUCCESS;
00572 }

static int handle_showuptime_deprecated ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 544 of file cli.c.

References ast_lastreloadtime, ast_startuptime, print_uptimestr(), RESULT_SHOWUSAGE, and RESULT_SUCCESS.

00545 {
00546    /* 'show uptime [seconds]' */
00547    time_t curtime = time(NULL);
00548    int printsec = (argc == 3 && !strcasecmp(argv[2],"seconds"));
00549 
00550    if (argc != 2 && !printsec)
00551       return RESULT_SHOWUSAGE;
00552    if (ast_startuptime)
00553       print_uptimestr(fd, curtime - ast_startuptime, "System uptime", printsec);
00554    if (ast_lastreloadtime)
00555       print_uptimestr(fd, curtime - ast_lastreloadtime, "Last reload", printsec);
00556    return RESULT_SUCCESS;
00557 }

static int handle_softhangup ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 791 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.

00792 {
00793    struct ast_channel *c=NULL;
00794    if (argc != 3)
00795       return RESULT_SHOWUSAGE;
00796    c = ast_get_channel_by_name_locked(argv[2]);
00797    if (c) {
00798       ast_cli(fd, "Requested Hangup on channel '%s'\n", c->name);
00799       ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
00800       ast_channel_unlock(c);
00801    } else
00802       ast_cli(fd, "%s is not a known channel\n", argv[2]);
00803    return RESULT_SUCCESS;
00804 }

static int handle_unload ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 439 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.

00440 {
00441    int x;
00442    int force = AST_FORCE_SOFT;
00443    if (argc < 3)
00444       return RESULT_SHOWUSAGE;
00445    for (x = 2; x < argc; x++) {
00446       if (argv[x][0] == '-') {
00447          switch(argv[x][1]) {
00448          case 'f':
00449             force = AST_FORCE_FIRM;
00450             break;
00451          case 'h':
00452             force = AST_FORCE_HARD;
00453             break;
00454          default:
00455             return RESULT_SHOWUSAGE;
00456          }
00457       } else if (x != argc - 1) 
00458          return RESULT_SHOWUSAGE;
00459       else if (ast_unload_resource(argv[x], force)) {
00460          ast_cli(fd, "Unable to unload resource %s\n", argv[x]);
00461          return RESULT_FAILURE;
00462       }
00463    }
00464    return RESULT_SUCCESS;
00465 }

static int handle_unload_deprecated ( int  fd,
int  argc,
char *  argv[] 
) [static]

Definition at line 411 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.

00412 {
00413    int x;
00414    int force = AST_FORCE_SOFT;
00415    if (argc < 2)
00416       return RESULT_SHOWUSAGE;
00417    for (x = 1; x < argc; x++) {
00418       if (argv[x][0] == '-') {
00419          switch(argv[x][1]) {
00420          case 'f':
00421             force = AST_FORCE_FIRM;
00422             break;
00423          case 'h':
00424             force = AST_FORCE_HARD;
00425             break;
00426          default:
00427             return RESULT_SHOWUSAGE;
00428          }
00429       } else if (x != argc - 1) 
00430          return RESULT_SHOWUSAGE;
00431       else if (ast_unload_resource(argv[x], force)) {
00432          ast_cli(fd, "Unable to unload resource %s\n", argv[x]);
00433          return RESULT_FAILURE;
00434       }
00435    }
00436    return RESULT_SUCCESS;
00437 }

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 and print an error message if not found.

Definition at line 1723 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, and ast_cli_entry::summary.

Referenced by handle_help(), and help_workhorse().

01724 {
01725    char matchstr[80] = "";
01726    struct ast_cli_entry *e;
01727    int len = 0;
01728    int found = 0;
01729    struct cli_iterator i = { NULL, NULL};
01730 
01731    if (match) {
01732       ast_join(matchstr, sizeof(matchstr), match);
01733       len = strlen(matchstr);
01734    }
01735    if (!locked)
01736       AST_LIST_LOCK(&helpers);
01737    while ( (e = cli_next(&i)) ) {
01738       /* Hide commands that start with '_' */
01739       if (e->_full_cmd[0] == '_')
01740          continue;
01741       /* Hide commands that are marked as deprecated. */
01742       if (e->deprecated)
01743          continue;
01744       if (match && strncasecmp(matchstr, e->_full_cmd, len))
01745          continue;
01746       ast_cli(fd, "%25.25s  %s\n", e->_full_cmd, e->summary);
01747       found++;
01748    }
01749    AST_LIST_UNLOCK(&helpers);
01750    if (!locked && !found && matchstr[0])
01751       ast_cli(fd, "No such command '%s'.\n", matchstr);
01752    return 0;
01753 }

static int help_workhorse ( int  fd,
char *  match[] 
) [static]

Definition at line 1755 of file cli.c.

References help1().

Referenced by handle_help(), and handle_showagi().

01756 {
01757    return help1(fd, match, 0 /* do not print errors */);
01758 }

static int modlist_modentry ( const char *  module,
const char *  description,
int  usecnt,
const char *  like 
) [static]

Definition at line 473 of file cli.c.

References ast_cli(), MODLIST_FORMAT, and strcasestr().

Referenced by handle_modlist().

00474 {
00475    /* Comparing the like with the module */
00476    if (strcasestr(module, like) ) {
00477       ast_cli(climodentryfd, MODLIST_FORMAT, module, description, usecnt);
00478       return 1;
00479    } 
00480    return 0;
00481 }

static char* parse_args ( const char *  s,
int *  argc,
char *  argv[],
int  max,
int *  trailingwhitespace 
) [static]

Definition at line 1784 of file cli.c.

References ast_log(), ast_strdup, and LOG_WARNING.

Referenced by __ast_cli_generator(), agi_handle_command(), and ast_cli_command().

01785 {
01786    char *dup, *cur;
01787    int x = 0;
01788    int quoted = 0;
01789    int escaped = 0;
01790    int whitespace = 1;
01791 
01792    *trailingwhitespace = 0;
01793    if (s == NULL) /* invalid, though! */
01794       return NULL;
01795    /* make a copy to store the parsed string */
01796    if (!(dup = ast_strdup(s)))
01797       return NULL;
01798 
01799    cur = dup;
01800    /* scan the original string copying into cur when needed */
01801    for (; *s ; s++) {
01802       if (x >= max - 1) {
01803          ast_log(LOG_WARNING, "Too many arguments, truncating at %s\n", s);
01804          break;
01805       }
01806       if (*s == '"' && !escaped) {
01807          quoted = !quoted;
01808          if (quoted && whitespace) {
01809             /* start a quoted string from previous whitespace: new argument */
01810             argv[x++] = cur;
01811             whitespace = 0;
01812          }
01813       } else if ((*s == ' ' || *s == '\t') && !(quoted || escaped)) {
01814          /* If we are not already in whitespace, and not in a quoted string or
01815             processing an escape sequence, and just entered whitespace, then
01816             finalize the previous argument and remember that we are in whitespace
01817          */
01818          if (!whitespace) {
01819             *cur++ = '\0';
01820             whitespace = 1;
01821          }
01822       } else if (*s == '\\' && !escaped) {
01823          escaped = 1;
01824       } else {
01825          if (whitespace) {
01826             /* we leave whitespace, and are not quoted. So it's a new argument */
01827             argv[x++] = cur;
01828             whitespace = 0;
01829          }
01830          *cur++ = *s;
01831          escaped = 0;
01832       }
01833    }
01834    /* Null terminate */
01835    *cur++ = '\0';
01836    /* XXX put a NULL in the last argument, because some functions that take
01837     * the array may want a null-terminated array.
01838     * argc still reflects the number of non-NULL entries.
01839     */
01840    argv[x] = NULL;
01841    *argc = x;
01842    *trailingwhitespace = whitespace;
01843    return dup;
01844 }

static void print_uptimestr ( int  fd,
time_t  timeval,
const char *  prefix,
int  printsec 
) [static]

Definition at line 492 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().

00493 {
00494    int x; /* the main part - years, weeks, etc. */
00495    char timestr[256]="", *s = timestr;
00496    size_t maxbytes = sizeof(timestr);
00497 
00498 #define SECOND (1)
00499 #define MINUTE (SECOND*60)
00500 #define HOUR (MINUTE*60)
00501 #define DAY (HOUR*24)
00502 #define WEEK (DAY*7)
00503 #define YEAR (DAY*365)
00504 #define ESS(x) ((x == 1) ? "" : "s")   /* plural suffix */
00505 #define NEEDCOMMA(x) ((x)? ",": "") /* define if we need a comma */
00506    if (timeval < 0)  /* invalid, nothing to show */
00507       return;
00508    if (printsec)  {  /* plain seconds output */
00509       ast_build_string(&s, &maxbytes, "%lu", (u_long)timeval);
00510       timeval = 0; /* bypass the other cases */
00511    }
00512    if (timeval > YEAR) {
00513       x = (timeval / YEAR);
00514       timeval -= (x * YEAR);
00515       ast_build_string(&s, &maxbytes, "%d year%s%s ", x, ESS(x),NEEDCOMMA(timeval));
00516    }
00517    if (timeval > WEEK) {
00518       x = (timeval / WEEK);
00519       timeval -= (x * WEEK);
00520       ast_build_string(&s, &maxbytes, "%d week%s%s ", x, ESS(x),NEEDCOMMA(timeval));
00521    }
00522    if (timeval > DAY) {
00523       x = (timeval / DAY);
00524       timeval -= (x * DAY);
00525       ast_build_string(&s, &maxbytes, "%d day%s%s ", x, ESS(x),NEEDCOMMA(timeval));
00526    }
00527    if (timeval > HOUR) {
00528       x = (timeval / HOUR);
00529       timeval -= (x * HOUR);
00530       ast_build_string(&s, &maxbytes, "%d hour%s%s ", x, ESS(x),NEEDCOMMA(timeval));
00531    }
00532    if (timeval > MINUTE) {
00533       x = (timeval / MINUTE);
00534       timeval -= (x * MINUTE);
00535       ast_build_string(&s, &maxbytes, "%d minute%s%s ", x, ESS(x),NEEDCOMMA(timeval));
00536    }
00537    x = timeval;
00538    if (x > 0)
00539       ast_build_string(&s, &maxbytes, "%d second%s ", x, ESS(x));
00540    if (timestr[0] != '\0')
00541       ast_cli(fd, "%s: %s\n", prefix, timestr);
00542 }


Variable Documentation

struct ast_cli_entry builtins[] [static]

Definition at line 1347 of file cli.c.

Referenced by ast_builtins_init(), cli_next(), and load_pbx().

char chanlist_help[] [static]

Definition at line 96 of file cli.c.

struct ast_cli_entry cli_cli[] [static]

Definition at line 1424 of file cli.c.

Referenced by ast_builtins_init().

struct ast_cli_entry cli_debug_channel_deprecated [static]

Initial value:

 {
   { "debug", "channel", NULL },
   handle_debugchan_deprecated, NULL,
   NULL, complete_ch_3 }

Definition at line 1364 of file cli.c.

struct ast_cli_entry cli_debug_level_deprecated [static]

Initial value:

 {
   { "debug", "level", NULL },
   handle_debuglevel_deprecated, NULL,
   NULL }

Definition at line 1369 of file cli.c.

struct ast_cli_entry cli_module_load_deprecated [static]

Initial value:

 {
   { "load", NULL },
   handle_load_deprecated, NULL,
   NULL, complete_fn_2 }

Definition at line 1404 of file cli.c.

struct ast_cli_entry cli_module_reload_deprecated [static]

Initial value:

 {
   { "reload", NULL },
   handle_reload_deprecated, NULL,
   NULL, complete_mod_2 }

Definition at line 1409 of file cli.c.

struct ast_cli_entry cli_module_unload_deprecated [static]

Initial value:

 {
   { "unload", NULL },
   handle_unload_deprecated, NULL,
   NULL, complete_mod_2 }

Definition at line 1414 of file cli.c.

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 }

Definition at line 1374 of file cli.c.

struct ast_cli_entry cli_set_verbose_deprecated [static]

Initial value:

 {
   { "set", "verbose", NULL },
   handle_set_verbose_deprecated, NULL,
   NULL }

Definition at line 1379 of file cli.c.

struct ast_cli_entry cli_show_channel_deprecated [static]

Initial value:

 {
   { "show", "channel", NULL },
   handle_showchan_deprecated, NULL,
   NULL, complete_ch_3 }

Definition at line 1384 of file cli.c.

struct ast_cli_entry cli_show_channels_deprecated [static]

Initial value:

 {
   { "show", "channels", NULL },
   handle_chanlist_deprecated, NULL,
   NULL, complete_show_channels_deprecated }

Definition at line 1389 of file cli.c.

struct ast_cli_entry cli_show_modules_deprecated [static]

Initial value:

 {
   { "show", "modules", NULL },
   handle_modlist, NULL,
   NULL }

Definition at line 1394 of file cli.c.

struct ast_cli_entry cli_show_modules_like_deprecated [static]

Initial value:

 {
   { "show", "modules", "like", NULL },
   handle_modlist, NULL,
   NULL, complete_mod_4 }

Definition at line 1399 of file cli.c.

struct ast_cli_entry cli_show_uptime_deprecated [static]

Initial value:

 {
   { "show", "uptime", NULL },
   handle_showuptime_deprecated, "Show uptime information",
   NULL }

Definition at line 1419 of file cli.c.

int climodentryfd = -1 [static]

Definition at line 471 of file cli.c.

char commandcomplete_help[] [static]

Initial value:

 
"Usage: _command complete \"<line>\" text state\n"
"       This function is used internally to help with command completion and should.\n"
"       never be called by the user directly.\n"

Definition at line 776 of file cli.c.

char commandmatchesarray_help[] [static]

Initial value:

 
"Usage: _command matchesarray \"<line>\" text \n"
"       This function is used internally to help with command completion and should.\n"
"       never be called by the user directly.\n"

Definition at line 786 of file cli.c.

char commandnummatches_help[] [static]

Initial value:

 
"Usage: _command nummatches \"<line>\" text \n"
"       This function is used internally to help with command completion and should.\n"
"       never be called by the user directly.\n"

Definition at line 781 of file cli.c.

char debug_help[] [static]

Definition at line 114 of file cli.c.

char debugchan_help[] [static]

Initial value:

 
"Usage: core set debug channel <channel> [off]\n"
"       Enables/disables debugging on a specific channel.\n"

Definition at line 772 of file cli.c.

unsigned long global_fin

Definition at line 100 of file channel.c.

unsigned long global_fout

Definition at line 100 of file channel.c.

char group_show_channels_help[] [static]

Initial value:

 
"Usage: group show channels [pattern]\n"
"       Lists all currently active channels with channel group(s) specified.\n"
"       Optional regular expression pattern is matched to group names for each\n"
"       channel.\n"

Definition at line 135 of file cli.c.

char help_help[] [static]

Initial value:

"Usage: help [topic]\n"
"       When called with a topic as an argument, displays usage\n"
"       information on the given command. If called without a\n"
"       topic, it provides a list of commands.\n"

Definition at line 90 of file cli.c.

char load_help[] [static]

Initial value:

 
"Usage: module load <module name>\n"
"       Loads the specified module into Asterisk.\n"

Definition at line 78 of file cli.c.

char logger_mute_help[] [static]

Initial value:

 
"Usage: logger mute\n"
"       Disables logging output to the current console, making it possible to\n"
"       gather information without being disturbed by scrolling lines.\n"

Definition at line 125 of file cli.c.

char modlist_help[] [static]

Initial value:

"Usage: module show [like <keyword>]\n"
"       Shows Asterisk modules currently in use, and usage statistics.\n"

Definition at line 483 of file cli.c.

char nodebug_help[] [static]

Initial value:

 
"Usage: core set debug off\n"
"       Turns off core debug messages.\n"

Definition at line 121 of file cli.c.

char reload_help[] [static]

Initial value:

 
"Usage: module reload [module ...]\n"
"       Reloads configuration files for all listed modules which support\n"
"       reloading, or for all supported modules if none are listed.\n"

Definition at line 103 of file cli.c.

char showchan_help[] [static]

Initial value:

 
"Usage: core show channel <channel>\n"
"       Shows lots of information about the specified channel.\n"

Definition at line 768 of file cli.c.

char softhangup_help[] [static]

Initial value:

"Usage: soft hangup <channel>\n"
"       Request that a channel be hung up. The hangup takes effect\n"
"       the next time the driver reads or writes from the channel\n"

Definition at line 130 of file cli.c.

char unload_help[] [static]

Definition at line 82 of file cli.c.

char uptime_help[] [static]

Initial value:

"Usage: core show uptime [seconds]\n"
"       Shows Asterisk uptime information.\n"
"       The seconds word returns the uptime in seconds only.\n"

Definition at line 487 of file cli.c.

char verbose_help[] [static]

Initial value:

 
"Usage: core set verbose <level>\n"
"       Sets level of verbose messages to be displayed.  0 means\n"
"       no messages should be displayed. Equivalent to -v[v[v...]]\n"
"       on startup\n"

Definition at line 108 of file cli.c.


Generated on Mon May 14 04:46:12 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1