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