[Asterisk-code-review] CLI: Fix remote console completion. (asterisk[15])

Corey Farrell asteriskteam at digium.com
Thu Dec 7 10:39:07 CST 2017


Corey Farrell has uploaded this change for review. ( https://gerrit.asterisk.org/7469


Change subject: CLI: Fix remote console completion.
......................................................................

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.

Change-Id: Ibbdb29f88211742071836c9b3f4d2aa1221cd0f9
---
M main/asterisk.c
1 file changed, 11 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/69/7469/1

diff --git a/main/asterisk.c b/main/asterisk.c
index 2c86d1e..4ba621c 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -3012,10 +3012,17 @@
 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, " "))) {
@@ -3024,7 +3031,7 @@
 		}
 
 		/* 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 @@
 		}
 	}
 
-	if (!AST_VECTOR_SIZE(vec)) {
+	bestmatch = ast_strdup(bestmatch);
+	if (!bestmatch || AST_VECTOR_INSERT_AT(vec, 0, bestmatch)) {
+		ast_free(bestmatch);
 		goto vector_cleanup;
 	}
 

-- 
To view, visit https://gerrit.asterisk.org/7469
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibbdb29f88211742071836c9b3f4d2aa1221cd0f9
Gerrit-Change-Number: 7469
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171207/2134eb50/attachment.html>


More information about the asterisk-code-review mailing list