mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-02 20:08:17 +00:00
Some fixes to autocompletion in some commands.
Changes applied by this patch: - Fix autocompletion in 'sip prune realtime', sip peers where never auto completed. Now we complete this command with: 'sip prune realtime peer' -> all | like | sip peers Also I have modified the syntax in the usage, was wrong... - Pass ast_cli_args->argv and ast_cli_args->argc while running autocompletion on CLI commands (CLI_GENERATE). With this we avoid comparisons on ast_cli_args->line like this: strcasestr(a->line, " description") strcasestr(a->line, "descriptions ") strcasestr(a->line, "realtime peer"), and so on.. Making the code more confusing (check the spaces in description!). The only thing we must be sure is to first check a->pos or a->argc. - Fix 'iax2 prune realtime' autocompletion, now we autocomplete this command with 'all' & 'iax2 peers', check a look that iax2 peers where all the peers, now only the ones in the cache.. (closes issue #13133) Reported by: eliel Patches: clichanges.patch uploaded by eliel (license 64) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@141464 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -731,7 +731,7 @@ static void reg_source_db(struct iax2_peer *p);
|
|||||||
static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in *sin);
|
static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in *sin);
|
||||||
|
|
||||||
static int ast_cli_netstats(struct mansession *s, int fd, int limit_fmt);
|
static int ast_cli_netstats(struct mansession *s, int fd, int limit_fmt);
|
||||||
static char *complete_iax2_peers(const char *line, const char *word, int pos, int state);
|
static char *complete_iax2_peers(const char *line, const char *word, int pos, int state, int flags);
|
||||||
static char *complete_iax2_unregister(const char *line, const char *word, int pos, int state);
|
static char *complete_iax2_unregister(const char *line, const char *word, int pos, int state);
|
||||||
|
|
||||||
enum iax2_thread_iostate {
|
enum iax2_thread_iostate {
|
||||||
@@ -2461,6 +2461,8 @@ static int attempt_transmit(const void *data)
|
|||||||
static char *handle_cli_iax2_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
static char *handle_cli_iax2_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
|
||||||
{
|
{
|
||||||
struct iax2_peer *peer;
|
struct iax2_peer *peer;
|
||||||
|
static char *choices[] = { "all", NULL };
|
||||||
|
char *cmplt;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case CLI_INIT:
|
case CLI_INIT:
|
||||||
@@ -2470,18 +2472,22 @@ static char *handle_cli_iax2_prune_realtime(struct ast_cli_entry *e, int cmd, st
|
|||||||
" Prunes object(s) from the cache\n";
|
" Prunes object(s) from the cache\n";
|
||||||
return NULL;
|
return NULL;
|
||||||
case CLI_GENERATE:
|
case CLI_GENERATE:
|
||||||
if (a->pos == 3)
|
if (a->pos == 3) {
|
||||||
return complete_iax2_peers(a->line, a->word, a->pos, a->n);
|
cmplt = ast_cli_complete(a->word, choices, a->n);
|
||||||
|
if (!cmplt)
|
||||||
|
cmplt = complete_iax2_peers(a->line, a->word, a->pos, a->n - sizeof(choices), IAX_RTCACHEFRIENDS);
|
||||||
|
return cmplt;
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a->argc != 4)
|
if (a->argc != 4)
|
||||||
return CLI_SHOWUSAGE;
|
return CLI_SHOWUSAGE;
|
||||||
if (!strcmp(a->argv[3], "all")) {
|
if (!strcmp(a->argv[3], "all")) {
|
||||||
reload_config();
|
reload_config();
|
||||||
ast_cli(a->fd, "Cache flushed successfully.\n");
|
ast_cli(a->fd, "Cache flushed successfully.\n");
|
||||||
} else if ((peer = find_peer(a->argv[3], 0))) {
|
} else if ((peer = find_peer(a->argv[3], 0))) {
|
||||||
if(ast_test_flag(peer, IAX_RTCACHEFRIENDS)) {
|
if (ast_test_flag(peer, IAX_RTCACHEFRIENDS)) {
|
||||||
ast_set_flag(peer, IAX_RTAUTOCLEAR);
|
ast_set_flag(peer, IAX_RTAUTOCLEAR);
|
||||||
expire_registry(peer_ref(peer));
|
expire_registry(peer_ref(peer));
|
||||||
ast_cli(a->fd, "Peer %s was removed from the cache.\n", a->argv[3]);
|
ast_cli(a->fd, "Peer %s was removed from the cache.\n", a->argv[3]);
|
||||||
@@ -2627,7 +2633,7 @@ static char *handle_cli_iax2_show_peer(struct ast_cli_entry *e, int cmd, struct
|
|||||||
return NULL;
|
return NULL;
|
||||||
case CLI_GENERATE:
|
case CLI_GENERATE:
|
||||||
if (a->pos == 3)
|
if (a->pos == 3)
|
||||||
return complete_iax2_peers(a->line, a->word, a->pos, a->n);
|
return complete_iax2_peers(a->line, a->word, a->pos, a->n, 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2683,7 +2689,7 @@ static char *handle_cli_iax2_show_peer(struct ast_cli_entry *e, int cmd, struct
|
|||||||
return CLI_SUCCESS;
|
return CLI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *complete_iax2_peers(const char *line, const char *word, int pos, int state)
|
static char *complete_iax2_peers(const char *line, const char *word, int pos, int state, int flags)
|
||||||
{
|
{
|
||||||
int which = 0;
|
int which = 0;
|
||||||
struct iax2_peer *peer;
|
struct iax2_peer *peer;
|
||||||
@@ -2693,7 +2699,8 @@ static char *complete_iax2_peers(const char *line, const char *word, int pos, in
|
|||||||
|
|
||||||
i = ao2_iterator_init(peers, 0);
|
i = ao2_iterator_init(peers, 0);
|
||||||
while ((peer = ao2_iterator_next(&i))) {
|
while ((peer = ao2_iterator_next(&i))) {
|
||||||
if (!strncasecmp(peer->name, word, wordlen) && ++which > state) {
|
if (!strncasecmp(peer->name, word, wordlen) && ++which > state
|
||||||
|
&& (!flags || ast_test_flag(peer, flags))) {
|
||||||
res = ast_strdup(peer->name);
|
res = ast_strdup(peer->name);
|
||||||
peer_unref(peer);
|
peer_unref(peer);
|
||||||
break;
|
break;
|
||||||
@@ -5642,8 +5649,8 @@ static char *handle_cli_iax2_set_debug(struct ast_cli_entry *e, int cmd, struct
|
|||||||
" Enables/Disables dumping of IAX packets for debugging purposes.\n";
|
" Enables/Disables dumping of IAX packets for debugging purposes.\n";
|
||||||
return NULL;
|
return NULL;
|
||||||
case CLI_GENERATE:
|
case CLI_GENERATE:
|
||||||
if (a->pos == 4)
|
if (a->pos == 4 && !strcasecmp(a->argv[3], "peer"))
|
||||||
return complete_iax2_peers(a->line, a->word, a->pos, a->n);
|
return complete_iax2_peers(a->line, a->word, a->pos, a->n, 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12740,19 +12740,25 @@ static char *sip_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli
|
|||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
regex_t regexbuf;
|
regex_t regexbuf;
|
||||||
struct ao2_iterator i;
|
struct ao2_iterator i;
|
||||||
|
static char *choices[] = { "all", "like", NULL };
|
||||||
|
char *cmplt;
|
||||||
|
|
||||||
if (cmd == CLI_INIT) {
|
if (cmd == CLI_INIT) {
|
||||||
e->command = "sip prune realtime [peer|all] [all|like]";
|
e->command = "sip prune realtime [peer|all]";
|
||||||
e->usage =
|
e->usage =
|
||||||
"Usage: sip prune realtime [peer] [<name>|all|like <pattern>]\n"
|
"Usage: sip prune realtime [peer [<name>|all|like <pattern>]|all]\n"
|
||||||
" Prunes object(s) from the cache.\n"
|
" Prunes object(s) from the cache.\n"
|
||||||
" Optional regular expression pattern is used to filter the objects.\n";
|
" Optional regular expression pattern is used to filter the objects.\n";
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (cmd == CLI_GENERATE) {
|
} else if (cmd == CLI_GENERATE) {
|
||||||
if (a->pos == 4) {
|
if (a->pos == 4 && !strcasecmp(a->argv[3], "peer")) {
|
||||||
if (strcasestr(a->line, "realtime peer"))
|
cmplt = ast_cli_complete(a->word, choices, a->n);
|
||||||
return complete_sip_peer(a->word, a->n, SIP_PAGE2_RTCACHEFRIENDS);
|
if (!cmplt)
|
||||||
|
cmplt = complete_sip_peer(a->word, a->n - sizeof(choices), SIP_PAGE2_RTCACHEFRIENDS);
|
||||||
|
return cmplt;
|
||||||
}
|
}
|
||||||
|
if (a->pos == 5 && !strcasecmp(a->argv[4], "like"))
|
||||||
|
return complete_sip_peer(a->word, a->n, SIP_PAGE2_RTCACHEFRIENDS);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
switch (a->argc) {
|
switch (a->argc) {
|
||||||
@@ -12778,9 +12784,9 @@ static char *sip_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli
|
|||||||
multi = TRUE;
|
multi = TRUE;
|
||||||
} else
|
} else
|
||||||
return CLI_SHOWUSAGE;
|
return CLI_SHOWUSAGE;
|
||||||
if (!strcasecmp(a->argv[4], "like"))
|
if (!strcasecmp(name, "like"))
|
||||||
return CLI_SHOWUSAGE;
|
return CLI_SHOWUSAGE;
|
||||||
if (!multi && !strcasecmp(a->argv[4], "all")) {
|
if (!multi && !strcasecmp(name, "all")) {
|
||||||
multi = TRUE;
|
multi = TRUE;
|
||||||
name = NULL;
|
name = NULL;
|
||||||
}
|
}
|
||||||
@@ -14384,7 +14390,7 @@ static char *sip_do_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_args
|
|||||||
" IP address or registered peer.\n";
|
" IP address or registered peer.\n";
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (cmd == CLI_GENERATE) {
|
} else if (cmd == CLI_GENERATE) {
|
||||||
if (a->pos == 4 && strcasestr(a->line, " peer")) /* XXX should check on argv too */
|
if (a->pos == 4 && !strcasecmp(a->argv[3], "peer"))
|
||||||
return complete_sip_peer(a->word, a->n, 0);
|
return complete_sip_peer(a->word, a->n, 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1835,7 +1835,9 @@ static char *__ast_cli_generator(const char *text, const char *word, int state,
|
|||||||
struct ast_cli_args a = {
|
struct ast_cli_args a = {
|
||||||
.line = matchstr, .word = word,
|
.line = matchstr, .word = word,
|
||||||
.pos = argindex,
|
.pos = argindex,
|
||||||
.n = state - matchnum };
|
.n = state - matchnum,
|
||||||
|
.argv = argv,
|
||||||
|
.argc = x};
|
||||||
ret = e->handler(e, CLI_GENERATE, &a);
|
ret = e->handler(e, CLI_GENERATE, &a);
|
||||||
}
|
}
|
||||||
if (ret)
|
if (ret)
|
||||||
|
|||||||
Reference in New Issue
Block a user