diff options
author | Jenkins2 <jenkins2@gerrit.asterisk.org> | 2017-12-07 14:19:53 -0600 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2017-12-07 14:19:53 -0600 |
commit | ac7501b15ce3e3db463ccd98c8fc1471f9f5e2c1 (patch) | |
tree | aa2cff37ddc7065e24536c86927a87ca40a519f5 /main | |
parent | 9bf73ae1b37768240dfd509a2fd39b2fa82fa397 (diff) | |
parent | 5a0dcd92758787b366312a162cad4fd15dd639b2 (diff) |
Merge "CLI: Fix remote console completion." into 13
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 3807b0af7..0026b36d7 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; } |