Asterisk - The Open Source Telephony Project  18.5.0
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 <[email protected]>
23  * \author Russell Bryant <[email protected]>
24  */
25 
26 /*** MODULEINFO
27  <support_level>core</support_level>
28  ***/
29 
30 #include "asterisk.h"
31 
32 #include <math.h>
33 
34 #include "asterisk/lock.h"
35 #include "asterisk/linkedlists.h"
36 #include "asterisk/indications.h"
37 #include "asterisk/frame.h"
38 #include "asterisk/format_cache.h"
39 #include "asterisk/channel.h"
40 #include "asterisk/utils.h"
41 #include "asterisk/cli.h"
42 #include "asterisk/module.h"
43 #include "asterisk/astobj2.h"
44 
45 #include "asterisk/_private.h" /* _init(), _reload() */
46 
47 /* Globals */
48 static const char config[] = "indications.conf";
49 
50 static const int midi_tohz[128] = {
51  8, 8, 9, 9, 10, 10, 11, 12, 12, 13,
52  14, 15, 16, 17, 18, 19, 20, 21, 23, 24,
53  25, 27, 29, 30, 32, 34, 36, 38, 41, 43,
54  46, 48, 51, 55, 58, 61, 65, 69, 73, 77,
55  82, 87, 92, 97, 103, 110, 116, 123, 130, 138,
56  146, 155, 164, 174, 184, 195, 207, 220, 233, 246,
57  261, 277, 293, 311, 329, 349, 369, 391, 415, 440,
58  466, 493, 523, 554, 587, 622, 659, 698, 739, 783,
59  830, 880, 932, 987, 1046, 1108, 1174, 1244, 1318, 1396,
60  1479, 1567, 1661, 1760, 1864, 1975, 2093, 2217, 2349, 2489,
61  2637, 2793, 2959, 3135, 3322, 3520, 3729, 3951, 4186, 4434,
62  4698, 4978, 5274, 5587, 5919, 6271, 6644, 7040, 7458, 7902,
63  8372, 8869, 9397, 9956, 10548, 11175, 11839, 12543
64 };
65 
67 
68 #define NUM_TONE_ZONE_BUCKETS 53
69 
70 /*!
71  * \note Access to this is protected by locking the ast_tone_zones container
72  */
74 
76  int fac1;
77  int init_v2_1;
78  int init_v3_1;
79  int fac2;
80  int init_v2_2;
81  int init_v3_2;
82  int modulate;
83  int duration;
84 };
85 
86 struct playtones_def {
87  int vol;
88  int reppos;
89  int nitems;
92 };
93 
95  int vol;
96  int v1_1;
97  int v2_1;
98  int v3_1;
99  int v1_2;
100  int v2_2;
101  int v3_2;
102  int reppos;
103  int nitems;
105  int npos;
106  int oldnpos;
107  int pos;
109  struct ast_frame f;
110  unsigned char offset[AST_FRIENDLY_OFFSET];
111  short data[4000];
112 };
113 
114 static void playtones_release(struct ast_channel *chan, void *params)
115 {
116  struct playtones_state *ps = params;
117 
118  if (chan) {
119  ast_set_write_format(chan, ps->origwfmt);
120  }
121 
122  ao2_cleanup(ps->origwfmt);
123  ast_free(ps->items);
124 
125  ast_free(ps);
126 }
127 
128 static void *playtones_alloc(struct ast_channel *chan, void *params)
129 {
130  struct playtones_def *pd = params;
131  struct playtones_state *ps = NULL;
132 
133  if (!(ps = ast_calloc(1, sizeof(*ps)))) {
134  return NULL;
135  }
136 
138 
140  ast_log(LOG_WARNING, "Unable to set '%s' to signed linear format (write)\n", ast_channel_name(chan));
141  playtones_release(NULL, ps);
142  ps = NULL;
143  } else {
144  ps->vol = pd->vol;
145  ps->reppos = pd->reppos;
146  ps->nitems = pd->nitems;
147  ps->items = pd->items;
148  ps->oldnpos = -1;
149  }
150 
151  /* Let interrupts interrupt :) */
152  if (pd->interruptible) {
154  } else {
156  }
157 
158  return ps;
159 }
160 
161 static int playtones_generator(struct ast_channel *chan, void *data, int len, int samples)
162 {
163  struct playtones_state *ps = data;
164  struct playtones_item *pi;
165  int x;
166 
167  /* we need to prepare a frame with 16 * timelen samples as we're
168  * generating SLIN audio */
169 
170  len = samples * 2;
171  if (len > sizeof(ps->data) / 2 - 1) {
172  ast_log(LOG_WARNING, "Can't generate that much data!\n");
173  return -1;
174  }
175 
176  memset(&ps->f, 0, sizeof(ps->f));
177 
178  pi = &ps->items[ps->npos];
179 
180  if (ps->oldnpos != ps->npos) {
181  /* Load new parameters */
182  ps->v1_1 = 0;
183  ps->v2_1 = pi->init_v2_1;
184  ps->v3_1 = pi->init_v3_1;
185  ps->v1_2 = 0;
186  ps->v2_2 = pi->init_v2_2;
187  ps->v3_2 = pi->init_v3_2;
188  ps->oldnpos = ps->npos;
189  }
190 
191  for (x = 0; x < samples; x++) {
192  ps->v1_1 = ps->v2_1;
193  ps->v2_1 = ps->v3_1;
194  ps->v3_1 = (pi->fac1 * ps->v2_1 >> 15) - ps->v1_1;
195 
196  ps->v1_2 = ps->v2_2;
197  ps->v2_2 = ps->v3_2;
198  ps->v3_2 = (pi->fac2 * ps->v2_2 >> 15) - ps->v1_2;
199  if (pi->modulate) {
200  int p;
201  p = ps->v3_2 - 32768;
202  if (p < 0) {
203  p = -p;
204  }
205  p = ((p * 9) / 10) + 1;
206  ps->data[x] = (ps->v3_1 * p) >> 15;
207  } else {
208  ps->data[x] = ps->v3_1 + ps->v3_2;
209  }
210  }
211 
214  ps->f.datalen = len;
215  ps->f.samples = samples;
217  ps->f.data.ptr = ps->data;
218 
219  if (ast_write(chan, &ps->f)) {
220  return -1;
221  }
222 
223  ps->pos += x;
224 
225  if (pi->duration && ps->pos >= pi->duration * 8) { /* item finished? */
226  ps->pos = 0; /* start new item */
227  ps->npos++;
228  if (ps->npos >= ps->nitems) { /* last item? */
229  if (ps->reppos == -1) { /* repeat set? */
230  return -1;
231  }
232  ps->npos = ps->reppos; /* redo from top */
233  }
234  }
235 
236  return 0;
237 }
238 
239 static struct ast_generator playtones = {
241  .release = playtones_release,
242  .generate = playtones_generator,
243 };
244 
245 int ast_tone_zone_part_parse(const char *s, struct ast_tone_zone_part *tone_data)
246 {
247  if (sscanf(s, "%30u+%30u/%30u", &tone_data->freq1, &tone_data->freq2,
248  &tone_data->time) == 3) {
249  /* f1+f2/time format */
250  } else if (sscanf(s, "%30u+%30u", &tone_data->freq1, &tone_data->freq2) == 2) {
251  /* f1+f2 format */
252  tone_data->time = 0;
253  } else if (sscanf(s, "%30u*%30u/%30u", &tone_data->freq1, &tone_data->freq2,
254  &tone_data->time) == 3) {
255  /* f1*f2/time format */
256  tone_data->modulate = 1;
257  } else if (sscanf(s, "%30u*%30u", &tone_data->freq1, &tone_data->freq2) == 2) {
258  /* f1*f2 format */
259  tone_data->time = 0;
260  tone_data->modulate = 1;
261  } else if (sscanf(s, "%30u/%30u", &tone_data->freq1, &tone_data->time) == 2) {
262  /* f1/time format */
263  tone_data->freq2 = 0;
264  } else if (sscanf(s, "%30u", &tone_data->freq1) == 1) {
265  /* f1 format */
266  tone_data->freq2 = 0;
267  tone_data->time = 0;
268  } else if (sscanf(s, "M%30u+M%30u/%30u", &tone_data->freq1, &tone_data->freq2,
269  &tone_data->time) == 3) {
270  /* Mf1+Mf2/time format */
271  tone_data->midinote = 1;
272  } else if (sscanf(s, "M%30u+M%30u", &tone_data->freq1, &tone_data->freq2) == 2) {
273  /* Mf1+Mf2 format */
274  tone_data->time = 0;
275  tone_data->midinote = 1;
276  } else if (sscanf(s, "M%30u*M%30u/%30u", &tone_data->freq1, &tone_data->freq2,
277  &tone_data->time) == 3) {
278  /* Mf1*Mf2/time format */
279  tone_data->modulate = 1;
280  tone_data->midinote = 1;
281  } else if (sscanf(s, "M%30u*M%30u", &tone_data->freq1, &tone_data->freq2) == 2) {
282  /* Mf1*Mf2 format */
283  tone_data->time = 0;
284  tone_data->modulate = 1;
285  tone_data->midinote = 1;
286  } else if (sscanf(s, "M%30u/%30u", &tone_data->freq1, &tone_data->time) == 2) {
287  /* Mf1/time format */
288  tone_data->freq2 = -1;
289  tone_data->midinote = 1;
290  } else if (sscanf(s, "M%30u", &tone_data->freq1) == 1) {
291  /* Mf1 format */
292  tone_data->freq2 = -1;
293  tone_data->time = 0;
294  tone_data->midinote = 1;
295  } else {
296  return -1;
297  }
298 
299  return 0;
300 }
301 
302 int ast_playtones_start(struct ast_channel *chan, int vol, const char *playlst, int interruptible)
303 {
304  char *s, *data = ast_strdupa(playlst);
305  struct playtones_def d = { vol, -1, 0, 1, NULL };
306  char *stringp;
307  char *separator;
308  static const float sample_rate = 8000.0;
309  static const float max_sample_val = 32768.0;
310 
311  if (vol < 1) {
312  d.vol = 7219; /* Default to -8db */
313  }
314 
316 
317  stringp = data;
318 
319  /* check if the data is separated with '|' or with ',' by default */
320  if (strchr(stringp,'|')) {
321  separator = "|";
322  } else {
323  separator = ",";
324  }
325 
326  while ((s = strsep(&stringp, separator)) && !ast_strlen_zero(s)) {
327  struct playtones_item *new_items;
328  struct ast_tone_zone_part tone_data = {
329  .time = 0,
330  };
331 
332  s = ast_strip(s);
333  if (s[0]=='!') {
334  s++;
335  } else if (d.reppos == -1) {
336  d.reppos = d.nitems;
337  }
338 
339  if (ast_tone_zone_part_parse(s, &tone_data)) {
340  ast_log(LOG_ERROR, "Failed to parse tone part '%s'\n", s);
341  continue;
342  }
343 
344  if (tone_data.midinote) {
345  /* midi notes must be between 0 and 127 */
346  if (tone_data.freq1 <= 127) {
347  tone_data.freq1 = midi_tohz[tone_data.freq1];
348  } else {
349  tone_data.freq1 = 0;
350  }
351 
352  if (tone_data.freq2 <= 127) {
353  tone_data.freq2 = midi_tohz[tone_data.freq2];
354  } else {
355  tone_data.freq2 = 0;
356  }
357  }
358 
359  new_items = ast_realloc(d.items, (d.nitems + 1) * sizeof(*d.items));
360  if (!new_items) {
361  ast_free(d.items);
362  return -1;
363  }
364  d.items = new_items;
365 
366  d.items[d.nitems].fac1 = 2.0 * cos(2.0 * M_PI * (tone_data.freq1 / sample_rate)) * max_sample_val;
367  d.items[d.nitems].init_v2_1 = sin(-4.0 * M_PI * (tone_data.freq1 / sample_rate)) * d.vol;
368  d.items[d.nitems].init_v3_1 = sin(-2.0 * M_PI * (tone_data.freq1 / sample_rate)) * d.vol;
369 
370  d.items[d.nitems].fac2 = 2.0 * cos(2.0 * M_PI * (tone_data.freq2 / sample_rate)) * max_sample_val;
371  d.items[d.nitems].init_v2_2 = sin(-4.0 * M_PI * (tone_data.freq2 / sample_rate)) * d.vol;
372  d.items[d.nitems].init_v3_2 = sin(-2.0 * M_PI * (tone_data.freq2 / sample_rate)) * d.vol;
373 
374  d.items[d.nitems].duration = tone_data.time;
375  d.items[d.nitems].modulate = tone_data.modulate;
376 
377  d.nitems++;
378  }
379 
380  if (!d.nitems) {
381  ast_log(LOG_ERROR, "No valid tone parts\n");
382  return -1;
383  }
384 
385  if (ast_activate_generator(chan, &playtones, &d)) {
386  ast_free(d.items);
387  return -1;
388  }
389 
390  return 0;
391 }
392 
393 void ast_playtones_stop(struct ast_channel *chan)
394 {
396 }
397 
399 {
400  return ao2_container_count(ast_tone_zones);
401 }
402 
404 {
405  return ao2_iterator_init(ast_tone_zones, 0);
406 }
407 
408 /*! \brief Set global indication country
409  If no country is specified or we are unable to find the zone, then return not found */
410 static int ast_set_indication_country(const char *country)
411 {
412  struct ast_tone_zone *zone = NULL;
413 
414  if (ast_strlen_zero(country) || !(zone = ast_get_indication_zone(country))) {
415  return -1;
416  }
417 
418  ast_verb(3, "Setting default indication country to '%s'\n", country);
419 
420  ao2_lock(ast_tone_zones);
421  if (default_tone_zone) {
422  default_tone_zone = ast_tone_zone_unref(default_tone_zone);
423  }
424  default_tone_zone = ast_tone_zone_ref(zone);
425  ao2_unlock(ast_tone_zones);
426 
427  zone = ast_tone_zone_unref(zone);
428 
429  return 0;
430 }
431 
432 /*! \brief locate ast_tone_zone, given the country. if country == NULL, use the default country */
434 {
435  struct ast_tone_zone *tz = NULL;
436  struct ast_tone_zone zone_arg = {
437  .nrringcadence = 0,
438  };
439 
440  if (ast_strlen_zero(country)) {
441  ao2_lock(ast_tone_zones);
442  if (default_tone_zone) {
443  tz = ast_tone_zone_ref(default_tone_zone);
444  }
445  ao2_unlock(ast_tone_zones);
446 
447  return tz;
448  }
449 
450  ast_copy_string(zone_arg.country, country, sizeof(zone_arg.country));
451 
452  return ao2_find(ast_tone_zones, &zone_arg, OBJ_POINTER);
453 }
454 
455 struct ast_tone_zone_sound *ast_get_indication_tone(const struct ast_tone_zone *_zone, const char *indication)
456 {
457  struct ast_tone_zone_sound *ts = NULL;
458  /* _zone is const to the users of the API */
459  struct ast_tone_zone *zone = (struct ast_tone_zone *) _zone;
460 
461  /* If no zone is specified, use the default */
462  if (!zone) {
463  ao2_lock(ast_tone_zones);
464  if (default_tone_zone) {
465  zone = ast_tone_zone_ref(default_tone_zone);
466  }
467  ao2_unlock(ast_tone_zones);
468 
469  if (!zone) {
470  return NULL;
471  }
472  }
473 
474  ast_tone_zone_lock(zone);
475 
476  /* Look through list of tones in the zone searching for the right one */
477  AST_LIST_TRAVERSE(&zone->tones, ts, entry) {
478  if (!strcasecmp(ts->name, indication)) {
479  /* Increase ref count for the reference we will return */
480  ts = ast_tone_zone_sound_ref(ts);
481  break;
482  }
483  }
484 
485  ast_tone_zone_unlock(zone);
486 
487  if (!_zone)
488  zone = ast_tone_zone_unref(zone);
489 
490  return ts;
491 }
492 
493 static void ast_tone_zone_sound_destructor(void *obj)
494 {
495  struct ast_tone_zone_sound *ts = obj;
496 
497  /* Deconstify the 'const char *'s so the compiler doesn't complain. (but it's safe) */
498  if (ts->name) {
499  ast_free((char *) ts->name);
500  ts->name = NULL;
501  }
502 
503  if (ts->data) {
504  ast_free((char *) ts->data);
505  ts->data = NULL;
506  }
507 }
508 
509 /*! \brief deallocate the passed tone zone */
510 static void ast_tone_zone_destructor(void *obj)
511 {
512  struct ast_tone_zone *zone = obj;
513  struct ast_tone_zone_sound *current;
514 
515  while ((current = AST_LIST_REMOVE_HEAD(&zone->tones, entry))) {
516  current = ast_tone_zone_sound_unref(current);
517  }
518 
519  if (zone->ringcadence) {
520  ast_free(zone->ringcadence);
521  zone->ringcadence = NULL;
522  }
523 }
524 
525 /*! \brief add a new country, if country exists, it will be replaced. */
527 {
528  ao2_lock(ast_tone_zones);
529  if (!default_tone_zone) {
530  default_tone_zone = ast_tone_zone_ref(zone);
531  }
532  ao2_unlock(ast_tone_zones);
533 
534  ao2_link(ast_tone_zones, zone);
535 
536  ast_verb(3, "Registered indication country '%s'\n", zone->country);
537 
538  return 0;
539 }
540 
541 /*! \brief remove an existing country and all its indications, country must exist. */
543 {
544  struct ast_tone_zone *tz = NULL;
545  struct ast_tone_zone zone_arg = {
546  .nrringcadence = 0,
547  };
548 
549  ast_copy_string(zone_arg.country, country, sizeof(zone_arg.country));
550 
551  ao2_lock(ast_tone_zones);
552  tz = ao2_find(ast_tone_zones, &zone_arg, OBJ_POINTER | OBJ_UNLINK);
553  if (!tz) {
554  ao2_unlock(ast_tone_zones);
555  return -1;
556  }
557 
558  if (default_tone_zone == tz) {
559  ast_tone_zone_unref(default_tone_zone);
560  /* Get a new default, punt to the first one we find */
561  default_tone_zone = ao2_callback(ast_tone_zones, 0, NULL, NULL);
562  }
563  ao2_unlock(ast_tone_zones);
564 
565  tz = ast_tone_zone_unref(tz);
566 
567  return 0;
568 }
569 
570 /*!
571  * \note called with the tone zone locked
572  */
573 static int ast_register_indication(struct ast_tone_zone *zone, const char *indication,
574  const char *tonelist)
575 {
576  struct ast_tone_zone_sound *ts;
577 
578  if (ast_strlen_zero(indication) || ast_strlen_zero(tonelist)) {
579  return -1;
580  }
581 
583  if (!strcasecmp(indication, ts->name)) {
585  ts = ast_tone_zone_sound_unref(ts);
586  break;
587  }
588  }
590 
593  if (!ts) {
594  return -1;
595  }
596 
597  if (!(ts->name = ast_strdup(indication)) || !(ts->data = ast_strdup(tonelist))) {
598  ts = ast_tone_zone_sound_unref(ts);
599  return -1;
600  }
601 
602  AST_LIST_INSERT_TAIL(&zone->tones, ts, entry); /* Inherit reference */
603 
604  return 0;
605 }
606 
607 /*! \brief remove an existing country's indication. Both country and indication must exist */
608 static int ast_unregister_indication(struct ast_tone_zone *zone, const char *indication)
609 {
610  struct ast_tone_zone_sound *ts;
611  int res = -1;
612 
613  ast_tone_zone_lock(zone);
614 
616  if (!strcasecmp(indication, ts->name)) {
618  ts = ast_tone_zone_sound_unref(ts);
619  res = 0;
620  break;
621  }
622  }
624 
625  ast_tone_zone_unlock(zone);
626 
627  return res;
628 }
629 
630 static struct ast_tone_zone *ast_tone_zone_alloc(void)
631 {
632  return ao2_alloc(sizeof(struct ast_tone_zone), ast_tone_zone_destructor);
633 }
634 
635 static char *complete_country(struct ast_cli_args *a)
636 {
637  struct ao2_iterator i;
638  size_t wordlen;
639  struct ast_tone_zone *tz;
640 
641  wordlen = strlen(a->word);
642 
643  i = ao2_iterator_init(ast_tone_zones, 0);
644  while ((tz = ao2_iterator_next(&i))) {
645  if (!strncasecmp(a->word, tz->country, wordlen)) {
648  break;
649  }
650  }
652  }
654 
655  return NULL;
656 }
657 
658 static char *handle_cli_indication_add(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
659 {
660  struct ast_tone_zone *tz;
661  int created_country = 0;
662  char *res = CLI_SUCCESS;
663 
664  switch (cmd) {
665  case CLI_INIT:
666  e->command = "indication add";
667  e->usage =
668  "Usage: indication add <country> <indication> \"<tonelist>\"\n"
669  " Add the given indication to the country.\n";
670  return NULL;
671  case CLI_GENERATE:
672  if (a->pos == 2) {
673  return complete_country(a);
674  } else {
675  return NULL;
676  }
677  }
678 
679  if (a->argc != 5) {
680  return CLI_SHOWUSAGE;
681  }
682 
683  if (!(tz = ast_get_indication_zone(a->argv[2]))) {
684  /* country does not exist, create it */
685  ast_log(LOG_NOTICE, "Country '%s' does not exist, creating it.\n", a->argv[2]);
686 
687  if (!(tz = ast_tone_zone_alloc())) {
688  return CLI_FAILURE;
689  }
690 
691  ast_copy_string(tz->country, a->argv[2], sizeof(tz->country));
692 
694  ast_log(LOG_WARNING, "Unable to register new country\n");
695  tz = ast_tone_zone_unref(tz);
696  return CLI_FAILURE;
697  }
698 
699  created_country = 1;
700  }
701 
702  ast_tone_zone_lock(tz);
703 
704  if (ast_register_indication(tz, a->argv[3], a->argv[4])) {
705  if (ast_strlen_zero(a->argv[3])) {
706  ast_log(LOG_WARNING, "Unable to register indication %s\n", a->argv[2]);
707  } else {
708  ast_log(LOG_WARNING, "Unable to register indication %s/%s\n", a->argv[2], a->argv[3]);
709  }
710  if (created_country) {
712  }
713  res = CLI_FAILURE;
714  }
715 
717 
718  tz = ast_tone_zone_unref(tz);
719 
720  return res;
721 }
722 
723 static char *complete_indications(struct ast_cli_args *a)
724 {
725  size_t wordlen;
726  struct ast_tone_zone_sound *ts;
727  struct ast_tone_zone *tz;
728  struct ast_tone_zone tmp_tz = {
729  .nrringcadence = 0,
730  };
731 
732  ast_copy_string(tmp_tz.country, a->argv[a->pos - 1], sizeof(tmp_tz.country));
733 
734  tz = ao2_find(ast_tone_zones, &tmp_tz, OBJ_POINTER);
735  if (!tz) {
736  return NULL;
737  }
738 
739  wordlen = strlen(a->word);
740 
741  ast_tone_zone_lock(tz);
742  AST_LIST_TRAVERSE(&tz->tones, ts, entry) {
743  if (!strncasecmp(a->word, ts->name, wordlen)) {
745  break;
746  }
747  }
748  }
750 
751  tz = ast_tone_zone_unref(tz);
752 
753  return NULL;
754 }
755 
756 static char *handle_cli_indication_remove(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
757 {
758  struct ast_tone_zone *tz;
759  char *res = CLI_SUCCESS;
760 
761  switch (cmd) {
762  case CLI_INIT:
763  e->command = "indication remove";
764  e->usage =
765  "Usage: indication remove <country> [indication]\n"
766  " Remove the given indication from the country.\n";
767  return NULL;
768  case CLI_GENERATE:
769  if (a->pos == 2) {
770  return complete_country(a);
771  }
772  if (a->pos == 3) {
773  return complete_indications(a);
774  }
775  return NULL;
776  }
777 
778  if (a->argc != 3 && a->argc != 4) {
779  return CLI_SHOWUSAGE;
780  }
781 
782  if (a->argc == 3) {
783  /* remove entire country */
785  ast_log(LOG_WARNING, "Unable to unregister indication country %s\n", a->argv[2]);
786  return CLI_FAILURE;
787  }
788 
789  return CLI_SUCCESS;
790  }
791 
792  if (!(tz = ast_get_indication_zone(a->argv[2]))) {
793  ast_log(LOG_WARNING, "Unable to unregister indication %s/%s, country does not exists\n", a->argv[2], a->argv[3]);
794  return CLI_FAILURE;
795  }
796 
797  if (ast_unregister_indication(tz, a->argv[3])) {
798  ast_log(LOG_WARNING, "Unable to unregister indication %s/%s\n", a->argv[2], a->argv[3]);
799  res = CLI_FAILURE;
800  }
801 
802  tz = ast_tone_zone_unref(tz);
803 
804  return res;
805 }
806 
807 static char *handle_cli_indication_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
808 {
809  struct ast_tone_zone *tz = NULL;
810  struct ast_str *buf;
811  int found_country = 0;
812  int i;
813 
814  switch (cmd) {
815  case CLI_INIT:
816  e->command = "indication show";
817  e->usage =
818  "Usage: indication show [<country> ...]\n"
819  " Display either a condensed summary of all countries and indications, or a\n"
820  " more verbose list of indications for the specified countries.\n";
821  return NULL;
822  case CLI_GENERATE:
823  return complete_country(a);
824  }
825 
826  if (a->argc == 2) {
827  struct ao2_iterator iter;
828  /* no arguments, show a list of countries */
829  ast_cli(a->fd, "Country Description\n");
830  ast_cli(a->fd, "===========================\n");
832  while ((tz = ao2_iterator_next(&iter))) {
833  ast_tone_zone_lock(tz);
834  ast_cli(a->fd, "%-7.7s %s\n", tz->country, tz->description);
836  tz = ast_tone_zone_unref(tz);
837  }
838  ao2_iterator_destroy(&iter);
839  return CLI_SUCCESS;
840  }
841 
842  buf = ast_str_alloca(256);
843 
844  for (i = 2; i < a->argc; i++) {
845  struct ast_tone_zone zone_arg = {
846  .nrringcadence = 0,
847  };
848  struct ast_tone_zone_sound *ts;
849  int j;
850 
851  ast_copy_string(zone_arg.country, a->argv[i], sizeof(zone_arg.country));
852 
853  if (!(tz = ao2_find(ast_tone_zones, &zone_arg, OBJ_POINTER))) {
854  continue;
855  }
856 
857  if (!found_country) {
858  found_country = 1;
859  ast_cli(a->fd, "Country Indication PlayList\n");
860  ast_cli(a->fd, "=====================================\n");
861  }
862 
863  ast_tone_zone_lock(tz);
864 
865  ast_str_set(&buf, 0, "%-7.7s %-15.15s ", tz->country, "<ringcadence>");
866  for (j = 0; j < tz->nrringcadence; j++) {
867  ast_str_append(&buf, 0, "%d%s", tz->ringcadence[j],
868  (j == tz->nrringcadence - 1) ? "" : ",");
869  }
870  ast_str_append(&buf, 0, "\n");
871  ast_cli(a->fd, "%s", ast_str_buffer(buf));
872 
873  AST_LIST_TRAVERSE(&tz->tones, ts, entry) {
874  ast_cli(a->fd, "%-7.7s %-15.15s %s\n", tz->country, ts->name, ts->data);
875  }
876 
878  tz = ast_tone_zone_unref(tz);
879  }
880 
881  if (!found_country) {
882  ast_cli(a->fd, "No countries matched your criteria.\n");
883  }
884 
885  return CLI_SUCCESS;
886 }
887 
888 static int is_valid_tone_zone(struct ast_tone_zone *zone)
889 {
890  int res;
891 
892  ast_tone_zone_lock(zone);
893  res = (!ast_strlen_zero(zone->description) && !AST_LIST_EMPTY(&zone->tones));
894  ast_tone_zone_unlock(zone);
895 
896  return res;
897 }
898 
899 /*!\brief
900  *
901  * \note This is called with the tone zone locked.
902  */
903 static void store_tone_zone_ring_cadence(struct ast_tone_zone *zone, const char *val)
904 {
905  char buf[1024];
906  char *ring, *c = buf;
907 
908  ast_copy_string(buf, val, sizeof(buf));
909 
910  while ((ring = strsep(&c, ","))) {
911  int *tmp, value;
912 
913  ring = ast_strip(ring);
914 
915  if (!isdigit(ring[0]) || (value = atoi(ring)) == -1) {
916  ast_log(LOG_WARNING, "Invalid ringcadence given '%s'.\n", ring);
917  continue;
918  }
919 
920  if (!(tmp = ast_realloc(zone->ringcadence, (zone->nrringcadence + 1) * sizeof(int)))) {
921  return;
922  }
923 
924  zone->ringcadence = tmp;
925  tmp[zone->nrringcadence] = value;
926  zone->nrringcadence++;
927  }
928 }
929 
930 static void store_config_tone_zone(struct ast_tone_zone *zone, const char *var,
931  const char *value)
932 {
933  CV_START(var, value);
934 
935  CV_STR("description", zone->description);
936  CV_F("ringcadence", store_tone_zone_ring_cadence(zone, value));
937 
938  ast_register_indication(zone, var, value);
939 
940  CV_END;
941 }
942 
943 static void reset_tone_zone(struct ast_tone_zone *zone)
944 {
945  ast_tone_zone_lock(zone);
946 
947  zone->killme = 0;
948 
949  if (zone->nrringcadence) {
950  zone->nrringcadence = 0;
951  ast_free(zone->ringcadence);
952  zone->ringcadence = NULL;
953  }
954 
955  ast_tone_zone_unlock(zone);
956 }
957 
958 static int parse_tone_zone(struct ast_config *cfg, const char *country)
959 {
960  struct ast_variable *v;
961  struct ast_tone_zone *zone;
962  struct ast_tone_zone tmp_zone = {
963  .nrringcadence = 0,
964  };
965  int allocd = 0;
966 
967  ast_copy_string(tmp_zone.country, country, sizeof(tmp_zone.country));
968 
969  if ((zone = ao2_find(ast_tone_zones, &tmp_zone, OBJ_POINTER))) {
970  reset_tone_zone(zone);
971  } else if ((zone = ast_tone_zone_alloc())) {
972  allocd = 1;
973  ast_copy_string(zone->country, country, sizeof(zone->country));
974  } else {
975  return -1;
976  }
977 
978  ast_tone_zone_lock(zone);
979  for (v = ast_variable_browse(cfg, country); v; v = v->next) {
980  store_config_tone_zone(zone, v->name, v->value);
981  }
982  ast_tone_zone_unlock(zone);
983 
984  if (allocd) {
985  if (!is_valid_tone_zone(zone)) {
986  ast_log(LOG_WARNING, "Indication country '%s' is invalid\n", country);
987  } else if (ast_register_indication_country(zone)) {
988  ast_log(LOG_WARNING, "Unable to register indication country '%s'.\n",
989  country);
990  }
991  }
992 
993  zone = ast_tone_zone_unref(zone);
994 
995  return 0;
996 }
997 
998 /*! \brief
999  * Mark the zone and its tones before parsing configuration. We will use this
1000  * to know what to remove after configuration is parsed.
1001  */
1002 static int tone_zone_mark(void *obj, void *arg, int flags)
1003 {
1004  struct ast_tone_zone *zone = obj;
1005  struct ast_tone_zone_sound *s;
1006 
1007  ast_tone_zone_lock(zone);
1008 
1009  zone->killme = 1;
1010 
1011  AST_LIST_TRAVERSE(&zone->tones, s, entry) {
1012  s->killme = 1;
1013  }
1014 
1015  ast_tone_zone_unlock(zone);
1016 
1017  return 0;
1018 }
1019 
1020 /*! \brief
1021  * Prune tones no longer in the configuration, and have the tone zone unlinked
1022  * if it is no longer in the configuration at all.
1023  */
1024 static int prune_tone_zone(void *obj, void *arg, int flags)
1025 {
1026  struct ast_tone_zone *zone = obj;
1027  struct ast_tone_zone_sound *s;
1028 
1029  ast_tone_zone_lock(zone);
1030 
1032  if (s->killme) {
1035  }
1036  }
1038 
1039  ast_tone_zone_unlock(zone);
1040 
1041  return zone->killme ? CMP_MATCH : 0;
1042 }
1043 
1044 /*! \brief load indications module */
1045 static int load_indications(int reload)
1046 {
1047  struct ast_config *cfg;
1048  const char *cxt = NULL;
1049  const char *country = NULL;
1050  struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
1051  int res = -1;
1052 
1053  cfg = ast_config_load2(config, "indications", config_flags);
1054 
1056  ast_log(LOG_WARNING, "Can't find indications config file %s.\n", config);
1057  return 0;
1058  } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) {
1059  return 0;
1060  }
1061 
1062  /* Lock the container to prevent multiple simultaneous reloads */
1063  ao2_lock(ast_tone_zones);
1064 
1065  ao2_callback(ast_tone_zones, OBJ_NODATA, tone_zone_mark, NULL);
1066 
1067  /* Use existing config to populate the Indication table */
1068  while ((cxt = ast_category_browse(cfg, cxt))) {
1069  /* All categories but "general" are considered countries */
1070  if (!strcasecmp(cxt, "general")) {
1071  continue;
1072  }
1073 
1074  if (parse_tone_zone(cfg, cxt)) {
1075  goto return_cleanup;
1076  }
1077  }
1078 
1079  ao2_callback(ast_tone_zones, OBJ_NODATA | OBJ_MULTIPLE | OBJ_UNLINK,
1081 
1082  /* determine which country is the default */
1083  country = ast_variable_retrieve(cfg, "general", "country");
1084  if (ast_strlen_zero(country) || ast_set_indication_country(country)) {
1085  ast_log(LOG_WARNING, "Unable to set the default country (for indication tones)\n");
1086  }
1087 
1088  res = 0;
1089 
1090 return_cleanup:
1091  ao2_unlock(ast_tone_zones);
1092  ast_config_destroy(cfg);
1093 
1094  return res;
1095 }
1096 
1097 /*! \brief CLI entries for commands provided by this module */
1098 static struct ast_cli_entry cli_indications[] = {
1099  AST_CLI_DEFINE(handle_cli_indication_add, "Add the given indication to the country"),
1100  AST_CLI_DEFINE(handle_cli_indication_remove, "Remove the given indication from the country"),
1101  AST_CLI_DEFINE(handle_cli_indication_show, "Display a list of all countries/indications")
1102 };
1103 
1104 static int ast_tone_zone_hash(const void *obj, const int flags)
1105 {
1106  const struct ast_tone_zone *zone = obj;
1107 
1108  return ast_str_case_hash(zone->country);
1109 }
1110 
1111 static int ast_tone_zone_cmp(void *obj, void *arg, int flags)
1112 {
1113  struct ast_tone_zone *zone = obj;
1114  struct ast_tone_zone *zone_arg = arg;
1115 
1116  return (!strcasecmp(zone->country, zone_arg->country)) ?
1117  CMP_MATCH | CMP_STOP : 0;
1118 }
1119 
1120 /*!
1121  * \internal
1122  * \brief Clean up resources on Asterisk shutdown
1123  */
1124 static int unload_module(void)
1125 {
1126  ast_cli_unregister_multiple(cli_indications, ARRAY_LEN(cli_indications));
1127  if (default_tone_zone) {
1128  ast_tone_zone_unref(default_tone_zone);
1129  default_tone_zone = NULL;
1130  }
1131  if (ast_tone_zones) {
1132  ao2_ref(ast_tone_zones, -1);
1133  ast_tone_zones = NULL;
1134  }
1135 
1136  return 0;
1137 }
1138 
1139 /*! \brief Load indications module */
1140 static int load_module(void)
1141 {
1144  if (!ast_tone_zones) {
1145  return AST_MODULE_LOAD_FAILURE;
1146  }
1147 
1148  if (load_indications(0)) {
1149  return AST_MODULE_LOAD_FAILURE;
1150  }
1151 
1152  ast_cli_register_multiple(cli_indications, ARRAY_LEN(cli_indications));
1153 
1154  return AST_MODULE_LOAD_SUCCESS;
1155 }
1156 
1157 /*! \brief Reload indications module */
1158 static int reload_module(void)
1159 {
1160  return load_indications(1);
1161 }
1162 
1164  .support_level = AST_MODULE_SUPPORT_CORE,
1165  .load = load_module,
1166  .unload = unload_module,
1167  .reload = reload_module,
1168  .load_pri = AST_MODPRI_CORE,
1169  .requires = "extconfig",
1170 );
struct ast_variable * next
Tone Indication Support.
Main Channel structure associated with a channel.
#define AST_CLI_DEFINE(fn, txt,...)
Definition: cli.h:197
unsigned int cos
Definition: chan_iax2.c:352
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
#define ast_realloc(p, len)
A wrapper for realloc()
Definition: astmm.h:228
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
char description[40]
Text description of the given country.
Definition: indications.h:82
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
static char * handle_cli_indication_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: indications.c:807
struct ast_frame f
Definition: indications.c:109
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:205
Definition: ast_expr2.c:325
static char * complete_country(struct ast_cli_args *a)
Definition: indications.c:635
void *(* alloc)(struct ast_channel *chan, void *params)
Definition: channel.h:227
int ast_cli_unregister_multiple(struct ast_cli_entry *e, int len)
Unregister multiple commands.
Definition: clicompat.c:30
char country[MAX_TONEZONE_COUNTRY]
Country code that this set of tones is for.
Definition: indications.h:76
static struct ast_tone_zone * default_tone_zone
Definition: indications.c:73
static char * handle_cli_indication_add(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: indications.c:658
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition: extconf.c:1216
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
Definition: channel.c:2960
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define OBJ_POINTER
Definition: astobj2.h:1154
#define ast_set_flag(p, flag)
Definition: utils.h:70
descriptor for a cli entry.
Definition: cli.h:171
const int argc
Definition: cli.h:160
#define LOG_WARNING
Definition: logger.h:274
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define ast_tone_zone_unlock(tz)
Unlock an ast_tone_zone.
Definition: indications.h:193
static struct ao2_container * ast_tone_zones
Definition: indications.c:66
#define ao2_callback(c, flags, cb_fn, arg)
Definition: astobj2.h:1716
#define CONFIG_STATUS_FILEINVALID
A description of a part of a tone.
Definition: indications.h:109
int ast_tone_zone_part_parse(const char *s, struct ast_tone_zone_part *tone_data)
Parse a tone part.
Definition: indications.c:245
unsigned int midinote
Definition: indications.h:114
static int tmp()
Definition: bt_open.c:389
static int reload_module(void)
Reload indications module.
Definition: indications.c:1158
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Definition: main/config.c:3154
Structure for variables, used for configurations and for channel variables.
#define var
Definition: ast_expr2f.c:614
static int load_module(void)
Load indications module.
Definition: indications.c:1140
static int ast_tone_zone_cmp(void *obj, void *arg, int flags)
Definition: indications.c:1111
static int prune_tone_zone(void *obj, void *arg, int flags)
Prune tones no longer in the configuration, and have the tone zone unlinked if it is no longer in the...
Definition: indications.c:1024
Definition: cli.h:152
Definition of a media format.
Definition: format.c:43
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:1091
#define ast_cli_register_multiple(e, len)
Register multiple commands.
Definition: cli.h:265
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
static char * complete_indications(struct ast_cli_args *a)
Definition: indications.c:723
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:449
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
static int ast_unregister_indication(struct ast_tone_zone *zone, const char *indication)
remove an existing country&#39;s indication. Both country and indication must exist
Definition: indications.c:608
#define ao2_unlock(a)
Definition: astobj2.h:730
static struct test_val c
#define ast_str_alloca(init_len)
Definition: strings.h:800
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:243
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
Definition: extconf.c:3328
#define NULL
Definition: resample.c:96
#define CV_END
close a variable parsing block
static void reset_tone_zone(struct ast_tone_zone *zone)
Definition: indications.c:943
int value
Definition: syslog.c:37
void ast_cli(int fd, const char *fmt,...)
Definition: clicompat.c:6
static struct ast_generator playtones
Definition: indications.c:239
static int ast_register_indication(struct ast_tone_zone *zone, const char *indication, const char *tonelist)
Definition: indications.c:573
#define CV_START(__in_var, __in_val)
the macro to open a block for variable parsing
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:614
#define ast_verb(level,...)
Definition: logger.h:463
#define CV_STR(__x, __dst)
struct ast_frame_subclass subclass
unsigned int freq1
Definition: indications.h:110
Utility functions.
#define ast_strlen_zero(foo)
Definition: strings.h:52
static struct ast_tone_zone * ast_tone_zone_alloc(void)
Definition: indications.c:630
static int tone_zone_mark(void *obj, void *arg, int flags)
Mark the zone and its tones before parsing configuration. We will use this to know what to remove aft...
Definition: indications.c:1002
#define ao2_bump(obj)
Definition: astobj2.h:491
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:1065
#define CV_F(__pattern, __body)
call a generic function if the name matches.
static int is_valid_tone_zone(struct ast_tone_zone *zone)
Definition: indications.c:888
#define ast_log
Definition: astobj2.c:42
static int ast_register_indication_country(struct ast_tone_zone *zone)
add a new country, if country exists, it will be replaced.
Definition: indications.c:526
General Asterisk PBX channel definitions.
short data[4000]
Definition: indications.c:111
#define AST_FRIENDLY_OFFSET
Offset into a frame&#39;s data buffer.
A set of tones for a given locale.
Definition: indications.h:74
const int fd
Definition: cli.h:159
static int unload_module(void)
Definition: indications.c:1124
#define M_PI
Definition: resample.c:83
static void ast_tone_zone_destructor(void *obj)
deallocate the passed tone zone
Definition: indications.c:510
struct playtones_item * items
Definition: indications.c:104
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:219
static struct ast_cli_entry cli_indications[]
CLI entries for commands provided by this module.
Definition: indications.c:1098
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:556
Asterisk internal frame definitions.
#define ao2_ref(o, delta)
Definition: astobj2.h:464
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
#define ao2_lock(a)
Definition: astobj2.h:718
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
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:227
A set of macros to manage forward-linked lists.
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
Definition: channel.c:5890
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Definition: linkedlists.h:832
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
Definition: indications.c:393
int ast_playtones_start(struct ast_channel *chan, int vol, const char *playlst, int interruptible)
Start playing a list of tones on a channel.
Definition: indications.c:302
static void store_config_tone_zone(struct ast_tone_zone *zone, const char *var, const char *value)
Definition: indications.c:930
const char * name
Name of the tone. For example, "busy".
Definition: indications.h:37
#define CONFIG_STATUS_FILEUNCHANGED
const char *const * argv
Definition: cli.h:161
static int playtones_generator(struct ast_channel *chan, void *data, int len, int samples)
Definition: indications.c:161
#define LOG_ERROR
Definition: logger.h:285
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:730
#define ao2_container_alloc_hash(ao2_options, container_options, n_buckets, hash_fn, sort_fn, cmp_fn)
Definition: astobj2.h:1310
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
unsigned int time
Definition: indications.h:112
#define CLI_SHOWUSAGE
Definition: cli.h:45
static char country[80]
Definition: pbx_dundi.c:205
static char * tz
Definition: cdr_pgsql.c:75
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:238
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
Description of a tone.
Definition: indications.h:35
unsigned int killme
Definition: indications.h:98
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:216
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:411
#define NUM_TONE_ZONE_BUCKETS
Definition: indications.c:68
#define LOG_NOTICE
Definition: logger.h:263
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
Definition: linkedlists.h:490
#define CLI_FAILURE
Definition: cli.h:46
static void * playtones_alloc(struct ast_channel *chan, void *params)
Definition: indications.c:128
#define ast_free(a)
Definition: astmm.h:182
char * command
Definition: cli.h:186
struct ao2_iterator ast_tone_zone_iterator_init(void)
Get an iterator for the available tone zones.
Definition: indications.c:403
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
static int reload(void)
Definition: cdr_mysql.c:741
int ast_tone_zone_count(void)
Get the number of registered tone zones.
Definition: indications.c:398
unsigned int killme
Definition: indications.h:59
Module could not be loaded properly.
Definition: module.h:102
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:5189
const char * word
Definition: cli.h:163
Prototypes for public functions only of internal interest,.
struct playtones_item * items
Definition: indications.c:91
#define ao2_find(container, arg, flags)
Definition: astobj2.h:1756
static int ast_tone_zone_hash(const void *obj, const int flags)
Definition: indications.c:1104
Structure used to handle boolean flags.
Definition: utils.h:199
#define ast_clear_flag(p, flag)
Definition: utils.h:77
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
int * ringcadence
Array of ring cadence parts.
Definition: indications.h:91
unsigned int modulate
Definition: indications.h:113
const char * usage
Definition: cli.h:177
struct ast_tone_zone * ast_get_indication_zone(const char *country)
locate ast_tone_zone, given the country. if country == NULL, use the default country ...
Definition: indications.c:433
static int load_indications(int reload)
load indications module
Definition: indications.c:1045
#define CONFIG_STATUS_FILEMISSING
#define CLI_SUCCESS
Definition: cli.h:44
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
Definition: main/config.c:694
void ast_deactivate_generator(struct ast_channel *chan)
Definition: channel.c:2902
static int parse_tone_zone(struct ast_config *cfg, const char *country)
Definition: indications.c:958
char * strsep(char **str, const char *delims)
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
static int ast_set_indication_country(const char *country)
Set global indication country If no country is specified or we are unable to find the zone...
Definition: indications.c:410
Standard Command Line Interface.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
unsigned int nrringcadence
Number of ring cadence elements in the ringcadence array.
Definition: indications.h:84
const char * ast_channel_name(const struct ast_channel *chan)
const int pos
Definition: cli.h:164
struct ast_format * origwfmt
Definition: indications.c:108
Data structure associated with a single frame of data.
unsigned int freq2
Definition: indications.h:111
static void ast_tone_zone_sound_destructor(void *obj)
Definition: indications.c:493
static const char config[]
Definition: indications.c:48
Definition: search.h:40
const char * data
Description of a tone.
Definition: indications.h:52
#define ast_tone_zone_lock(tz)
Lock an ast_tone_zone.
Definition: indications.h:188
union ast_frame::@263 data
#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
Generic container type.
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
struct ast_format * format
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:455
int ast_cli_completion_add(char *value)
Add a result to a request for completion options.
Definition: main/cli.c:2726
static void store_tone_zone_ring_cadence(struct ast_tone_zone *zone, const char *val)
Definition: indications.c:903
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
Asterisk module definitions.
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
static const int midi_tohz[128]
Definition: indications.c:50
static void playtones_release(struct ast_channel *chan, void *params)
Definition: indications.c:114
static char * handle_cli_indication_remove(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Definition: indications.c:756
struct ao2_iterator ao2_iterator_init(struct ao2_container *c, int flags) attribute_warn_unused_result
Create an iterator for a container.
static int ast_unregister_indication_country(const char *country)
remove an existing country and all its indications, country must exist.
Definition: indications.c:542
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:1250
Media Format Cache API.
struct ast_tone_zone::@271 tones
A list of tones for this locale.
static struct test_val a
#define ao2_link(container, obj)
Definition: astobj2.h:1549