Asterisk - The Open Source Telephony Project  21.4.1
Macros | Functions | Variables
sounds.c File Reference

Sound file format and description index. More...

#include "asterisk.h"
#include <dirent.h>
#include <sys/stat.h>
#include "asterisk/utils.h"
#include "asterisk/lock.h"
#include "asterisk/format.h"
#include "asterisk/format_cap.h"
#include "asterisk/paths.h"
#include "asterisk/media_index.h"
#include "asterisk/sounds_index.h"
#include "asterisk/file.h"
#include "asterisk/cli.h"
#include "asterisk/module.h"
#include "asterisk/stasis_message_router.h"
#include "asterisk/stasis_system.h"

Go to the source code of this file.

Macros

#define LANGUAGE_BUCKETS   7
 The number of buckets to be used for storing language-keyed objects.
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
struct ast_media_indexast_sounds_get_index (void)
 Get the sounds index. More...
 
struct ast_media_indexast_sounds_get_index_for_file (const char *filename)
 Get the index for a specific sound file. More...
 
static struct ao2_containerget_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.
 
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.
 
static int load_module (void)
 
static int show_sound_info_cb (void *obj, void *arg, void *data, int flags)
 
static int show_sounds_cb (void *obj, void *arg, int flags)
 
static int sound_sorter (const void *obj_left, const void *obj_right, int flags)
 
static int unload_module (void)
 
static int update_index_cb (void *obj, void *arg, void *data, int flags)
 Callback to process an individual language directory or subdirectory.
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER , .description = "Sounds Index" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "da6642af068ee5e6490c5b1d2cc1d238" , .support_level = AST_MODULE_SUPPORT_CORE, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_APP_DEPEND + 1, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct ast_cli_entry cli_sounds []
 Struct for registering CLI commands. More...
 

Detailed Description

Sound file format and description index.

Definition in file sounds.c.

Function Documentation

struct ast_media_index* ast_sounds_get_index ( void  )

Get the sounds index.

Return values
soundsindex (must be ao2_cleanup()'ed)
NULLon failure

Definition at line 308 of file sounds.c.

References ast_sounds_get_index_for_file().

Referenced by ast_ari_sounds_list(), handle_cli_sound_show(), and handle_cli_sounds_show().

309 {
310  return ast_sounds_get_index_for_file(NULL);
311 }
struct ast_media_index * ast_sounds_get_index_for_file(const char *filename)
Get the index for a specific sound file.
Definition: sounds.c:313
struct ast_media_index* ast_sounds_get_index_for_file ( const char *  filename)

Get the index for a specific sound file.

Since
13.25.0
16.2.0
Parameters
filenameSound file name without extension
Return values
soundsindex (must be ao2_cleanup()'ed)
NULLon failure

Definition at line 313 of file sounds.c.

References ao2_ref, ast_media_index_create(), ast_str_buffer(), ast_str_create, ast_str_set(), get_languages(), and update_index_cb().

Referenced by ast_ari_sounds_get(), ast_sounds_get_index(), and handle_cli_sound_show().

314 {
315  struct ast_str *sounds_dir = ast_str_create(64);
316  struct ao2_container *languages;
317  char *failed_index;
318  struct ast_media_index *new_index;
319 
320  if (!sounds_dir) {
321  return NULL;
322  }
323 
324  ast_str_set(&sounds_dir, 0, "%s/sounds", ast_config_AST_DATA_DIR);
325  new_index = ast_media_index_create(ast_str_buffer(sounds_dir));
326  ast_free(sounds_dir);
327  if (!new_index) {
328  return NULL;
329  }
330 
331  languages = get_languages();
332  if (!languages) {
333  ao2_ref(new_index, -1);
334  return NULL;
335  }
336 
337  failed_index = ao2_callback_data(languages, 0, update_index_cb, new_index, (void *)filename);
338  ao2_ref(languages, -1);
339  if (failed_index) {
340  ao2_ref(failed_index, -1);
341  ao2_ref(new_index, -1);
342  new_index = NULL;
343  }
344 
345  return new_index;
346 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
static int update_index_cb(void *obj, void *arg, void *data, int flags)
Callback to process an individual language directory or subdirectory.
Definition: sounds.c:295
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1113
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
static struct ao2_container * get_languages(void)
Get the languages in which sound files are available.
Definition: sounds.c:49
Support for dynamic strings.
Definition: strings.h:623
struct ast_media_index * ast_media_index_create(const char *base_dir)
Creates a new media index.
Definition: media_index.c:162
Generic container type.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659

Variable Documentation

struct ast_cli_entry cli_sounds[]
static
Initial value:
= {
{ .handler = handle_cli_sounds_show , .summary = "Shows available sounds" ,},
{ .handler = handle_cli_sound_show , .summary = "Shows details about a specific sound" ,},
}
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.
Definition: sounds.c:144
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.
Definition: sounds.c:193

Struct for registering CLI commands.

Definition at line 270 of file sounds.c.