Asterisk - The Open Source Telephony Project
21.4.1
|
Standard Command Line Interface. More...
Go to the source code of this file.
Data Structures | |
struct | ast_cli_args |
struct | ast_cli_entry |
descriptor for a cli entry. More... | |
Macros | |
#define | ast_cli_command(fd, s) ast_cli_command_full(CLI_NO_PERMS, CLI_NO_PERMS, fd, s) |
#define | ast_cli_command_multiple(fd, size, s) ast_cli_command_multiple_full(CLI_NO_PERMS, CLI_NO_PERMS, fd, size, s) |
#define | AST_CLI_COMPLETE_EOF "_EOF_" |
#define | AST_CLI_DEFINE(fn, txt, ...) { .handler = fn, .summary = txt, ## __VA_ARGS__ } |
#define | AST_CLI_ONOFF(x) (x) ? "On" : "Off" |
return On or Off depending on the argument. This is used in many places in CLI command, having a function to generate this helps maintaining a consistent output (and possibly emitting the output in other languages, at some point). | |
#define | ast_cli_register(e) __ast_cli_register(e, AST_MODULE_SELF) |
Registers a command or an array of commands. More... | |
#define | ast_cli_register_multiple(e, len) __ast_cli_register_multiple(e, len, AST_MODULE_SELF) |
Register multiple commands. More... | |
#define | AST_CLI_YESNO(x) AST_YESNO(x) |
Return Yes or No depending on the argument. More... | |
#define | AST_MAX_ARGS 64 |
#define | AST_MAX_CMD_LEN 16 |
#define | CLI_FAILURE (char *)RESULT_FAILURE |
#define | CLI_NO_PERMS -1 |
#define | CLI_SHOWUSAGE (char *)RESULT_SHOWUSAGE |
#define | CLI_SUCCESS (char *)RESULT_SUCCESS |
#define | ESS(x) ((x) == 1 ? "" : "s") |
#define | RESULT_FAILURE 2 |
#define | RESULT_SHOWUSAGE 1 |
#define | RESULT_SUCCESS 0 |
Enumerations | |
enum | ast_cli_command { CLI_INIT = -2, CLI_GENERATE = -3, CLI_HANDLER = -4 } |
calling arguments for new-style handlers. More... | |
Functions | |
int | __ast_cli_register (struct ast_cli_entry *e, struct ast_module *mod) |
int | __ast_cli_register_multiple (struct ast_cli_entry *e, int len, struct ast_module *mod) |
void | ast_cli (int fd, const char *fmt,...) |
int | ast_cli_allow_at_shutdown (struct ast_cli_entry *e) |
Allow a CLI command to be executed while Asterisk is shutting down. More... | |
int | ast_cli_command_full (int uid, int gid, int fd, const char *s) |
Interprets a command Interpret a command s, sending output to fd if uid:gid has permissions to run this command. uid = CLI_NO_PERMS to avoid checking user permissions gid = CLI_NO_PERMS to avoid checking group permissions. More... | |
int | ast_cli_command_multiple_full (int uid, int gid, int fd, size_t size, const char *s) |
Executes multiple CLI commands Interpret strings separated by NULL and execute each one, sending output to fd if uid has permissions, uid = CLI_NO_PERMS to avoid checking users permissions. gid = CLI_NO_PERMS to avoid checking group permissions. More... | |
char * | ast_cli_complete (const char *word, const char *const choices[], int pos) |
int | ast_cli_completion_add (char *value) |
Add a result to a request for completion options. More... | |
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. More... | |
struct ast_vector_string * | ast_cli_completion_vector (const char *text, const char *word) |
Generates a vector of strings for CLI completion. More... | |
char * | ast_cli_generator (const char *, const char *, int) |
Readline madness Useful for readline, that's about it. More... | |
void | ast_cli_print_timestr_fromseconds (int fd, int seconds, const char *prefix) |
Print on cli a duration in seconds in format s year(s), s week(s), s day(s), s hour(s), s second(s) More... | |
int | ast_cli_unregister (struct ast_cli_entry *e) |
Unregisters a command or an array of commands. More... | |
int | ast_cli_unregister_multiple (struct ast_cli_entry *e, int len) |
Unregister multiple commands. More... | |
char * | ast_complete_channels (const char *line, const char *word, int pos, int state, int rpos) |
Command completion for the list of active channels. More... | |
Standard Command Line Interface.
Definition in file cli.h.
#define ast_cli_register | ( | e | ) | __ast_cli_register(e, AST_MODULE_SELF) |
Registers a command or an array of commands.
e | which cli entry to register. Register your own command |
0 | on success |
-1 | on failure |
Definition at line 256 of file cli.h.
Referenced by load_config().
#define ast_cli_register_multiple | ( | e, | |
len | |||
) | __ast_cli_register_multiple(e, len, AST_MODULE_SELF) |
Register multiple commands.
e | pointer to first cli entry to register |
len | number of entries to register |
Definition at line 265 of file cli.h.
Referenced by aco_init(), ast_aoc_cli_init(), ast_ari_cli_register(), ast_bridging_init(), ast_builtins_init(), ast_channels_init(), ast_cli_channels_init(), ast_codec_init(), ast_file_init(), ast_image_init(), ast_local_init(), ast_media_cache_init(), ast_sip_initialize_scheduler(), ast_stun_init(), ast_test_init(), ast_timing_init(), ast_tps_init(), ast_translate_init(), astdb_init(), astobj2_init(), cli_init(), conf_load_config(), crypto_init(), init_logger(), load_module(), load_parking_ui(), load_pbx(), load_pbx_app(), load_pbx_functions_cli(), load_pbx_hangup_handler(), load_pbx_switch(), load_pbx_variables(), pjsip_channel_cli_register(), register_config_cli(), rtp_reload(), and stasis_init().
#define AST_CLI_YESNO | ( | x | ) | AST_YESNO(x) |
Return Yes or No depending on the argument.
Note that this should probably still be used for CLI commands instead of AST_YESNO(), in the off chance we someday want to translate the CLI.
x | Boolean value |
Definition at line 71 of file cli.h.
Referenced by action_coresettings(), and handle_manager_show_settings().
#define ESS | ( | x | ) | ((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 59 of file cli.h.
Referenced by auto_unload_resource().
enum ast_cli_command |
calling arguments for new-style handlers.
int ast_cli_allow_at_shutdown | ( | struct ast_cli_entry * | e | ) |
Allow a CLI command to be executed while Asterisk is shutting down.
CLI commands by defeault are disabled when Asterisk is shutting down. This is to ensure the safety of the shutdown since CLI commands may attempt to access resources that have been freed as a result of the shutdown.
If a CLI command should be allowed at shutdown, then the best way to enable this is to call ast_cli_allow_at_shutdown during the CLI_INIT state of the CLI handler.
Definition at line 3061 of file main/cli.c.
References AST_VECTOR_APPEND.
int ast_cli_command_full | ( | int | uid, |
int | gid, | ||
int | fd, | ||
const char * | s | ||
) |
Interprets a command Interpret a command s, sending output to fd if uid:gid has permissions to run this command. uid = CLI_NO_PERMS to avoid checking user permissions gid = CLI_NO_PERMS to avoid checking group permissions.
uid | User ID that is trying to run the command. |
gid | Group ID that is trying to run the command. |
fd | pipe |
s | incoming string |
0 | on success |
-1 | on failure |
Definition at line 2974 of file main/cli.c.
References ast_atomic_fetchadd_int(), ast_join, ast_module_running_ref, ast_module_unref, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_shutting_down(), find_best(), ast_cli_entry::inuse, ast_cli_entry::module, S_OR, and ast_cli_entry::usage.
Referenced by ast_cli_command_multiple_full().
int ast_cli_command_multiple_full | ( | int | uid, |
int | gid, | ||
int | fd, | ||
size_t | size, | ||
const char * | s | ||
) |
Executes multiple CLI commands Interpret strings separated by NULL and execute each one, sending output to fd if uid has permissions, uid = CLI_NO_PERMS to avoid checking users permissions. gid = CLI_NO_PERMS to avoid checking group permissions.
uid | User ID that is trying to run the command. |
gid | Group ID that is trying to run the command. |
fd | pipe |
size | is the total size of the string |
s | incoming string |
Definition at line 3039 of file main/cli.c.
References ast_cli_command_full().
char* ast_cli_complete | ( | const char * | word, |
const 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):
Definition at line 1846 of file main/cli.c.
References ast_cli_completion_add(), and ast_strdup.
Referenced by handle_orig().
int ast_cli_completion_add | ( | char * | value | ) |
Add a result to a request for completion options.
value | A completion option text. |
0 | Success |
-1 | Failure |
This is an alternative to returning individual values from CLI_GENERATE. Instead of repeatedly being asked for the next match and having to start over, you can call this function repeatedly from your own stateful loop. When all matches have been added you can return NULL from the CLI_GENERATE function.
Definition at line 2761 of file main/cli.c.
References ast_threadstorage_get_ptr().
Referenced by ast_cli_complete(), ast_complete_applications(), ast_complete_channels(), cli_complete_show(), handle_cli_sound_show(), and handle_show_named_acl_cmd().
char** ast_cli_completion_matches | ( | const char * | , |
const char * | |||
) |
Generates a NULL-terminated array of strings that 1) begin with the string in the second parameter, and 2) are valid in a command after the string in the first parameter.
The first entry (offset 0) of the result is the longest common substring in the results, useful to extend the string that has been completed. Subsequent entries are all possible values, followed by a NULL. All strings and the array itself are malloc'ed and must be freed by the caller.
Definition at line 2705 of file main/cli.c.
References ast_cli_completion_vector(), AST_VECTOR_APPEND, AST_VECTOR_CALLBACK_VOID, AST_VECTOR_PTR_FREE, and AST_VECTOR_STEAL_ELEMENTS.
struct ast_vector_string* ast_cli_completion_vector | ( | const char * | text, |
const char * | word | ||
) |
Generates a vector of strings for CLI completion.
text | Complete input being matched. |
word | Current word being matched |
The results contain strings that both: 1) Begin with the string in word. 2) Are valid in a command after the string in text.
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.
Definition at line 2766 of file main/cli.c.
References ast_calloc, ast_cli_generator(), ast_strndup, ast_threadstorage_get_ptr(), ast_threadstorage_set_ptr(), AST_VECTOR_CALLBACK_VOID, AST_VECTOR_GET, AST_VECTOR_INSERT_AT, AST_VECTOR_PTR_FREE, AST_VECTOR_REMOVE, and AST_VECTOR_SIZE.
Referenced by ast_cli_completion_matches().
char* ast_cli_generator | ( | const char * | , |
const char * | , | ||
int | |||
) |
Readline madness Useful for readline, that's about it.
0 | on success |
-1 | on failure |
Only call this function to proxy the CLI generator to another.
Definition at line 2952 of file main/cli.c.
Referenced by ast_cli_completion_vector(), cli_alias_passthrough(), and handle_cli_check_permissions().
void ast_cli_print_timestr_fromseconds | ( | int | fd, |
int | seconds, | ||
const char * | prefix | ||
) |
Print on cli a duration in seconds in format s year(s), s week(s), s day(s), s hour(s), s second(s)
fd | fd to print by ast_cli |
seconds | The time (in seconds) to print |
prefix | A Prefix string to add before of duration formatted |
Definition at line 3056 of file main/cli.c.
References ast_tv().
Referenced by handle_cdr_pgsql_status(), and realtime_ldap_status().
int ast_cli_unregister | ( | struct ast_cli_entry * | e | ) |
Unregisters a command or an array of commands.
e | which cli entry to unregister Unregister your own command. You must pass a completed ast_cli_entry structure |
Definition at line 2432 of file main/cli.c.
References ast_cli_entry::_full_cmd, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_cli_entry::cmda, ast_cli_entry::command, ast_cli_entry::inuse, and ast_cli_entry::usage.
Referenced by alias_unregister_cb(), ast_cli_unregister_multiple(), unload_module(), and xmldoc_unload_documentation().
int ast_cli_unregister_multiple | ( | struct ast_cli_entry * | e, |
int | len | ||
) |
Unregister multiple commands.
e | pointer to first cli entry to unregister |
len | number of entries to unregister |
Definition at line 30 of file clicompat.c.
References ast_cli_unregister().
Referenced by ast_ari_cli_unregister(), close_logger(), codec_shutdown(), conf_destroy_config(), load_module(), pjsip_channel_cli_unregister(), rtp_reload(), stasis_cleanup(), unload_module(), and unload_parking_ui().
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 1865 of file main/cli.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_ref, ast_cli_completion_add(), ast_strdup, ast_channel_snapshot::base, ast_channel_snapshot_base::name, and ast_channel_snapshot::state.
Referenced by handle_cli_agi_add_cmd(), handle_redirect(), handle_show_chanvar(), handle_show_hangup_channel(), and handle_showchan().