#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 <asterisk/manager.h>#include <asterisk/utils.h>#include <asterisk/lock.h>#include <sys/signal.h>#include <stdio.h>#include <signal.h>#include <string.h>#include <ctype.h>#include "editline/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 | MINUTE (SECOND*60) |
| #define | HOUR (MINUTE*60) |
| #define | DAY (HOUR*24) |
| #define | WEEK (DAY*7) |
| #define | YEAR (DAY*365) |
| #define | ESS(x) ((x == 1) ? "" : "s") |
| #define | FORMAT_STRING "%15s (%-10s %-12s %-4d) %7s %-12s %-15s\n" |
| #define | FORMAT_STRING2 "%15s (%-10s %-12s %-4s) %7s %-12s %-15s\n" |
| #define | CONCISE_FORMAT_STRING "%s:%s:%s:%d:%s:%s:%s:%s:%s:%d\n" |
Functions | |
| void | ast_cli (int fd, char *fmt,...) |
| AST_MUTEX_DEFINE_STATIC (clilock) | |
| AST_MUTEX_DEFINE_STATIC (climodentrylock) | |
| 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_cli_entry * | helpers = NULL |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Value: "Asterisk " ASTERISK_VERSION " built by " BUILD_USER "@" BUILD_HOSTNAME \ " on a " BUILD_MACHINE " running " BUILD_OS |
|
|
|
|
|
|
|
||||||||||||||||
|
Definition at line 40 of file cli.c. References ast_carefulwrite(), ast_log(), free, LOG_ERROR, and vasprintf. Referenced by ast_cli_command(), astman_send_error(), astman_send_response(), and manager_event(). 00041 { 00042 char *stuff; 00043 int res = 0; 00044 00045 va_list ap; 00046 va_start(ap, fmt); 00047 res = vasprintf(&stuff, fmt, ap); 00048 va_end(ap); 00049 if (res == -1) { 00050 ast_log(LOG_ERROR, "Out of memory\n"); 00051 } else { 00052 ast_carefulwrite(fd, stuff, strlen(stuff), 100); 00053 free(stuff); 00054 } 00055 }
|
|
||||||||||||
|
Interprets a command. Interpret a command s, sending output to fd Returns 0 on succes, -1 on failure Definition at line 1134 of file cli.c. References ast_cli(), ast_log(), AST_MAX_ARGS, ast_mutex_lock, ast_mutex_unlock, free, ast_cli_entry::handler, ast_cli_entry::inuse, LOG_WARNING, RESULT_SHOWUSAGE, and ast_cli_entry::usage. 01135 { 01136 char *argv[AST_MAX_ARGS]; 01137 struct ast_cli_entry *e; 01138 int x; 01139 char *dup; 01140 01141 if ((dup = parse_args(s, &x, argv, sizeof(argv) / sizeof(argv[0])))) { 01142 /* We need at least one entry, or ignore */ 01143 if (x > 0) { 01144 ast_mutex_lock(&clilock); 01145 e = find_cli(argv, 0); 01146 if (e) 01147 e->inuse++; 01148 ast_mutex_unlock(&clilock); 01149 if (e) { 01150 switch(e->handler(fd, x, argv)) { 01151 case RESULT_SHOWUSAGE: 01152 ast_cli(fd, e->usage); 01153 break; 01154 } 01155 } else 01156 ast_cli(fd, "No such command '%s' (type 'help' for help)\n", find_best(argv)); 01157 if (e) { 01158 ast_mutex_lock(&clilock); 01159 e->inuse--; 01160 ast_mutex_unlock(&clilock); 01161 } 01162 } 01163 free(dup); 01164 } else { 01165 ast_log(LOG_WARNING, "Out of memory\n"); 01166 return -1; 01167 } 01168 return 0; 01169 }
|
|
||||||||||||
|
Definition at line 1018 of file cli.c. References ast_cli_generator(), malloc, and realloc. 01019 { 01020 char **match_list = NULL, *retstr, *prevstr; 01021 size_t match_list_len, max_equal, which, i; 01022 int matches = 0; 01023 01024 match_list_len = 1; 01025 while ((retstr = ast_cli_generator(text, word, matches)) != NULL) { 01026 if (matches + 1 >= match_list_len) { 01027 match_list_len <<= 1; 01028 match_list = realloc(match_list, match_list_len * sizeof(char *)); 01029 } 01030 match_list[++matches] = retstr; 01031 } 01032 01033 if (!match_list) 01034 return (char **) NULL; 01035 01036 which = 2; 01037 prevstr = match_list[1]; 01038 max_equal = strlen(prevstr); 01039 for (; which <= matches; which++) { 01040 for (i = 0; i < max_equal && toupper(prevstr[i]) == toupper(match_list[which][i]); i++) 01041 continue; 01042 max_equal = i; 01043 } 01044 01045 retstr = malloc(max_equal + 1); 01046 (void) strncpy(retstr, match_list[1], max_equal); 01047 retstr[max_equal] = '\0'; 01048 match_list[0] = retstr; 01049 01050 if (matches + 1 >= match_list_len) 01051 match_list = realloc(match_list, (match_list_len + 1) * sizeof(char *)); 01052 match_list[matches + 1] = (char *) NULL; 01053 01054 return (match_list); 01055 }
|
|
||||||||||||||||
|
Readline madness.
Definition at line 1129 of file cli.c. Referenced by ast_cli_completion_matches(), and ast_cli_generatornummatches().
|
|
||||||||||||
|
Definition at line 1002 of file cli.c. References ast_cli_generator(). 01003 { 01004 int matches = 0, i = 0; 01005 char *buf = NULL, *oldbuf = NULL; 01006 01007 while ( (buf = ast_cli_generator(text, word, i)) ) { 01008 if (++i > 1 && strcmp(buf,oldbuf) == 0) { 01009 continue; 01010 } 01011 oldbuf = buf; 01012 matches++; 01013 } 01014 01015 return matches; 01016 }
|
|
|
Registers a command.
Definition at line 830 of file cli.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_cli_entry::cmda, LOG_WARNING, and ast_cli_entry::next. Referenced by ast_file_init(), ast_image_init(), ast_register_translator(), astdb_init(), init_framer(), init_logger(), init_manager(), load_pbx(), main(), and register_config_cli(). 00831 { 00832 struct ast_cli_entry *cur, *l=NULL; 00833 char fulle[80] ="", fulltst[80] =""; 00834 static int len; 00835 ast_mutex_lock(&clilock); 00836 join2(fulle, sizeof(fulle), e->cmda); 00837 if (find_cli(e->cmda, -1)) { 00838 ast_mutex_unlock(&clilock); 00839 ast_log(LOG_WARNING, "Command '%s' already registered (or something close enough)\n", fulle); 00840 return -1; 00841 } 00842 cur = helpers; 00843 while(cur) { 00844 join2(fulltst, sizeof(fulltst), cur->cmda); 00845 len = strlen(fulltst); 00846 if (strlen(fulle) < len) 00847 len = strlen(fulle); 00848 if (strncasecmp(fulle, fulltst, len) < 0) { 00849 if (l) { 00850 e->next = l->next; 00851 l->next = e; 00852 } else { 00853 e->next = helpers; 00854 helpers = e; 00855 } 00856 break; 00857 } 00858 l = cur; 00859 cur = cur->next; 00860 } 00861 if (!cur) { 00862 if (l) 00863 l->next = e; 00864 else 00865 helpers = e; 00866 e->next = NULL; 00867 } 00868 ast_mutex_unlock(&clilock); 00869 return 0; 00870 }
|
|
|
Unregisters a command.
Definition at line 804 of file cli.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_cli_entry::inuse, LOG_WARNING, and ast_cli_entry::next. 00805 { 00806 struct ast_cli_entry *cur, *l=NULL; 00807 ast_mutex_lock(&clilock); 00808 cur = helpers; 00809 while(cur) { 00810 if (e == cur) { 00811 if (e->inuse) { 00812 ast_log(LOG_WARNING, "Can't remove command that is in use\n"); 00813 } else { 00814 /* Rewrite */ 00815 if (l) 00816 l->next = e->next; 00817 else 00818 helpers = e->next; 00819 e->next = NULL; 00820 break; 00821 } 00822 } 00823 l = cur; 00824 cur = cur->next; 00825 } 00826 ast_mutex_unlock(&clilock); 00827 return 0; 00828 }
|
|
|
|
|
|
|
|
|
|
1.4.4