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

George Joseph asteriskteam at digium.com
Tue Mar 20 10:08:44 CDT 2018


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/8582 )

Change subject: main/sounds: Use ast_cli_completion_add.
......................................................................

main/sounds: Use ast_cli_completion_add.

Change-Id: I140e1137906bbfcdb61c0c6304159be459ad873e
---
M main/sounds.c
1 file changed, 19 insertions(+), 13 deletions(-)

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



diff --git a/main/sounds.c b/main/sounds.c
index c792c1b..6fec48e 100644
--- a/main/sounds.c
+++ b/main/sounds.c
@@ -219,6 +219,11 @@
 /*! \brief Show details about a sound available in the system */
 static char *handle_cli_sound_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
+	int length;
+	struct ao2_iterator it_sounds;
+	char *filename;
+	struct ao2_container *sound_files;
+
 	switch (cmd) {
 	case CLI_INIT:
 		e->command = "core show sound";
@@ -227,29 +232,30 @@
 			"       Shows information about the specified sound.\n";
 		return NULL;
 	case CLI_GENERATE:
-	{
-		int length = strlen(a->word);
-		int which = 0;
-		struct ao2_iterator it_sounds;
-		char *match = NULL;
-		char *filename;
-		RAII_VAR(struct ao2_container *, sound_files, ast_media_get_media(sounds_index), ao2_cleanup);
+		if (a->pos != 3) {
+			return NULL;
+		}
+
+		sound_files = ast_media_get_media(sounds_index);
 		if (!sound_files) {
 			return NULL;
 		}
 
+		length = strlen(a->word);
 		it_sounds = ao2_iterator_init(sound_files, 0);
 		while ((filename = ao2_iterator_next(&it_sounds))) {
-			if (!strncasecmp(a->word, filename, length) && ++which > a->n) {
-				match = ast_strdup(filename);
-				ao2_ref(filename, -1);
-				break;
+			if (!strncasecmp(a->word, filename, length)) {
+				if (ast_cli_completion_add(ast_strdup(filename))) {
+					ao2_ref(filename, -1);
+					break;
+				}
 			}
 			ao2_ref(filename, -1);
 		}
 		ao2_iterator_destroy(&it_sounds);
-		return match;
-	}
+		ao2_ref(sound_files, -1);
+
+		return NULL;
 	}
 
 	if (a->argc == 4) {

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

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: merged
Gerrit-Change-Id: I140e1137906bbfcdb61c0c6304159be459ad873e
Gerrit-Change-Number: 8582
Gerrit-PatchSet: 2
Gerrit-Owner: 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/bca61aa8/attachment-0001.html>


More information about the asterisk-code-review mailing list