#include <unistd.h>#include <stdlib.h>#include <asterisk/logger.h>#include <asterisk/options.h>#include <asterisk/cli.h>#include <asterisk/module.h>#include <asterisk/channel.h>#include <asterisk/channel_pvt.h>#include <sys/signal.h>#include <stdio.h>#include <signal.h>#include <string.h>#include <pthread.h>#include "readline/readline.h"#include "asterisk.h"#include "build.h"#include "astconf.h"Go to the source code of this file.
Defines | |
| #define | VERSION_INFO |
| #define | MODLIST_FORMAT "%-25s %-40.40s %-10d\n" |
| #define | MODLIST_FORMAT2 "%-25s %-40.40s %-10s\n" |
| #define | SECOND (1) |
| #define | MIN (SECOND*60) |
| #define | HOUR (MIN*60) |
| #define | DAY (HOUR*24) |
| #define | WEEK (DAY*7) |
| #define | YEAR (DAY*365) |
| #define | FORMAT_STRING "%15s (%-10s %-12s %-4d) %7s %-12s %-15s\n" |
| #define | FORMAT_STRING2 "%15s (%-10s %-12s %-4s) %7s %-12s %-15s\n" |
Functions | |
| void | ast_cli (int fd, char *fmt,...) |
| int | ast_cli_unregister (struct ast_cli_entry *e) |
| Unregisters a command. | |
| int | ast_cli_register (struct ast_cli_entry *e) |
| Registers a command. | |
| int | ast_cli_generatornummatches (char *text, char *word) |
| char ** | ast_cli_completion_matches (char *text, char *word) |
| char * | ast_cli_generator (char *text, char *word, int state) |
| Readline madness. | |
| int | ast_cli_command (int fd, char *s) |
| Interprets a command. | |
Variables | |
| ast_mutex_t | clilock = AST_MUTEX_INITIALIZER |
| ast_cli_entry * | helpers = NULL |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Value: "Asterisk " ASTERISK_VERSION " built by " BUILD_USER "@" BUILD_HOSTNAME \ " on a " BUILD_MACHINE " running " BUILD_OS |
|
|
|
|
|
|
|
||||||||||||||||
|
Definition at line 37 of file cli.c. References free, and vasprintf.
|
|
||||||||||||
|
Interprets a command. Interpret a command s, sending output to fd Returns 0 on succes, -1 on failure Definition at line 1003 of file cli.c. References ast_cli(), ast_log(), AST_MAX_ARGS, ast_mutex_lock, ast_mutex_unlock, clilock, free, LOG_WARNING, RESULT_SHOWUSAGE, and s.
01004 {
01005 char *argv[AST_MAX_ARGS];
01006 struct ast_cli_entry *e;
01007 int x;
01008 char *dup;
01009 x = AST_MAX_ARGS;
01010 if ((dup = parse_args(s, &x, argv))) {
01011 /* We need at least one entry, or ignore */
01012 if (x > 0) {
01013 ast_mutex_lock(&clilock);
01014 e = find_cli(argv, 0);
01015 if (e)
01016 e->inuse++;
01017 ast_mutex_unlock(&clilock);
01018 if (e) {
01019 switch(e->handler(fd, x, argv)) {
01020 case RESULT_SHOWUSAGE:
01021 ast_cli(fd, e->usage);
01022 break;
01023 }
01024 } else
01025 ast_cli(fd, "No such command '%s' (type 'help' for help)\n", find_best(argv));
01026 if (e) {
01027 ast_mutex_lock(&clilock);
01028 e->inuse--;
01029 ast_mutex_unlock(&clilock);
01030 }
01031 }
01032 free(dup);
01033 } else {
01034 ast_log(LOG_WARNING, "Out of memory\n");
01035 return -1;
01036 }
01037 return 0;
01038 }
|
|
||||||||||||
|
Definition at line 887 of file cli.c. References ast_cli_generator(), malloc, and realloc.
00888 {
00889 char **match_list = NULL, *retstr, *prevstr;
00890 size_t match_list_len, max_equal, which, i;
00891 int matches = 0;
00892
00893 match_list_len = 1;
00894 while ((retstr = ast_cli_generator(text, word, matches)) != NULL) {
00895 if (matches + 1 >= match_list_len) {
00896 match_list_len <<= 1;
00897 match_list = realloc(match_list, match_list_len * sizeof(char *));
00898 }
00899 match_list[++matches] = retstr;
00900 }
00901
00902 if (!match_list)
00903 return (char **) NULL;
00904
00905 which = 2;
00906 prevstr = match_list[1];
00907 max_equal = strlen(prevstr);
00908 for (; which <= matches; which++) {
00909 for (i = 0; i < max_equal && prevstr[i] == match_list[which][i]; i++)
00910 continue;
00911 max_equal = i;
00912 }
00913
00914 retstr = malloc(max_equal + 1);
00915 (void) strncpy(retstr, match_list[1], max_equal);
00916 retstr[max_equal] = '\0';
00917 match_list[0] = retstr;
00918
00919 if (matches + 1 >= match_list_len)
00920 match_list = realloc(match_list, (match_list_len + 1) * sizeof(char *));
00921 match_list[matches + 1] = (char *) NULL;
00922
00923 return (match_list);
00924 }
|
|
||||||||||||||||
|
Readline madness.
Definition at line 998 of file cli.c. Referenced by ast_cli_completion_matches(), and ast_cli_generatornummatches().
00999 {
01000 return __ast_cli_generator(text, word, state, 1);
01001 }
|
|
||||||||||||
|
Definition at line 870 of file cli.c. References ast_cli_generator().
00871 {
00872 int matches = 0, i = 0;
00873 char *buf, *oldbuf = NULL;
00874
00875
00876 while ( (buf = ast_cli_generator(text, word, i)) ) {
00877 if (++i > 1 && strcmp(buf,oldbuf) == 0) {
00878 continue;
00879 }
00880 oldbuf = buf;
00881 matches++;
00882 }
00883
00884 return matches;
00885 }
|
|
|
Registers a command.
Definition at line 693 of file cli.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, clilock, ast_cli_entry::cmda, helpers, LOG_WARNING, and ast_cli_entry::next. Referenced by ast_image_init(), ast_register_translator(), astdb_init(), init_framer(), init_logger(), init_manager(), and main().
00694 {
00695 struct ast_cli_entry *cur, *l=NULL;
00696 char fulle[80] ="", fulltst[80] ="";
00697 static int len;
00698 ast_mutex_lock(&clilock);
00699 join2(fulle, sizeof(fulle), e->cmda);
00700 if (find_cli(e->cmda, -1)) {
00701 ast_mutex_unlock(&clilock);
00702 ast_log(LOG_WARNING, "Command '%s' already registered (or something close enough)\n", fulle);
00703 return -1;
00704 }
00705 cur = helpers;
00706 while(cur) {
00707 join2(fulltst, sizeof(fulltst), cur->cmda);
00708 len = strlen(fulltst);
00709 if (strlen(fulle) < len)
00710 len = strlen(fulle);
00711 if (strncasecmp(fulle, fulltst, len) < 0) {
00712 if (l) {
00713 e->next = l->next;
00714 l->next = e;
00715 } else {
00716 e->next = helpers;
00717 helpers = e;
00718 }
00719 break;
00720 }
00721 l = cur;
00722 cur = cur->next;
00723 }
00724 if (!cur) {
00725 if (l)
00726 l->next = e;
00727 else
00728 helpers = e;
00729 e->next = NULL;
00730 }
00731 ast_mutex_unlock(&clilock);
00732 return 0;
00733 }
|
|
|
Unregisters a command.
Definition at line 667 of file cli.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, clilock, helpers, ast_cli_entry::inuse, LOG_WARNING, and ast_cli_entry::next.
00668 {
00669 struct ast_cli_entry *cur, *l=NULL;
00670 ast_mutex_lock(&clilock);
00671 cur = helpers;
00672 while(cur) {
00673 if (e == cur) {
00674 if (e->inuse) {
00675 ast_log(LOG_WARNING, "Can't remove command that is in use\n");
00676 } else {
00677 /* Rewrite */
00678 if (l)
00679 l->next = e->next;
00680 else
00681 helpers = e->next;
00682 e->next = NULL;
00683 break;
00684 }
00685 }
00686 l = cur;
00687 cur = cur->next;
00688 }
00689 ast_mutex_unlock(&clilock);
00690 return 0;
00691 }
|
|
|
Definition at line 48 of file cli.c. Referenced by ast_cli_command(), ast_cli_register(), and ast_cli_unregister(). |
|
|
Definition at line 51 of file cli.c. Referenced by ast_cli_register(), and ast_cli_unregister(). |
1.3.6-20040222