Codename Pineapple

Home page | Mailing list | Docs

Last updated: Sat Feb 3 05:01:28 2007

Asterisk developer's documentation :: Codename Pineapple


cli.h File Reference


Detailed Description

Standard Command Line Interface.

Definition in file cli.h.

#include <stdarg.h>
#include "asterisk/linkedlists.h"

Include dependency graph for cli.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_cli_args
struct  ast_cli_entry
 descriptor for a cli entry See CLI_command_API More...

Defines

#define AST_CLI_COMPLETE_EOF   "_EOF_"
#define AST_MAX_ARGS   64
#define AST_MAX_CMD_LEN   16
#define CLI_FAILURE   (char *)RESULT_FAILURE
#define CLI_SHOWUSAGE   (char *)RESULT_SHOWUSAGE
#define CLI_SUCCESS   (char *)RESULT_SUCCESS
#define ESS(x)   ((x) == 1 ? "" : "s")
#define NEW_CLI(fn, txt,)   { .new_handler = fn, .summary = txt, ## __VA_ARGS__ }
#define RESULT_FAILURE   2
#define RESULT_SHOWUSAGE   1
#define RESULT_SUCCESS   0

Typedefs

typedef char *(* new_cli_fn )(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
typedef int(* old_cli_fn )(int fd, int argc, char *argv[])

Enumerations

enum  ast_cli_fn { CLI_INIT = -2, CLI_GENERATE = -3, CLI_HANDLER = -4 }
 calling arguments for new-style handlers See CLI_command_API More...

Functions

void ast_cli (int fd, char *fmt,...) __attribute__((format(printf
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 pos)
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.
char * ast_cli_generator (const char *, const char *, int)
 Readline madness Useful for readline, that's about it Returns 0 on success, -1 on failure.
int ast_cli_generatornummatches (const char *, const char *)
 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.


Define Documentation

#define AST_CLI_COMPLETE_EOF   "_EOF_"
 

Definition at line 49 of file cli.h.

Referenced by ast_el_strtoarr(), and cli_complete().

#define AST_MAX_ARGS   64
 

Definition at line 47 of file cli.h.

Referenced by __ast_cli_generator(), and ast_cli_command().

#define AST_MAX_CMD_LEN   16
 

Definition at line 45 of file cli.h.

Referenced by __ast_cli_register(), and find_best().

#define CLI_FAILURE   (char *)RESULT_FAILURE
 

Definition at line 43 of file cli.h.

Referenced by console_answer(), console_autoanswer(), console_dial(), console_flash(), console_hangup(), console_sendtext(), handle_load(), and handle_unload().

#define CLI_SHOWUSAGE   (char *)RESULT_SHOWUSAGE
 

Definition at line 42 of file cli.h.

Referenced by ast_cli_command(), console_answer(), console_autoanswer(), console_dial(), console_flash(), console_hangup(), console_mute(), console_sendtext(), handle_chanlist(), handle_core_set_debug_channel(), handle_debugchan_deprecated(), handle_load(), handle_modlist(), handle_nodebugchan_deprecated(), handle_showuptime(), handle_unload(), and handle_verbose().

#define CLI_SUCCESS   (char *)RESULT_SUCCESS
 

Definition at line 41 of file cli.h.

Referenced by ast_cli_command(), console_answer(), console_autoanswer(), console_dial(), console_flash(), console_hangup(), console_mute(), console_sendtext(), handle_chanlist(), handle_load(), handle_reload(), handle_showuptime(), handle_verbose(), and help1().

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

In many cases we need to print singular or plural words depending on a count. This macro helps us e.g. printf("we have %d object%s", n, ESS(n));

Definition at line 56 of file cli.h.

Referenced by cli_realtime_update(), group_show_channels(), handle_chanlist(), handle_cli_status(), and print_uptimestr().

#define NEW_CLI fn,
txt   )     { .new_handler = fn, .summary = txt, ## __VA_ARGS__ }
 

Definition at line 200 of file cli.h.

#define RESULT_FAILURE   2
 

Definition at line 39 of file cli.h.

Referenced by agi_handle_command(), aji_test(), ast_cli_command(), cli_audio_convert(), cli_realtime_load(), cli_realtime_update(), console_answer(), console_dial(), console_hangup(), console_sendtext(), console_transfer(), handle_answer(), handle_commandmatchesarray(), handle_context_add_extension(), handle_context_add_ignorepat(), handle_context_add_include(), handle_context_remove_extension(), handle_context_remove_ignorepat(), handle_context_remove_include(), handle_controlstreamfile(), handle_getoption(), handle_logger_reload(), handle_logger_rotate(), handle_recordfile(), handle_recvchar(), handle_save_dialplan(), handle_sayalpha(), handle_saydate(), handle_saydatetime(), handle_saydigits(), handle_saynumber(), handle_sayphonetic(), handle_saytime(), handle_sendimage(), handle_sendtext(), handle_show_dialplan(), handle_show_function(), handle_streamfile(), handle_waitfordigit(), misdn_send_display(), realtime_pgsql_status(), show_channeltype(), sip_notify(), zap_destroy_channel(), zap_restart_cmd(), and zap_show_status().

#define RESULT_SHOWUSAGE   1
 

Definition at line 38 of file cli.h.

Referenced by __iax2_show_peers(), __sip_show_channels(), _sip_show_device(), _sip_show_devices(), _sip_show_peer(), _sip_show_peers(), agent_logoff_cmd(), agents_show(), agents_show_online(), agi_do_debug(), agi_handle_command(), agi_no_debug(), aji_test(), ast_cli_command(), cli_audio_convert(), console_active(), console_answer(), console_autoanswer(), console_dial(), console_hangup(), console_sendtext(), console_transfer(), database_del(), database_deltree(), database_get(), database_put(), database_show(), database_showkey(), 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_ep_hangup(), h323_gk_cycle(), h323_no_debug(), h323_no_trace(), h323_tokens_show(), handle_abort_halt(), handle_add_indication(), handle_agidumphtml(), handle_autohangup(), handle_channelstatus(), handle_cli_refresh(), handle_cli_reload(), handle_cli_status(), handle_cli_submit(), handle_commandcomplete(), handle_commandmatchesarray(), handle_commandnummatches(), handle_context_add_extension(), handle_context_add_ignorepat(), handle_context_add_include(), handle_context_remove_extension(), handle_context_remove_ignorepat(), handle_context_remove_include(), handle_controlstreamfile(), handle_dbdel(), handle_dbdeltree(), handle_dbget(), handle_dbput(), handle_exec(), handle_getdata(), handle_getoption(), handle_getvariable(), handle_getvariablefull(), handle_hangup(), handle_logger_mute(), handle_mandebug(), handle_orig(), handle_recordfile(), handle_recvchar(), handle_recvtext(), handle_reload_extensions(), handle_remove_indication(), handle_restart_gracefully(), handle_restart_now(), handle_restart_when_convenient(), handle_save_dialplan(), handle_sayalpha(), handle_saydate(), handle_saydatetime(), handle_saydigits(), handle_saynumber(), handle_sayphonetic(), handle_saytime(), handle_sendimage(), handle_sendtext(), handle_set_global(), handle_setcontext(), handle_setextension(), handle_setpriority(), handle_show_application(), handle_show_dialplan(), handle_show_function(), handle_show_functions(), handle_show_http(), handle_show_version_files(), handle_showagi(), handle_showchan(), handle_showmanager(), handle_showmanagers(), handle_showmancmd(), handle_shutdown_gracefully(), handle_shutdown_now(), handle_shutdown_when_convenient(), handle_softhangup(), handle_streamfile(), handle_tddmode(), handle_verbose(), handle_version(), handle_waitfordigit(), 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_set_mtu(), iax2_show_channels(), iax2_show_firmware(), iax2_show_netstats(), iax2_show_peer(), iax2_show_registry(), iax2_show_stats(), iax2_show_threads(), iax2_show_users(), iax2_test_losspct(), iax_show_provisioning(), locals_show(), mgcp_audit_endpoint(), mgcp_do_debug(), mgcp_no_debug(), mgcp_show_endpoints(), misdn_port_block(), misdn_port_down(), misdn_port_unblock(), misdn_port_up(), misdn_restart_pid(), misdn_restart_port(), misdn_send_cd(), misdn_send_digit(), misdn_send_display(), misdn_set_crypt_debug(), misdn_set_debug(), misdn_set_tics(), misdn_show_cl(), misdn_show_config(), misdn_show_port(), misdn_toggle_echocancel(), my_ulimit(), orig_app(), orig_exten(), rtcp_do_debug(), rtcp_do_debug_ip(), rtcp_do_stats(), rtcp_no_debug(), rtcp_no_stats(), rtp_do_debug(), rtp_do_debug_ip(), rtp_no_debug(), show_channeltype(), show_codec_n(), show_codecs(), show_file_formats(), show_image_formats(), show_translation(), sip_do_debug(), sip_do_debug_device(), sip_do_debug_ip(), sip_do_debug_peer(), sip_do_history(), sip_no_debug(), sip_no_history(), sip_notify(), sip_prune_realtime(), sip_show_channel(), 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_reset_device(), skinny_show_devices(), skinny_show_lines(), stun_do_debug(), stun_no_debug(), udptl_do_debug(), udptl_do_debug_ip(), udptl_nodebug(), zap_destroy_channel(), zap_restart_cmd(), zap_show_channel(), and zap_show_channels().

#define RESULT_SUCCESS   0
 

Definition at line 37 of file cli.h.

Referenced by __iax2_show_peers(), agent_logoff_cmd(), agents_show(), agents_show_online(), agi_do_debug(), agi_no_debug(), aji_do_reload(), ast_cli_command(), cli_audio_convert(), cli_realtime_load(), cli_realtime_update(), console_active(), console_answer(), console_autoanswer(), console_dial(), console_hangup(), console_sendtext(), console_transfer(), database_del(), database_deltree(), database_get(), database_put(), database_show(), database_showkey(), do_boost(), dundi_do_debug(), dundi_do_precache(), dundi_do_query(), dundi_do_store_history(), dundi_no_debug(), dundi_no_store_history(), dundi_show_entityid(), dundi_show_mappings(), dundi_show_peers(), dundi_show_precache(), dundi_show_requests(), dundi_show_trans(), features_show(), group_show_channels(), gtalk_do_reload(), gtalk_show_channels(), h323_do_debug(), h323_do_trace(), h323_ep_hangup(), h323_gk_cycle(), h323_no_debug(), h323_no_trace(), h323_tokens_show(), handle_abort_halt(), handle_answer(), handle_autohangup(), handle_bang(), handle_channelstatus(), handle_commandcomplete(), handle_commandnummatches(), handle_context_add_extension(), handle_context_add_ignorepat(), handle_context_add_include(), handle_context_remove_extension(), handle_context_remove_ignorepat(), handle_context_remove_include(), handle_controlstreamfile(), handle_core_set_debug_channel(), handle_dbdel(), handle_dbdeltree(), handle_dbget(), handle_dbput(), handle_getdata(), handle_getoption(), handle_getvariable(), handle_getvariablefull(), handle_hangup(), handle_help(), handle_logger_mute(), handle_logger_reload(), handle_logger_rotate(), handle_logger_show_channels(), handle_mandebug(), handle_modlist(), handle_noop(), handle_recordfile(), handle_recvchar(), handle_recvtext(), handle_reload_extensions(), handle_restart_gracefully(), handle_restart_now(), handle_restart_when_convenient(), handle_sayalpha(), handle_saydate(), handle_saydatetime(), handle_saydigits(), handle_saynumber(), handle_sayphonetic(), handle_saytime(), handle_sendimage(), handle_sendtext(), handle_set_global(), handle_setcallerid(), handle_setcontext(), handle_setextension(), handle_setmusic(), handle_setpriority(), handle_setvariable(), handle_show_dialplan(), handle_show_function(), handle_show_functions(), handle_show_globals(), handle_show_hints(), handle_show_http(), handle_show_switches(), handle_show_version_files(), handle_showagi(), handle_showchan(), handle_showmanager(), handle_showmanagers(), handle_showmancmds(), handle_showmanconn(), handle_showmaneventq(), handle_shutdown_gracefully(), handle_shutdown_now(), handle_shutdown_when_convenient(), handle_softhangup(), handle_streamfile(), handle_tddmode(), handle_verbose(), handle_version(), handle_waitfordigit(), 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_set_mtu(), iax2_show_cache(), iax2_show_firmware(), iax2_show_netstats(), iax2_show_registry(), iax2_show_stats(), iax2_show_threads(), iax2_show_users(), iax2_test_losspct(), init_keys(), locals_show(), manager_iax2_show_netstats(), mgcp_audit_endpoint(), mgcp_do_debug(), mgcp_no_debug(), mgcp_show_endpoints(), misdn_send_display(), my_ulimit(), orig_app(), orig_exten(), realtime_pgsql_status(), rtcp_do_debug(), rtcp_do_debug_ip(), rtcp_do_stats(), rtcp_no_debug(), rtcp_no_stats(), rtp_do_debug(), rtp_do_debug_ip(), rtp_no_debug(), show_channeltype(), show_channeltypes(), show_file_formats(), show_image_formats(), show_keys(), show_license(), show_warranty(), sip_do_debug(), sip_do_debug_device(), sip_do_debug_ip(), sip_do_debug_peer(), sip_do_history(), sip_listconfigs(), sip_no_debug(), sip_no_history(), sip_show_domains(), sip_show_objects(), sip_show_settings(), sip_show_user(), skinny_do_debug(), skinny_no_debug(), stun_do_debug(), stun_no_debug(), udptl_do_debug(), udptl_do_debug_ip(), udptl_nodebug(), zap_destroy_channel(), and zap_restart_cmd().


Typedef Documentation

typedef char*(* new_cli_fn)(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 

Definition at line 148 of file cli.h.

typedef int(* old_cli_fn)(int fd, int argc, char *argv[])
 

Definition at line 147 of file cli.h.


Enumeration Type Documentation

enum ast_cli_fn
 

calling arguments for new-style handlers See CLI_command_API

Enumerator:
CLI_INIT 
CLI_GENERATE 
CLI_HANDLER 

Definition at line 129 of file cli.h.

00129                 {
00130    CLI_INIT = -2,    /* return the usage string */
00131    CLI_GENERATE = -3,   /* behave as 'generator', remap argv to struct ast_cli_args */
00132    CLI_HANDLER = -4, /* run the normal handler */
00133 };


Function Documentation

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.

Definition at line 1682 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, CLI_HANDLER, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::deprecated, ast_cli_args::fd, find_best(), find_cli(), free, ast_cli_entry::handler, ast_cli_entry::inuse, ast_cli_entry::new_handler, parse_args(), RESULT_FAILURE, RESULT_SHOWUSAGE, RESULT_SUCCESS, S_OR, and ast_cli_entry::usage.

Referenced by action_command(), cli_activate(), consolehandler(), and exit_completely().

01683 {
01684    char *args[AST_MAX_ARGS + 1];
01685    struct ast_cli_entry *e;
01686    int x;
01687    int res;
01688    char *dup = parse_args(s, &x, args + 1, AST_MAX_ARGS, NULL);
01689 
01690    if (dup == NULL)
01691       return -1;
01692 
01693    if (x < 1)  /* We need at least one entry, otherwise ignore */
01694       goto done;
01695 
01696    AST_LIST_LOCK(&helpers);
01697    e = find_cli(args + 1, 0);
01698    if (e)
01699       ast_atomic_fetchadd_int(&e->inuse, 1);
01700    AST_LIST_UNLOCK(&helpers);
01701    if (e == NULL) {
01702       ast_cli(fd, "No such command '%s' (type 'help' for help)\n", find_best(args + 1));
01703       goto done;
01704    }
01705    /*
01706     * Within the handler, argv[-1] contains a pointer to the ast_cli_entry.
01707     * Remember that the array returned by parse_args is NULL-terminated.
01708     */
01709    args[0] = (char *)e;
01710 
01711    if (!e->new_handler) /* old style */
01712       res = e->handler(fd, x, args + 1);
01713    else {
01714       struct ast_cli_args a = {
01715          .fd = fd, .argc = x, .argv = args+1 };
01716       char *retval = e->new_handler(e, CLI_HANDLER, &a);
01717 
01718       if (retval == CLI_SUCCESS)
01719          res = RESULT_SUCCESS;
01720       else if (retval == CLI_SHOWUSAGE)
01721          res = RESULT_SHOWUSAGE;
01722       else
01723          res = RESULT_FAILURE;
01724    }
01725    switch (res) {
01726    case RESULT_SHOWUSAGE:
01727       ast_cli(fd, "%s", S_OR(e->usage, "Invalid usage, but no usage information available.\n"));
01728       break;
01729 
01730    case RESULT_FAILURE:
01731       ast_cli(fd, "Command '%s' failed.\n", s);
01732       /* FALLTHROUGH */
01733    default:
01734       AST_LIST_LOCK(&helpers);
01735       if (e->deprecated == 1) {
01736          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);
01737          e->deprecated = 2;
01738       }
01739       AST_LIST_UNLOCK(&helpers);
01740       break;
01741    }
01742    ast_atomic_fetchadd_int(&e->inuse, -1);
01743 done:
01744    free(dup);
01745    return 0;
01746 }

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

References ast_strdup, ast_strlen_zero(), and len.

Referenced by complete_orig(), and complete_show_applications().

00859 {
00860    int i, which = 0, len;
00861    len = ast_strlen_zero(word) ? 0 : strlen(word);
00862 
00863    for (i = 0; choices[i]; i++) {
00864       if ((!len || !strncasecmp(word, choices[i], len)) && ++which > state)
00865          return ast_strdup(choices[i]);
00866    }
00867    return NULL;
00868 }

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

References ast_cli_generator(), and ast_realloc.

Referenced by cli_complete(), and handle_commandmatchesarray().

01536 {
01537    char **match_list = NULL, *retstr, *prevstr;
01538    size_t match_list_len, max_equal, which, i;
01539    int matches = 0;
01540 
01541    /* leave entry 0 free for the longest common substring */
01542    match_list_len = 1;
01543    while ((retstr = ast_cli_generator(text, word, matches)) != NULL) {
01544       if (matches + 1 >= match_list_len) {
01545          match_list_len <<= 1;
01546          if (!(match_list = ast_realloc(match_list, match_list_len * sizeof(*match_list))))
01547             return NULL;
01548       }
01549       match_list[++matches] = retstr;
01550    }
01551 
01552    if (!match_list)
01553       return match_list; /* NULL */
01554 
01555    /* Find the longest substring that is common to all results
01556     * (it is a candidate for completion), and store a copy in entry 0.
01557     */
01558    prevstr = match_list[1];
01559    max_equal = strlen(prevstr);
01560    for (which = 2; which <= matches; which++) {
01561       for (i = 0; i < max_equal && toupper(prevstr[i]) == toupper(match_list[which][i]); i++)
01562          continue;
01563       max_equal = i;
01564    }
01565 
01566    if (!(retstr = ast_malloc(max_equal + 1)))
01567       return NULL;
01568    
01569    ast_copy_string(retstr, match_list[1], max_equal + 1);
01570    match_list[0] = retstr;
01571 
01572    /* ensure that the array is NULL terminated */
01573    if (matches + 1 >= match_list_len) {
01574       if (!(match_list = ast_realloc(match_list, (match_list_len + 1) * sizeof(*match_list))))
01575          return NULL;
01576    }
01577    match_list[matches + 1] = NULL;
01578 
01579    return match_list;
01580 }

char* ast_cli_generator const char *  ,
const char *  ,
int 
 

Readline madness Useful for readline, that's about it Returns 0 on success, -1 on failure.

Definition at line 1677 of file cli.c.

References __ast_cli_generator().

Referenced by ast_cli_completion_matches(), and ast_cli_generatornummatches().

01678 {
01679    return __ast_cli_generator(text, word, state, 1);
01680 }

int ast_cli_generatornummatches const char *  ,
const char * 
 

Return the number of unique matches for the generator.

Definition at line 1518 of file cli.c.

References ast_cli_generator(), and free.

Referenced by handle_commandnummatches().

01519 {
01520    int matches = 0, i = 0;
01521    char *buf = NULL, *oldbuf = NULL;
01522 
01523    while ((buf = ast_cli_generator(text, word, i++))) {
01524       if (!oldbuf || strcmp(buf,oldbuf))
01525          matches++;
01526       if (oldbuf)
01527          free(oldbuf);
01528       oldbuf = buf;
01529    }
01530    if (oldbuf)
01531       free(oldbuf);
01532    return matches;
01533 }

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

References __ast_cli_register().

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

01350 {
01351    return __ast_cli_register(e, NULL);
01352 }

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 1357 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(), register_config_cli(), and sip_cli_and_manager_commands_register().

01358 {
01359    int i;
01360 
01361    for (i = 0; i < len; i++)
01362       ast_cli_register(e + i);
01363 }

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

References __ast_cli_unregister().

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

01344 {
01345    return __ast_cli_unregister(e, NULL);
01346 }

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

References ast_cli_unregister().

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

01366 {
01367    int i;
01368 
01369    for (i = 0; i < len; i++)
01370       ast_cli_unregister(e + i);
01371 }

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

References ast_channel_unlock, ast_channel_walk_locked(), and ast_strdup.

Referenced by complete_ch_3(), complete_ch_4(), and handle_core_set_debug_channel().

00871 {
00872    struct ast_channel *c = NULL;
00873    int which = 0;
00874    int wordlen;
00875    char notfound = '\0';
00876    char *ret = &notfound; /* so NULL can break the loop */
00877 
00878    if (pos != rpos)
00879       return NULL;
00880 
00881    wordlen = strlen(word); 
00882 
00883    while (ret == &notfound && (c = ast_channel_walk_locked(c))) {
00884       if (!strncasecmp(word, c->name, wordlen) && ++which > state)
00885          ret = ast_strdup(c->name);
00886       ast_channel_unlock(c);
00887    }
00888    return ret == &notfound ? NULL : ret;
00889 }


Asterisk is a trademark for Digium, inc.. | Edvina.net | Asterisk.org | This documentation was generated with Doxygen