#include <stdarg.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.
Defines | |
| #define | AST_CLI_COMPLETE_EOF "_EOF_" |
| #define | AST_MAX_ARGS 64 |
| #define | AST_MAX_CMD_LEN 16 |
| #define | RESULT_FAILURE 2 |
| #define | RESULT_SHOWUSAGE 1 |
| #define | RESULT_SUCCESS 0 |
Functions | |
| void | ast_cli (int fd, char *fmt,...) __attribute__((format(printf |
| int | ast_cli_command (int fd, char *s) |
| Interprets a command Interpret a command s, sending output to fd Returns 0 on succes, -1 on failure. | |
| char ** | ast_cli_completion_matches (char *, char *) |
| char * | ast_cli_generator (char *, char *, int) |
| Readline madness Useful for readline, that's about it Returns 0 on success, -1 on failure. | |
| int | ast_cli_generatornummatches (char *, char *) |
| 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. | |
Definition in file cli.h.
|
|
Definition at line 43 of file cli.h. Referenced by ast_el_strtoarr(), cli_complete(), and handle_commandmatchesarray(). |
|
|
Definition at line 41 of file cli.h. Referenced by __ast_cli_generator(), and ast_cli_command(). |
|
|
Definition at line 39 of file cli.h. Referenced by find_best(). |
|
|
|
|
||||||||||||||||
|
|
|
||||||||||||
|
Interprets a command Interpret a command s, sending output to fd Returns 0 on succes, -1 on failure.
Definition at line 1347 of file cli.c. References ast_cli(), ast_log(), AST_MAX_ARGS, ast_mutex_lock(), ast_mutex_unlock(), find_best(), find_cli(), free, ast_cli_entry::handler, ast_cli_entry::inuse, LOG_WARNING, parse_args(), RESULT_SHOWUSAGE, and ast_cli_entry::usage. Referenced by action_command(), cli_activate(), consolehandler(), exit_completely(), and netconsole(). 01348 {
01349 char *argv[AST_MAX_ARGS];
01350 struct ast_cli_entry *e;
01351 int x;
01352 char *dup;
01353 int tws;
01354
01355 if ((dup = parse_args(s, &x, argv, sizeof(argv) / sizeof(argv[0]), &tws))) {
01356 /* We need at least one entry, or ignore */
01357 if (x > 0) {
01358 ast_mutex_lock(&clilock);
01359 e = find_cli(argv, 0);
01360 if (e)
01361 e->inuse++;
01362 ast_mutex_unlock(&clilock);
01363 if (e) {
01364 switch(e->handler(fd, x, argv)) {
01365 case RESULT_SHOWUSAGE:
01366 if (e->usage)
01367 ast_cli(fd, "%s", e->usage);
01368 else
01369 ast_cli(fd, "%s", "Invalid usage, but no usage information available.\n");
01370 break;
01371 }
01372 } else
01373 ast_cli(fd, "No such command '%s' (type 'help' for help)\n", find_best(argv));
01374 if (e) {
01375 ast_mutex_lock(&clilock);
01376 e->inuse--;
01377 ast_mutex_unlock(&clilock);
01378 }
01379 }
01380 free(dup);
01381 } else {
01382 ast_log(LOG_WARNING, "Out of memory\n");
01383 return -1;
01384 }
01385 return 0;
01386 }
|
|
||||||||||||
|
Definition at line 1227 of file cli.c. References ast_cli_generator(), malloc, and realloc. Referenced by cli_complete(), and handle_commandmatchesarray(). 01228 {
01229 char **match_list = NULL, *retstr, *prevstr;
01230 size_t match_list_len, max_equal, which, i;
01231 int matches = 0;
01232
01233 match_list_len = 1;
01234 while ((retstr = ast_cli_generator(text, word, matches)) != NULL) {
01235 if (matches + 1 >= match_list_len) {
01236 match_list_len <<= 1;
01237 match_list = realloc(match_list, match_list_len * sizeof(char *));
01238 }
01239 match_list[++matches] = retstr;
01240 }
01241
01242 if (!match_list)
01243 return (char **) NULL;
01244
01245 which = 2;
01246 prevstr = match_list[1];
01247 max_equal = strlen(prevstr);
01248 for (; which <= matches; which++) {
01249 for (i = 0; i < max_equal && toupper(prevstr[i]) == toupper(match_list[which][i]); i++)
01250 continue;
01251 max_equal = i;
01252 }
01253
01254 retstr = malloc(max_equal + 1);
01255 (void) strncpy(retstr, match_list[1], max_equal);
01256 retstr[max_equal] = '\0';
01257 match_list[0] = retstr;
01258
01259 if (matches + 1 >= match_list_len)
01260 match_list = realloc(match_list, (match_list_len + 1) * sizeof(char *));
01261 match_list[matches + 1] = (char *) NULL;
01262
01263 return (match_list);
01264 }
|
|
||||||||||||||||
|
Readline madness Useful for readline, that's about it Returns 0 on success, -1 on failure.
Definition at line 1342 of file cli.c. References __ast_cli_generator(). Referenced by ast_cli_completion_matches(), and ast_cli_generatornummatches(). 01343 {
01344 return __ast_cli_generator(text, word, state, 1);
01345 }
|
|
||||||||||||
|
Definition at line 1210 of file cli.c. References ast_cli_generator(), and free. Referenced by cli_complete(), and handle_commandnummatches(). 01211 {
01212 int matches = 0, i = 0;
01213 char *buf = NULL, *oldbuf = NULL;
01214
01215 while ( (buf = ast_cli_generator(text, word, i++)) ) {
01216 if (!oldbuf || strcmp(buf,oldbuf))
01217 matches++;
01218 if (oldbuf)
01219 free(oldbuf);
01220 oldbuf = buf;
01221 }
01222 if (oldbuf)
01223 free(oldbuf);
01224 return matches;
01225 }
|
|
|
Registers a command or an array of commands.
Definition at line 1018 of file cli.c. References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_cli_entry::cmda, find_cli(), join2(), LOG_WARNING, and ast_cli_entry::next. Referenced by ast_cdr_engine_init(), ast_channels_init(), ast_cli_register_multiple(), ast_file_init(), ast_image_init(), ast_register_translator(), ast_rtp_init(), astdb_init(), crypto_init(), dnsmgr_init(), do_reload(), iax_provision_init(), init_logger(), init_manager(), load_module(), register_config_cli(), and unload_module(). 01019 {
01020 struct ast_cli_entry *cur, *l=NULL;
01021 char fulle[80] ="", fulltst[80] ="";
01022 static int len;
01023 ast_mutex_lock(&clilock);
01024 join2(fulle, sizeof(fulle), e->cmda);
01025 if (find_cli(e->cmda, -1)) {
01026 ast_mutex_unlock(&clilock);
01027 ast_log(LOG_WARNING, "Command '%s' already registered (or something close enough)\n", fulle);
01028 return -1;
01029 }
01030 cur = helpers;
01031 while(cur) {
01032 join2(fulltst, sizeof(fulltst), cur->cmda);
01033 len = strlen(fulltst);
01034 if (strlen(fulle) < len)
01035 len = strlen(fulle);
01036 if (strncasecmp(fulle, fulltst, len) < 0) {
01037 if (l) {
01038 e->next = l->next;
01039 l->next = e;
01040 } else {
01041 e->next = helpers;
01042 helpers = e;
01043 }
01044 break;
01045 }
01046 l = cur;
01047 cur = cur->next;
01048 }
01049 if (!cur) {
01050 if (l)
01051 l->next = e;
01052 else
01053 helpers = e;
01054 e->next = NULL;
01055 }
01056 ast_mutex_unlock(&clilock);
01057 return 0;
01058 }
|
|
||||||||||||
|
Register multiple commands.
Definition at line 1063 of file cli.c. References ast_cli_register(). Referenced by init_framer(), load_module(), load_pbx(), and main(). 01064 {
01065 int i;
01066
01067 for (i=0; i < len; i++)
01068 ast_cli_register(e + i);
01069 }
|
|
|
Unregisters a command or an array of commands.
Definition at line 992 of file cli.c. References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_cli_entry::inuse, LOG_WARNING, and ast_cli_entry::next. Referenced by ast_cli_unregister_multiple(), do_reload(), iax_provision_unload(), and unload_module(). 00993 {
00994 struct ast_cli_entry *cur, *l=NULL;
00995 ast_mutex_lock(&clilock);
00996 cur = helpers;
00997 while(cur) {
00998 if (e == cur) {
00999 if (e->inuse) {
01000 ast_log(LOG_WARNING, "Can't remove command that is in use\n");
01001 } else {
01002 /* Rewrite */
01003 if (l)
01004 l->next = e->next;
01005 else
01006 helpers = e->next;
01007 e->next = NULL;
01008 break;
01009 }
01010 }
01011 l = cur;
01012 cur = cur->next;
01013 }
01014 ast_mutex_unlock(&clilock);
01015 return 0;
01016 }
|
|
||||||||||||
|
Unregister multiple commands.
Definition at line 1071 of file cli.c. References ast_cli_unregister(). Referenced by __unload_module(), and unload_module(). 01072 {
01073 int i;
01074
01075 for (i=0; i < len; i++)
01076 ast_cli_unregister(e + i);
01077 }
|
1.4.2