diff options
Diffstat (limited to 'main/sounds.c')
-rw-r--r-- | main/sounds.c | 66 |
1 files changed, 39 insertions, 27 deletions
diff --git a/main/sounds.c b/main/sounds.c index c792c1bbd..745b62805 100644 --- a/main/sounds.c +++ b/main/sounds.c @@ -34,7 +34,7 @@ #include "asterisk/sounds_index.h" #include "asterisk/file.h" #include "asterisk/cli.h" -#include "asterisk/_private.h" +#include "asterisk/module.h" #include "asterisk/stasis_message_router.h" #include "asterisk/stasis_system.h" @@ -111,7 +111,7 @@ static int update_index_cb(void *obj, void *arg, int flags) AST_MUTEX_DEFINE_STATIC(reload_lock); -int ast_sounds_reindex(void) +static int reload_module(void) { RAII_VAR(struct ast_str *, sounds_dir, NULL, ast_free); RAII_VAR(struct ao2_container *, languages, NULL, ao2_cleanup); @@ -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) { @@ -273,13 +279,15 @@ static struct ast_cli_entry cli_sounds[] = { AST_CLI_DEFINE(handle_cli_sound_show, "Shows details about a specific sound"), }; -static void sounds_cleanup(void) +static int unload_module(void) { stasis_message_router_unsubscribe_and_join(sounds_system_router); sounds_system_router = NULL; ast_cli_unregister_multiple(cli_sounds, ARRAY_LEN(cli_sounds)); ao2_cleanup(sounds_index); sounds_index = NULL; + + return 0; } static void format_update_cb(void *data, struct stasis_subscription *sub, @@ -287,21 +295,21 @@ static void format_update_cb(void *data, struct stasis_subscription *sub, { /* Reindexing during shutdown is pointless. */ if (!ast_shutting_down()) { - ast_sounds_reindex(); + reload_module(); } } -int ast_sounds_index_init(void) +static int load_module(void) { int res = 0; - if (ast_sounds_reindex()) { - return -1; + if (reload_module()) { + return AST_MODULE_LOAD_FAILURE; } res |= ast_cli_register_multiple(cli_sounds, ARRAY_LEN(cli_sounds)); sounds_system_router = stasis_message_router_create(ast_system_topic()); if (!sounds_system_router) { - return -1; + return AST_MODULE_LOAD_FAILURE; } if (ast_format_register_type()) { @@ -320,15 +328,19 @@ int ast_sounds_index_init(void) NULL); } - if (res) { - return -1; - } - - ast_register_cleanup(sounds_cleanup); - return 0; + return res ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS; } struct ast_media_index *ast_sounds_get_index(void) { return ao2_bump(sounds_index); } + +AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Sounds Index", + .support_level = AST_MODULE_SUPPORT_CORE, + .load = load_module, + .unload = unload_module, + .reload = reload_module, + /* Load after the format modules to reduce processing during startup. */ + .load_pri = AST_MODPRI_APP_DEPEND + 1, +); |