diff options
author | Joshua Colp <jcolp@digium.com> | 2017-12-07 14:36:40 -0600 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2017-12-07 14:36:40 -0600 |
commit | fead60166e0cda9e3f966c5e76a34b7471d5ea83 (patch) | |
tree | 0b661ba56fe90ca246adc3ccfbbbb8e00d7e0775 | |
parent | a51c82eb025e3a82d95dd66cd4f87890148df1eb (diff) | |
parent | b8a063f4bf5e0236e55f0fa58dbdf17aa4085584 (diff) |
Merge "CLI: Fix remote console completion." into 15
-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 2238d433c..faac569c0 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -3012,19 +3012,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; } @@ -3036,7 +3043,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; } |