38 #include "asterisk/stasis_message_router.h"
39 #include "asterisk/stasis_system.h"
46 #define LANGUAGE_BUCKETS 7
58 if (!media_dir || !lang_dirs) {
62 ast_str_set(&media_dir, 0,
"%s/sounds", ast_config_AST_DATA_DIR);
67 ast_log(LOG_ERROR,
"Failed to open %s\n",
ast_str_buffer(media_dir));
71 while((dent = readdir(srcdir)) != NULL) {
74 if(!strcmp(dent->d_name,
".") || !strcmp(dent->d_name,
"..")) {
82 ast_log(LOG_ERROR,
"Failed to stat %s\n",
ast_str_buffer(variant_dir));
86 if (S_ISDIR(st.st_mode)) {
96 static int show_sounds_cb(
void *obj,
void *arg,
int flags)
100 ast_cli(a->fd,
"%s\n", name);
104 static int show_sound_info_cb(
void *obj,
void *arg,
void *data,
int flags)
106 char *language = obj;
109 int formats_shown = 0;
114 ast_cli(a->fd,
" Language %s:\n", language);
115 if (!ast_strlen_zero(description)) {
116 ast_cli(a->fd,
" Description: %s\n", description);
131 if (!formats_shown) {
132 ast_cli(a->fd,
" No Formats Available\n");
138 static int sound_sorter(
const void *obj_left,
const void *obj_right,
int flags)
140 return strcmp(obj_left, obj_right);
148 e->
command =
"core show sounds";
150 "Usage: core show sounds\n"
151 " Shows a listing of sound files available on the system.\n";
177 ao2_cleanup(sound_files);
181 ast_cli(a->fd,
"Available audio files:\n");
189 return CLI_SHOWUSAGE;
203 e->
command =
"core show sound";
205 "Usage: core show sound [soundid]\n"
206 " Shows information about the specified sound.\n";
224 length = strlen(a->word);
226 while ((filename = ao2_iterator_next(&it_sounds))) {
227 if (!strncasecmp(a->word, filename, length)) {
253 ao2_cleanup(variants);
254 ast_cli(a->fd,
"ERROR: File %s not found in index\n", a->argv[3]);
258 ast_cli(a->fd,
"Indexed Information for %s:\n", a->argv[3]);
266 return CLI_SHOWUSAGE;
275 static int unload_module(
void)
282 static int load_module(
void)
298 char *filename = data;
324 ast_str_set(&sounds_dir, 0,
"%s/sounds", ast_config_AST_DATA_DIR);
326 ast_free(sounds_dir);
337 failed_index = ao2_callback_data(languages, 0,
update_index_cb, new_index, (
void *)filename);
348 AST_MODULE_INFO(
ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER,
"Sounds Index",
349 .support_level = AST_MODULE_SUPPORT_CORE,
351 .unload = unload_module,
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
static char * handle_cli_sounds_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Show a list of sounds available on the system.
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
descriptor for a cli entry.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
#define ao2_callback(c, flags, cb_fn, arg)
ao2_callback() is a generic function that applies cb_fn() to all objects in a container, as described below.
static int update_index_cb(void *obj, void *arg, void *data, int flags)
Callback to process an individual language directory or subdirectory.
struct ast_media_index * ast_sounds_get_index_for_file(const char *filename)
Get the index for a specific sound file.
#define ast_str_container_alloc(buckets)
Allocates a hash container for bare strings.
#define ast_cli_register_multiple(e, len)
Register multiple commands.
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
#define ast_strdup(str)
A wrapper for strdup()
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Asterisk file paths, configured in asterisk.conf.
#define LANGUAGE_BUCKETS
The number of buckets to be used for storing language-keyed objects.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
static struct ao2_container * get_languages(void)
Get the languages in which sound files are available.
static char * handle_cli_sound_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Show details about a sound available in the system.
Support for dynamic strings.
Sound file format and description indexer.
int ao2_container_dup(struct ao2_container *dest, struct ao2_container *src, enum search_flags flags)
Copy all object references in the src container into the dest container.
Module has failed to load, may be in an inconsistent state.
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
struct ast_media_index * ast_sounds_get_index(void)
Get the sounds index.
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Standard Command Line Interface.
#define ao2_container_alloc_rbtree(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a red-black tree container.
static struct ast_cli_entry cli_sounds[]
Struct for registering CLI commands.
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
int ast_str_container_add(struct ao2_container *str_container, const char *add)
Adds a string to a string container allocated by ast_str_container_alloc.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.