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

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


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


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/70/7470/1

diff --git a/main/asterisk.c b/main/asterisk.c
index 0abb360..bc78687 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -3133,10 +3133,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, " "))) {
@@ -3145,7 +3152,7 @@
 		}
 
 		/* 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 @@
 		}
 	}
 
-	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/7470
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibbdb29f88211742071836c9b3f4d2aa1221cd0f9
Gerrit-Change-Number: 7470
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/562ae787/attachment.html>


More information about the asterisk-code-review mailing list