Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 132644) +++ channels/chan_sip.c (working copy) @@ -12709,19 +12709,25 @@ char *name = NULL; regex_t regexbuf; struct ao2_iterator i; + static char *choices[] = { "all", "like", NULL }; + char *cmplt; if (cmd == CLI_INIT) { - e->command = "sip prune realtime [peer|all] [all|like]"; + e->command = "sip prune realtime [peer|all]"; e->usage = - "Usage: sip prune realtime [peer] [|all|like ]\n" + "Usage: sip prune realtime [peer [|all|like ]|all]\n" " Prunes object(s) from the cache.\n" " Optional regular expression pattern is used to filter the objects.\n"; return NULL; } else if (cmd == CLI_GENERATE) { - if (a->pos == 4) { - if (strcasestr(a->line, "realtime peer")) - return complete_sip_peer(a->word, a->n, SIP_PAGE2_RTCACHEFRIENDS); + if (a->pos == 4 && !strcasecmp(a->argv[3], "peer")) { + cmplt = ast_cli_complete(a->word, choices, a->n); + 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; } switch (a->argc) { @@ -12747,9 +12753,9 @@ multi = TRUE; } else return CLI_SHOWUSAGE; - if (!strcasecmp(a->argv[4], "like")) + if (!strcasecmp(name, "like")) return CLI_SHOWUSAGE; - if (!multi && !strcasecmp(a->argv[4], "all")) { + if (!multi && !strcasecmp(name, "all")) { multi = TRUE; name = NULL; } @@ -14354,7 +14360,7 @@ " IP address or registered peer.\n"; return NULL; } 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 NULL; } Index: channels/chan_iax2.c =================================================================== --- channels/chan_iax2.c (revision 132644) +++ channels/chan_iax2.c (working copy) @@ -708,7 +708,7 @@ 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 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); enum iax2_thread_iostate { @@ -2436,6 +2436,8 @@ static char *handle_cli_iax2_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { struct iax2_peer *peer; + static char *choices[] = { "all", NULL }; + char *cmplt; switch (cmd) { case CLI_INIT: @@ -2445,18 +2447,22 @@ " Prunes object(s) from the cache\n"; return NULL; case CLI_GENERATE: - if (a->pos == 3) - return complete_iax2_peers(a->line, a->word, a->pos, a->n); + if (a->pos == 3) { + 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; } if (a->argc != 4) - return CLI_SHOWUSAGE; + return CLI_SHOWUSAGE; if (!strcmp(a->argv[3], "all")) { reload_config(); ast_cli(a->fd, "Cache flushed successfully.\n"); } 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); expire_registry(peer_ref(peer)); ast_cli(a->fd, "Peer %s was removed from the cache.\n", a->argv[3]); @@ -2602,7 +2608,7 @@ return NULL; case CLI_GENERATE: 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; } @@ -2658,7 +2664,7 @@ 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; struct iax2_peer *peer; @@ -2668,7 +2674,8 @@ i = ao2_iterator_init(peers, 0); 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); peer_unref(peer); break; @@ -5551,8 +5558,8 @@ " Enables/Disables dumping of IAX packets for debugging purposes.\n"; return NULL; case CLI_GENERATE: - if (a->pos == 4) - return complete_iax2_peers(a->line, a->word, a->pos, a->n); + if (a->pos == 4 && !strcasecmp(a->argv[3], "peer")) + return complete_iax2_peers(a->line, a->word, a->pos, a->n, 0); return NULL; } Index: main/cli.c =================================================================== --- main/cli.c (revision 132644) +++ main/cli.c (working copy) @@ -1835,7 +1835,9 @@ struct ast_cli_args a = { .line = matchstr, .word = word, .pos = argindex, - .n = state - matchnum }; + .n = state - matchnum, + .argv = argv, + .argc = x}; ret = e->handler(e, CLI_GENERATE, &a); } if (ret)