diff options
author | Corey Farrell <git@cfware.com> | 2017-12-07 11:35:39 -0500 |
---|---|---|
committer | Corey Farrell <git@cfware.com> | 2017-12-07 11:26:50 -0600 |
commit | 5a0dcd92758787b366312a162cad4fd15dd639b2 (patch) | |
tree | 80b3a6fda194af3521de44ee48873a2caddd9f64 /main | |
parent | 93859f9acaf53ef9a6390ffb4f884d4666a4c77c (diff) |
CLI: Fix remote console completion.
Duplicate checking was done incorrectly when parsing completion options
from a remote console causing all options to be ignored as duplicates.
Once fixed I had to separate processing of the best match to ensure it
was not identified as a duplicate when it is the only match.
ASTERISK-27465
Change-Id: Ibbdb29f88211742071836c9b3f4d2aa1221cd0f9
Diffstat (limited to 'main')
-rw-r--r-- | main/asterisk.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/main/asterisk.c b/main/asterisk.c index 0abb3600d..bc78687d2 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -3133,19 +3133,26 @@ static char *cli_prompt(EditLine *editline) static struct ast_vector_string *ast_el_strtoarr(char *buf) { char *retstr; + char *bestmatch; struct ast_vector_string *vec = ast_calloc(1, sizeof(*vec)); if (!vec) { return NULL; } + /* bestmatch must not be deduplicated */ + bestmatch = strsep(&buf, " "); + if (!bestmatch || !strcmp(bestmatch, AST_CLI_COMPLETE_EOF)) { + goto vector_cleanup; + } + while ((retstr = strsep(&buf, " "))) { if (!strcmp(retstr, AST_CLI_COMPLETE_EOF)) { break; } /* Older daemons sent duplicates. */ - if (AST_VECTOR_GET_CMP(vec, retstr, strcasecmp)) { + if (AST_VECTOR_GET_CMP(vec, retstr, !strcasecmp)) { continue; } @@ -3157,7 +3164,9 @@ static struct ast_vector_string *ast_el_strtoarr(char *buf) } } - if (!AST_VECTOR_SIZE(vec)) { + bestmatch = ast_strdup(bestmatch); + if (!bestmatch || AST_VECTOR_INSERT_AT(vec, 0, bestmatch)) { + ast_free(bestmatch); goto vector_cleanup; } |