#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 991 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.
00992 { 00993 char *argv[AST_MAX_ARGS]; 00994 struct ast_cli_entry *e; 00995 int x; 00996 char *dup; 00997 x = AST_MAX_ARGS; 00998 if ((dup = parse_args(s, &x, argv))) { 00999 /* We need at least one entry, or ignore */ 01000 if (x > 0) { 01001 ast_mutex_lock(&clilock); 01002 e = find_cli(argv, 0); 01003 if (e) 01004 e->inuse++; 01005 ast_mutex_unlock(&clilock); 01006 if (e) { 01007 switch(e->handler(fd, x, argv)) { 01008 case RESULT_SHOWUSAGE: 01009 ast_cli(fd, e->usage); 01010 break; 01011 } 01012 } else 01013 ast_cli(fd, "No such command '%s' (type 'help' for help)\n", find_best(argv)); 01014 if (e) { 01015 ast_mutex_lock(&clilock); 01016 e->inuse--; 01017 ast_mutex_unlock(&clilock); 01018 } 01019 } 01020 free(dup); 01021 } else { 01022 ast_log(LOG_WARNING, "Out of memory\n"); 01023 return -1; 01024 } 01025 return 0; 01026 } |
|
Definition at line 876 of file cli.c. References ast_cli_generator(), malloc, and realloc.
00877 { 00878 char **match_list = NULL, *retstr, *prevstr; 00879 size_t match_list_len, max_equal, which, i; 00880 int matches = 0; 00881 00882 match_list_len = 1; 00883 while ((retstr = ast_cli_generator(text, word, matches)) != NULL) { 00884 if (matches + 1 >= match_list_len) { 00885 match_list_len <<= 1; 00886 match_list = realloc(match_list, match_list_len * sizeof(char *)); 00887 } 00888 match_list[++matches] = retstr; 00889 } 00890 00891 if (!match_list) 00892 return (char **) NULL; 00893 00894 which = 2; 00895 prevstr = match_list[1]; 00896 max_equal = strlen(prevstr); 00897 for (; which <= matches; which++) { 00898 for (i = 0; i < max_equal && prevstr[i] == match_list[which][i]; i++) 00899 continue; 00900 max_equal = i; 00901 } 00902 00903 retstr = malloc(max_equal + 1); 00904 (void) strncpy(retstr, match_list[1], max_equal); 00905 retstr[max_equal] = '\0'; 00906 match_list[0] = retstr; 00907 00908 if (matches + 1 >= match_list_len) 00909 match_list = realloc(match_list, (match_list_len + 1) * sizeof(char *)); 00910 match_list[matches + 1] = (char *) NULL; 00911 00912 return (match_list); 00913 } |
|
Readline madness.
Definition at line 986 of file cli.c. Referenced by ast_cli_completion_matches(), and ast_cli_generatornummatches().
00987 {
00988 return __ast_cli_generator(text, word, state, 1);
00989 }
|
|
Definition at line 859 of file cli.c. References ast_cli_generator().
00860 { 00861 int matches = 0, i = 0; 00862 char *buf, *oldbuf = NULL; 00863 00864 00865 while ( (buf = ast_cli_generator(text, word, i)) ) { 00866 if (++i > 1 && strcmp(buf,oldbuf) == 0) { 00867 continue; 00868 } 00869 oldbuf = buf; 00870 matches++; 00871 } 00872 00873 return matches; 00874 } |
|
Registers a command.
Definition at line 682 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().
00683 { 00684 struct ast_cli_entry *cur, *l=NULL; 00685 char fulle[80] ="", fulltst[80] =""; 00686 static int len; 00687 ast_mutex_lock(&clilock); 00688 join2(fulle, sizeof(fulle), e->cmda); 00689 if (find_cli(e->cmda, -1)) { 00690 ast_mutex_unlock(&clilock); 00691 ast_log(LOG_WARNING, "Command '%s' already registered (or something close enough)\n", fulle); 00692 return -1; 00693 } 00694 cur = helpers; 00695 while(cur) { 00696 join2(fulltst, sizeof(fulltst), cur->cmda); 00697 len = strlen(fulltst); 00698 if (strlen(fulle) < len) 00699 len = strlen(fulle); 00700 if (strncasecmp(fulle, fulltst, len) < 0) { 00701 if (l) { 00702 e->next = l->next; 00703 l->next = e; 00704 } else { 00705 e->next = helpers; 00706 helpers = e; 00707 } 00708 break; 00709 } 00710 l = cur; 00711 cur = cur->next; 00712 } 00713 if (!cur) { 00714 if (l) 00715 l->next = e; 00716 else 00717 helpers = e; 00718 e->next = NULL; 00719 } 00720 ast_mutex_unlock(&clilock); 00721 return 0; 00722 } |
|
Unregisters a command.
Definition at line 656 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.
00657 { 00658 struct ast_cli_entry *cur, *l=NULL; 00659 ast_mutex_lock(&clilock); 00660 cur = helpers; 00661 while(cur) { 00662 if (e == cur) { 00663 if (e->inuse) { 00664 ast_log(LOG_WARNING, "Can't remove command that is in use\n"); 00665 } else { 00666 /* Rewrite */ 00667 if (l) 00668 l->next = e->next; 00669 else 00670 helpers = e->next; 00671 e->next = NULL; 00672 break; 00673 } 00674 } 00675 l = cur; 00676 cur = cur->next; 00677 } 00678 ast_mutex_unlock(&clilock); 00679 return 0; 00680 } |
|
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(). |