From ebe957c5e905e944ea9ac8b377ef6f1a4db7987b Mon Sep 17 00:00:00 2001
From: Corey Farrell <git@cfware.com>
Date: Thu, 15 Mar 2018 10:32:37 -0400
Subject: [PATCH] main/cdr: Use ast_cli_completion_add for CDR channel
 completion.

Change-Id: Ie81830647a23aad61c1162583b6d50adbe6e7822
---
 main/cdr.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/main/cdr.c b/main/cdr.c
index 4acadf975f..b0a48e1d6a 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -3950,18 +3950,14 @@ static char *handle_cli_debug(struct ast_cli_entry *e, int cmd, struct ast_cli_a
 /*! \brief Complete user input for 'cdr show' */
 static char *cli_complete_show(struct ast_cli_args *a)
 {
-	char *result = NULL;
 	int wordlen = strlen(a->word);
-	int which = 0;
 	struct ao2_iterator it_cdrs;
 	struct cdr_object *cdr;
 
 	it_cdrs = ao2_iterator_init(active_cdrs_master, 0);
 	while ((cdr = ao2_iterator_next(&it_cdrs))) {
-		if (!strncasecmp(a->word, cdr->party_a.snapshot->name, wordlen) &&
-			(++which > a->n)) {
-			result = ast_strdup(cdr->party_a.snapshot->name);
-			if (result) {
+		if (!strncasecmp(a->word, cdr->party_a.snapshot->name, wordlen)) {
+			if (ast_cli_completion_add(ast_strdup(cdr->party_a.snapshot->name))) {
 				ao2_ref(cdr, -1);
 				break;
 			}
@@ -3969,7 +3965,8 @@ static char *cli_complete_show(struct ast_cli_args *a)
 		ao2_ref(cdr, -1);
 	}
 	ao2_iterator_destroy(&it_cdrs);
-	return result;
+
+	return NULL;
 }
 
 static void cli_show_channels(struct ast_cli_args *a)
-- 
GitLab