Wed Jan 8 2020 09:49:48

Asterisk developer's documentation


indications.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2002, Pauline Middelink
5  * Copyright (C) 2009, Digium, Inc.
6  *
7  * See http://www.asterisk.org for more information about
8  * the Asterisk project. Please do not directly contact
9  * any of the maintainers of this project for assistance;
10  * the project provides a web site, mailing lists and IRC
11  * channels for your use.
12  *
13  * This program is free software, distributed under the terms of
14  * the GNU General Public License Version 2. See the LICENSE file
15  * at the top of the source tree.
16  */
17 
18 /*!
19  * \file
20  * \brief Indication Tone Handling
21  *
22  * \author Pauline Middelink <middelink@polyware.nl>
23  * \author Russell Bryant <russell@digium.com>
24  */
25 
26 /*** MODULEINFO
27  <support_level>core</support_level>
28  ***/
29 
30 #include "asterisk.h"
31 
32 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 398757 $")
33 
34 #include <math.h>
35 
36 #include "asterisk/lock.h"
37 #include "asterisk/linkedlists.h"
38 #include "asterisk/indications.h"
39 #include "asterisk/frame.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/utils.h"
42 #include "asterisk/cli.h"
43 #include "asterisk/module.h"
44 #include "asterisk/astobj2.h"
45 #include "asterisk/data.h"
46 
47 #include "asterisk/_private.h" /* _init(), _reload() */
48 
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)
53 
55 
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)
59 
61 
62 /* Globals */
63 static const char config[] = "indications.conf";
64 
65 static const int midi_tohz[128] = {
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
79 };
80 
82 
83 #define NUM_TONE_ZONE_BUCKETS 53
84 
85 /*!
86  * \note Access to this is protected by locking the ast_tone_zones container
87  */
89 
91  int fac1;
92  int init_v2_1;
93  int init_v3_1;
94  int fac2;
95  int init_v2_2;
96  int init_v3_2;
97  int modulate;
98  int duration;
99 };
100 
102  int vol;
103  int reppos;
104  int nitems;
107 };
108 
110  int vol;
111  int v1_1;
112  int v2_1;
113  int v3_1;
114  int v1_2;
115  int v2_2;
116  int v3_2;
117  int reppos;
118  int nitems;
120  int npos;
121  int oldnpos;
122  int pos;
123  int origwfmt;
124  struct ast_frame f;
125  unsigned char offset[AST_FRIENDLY_OFFSET];
126  short data[4000];
127 };
128 
129 static void playtones_release(struct ast_channel *chan, void *params)
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 }
144 
145 static void *playtones_alloc(struct ast_channel *chan, void *params)
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 }
177 
178 static int playtones_generator(struct ast_channel *chan, void *data, int len, int samples)
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 }
255 
256 static struct ast_generator playtones = {
258  .release = playtones_release,
259  .generate = playtones_generator,
260 };
261 
262 int ast_tone_zone_part_parse(const char *s, struct ast_tone_zone_part *tone_data)
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 }
318 
319 int ast_playtones_start(struct ast_channel *chan, int vol, const char *playlst, int interruptible)
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 }
410 
411 void ast_playtones_stop(struct ast_channel *chan)
412 {
414 }
415 
417 {
418  return ao2_container_count(ast_tone_zones);
419 }
420 
422 {
423  return ao2_iterator_init(ast_tone_zones, 0);
424 }
425 
426 /* Set global indication country */
427 static int ast_set_indication_country(const char *country)
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 */
432  if (ast_strlen_zero(country) || !(zone = ast_get_indication_zone(country))) {
433  return -1;
434  }
435 
436  ast_verb(3, "Setting default indication country to '%s'\n", country);
437 
438  ao2_lock(ast_tone_zones);
439  if (default_tone_zone) {
440  default_tone_zone = ast_tone_zone_unref(default_tone_zone);
441  }
442  default_tone_zone = ast_tone_zone_ref(zone);
443  ao2_unlock(ast_tone_zones);
444 
445  zone = ast_tone_zone_unref(zone);
446 
447  return 0;
448 }
449 
450 /* locate ast_tone_zone, given the country. if country == NULL, use the default country */
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)) {
459  ao2_lock(ast_tone_zones);
460  if (default_tone_zone) {
461  tz = ast_tone_zone_ref(default_tone_zone);
462  }
463  ao2_unlock(ast_tone_zones);
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 }
472 
473 struct ast_tone_zone_sound *ast_get_indication_tone(const struct ast_tone_zone *_zone, const char *indication)
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) {
481  ao2_lock(ast_tone_zones);
482  if (default_tone_zone) {
483  zone = ast_tone_zone_ref(default_tone_zone);
484  }
485  ao2_unlock(ast_tone_zones);
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 }
507 
508 static void ast_tone_zone_sound_destructor(void *obj)
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 }
523 
524 /*! \brief deallocate the passed tone zone */
525 static void ast_tone_zone_destructor(void *obj)
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 }
539 
540 /* add a new country, if country exists, it will be replaced. */
542 {
543  ao2_lock(ast_tone_zones);
544  if (!default_tone_zone) {
545  default_tone_zone = ast_tone_zone_ref(zone);
546  }
547  ao2_unlock(ast_tone_zones);
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 }
555 
556 /* remove an existing country and all its indications, country must exist. */
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 
566  ao2_lock(ast_tone_zones);
567  tz = ao2_find(ast_tone_zones, &zone_arg, OBJ_POINTER | OBJ_UNLINK);
568  if (!tz) {
569  ao2_unlock(ast_tone_zones);
570  return -1;
571  }
572 
573  if (default_tone_zone == tz) {
574  ast_tone_zone_unref(default_tone_zone);
575  /* Get a new default, punt to the first one we find */
576  default_tone_zone = ao2_callback(ast_tone_zones, 0, NULL, NULL);
577  }
578  ao2_unlock(ast_tone_zones);
579 
580  tz = ast_tone_zone_unref(tz);
581 
582  return 0;
583 }
584 
585 /*!
586  * \note called with the tone zone locked
587  */
588 static int ast_register_indication(struct ast_tone_zone *zone, const char *indication,
589  const char *tonelist)
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 }
619 
620 /* remove an existing country's indication. Both country and indication must exist */
621 static int ast_unregister_indication(struct ast_tone_zone *zone, const char *indication)
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 }
642 
643 static struct ast_tone_zone *ast_tone_zone_alloc(void)
644 {
645  return ao2_alloc(sizeof(struct ast_tone_zone), ast_tone_zone_destructor);
646 }
647 
648 static char *complete_country(struct ast_cli_args *a)
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 
658  i = ao2_iterator_init(ast_tone_zones, 0);
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 }
672 
673 static char *handle_cli_indication_add(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
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 }
733 
734 static char *complete_indications(struct ast_cli_args *a)
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 }
765 
766 static char *handle_cli_indication_remove(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
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 }
814 
815 static char *handle_cli_indication_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
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 }
895 
896 static int is_valid_tone_zone(struct ast_tone_zone *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 }
906 
907 /*!
908  * \note This is called with the tone zone locked.
909  */
910 static void store_tone_zone_ring_cadence(struct ast_tone_zone *zone, const char *val)
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 }
936 
937 static void store_config_tone_zone(struct ast_tone_zone *zone, const char *var,
938  const char *value)
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 
945  ast_register_indication(zone, var, value);
946 
947  CV_END;
948 }
949 
950 static void reset_tone_zone(struct ast_tone_zone *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 }
964 
965 static int parse_tone_zone(struct ast_config *cfg, const char *country)
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 }
1004 
1005 /*!
1006  * Mark the zone and its tones before parsing configuration. We will use this
1007  * to know what to remove after configuration is parsed.
1008  */
1009 static int tone_zone_mark(void *obj, void *arg, int flags)
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 }
1026 
1027 /*!
1028  * Prune tones no longer in the configuration, and have the tone zone unlinked
1029  * if it is no longer in the configuration at all.
1030  */
1031 static int prune_tone_zone(void *obj, void *arg, int flags)
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 }
1050 
1051 /*! \brief load indications module */
1052 static int load_indications(int 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 */
1070  ao2_lock(ast_tone_zones);
1071 
1072  ao2_callback(ast_tone_zones, OBJ_NODATA, tone_zone_mark, NULL);
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 
1086  ao2_callback(ast_tone_zones, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK,
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:
1098  ao2_unlock(ast_tone_zones);
1099  ast_config_destroy(cfg);
1100 
1101  return res;
1102 }
1103 
1104 /*! \brief CLI entries for commands provided by this module */
1105 static struct ast_cli_entry cli_indications[] = {
1106  AST_CLI_DEFINE(handle_cli_indication_add, "Add the given indication to the country"),
1107  AST_CLI_DEFINE(handle_cli_indication_remove, "Remove the given indication from the country"),
1108  AST_CLI_DEFINE(handle_cli_indication_show, "Display a list of all countries/indications")
1109 };
1110 
1111 static int ast_tone_zone_hash(const void *obj, const int flags)
1112 {
1113  const struct ast_tone_zone *zone = obj;
1114 
1115  return ast_str_case_hash(zone->country);
1116 }
1117 
1118 static int ast_tone_zone_cmp(void *obj, void *arg, int flags)
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 }
1126 
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 }
1153 
1154 /*! \internal \brief Clean up resources on Asterisk shutdown */
1155 static void indications_shutdown(void)
1156 {
1157  ast_cli_unregister_multiple(cli_indications, ARRAY_LEN(cli_indications));
1158  if (default_tone_zone) {
1159  ast_tone_zone_unref(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 }
1167 
1168 /*! \brief Load indications module */
1170 {
1171  if (!(ast_tone_zones = ao2_container_alloc(NUM_TONE_ZONE_BUCKETS,
1173  return -1;
1174  }
1175 
1176  if (load_indications(0)) {
1178  return -1;
1179  }
1180 
1181  ast_cli_register_multiple(cli_indications, ARRAY_LEN(cli_indications));
1182 
1184  return 0;
1185 }
1186 
1187 /*! \brief Reload indications module */
1189 {
1190  return load_indications(1);
1191 }
1192 
int ast_indications_init(void)
Load indications module.
Definition: indications.c:1169
union ast_frame_subclass subclass
Definition: frame.h:146
Tone Indication Support.
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_CLI_DEFINE(fn, txt,...)
Definition: cli.h:191
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
#define ao2_link(arg1, arg2)
Definition: astobj2.h:785
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
Definition: astobj2.c:470
const char * ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable)
Gets a variable.
Definition: config.c:625
char description[40]
Text description of the given country.
Definition: indications.h:81
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
int offset
Definition: frame.h:156
The data tree to be returned by the callbacks and managed by functions local to this file...
Definition: data.c:85
static char * handle_cli_indication_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: indications.c:815
struct ast_frame f
Definition: indications.c:124
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.
Definition: indications.h:204
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
Definition: ast_expr2.c:325
format_t writeformat
Definition: channel.h:854
static char * complete_country(struct ast_cli_args *a)
Definition: indications.c:648
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: cli.c:2177
unsigned char offset[AST_FRIENDLY_OFFSET]
Definition: indications.c:125
static struct ast_tone_zone * default_tone_zone
Definition: indications.c:88
static char * handle_cli_indication_add(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: indications.c:673
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
Definition: channel.c:3148
#define CV_STR(__x, __dst)
Definition: config.h:744
int ast_indications_reload(void)
Reload indications module.
Definition: indications.c:1188
void * ptr
Definition: frame.h:160
#define ao2_iterator_next(arg1)
Definition: astobj2.h:1126
#define ast_set_flag(p, flag)
Definition: utils.h:70
descriptor for a cli entry.
Definition: cli.h:165
const int argc
Definition: cli.h:154
#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
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
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:910
A description of a part of a tone.
Definition: indications.h:108
unsigned int midinote
Definition: indications.h:113
Data retrieval API.
Structure for variables, used for configurations and for channel variables.
Definition: config.h:75
#define var
Definition: ast_expr2f.c:606
static int ast_tone_zone_cmp(void *obj, void *arg, int flags)
Definition: indications.c:1118
static int prune_tone_zone(void *obj, void *arg, int flags)
Definition: indications.c:1031
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 * complete_indications(struct ast_cli_args *a)
Definition: indications.c:734
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
static int ast_unregister_indication(struct ast_tone_zone *zone, const char *indication)
Definition: indications.c:621
#define ao2_unlock(a)
Definition: astobj2.h:497
static char * tz
Definition: cdr_pgsql.c:56
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags)
Create an iterator for a container.
Definition: astobj2.c:818
#define ast_str_alloca(init_len)
Definition: strings.h:608
format_t codec
Definition: frame.h:137
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
Definition: indications.c:411
static void reset_tone_zone(struct ast_tone_zone *zone)
Definition: indications.c:950
int value
Definition: syslog.c:39
void ast_cli(int fd, const char *fmt,...)
Definition: cli.c:105
static struct ast_generator playtones
Definition: indications.c:256
static int ast_register_indication(struct ast_tone_zone *zone, const char *indication, const char *tonelist)
Definition: indications.c:588
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:600
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
#define ast_verb(level,...)
Definition: logger.h:243
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: config.c:1037
unsigned int freq1
Definition: indications.h:109
Utility functions.
#define M_PI
static struct ast_tone_zone * ast_tone_zone_alloc(void)
Definition: indications.c:643
static int tone_zone_mark(void *obj, void *arg, int flags)
Definition: indications.c:1009
#define CONFIG_STATUS_FILEMISSING
Definition: config.h:50
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
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
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
#define CV_END
close a variable parsing block
Definition: config.h:733
#define DATA_EXPORT_TONE_ZONE(MEMBER)
Definition: indications.c:49
General Asterisk PBX channel definitions.
#define CV_START(__in_var, __in_val)
the macro to open a block for variable parsing
Definition: config.h:727
short data[4000]
Definition: indications.c:126
#define AST_FRIENDLY_OFFSET
Offset into a frame&#39;s data buffer.
Definition: frame.h:204
A set of tones for a given locale.
Definition: indications.h:73
const int fd
Definition: cli.h:153
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
const int n
Definition: cli.h:159
Asterisk internal frame definitions.
struct ast_data * ast_data_add_node(struct ast_data *root, const char *childname)
Add a container child.
Definition: data.c:2317
int ast_tone_zone_count(void)
Get the number of registered tone zones.
Definition: indications.c:416
static void ast_tone_zone_destructor(void *obj)
deallocate the passed tone zone
Definition: indications.c:525
struct playtones_item * items
Definition: indications.c:119
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:155
int datalen
Definition: frame.h:148
static struct ast_cli_entry cli_indications[]
CLI entries for commands provided by this module.
Definition: indications.c:1105
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:554
#define ao2_ref(o, delta)
Definition: astobj2.h:472
char * ast_category_browse(struct ast_config *config, const char *prev)
Goes through categories.
Definition: config.c:810
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
Definition: asterisk.c:998
#define ao2_lock(a)
Definition: astobj2.h:488
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
A set of macros to manage forward-linked lists.
const char * name
Definition: config.h:77
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:818
static void store_config_tone_zone(struct ast_tone_zone *zone, const char *var, const char *value)
Definition: indications.c:937
const char * name
Name of the tone. For example, &quot;busy&quot;.
Definition: indications.h:38
#define ast_data_add_structure(structure_name, root, structure)
Definition: data.h:620
const char *const * argv
Definition: cli.h:155
static int reload(void)
Definition: app_amd.c:497
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
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.
Definition: indications.c:1127
static int playtones_generator(struct ast_channel *chan, void *data, int len, int samples)
Definition: indications.c:178
#define LOG_ERROR
Definition: logger.h:155
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:716
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:364
#define DATA_EXPORT_TONE_ZONE_SOUND(MEMBER)
Definition: indications.c:56
unsigned int time
Definition: indications.h:111
#define CLI_SHOWUSAGE
Definition: cli.h:44
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_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
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
Description of a tone.
Definition: indications.h:36
struct ast_tone_zone_sound * ast_get_indication_tone(const struct ast_tone_zone *zone, const char *indication)
Locate a tone zone sound.
Definition: indications.c:473
unsigned int killme
Definition: indications.h:97
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
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_alloc(data_size, destructor_fn)
Definition: astobj2.h:430
#define NUM_TONE_ZONE_BUCKETS
Definition: indications.c:83
#define LOG_NOTICE
Definition: logger.h:133
#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
#define CLI_FAILURE
Definition: cli.h:45
void *(* alloc)(struct ast_channel *chan, void *params)
Definition: channel.h:180
static void * playtones_alloc(struct ast_channel *chan, void *params)
Definition: indications.c:145
#define ast_free(a)
Definition: astmm.h:97
char * command
Definition: cli.h:180
unsigned int killme
Definition: indications.h:60
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
const char * word
Definition: cli.h:157
Prototypes for public functions only of internal interest,.
struct playtones_item * items
Definition: indications.c:106
static int ast_tone_zone_hash(const void *obj, const int flags)
Definition: indications.c:1111
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
Structure used to handle boolean flags.
Definition: utils.h:200
#define ast_clear_flag(p, flag)
Definition: utils.h:77
int * ringcadence
Array of ring cadence parts.
Definition: indications.h:90
unsigned int modulate
Definition: indications.h:112
const char * usage
Definition: cli.h:171
static int load_indications(int reload)
load indications module
Definition: indications.c:1052
#define CLI_SUCCESS
Definition: cli.h:43
#define CV_F(__pattern, __body)
call a generic function if the name matches.
Definition: config.h:736
void ast_deactivate_generator(struct ast_channel *chan)
Definition: channel.c:3107
static void indications_shutdown(void)
Definition: indications.c:1155
static int parse_tone_zone(struct ast_config *cfg, const char *country)
Definition: indications.c:965
#define AST_FORMAT_SLINEAR
Definition: frame.h:254
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 int ast_set_indication_country(const char *country)
Definition: indications.c:427
Standard Command Line Interface.
#define ast_calloc(a, b)
Definition: astmm.h:82
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:223
#define ao2_container_alloc(arg1, arg2, arg3)
Definition: astobj2.h:734
unsigned int nrringcadence
Number of ring cadence elements in the ringcadence array.
Definition: indications.h:83
int ast_cli_register_multiple(struct ast_cli_entry *e, int len)
Register multiple commands.
Definition: cli.c:2167
const int pos
Definition: cli.h:158
struct ao2_iterator ast_tone_zone_iterator_init(void)
Get an iterator for the available tone zones.
Definition: indications.c:421
#define ast_realloc(a, b)
Definition: astmm.h:103
Data structure associated with a single frame of data.
Definition: frame.h:142
#define AST_DATA_STRUCTURE(__struct, __name)
Definition: data.h:300
unsigned int freq2
Definition: indications.h:110
static void ast_tone_zone_sound_destructor(void *obj)
Definition: indications.c:508
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
Definition: indications.c:319
static const char config[]
Definition: indications.c:63
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
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:528
enum ast_frame_type frametype
Definition: frame.h:144
struct ast_variable * next
Definition: config.h:82
#define CONFIG_STATUS_FILEINVALID
Definition: config.h:52
static unsigned int cos
Definition: chan_h323.c:147
static void store_tone_zone_ring_cadence(struct ast_tone_zone *zone, const char *val)
Definition: indications.c:910
Asterisk module definitions.
union ast_frame::@172 data
static const int midi_tohz[128]
Definition: indications.c:65
static void playtones_release(struct ast_channel *chan, void *params)
Definition: indications.c:129
static char * handle_cli_indication_remove(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: indications.c:766
static int ast_unregister_indication_country(const char *country)
Definition: indications.c:557
int ast_tone_zone_part_parse(const char *s, struct ast_tone_zone_part *tone_data)
Parse a tone part.
Definition: indications.c:262
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
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180
int samples
Definition: frame.h:150
#define CONFIG_STATUS_FILEUNCHANGED
Definition: config.h:51