diff options
author | Jenkins2 <jenkins2@gerrit.asterisk.org> | 2018-03-20 10:09:26 -0500 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2018-03-20 10:09:26 -0500 |
commit | b68dae189da38e262bc483b9e6fe9c787757945a (patch) | |
tree | 2118410d9926f5bd7c0741736c937f70a32e88c9 | |
parent | dc2ce3ce32752ecbb365a33fd89e18460ce84bb8 (diff) | |
parent | 645203a422be470b40a202ae088d3820ab94a2db (diff) |
Merge "main/sounds: Use ast_cli_completion_add."
-rw-r--r-- | main/sounds.c | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/main/sounds.c b/main/sounds.c index 08e29275e..745b62805 100644 --- a/main/sounds.c +++ b/main/sounds.c @@ -219,6 +219,11 @@ static char *handle_cli_sounds_show(struct ast_cli_entry *e, int cmd, struct ast /*! \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 @@ static char *handle_cli_sound_show(struct ast_cli_entry *e, int cmd, struct ast_ " 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) { |