[Asterisk-code-review] main/config: Use ast cli completion add for reload completion. (asterisk[15])

Joshua Colp asteriskteam at digium.com
Tue Mar 20 11:44:23 CDT 2018


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/8585 )

Change subject: main/config: Use ast_cli_completion_add for reload completion.
......................................................................

main/config: Use ast_cli_completion_add for reload completion.

Change-Id: Ia3fa4c03f2285a1ec8814bbe7f4624ead9111ad1
---
M main/config.c
1 file changed, 12 insertions(+), 11 deletions(-)

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



diff --git a/main/config.c b/main/config.c
index 38192ed..2a16a34 100644
--- a/main/config.c
+++ b/main/config.c
@@ -3932,8 +3932,8 @@
 static char *handle_cli_config_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct cache_file_mtime *cfmtime;
-	char *prev = "", *completion_value = NULL;
-	int wordlen, which = 0;
+	char *prev = "";
+	int wordlen;
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -3951,19 +3951,20 @@
 
 		AST_LIST_LOCK(&cfmtime_head);
 		AST_LIST_TRAVERSE(&cfmtime_head, cfmtime, list) {
-			/* Skip duplicates - this only works because the list is sorted by filename */
-			if (strcmp(cfmtime->filename, prev) == 0) {
-				continue;
-			}
-
 			/* Core configs cannot be reloaded */
 			if (ast_strlen_zero(cfmtime->who_asked)) {
 				continue;
 			}
 
-			if (++which > a->n && strncmp(cfmtime->filename, a->word, wordlen) == 0) {
-				completion_value = ast_strdup(cfmtime->filename);
-				break;
+			/* Skip duplicates - this only works because the list is sorted by filename */
+			if (!strcmp(cfmtime->filename, prev)) {
+				continue;
+			}
+
+			if (!strncmp(cfmtime->filename, a->word, wordlen)) {
+				if (ast_cli_completion_add(ast_strdup(cfmtime->filename))) {
+					break;
+				}
 			}
 
 			/* Otherwise save that we've seen this filename */
@@ -3971,7 +3972,7 @@
 		}
 		AST_LIST_UNLOCK(&cfmtime_head);
 
-		return completion_value;
+		return NULL;
 	}
 
 	if (a->argc != 3) {

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

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia3fa4c03f2285a1ec8814bbe7f4624ead9111ad1
Gerrit-Change-Number: 8585
Gerrit-PatchSet: 1
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/20180320/a36fdbd7/attachment.html>


More information about the asterisk-code-review mailing list