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

Joshua Colp asteriskteam at digium.com
Thu Dec 7 14:36:41 CST 2017


Joshua Colp has submitted this change and it was merged. ( 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.

ASTERISK-27465

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

Approvals:
  Richard Mudgett: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Joshua Colp: Approved for Submit



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: merged
Gerrit-Change-Id: Ibbdb29f88211742071836c9b3f4d2aa1221cd0f9
Gerrit-Change-Number: 7469
Gerrit-PatchSet: 2
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20171207/dfd641b8/attachment.html>


More information about the asterisk-code-review mailing list