#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 "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) | |
| int | ast_cli_unregister (struct ast_cli_entry *e) |
| Unregisters a command. More... | |
| int | ast_cli_register (struct ast_cli_entry *e) |
| Registers a command. More... | |
| 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. More... | |
| int | ast_cli_command (int fd, char *s) |
| Interprets a command. More... | |
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 39 of file cli.c. References ast_carefulwrite(), ast_log(), free, LOG_ERROR, and vasprintf.
00040 {
00041 char *stuff;
00042 int res = 0;
00043
00044 va_list ap;
00045 va_start(ap, fmt);
00046 res = vasprintf(&stuff, fmt, ap);
00047 va_end(ap);
00048 if (res == -1) {
00049 ast_log(LOG_ERROR, "Out of memory\n");
00050 } else {
00051 ast_carefulwrite(fd, stuff, strlen(stuff), 100);
00052 free(stuff);
00053 }
00054 }
|
|
||||||||||||
|
Interprets a command. Interpret a command s, sending output to fd Returns 0 on succes, -1 on failure Definition at line 1132 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, s, and ast_cli_entry::usage.
01133 {
01134 char *argv[AST_MAX_ARGS];
01135 struct ast_cli_entry *e;
01136 int x;
01137 char *dup;
01138 x = AST_MAX_ARGS;
01139 if ((dup = parse_args(s, &x, argv))) {
01140 /* We need at least one entry, or ignore */
01141 if (x > 0) {
01142 ast_mutex_lock(&clilock);
01143 e = find_cli(argv, 0);
01144 if (e)
01145 e->inuse++;
01146 ast_mutex_unlock(&clilock);
01147 if (e) {
01148 switch(e->handler(fd, x, argv)) {
01149 case RESULT_SHOWUSAGE:
01150 ast_cli(fd, e->usage);
01151 break;
01152 }
01153 } else
01154 ast_cli(fd, "No such command '%s' (type 'help' for help)\n", find_best(argv));
01155 if (e) {
01156 ast_mutex_lock(&clilock);
01157 e->inuse--;
01158 ast_mutex_unlock(&clilock);
01159 }
01160 }
01161 free(dup);
01162 } else {
01163 ast_log(LOG_WARNING, "Out of memory\n");
01164 return -1;
01165 }
01166 return 0;
01167 }
|
|
||||||||||||
|
Definition at line 1016 of file cli.c. References ast_cli_generator(), malloc, and realloc.
01017 {
01018 char **match_list = NULL, *retstr, *prevstr;
01019 size_t match_list_len, max_equal, which, i;
01020 int matches = 0;
01021
01022 match_list_len = 1;
01023 while ((retstr = ast_cli_generator(text, word, matches)) != NULL) {
01024 if (matches + 1 >= match_list_len) {
01025 match_list_len <<= 1;
01026 match_list = realloc(match_list, match_list_len * sizeof(char *));
01027 }
01028 match_list[++matches] = retstr;
01029 }
01030
01031 if (!match_list)
01032 return (char **) NULL;
01033
01034 which = 2;
01035 prevstr = match_list[1];
01036 max_equal = strlen(prevstr);
01037 for (; which <= matches; which++) {
01038 for (i = 0; i < max_equal && prevstr[i] == match_list[which][i]; i++)
01039 continue;
01040 max_equal = i;
01041 }
01042
01043 retstr = malloc(max_equal + 1);
01044 (void) strncpy(retstr, match_list[1], max_equal);
01045 retstr[max_equal] = '\0';
01046 match_list[0] = retstr;
01047
01048 if (matches + 1 >= match_list_len)
01049 match_list = realloc(match_list, (match_list_len + 1) * sizeof(char *));
01050 match_list[matches + 1] = (char *) NULL;
01051
01052 return (match_list);
01053 }
|
|
||||||||||||||||
|
Readline madness.
Definition at line 1127 of file cli.c. Referenced by ast_cli_completion_matches(), and ast_cli_generatornummatches().
01128 {
01129 return __ast_cli_generator(text, word, state, 1);
01130 }
|
|
||||||||||||
|
Definition at line 999 of file cli.c. References ast_cli_generator().
01000 {
01001 int matches = 0, i = 0;
01002 char *buf, *oldbuf = NULL;
01003
01004
01005 while ( (buf = ast_cli_generator(text, word, i)) ) {
01006 if (++i > 1 && strcmp(buf,oldbuf) == 0) {
01007 continue;
01008 }
01009 oldbuf = buf;
01010 matches++;
01011 }
01012
01013 return matches;
01014 }
|
|
|
Registers a command.
Definition at line 822 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().
00823 {
00824 struct ast_cli_entry *cur, *l=NULL;
00825 char fulle[80] ="", fulltst[80] ="";
00826 static int len;
00827 ast_mutex_lock(&clilock);
00828 join2(fulle, sizeof(fulle), e->cmda);
00829 if (find_cli(e->cmda, -1)) {
00830 ast_mutex_unlock(&clilock);
00831 ast_log(LOG_WARNING, "Command '%s' already registered (or something close enough)\n", fulle);
00832 return -1;
00833 }
00834 cur = helpers;
00835 while(cur) {
00836 join2(fulltst, sizeof(fulltst), cur->cmda);
00837 len = strlen(fulltst);
00838 if (strlen(fulle) < len)
00839 len = strlen(fulle);
00840 if (strncasecmp(fulle, fulltst, len) < 0) {
00841 if (l) {
00842 e->next = l->next;
00843 l->next = e;
00844 } else {
00845 e->next = helpers;
00846 helpers = e;
00847 }
00848 break;
00849 }
00850 l = cur;
00851 cur = cur->next;
00852 }
00853 if (!cur) {
00854 if (l)
00855 l->next = e;
00856 else
00857 helpers = e;
00858 e->next = NULL;
00859 }
00860 ast_mutex_unlock(&clilock);
00861 return 0;
00862 }
|
|
|
Unregisters a command.
Definition at line 796 of file cli.c. References ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_cli_entry::inuse, LOG_WARNING, and ast_cli_entry::next.
00797 {
00798 struct ast_cli_entry *cur, *l=NULL;
00799 ast_mutex_lock(&clilock);
00800 cur = helpers;
00801 while(cur) {
00802 if (e == cur) {
00803 if (e->inuse) {
00804 ast_log(LOG_WARNING, "Can't remove command that is in use\n");
00805 } else {
00806 /* Rewrite */
00807 if (l)
00808 l->next = e->next;
00809 else
00810 helpers = e->next;
00811 e->next = NULL;
00812 break;
00813 }
00814 }
00815 l = cur;
00816 cur = cur->next;
00817 }
00818 ast_mutex_unlock(&clilock);
00819 return 0;
00820 }
|
|
|
|
|
|
|
1.2.15