diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/dnsmgr.c | 93 | ||||
-rw-r--r-- | main/frame.c | 136 | ||||
-rw-r--r-- | main/http.c | 57 | ||||
-rw-r--r-- | main/logger.c | 107 | ||||
-rw-r--r-- | main/manager.c | 313 | ||||
-rw-r--r-- | main/pbx.c | 456 |
6 files changed, 606 insertions, 556 deletions
diff --git a/main/dnsmgr.c b/main/dnsmgr.c index d1e5dd30b..ea79d85d0 100644 --- a/main/dnsmgr.c +++ b/main/dnsmgr.c @@ -255,28 +255,48 @@ void dnsmgr_start_refresh(void) static int do_reload(int loading); -static int handle_cli_reload(int fd, int argc, char *argv[]) +static char *handle_cli_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { - if (argc > 2) - return RESULT_SHOWUSAGE; + switch (cmd) { + case CLI_INIT: + e->command = "dnsmgr reload"; + e->usage = + "Usage: dnsmgr reload\n" + " Reloads the DNS manager configuration.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + if (a->argc > 2) + return CLI_SHOWUSAGE; do_reload(0); - return 0; + return CLI_SUCCESS; } -static int handle_cli_refresh(int fd, int argc, char *argv[]) +static char *handle_cli_refresh(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct refresh_info info = { .entries = &entry_list, .verbose = 1, }; + switch (cmd) { + case CLI_INIT: + e->command = "dnsmgr refresh"; + e->usage = + "Usage: dnsmgr refresh [pattern]\n" + " Peforms an immediate refresh of the managed DNS entries.\n" + " Optional regular expression pattern is used to filter the entries to refresh.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + if (a->argc > 3) + return CLI_SHOWUSAGE; - if (argc > 3) - return RESULT_SHOWUSAGE; - - if (argc == 3) { - if (regcomp(&info.filter, argv[2], REG_EXTENDED | REG_NOSUB)) - return RESULT_SHOWUSAGE; + if (a->argc == 3) { + if ( regcomp(&info.filter, a->argv[2], REG_EXTENDED | REG_NOSUB) ) + return CLI_SHOWUSAGE; else info.regex_present = 1; } @@ -286,49 +306,41 @@ static int handle_cli_refresh(int fd, int argc, char *argv[]) if (info.regex_present) regfree(&info.filter); - return 0; + return CLI_SUCCESS; } -static int handle_cli_status(int fd, int argc, char *argv[]) +static char *handle_cli_status(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int count = 0; struct ast_dnsmgr_entry *entry; + switch (cmd) { + case CLI_INIT: + e->command = "dnsmgr status"; + e->usage = + "Usage: dnsmgr status\n" + " Displays the DNS manager status.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } - if (argc > 2) - return RESULT_SHOWUSAGE; + if (a->argc > 2) + return CLI_SHOWUSAGE; - ast_cli(fd, "DNS Manager: %s\n", enabled ? "enabled" : "disabled"); - ast_cli(fd, "Refresh Interval: %d seconds\n", refresh_interval); + ast_cli(a->fd, "DNS Manager: %s\n", enabled ? "enabled" : "disabled"); + ast_cli(a->fd, "Refresh Interval: %d seconds\n", refresh_interval); AST_RWLIST_RDLOCK(&entry_list); AST_RWLIST_TRAVERSE(&entry_list, entry, list) count++; AST_RWLIST_UNLOCK(&entry_list); - ast_cli(fd, "Number of entries: %d\n", count); + ast_cli(a->fd, "Number of entries: %d\n", count); - return 0; + return CLI_SUCCESS; } -static struct ast_cli_entry cli_reload = { - { "dnsmgr", "reload", NULL }, - handle_cli_reload, "Reloads the DNS manager configuration", - "Usage: dnsmgr reload\n" - " Reloads the DNS manager configuration.\n" -}; - -static struct ast_cli_entry cli_refresh = { - { "dnsmgr", "refresh", NULL }, - handle_cli_refresh, "Performs an immediate refresh", - "Usage: dnsmgr refresh [pattern]\n" - " Peforms an immediate refresh of the managed DNS entries.\n" - " Optional regular expression pattern is used to filter the entries to refresh.\n", -}; - -static struct ast_cli_entry cli_status = { - { "dnsmgr", "status", NULL }, - handle_cli_status, "Display the DNS manager status", - "Usage: dnsmgr status\n" - " Displays the DNS manager status.\n" -}; +static struct ast_cli_entry cli_reload = NEW_CLI(handle_cli_reload, "Reloads the DNS manager configuration"); +static struct ast_cli_entry cli_refresh = NEW_CLI(handle_cli_refresh, "Performs an immediate refresh"); +static struct ast_cli_entry cli_status = NEW_CLI(handle_cli_status, "Display the DNS manager status"); int dnsmgr_init(void) { @@ -338,6 +350,7 @@ int dnsmgr_init(void) } ast_cli_register(&cli_reload); ast_cli_register(&cli_status); + ast_cli_register(&cli_refresh); return do_reload(1); } diff --git a/main/frame.c b/main/frame.c index a5383e300..2a5ab57d0 100644 --- a/main/frame.c +++ b/main/frame.c @@ -611,80 +611,94 @@ char *ast_codec2str(int codec) return ret; } -static int show_codecs(int fd, int argc, char *argv[]) +static char *show_codecs(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int i, found=0; char hex[25]; + + switch (cmd) { + case CLI_INIT: + e->command = "core show codecs [audio|video|image]"; + e->usage = + "Usage: core show codecs [audio|video|image]\n" + " Displays codec mapping\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } - if ((argc < 3) || (argc > 4)) - return RESULT_SHOWUSAGE; + if ((a->argc < 3) || (a->argc > 4)) + return CLI_SHOWUSAGE; if (!ast_opt_dont_warn) - ast_cli(fd, "Disclaimer: this command is for informational purposes only.\n" + ast_cli(a->fd, "Disclaimer: this command is for informational purposes only.\n" "\tIt does not indicate anything about your configuration.\n"); - ast_cli(fd, "%11s %9s %10s TYPE %8s %s\n","INT","BINARY","HEX","NAME","DESC"); - ast_cli(fd, "--------------------------------------------------------------------------------\n"); - if ((argc == 3) || (!strcasecmp(argv[3],"audio"))) { + ast_cli(a->fd, "%11s %9s %10s TYPE %8s %s\n","INT","BINARY","HEX","NAME","DESC"); + ast_cli(a->fd, "--------------------------------------------------------------------------------\n"); + if ((a->argc == 3) || (!strcasecmp(a->argv[3],"audio"))) { found = 1; for (i=0;i<13;i++) { snprintf(hex,25,"(0x%x)",1<<i); - ast_cli(fd, "%11u (1 << %2d) %10s audio %8s (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i)); + ast_cli(a->fd, "%11u (1 << %2d) %10s audio %8s (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i)); } } - if ((argc == 3) || (!strcasecmp(argv[3],"image"))) { + if ((a->argc == 3) || (!strcasecmp(a->argv[3],"image"))) { found = 1; for (i=16;i<18;i++) { snprintf(hex,25,"(0x%x)",1<<i); - ast_cli(fd, "%11u (1 << %2d) %10s image %8s (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i)); + ast_cli(a->fd, "%11u (1 << %2d) %10s image %8s (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i)); } } - if ((argc == 3) || (!strcasecmp(argv[3],"video"))) { + if ((a->argc == 3) || (!strcasecmp(a->argv[3],"video"))) { found = 1; for (i=18;i<22;i++) { snprintf(hex,25,"(0x%x)",1<<i); - ast_cli(fd, "%11u (1 << %2d) %10s video %8s (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i)); + ast_cli(a->fd, "%11u (1 << %2d) %10s video %8s (%s)\n",1 << i,i,hex,ast_getformatname(1<<i),ast_codec2str(1<<i)); } } - if (! found) - return RESULT_SHOWUSAGE; + if (!found) + return CLI_SHOWUSAGE; else - return RESULT_SUCCESS; + return CLI_SUCCESS; } -static const char frame_show_codecs_usage[] = -"Usage: core show codecs [audio|video|image]\n" -" Displays codec mapping\n"; - -static int show_codec_n(int fd, int argc, char *argv[]) +static char *show_codec_n(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int codec, i, found=0; - if (argc != 4) - return RESULT_SHOWUSAGE; + switch (cmd) { + case CLI_INIT: + e->command = "core show codec"; + e->usage = + "Usage: core show codec <number>\n" + " Displays codec mapping\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } - if (sscanf(argv[3],"%d",&codec) != 1) - return RESULT_SHOWUSAGE; + if (a->argc != 4) + return CLI_SHOWUSAGE; + + if (sscanf(a->argv[3],"%d",&codec) != 1) + return CLI_SHOWUSAGE; for (i = 0; i < 32; i++) if (codec & (1 << i)) { found = 1; - ast_cli(fd, "%11u (1 << %2d) %s\n",1 << i,i,ast_codec2str(1<<i)); + ast_cli(a->fd, "%11u (1 << %2d) %s\n",1 << i,i,ast_codec2str(1<<i)); } if (!found) - ast_cli(fd, "Codec %d not found\n", codec); + ast_cli(a->fd, "Codec %d not found\n", codec); - return RESULT_SUCCESS; + return CLI_SUCCESS; } -static char frame_show_codec_n_usage[] = -"Usage: core show codec <number>\n" -" Displays codec mapping\n"; - /*! Dump a frame for debugging purposes */ void ast_frame_dump(const char *name, struct ast_frame *f, char *prefix) { @@ -867,54 +881,42 @@ void ast_frame_dump(const char *name, struct ast_frame *f, char *prefix) #ifdef TRACE_FRAMES -static int show_frame_stats(int fd, int argc, char *argv[]) +static char *show_frame_stats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct ast_frame *f; int x=1; - if (argc != 4) - return RESULT_SHOWUSAGE; + + switch (cmd) { + case CLI_INIT: + e->command = "core show frame stats"; + e->usage = + "Usage: core show frame stats\n" + " Displays debugging statistics from framer\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + + if (a->argc != 4) + return CLI_SHOWUSAGE; AST_LIST_LOCK(&headerlist); - ast_cli(fd, " Framer Statistics \n"); - ast_cli(fd, "---------------------------\n"); - ast_cli(fd, "Total allocated headers: %d\n", headers); - ast_cli(fd, "Queue Dump:\n"); + ast_cli(a->fd, " Framer Statistics \n"); + ast_cli(a->fd, "---------------------------\n"); + ast_cli(a->fd, "Total allocated headers: %d\n", headers); + ast_cli(a->fd, "Queue Dump:\n"); AST_LIST_TRAVERSE(&headerlist, f, frame_list) - ast_cli(fd, "%d. Type %d, subclass %d from %s\n", x++, f->frametype, f->subclass, f->src ? f->src : "<Unknown>"); + ast_cli(a->fd, "%d. Type %d, subclass %d from %s\n", x++, f->frametype, f->subclass, f->src ? f->src : "<Unknown>"); AST_LIST_UNLOCK(&headerlist); - return RESULT_SUCCESS; + return CLI_SUCCESS; } - -static const char frame_stats_usage[] = -"Usage: core show frame stats\n" -" Displays debugging statistics from framer\n"; #endif /* Builtin Asterisk CLI-commands for debugging */ static struct ast_cli_entry my_clis[] = { - { { "core", "show", "codecs", NULL }, - show_codecs, "Displays a list of codecs", - frame_show_codecs_usage }, - - { { "core", "show", "codecs", "audio", NULL }, - show_codecs, "Displays a list of audio codecs", - frame_show_codecs_usage }, - - { { "core", "show", "codecs", "video", NULL }, - show_codecs, "Displays a list of video codecs", - frame_show_codecs_usage }, - - { { "core", "show", "codecs", "image", NULL }, - show_codecs, "Displays a list of image codecs", - frame_show_codecs_usage }, - - { { "core", "show", "codec", NULL }, - show_codec_n, "Shows a specific codec", - frame_show_codec_n_usage }, - + NEW_CLI(show_codecs, "Displays a list of codecs"), + NEW_CLI(show_codec_n, "Shows a specific codec"), #ifdef TRACE_FRAMES - { { "core", "show", "frame", "stats", NULL }, - show_frame_stats, "Shows frame statistics", - frame_stats_usage }, + NEW_CLI(show_frame_stats, "Shows frame statistics"), #endif }; diff --git a/main/http.c b/main/http.c index c72f35ec5..9413fa9a4 100644 --- a/main/http.c +++ b/main/http.c @@ -1232,56 +1232,65 @@ static int __ast_http_load(int reload) return 0; } -static int handle_show_http(int fd, int argc, char *argv[]) +static char *handle_show_http(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct ast_http_uri *urih; struct http_uri_redirect *redirect; struct ast_http_post_mapping *post_map; - - if (argc != 3) - return RESULT_SHOWUSAGE; - - ast_cli(fd, "HTTP Server Status:\n"); - ast_cli(fd, "Prefix: %s\n", prefix); + switch (cmd) { + case CLI_INIT: + e->command = "http show status"; + e->usage = + "Usage: http show status\n" + " Lists status of internal HTTP engine\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + + if (a->argc != 3) + return CLI_SHOWUSAGE; + ast_cli(a->fd, "HTTP Server Status:\n"); + ast_cli(a->fd, "Prefix: %s\n", prefix); if (!http_desc.oldsin.sin_family) - ast_cli(fd, "Server Disabled\n\n"); + ast_cli(a->fd, "Server Disabled\n\n"); else { - ast_cli(fd, "Server Enabled and Bound to %s:%d\n\n", + ast_cli(a->fd, "Server Enabled and Bound to %s:%d\n\n", ast_inet_ntoa(http_desc.oldsin.sin_addr), ntohs(http_desc.oldsin.sin_port)); if (http_tls_cfg.enabled) - ast_cli(fd, "HTTPS Server Enabled and Bound to %s:%d\n\n", + ast_cli(a->fd, "HTTPS Server Enabled and Bound to %s:%d\n\n", ast_inet_ntoa(https_desc.oldsin.sin_addr), ntohs(https_desc.oldsin.sin_port)); } - ast_cli(fd, "Enabled URI's:\n"); + ast_cli(a->fd, "Enabled URI's:\n"); AST_RWLIST_RDLOCK(&uris); if (AST_RWLIST_EMPTY(&uris)) { - ast_cli(fd, "None.\n"); + ast_cli(a->fd, "None.\n"); } else { AST_RWLIST_TRAVERSE(&uris, urih, entry) - ast_cli(fd, "%s/%s%s => %s\n", prefix, urih->uri, (urih->has_subtree ? "/..." : "" ), urih->description); + ast_cli(a->fd, "%s/%s%s => %s\n", prefix, urih->uri, (urih->has_subtree ? "/..." : "" ), urih->description); } AST_RWLIST_UNLOCK(&uris); - ast_cli(fd, "\nEnabled Redirects:\n"); + ast_cli(a->fd, "\nEnabled Redirects:\n"); AST_RWLIST_RDLOCK(&uri_redirects); AST_RWLIST_TRAVERSE(&uri_redirects, redirect, entry) - ast_cli(fd, " %s => %s\n", redirect->target, redirect->dest); + ast_cli(a->fd, " %s => %s\n", redirect->target, redirect->dest); if (AST_RWLIST_EMPTY(&uri_redirects)) - ast_cli(fd, " None.\n"); + ast_cli(a->fd, " None.\n"); AST_RWLIST_UNLOCK(&uri_redirects); - ast_cli(fd, "\nPOST mappings:\n"); + ast_cli(a->fd, "\nPOST mappings:\n"); AST_RWLIST_RDLOCK(&post_mappings); AST_LIST_TRAVERSE(&post_mappings, post_map, entry) - ast_cli(fd, "%s/%s => %s\n", prefix, post_map->from, post_map->to); - ast_cli(fd, "%s\n", AST_LIST_EMPTY(&post_mappings) ? "None.\n" : ""); + ast_cli(a->fd, "%s/%s => %s\n", prefix, post_map->from, post_map->to); + ast_cli(a->fd, "%s\n", AST_LIST_EMPTY(&post_mappings) ? "None.\n" : ""); AST_RWLIST_UNLOCK(&post_mappings); - return RESULT_SUCCESS; + return CLI_SUCCESS; } int ast_http_reload(void) @@ -1289,14 +1298,8 @@ int ast_http_reload(void) return __ast_http_load(1); } -static char show_http_help[] = -"Usage: http show status\n" -" Lists status of internal HTTP engine\n"; - static struct ast_cli_entry cli_http[] = { - { { "http", "show", "status", NULL }, - handle_show_http, "Display HTTP server status", - show_http_help }, + NEW_CLI(handle_show_http, "Display HTTP server status"), }; int ast_http_init(void) diff --git a/main/logger.c b/main/logger.c index b2b94da0b..a74cfa31e 100644 --- a/main/logger.c +++ b/main/logger.c @@ -616,59 +616,88 @@ int reload_logger(int rotate) return res; } -static int handle_logger_reload(int fd, int argc, char *argv[]) +static char *handle_logger_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { + switch (cmd) { + case CLI_INIT: + e->command = "logger reload"; + e->usage = + "Usage: logger reload\n" + " Reloads the logger subsystem state. Use after restarting syslogd(8) if you are using syslog logging.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } if (reload_logger(0)) { - ast_cli(fd, "Failed to reload the logger\n"); - return RESULT_FAILURE; + ast_cli(a->fd, "Failed to reload the logger\n"); + return CLI_FAILURE; } else - return RESULT_SUCCESS; + return CLI_SUCCESS; } -static int handle_logger_rotate(int fd, int argc, char *argv[]) +static char *handle_logger_rotate(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { + switch (cmd) { + case CLI_INIT: + e->command = "logger rotate"; + e->usage = + "Usage: logger rotate\n" + " Rotates and Reopens the log files.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } if (reload_logger(1)) { - ast_cli(fd, "Failed to reload the logger and rotate log files\n"); - return RESULT_FAILURE; + ast_cli(a->fd, "Failed to reload the logger and rotate log files\n"); + return CLI_FAILURE; } else - return RESULT_SUCCESS; + return CLI_SUCCESS; } /*! \brief CLI command to show logging system configuration */ -static int handle_logger_show_channels(int fd, int argc, char *argv[]) +static char *handle_logger_show_channels(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { #define FORMATL "%-35.35s %-8.8s %-9.9s " struct logchannel *chan; - - ast_cli(fd,FORMATL, "Channel", "Type", "Status"); - ast_cli(fd, "Configuration\n"); - ast_cli(fd,FORMATL, "-------", "----", "------"); - ast_cli(fd, "-------------\n"); + switch (cmd) { + case CLI_INIT: + e->command = "logger show channels"; + e->usage = + "Usage: logger show channels\n" + " List configured logger channels.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + ast_cli(a->fd,FORMATL, "Channel", "Type", "Status"); + ast_cli(a->fd, "Configuration\n"); + ast_cli(a->fd,FORMATL, "-------", "----", "------"); + ast_cli(a->fd, "-------------\n"); AST_RWLIST_RDLOCK(&logchannels); AST_RWLIST_TRAVERSE(&logchannels, chan, list) { - ast_cli(fd, FORMATL, chan->filename, chan->type==LOGTYPE_CONSOLE ? "Console" : (chan->type==LOGTYPE_SYSLOG ? "Syslog" : "File"), + ast_cli(a->fd, FORMATL, chan->filename, chan->type==LOGTYPE_CONSOLE ? "Console" : (chan->type==LOGTYPE_SYSLOG ? "Syslog" : "File"), chan->disabled ? "Disabled" : "Enabled"); - ast_cli(fd, " - "); + ast_cli(a->fd, " - "); if (chan->logmask & (1 << __LOG_DEBUG)) - ast_cli(fd, "Debug "); + ast_cli(a->fd, "Debug "); if (chan->logmask & (1 << __LOG_DTMF)) - ast_cli(fd, "DTMF "); + ast_cli(a->fd, "DTMF "); if (chan->logmask & (1 << __LOG_VERBOSE)) - ast_cli(fd, "Verbose "); + ast_cli(a->fd, "Verbose "); if (chan->logmask & (1 << __LOG_WARNING)) - ast_cli(fd, "Warning "); + ast_cli(a->fd, "Warning "); if (chan->logmask & (1 << __LOG_NOTICE)) - ast_cli(fd, "Notice "); + ast_cli(a->fd, "Notice "); if (chan->logmask & (1 << __LOG_ERROR)) - ast_cli(fd, "Error "); + ast_cli(a->fd, "Error "); if (chan->logmask & (1 << __LOG_EVENT)) - ast_cli(fd, "Event "); - ast_cli(fd, "\n"); + ast_cli(a->fd, "Event "); + ast_cli(a->fd, "\n"); } AST_RWLIST_UNLOCK(&logchannels); - ast_cli(fd, "\n"); + ast_cli(a->fd, "\n"); - return RESULT_SUCCESS; + return CLI_SUCCESS; } struct verb { @@ -678,30 +707,10 @@ struct verb { static AST_RWLIST_HEAD_STATIC(verbosers, verb); -static char logger_reload_help[] = -"Usage: logger reload\n" -" Reloads the logger subsystem state. Use after restarting syslogd(8) if you are using syslog logging.\n"; - -static char logger_rotate_help[] = -"Usage: logger rotate\n" -" Rotates and Reopens the log files.\n"; - -static char logger_show_channels_help[] = -"Usage: logger show channels\n" -" List configured logger channels.\n"; - static struct ast_cli_entry cli_logger[] = { - { { "logger", "show", "channels", NULL }, - handle_logger_show_channels, "List configured log channels", - logger_show_channels_help }, - - { { "logger", "reload", NULL }, - handle_logger_reload, "Reopens the log files", - logger_reload_help }, - - { { "logger", "rotate", NULL }, - handle_logger_rotate, "Rotates and reopens the log files", - logger_rotate_help }, + NEW_CLI(handle_logger_show_channels, "List configured log channels"), + NEW_CLI(handle_logger_reload, "Reopens the log files"), + NEW_CLI(handle_logger_rotate, "Rotates and reopens the log files") }; static int handle_SIGXFSZ(int sig) diff --git a/main/manager.c b/main/manager.c index bf5ed3045..55113db81 100644 --- a/main/manager.c +++ b/main/manager.c @@ -406,45 +406,6 @@ static int strings_to_mask(const char *string) return get_perm(string); } -static char *complete_show_mancmd(const char *line, const char *word, int pos, int state) -{ - struct manager_action *cur; - int l = strlen(word), which = 0; - char *ret = NULL; - - AST_RWLIST_RDLOCK(&actions); - AST_RWLIST_TRAVERSE(&actions, cur, list) { - if (!strncasecmp(word, cur->action, l) && ++which > state) { - ret = ast_strdup(cur->action); - break; /* make sure we exit even if ast_strdup() returns NULL */ - } - } - AST_RWLIST_UNLOCK(&actions); - - return ret; -} - -static char *complete_show_manuser(const char *line, const char *word, int pos, int state) -{ - struct ast_manager_user *user = NULL; - int l = strlen(word), which = 0; - char *ret = NULL; - - if (pos != 3) - return NULL; - - AST_RWLIST_RDLOCK(&users); - AST_RWLIST_TRAVERSE(&users, user, list) { - if (!strncasecmp(word, user->username, l) && ++which > state) { - ret = ast_strdup(user->username); - break; - } - } - AST_RWLIST_UNLOCK(&users); - - return ret; -} - static int check_manager_session_inuse(const char *name) { struct mansession *session = NULL; @@ -491,63 +452,116 @@ static int manager_displayconnects (struct mansession *s) return ret; } -static int handle_showmancmd(int fd, int argc, char *argv[]) +static char *handle_showmancmd(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct manager_action *cur; - struct ast_str *authority = ast_str_alloca(80); - int num; - - if (argc != 4) - return RESULT_SHOWUSAGE; + struct ast_str *authority; + int num, l, which; + char *ret = NULL; + switch (cmd) { + case CLI_INIT: + e->command = "manager show command"; + e->usage = + "Usage: manager show command <actionname>\n" + " Shows the detailed description for a specific Asterisk manager interface command.\n"; + return NULL; + case CLI_GENERATE: + l = strlen(a->word); + which = 0; + AST_RWLIST_RDLOCK(&actions); + AST_RWLIST_TRAVERSE(&actions, cur, list) { + if (!strncasecmp(a->word, cur->action, l) && ++which > a->n) { + ret = ast_strdup(cur->action); + break; /* make sure we exit even if ast_strdup() returns NULL */ + } + } + AST_RWLIST_UNLOCK(&actions); + return ret; + } + authority = ast_str_alloca(80); + if (a->argc != 4) + return CLI_SHOWUSAGE; AST_RWLIST_RDLOCK(&actions); AST_RWLIST_TRAVERSE(&actions, cur, list) { - for (num = 3; num < argc; num++) { - if (!strcasecmp(cur->action, argv[num])) { - ast_cli(fd, "Action: %s\nSynopsis: %s\nPrivilege: %s\n%s\n", + for (num = 3; num < a->argc; num++) { + if (!strcasecmp(cur->action, a->argv[num])) { + ast_cli(a->fd, "Action: %s\nSynopsis: %s\nPrivilege: %s\n%s\n", cur->action, cur->synopsis, authority_to_str(cur->authority, &authority), - S_OR(cur->description, "") ); + S_OR(cur->description, "")); } } } AST_RWLIST_UNLOCK(&actions); - return RESULT_SUCCESS; + return CLI_SUCCESS; } -static int handle_mandebug(int fd, int argc, char *argv[]) +static char *handle_mandebug(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { - if (argc == 2) - ast_cli(fd, "manager debug is %s\n", manager_debug? "on" : "off"); - else if (argc == 3) { - if (!strcasecmp(argv[2], "on")) + switch (cmd) { + case CLI_INIT: + e->command = "manager debug [on|off]"; + e->usage = "Usage: manager debug [on|off]\n Show, enable, disable debugging of the manager code.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + if (a->argc == 2) + ast_cli(a->fd, "manager debug is %s\n", manager_debug? "on" : "off"); + else if (a->argc == 3) { + if (!strcasecmp(a->argv[2], "on")) manager_debug = 1; - else if (!strcasecmp(argv[2], "off")) + else if (!strcasecmp(a->argv[2], "off")) manager_debug = 0; else - return RESULT_SHOWUSAGE; + return CLI_SHOWUSAGE; } - return RESULT_SUCCESS; + return CLI_SUCCESS; } -static int handle_showmanager(int fd, int argc, char *argv[]) +static char *handle_showmanager(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct ast_manager_user *user = NULL; + int l, which; + char *ret = NULL; + switch (cmd) { + case CLI_INIT: + e->command = "manager show user"; + e->usage = + " Usage: manager show user <user>\n" + " Display all information related to the manager user specified.\n"; + return NULL; + case CLI_GENERATE: + l = strlen(a->word); + which = 0; + if (a->pos != 3) + return NULL; + AST_RWLIST_RDLOCK(&users); + AST_RWLIST_TRAVERSE(&users, user, list) { + if ( !strncasecmp(a->word, user->username, l) && ++which > a->n ) { + ret = ast_strdup(user->username); + break; + } + } + AST_RWLIST_UNLOCK(&users); + return ret; + } - if (argc != 4) - return RESULT_SHOWUSAGE; + if (a->argc != 4) + return CLI_SHOWUSAGE; AST_RWLIST_RDLOCK(&users); - if (!(user = get_manager_by_name_locked(argv[3]))) { - ast_cli(fd, "There is no manager called %s\n", argv[3]); + if (!(user = get_manager_by_name_locked(a->argv[3]))) { + ast_cli(a->fd, "There is no manager called %s\n", a->argv[3]); AST_RWLIST_UNLOCK(&users); - return -1; + return CLI_SUCCESS; } - ast_cli(fd,"\n"); - ast_cli(fd, + ast_cli(a->fd,"\n"); + ast_cli(a->fd, " username: %s\n" " secret: %s\n" " deny: %s\n" @@ -565,154 +579,147 @@ static int handle_showmanager(int fd, int argc, char *argv[]) AST_RWLIST_UNLOCK(&users); - return RESULT_SUCCESS; + return CLI_SUCCESS; } -static int handle_showmanagers(int fd, int argc, char *argv[]) +static char *handle_showmanagers(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct ast_manager_user *user = NULL; int count_amu = 0; - - if (argc != 3) - return RESULT_SHOWUSAGE; + switch (cmd) { + case CLI_INIT: + e->command = "manager show users"; + e->usage = + "Usage: manager show users\n" + " Prints a listing of all managers that are currently configured on that\n" + " system.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + if (a->argc != 3) + return CLI_SHOWUSAGE; AST_RWLIST_RDLOCK(&users); /* If there are no users, print out something along those lines */ if (AST_RWLIST_EMPTY(&users)) { - ast_cli(fd, "There are no manager users.\n"); + ast_cli(a->fd, "There are no manager users.\n"); AST_RWLIST_UNLOCK(&users); - return RESULT_SUCCESS; + return CLI_SUCCESS; } - ast_cli(fd, "\nusername\n--------\n"); + ast_cli(a->fd, "\nusername\n--------\n"); AST_RWLIST_TRAVERSE(&users, user, list) { - ast_cli(fd, "%s\n", user->username); + ast_cli(a->fd, "%s\n", user->username); count_amu++; } AST_RWLIST_UNLOCK(&users); - ast_cli(fd,"-------------------\n"); - ast_cli(fd,"%d manager users configured.\n", count_amu); + ast_cli(a->fd,"-------------------\n"); + ast_cli(a->fd,"%d manager users configured.\n", count_amu); - return RESULT_SUCCESS; + return CLI_SUCCESS; } /*! \brief CLI command manager list commands */ -static int handle_showmancmds(int fd, int argc, char *argv[]) +static char *handle_showmancmds(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct manager_action *cur; - struct ast_str *authority = ast_str_alloca(80); - char *format = " %-15.15s %-15.15s %-55.55s\n"; - - ast_cli(fd, format, "Action", "Privilege", "Synopsis"); - ast_cli(fd, format, "------", "---------", "--------"); + struct ast_str *authority; + static const char *format = " %-15.15s %-15.15s %-55.55s\n"; + switch (cmd) { + case CLI_INIT: + e->command = "manager show commands"; + e->usage = + "Usage: manager show commands\n" + " Prints a listing of all the available Asterisk manager interface commands.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + authority = ast_str_alloca(80); + ast_cli(a->fd, format, "Action", "Privilege", "Synopsis"); + ast_cli(a->fd, format, "------", "---------", "--------"); AST_RWLIST_RDLOCK(&actions); AST_RWLIST_TRAVERSE(&actions, cur, list) - ast_cli(fd, format, cur->action, authority_to_str(cur->authority, &authority), cur->synopsis); + ast_cli(a->fd, format, cur->action, authority_to_str(cur->authority, &authority), cur->synopsis); AST_RWLIST_UNLOCK(&actions); - return RESULT_SUCCESS; + return CLI_SUCCESS; } /*! \brief CLI command manager list connected */ -static int handle_showmanconn(int fd, int argc, char *argv[]) +static char *handle_showmanconn(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct mansession *s; - char *format = " %-15.15s %-15.15s\n"; + static const char *format = " %-15.15s %-15.15s\n"; int count = 0; - - ast_cli(fd, format, "Username", "IP Address"); + switch (cmd) { + case CLI_INIT: + e->command = "manager show connected"; + e->usage = + "Usage: manager show connected\n" + " Prints a listing of the users that are currently connected to the\n" + "Asterisk manager interface.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + ast_cli(a->fd, format, "Username", "IP Address"); AST_LIST_LOCK(&sessions); AST_LIST_TRAVERSE(&sessions, s, list) { - ast_cli(fd, format,s->username, ast_inet_ntoa(s->sin.sin_addr)); + ast_cli(a->fd, format,s->username, ast_inet_ntoa(s->sin.sin_addr)); count++; } AST_LIST_UNLOCK(&sessions); - ast_cli(fd, "%d users connected.\n", count); + ast_cli(a->fd, "%d users connected.\n", count); - return RESULT_SUCCESS; + return CLI_SUCCESS; } /*! \brief CLI command manager list eventq */ /* Should change to "manager show connected" */ -static int handle_showmaneventq(int fd, int argc, char *argv[]) +static char *handle_showmaneventq(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct eventqent *s; - + switch (cmd) { + case CLI_INIT: + e->command = "manager show eventq"; + e->usage = + "Usage: manager show eventq\n" + " Prints a listing of all events pending in the Asterisk manger\n" + "event queue.\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } AST_LIST_LOCK(&all_events); AST_LIST_TRAVERSE(&all_events, s, eq_next) { - ast_cli(fd, "Usecount: %d\n",s->usecount); - ast_cli(fd, "Category: %d\n", s->category); - ast_cli(fd, "Event:\n%s", s->eventdata); + ast_cli(a->fd, "Usecount: %d\n",s->usecount); + ast_cli(a->fd, "Category: %d\n", s->category); + ast_cli(a->fd, "Event:\n%s", s->eventdata); } AST_LIST_UNLOCK(&all_events); - return RESULT_SUCCESS; + return CLI_SUCCESS; } -static char showmancmd_help[] = -"Usage: manager show command <actionname>\n" -" Shows the detailed description for a specific Asterisk manager interface command.\n"; - -static char showmancmds_help[] = -"Usage: manager show commands\n" -" Prints a listing of all the available Asterisk manager interface commands.\n"; - -static char showmanconn_help[] = -"Usage: manager show connected\n" -" Prints a listing of the users that are currently connected to the\n" -"Asterisk manager interface.\n"; - -static char showmaneventq_help[] = -"Usage: manager show eventq\n" -" Prints a listing of all events pending in the Asterisk manger\n" -"event queue.\n"; - -static char showmanagers_help[] = -"Usage: manager show users\n" -" Prints a listing of all managers that are currently configured on that\n" -" system.\n"; - -static char showmanager_help[] = -" Usage: manager show user <user>\n" -" Display all information related to the manager user specified.\n"; - static struct ast_cli_entry cli_manager[] = { - { { "manager", "show", "command", NULL }, - handle_showmancmd, "Show a manager interface command", - showmancmd_help, complete_show_mancmd }, - - { { "manager", "show", "commands", NULL }, - handle_showmancmds, "List manager interface commands", - showmancmds_help }, - - { { "manager", "show", "connected", NULL }, - handle_showmanconn, "List connected manager interface users", - showmanconn_help }, - - { { "manager", "show", "eventq", NULL }, - handle_showmaneventq, "List manager interface queued events", - showmaneventq_help }, - - { { "manager", "show", "users", NULL }, - handle_showmanagers, "List configured manager users", - showmanagers_help, NULL, NULL }, - - { { "manager", "show", "user", NULL }, - handle_showmanager, "Display information on a specific manager user", - showmanager_help, complete_show_manuser, NULL }, - - { { "manager", "debug", NULL }, - handle_mandebug, "Show, enable, disable debugging of the manager code", - "Usage: manager debug [on|off]\n Show, enable, disable debugging of the manager code.\n", NULL, NULL }, + NEW_CLI(handle_showmancmd, "Show a manager interface command"), + NEW_CLI(handle_showmancmds, "List manager interface commands"), + NEW_CLI(handle_showmanconn, "List connected manager interface users"), + NEW_CLI(handle_showmaneventq, "List manager interface queued events"), + NEW_CLI(handle_showmanagers, "List configured manager users"), + NEW_CLI(handle_showmanager, "Display information on a specific manager user"), + NEW_CLI(handle_mandebug, "Show, enable, disable debugging of the manager code"), }; /* diff --git a/main/pbx.c b/main/pbx.c index 82f69c5f4..6b8282a86 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -1246,35 +1246,46 @@ void pbx_retrieve_variable(struct ast_channel *c, const char *var, char **ret, c } } -static int handle_show_functions(int fd, int argc, char *argv[]) +static char *handle_show_functions(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct ast_custom_function *acf; int count_acf = 0; int like = 0; - if (argc == 5 && (!strcmp(argv[3], "like")) ) { + switch (cmd) { + case CLI_INIT: + e->command = "core show functions [like]"; + e->usage = + "Usage: core show functions [like <text>]\n" + " List builtin functions, optionally only those matching a given string\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + + if (a->argc == 5 && (!strcmp(a->argv[3], "like")) ) { like = 1; - } else if (argc != 3) { - return RESULT_SHOWUSAGE; + } else if (a->argc != 3) { + return CLI_SHOWUSAGE; } - ast_cli(fd, "%s Custom Functions:\n--------------------------------------------------------------------------------\n", like ? "Matching" : "Installed"); + ast_cli(a->fd, "%s Custom Functions:\n--------------------------------------------------------------------------------\n", like ? "Matching" : "Installed"); AST_RWLIST_RDLOCK(&acf_root); AST_RWLIST_TRAVERSE(&acf_root, acf, acflist) { - if (!like || strstr(acf->name, argv[4])) { + if (!like || strstr(acf->name, a->argv[4])) { count_acf++; - ast_cli(fd, "%-20.20s %-35.35s %s\n", acf->name, acf->syntax, acf->synopsis); + ast_cli(a->fd, "%-20.20s %-35.35s %s\n", acf->name, acf->syntax, acf->synopsis); } } AST_RWLIST_UNLOCK(&acf_root); - ast_cli(fd, "%d %scustom functions installed.\n", count_acf, like ? "matching " : ""); + ast_cli(a->fd, "%d %scustom functions installed.\n", count_acf, like ? "matching " : ""); - return RESULT_SUCCESS; + return CLI_SUCCESS; } -static int handle_show_function(int fd, int argc, char *argv[]) +static char *handle_show_function(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct ast_custom_function *acf; /* Maximum number of characters added by terminal coloring is 22 */ @@ -1282,13 +1293,38 @@ static int handle_show_function(int fd, int argc, char *argv[]) char info[64 + AST_MAX_APP], *synopsis = NULL, *description = NULL; char stxtitle[40], *syntax = NULL; int synopsis_size, description_size, syntax_size; + char *ret = NULL; + int which = 0; + int wordlen; - if (argc < 4) - return RESULT_SHOWUSAGE; + switch (cmd) { + case CLI_INIT: + e->command = "core show function"; + e->usage = + "Usage: core show function <function>\n" + " Describe a particular dialplan function.\n"; + return NULL; + case CLI_GENERATE: + wordlen = strlen(a->word); + /* case-insensitive for convenience in this 'complete' function */ + AST_RWLIST_RDLOCK(&acf_root); + AST_RWLIST_TRAVERSE(&acf_root, acf, acflist) { + if (!strncasecmp(a->word, acf->name, wordlen) && ++which > a->n) { + ret = ast_strdup(acf->name); + break; + } + } + AST_RWLIST_UNLOCK(&acf_root); - if (!(acf = ast_custom_function_find(argv[3]))) { - ast_cli(fd, "No function by that name registered.\n"); - return RESULT_FAILURE; + return ret; + } + + if (a->argc < 4) + return CLI_SHOWUSAGE; + + if (!(acf = ast_custom_function_find(a->argv[3]))) { + ast_cli(a->fd, "No function by that name registered.\n"); + return CLI_FAILURE; } @@ -1325,29 +1361,9 @@ static int handle_show_function(int fd, int argc, char *argv[]) acf->desc ? acf->desc : "Not available", COLOR_CYAN, 0, description_size); - ast_cli(fd,"%s%s%s\n\n%s%s\n\n%s%s\n", infotitle, stxtitle, syntax, syntitle, synopsis, destitle, description); - - return RESULT_SUCCESS; -} - -static char *complete_show_function(const char *line, const char *word, int pos, int state) -{ - struct ast_custom_function *acf; - char *ret = NULL; - int which = 0; - int wordlen = strlen(word); - - /* case-insensitive for convenience in this 'complete' function */ - AST_RWLIST_RDLOCK(&acf_root); - AST_RWLIST_TRAVERSE(&acf_root, acf, acflist) { - if (!strncasecmp(word, acf->name, wordlen) && ++which > state) { - ret = ast_strdup(acf->name); - break; - } - } - AST_RWLIST_UNLOCK(&acf_root); + ast_cli(a->fd,"%s%s%s\n\n%s%s\n\n%s%s\n", infotitle, stxtitle, syntax, syntitle, synopsis, destitle, description); - return ret; + return CLI_SUCCESS; } struct ast_custom_function *ast_custom_function_find(const char *name) @@ -3008,89 +3024,55 @@ void ast_unregister_switch(struct ast_switch *sw) /* * Help for CLI commands ... */ -static char show_applications_help[] = -"Usage: core show applications [{like|describing} <text>]\n" -" List applications which are currently available.\n" -" If 'like', <text> will be a substring of the app name\n" -" If 'describing', <text> will be a substring of the description\n"; - -static char show_functions_help[] = -"Usage: core show functions [like <text>]\n" -" List builtin functions, optionally only those matching a given string\n"; - -static char show_switches_help[] = -"Usage: core show switches\n" -" List registered switches\n"; - -static char show_hints_help[] = -"Usage: core show hints\n" -" List registered hints\n"; - -static char show_globals_help[] = -"Usage: core show globals\n" -" List current global dialplan variables and their values\n"; - -static char show_application_help[] = -"Usage: core show application <application> [<application> [<application> [...]]]\n" -" Describes a particular application.\n"; - -static char show_function_help[] = -"Usage: core show function <function>\n" -" Describe a particular dialplan function.\n"; - -static char show_dialplan_help[] = -"Usage: core show dialplan [exten@][context]\n" -" Show dialplan\n"; - -static char set_global_help[] = -"Usage: core set global <name> <value>\n" -" Set global dialplan variable <name> to <value>\n"; - - -/* - * \brief 'show application' CLI command implementation functions ... - */ /* - * There is a possibility to show informations about more than one - * application at one time. You can type 'show application Dial Echo' and - * you will see informations about these two applications ... + * \brief 'show application' CLI command implementation function... */ -static char *complete_show_application(const char *line, const char *word, int pos, int state) +static char *handle_show_application(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { - struct ast_app *a; + struct ast_app *aa; + int app, no_registered_app = 1; char *ret = NULL; int which = 0; - int wordlen = strlen(word); + int wordlen; - /* return the n-th [partial] matching entry */ - AST_RWLIST_RDLOCK(&apps); - AST_RWLIST_TRAVERSE(&apps, a, list) { - if (!strncasecmp(word, a->name, wordlen) && ++which > state) { - ret = ast_strdup(a->name); - break; + switch (cmd) { + case CLI_INIT: + e->command = "core show application"; + e->usage = + "Usage: core show application <application> [<application> [<application> [...]]]\n" + " Describes a particular application.\n"; + return NULL; + case CLI_GENERATE: + /* + * There is a possibility to show informations about more than one + * application at one time. You can type 'show application Dial Echo' and + * you will see informations about these two applications ... + */ + wordlen = strlen(a->word); + /* return the n-th [partial] matching entry */ + AST_RWLIST_RDLOCK(&apps); + AST_RWLIST_TRAVERSE(&apps, aa, list) { + if (!strncasecmp(a->word, aa->name, wordlen) && ++which > a->n) { + ret = ast_strdup(aa->name); + break; + } } - } - AST_RWLIST_UNLOCK(&apps); - - return ret; -} + AST_RWLIST_UNLOCK(&apps); -static int handle_show_application(int fd, int argc, char *argv[]) -{ - struct ast_app *a; - int app, no_registered_app = 1; + return ret; + } - if (argc < 4) - return RESULT_SHOWUSAGE; + if (a->argc < 4) + return CLI_SHOWUSAGE; /* ... go through all applications ... */ AST_RWLIST_RDLOCK(&apps); - AST_RWLIST_TRAVERSE(&apps, a, list) { + AST_RWLIST_TRAVERSE(&apps, aa, list) { /* ... compare this application name with all arguments given * to 'show application' command ... */ - for (app = 3; app < argc; app++) { - if (!strcasecmp(a->name, argv[app])) { + for (app = 3; app < a->argc; app++) { + if (!strcasecmp(aa->name, a->argv[app])) { /* Maximum number of characters added by terminal coloring is 22 */ char infotitle[64 + AST_MAX_APP + 22], syntitle[40], destitle[40]; char info[64 + AST_MAX_APP], *synopsis = NULL, *description = NULL; @@ -3098,39 +3080,39 @@ static int handle_show_application(int fd, int argc, char *argv[]) no_registered_app = 0; - if (a->synopsis) - synopsis_size = strlen(a->synopsis) + 23; + if (aa->synopsis) + synopsis_size = strlen(aa->synopsis) + 23; else synopsis_size = strlen("Not available") + 23; synopsis = alloca(synopsis_size); - if (a->description) - description_size = strlen(a->description) + 23; + if (aa->description) + description_size = strlen(aa->description) + 23; else description_size = strlen("Not available") + 23; description = alloca(description_size); if (synopsis && description) { - snprintf(info, 64 + AST_MAX_APP, "\n -= Info about application '%s' =- \n\n", a->name); + snprintf(info, 64 + AST_MAX_APP, "\n -= Info about application '%s' =- \n\n", aa->name); term_color(infotitle, info, COLOR_MAGENTA, 0, 64 + AST_MAX_APP + 22); term_color(syntitle, "[Synopsis]\n", COLOR_MAGENTA, 0, 40); term_color(destitle, "[Description]\n", COLOR_MAGENTA, 0, 40); term_color(synopsis, - a->synopsis ? a->synopsis : "Not available", + aa->synopsis ? aa->synopsis : "Not available", COLOR_CYAN, 0, synopsis_size); term_color(description, - a->description ? a->description : "Not available", + aa->description ? aa->description : "Not available", COLOR_CYAN, 0, description_size); - ast_cli(fd,"%s%s%s\n\n%s%s\n", infotitle, syntitle, synopsis, destitle, description); + ast_cli(a->fd,"%s%s%s\n\n%s%s\n", infotitle, syntitle, synopsis, destitle, description); } else { /* ... one of our applications, show info ...*/ - ast_cli(fd,"\n -= Info about application '%s' =- \n\n" + ast_cli(a->fd,"\n -= Info about application '%s' =- \n\n" "[Synopsis]\n %s\n\n" "[Description]\n%s\n", - a->name, - a->synopsis ? a->synopsis : "Not available", - a->description ? a->description : "Not available"); + aa->name, + aa->synopsis ? aa->synopsis : "Not available", + aa->description ? aa->description : "Not available"); } } } @@ -3139,112 +3121,148 @@ static int handle_show_application(int fd, int argc, char *argv[]) /* we found at least one app? no? */ if (no_registered_app) { - ast_cli(fd, "Your application(s) is (are) not registered\n"); - return RESULT_FAILURE; + ast_cli(a->fd, "Your application(s) is (are) not registered\n"); + return CLI_FAILURE; } - return RESULT_SUCCESS; + return CLI_SUCCESS; } /*! \brief handle_show_hints: CLI support for listing registered dial plan hints */ -static int handle_show_hints(int fd, int argc, char *argv[]) +static char *handle_show_hints(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct ast_hint *hint; int num = 0; int watchers; struct ast_state_cb *watcher; + switch (cmd) { + case CLI_INIT: + e->command = "core show hints"; + e->usage = + "Usage: core show hints\n" + " List registered hints\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + AST_RWLIST_RDLOCK(&hints); if (AST_RWLIST_EMPTY(&hints)) { - ast_cli(fd, "There are no registered dialplan hints\n"); + ast_cli(a->fd, "There are no registered dialplan hints\n"); AST_RWLIST_UNLOCK(&hints); - return RESULT_SUCCESS; + return CLI_SUCCESS; } /* ... we have hints ... */ - ast_cli(fd, "\n -= Registered Asterisk Dial Plan Hints =-\n"); + ast_cli(a->fd, "\n -= Registered Asterisk Dial Plan Hints =-\n"); AST_RWLIST_TRAVERSE(&hints, hint, list) { watchers = 0; for (watcher = hint->callbacks; watcher; watcher = watcher->next) watchers++; - ast_cli(fd, " %20s@%-20.20s: %-20.20s State:%-15.15s Watchers %2d\n", + ast_cli(a->fd, " %20s@%-20.20s: %-20.20s State:%-15.15s Watchers %2d\n", ast_get_extension_name(hint->exten), ast_get_context_name(ast_get_extension_context(hint->exten)), ast_get_extension_app(hint->exten), ast_extension_state2str(hint->laststate), watchers); num++; } - ast_cli(fd, "----------------\n"); - ast_cli(fd, "- %d hints registered\n", num); + ast_cli(a->fd, "----------------\n"); + ast_cli(a->fd, "- %d hints registered\n", num); AST_RWLIST_UNLOCK(&hints); - return RESULT_SUCCESS; + return CLI_SUCCESS; } /*! \brief handle_show_switches: CLI support for listing registered dial plan switches */ -static int handle_show_switches(int fd, int argc, char *argv[]) +static char *handle_show_switches(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct ast_switch *sw; + switch (cmd) { + case CLI_INIT: + e->command = "core show switches"; + e->usage = + "Usage: core show switches\n" + " List registered switches\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + AST_RWLIST_RDLOCK(&switches); if (AST_RWLIST_EMPTY(&switches)) { AST_RWLIST_UNLOCK(&switches); - ast_cli(fd, "There are no registered alternative switches\n"); + ast_cli(a->fd, "There are no registered alternative switches\n"); return RESULT_SUCCESS; } - ast_cli(fd, "\n -= Registered Asterisk Alternative Switches =-\n"); + ast_cli(a->fd, "\n -= Registered Asterisk Alternative Switches =-\n"); AST_RWLIST_TRAVERSE(&switches, sw, list) - ast_cli(fd, "%s: %s\n", sw->name, sw->description); + ast_cli(a->fd, "%s: %s\n", sw->name, sw->description); AST_RWLIST_UNLOCK(&switches); - return RESULT_SUCCESS; + return CLI_SUCCESS; } -static int handle_show_applications(int fd, int argc, char *argv[]) +static char *handle_show_applications(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { - struct ast_app *a; + struct ast_app *aa; int like = 0, describing = 0; int total_match = 0; /* Number of matches in like clause */ int total_apps = 0; /* Number of apps registered */ + static char* choices[] = { "like", "describing", NULL }; + + switch (cmd) { + case CLI_INIT: + e->command = "core show applications [like|describing]"; + e->usage = + "Usage: core show applications [{like|describing} <text>]\n" + " List applications which are currently available.\n" + " If 'like', <text> will be a substring of the app name\n" + " If 'describing', <text> will be a substring of the description\n"; + return NULL; + case CLI_GENERATE: + return (a->pos != 3) ? NULL : ast_cli_complete(a->word, choices, a->n); + } AST_RWLIST_RDLOCK(&apps); if (AST_RWLIST_EMPTY(&apps)) { - ast_cli(fd, "There are no registered applications\n"); + ast_cli(a->fd, "There are no registered applications\n"); AST_RWLIST_UNLOCK(&apps); - return -1; + return CLI_SUCCESS; } /* core list applications like <keyword> */ - if ((argc == 5) && (!strcmp(argv[3], "like"))) { + if ((a->argc == 5) && (!strcmp(a->argv[3], "like"))) { like = 1; - } else if ((argc > 4) && (!strcmp(argv[3], "describing"))) { + } else if ((a->argc > 4) && (!strcmp(a->argv[3], "describing"))) { describing = 1; } /* core list applications describing <keyword1> [<keyword2>] [...] */ if ((!like) && (!describing)) { - ast_cli(fd, " -= Registered Asterisk Applications =-\n"); + ast_cli(a->fd, " -= Registered Asterisk Applications =-\n"); } else { - ast_cli(fd, " -= Matching Asterisk Applications =-\n"); + ast_cli(a->fd, " -= Matching Asterisk Applications =-\n"); } - AST_RWLIST_TRAVERSE(&apps, a, list) { + AST_RWLIST_TRAVERSE(&apps, aa, list) { int printapp = 0; total_apps++; if (like) { - if (strcasestr(a->name, argv[4])) { + if (strcasestr(aa->name, a->argv[4])) { printapp = 1; total_match++; } } else if (describing) { - if (a->description) { + if (aa->description) { /* Match all words on command line */ int i; printapp = 1; - for (i = 4; i < argc; i++) { - if (!strcasestr(a->description, argv[i])) { + for (i = 4; i < a->argc; i++) { + if (!strcasestr(aa->description, a->argv[i])) { printapp = 0; } else { total_match++; @@ -3256,25 +3274,18 @@ static int handle_show_applications(int fd, int argc, char *argv[]) } if (printapp) { - ast_cli(fd," %20s: %s\n", a->name, a->synopsis ? a->synopsis : "<Synopsis not available>"); + ast_cli(a->fd," %20s: %s\n", aa->name, aa->synopsis ? aa->synopsis : "<Synopsis not available>"); } } if ((!like) && (!describing)) { - ast_cli(fd, " -= %d Applications Registered =-\n",total_apps); + ast_cli(a->fd, " -= %d Applications Registered =-\n",total_apps); } else { - ast_cli(fd, " -= %d Applications Matching =-\n",total_match); + ast_cli(a->fd, " -= %d Applications Matching =-\n",total_match); } AST_RWLIST_UNLOCK(&apps); - return RESULT_SUCCESS; -} - -static char *complete_show_applications(const char *line, const char *word, int pos, int state) -{ - static char* choices[] = { "like", "describing", NULL }; - - return (pos != 3) ? NULL : ast_cli_complete(word, choices, state); + return CLI_SUCCESS; } /* @@ -3485,59 +3496,70 @@ static int show_dialplan_helper(int fd, const char *context, const char *exten, return (dpc->total_exten == old_total_exten) ? -1 : res; } -static int handle_show_dialplan(int fd, int argc, char *argv[]) +static char *handle_show_dialplan(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { char *exten = NULL, *context = NULL; /* Variables used for different counters */ struct dialplan_counters counters; - const char *incstack[AST_PBX_MAX_STACK]; + + switch (cmd) { + case CLI_INIT: + e->command = "dialplan show"; + e->usage = + "Usage: core show dialplan [exten@][context]\n" + " Show dialplan\n"; + return NULL; + case CLI_GENERATE: + return complete_show_dialplan_context(a->line, a->word, a->pos, a->n); + } + memset(&counters, 0, sizeof(counters)); - if (argc != 2 && argc != 3) - return RESULT_SHOWUSAGE; + if (a->argc != 2 && a->argc != 3) + return CLI_SHOWUSAGE; /* we obtain [exten@]context? if yes, split them ... */ - if (argc == 3) { - if (strchr(argv[2], '@')) { /* split into exten & context */ - context = ast_strdupa(argv[2]); + if (a->argc == 3) { + if (strchr(a->argv[2], '@')) { /* split into exten & context */ + context = ast_strdupa(a->argv[2]); exten = strsep(&context, "@"); /* change empty strings to NULL */ if (ast_strlen_zero(exten)) exten = NULL; } else { /* no '@' char, only context given */ - context = argv[2]; + context = a->argv[2]; } if (ast_strlen_zero(context)) context = NULL; } /* else Show complete dial plan, context and exten are NULL */ - show_dialplan_helper(fd, context, exten, &counters, NULL, 0, incstack); + show_dialplan_helper(a->fd, context, exten, &counters, NULL, 0, incstack); /* check for input failure and throw some error messages */ if (context && !counters.context_existence) { - ast_cli(fd, "There is no existence of '%s' context\n", context); - return RESULT_FAILURE; + ast_cli(a->fd, "There is no existence of '%s' context\n", context); + return CLI_FAILURE; } if (exten && !counters.extension_existence) { if (context) - ast_cli(fd, "There is no existence of %s@%s extension\n", + ast_cli(a->fd, "There is no existence of %s@%s extension\n", exten, context); else - ast_cli(fd, + ast_cli(a->fd, "There is no existence of '%s' extension in all contexts\n", exten); - return RESULT_FAILURE; + return CLI_FAILURE; } - ast_cli(fd,"-= %d %s (%d %s) in %d %s. =-\n", + ast_cli(a->fd,"-= %d %s (%d %s) in %d %s. =-\n", counters.total_exten, counters.total_exten == 1 ? "extension" : "extensions", counters.total_prio, counters.total_prio == 1 ? "priority" : "priorities", counters.total_context, counters.total_context == 1 ? "context" : "contexts"); /* everything ok */ - return RESULT_SUCCESS; + return CLI_SUCCESS; } /*! \brief Send ack once */ @@ -3751,74 +3773,68 @@ static char mandescr_show_dialplan[] = /*! \brief CLI support for listing global variables in a parseable way */ -static int handle_show_globals(int fd, int argc, char *argv[]) +static char *handle_show_globals(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int i = 0; struct ast_var_t *newvariable; + switch (cmd) { + case CLI_INIT: + e->command = "core show globals"; + e->usage = + "Usage: core show globals\n" + " List current global dialplan variables and their values\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + ast_rwlock_rdlock(&globalslock); AST_LIST_TRAVERSE (&globals, newvariable, entries) { i++; - ast_cli(fd, " %s=%s\n", ast_var_name(newvariable), ast_var_value(newvariable)); + ast_cli(a->fd, " %s=%s\n", ast_var_name(newvariable), ast_var_value(newvariable)); } ast_rwlock_unlock(&globalslock); - ast_cli(fd, "\n -- %d variables\n", i); + ast_cli(a->fd, "\n -- %d variables\n", i); - return RESULT_SUCCESS; + return CLI_SUCCESS; } -static int handle_set_global(int fd, int argc, char *argv[]) +static char *handle_set_global(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { - if (argc != 5) - return RESULT_SHOWUSAGE; - - pbx_builtin_setvar_helper(NULL, argv[3], argv[4]); - ast_cli(fd, "\n -- Global variable %s set to %s\n", argv[3], argv[4]); + switch (cmd) { + case CLI_INIT: + e->command = "core set global"; + e->usage = + "Usage: core set global <name> <value>\n" + " Set global dialplan variable <name> to <value>\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } - return RESULT_SUCCESS; -} + if (a->argc != 5) + return CLI_SHOWUSAGE; + pbx_builtin_setvar_helper(NULL, a->argv[3], a->argv[4]); + ast_cli(a->fd, "\n -- Global variable %s set to %s\n", a->argv[3], a->argv[4]); + return CLI_SUCCESS; +} /* * CLI entries for upper commands ... */ static struct ast_cli_entry pbx_cli[] = { - { { "core", "show", "applications", NULL }, - handle_show_applications, "Shows registered dialplan applications", - show_applications_help, complete_show_applications }, - - { { "core", "show", "functions", NULL }, - handle_show_functions, "Shows registered dialplan functions", - show_functions_help }, - - { { "core", "show", "switches", NULL }, - handle_show_switches, "Show alternative switches", - show_switches_help }, - - { { "core", "show", "hints", NULL }, - handle_show_hints, "Show dialplan hints", - show_hints_help }, - - { { "core", "show", "globals", NULL }, - handle_show_globals, "Show global dialplan variables", - show_globals_help }, - - { { "core", "show" , "function", NULL }, - handle_show_function, "Describe a specific dialplan function", - show_function_help, complete_show_function }, - - { { "core", "show", "application", NULL }, - handle_show_application, "Describe a specific dialplan application", - show_application_help, complete_show_application }, - - { { "core", "set", "global", NULL }, - handle_set_global, "Set global dialplan variable", - set_global_help }, - - { { "dialplan", "show", NULL }, - handle_show_dialplan, "Show dialplan", - show_dialplan_help, complete_show_dialplan_context }, + NEW_CLI(handle_show_applications, "Shows registered dialplan applications"), + NEW_CLI(handle_show_functions, "Shows registered dialplan functions"), + NEW_CLI(handle_show_switches, "Show alternative switches"), + NEW_CLI(handle_show_hints, "Show dialplan hints"), + NEW_CLI(handle_show_globals, "Show global dialplan variables"), + NEW_CLI(handle_show_function, "Describe a specific dialplan function"), + NEW_CLI(handle_show_application, "Describe a specific dialplan application"), + NEW_CLI(handle_set_global, "Set global dialplan variable"), + NEW_CLI(handle_show_dialplan, "Show dialplan"), }; static void unreference_cached_app(struct ast_app *app) |