Wed Jan 8 2020 09:50:13

Asterisk developer's documentation


indications.c File Reference

Indication Tone Handling. More...

#include "asterisk.h"
#include <math.h>
#include "asterisk/lock.h"
#include "asterisk/linkedlists.h"
#include "asterisk/indications.h"
#include "asterisk/frame.h"
#include "asterisk/channel.h"
#include "asterisk/utils.h"
#include "asterisk/cli.h"
#include "asterisk/module.h"
#include "asterisk/astobj2.h"
#include "asterisk/data.h"
#include "asterisk/_private.h"

Go to the source code of this file.

Data Structures

struct  playtones_def
 
struct  playtones_item
 
struct  playtones_state
 

Macros

#define DATA_EXPORT_TONE_ZONE(MEMBER)
 
#define DATA_EXPORT_TONE_ZONE_SOUND(MEMBER)
 
#define NUM_TONE_ZONE_BUCKETS   53
 

Functions

 AST_DATA_STRUCTURE (ast_tone_zone, DATA_EXPORT_TONE_ZONE)
 
 AST_DATA_STRUCTURE (ast_tone_zone_sound, DATA_EXPORT_TONE_ZONE_SOUND)
 
struct ast_tone_zone_soundast_get_indication_tone (const struct ast_tone_zone *_zone, const char *indication)
 Locate a tone zone sound. More...
 
struct ast_tone_zoneast_get_indication_zone (const char *country)
 locate ast_tone_zone More...
 
int ast_indications_init (void)
 Load indications module. More...
 
int ast_indications_reload (void)
 Reload indications module. More...
 
int ast_playtones_start (struct ast_channel *chan, int vol, const char *playlst, int interruptible)
 Start playing a list of tones on a channel. More...
 
void ast_playtones_stop (struct ast_channel *chan)
 Stop playing tones on a channel. More...
 
static int ast_register_indication (struct ast_tone_zone *zone, const char *indication, const char *tonelist)
 
static int ast_register_indication_country (struct ast_tone_zone *zone)
 
static int ast_set_indication_country (const char *country)
 
static struct ast_tone_zoneast_tone_zone_alloc (void)
 
static int ast_tone_zone_cmp (void *obj, void *arg, int flags)
 
int ast_tone_zone_count (void)
 Get the number of registered tone zones. More...
 
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. More...
 
static void ast_tone_zone_destructor (void *obj)
 deallocate the passed tone zone More...
 
static int ast_tone_zone_hash (const void *obj, const int flags)
 
struct ao2_iterator ast_tone_zone_iterator_init (void)
 Get an iterator for the available tone zones. More...
 
int ast_tone_zone_part_parse (const char *s, struct ast_tone_zone_part *tone_data)
 Parse a tone part. More...
 
static void ast_tone_zone_sound_destructor (void *obj)
 
static int ast_unregister_indication (struct ast_tone_zone *zone, const char *indication)
 
static int ast_unregister_indication_country (const char *country)
 
static char * complete_country (struct ast_cli_args *a)
 
static char * complete_indications (struct ast_cli_args *a)
 
static char * handle_cli_indication_add (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_cli_indication_remove (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static char * handle_cli_indication_show (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 
static void indications_shutdown (void)
 
static int is_valid_tone_zone (struct ast_tone_zone *zone)
 
static int load_indications (int reload)
 load indications module More...
 
static int parse_tone_zone (struct ast_config *cfg, const char *country)
 
static void * playtones_alloc (struct ast_channel *chan, void *params)
 
static int playtones_generator (struct ast_channel *chan, void *data, int len, int samples)
 
static void playtones_release (struct ast_channel *chan, void *params)
 
static int prune_tone_zone (void *obj, void *arg, int flags)
 
static void reset_tone_zone (struct ast_tone_zone *zone)
 
static void store_config_tone_zone (struct ast_tone_zone *zone, const char *var, const char *value)
 
static void store_tone_zone_ring_cadence (struct ast_tone_zone *zone, const char *val)
 
static int tone_zone_mark (void *obj, void *arg, int flags)
 

Variables

static struct ao2_containerast_tone_zones
 
static struct ast_cli_entry cli_indications []
 CLI entries for commands provided by this module. More...
 
static const char config [] = "indications.conf"
 
static struct ast_tone_zonedefault_tone_zone
 
static const int midi_tohz [128]
 
static struct ast_generator playtones
 

Detailed Description

Indication Tone Handling.

Author
Pauline Middelink midde.nosp@m.link.nosp@m.@poly.nosp@m.ware.nosp@m..nl
Russell Bryant russe.nosp@m.ll@d.nosp@m.igium.nosp@m..com

Definition in file indications.c.

Macro Definition Documentation

#define DATA_EXPORT_TONE_ZONE (   MEMBER)
Value:
MEMBER(ast_tone_zone, description, AST_DATA_STRING) \
MEMBER(ast_tone_zone, nrringcadence, AST_DATA_UNSIGNED_INTEGER)
A set of tones for a given locale.
Definition: indications.h:73
static char country[80]
Definition: pbx_dundi.c:196

Definition at line 49 of file indications.c.

#define DATA_EXPORT_TONE_ZONE_SOUND (   MEMBER)
Value:
Description of a tone.
Definition: indications.h:36
static const char name[]
union ast_frame::@172 data

Definition at line 56 of file indications.c.

#define NUM_TONE_ZONE_BUCKETS   53

Definition at line 83 of file indications.c.

Referenced by ast_indications_init().

Function Documentation

AST_DATA_STRUCTURE ( ast_tone_zone  ,
DATA_EXPORT_TONE_ZONE   
)
AST_DATA_STRUCTURE ( ast_tone_zone_sound  ,
DATA_EXPORT_TONE_ZONE_SOUND   
)
struct ast_tone_zone_sound* ast_get_indication_tone ( const struct ast_tone_zone zone,
const char *  indication 
)

Locate a tone zone sound.

Parameters
zoneZone to look in for a sound, if NULL, the default will be used
indicationSound to look for, such as "busy"
Returns
a reference to the specified sound if it exists, NULL if not

Definition at line 473 of file indications.c.

References ao2_lock, ao2_unlock, AST_LIST_TRAVERSE, ast_tone_zone_lock, ast_tone_zone_ref(), ast_tone_zone_sound_ref(), ast_tone_zone_unlock, ast_tone_zone_sound::name, and ast_tone_zone::tones.

Referenced by ast_app_dtget(), ast_indicate_data(), dial_handle_playtones(), dialtone_indicate(), handle_playtones(), in_band_indication(), pbx_builtin_waitexten(), play_dialtone(), read_exec(), readexten_exec(), and skinny_transfer().

474 {
475  struct ast_tone_zone_sound *ts = NULL;
476  /* _zone is const to the users of the API */
477  struct ast_tone_zone *zone = (struct ast_tone_zone *) _zone;
478 
479  /* If no zone is specified, use the default */
480  if (!zone) {
482  if (default_tone_zone) {
484  }
486 
487  if (!zone) {
488  return NULL;
489  }
490  }
491 
492  ast_tone_zone_lock(zone);
493 
494  /* Look through list of tones in the zone searching for the right one */
495  AST_LIST_TRAVERSE(&zone->tones, ts, entry) {
496  if (!strcasecmp(ts->name, indication)) {
497  /* Increase ref count for the reference we will return */
498  ts = ast_tone_zone_sound_ref(ts);
499  break;
500  }
501  }
502 
503  ast_tone_zone_unlock(zone);
504 
505  return ts;
506 }
static struct ast_tone_zone * default_tone_zone
Definition: indications.c:88
#define ast_tone_zone_unlock(tz)
Unlock an ast_tone_zone.
Definition: indications.h:192
static struct ao2_container * ast_tone_zones
Definition: indications.c:81
struct ast_tone_zone::@181 tones
A list of tones for this locale.
#define ao2_unlock(a)
Definition: astobj2.h:497
A set of tones for a given locale.
Definition: indications.h:73
#define ao2_lock(a)
Definition: astobj2.h:488
const char * name
Name of the tone. For example, &quot;busy&quot;.
Definition: indications.h:38
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.
Definition: indications.h:237
Description of a tone.
Definition: indications.h:36
static struct ast_tone_zone * ast_tone_zone_ref(struct ast_tone_zone *tz)
Increase the reference count on an ast_tone_zone.
Definition: indications.h:215
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_tone_zone_lock(tz)
Lock an ast_tone_zone.
Definition: indications.h:187
struct ast_tone_zone* ast_get_indication_zone ( const char *  country)

locate ast_tone_zone

Parameters
countrycountry to find. If NULL is provided, get the default.
Returns
a reference to the specified country if found or NULL if not found

Definition at line 451 of file indications.c.

References ao2_find, ao2_lock, ao2_unlock, ast_copy_string(), ast_strlen_zero(), ast_tone_zone_ref(), ast_tone_zone::country, ast_tone_zone::nrringcadence, OBJ_POINTER, and tz.

Referenced by ast_set_indication_country(), ast_var_indications(), build_device(), func_channel_write_real(), handle_cli_indication_add(), and handle_cli_indication_remove().

452 {
453  struct ast_tone_zone *tz = NULL;
454  struct ast_tone_zone zone_arg = {
455  .nrringcadence = 0,
456  };
457 
458  if (ast_strlen_zero(country)) {
460  if (default_tone_zone) {
462  }
464 
465  return tz;
466  }
467 
468  ast_copy_string(zone_arg.country, country, sizeof(zone_arg.country));
469 
470  return ao2_find(ast_tone_zones, &zone_arg, OBJ_POINTER);
471 }
static struct ast_tone_zone * default_tone_zone
Definition: indications.c:88
static struct ao2_container * ast_tone_zones
Definition: indications.c:81
#define ao2_unlock(a)
Definition: astobj2.h:497
static char * tz
Definition: cdr_pgsql.c:56
A set of tones for a given locale.
Definition: indications.h:73
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ao2_lock(a)
Definition: astobj2.h:488
static char country[80]
Definition: pbx_dundi.c:196
static struct ast_tone_zone * ast_tone_zone_ref(struct ast_tone_zone *tz)
Increase the reference count on an ast_tone_zone.
Definition: indications.h:215
#define ao2_find(arg1, arg2, arg3)
Definition: astobj2.h:964
char country[16]
Country code that this set of tones is for.
Definition: indications.h:75
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
unsigned int nrringcadence
Number of ring cadence elements in the ringcadence array.
Definition: indications.h:83
int ast_indications_init ( void  )

Load indications module.

Provided by indications.c

Definition at line 1169 of file indications.c.

References ao2_container_alloc, ARRAY_LEN, ast_cli_register_multiple(), ast_register_atexit(), ast_tone_zone_cmp(), ast_tone_zone_hash(), indications_shutdown(), load_indications(), and NUM_TONE_ZONE_BUCKETS.

Referenced by main().

1170 {
1173  return -1;
1174  }
1175 
1176  if (load_indications(0)) {
1178  return -1;
1179  }
1180 
1182 
1184  return 0;
1185 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct ao2_container * ast_tone_zones
Definition: indications.c:81
static int ast_tone_zone_cmp(void *obj, void *arg, int flags)
Definition: indications.c:1118
static struct ast_cli_entry cli_indications[]
CLI entries for commands provided by this module.
Definition: indications.c:1105
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
Definition: asterisk.c:998
#define NUM_TONE_ZONE_BUCKETS
Definition: indications.c:83
static int ast_tone_zone_hash(const void *obj, const int flags)
Definition: indications.c:1111
static int load_indications(int reload)
load indications module
Definition: indications.c:1052
static void indications_shutdown(void)
Definition: indications.c:1155
#define ao2_container_alloc(arg1, arg2, arg3)
Definition: astobj2.h:734
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
Definition: cli.c:2167
int ast_indications_reload ( void  )

Reload indications module.

Provided by indications.c

Definition at line 1188 of file indications.c.

References load_indications().

1189 {
1190  return load_indications(1);
1191 }
static int load_indications(int reload)
load indications module
Definition: indications.c:1052
int ast_playtones_start ( struct ast_channel chan,
int  vol,
const char *  tonelist,
int  interruptible 
)

Start playing a list of tones on a channel.

Parameters
chanthe channel to play tones on
volvolume
tonelistthe list of tones to play, comma separated
interruptiblewhether or not this tone can be interrupted
Return values
0success
non-zerofailure

Definition at line 319 of file indications.c.

References ast_activate_generator(), ast_free, ast_log(), ast_realloc, ast_strdupa, ast_strip(), ast_strlen_zero(), ast_tone_zone_part_parse(), cos, playtones_item::duration, playtones_item::fac1, playtones_item::fac2, ast_tone_zone_part::freq1, ast_tone_zone_part::freq2, playtones_item::init_v2_1, playtones_item::init_v2_2, playtones_item::init_v3_1, playtones_item::init_v3_2, playtones_def::interruptible, playtones_def::items, LOG_ERROR, M_PI, ast_tone_zone_part::midinote, playtones_item::modulate, ast_tone_zone_part::modulate, playtones_def::nitems, playtones_def::reppos, strsep(), ast_tone_zone_part::time, and playtones_def::vol.

Referenced by ast_app_dtget(), ast_indicate_data(), ast_senddigit_begin(), dial_handle_playtones(), dialtone_indicate(), handle_playtones(), in_band_indication(), milliwatt_exec(), pbx_builtin_waitexten(), play_dialtone(), playtone(), read_exec(), readexten_exec(), receivefax_t38_init(), send_digit_to_chan(), sendfax_t38_init(), and skinny_transfer().

320 {
321  char *s, *data = ast_strdupa(playlst);
322  struct playtones_def d = { vol, -1, 0, 1, NULL };
323  char *stringp;
324  char *separator;
325  static const float sample_rate = 8000.0;
326  static const float max_sample_val = 32768.0;
327 
328  if (vol < 1) {
329  d.vol = 7219; /* Default to -8db */
330  }
331 
333 
334  stringp = data;
335 
336  /* check if the data is separated with '|' or with ',' by default */
337  if (strchr(stringp,'|')) {
338  separator = "|";
339  } else {
340  separator = ",";
341  }
342 
343  while ((s = strsep(&stringp, separator)) && !ast_strlen_zero(s)) {
344  struct playtones_item *new_items;
345  struct ast_tone_zone_part tone_data = {
346  .time = 0,
347  };
348 
349  s = ast_strip(s);
350  if (s[0]=='!') {
351  s++;
352  } else if (d.reppos == -1) {
353  d.reppos = d.nitems;
354  }
355 
356  if (ast_tone_zone_part_parse(s, &tone_data)) {
357  ast_log(LOG_ERROR, "Failed to parse tone part '%s'\n", s);
358  continue;
359  }
360 
361  if (tone_data.midinote) {
362  /* midi notes must be between 0 and 127 */
363 
364  if (tone_data.freq1 >= 0 && tone_data.freq1 <= 127) {
365  tone_data.freq1 = midi_tohz[tone_data.freq1];
366  } else {
367  tone_data.freq1 = 0;
368  }
369 
370  if (tone_data.freq2 >= 0 && tone_data.freq2 <= 127) {
371  tone_data.freq2 = midi_tohz[tone_data.freq2];
372  } else {
373  tone_data.freq2 = 0;
374  }
375  }
376 
377  new_items = ast_realloc(d.items, (d.nitems + 1) * sizeof(*d.items));
378  if (!new_items) {
379  ast_free(d.items);
380  return -1;
381  }
382  d.items = new_items;
383 
384  d.items[d.nitems].fac1 = 2.0 * cos(2.0 * M_PI * (tone_data.freq1 / sample_rate)) * max_sample_val;
385  d.items[d.nitems].init_v2_1 = sin(-4.0 * M_PI * (tone_data.freq1 / sample_rate)) * d.vol;
386  d.items[d.nitems].init_v3_1 = sin(-2.0 * M_PI * (tone_data.freq1 / sample_rate)) * d.vol;
387 
388  d.items[d.nitems].fac2 = 2.0 * cos(2.0 * M_PI * (tone_data.freq2 / sample_rate)) * max_sample_val;
389  d.items[d.nitems].init_v2_2 = sin(-4.0 * M_PI * (tone_data.freq2 / sample_rate)) * d.vol;
390  d.items[d.nitems].init_v3_2 = sin(-2.0 * M_PI * (tone_data.freq2 / sample_rate)) * d.vol;
391 
392  d.items[d.nitems].duration = tone_data.time;
393  d.items[d.nitems].modulate = tone_data.modulate;
394 
395  d.nitems++;
396  }
397 
398  if (!d.nitems) {
399  ast_log(LOG_ERROR, "No valid tone parts\n");
400  return -1;
401  }
402 
403  if (ast_activate_generator(chan, &playtones, &d)) {
404  ast_free(d.items);
405  return -1;
406  }
407 
408  return 0;
409 }
char * strsep(char **str, const char *delims)
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
Definition: channel.c:3148
A description of a part of a tone.
Definition: indications.h:108
unsigned int midinote
Definition: indications.h:113
static struct ast_generator playtones
Definition: indications.c:256
unsigned int freq1
Definition: indications.h:109
#define M_PI
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:155
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
#define LOG_ERROR
Definition: logger.h:155
unsigned int time
Definition: indications.h:111
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...
Definition: logger.c:1207
#define ast_free(a)
Definition: astmm.h:97
struct playtones_item * items
Definition: indications.c:106
unsigned int modulate
Definition: indications.h:112
#define ast_realloc(a, b)
Definition: astmm.h:103
unsigned int freq2
Definition: indications.h:110
static unsigned int cos
Definition: chan_h323.c:147
static const int midi_tohz[128]
Definition: indications.c:65
int ast_tone_zone_part_parse(const char *s, struct ast_tone_zone_part *tone_data)
Parse a tone part.
Definition: indications.c:262
void ast_playtones_stop ( struct ast_channel chan)

Stop playing tones on a channel.

Parameters
chanthe channel to stop tones on

Definition at line 411 of file indications.c.

References ast_deactivate_generator().

Referenced by ast_app_dtget(), ast_indicate_data(), ast_senddigit_end(), disa_exec(), handle_stopplaytones(), pbx_builtin_waitexten(), playtone(), read_exec(), readexten_exec(), receivefax_t38_init(), sendfax_t38_init(), stop_indicate(), and unistim_indicate().

412 {
414 }
void ast_deactivate_generator(struct ast_channel *chan)
Definition: channel.c:3107
static int ast_register_indication ( struct ast_tone_zone zone,
const char *  indication,
const char *  tonelist 
)
static
Note
called with the tone zone locked

Definition at line 588 of file indications.c.

References ao2_alloc, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_strdup, ast_strlen_zero(), ast_tone_zone_sound_destructor(), ast_tone_zone_sound_unref(), ast_tone_zone_sound::data, ast_tone_zone_sound::entry, ast_tone_zone_sound::name, and ast_tone_zone::tones.

Referenced by handle_cli_indication_add(), and store_config_tone_zone().

590 {
591  struct ast_tone_zone_sound *ts;
592 
593  if (ast_strlen_zero(indication) || ast_strlen_zero(tonelist)) {
594  return -1;
595  }
596 
598  if (!strcasecmp(indication, ts->name)) {
600  ts = ast_tone_zone_sound_unref(ts);
601  break;
602  }
603  }
605 
606  if (!(ts = ao2_alloc(sizeof(*ts), ast_tone_zone_sound_destructor))) {
607  return -1;
608  }
609 
610  if (!(ts->name = ast_strdup(indication)) || !(ts->data = ast_strdup(tonelist))) {
611  ts = ast_tone_zone_sound_unref(ts);
612  return -1;
613  }
614 
615  AST_LIST_INSERT_TAIL(&zone->tones, ts, entry); /* Inherit reference */
616 
617  return 0;
618 }
struct ast_tone_zone_sound::@176 entry
Linked list fields for including in the list on an ast_tone_zone.
#define ast_strdup(a)
Definition: astmm.h:109
struct ast_tone_zone::@181 tones
A list of tones for this locale.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:600
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:554
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.
Definition: indications.h:226
const char * name
Name of the tone. For example, &quot;busy&quot;.
Definition: indications.h:38
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:716
Description of a tone.
Definition: indications.h:36
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:430
static void ast_tone_zone_sound_destructor(void *obj)
Definition: indications.c:508
const char * data
Description of a tone.
Definition: indications.h:53
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
static int ast_register_indication_country ( struct ast_tone_zone zone)
static

Definition at line 541 of file indications.c.

References ao2_link, ao2_lock, ao2_unlock, ast_tone_zone_ref(), ast_verb, and ast_tone_zone::country.

Referenced by handle_cli_indication_add(), and parse_tone_zone().

542 {
544  if (!default_tone_zone) {
546  }
548 
549  ao2_link(ast_tone_zones, zone);
550 
551  ast_verb(3, "Registered indication country '%s'\n", zone->country);
552 
553  return 0;
554 }
#define ao2_link(arg1, arg2)
Definition: astobj2.h:785
static struct ast_tone_zone * default_tone_zone
Definition: indications.c:88
static struct ao2_container * ast_tone_zones
Definition: indications.c:81
#define ao2_unlock(a)
Definition: astobj2.h:497
#define ast_verb(level,...)
Definition: logger.h:243
#define ao2_lock(a)
Definition: astobj2.h:488
static struct ast_tone_zone * ast_tone_zone_ref(struct ast_tone_zone *tz)
Increase the reference count on an ast_tone_zone.
Definition: indications.h:215
char country[16]
Country code that this set of tones is for.
Definition: indications.h:75
static int ast_set_indication_country ( const char *  country)
static

Definition at line 427 of file indications.c.

References ao2_lock, ao2_unlock, ast_get_indication_zone(), ast_strlen_zero(), ast_tone_zone_ref(), ast_tone_zone_unref(), and ast_verb.

Referenced by load_indications().

428 {
429  struct ast_tone_zone *zone = NULL;
430 
431  /* If no country is specified or we are unable to find the zone, then return not found */
433  return -1;
434  }
435 
436  ast_verb(3, "Setting default indication country to '%s'\n", country);
437 
439  if (default_tone_zone) {
441  }
444 
445  zone = ast_tone_zone_unref(zone);
446 
447  return 0;
448 }
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
Definition: indications.h:204
static struct ast_tone_zone * default_tone_zone
Definition: indications.c:88
static struct ao2_container * ast_tone_zones
Definition: indications.c:81
#define ao2_unlock(a)
Definition: astobj2.h:497
#define ast_verb(level,...)
Definition: logger.h:243
A set of tones for a given locale.
Definition: indications.h:73
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ao2_lock(a)
Definition: astobj2.h:488
static char country[80]
Definition: pbx_dundi.c:196
struct ast_tone_zone * ast_get_indication_zone(const char *country)
locate ast_tone_zone
Definition: indications.c:451
static struct ast_tone_zone * ast_tone_zone_ref(struct ast_tone_zone *tz)
Increase the reference count on an ast_tone_zone.
Definition: indications.h:215
static struct ast_tone_zone* ast_tone_zone_alloc ( void  )
static

Definition at line 643 of file indications.c.

References ao2_alloc, and ast_tone_zone_destructor().

Referenced by handle_cli_indication_add(), and parse_tone_zone().

644 {
645  return ao2_alloc(sizeof(struct ast_tone_zone), ast_tone_zone_destructor);
646 }
A set of tones for a given locale.
Definition: indications.h:73
static void ast_tone_zone_destructor(void *obj)
deallocate the passed tone zone
Definition: indications.c:525
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:430
static int ast_tone_zone_cmp ( void *  obj,
void *  arg,
int  flags 
)
static

Definition at line 1118 of file indications.c.

References CMP_MATCH, CMP_STOP, and ast_tone_zone::country.

Referenced by ast_indications_init().

1119 {
1120  struct ast_tone_zone *zone = obj;
1121  struct ast_tone_zone *zone_arg = arg;
1122 
1123  return (!strcasecmp(zone->country, zone_arg->country)) ?
1124  CMP_MATCH | CMP_STOP : 0;
1125 }
A set of tones for a given locale.
Definition: indications.h:73
char country[16]
Country code that this set of tones is for.
Definition: indications.h:75
int ast_tone_zone_count ( void  )

Get the number of registered tone zones.

Returns
the total number of registered tone zones

Definition at line 416 of file indications.c.

References ao2_container_count().

417 {
419 }
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
Definition: astobj2.c:470
static struct ao2_container * ast_tone_zones
Definition: indications.c:81
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.

Return values
<0on error.
0on success.

Definition at line 1127 of file indications.c.

References ast_data_add_node(), ast_data_add_structure, AST_LIST_EMPTY, AST_LIST_TRAVERSE, ast_tone_zone_lock, ast_tone_zone_unlock, ast_tone_zone_sound::entry, and ast_tone_zone::tones.

Referenced by ast_channel_data_add_structure().

1128 {
1129  struct ast_data *data_zone_sound;
1130  struct ast_tone_zone_sound *s;
1131 
1133 
1134  if (AST_LIST_EMPTY(&zone->tones)) {
1135  return 0;
1136  }
1137 
1138  data_zone_sound = ast_data_add_node(tree, "tones");
1139  if (!data_zone_sound) {
1140  return -1;
1141  }
1142 
1143  ast_tone_zone_lock(zone);
1144 
1145  AST_LIST_TRAVERSE(&zone->tones, s, entry) {
1146  ast_data_add_structure(ast_tone_zone_sound, data_zone_sound, s);
1147  }
1148 
1149  ast_tone_zone_unlock(zone);
1150 
1151  return 0;
1152 }
The data tree to be returned by the callbacks and managed by functions local to this file...
Definition: data.c:85
struct ast_tone_zone_sound::@176 entry
Linked list fields for including in the list on an ast_tone_zone.
#define ast_tone_zone_unlock(tz)
Unlock an ast_tone_zone.
Definition: indications.h:192
struct ast_tone_zone::@181 tones
A list of tones for this locale.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
A set of tones for a given locale.
Definition: indications.h:73
struct ast_data * ast_data_add_node(struct ast_data *root, const char *childname)
Add a container child.
Definition: data.c:2317
#define ast_data_add_structure(structure_name, root, structure)
Definition: data.h:620
Description of a tone.
Definition: indications.h:36
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ast_tone_zone_lock(tz)
Lock an ast_tone_zone.
Definition: indications.h:187
static void ast_tone_zone_destructor ( void *  obj)
static

deallocate the passed tone zone

Definition at line 525 of file indications.c.

References ast_free, AST_LIST_REMOVE_HEAD, ast_tone_zone_sound_unref(), ast_tone_zone_sound::entry, ast_tone_zone::ringcadence, and ast_tone_zone::tones.

Referenced by ast_tone_zone_alloc().

526 {
527  struct ast_tone_zone *zone = obj;
528  struct ast_tone_zone_sound *current;
529 
530  while ((current = AST_LIST_REMOVE_HEAD(&zone->tones, entry))) {
531  current = ast_tone_zone_sound_unref(current);
532  }
533 
534  if (zone->ringcadence) {
535  ast_free(zone->ringcadence);
536  zone->ringcadence = NULL;
537  }
538 }
struct ast_tone_zone_sound::@176 entry
Linked list fields for including in the list on an ast_tone_zone.
struct ast_tone_zone::@181 tones
A list of tones for this locale.
A set of tones for a given locale.
Definition: indications.h:73
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.
Definition: indications.h:226
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:818
Description of a tone.
Definition: indications.h:36
#define ast_free(a)
Definition: astmm.h:97
int * ringcadence
Array of ring cadence parts.
Definition: indications.h:90
static int ast_tone_zone_hash ( const void *  obj,
const int  flags 
)
static

Definition at line 1111 of file indications.c.

References ast_str_case_hash(), and ast_tone_zone::country.

Referenced by ast_indications_init().

1112 {
1113  const struct ast_tone_zone *zone = obj;
1114 
1115  return ast_str_case_hash(zone->country);
1116 }
A set of tones for a given locale.
Definition: indications.h:73
char country[16]
Country code that this set of tones is for.
Definition: indications.h:75
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
Definition: strings.h:989
struct ao2_iterator ast_tone_zone_iterator_init ( void  )

Get an iterator for the available tone zones.

Note
Use ao2_iterator_next() to iterate the tone zones.
Use ao2_iterator_destroy() to clean up.
Returns
an initialized iterator

Definition at line 421 of file indications.c.

References ao2_iterator_init().

Referenced by ast_var_indications(), ast_var_indications_table(), and handle_cli_indication_show().

422 {
424 }
static struct ao2_container * ast_tone_zones
Definition: indications.c:81
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags)
Create an iterator for a container.
Definition: astobj2.c:818
int ast_tone_zone_part_parse ( const char *  s,
struct ast_tone_zone_part tone_data 
)

Parse a tone part.

Parameters
sThe part of a tone to parse. This should be in the form described for the data part of ast_tone_zone_sound. '!' should be removed if present.
tone_dataAn output parameter that contains the result of the parsing.
Return values
0success
-1failure, and the contents of tone_data are undefined

Definition at line 262 of file indications.c.

References ast_tone_zone_part::freq1, ast_tone_zone_part::freq2, ast_tone_zone_part::midinote, ast_tone_zone_part::modulate, and ast_tone_zone_part::time.

Referenced by ast_playtones_start().

263 {
264  if (sscanf(s, "%30u+%30u/%30u", &tone_data->freq1, &tone_data->freq2,
265  &tone_data->time) == 3) {
266  /* f1+f2/time format */
267  } else if (sscanf(s, "%30u+%30u", &tone_data->freq1, &tone_data->freq2) == 2) {
268  /* f1+f2 format */
269  tone_data->time = 0;
270  } else if (sscanf(s, "%30u*%30u/%30u", &tone_data->freq1, &tone_data->freq2,
271  &tone_data->time) == 3) {
272  /* f1*f2/time format */
273  tone_data->modulate = 1;
274  } else if (sscanf(s, "%30u*%30u", &tone_data->freq1, &tone_data->freq2) == 2) {
275  /* f1*f2 format */
276  tone_data->time = 0;
277  tone_data->modulate = 1;
278  } else if (sscanf(s, "%30u/%30u", &tone_data->freq1, &tone_data->time) == 2) {
279  /* f1/time format */
280  tone_data->freq2 = 0;
281  } else if (sscanf(s, "%30u", &tone_data->freq1) == 1) {
282  /* f1 format */
283  tone_data->freq2 = 0;
284  tone_data->time = 0;
285  } else if (sscanf(s, "M%30u+M%30u/%30u", &tone_data->freq1, &tone_data->freq2,
286  &tone_data->time) == 3) {
287  /* Mf1+Mf2/time format */
288  tone_data->midinote = 1;
289  } else if (sscanf(s, "M%30u+M%30u", &tone_data->freq1, &tone_data->freq2) == 2) {
290  /* Mf1+Mf2 format */
291  tone_data->time = 0;
292  tone_data->midinote = 1;
293  } else if (sscanf(s, "M%30u*M%30u/%30u", &tone_data->freq1, &tone_data->freq2,
294  &tone_data->time) == 3) {
295  /* Mf1*Mf2/time format */
296  tone_data->modulate = 1;
297  tone_data->midinote = 1;
298  } else if (sscanf(s, "M%30u*M%30u", &tone_data->freq1, &tone_data->freq2) == 2) {
299  /* Mf1*Mf2 format */
300  tone_data->time = 0;
301  tone_data->modulate = 1;
302  tone_data->midinote = 1;
303  } else if (sscanf(s, "M%30u/%30u", &tone_data->freq1, &tone_data->time) == 2) {
304  /* Mf1/time format */
305  tone_data->freq2 = -1;
306  tone_data->midinote = 1;
307  } else if (sscanf(s, "M%30u", &tone_data->freq1) == 1) {
308  /* Mf1 format */
309  tone_data->freq2 = -1;
310  tone_data->time = 0;
311  tone_data->midinote = 1;
312  } else {
313  return -1;
314  }
315 
316  return 0;
317 }
unsigned int midinote
Definition: indications.h:113
unsigned int freq1
Definition: indications.h:109
unsigned int time
Definition: indications.h:111
unsigned int modulate
Definition: indications.h:112
unsigned int freq2
Definition: indications.h:110
static void ast_tone_zone_sound_destructor ( void *  obj)
static

Definition at line 508 of file indications.c.

References ast_free, ast_tone_zone_sound::data, and ast_tone_zone_sound::name.

Referenced by ast_register_indication().

509 {
510  struct ast_tone_zone_sound *ts = obj;
511 
512  /* Deconstify the 'const char *'s so the compiler doesn't complain. (but it's safe) */
513  if (ts->name) {
514  ast_free((char *) ts->name);
515  ts->name = NULL;
516  }
517 
518  if (ts->data) {
519  ast_free((char *) ts->data);
520  ts->data = NULL;
521  }
522 }
const char * name
Name of the tone. For example, &quot;busy&quot;.
Definition: indications.h:38
Description of a tone.
Definition: indications.h:36
#define ast_free(a)
Definition: astmm.h:97
const char * data
Description of a tone.
Definition: indications.h:53
static int ast_unregister_indication ( struct ast_tone_zone zone,
const char *  indication 
)
static

Definition at line 621 of file indications.c.

References AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_tone_zone_lock, ast_tone_zone_sound_unref(), ast_tone_zone_unlock, ast_tone_zone_sound::entry, ast_tone_zone_sound::name, and ast_tone_zone::tones.

Referenced by handle_cli_indication_remove().

622 {
623  struct ast_tone_zone_sound *ts;
624  int res = -1;
625 
626  ast_tone_zone_lock(zone);
627 
629  if (!strcasecmp(indication, ts->name)) {
631  ts = ast_tone_zone_sound_unref(ts);
632  res = 0;
633  break;
634  }
635  }
637 
638  ast_tone_zone_unlock(zone);
639 
640  return res;
641 }
struct ast_tone_zone_sound::@176 entry
Linked list fields for including in the list on an ast_tone_zone.
#define ast_tone_zone_unlock(tz)
Unlock an ast_tone_zone.
Definition: indications.h:192
struct ast_tone_zone::@181 tones
A list of tones for this locale.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:600
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:554
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.
Definition: indications.h:226
const char * name
Name of the tone. For example, &quot;busy&quot;.
Definition: indications.h:38
Description of a tone.
Definition: indications.h:36
#define ast_tone_zone_lock(tz)
Lock an ast_tone_zone.
Definition: indications.h:187
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
static int ast_unregister_indication_country ( const char *  country)
static

Definition at line 557 of file indications.c.

References ao2_callback, ao2_find, ao2_lock, ao2_unlock, ast_copy_string(), ast_tone_zone_unref(), ast_tone_zone::country, ast_tone_zone::nrringcadence, OBJ_POINTER, OBJ_UNLINK, and tz.

Referenced by handle_cli_indication_add(), and handle_cli_indication_remove().

558 {
559  struct ast_tone_zone *tz = NULL;
560  struct ast_tone_zone zone_arg = {
561  .nrringcadence = 0,
562  };
563 
564  ast_copy_string(zone_arg.country, country, sizeof(zone_arg.country));
565 
567  tz = ao2_find(ast_tone_zones, &zone_arg, OBJ_POINTER | OBJ_UNLINK);
568  if (!tz) {
570  return -1;
571  }
572 
573  if (default_tone_zone == tz) {
575  /* Get a new default, punt to the first one we find */
577  }
579 
580  tz = ast_tone_zone_unref(tz);
581 
582  return 0;
583 }
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
Definition: indications.h:204
static struct ast_tone_zone * default_tone_zone
Definition: indications.c:88
static struct ao2_container * ast_tone_zones
Definition: indications.c:81
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:910
#define ao2_unlock(a)
Definition: astobj2.h:497
static char * tz
Definition: cdr_pgsql.c:56
A set of tones for a given locale.
Definition: indications.h:73
#define ao2_lock(a)
Definition: astobj2.h:488
static char country[80]
Definition: pbx_dundi.c:196
#define ao2_find(arg1, arg2, arg3)
Definition: astobj2.h:964
char country[16]
Country code that this set of tones is for.
Definition: indications.h:75
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
unsigned int nrringcadence
Number of ring cadence elements in the ringcadence array.
Definition: indications.h:83
static char* complete_country ( struct ast_cli_args a)
static

Definition at line 648 of file indications.c.

References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ast_strdup, ast_tone_zone_unref(), ast_tone_zone::country, ast_cli_args::n, tz, and ast_cli_args::word.

Referenced by handle_cli_indication_add(), handle_cli_indication_remove(), and handle_cli_indication_show().

649 {
650  char *res = NULL;
651  struct ao2_iterator i;
652  int which = 0;
653  size_t wordlen;
654  struct ast_tone_zone *tz;
655 
656  wordlen = strlen(a->word);
657 
659  while ((tz = ao2_iterator_next(&i))) {
660  if (!strncasecmp(a->word, tz->country, wordlen) && ++which > a->n) {
661  res = ast_strdup(tz->country);
662  }
663  tz = ast_tone_zone_unref(tz);
664  if (res) {
665  break;
666  }
667  }
669 
670  return res;
671 }
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
Definition: indications.h:204
#define ast_strdup(a)
Definition: astmm.h:109
#define ao2_iterator_next(arg1)
Definition: astobj2.h:1126
static struct ao2_container * ast_tone_zones
Definition: indications.c:81
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags)
Create an iterator for a container.
Definition: astobj2.c:818
static char * tz
Definition: cdr_pgsql.c:56
A set of tones for a given locale.
Definition: indications.h:73
const int n
Definition: cli.h:159
const char * word
Definition: cli.h:157
char country[16]
Country code that this set of tones is for.
Definition: indications.h:75
void ao2_iterator_destroy(struct ao2_iterator *i)
Destroy a container iterator.
Definition: astobj2.c:833
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1053
static char* complete_indications ( struct ast_cli_args a)
static

Definition at line 734 of file indications.c.

References ao2_find, ast_cli_args::argv, ast_copy_string(), AST_LIST_TRAVERSE, ast_strdup, ast_tone_zone_lock, ast_tone_zone_unlock, ast_tone_zone_unref(), ast_tone_zone::country, ast_cli_args::n, ast_tone_zone_sound::name, OBJ_POINTER, ast_cli_args::pos, ast_tone_zone::tones, tz, and ast_cli_args::word.

Referenced by handle_cli_indication_remove().

735 {
736  char *res = NULL;
737  int which = 0;
738  size_t wordlen;
739  struct ast_tone_zone_sound *ts;
740  struct ast_tone_zone *tz, tmp_tz = {
741  .nrringcadence = 0,
742  };
743 
744  ast_copy_string(tmp_tz.country, a->argv[a->pos - 1], sizeof(tmp_tz.country));
745 
746  if (!(tz = ao2_find(ast_tone_zones, &tmp_tz, OBJ_POINTER))) {
747  return NULL;
748  }
749 
750  wordlen = strlen(a->word);
751 
752  ast_tone_zone_lock(tz);
753  AST_LIST_TRAVERSE(&tz->tones, ts, entry) {
754  if (!strncasecmp(a->word, ts->name, wordlen) && ++which > a->n) {
755  res = ast_strdup(ts->name);
756  break;
757  }
758  }
760 
761  tz = ast_tone_zone_unref(tz);
762 
763  return res;
764 }
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
Definition: indications.h:204
#define ast_strdup(a)
Definition: astmm.h:109
#define ast_tone_zone_unlock(tz)
Unlock an ast_tone_zone.
Definition: indications.h:192
static struct ao2_container * ast_tone_zones
Definition: indications.c:81
struct ast_tone_zone::@181 tones
A list of tones for this locale.
static char * tz
Definition: cdr_pgsql.c:56
A set of tones for a given locale.
Definition: indications.h:73
const int n
Definition: cli.h:159
const char * name
Name of the tone. For example, &quot;busy&quot;.
Definition: indications.h:38
const char *const * argv
Definition: cli.h:155
Description of a tone.
Definition: indications.h:36
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ao2_find(arg1, arg2, arg3)
Definition: astobj2.h:964
const char * word
Definition: cli.h:157
char country[16]
Country code that this set of tones is for.
Definition: indications.h:75
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
const int pos
Definition: cli.h:158
#define ast_tone_zone_lock(tz)
Lock an ast_tone_zone.
Definition: indications.h:187
static char* handle_cli_indication_add ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 673 of file indications.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_copy_string(), ast_get_indication_zone(), ast_log(), ast_register_indication(), ast_register_indication_country(), ast_tone_zone_alloc(), ast_tone_zone_lock, ast_tone_zone_unlock, ast_tone_zone_unref(), ast_unregister_indication_country(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_country(), ast_tone_zone::country, LOG_NOTICE, LOG_WARNING, ast_cli_args::pos, tz, and ast_cli_entry::usage.

674 {
675  struct ast_tone_zone *tz;
676  int created_country = 0;
677  char *res = CLI_SUCCESS;
678 
679  switch (cmd) {
680  case CLI_INIT:
681  e->command = "indication add";
682  e->usage =
683  "Usage: indication add <country> <indication> \"<tonelist>\"\n"
684  " Add the given indication to the country.\n";
685  return NULL;
686  case CLI_GENERATE:
687  if (a->pos == 2) {
688  return complete_country(a);
689  } else {
690  return NULL;
691  }
692  }
693 
694  if (a->argc != 5) {
695  return CLI_SHOWUSAGE;
696  }
697 
698  if (!(tz = ast_get_indication_zone(a->argv[2]))) {
699  /* country does not exist, create it */
700  ast_log(LOG_NOTICE, "Country '%s' does not exist, creating it.\n", a->argv[2]);
701 
702  if (!(tz = ast_tone_zone_alloc())) {
703  return CLI_FAILURE;
704  }
705 
706  ast_copy_string(tz->country, a->argv[2], sizeof(tz->country));
707 
709  ast_log(LOG_WARNING, "Unable to register new country\n");
710  tz = ast_tone_zone_unref(tz);
711  return CLI_FAILURE;
712  }
713 
714  created_country = 1;
715  }
716 
717  ast_tone_zone_lock(tz);
718 
719  if (ast_register_indication(tz, a->argv[3], a->argv[4])) {
720  ast_log(LOG_WARNING, "Unable to register indication %s/%s\n", a->argv[2], a->argv[3]);
721  if (created_country) {
723  }
724  res = CLI_FAILURE;
725  }
726 
728 
729  tz = ast_tone_zone_unref(tz);
730 
731  return res;
732 }
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
Definition: indications.h:204
static char * complete_country(struct ast_cli_args *a)
Definition: indications.c:648
const int argc
Definition: cli.h:154
#define LOG_WARNING
Definition: logger.h:144
#define ast_tone_zone_unlock(tz)
Unlock an ast_tone_zone.
Definition: indications.h:192
Definition: cli.h:146
static char * tz
Definition: cdr_pgsql.c:56
static int ast_register_indication(struct ast_tone_zone *zone, const char *indication, const char *tonelist)
Definition: indications.c:588
static struct ast_tone_zone * ast_tone_zone_alloc(void)
Definition: indications.c:643
static int ast_register_indication_country(struct ast_tone_zone *zone)
Definition: indications.c:541
A set of tones for a given locale.
Definition: indications.h:73
const char *const * argv
Definition: cli.h:155
#define CLI_SHOWUSAGE
Definition: cli.h:44
struct ast_tone_zone * ast_get_indication_zone(const char *country)
locate ast_tone_zone
Definition: indications.c:451
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...
Definition: logger.c:1207
#define LOG_NOTICE
Definition: logger.h:133
#define CLI_FAILURE
Definition: cli.h:45
char * command
Definition: cli.h:180
char country[16]
Country code that this set of tones is for.
Definition: indications.h:75
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
const int pos
Definition: cli.h:158
#define ast_tone_zone_lock(tz)
Lock an ast_tone_zone.
Definition: indications.h:187
static int ast_unregister_indication_country(const char *country)
Definition: indications.c:557
static char* handle_cli_indication_remove ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 766 of file indications.c.

References ast_cli_args::argc, ast_cli_args::argv, ast_get_indication_zone(), ast_log(), ast_tone_zone_unref(), ast_unregister_indication(), ast_unregister_indication_country(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_country(), complete_indications(), LOG_WARNING, ast_cli_args::pos, tz, and ast_cli_entry::usage.

767 {
768  struct ast_tone_zone *tz;
769  char *res = CLI_SUCCESS;
770 
771  switch (cmd) {
772  case CLI_INIT:
773  e->command = "indication remove";
774  e->usage =
775  "Usage: indication remove <country> [indication]\n"
776  " Remove the given indication from the country.\n";
777  return NULL;
778  case CLI_GENERATE:
779  if (a->pos == 2) {
780  return complete_country(a);
781  } else if (a->pos == 3) {
782  return complete_indications(a);
783  }
784  }
785 
786  if (a->argc != 3 && a->argc != 4) {
787  return CLI_SHOWUSAGE;
788  }
789 
790  if (a->argc == 3) {
791  /* remove entire country */
793  ast_log(LOG_WARNING, "Unable to unregister indication country %s\n", a->argv[2]);
794  return CLI_FAILURE;
795  }
796 
797  return CLI_SUCCESS;
798  }
799 
800  if (!(tz = ast_get_indication_zone(a->argv[2]))) {
801  ast_log(LOG_WARNING, "Unable to unregister indication %s/%s, country does not exists\n", a->argv[2], a->argv[3]);
802  return CLI_FAILURE;
803  }
804 
805  if (ast_unregister_indication(tz, a->argv[3])) {
806  ast_log(LOG_WARNING, "Unable to unregister indication %s/%s\n", a->argv[2], a->argv[3]);
807  res = CLI_FAILURE;
808  }
809 
810  tz = ast_tone_zone_unref(tz);
811 
812  return res;
813 }
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
Definition: indications.h:204
static char * complete_country(struct ast_cli_args *a)
Definition: indications.c:648
const int argc
Definition: cli.h:154
#define LOG_WARNING
Definition: logger.h:144
Definition: cli.h:146
static char * complete_indications(struct ast_cli_args *a)
Definition: indications.c:734
static int ast_unregister_indication(struct ast_tone_zone *zone, const char *indication)
Definition: indications.c:621
static char * tz
Definition: cdr_pgsql.c:56
A set of tones for a given locale.
Definition: indications.h:73
const char *const * argv
Definition: cli.h:155
#define CLI_SHOWUSAGE
Definition: cli.h:44
struct ast_tone_zone * ast_get_indication_zone(const char *country)
locate ast_tone_zone
Definition: indications.c:451
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...
Definition: logger.c:1207
#define CLI_FAILURE
Definition: cli.h:45
char * command
Definition: cli.h:180
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
const int pos
Definition: cli.h:158
static int ast_unregister_indication_country(const char *country)
Definition: indications.c:557
static char* handle_cli_indication_show ( struct ast_cli_entry e,
int  cmd,
struct ast_cli_args a 
)
static

Definition at line 815 of file indications.c.

References ao2_find, ao2_iterator_destroy(), ao2_iterator_next, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_copy_string(), AST_LIST_TRAVERSE, ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_tone_zone_iterator_init(), ast_tone_zone_lock, ast_tone_zone_unlock, ast_tone_zone_unref(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, complete_country(), ast_tone_zone::country, ast_tone_zone_sound::data, ast_tone_zone::description, ast_tone_zone_sound::entry, ast_cli_args::fd, ast_tone_zone_sound::name, ast_tone_zone::nrringcadence, OBJ_POINTER, ast_tone_zone::ringcadence, ast_tone_zone::tones, tz, and ast_cli_entry::usage.

816 {
817  struct ast_tone_zone *tz = NULL;
818  struct ast_str *buf;
819  int found_country = 0;
820  int i;
821 
822  switch (cmd) {
823  case CLI_INIT:
824  e->command = "indication show";
825  e->usage =
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";
829  return NULL;
830  case CLI_GENERATE:
831  return complete_country(a);
832  }
833 
834  if (a->argc == 2) {
835  struct ao2_iterator iter;
836  /* no arguments, show a list of countries */
837  ast_cli(a->fd, "Country Description\n");
838  ast_cli(a->fd, "===========================\n");
840  while ((tz = ao2_iterator_next(&iter))) {
841  ast_tone_zone_lock(tz);
842  ast_cli(a->fd, "%-7.7s %s\n", tz->country, tz->description);
844  tz = ast_tone_zone_unref(tz);
845  }
846  ao2_iterator_destroy(&iter);
847  return CLI_SUCCESS;
848  }
849 
850  buf = ast_str_alloca(256);
851 
852  for (i = 2; i < a->argc; i++) {
853  struct ast_tone_zone zone_arg = {
854  .nrringcadence = 0,
855  };
856  struct ast_tone_zone_sound *ts;
857  int j;
858 
859  ast_copy_string(zone_arg.country, a->argv[i], sizeof(zone_arg.country));
860 
861  if (!(tz = ao2_find(ast_tone_zones, &zone_arg, OBJ_POINTER))) {
862  continue;
863  }
864 
865  if (!found_country) {
866  found_country = 1;
867  ast_cli(a->fd, "Country Indication PlayList\n");
868  ast_cli(a->fd, "=====================================\n");
869  }
870 
871  ast_tone_zone_lock(tz);
872 
873  ast_str_set(&buf, 0, "%-7.7s %-15.15s ", tz->country, "<ringcadence>");
874  for (j = 0; j < tz->nrringcadence; j++) {
875  ast_str_append(&buf, 0, "%d%s", tz->ringcadence[j],
876  (j == tz->nrringcadence - 1) ? "" : ",");
877  }
878  ast_str_append(&buf, 0, "\n");
879  ast_cli(a->fd, "%s", ast_str_buffer(buf));
880 
881  AST_LIST_TRAVERSE(&tz->tones, ts, entry) {
882  ast_cli(a->fd, "%-7.7s %-15.15s %s\n", tz->country, ts->name, ts->data);
883  }
884 
886  tz = ast_tone_zone_unref(tz);
887  }
888 
889  if (!found_country) {
890  ast_cli(a->fd, "No countries matched your criteria.\n");
891  }
892 
893  return CLI_SUCCESS;
894 }
char description[40]
Text description of the given country.
Definition: indications.h:81
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
Definition: indications.h:204
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)
Definition: indications.c:648
#define ao2_iterator_next(arg1)
Definition: astobj2.h:1126
const int argc
Definition: cli.h:154
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
#define ast_tone_zone_unlock(tz)
Unlock an ast_tone_zone.
Definition: indications.h:192
static struct ao2_container * ast_tone_zones
Definition: indications.c:81
Definition: cli.h:146
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.
Definition: strings.h:900
static char * tz
Definition: cdr_pgsql.c:56
#define ast_str_alloca(init_len)
Definition: strings.h:608
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
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:874
A set of tones for a given locale.
Definition: indications.h:73
const int fd
Definition: cli.h:153
const char * name
Name of the tone. For example, &quot;busy&quot;.
Definition: indications.h:38
const char *const * argv
Definition: cli.h:155
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
Description of a tone.
Definition: indications.h:36
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define ao2_find(arg1, arg2, arg3)
Definition: astobj2.h:964
char * command
Definition: cli.h:180
char country[16]
Country code that this set of tones is for.
Definition: indications.h:75
void ao2_iterator_destroy(struct ao2_iterator *i)
Destroy a container iterator.
Definition: astobj2.c:833
int * ringcadence
Array of ring cadence parts.
Definition: indications.h:90
const char * usage
Definition: cli.h:171
#define CLI_SUCCESS
Definition: cli.h:43
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1053
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
unsigned int nrringcadence
Number of ring cadence elements in the ringcadence array.
Definition: indications.h:83
struct ao2_iterator ast_tone_zone_iterator_init(void)
Get an iterator for the available tone zones.
Definition: indications.c:421
const char * data
Description of a tone.
Definition: indications.h:53
#define ast_tone_zone_lock(tz)
Lock an ast_tone_zone.
Definition: indications.h:187
static void indications_shutdown ( void  )
static

Definition at line 1155 of file indications.c.

References ao2_ref, ARRAY_LEN, ast_cli_unregister_multiple(), and ast_tone_zone_unref().

Referenced by ast_indications_init().

1156 {
1158  if (default_tone_zone) {
1160  default_tone_zone = NULL;
1161  }
1162  if (ast_tone_zones) {
1163  ao2_ref(ast_tone_zones, -1);
1164  ast_tone_zones = NULL;
1165  }
1166 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
Definition: indications.h:204
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: cli.c:2177
static struct ast_tone_zone * default_tone_zone
Definition: indications.c:88
static struct ao2_container * ast_tone_zones
Definition: indications.c:81
static struct ast_cli_entry cli_indications[]
CLI entries for commands provided by this module.
Definition: indications.c:1105
#define ao2_ref(o, delta)
Definition: astobj2.h:472
static int is_valid_tone_zone ( struct ast_tone_zone zone)
static

Definition at line 896 of file indications.c.

References AST_LIST_EMPTY, ast_strlen_zero(), ast_tone_zone_lock, ast_tone_zone_unlock, ast_tone_zone::description, and ast_tone_zone::tones.

Referenced by parse_tone_zone().

897 {
898  int res;
899 
900  ast_tone_zone_lock(zone);
901  res = (!ast_strlen_zero(zone->description) && !AST_LIST_EMPTY(&zone->tones));
902  ast_tone_zone_unlock(zone);
903 
904  return res;
905 }
char description[40]
Text description of the given country.
Definition: indications.h:81
#define ast_tone_zone_unlock(tz)
Unlock an ast_tone_zone.
Definition: indications.h:192
struct ast_tone_zone::@181 tones
A list of tones for this locale.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_tone_zone_lock(tz)
Lock an ast_tone_zone.
Definition: indications.h:187
static int load_indications ( int  reload)
static

load indications module

Definition at line 1052 of file indications.c.

References ao2_callback, ao2_lock, ao2_unlock, ast_category_browse(), ast_config_destroy(), ast_config_load2(), ast_log(), ast_set_indication_country(), ast_strlen_zero(), ast_variable_retrieve(), CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEMISSING, CONFIG_STATUS_FILEUNCHANGED, country, LOG_WARNING, OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, parse_tone_zone(), prune_tone_zone(), and tone_zone_mark().

Referenced by ast_indications_init(), and ast_indications_reload().

1053 {
1054  struct ast_config *cfg;
1055  const char *cxt = NULL;
1056  const char *country = NULL;
1057  struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
1058  int res = -1;
1059 
1060  cfg = ast_config_load2(config, "indications", config_flags);
1061 
1063  ast_log(LOG_WARNING, "Can't find indications config file %s.\n", config);
1064  return 0;
1065  } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
1066  return 0;
1067  }
1068 
1069  /* Lock the container to prevent multiple simultaneous reloads */
1071 
1073 
1074  /* Use existing config to populate the Indication table */
1075  while ((cxt = ast_category_browse(cfg, cxt))) {
1076  /* All categories but "general" are considered countries */
1077  if (!strcasecmp(cxt, "general")) {
1078  continue;
1079  }
1080 
1081  if (parse_tone_zone(cfg, cxt)) {
1082  goto return_cleanup;
1083  }
1084  }
1085 
1087  prune_tone_zone, NULL);
1088 
1089  /* determine which country is the default */
1090  country = ast_variable_retrieve(cfg, "general", "country");
1091  if (ast_strlen_zero(country) || ast_set_indication_country(country)) {
1092  ast_log(LOG_WARNING, "Unable to set the default country (for indication tones)\n");
1093  }
1094 
1095  res = 0;
1096 
1097 return_cleanup:
1099  ast_config_destroy(cfg);
1100 
1101  return res;
1102 }
const char * ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable)
Gets a variable.
Definition: config.c:625
#define LOG_WARNING
Definition: logger.h:144
static struct ao2_container * ast_tone_zones
Definition: indications.c:81
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:910
static int prune_tone_zone(void *obj, void *arg, int flags)
Definition: indications.c:1031
#define ao2_unlock(a)
Definition: astobj2.h:497
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Definition: config.c:2499
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: config.c:1037
static int tone_zone_mark(void *obj, void *arg, int flags)
Definition: indications.c:1009
#define CONFIG_STATUS_FILEMISSING
Definition: config.h:50
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
char * ast_category_browse(struct ast_config *config, const char *prev)
Goes through categories.
Definition: config.c:810
#define ao2_lock(a)
Definition: astobj2.h:488
static int reload(void)
Definition: app_amd.c:497
static char country[80]
Definition: pbx_dundi.c:196
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...
Definition: logger.c:1207
Structure used to handle boolean flags.
Definition: utils.h:200
static int parse_tone_zone(struct ast_config *cfg, const char *country)
Definition: indications.c:965
static int ast_set_indication_country(const char *country)
Definition: indications.c:427
static const char config[]
Definition: indications.c:63
#define CONFIG_STATUS_FILEINVALID
Definition: config.h:52
#define CONFIG_STATUS_FILEUNCHANGED
Definition: config.h:51
static int parse_tone_zone ( struct ast_config cfg,
const char *  country 
)
static

Definition at line 965 of file indications.c.

References ao2_find, ast_copy_string(), ast_log(), ast_register_indication_country(), ast_tone_zone_alloc(), ast_tone_zone_lock, ast_tone_zone_unlock, ast_tone_zone_unref(), ast_variable_browse(), ast_tone_zone::country, is_valid_tone_zone(), LOG_WARNING, ast_variable::name, ast_variable::next, ast_tone_zone::nrringcadence, OBJ_POINTER, reset_tone_zone(), store_config_tone_zone(), and ast_variable::value.

Referenced by load_indications().

966 {
967  struct ast_variable *v;
968  struct ast_tone_zone *zone;
969  struct ast_tone_zone tmp_zone = {
970  .nrringcadence = 0,
971  };
972  int allocd = 0;
973 
974  ast_copy_string(tmp_zone.country, country, sizeof(tmp_zone.country));
975 
976  if ((zone = ao2_find(ast_tone_zones, &tmp_zone, OBJ_POINTER))) {
977  reset_tone_zone(zone);
978  } else if ((zone = ast_tone_zone_alloc())) {
979  allocd = 1;
980  ast_copy_string(zone->country, country, sizeof(zone->country));
981  } else {
982  return -1;
983  }
984 
985  ast_tone_zone_lock(zone);
986  for (v = ast_variable_browse(cfg, country); v; v = v->next) {
987  store_config_tone_zone(zone, v->name, v->value);
988  }
989  ast_tone_zone_unlock(zone);
990 
991  if (allocd) {
992  if (!is_valid_tone_zone(zone)) {
993  ast_log(LOG_WARNING, "Indication country '%s' is invalid\n", country);
994  } else if (ast_register_indication_country(zone)) {
995  ast_log(LOG_WARNING, "Unable to register indication country '%s'.\n",
996  country);
997  }
998  }
999 
1000  zone = ast_tone_zone_unref(zone);
1001 
1002  return 0;
1003 }
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
Definition: indications.h:204
#define LOG_WARNING
Definition: logger.h:144
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category)
Goes through variables.
Definition: config.c:597
#define ast_tone_zone_unlock(tz)
Unlock an ast_tone_zone.
Definition: indications.h:192
static struct ao2_container * ast_tone_zones
Definition: indications.c:81
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
static void reset_tone_zone(struct ast_tone_zone *zone)
Definition: indications.c:950
static struct ast_tone_zone * ast_tone_zone_alloc(void)
Definition: indications.c:643
static int is_valid_tone_zone(struct ast_tone_zone *zone)
Definition: indications.c:896
static int ast_register_indication_country(struct ast_tone_zone *zone)
Definition: indications.c:541
const char * value
Definition: config.h:79
A set of tones for a given locale.
Definition: indications.h:73
const char * name
Definition: config.h:77
static void store_config_tone_zone(struct ast_tone_zone *zone, const char *var, const char *value)
Definition: indications.c:937
static char country[80]
Definition: pbx_dundi.c:196
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...
Definition: logger.c:1207
#define ao2_find(arg1, arg2, arg3)
Definition: astobj2.h:964
char country[16]
Country code that this set of tones is for.
Definition: indications.h:75
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
unsigned int nrringcadence
Number of ring cadence elements in the ringcadence array.
Definition: indications.h:83
#define ast_tone_zone_lock(tz)
Lock an ast_tone_zone.
Definition: indications.h:187
struct ast_variable * next
Definition: config.h:82
static void* playtones_alloc ( struct ast_channel chan,
void *  params 
)
static

Definition at line 145 of file indications.c.

References ast_calloc, ast_clear_flag, AST_FLAG_WRITE_INT, AST_FORMAT_SLINEAR, ast_log(), ast_set_flag, ast_set_write_format(), playtones_def::interruptible, playtones_def::items, playtones_state::items, LOG_WARNING, ast_channel::name, playtones_def::nitems, playtones_state::nitems, playtones_state::oldnpos, playtones_state::origwfmt, playtones_release(), playtones_def::reppos, playtones_state::reppos, playtones_def::vol, playtones_state::vol, and ast_channel::writeformat.

146 {
147  struct playtones_def *pd = params;
148  struct playtones_state *ps = NULL;
149 
150  if (!(ps = ast_calloc(1, sizeof(*ps)))) {
151  return NULL;
152  }
153 
154  ps->origwfmt = chan->writeformat;
155 
157  ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", chan->name);
158  playtones_release(NULL, ps);
159  ps = NULL;
160  } else {
161  ps->vol = pd->vol;
162  ps->reppos = pd->reppos;
163  ps->nitems = pd->nitems;
164  ps->items = pd->items;
165  ps->oldnpos = -1;
166  }
167 
168  /* Let interrupts interrupt :) */
169  if (pd->interruptible) {
171  } else {
173  }
174 
175  return ps;
176 }
format_t writeformat
Definition: channel.h:854
#define ast_set_flag(p, flag)
Definition: utils.h:70
#define LOG_WARNING
Definition: logger.h:144
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 &quot;format&quot; is ...
Definition: channel.c:5307
struct playtones_item * items
Definition: indications.c:119
const ast_string_field name
Definition: channel.h:787
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...
Definition: logger.c:1207
struct playtones_item * items
Definition: indications.c:106
#define ast_clear_flag(p, flag)
Definition: utils.h:77
#define AST_FORMAT_SLINEAR
Definition: frame.h:254
#define ast_calloc(a, b)
Definition: astmm.h:82
static void playtones_release(struct ast_channel *chan, void *params)
Definition: indications.c:129
static int playtones_generator ( struct ast_channel chan,
void *  data,
int  len,
int  samples 
)
static

Definition at line 178 of file indications.c.

References AST_FORMAT_SLINEAR, AST_FRAME_VOICE, AST_FRIENDLY_OFFSET, ast_log(), ast_write(), ast_frame_subclass::codec, playtones_state::data, ast_frame::data, ast_frame::datalen, playtones_item::duration, playtones_state::f, playtones_item::fac1, playtones_item::fac2, ast_frame::frametype, playtones_item::init_v2_1, playtones_item::init_v2_2, playtones_item::init_v3_1, playtones_item::init_v3_2, playtones_state::items, len(), LOG_WARNING, playtones_item::modulate, playtones_state::nitems, playtones_state::npos, ast_frame::offset, playtones_state::oldnpos, playtones_state::pos, ast_frame::ptr, playtones_state::reppos, ast_frame::samples, ast_frame::subclass, playtones_state::v1_1, playtones_state::v1_2, playtones_state::v2_1, playtones_state::v2_2, playtones_state::v3_1, and playtones_state::v3_2.

179 {
180  struct playtones_state *ps = data;
181  struct playtones_item *pi;
182  int x;
183 
184  /* we need to prepare a frame with 16 * timelen samples as we're
185  * generating SLIN audio */
186 
187  len = samples * 2;
188  if (len > sizeof(ps->data) / 2 - 1) {
189  ast_log(LOG_WARNING, "Can't generate that much data!\n");
190  return -1;
191  }
192 
193  memset(&ps->f, 0, sizeof(ps->f));
194 
195  pi = &ps->items[ps->npos];
196 
197  if (ps->oldnpos != ps->npos) {
198  /* Load new parameters */
199  ps->v1_1 = 0;
200  ps->v2_1 = pi->init_v2_1;
201  ps->v3_1 = pi->init_v3_1;
202  ps->v1_2 = 0;
203  ps->v2_2 = pi->init_v2_2;
204  ps->v3_2 = pi->init_v3_2;
205  ps->oldnpos = ps->npos;
206  }
207 
208  for (x = 0; x < samples; x++) {
209  ps->v1_1 = ps->v2_1;
210  ps->v2_1 = ps->v3_1;
211  ps->v3_1 = (pi->fac1 * ps->v2_1 >> 15) - ps->v1_1;
212 
213  ps->v1_2 = ps->v2_2;
214  ps->v2_2 = ps->v3_2;
215  ps->v3_2 = (pi->fac2 * ps->v2_2 >> 15) - ps->v1_2;
216  if (pi->modulate) {
217  int p;
218  p = ps->v3_2 - 32768;
219  if (p < 0) {
220  p = -p;
221  }
222  p = ((p * 9) / 10) + 1;
223  ps->data[x] = (ps->v3_1 * p) >> 15;
224  } else {
225  ps->data[x] = ps->v3_1 + ps->v3_2;
226  }
227  }
228 
231  ps->f.datalen = len;
232  ps->f.samples = samples;
234  ps->f.data.ptr = ps->data;
235 
236  if (ast_write(chan, &ps->f)) {
237  return -1;
238  }
239 
240  ps->pos += x;
241 
242  if (pi->duration && ps->pos >= pi->duration * 8) { /* item finished? */
243  ps->pos = 0; /* start new item */
244  ps->npos++;
245  if (ps->npos >= ps->nitems) { /* last item? */
246  if (ps->reppos == -1) { /* repeat set? */
247  return -1;
248  }
249  ps->npos = ps->reppos; /* redo from top */
250  }
251  }
252 
253  return 0;
254 }
union ast_frame_subclass subclass
Definition: frame.h:146
int offset
Definition: frame.h:156
struct ast_frame f
Definition: indications.c:124
void * ptr
Definition: frame.h:160
#define LOG_WARNING
Definition: logger.h:144
format_t codec
Definition: frame.h:137
short data[4000]
Definition: indications.c:126
#define AST_FRIENDLY_OFFSET
Offset into a frame&#39;s data buffer.
Definition: frame.h:204
struct playtones_item * items
Definition: indications.c:119
int datalen
Definition: frame.h:148
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
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...
Definition: logger.c:1207
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.
Definition: channel.c:4916
#define AST_FORMAT_SLINEAR
Definition: frame.h:254
enum ast_frame_type frametype
Definition: frame.h:144
union ast_frame::@172 data
int samples
Definition: frame.h:150
static void playtones_release ( struct ast_channel chan,
void *  params 
)
static

Definition at line 129 of file indications.c.

References ast_free, ast_set_write_format(), playtones_state::items, and playtones_state::origwfmt.

Referenced by playtones_alloc().

130 {
131  struct playtones_state *ps = params;
132 
133  if (chan) {
134  ast_set_write_format(chan, ps->origwfmt);
135  }
136 
137  if (ps->items) {
138  ast_free(ps->items);
139  ps->items = NULL;
140  }
141 
142  ast_free(ps);
143 }
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 &quot;format&quot; is ...
Definition: channel.c:5307
struct playtones_item * items
Definition: indications.c:119
#define ast_free(a)
Definition: astmm.h:97
static int prune_tone_zone ( void *  obj,
void *  arg,
int  flags 
)
static

Prune tones no longer in the configuration, and have the tone zone unlinked if it is no longer in the configuration at all.

Definition at line 1031 of file indications.c.

References AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_tone_zone_lock, ast_tone_zone_sound_unref(), ast_tone_zone_unlock, CMP_MATCH, ast_tone_zone_sound::entry, ast_tone_zone_sound::killme, ast_tone_zone::killme, and ast_tone_zone::tones.

Referenced by load_indications().

1032 {
1033  struct ast_tone_zone *zone = obj;
1034  struct ast_tone_zone_sound *s;
1035 
1036  ast_tone_zone_lock(zone);
1037 
1039  if (s->killme) {
1042  }
1043  }
1045 
1046  ast_tone_zone_unlock(zone);
1047 
1048  return zone->killme ? CMP_MATCH : 0;
1049 }
struct ast_tone_zone_sound::@176 entry
Linked list fields for including in the list on an ast_tone_zone.
#define ast_tone_zone_unlock(tz)
Unlock an ast_tone_zone.
Definition: indications.h:192
struct ast_tone_zone::@181 tones
A list of tones for this locale.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:600
A set of tones for a given locale.
Definition: indications.h:73
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:554
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.
Definition: indications.h:226
Description of a tone.
Definition: indications.h:36
unsigned int killme
Definition: indications.h:97
unsigned int killme
Definition: indications.h:60
#define ast_tone_zone_lock(tz)
Lock an ast_tone_zone.
Definition: indications.h:187
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
static void reset_tone_zone ( struct ast_tone_zone zone)
static

Definition at line 950 of file indications.c.

References ast_free, ast_tone_zone_lock, ast_tone_zone_unlock, ast_tone_zone::killme, ast_tone_zone::nrringcadence, and ast_tone_zone::ringcadence.

Referenced by parse_tone_zone().

951 {
952  ast_tone_zone_lock(zone);
953 
954  zone->killme = 0;
955 
956  if (zone->nrringcadence) {
957  zone->nrringcadence = 0;
958  ast_free(zone->ringcadence);
959  zone->ringcadence = NULL;
960  }
961 
962  ast_tone_zone_unlock(zone);
963 }
#define ast_tone_zone_unlock(tz)
Unlock an ast_tone_zone.
Definition: indications.h:192
unsigned int killme
Definition: indications.h:97
#define ast_free(a)
Definition: astmm.h:97
int * ringcadence
Array of ring cadence parts.
Definition: indications.h:90
unsigned int nrringcadence
Number of ring cadence elements in the ringcadence array.
Definition: indications.h:83
#define ast_tone_zone_lock(tz)
Lock an ast_tone_zone.
Definition: indications.h:187
static void store_config_tone_zone ( struct ast_tone_zone zone,
const char *  var,
const char *  value 
)
static

Definition at line 937 of file indications.c.

References ast_register_indication(), CV_END, CV_F, CV_START, CV_STR, ast_tone_zone::description, and store_tone_zone_ring_cadence().

Referenced by parse_tone_zone().

939 {
940  CV_START(var, value);
941 
942  CV_STR("description", zone->description);
943  CV_F("ringcadence", store_tone_zone_ring_cadence(zone, value));
944 
946 
947  CV_END;
948 }
char description[40]
Text description of the given country.
Definition: indications.h:81
#define CV_STR(__x, __dst)
Definition: config.h:744
#define var
Definition: ast_expr2f.c:606
int value
Definition: syslog.c:39
static int ast_register_indication(struct ast_tone_zone *zone, const char *indication, const char *tonelist)
Definition: indications.c:588
#define CV_END
close a variable parsing block
Definition: config.h:733
#define CV_START(__in_var, __in_val)
the macro to open a block for variable parsing
Definition: config.h:727
#define CV_F(__pattern, __body)
call a generic function if the name matches.
Definition: config.h:736
static void store_tone_zone_ring_cadence(struct ast_tone_zone *zone, const char *val)
Definition: indications.c:910
static void store_tone_zone_ring_cadence ( struct ast_tone_zone zone,
const char *  val 
)
static
Note
This is called with the tone zone locked.

Definition at line 910 of file indications.c.

References ast_copy_string(), ast_log(), ast_realloc, ast_strip(), LOG_WARNING, ast_tone_zone::nrringcadence, ast_tone_zone::ringcadence, and strsep().

Referenced by store_config_tone_zone().

911 {
912  char buf[1024];
913  char *ring, *c = buf;
914 
915  ast_copy_string(buf, val, sizeof(buf));
916 
917  while ((ring = strsep(&c, ","))) {
918  int *tmp, val;
919 
920  ring = ast_strip(ring);
921 
922  if (!isdigit(ring[0]) || (val = atoi(ring)) == -1) {
923  ast_log(LOG_WARNING, "Invalid ringcadence given '%s'.\n", ring);
924  continue;
925  }
926 
927  if (!(tmp = ast_realloc(zone->ringcadence, (zone->nrringcadence + 1) * sizeof(int)))) {
928  return;
929  }
930 
931  zone->ringcadence = tmp;
932  tmp[zone->nrringcadence] = val;
933  zone->nrringcadence++;
934  }
935 }
char * strsep(char **str, const char *delims)
Definition: ast_expr2.c:325
#define LOG_WARNING
Definition: logger.h:144
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:155
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...
Definition: logger.c:1207
int * ringcadence
Array of ring cadence parts.
Definition: indications.h:90
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
unsigned int nrringcadence
Number of ring cadence elements in the ringcadence array.
Definition: indications.h:83
#define ast_realloc(a, b)
Definition: astmm.h:103
static int tone_zone_mark ( void *  obj,
void *  arg,
int  flags 
)
static

Mark the zone and its tones before parsing configuration. We will use this to know what to remove after configuration is parsed.

Definition at line 1009 of file indications.c.

References AST_LIST_TRAVERSE, ast_tone_zone_lock, ast_tone_zone_unlock, ast_tone_zone_sound::entry, ast_tone_zone_sound::killme, ast_tone_zone::killme, and ast_tone_zone::tones.

Referenced by load_indications().

1010 {
1011  struct ast_tone_zone *zone = obj;
1012  struct ast_tone_zone_sound *s;
1013 
1014  ast_tone_zone_lock(zone);
1015 
1016  zone->killme = 1;
1017 
1018  AST_LIST_TRAVERSE(&zone->tones, s, entry) {
1019  s->killme = 1;
1020  }
1021 
1022  ast_tone_zone_unlock(zone);
1023 
1024  return 0;
1025 }
struct ast_tone_zone_sound::@176 entry
Linked list fields for including in the list on an ast_tone_zone.
#define ast_tone_zone_unlock(tz)
Unlock an ast_tone_zone.
Definition: indications.h:192
struct ast_tone_zone::@181 tones
A list of tones for this locale.
A set of tones for a given locale.
Definition: indications.h:73
Description of a tone.
Definition: indications.h:36
unsigned int killme
Definition: indications.h:97
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
unsigned int killme
Definition: indications.h:60
#define ast_tone_zone_lock(tz)
Lock an ast_tone_zone.
Definition: indications.h:187

Variable Documentation

struct ao2_container* ast_tone_zones
static

Definition at line 81 of file indications.c.

struct ast_cli_entry cli_indications[]
static
Initial value:
= {
AST_CLI_DEFINE(handle_cli_indication_add, "Add the given indication to the country"),
AST_CLI_DEFINE(handle_cli_indication_remove, "Remove the given indication from the country"),
AST_CLI_DEFINE(handle_cli_indication_show, "Display a list of all countries/indications")
}
#define AST_CLI_DEFINE(fn, txt,...)
Definition: cli.h:191
static char * handle_cli_indication_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: indications.c:815
static char * handle_cli_indication_add(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: indications.c:673
static char * handle_cli_indication_remove(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: indications.c:766

CLI entries for commands provided by this module.

Definition at line 1105 of file indications.c.

const char config[] = "indications.conf"
static

Definition at line 63 of file indications.c.

struct ast_tone_zone* default_tone_zone
static
Note
Access to this is protected by locking the ast_tone_zones container

Definition at line 88 of file indications.c.

const int midi_tohz[128]
static

Definition at line 65 of file indications.c.

struct ast_generator playtones
static
Initial value:
= {
.alloc = playtones_alloc,
.release = playtones_release,
.generate = playtones_generator,
}
static int playtones_generator(struct ast_channel *chan, void *data, int len, int samples)
Definition: indications.c:178
static void * playtones_alloc(struct ast_channel *chan, void *params)
Definition: indications.c:145
static void playtones_release(struct ast_channel *chan, void *params)
Definition: indications.c:129

Definition at line 256 of file indications.c.