49 #define DATA_EXPORT_TONE_ZONE(MEMBER) \
50 MEMBER(ast_tone_zone, country, AST_DATA_STRING) \
51 MEMBER(ast_tone_zone, description, AST_DATA_STRING) \
52 MEMBER(ast_tone_zone, nrringcadence, AST_DATA_UNSIGNED_INTEGER)
56 #define DATA_EXPORT_TONE_ZONE_SOUND(MEMBER) \
57 MEMBER(ast_tone_zone_sound, name, AST_DATA_STRING) \
58 MEMBER(ast_tone_zone_sound, data, AST_DATA_STRING)
63 static const char config[] =
"indications.conf";
66 8, 8, 9, 9, 10, 10, 11, 12, 12, 13,
67 14, 15, 16, 17, 18, 19, 20, 21, 23, 24,
68 25, 27, 29, 30, 32, 34, 36, 38, 41, 43,
69 46, 48, 51, 55, 58, 61, 65, 69, 73, 77,
70 82, 87, 92, 97, 103, 110, 116, 123, 130, 138,
71 146, 155, 164, 174, 184, 195, 207, 220, 233, 246,
72 261, 277, 293, 311, 329, 349, 369, 391, 415, 440,
73 466, 493, 523, 554, 587, 622, 659, 698, 739, 783,
74 830, 880, 932, 987, 1046, 1108, 1174, 1244, 1318, 1396,
75 1479, 1567, 1661, 1760, 1864, 1975, 2093, 2217, 2349, 2489,
76 2637, 2793, 2959, 3135, 3322, 3520, 3729, 3951, 4186, 4434,
77 4698, 4978, 5274, 5587, 5919, 6271, 6644, 7040, 7458, 7902,
78 8372, 8869, 9397, 9956, 10548, 11175, 11839, 12543
83 #define NUM_TONE_ZONE_BUCKETS 53
188 if (len >
sizeof(ps->
data) / 2 - 1) {
193 memset(&ps->
f, 0,
sizeof(ps->
f));
208 for (x = 0; x < samples; x++) {
218 p = ps->
v3_2 - 32768;
222 p = ((p * 9) / 10) + 1;
264 if (sscanf(s,
"%30u+%30u/%30u", &tone_data->
freq1, &tone_data->
freq2,
265 &tone_data->
time) == 3) {
267 }
else if (sscanf(s,
"%30u+%30u", &tone_data->
freq1, &tone_data->
freq2) == 2) {
270 }
else if (sscanf(s,
"%30u*%30u/%30u", &tone_data->
freq1, &tone_data->
freq2,
271 &tone_data->
time) == 3) {
274 }
else if (sscanf(s,
"%30u*%30u", &tone_data->
freq1, &tone_data->
freq2) == 2) {
278 }
else if (sscanf(s,
"%30u/%30u", &tone_data->
freq1, &tone_data->
time) == 2) {
280 tone_data->
freq2 = 0;
281 }
else if (sscanf(s,
"%30u", &tone_data->
freq1) == 1) {
283 tone_data->
freq2 = 0;
285 }
else if (sscanf(s,
"M%30u+M%30u/%30u", &tone_data->
freq1, &tone_data->
freq2,
286 &tone_data->
time) == 3) {
289 }
else if (sscanf(s,
"M%30u+M%30u", &tone_data->
freq1, &tone_data->
freq2) == 2) {
293 }
else if (sscanf(s,
"M%30u*M%30u/%30u", &tone_data->
freq1, &tone_data->
freq2,
294 &tone_data->
time) == 3) {
298 }
else if (sscanf(s,
"M%30u*M%30u", &tone_data->
freq1, &tone_data->
freq2) == 2) {
303 }
else if (sscanf(s,
"M%30u/%30u", &tone_data->
freq1, &tone_data->
time) == 2) {
305 tone_data->
freq2 = -1;
307 }
else if (sscanf(s,
"M%30u", &tone_data->
freq1) == 1) {
309 tone_data->
freq2 = -1;
325 static const float sample_rate = 8000.0;
326 static const float max_sample_val = 32768.0;
337 if (strchr(stringp,
'|')) {
352 }
else if (d.
reppos == -1) {
364 if (tone_data.
freq1 >= 0 && tone_data.
freq1 <= 127) {
370 if (tone_data.
freq2 >= 0 && tone_data.
freq2 <= 127) {
436 ast_verb(3,
"Setting default indication country to '%s'\n", country);
439 if (default_tone_zone) {
460 if (default_tone_zone) {
482 if (default_tone_zone) {
496 if (!strcasecmp(ts->
name, indication)) {
544 if (!default_tone_zone) {
573 if (default_tone_zone == tz) {
576 default_tone_zone =
ao2_callback(ast_tone_zones, 0, NULL, NULL);
589 const char *tonelist)
598 if (!strcasecmp(indication, ts->
name)) {
629 if (!strcasecmp(indication, ts->
name)) {
656 wordlen = strlen(a->
word);
660 if (!strncasecmp(a->
word, tz->
country, wordlen) && ++which > a->
n) {
676 int created_country = 0;
683 "Usage: indication add <country> <indication> \"<tonelist>\"\n"
684 " Add the given indication to the country.\n";
721 if (created_country) {
750 wordlen = strlen(a->
word);
754 if (!strncasecmp(a->
word, ts->
name, wordlen) && ++which > a->
n) {
773 e->
command =
"indication remove";
775 "Usage: indication remove <country> [indication]\n"
776 " Remove the given indication from the country.\n";
781 }
else if (a->
pos == 3) {
819 int found_country = 0;
824 e->
command =
"indication show";
826 "Usage: indication show [<country> ...]\n"
827 " Display either a condensed summary of all countries and indications, or a\n"
828 " more verbose list of indications for the specified countries.\n";
838 ast_cli(a->
fd,
"===========================\n");
852 for (i = 2; i < a->
argc; i++) {
865 if (!found_country) {
867 ast_cli(a->
fd,
"Country Indication PlayList\n");
868 ast_cli(a->
fd,
"=====================================\n");
889 if (!found_country) {
890 ast_cli(a->
fd,
"No countries matched your criteria.\n");
913 char *ring, *c = buf;
917 while ((ring =
strsep(&c,
","))) {
922 if (!isdigit(ring[0]) || (val = atoi(ring)) == -1) {
1055 const char *cxt = NULL;
1077 if (!strcasecmp(cxt,
"general")) {
1082 goto return_cleanup;
1139 if (!data_zone_sound) {
1158 if (default_tone_zone) {
1160 default_tone_zone = NULL;
1162 if (ast_tone_zones) {
1164 ast_tone_zones = NULL;
int ast_indications_init(void)
Load indications module.
union ast_frame_subclass subclass
Main Channel structure associated with a channel.
#define AST_CLI_DEFINE(fn, txt,...)
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
#define ao2_link(arg1, arg2)
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
const char * ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable)
Gets a variable.
char description[40]
Text description of the given country.
The data tree to be returned by the callbacks and managed by functions local to this file...
static char * handle_cli_indication_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
char * strsep(char **str, const char *delims)
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
struct ast_tone_zone_sound::@176 entry
Linked list fields for including in the list on an ast_tone_zone.
static char * complete_country(struct ast_cli_args *a)
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
unsigned char offset[AST_FRIENDLY_OFFSET]
static struct ast_tone_zone * default_tone_zone
static char * handle_cli_indication_add(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
#define CV_STR(__x, __dst)
int ast_indications_reload(void)
Reload indications module.
#define ao2_iterator_next(arg1)
#define ast_set_flag(p, flag)
descriptor for a cli entry.
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
#define ast_tone_zone_unlock(tz)
Unlock an ast_tone_zone.
static struct ao2_container * ast_tone_zones
#define ao2_callback(c, flags, cb_fn, arg)
A description of a part of a tone.
Structure for variables, used for configurations and for channel variables.
static int ast_tone_zone_cmp(void *obj, void *arg, int flags)
static int prune_tone_zone(void *obj, void *arg, int flags)
struct ast_tone_zone::@181 tones
A list of tones for this locale.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
static char * complete_indications(struct ast_cli_args *a)
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
static int ast_unregister_indication(struct ast_tone_zone *zone, const char *indication)
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags)
Create an iterator for a container.
#define ast_str_alloca(init_len)
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
static void reset_tone_zone(struct ast_tone_zone *zone)
void ast_cli(int fd, const char *fmt,...)
static struct ast_generator playtones
static int ast_register_indication(struct ast_tone_zone *zone, const char *indication, const char *tonelist)
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
#define ast_verb(level,...)
void ast_config_destroy(struct ast_config *config)
Destroys a config.
static struct ast_tone_zone * ast_tone_zone_alloc(void)
static int tone_zone_mark(void *obj, void *arg, int flags)
#define CONFIG_STATUS_FILEMISSING
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
int ast_set_write_format(struct ast_channel *chan, format_t format)
Sets write format on channel chan Set write format for channel to whichever component of "format" is ...
static int is_valid_tone_zone(struct ast_tone_zone *zone)
static int ast_register_indication_country(struct ast_tone_zone *zone)
#define CV_END
close a variable parsing block
#define DATA_EXPORT_TONE_ZONE(MEMBER)
General Asterisk PBX channel definitions.
#define CV_START(__in_var, __in_val)
the macro to open a block for variable parsing
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
A set of tones for a given locale.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Asterisk internal frame definitions.
struct ast_data * ast_data_add_node(struct ast_data *root, const char *childname)
Add a container child.
int ast_tone_zone_count(void)
Get the number of registered tone zones.
static void ast_tone_zone_destructor(void *obj)
deallocate the passed tone zone
struct playtones_item * items
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
static struct ast_cli_entry cli_indications[]
CLI entries for commands provided by this module.
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
#define ao2_ref(o, delta)
char * ast_category_browse(struct ast_config *config, const char *prev)
Goes through categories.
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
static struct ast_tone_zone_sound * ast_tone_zone_sound_unref(struct ast_tone_zone_sound *ts)
Release a reference to an ast_tone_zone_sound.
A set of macros to manage forward-linked lists.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
static void store_config_tone_zone(struct ast_tone_zone *zone, const char *var, const char *value)
const char * name
Name of the tone. For example, "busy".
#define ast_data_add_structure(structure_name, root, structure)
#define ast_strdupa(s)
duplicate a string in memory from the stack
int ast_tone_zone_data_add_structure(struct ast_data *tree, struct ast_tone_zone *zone)
Add a tone_zone structure to the data tree specified.
static int playtones_generator(struct ast_channel *chan, void *data, int len, int samples)
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
#define DATA_EXPORT_TONE_ZONE_SOUND(MEMBER)
struct ast_tone_zone * ast_get_indication_zone(const char *country)
locate ast_tone_zone
static struct ast_tone_zone_sound * ast_tone_zone_sound_ref(struct ast_tone_zone_sound *ts)
Increase the reference count on an ast_tone_zone_sound.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
struct ast_tone_zone_sound * ast_get_indication_tone(const struct ast_tone_zone *zone, const char *indication)
Locate a tone zone sound.
const ast_string_field name
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
static struct ast_tone_zone * ast_tone_zone_ref(struct ast_tone_zone *tz)
Increase the reference count on an ast_tone_zone.
#define ao2_alloc(data_size, destructor_fn)
#define NUM_TONE_ZONE_BUCKETS
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define ao2_find(arg1, arg2, arg3)
void *(* alloc)(struct ast_channel *chan, void *params)
static void * playtones_alloc(struct ast_channel *chan, void *params)
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Prototypes for public functions only of internal interest,.
struct playtones_item * items
static int ast_tone_zone_hash(const void *obj, const int flags)
char country[16]
Country code that this set of tones is for.
void ao2_iterator_destroy(struct ao2_iterator *i)
Destroy a container iterator.
Structure used to handle boolean flags.
#define ast_clear_flag(p, flag)
int * ringcadence
Array of ring cadence parts.
static int load_indications(int reload)
load indications module
#define CV_F(__pattern, __body)
call a generic function if the name matches.
void ast_deactivate_generator(struct ast_channel *chan)
static void indications_shutdown(void)
static int parse_tone_zone(struct ast_config *cfg, const char *country)
#define AST_FORMAT_SLINEAR
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
static int ast_set_indication_country(const char *country)
Standard Command Line Interface.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#define ao2_container_alloc(arg1, arg2, arg3)
unsigned int nrringcadence
Number of ring cadence elements in the ringcadence array.
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
struct ao2_iterator ast_tone_zone_iterator_init(void)
Get an iterator for the available tone zones.
#define ast_realloc(a, b)
Data structure associated with a single frame of data.
#define AST_DATA_STRUCTURE(__struct, __name)
static void ast_tone_zone_sound_destructor(void *obj)
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
static const char config[]
const char * data
Description of a tone.
#define ast_tone_zone_lock(tz)
Lock an ast_tone_zone.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
enum ast_frame_type frametype
struct ast_variable * next
#define CONFIG_STATUS_FILEINVALID
static void store_tone_zone_ring_cadence(struct ast_tone_zone *zone, const char *val)
Asterisk module definitions.
union ast_frame::@172 data
static const int midi_tohz[128]
static void playtones_release(struct ast_channel *chan, void *params)
static char * handle_cli_indication_remove(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
static int ast_unregister_indication_country(const char *country)
int ast_tone_zone_part_parse(const char *s, struct ast_tone_zone_part *tone_data)
Parse a tone part.
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
#define CONFIG_STATUS_FILEUNCHANGED