Asterisk - The Open Source Telephony Project  GIT-master-a24979a
main/app.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  *
21  * \brief Convenient Application Routines
22  *
23  * \author Mark Spencer <markster@digium.com>
24  */
25 
26 /*!
27  * Application Skeleton is an example of creating an application for Asterisk.
28  * \example app_skel.c
29  */
30 
31 /*** MODULEINFO
32  <support_level>core</support_level>
33  ***/
34 
35 #include "asterisk.h"
36 
37 #ifdef HAVE_SYS_STAT_H
38 #include <sys/stat.h>
39 #endif
40 #include <regex.h> /* for regcomp(3) */
41 #include <sys/file.h> /* for flock(2) */
42 #include <signal.h> /* for pthread_sigmask(3) */
43 #include <stdlib.h> /* for closefrom(3) */
44 #include <sys/types.h>
45 #include <sys/wait.h> /* for waitpid(2) */
46 #ifndef HAVE_CLOSEFROM
47 #include <dirent.h> /* for opendir(3) */
48 #endif
49 #ifdef HAVE_CAP
50 #include <sys/capability.h>
51 #endif /* HAVE_CAP */
52 
53 #include "asterisk/paths.h" /* use ast_config_AST_DATA_DIR */
54 #include "asterisk/channel.h"
55 #include "asterisk/pbx.h"
56 #include "asterisk/file.h"
57 #include "asterisk/app.h"
58 #include "asterisk/dsp.h"
59 #include "asterisk/utils.h"
60 #include "asterisk/lock.h"
61 #include "asterisk/indications.h"
62 #include "asterisk/linkedlists.h"
63 #include "asterisk/threadstorage.h"
64 #include "asterisk/test.h"
65 #include "asterisk/module.h"
66 #include "asterisk/astobj2.h"
67 #include "asterisk/stasis.h"
69 #include "asterisk/json.h"
70 #include "asterisk/format_cache.h"
71 
72 AST_THREADSTORAGE_PUBLIC(ast_str_thread_global_buf);
73 
75 
76 struct zombie {
77  pid_t pid;
79 };
80 
82 
83 #ifdef HAVE_CAP
84 static cap_t child_cap;
85 #endif
86 /*!
87  * \brief Define \ref stasis topic objects
88  * @{
89  */
92 
93 /*! @} */
94 
95 static void *shaun_of_the_dead(void *data)
96 {
97  struct zombie *cur;
98  int status;
99  for (;;) {
100  if (!AST_LIST_EMPTY(&zombies)) {
101  /* Don't allow cancellation while we have a lock. */
102  pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
105  if (waitpid(cur->pid, &status, WNOHANG) != 0) {
107  ast_free(cur);
108  }
109  }
112  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
113  }
114  pthread_testcancel();
115  /* Wait for 60 seconds, without engaging in a busy loop. */
116  ast_poll(NULL, 0, AST_LIST_FIRST(&zombies) ? 5000 : 60000);
117  }
118  return NULL;
119 }
120 
121 
122 #define AST_MAX_FORMATS 10
123 
125 
126 /*!
127  * \brief This function presents a dialtone and reads an extension into 'collect'
128  * which must be a pointer to a **pre-initialized** array of char having a
129  * size of 'size' suitable for writing to. It will collect no more than the smaller
130  * of 'maxlen' or 'size' minus the original strlen() of collect digits.
131  * \param chan struct.
132  * \param context
133  * \param collect
134  * \param size
135  * \param maxlen
136  * \param timeout timeout in milliseconds
137 */
138 int ast_app_dtget(struct ast_channel *chan, const char *context, char *collect, size_t size, int maxlen, int timeout)
139 {
140  struct ast_tone_zone_sound *ts;
141  int res = 0, x = 0;
142 
143  if (maxlen > size) {
144  maxlen = size;
145  }
146 
147  if (!timeout) {
148  if (ast_channel_pbx(chan) && ast_channel_pbx(chan)->dtimeoutms) {
149  timeout = ast_channel_pbx(chan)->dtimeoutms;
150  } else {
151  timeout = 5000;
152  }
153  }
154 
155  if ((ts = ast_get_indication_tone(ast_channel_zone(chan), "dial"))) {
156  res = ast_playtones_start(chan, 0, ts->data, 0);
157  ts = ast_tone_zone_sound_unref(ts);
158  } else {
159  ast_log(LOG_NOTICE, "Huh....? no dial for indications?\n");
160  }
161 
162  for (x = strlen(collect); x < maxlen; ) {
163  res = ast_waitfordigit(chan, timeout);
164  if (!ast_ignore_pattern(context, collect)) {
165  ast_playtones_stop(chan);
166  }
167  if (res < 1) {
168  break;
169  }
170  if (res == '#') {
171  break;
172  }
173  collect[x++] = res;
174  if (!ast_matchmore_extension(chan, context, collect, 1,
175  S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL))) {
176  break;
177  }
178  }
179 
180  if (res >= 0) {
181  res = ast_exists_extension(chan, context, collect, 1,
182  S_COR(ast_channel_caller(chan)->id.number.valid, ast_channel_caller(chan)->id.number.str, NULL)) ? 1 : 0;
183  }
184 
185  return res;
186 }
187 
188 enum ast_getdata_result ast_app_getdata(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout)
189 {
190  return ast_app_getdata_terminator(c, prompt, s, maxlen, timeout, NULL);
191 }
192 
193 enum ast_getdata_result ast_app_getdata_terminator(struct ast_channel *c, const char *prompt, char *s,
194  int maxlen, int timeout, char *terminator)
195 {
196  int res = 0, to, fto;
197  char *front, *filename;
198 
199  /* XXX Merge with full version? XXX */
200 
201  if (maxlen)
202  s[0] = '\0';
203 
204  if (!prompt)
205  prompt = "";
206 
207  filename = ast_strdupa(prompt);
208  while ((front = strsep(&filename, "&"))) {
209  if (!ast_strlen_zero(front)) {
210  res = ast_streamfile(c, front, ast_channel_language(c));
211  if (res)
212  continue;
213  }
214  if (ast_strlen_zero(filename)) {
215  /* set timeouts for the last prompt */
216  fto = ast_channel_pbx(c) ? ast_channel_pbx(c)->rtimeoutms : 6000;
217  to = ast_channel_pbx(c) ? ast_channel_pbx(c)->dtimeoutms : 2000;
218 
219  if (timeout > 0) {
220  fto = to = timeout;
221  }
222  if (timeout < 0) {
223  fto = to = 1000000000;
224  }
225  } else {
226  /* there is more than one prompt, so
227  * get rid of the long timeout between
228  * prompts, and make it 50ms */
229  fto = 50;
230  to = ast_channel_pbx(c) ? ast_channel_pbx(c)->dtimeoutms : 2000;
231  }
232  res = ast_readstring(c, s, maxlen, to, fto, (terminator ? terminator : "#"));
234  return res;
235  }
236  if (!ast_strlen_zero(s)) {
237  return res;
238  }
239  }
240 
241  return res;
242 }
243 
244 /* The lock type used by ast_lock_path() / ast_unlock_path() */
246 
247 int ast_app_getdata_full(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd)
248 {
249  int res, to = 2000, fto = 6000;
250 
251  if (!ast_strlen_zero(prompt)) {
253  if (res < 0) {
254  return res;
255  }
256  }
257 
258  if (timeout > 0) {
259  fto = to = timeout;
260  }
261  if (timeout < 0) {
262  fto = to = 1000000000;
263  }
264 
265  res = ast_readstring_full(c, s, maxlen, to, fto, "#", audiofd, ctrlfd);
266 
267  return res;
268 }
269 
270 int ast_app_exec_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const char *macro_args)
271 {
272  struct ast_app *macro_app;
273  int res;
274 
275  macro_app = pbx_findapp("Macro");
276  if (!macro_app) {
278  "Cannot run 'Macro(%s)'. The application is not available.\n", macro_args);
279  return -1;
280  }
281  if (autoservice_chan) {
282  ast_autoservice_start(autoservice_chan);
283  }
284 
285  ast_debug(4, "%s Original location: %s,%s,%d\n", ast_channel_name(macro_chan),
286  ast_channel_context(macro_chan), ast_channel_exten(macro_chan),
287  ast_channel_priority(macro_chan));
288 
289  res = pbx_exec(macro_chan, macro_app, macro_args);
290  ast_debug(4, "Macro exited with status %d\n", res);
291 
292  /*
293  * Assume anything negative from Macro is an error.
294  * Anything else is success.
295  */
296  if (res < 0) {
297  res = -1;
298  } else {
299  res = 0;
300  }
301 
302  ast_debug(4, "%s Ending location: %s,%s,%d\n", ast_channel_name(macro_chan),
303  ast_channel_context(macro_chan), ast_channel_exten(macro_chan),
304  ast_channel_priority(macro_chan));
305 
306  if (autoservice_chan) {
307  ast_autoservice_stop(autoservice_chan);
308  }
309 
310  if (ast_check_hangup_locked(macro_chan)) {
311  ast_queue_hangup(macro_chan);
312  }
313 
314  return res;
315 }
316 
317 int ast_app_run_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const char *macro_name, const char *macro_args)
318 {
319  int res;
320  char *args_str;
321  size_t args_len;
322 
323  if (ast_strlen_zero(macro_args)) {
324  return ast_app_exec_macro(autoservice_chan, macro_chan, macro_name);
325  }
326 
327  /* Create the Macro application argument string. */
328  args_len = strlen(macro_name) + strlen(macro_args) + 2;
329  args_str = ast_malloc(args_len);
330  if (!args_str) {
331  return -1;
332  }
333  snprintf(args_str, args_len, "%s,%s", macro_name, macro_args);
334 
335  res = ast_app_exec_macro(autoservice_chan, macro_chan, args_str);
336  ast_free(args_str);
337  return res;
338 }
339 
340 /* BUGBUG this is not thread safe. */
342 
344 {
345  app_stack_callbacks = funcs;
346 }
347 
348 const char *ast_app_expand_sub_args(struct ast_channel *chan, const char *args)
349 {
350  const struct ast_app_stack_funcs *funcs;
351  const char *new_args;
352 
353  funcs = app_stack_callbacks;
354  if (!funcs || !funcs->expand_sub_args || !ast_module_running_ref(funcs->module)) {
356  "Cannot expand 'Gosub(%s)' arguments. The app_stack module is not available.\n",
357  args);
358  return NULL;
359  }
360 
361  new_args = funcs->expand_sub_args(chan, args);
362  ast_module_unref(funcs->module);
363 
364  return new_args;
365 }
366 
367 int ast_app_exec_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int ignore_hangup)
368 {
369  const struct ast_app_stack_funcs *funcs;
370  int res;
371 
372  funcs = app_stack_callbacks;
373  if (!funcs || !funcs->run_sub || !ast_module_running_ref(funcs->module)) {
375  "Cannot run 'Gosub(%s)'. The app_stack module is not available.\n",
376  sub_args);
377  return -1;
378  }
379 
380  if (autoservice_chan) {
381  ast_autoservice_start(autoservice_chan);
382  }
383 
384  res = funcs->run_sub(sub_chan, sub_args, ignore_hangup);
385  ast_module_unref(funcs->module);
386 
387  if (autoservice_chan) {
388  ast_autoservice_stop(autoservice_chan);
389  }
390 
391  if (!ignore_hangup && ast_check_hangup_locked(sub_chan)) {
392  ast_queue_hangup(sub_chan);
393  }
394 
395  return res;
396 }
397 
398 int ast_app_run_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_location, const char *sub_args, int ignore_hangup)
399 {
400  int res;
401  char *args_str;
402  size_t args_len;
403 
404  if (ast_strlen_zero(sub_args)) {
405  return ast_app_exec_sub(autoservice_chan, sub_chan, sub_location, ignore_hangup);
406  }
407 
408  /* Create the Gosub application argument string. */
409  args_len = strlen(sub_location) + strlen(sub_args) + 3;
410  args_str = ast_malloc(args_len);
411  if (!args_str) {
412  return -1;
413  }
414  snprintf(args_str, args_len, "%s(%s)", sub_location, sub_args);
415 
416  res = ast_app_exec_sub(autoservice_chan, sub_chan, args_str, ignore_hangup);
417  ast_free(args_str);
418  return res;
419 }
420 
421 /*! \brief The container for the voicemail provider */
422 static AO2_GLOBAL_OBJ_STATIC(vm_provider);
423 
424 /*! Voicemail not registered warning */
425 static int vm_warnings;
426 
428 {
429  struct ast_vm_functions *table;
430  int is_registered;
431 
432  table = ao2_global_obj_ref(vm_provider);
433  is_registered = table ? 1 : 0;
435  return is_registered;
436 }
437 
439 {
441 
442  if (!vm_table->module_name) {
443  ast_log(LOG_ERROR, "Voicemail provider missing required information.\n");
444  return -1;
445  }
447  ast_log(LOG_ERROR, "Voicemail provider '%s' has incorrect version\n",
449  return -1;
450  }
451 
452  table = ao2_global_obj_ref(vm_provider);
453  if (table) {
454  ast_log(LOG_WARNING, "Voicemail provider already registered by %s.\n",
455  table->module_name);
457  }
458 
460  if (!table) {
461  return -1;
462  }
463  *table = *vm_table;
464  table->module = module;
465 
466  ao2_global_obj_replace_unref(vm_provider, table);
467  return 0;
468 }
469 
471 {
472  struct ast_vm_functions *table;
473 
474  table = ao2_global_obj_ref(vm_provider);
475  if (table && !strcmp(table->module_name, module_name)) {
476  ao2_global_obj_release(vm_provider);
477  }
479 }
480 
481 #ifdef TEST_FRAMEWORK
482 /*! \brief Holding container for the voicemail provider used while testing */
483 static AO2_GLOBAL_OBJ_STATIC(vm_provider_holder);
484 static int provider_is_swapped = 0;
485 
486 void ast_vm_test_swap_table_in(const struct ast_vm_functions *vm_table)
487 {
488  RAII_VAR(struct ast_vm_functions *, holding_table, NULL, ao2_cleanup);
489  RAII_VAR(struct ast_vm_functions *, new_table, NULL, ao2_cleanup);
490 
491  if (provider_is_swapped) {
492  ast_log(LOG_ERROR, "Attempted to swap in test function table without swapping out old test table.\n");
493  return;
494  }
495 
496  holding_table = ao2_global_obj_ref(vm_provider);
497 
498  if (holding_table) {
499  ao2_global_obj_replace_unref(vm_provider_holder, holding_table);
500  }
501 
502  new_table = ao2_alloc_options(sizeof(*new_table), NULL, AO2_ALLOC_OPT_LOCK_NOLOCK);
503  if (!new_table) {
504  return;
505  }
506  *new_table = *vm_table;
507 
508  ao2_global_obj_replace_unref(vm_provider, new_table);
509  provider_is_swapped = 1;
510 }
511 
512 void ast_vm_test_swap_table_out(void)
513 {
514  RAII_VAR(struct ast_vm_functions *, held_table, NULL, ao2_cleanup);
515 
516  if (!provider_is_swapped) {
517  ast_log(LOG_ERROR, "Attempted to swap out test function table, but none is currently installed.\n");
518  return;
519  }
520 
521  held_table = ao2_global_obj_ref(vm_provider_holder);
522  if (!held_table) {
523  return;
524  }
525 
526  ao2_global_obj_replace_unref(vm_provider, held_table);
527  ao2_global_obj_release(vm_provider_holder);
528  provider_is_swapped = 0;
529 }
530 #endif
531 
532 /*! \brief The container for the voicemail greeter provider */
533 static AO2_GLOBAL_OBJ_STATIC(vm_greeter_provider);
534 
535 /*! Voicemail greeter not registered warning */
537 
539 {
541  int is_registered;
542 
543  table = ao2_global_obj_ref(vm_greeter_provider);
544  is_registered = table ? 1 : 0;
546  return is_registered;
547 }
548 
550 {
552 
553  if (!vm_table->module_name) {
554  ast_log(LOG_ERROR, "Voicemail greeter provider missing required information.\n");
555  return -1;
556  }
558  ast_log(LOG_ERROR, "Voicemail greeter provider '%s' has incorrect version\n",
560  return -1;
561  }
562 
563  table = ao2_global_obj_ref(vm_greeter_provider);
564  if (table) {
565  ast_log(LOG_WARNING, "Voicemail greeter provider already registered by %s.\n",
566  table->module_name);
568  }
569 
571  if (!table) {
572  return -1;
573  }
574  *table = *vm_table;
575  table->module = module;
576 
577  ao2_global_obj_replace_unref(vm_greeter_provider, table);
578  return 0;
579 }
580 
582 {
584 
585  table = ao2_global_obj_ref(vm_greeter_provider);
586  if (table && !strcmp(table->module_name, module_name)) {
587  ao2_global_obj_release(vm_greeter_provider);
588  }
590 }
591 
592 #ifdef TEST_FRAMEWORK
593 static ast_vm_test_create_user_fn *ast_vm_test_create_user_func = NULL;
594 static ast_vm_test_destroy_user_fn *ast_vm_test_destroy_user_func = NULL;
595 
596 void ast_install_vm_test_functions(ast_vm_test_create_user_fn *vm_test_create_user_func,
597  ast_vm_test_destroy_user_fn *vm_test_destroy_user_func)
598 {
599  ast_vm_test_create_user_func = vm_test_create_user_func;
600  ast_vm_test_destroy_user_func = vm_test_destroy_user_func;
601 }
602 
603 void ast_uninstall_vm_test_functions(void)
604 {
605  ast_vm_test_create_user_func = NULL;
606  ast_vm_test_destroy_user_func = NULL;
607 }
608 #endif
609 
610 static void vm_warn_no_provider(void)
611 {
612  if (vm_warnings++ % 10 == 0) {
613  ast_verb(3, "No voicemail provider registered.\n");
614  }
615 }
616 
617 #define VM_API_CALL(res, api_call, api_parms) \
618  do { \
619  struct ast_vm_functions *table; \
620  table = ao2_global_obj_ref(vm_provider); \
621  if (!table) { \
622  vm_warn_no_provider(); \
623  } else if (table->api_call) { \
624  ast_module_ref(table->module); \
625  (res) = table->api_call api_parms; \
626  ast_module_unref(table->module); \
627  } \
628  ao2_cleanup(table); \
629  } while (0)
630 
632 {
633  if (vm_greeter_warnings++ % 10 == 0) {
634  ast_verb(3, "No voicemail greeter provider registered.\n");
635  }
636 }
637 
638 #define VM_GREETER_API_CALL(res, api_call, api_parms) \
639  do { \
640  struct ast_vm_greeter_functions *table; \
641  table = ao2_global_obj_ref(vm_greeter_provider); \
642  if (!table) { \
643  vm_greeter_warn_no_provider(); \
644  } else if (table->api_call) { \
645  ast_module_ref(table->module); \
646  (res) = table->api_call api_parms; \
647  ast_module_unref(table->module); \
648  } \
649  ao2_cleanup(table); \
650  } while (0)
651 
652 int ast_app_has_voicemail(const char *mailboxes, const char *folder)
653 {
654  int res = 0;
655 
656  VM_API_CALL(res, has_voicemail, (mailboxes, folder));
657  return res;
658 }
659 
660 /*!
661  * \internal
662  * \brief Function used as a callback for ast_copy_recording_to_vm when a real one isn't installed.
663  * \param vm_rec_data Stores crucial information about the voicemail that will basically just be used
664  * to figure out what the name of the recipient was supposed to be
665  */
667 {
668  int res = -1;
669 
670  VM_API_CALL(res, copy_recording_to_vm, (vm_rec_data));
671  return res;
672 }
673 
674 int ast_app_inboxcount(const char *mailboxes, int *newmsgs, int *oldmsgs)
675 {
676  int res = 0;
677 
678  if (newmsgs) {
679  *newmsgs = 0;
680  }
681  if (oldmsgs) {
682  *oldmsgs = 0;
683  }
684 
685  VM_API_CALL(res, inboxcount, (mailboxes, newmsgs, oldmsgs));
686  return res;
687 }
688 
689 int ast_app_inboxcount2(const char *mailboxes, int *urgentmsgs, int *newmsgs, int *oldmsgs)
690 {
691  int res = 0;
692 
693  if (newmsgs) {
694  *newmsgs = 0;
695  }
696  if (oldmsgs) {
697  *oldmsgs = 0;
698  }
699  if (urgentmsgs) {
700  *urgentmsgs = 0;
701  }
702 
703  VM_API_CALL(res, inboxcount2, (mailboxes, urgentmsgs, newmsgs, oldmsgs));
704  return res;
705 }
706 
707 int ast_app_sayname(struct ast_channel *chan, const char *mailbox_id)
708 {
709  int res = -1;
710 
711  VM_GREETER_API_CALL(res, sayname, (chan, mailbox_id));
712  return res;
713 }
714 
715 int ast_app_messagecount(const char *mailbox_id, const char *folder)
716 {
717  int res = 0;
718 
719  VM_API_CALL(res, messagecount, (mailbox_id, folder));
720  return res;
721 }
722 
723 const char *ast_vm_index_to_foldername(int id)
724 {
725  const char *res = NULL;
726 
727  VM_API_CALL(res, index_to_foldername, (id));
728  return res;
729 }
730 
732  const char *context,
733  const char *folder,
734  int descending,
735  enum ast_vm_snapshot_sort_val sort_val,
736  int combine_INBOX_and_OLD)
737 {
738  struct ast_vm_mailbox_snapshot *res = NULL;
739 
740  VM_API_CALL(res, mailbox_snapshot_create, (mailbox, context, folder, descending,
741  sort_val, combine_INBOX_and_OLD));
742  return res;
743 }
744 
746 {
747  struct ast_vm_mailbox_snapshot *res = NULL;
748 
749  VM_API_CALL(res, mailbox_snapshot_destroy, (mailbox_snapshot));
750  return res;
751 }
752 
753 int ast_vm_msg_move(const char *mailbox,
754  const char *context,
755  size_t num_msgs,
756  const char *oldfolder,
757  const char *old_msg_ids[],
758  const char *newfolder)
759 {
760  int res = 0;
761 
762  VM_API_CALL(res, msg_move, (mailbox, context, num_msgs, oldfolder, old_msg_ids,
763  newfolder));
764  return res;
765 }
766 
767 int ast_vm_msg_remove(const char *mailbox,
768  const char *context,
769  size_t num_msgs,
770  const char *folder,
771  const char *msgs[])
772 {
773  int res = 0;
774 
775  VM_API_CALL(res, msg_remove, (mailbox, context, num_msgs, folder, msgs));
776  return res;
777 }
778 
780  const char *from_context,
781  const char *from_folder,
782  const char *to_mailbox,
783  const char *to_context,
784  const char *to_folder,
785  size_t num_msgs,
786  const char *msg_ids[],
787  int delete_old)
788 {
789  int res = 0;
790 
791  VM_API_CALL(res, msg_forward, (from_mailbox, from_context, from_folder, to_mailbox,
792  to_context, to_folder, num_msgs, msg_ids, delete_old));
793  return res;
794 }
795 
796 int ast_vm_msg_play(struct ast_channel *chan,
797  const char *mailbox,
798  const char *context,
799  const char *folder,
800  const char *msg_num,
801  ast_vm_msg_play_cb *cb)
802 {
803  int res = 0;
804 
805  VM_API_CALL(res, msg_play, (chan, mailbox, context, folder, msg_num, cb));
806  return res;
807 }
808 
809 #ifdef TEST_FRAMEWORK
810 int ast_vm_test_create_user(const char *context, const char *mailbox)
811 {
812  if (ast_vm_test_create_user_func) {
813  return ast_vm_test_create_user_func(context, mailbox);
814  }
815  return 0;
816 }
817 
818 int ast_vm_test_destroy_user(const char *context, const char *mailbox)
819 {
820  if (ast_vm_test_destroy_user_func) {
821  return ast_vm_test_destroy_user_func(context, mailbox);
822  }
823  return 0;
824 }
825 #endif
826 
827 static int external_sleep(struct ast_channel *chan, int ms)
828 {
829  usleep(ms * 1000);
830  return 0;
831 }
832 
833 static int sf_stream(struct ast_channel *chan, struct ast_channel *chan2, const char *digits, int frequency, int is_external)
834 {
835  /* Bell System Technical Journal 39 (Nov. 1960) */
836  #define SF_ON 67
837  #define SF_OFF 33
838  #define SF_BETWEEN 600
839 
840  const char *ptr;
841  int res;
842  struct ast_silence_generator *silgen = NULL, *silgen2 = NULL;
843  char *freq;
844  int (*my_sleep)(struct ast_channel *chan, int ms);
845 
846  if (frequency >= 100000) {
847  ast_log(LOG_WARNING, "Frequency too large: %d\n", frequency);
848  return -1;
849  }
850 
851  if (is_external) {
852  my_sleep = external_sleep;
853  } else {
854  my_sleep = ast_safe_sleep;
855  }
856 
857  /* Need a quiet time before sending digits. */
860  if (chan2) {
861  silgen2 = ast_channel_start_silence_generator(chan2);
862  }
863  }
864  if (chan2) {
865  ast_autoservice_start(chan2);
866  }
867  res = my_sleep(chan, 100);
868  if (chan2) {
869  ast_autoservice_stop(chan2);
870  }
871  if (res) {
872  goto sf_stream_cleanup;
873  }
874 
875 /* len(SF_ON) + len(SF_OFF) + len(0) + maxlen(frequency) + /,/ + null terminator = 2 + 2 + 1 + 5 at most + 3 + 1 = 14 */
876 #define SF_BUF_LEN 20
877  freq = ast_alloca(SF_BUF_LEN); /* min 20 to avoid compiler warning about insufficient buffer */
878  /* pauses need to send audio, so send 0 Hz */
879  snprintf(freq, SF_BUF_LEN, "%d/%d,%d/%d", frequency, SF_ON, 0, SF_OFF);
880 
881  for (ptr = digits; *ptr; ptr++) {
882  if (*ptr == 'w') {
883  /* 'w' -- wait half a second */
884  if (chan2) {
885  ast_autoservice_start(chan2);
886  }
887  res = my_sleep(chan, 500);
888  if (chan2) {
889  ast_autoservice_stop(chan2);
890  }
891  if (res) {
892  break;
893  }
894  } else if (*ptr == 'h' || *ptr == 'H') {
895  /* 'h' -- 2600 Hz for half a second, but
896  only to far end of trunk, not near end */
897  ast_playtones_start(chan, 0, "2600", 0);
898  if (chan2) {
899  ast_playtones_start(chan2, 0, "0", 0);
900  ast_autoservice_start(chan2);
901  }
902  res = my_sleep(chan, 250);
903  ast_senddigit_mf_end(chan);
904  if (chan2) {
905  ast_autoservice_stop(chan2);
906  ast_senddigit_mf_end(chan2);
907  }
908  if (res) {
909  break;
910  }
911  } else if (strchr("0123456789*#ABCDabcdwWfF", *ptr)) {
912  if (*ptr == 'f' || *ptr == 'F') {
913  /* ignore return values if not supported by channel */
915  } else if (*ptr == 'W') {
916  /* ignore return values if not supported by channel */
918  } else {
919  /* Character represents valid SF */
920  int beeps;
921  if (*ptr == '*') {
922  beeps = 11;
923  } else if (*ptr == '#') {
924  beeps = 12;
925  } else if (*ptr == 'D') {
926  beeps = 13;
927  } else if (*ptr == 'C') {
928  beeps = 14;
929  } else if (*ptr == 'B') {
930  beeps = 15;
931  } else if (*ptr == 'A') {
932  beeps = 16;
933  } else {
934  beeps = (*ptr == '0') ? 10 : *ptr - '0';
935  }
936  while (beeps-- > 0) {
937  ast_playtones_start(chan, 0, freq, 0);
938  if (chan2) {
939  ast_playtones_start(chan2, 0, freq, 0);
940  ast_autoservice_start(chan2);
941  }
942  res = my_sleep(chan, SF_ON + SF_OFF);
943  ast_senddigit_mf_end(chan);
944  if (chan2) {
945  ast_autoservice_stop(chan2);
946  ast_senddigit_mf_end(chan2);
947  }
948  if (res) {
949  break;
950  }
951  }
952  }
953  /* pause between digits */
954  ast_playtones_start(chan, 0, "0", 0);
955  if (chan2) {
956  ast_playtones_start(chan2, 0, "0", 0);
957  ast_autoservice_start(chan2);
958  }
959  res = my_sleep(chan, SF_BETWEEN);
960  if (chan2) {
961  ast_autoservice_stop(chan2);
962  ast_senddigit_mf_end(chan2);
963  }
964  ast_senddigit_mf_end(chan);
965  if (res) {
966  break;
967  }
968  } else {
969  ast_log(LOG_WARNING, "Illegal SF character '%c' in string. (0-9A-DwWfFhH allowed)\n", *ptr);
970  }
971  }
972 
973 sf_stream_cleanup:
974  if (silgen) {
976  }
977  if (silgen2) {
978  ast_channel_stop_silence_generator(chan2, silgen2);
979  }
980 
981  return res;
982 }
983 
984 static int mf_stream(struct ast_channel *chan, struct ast_channel *chan2, const char *digits, int between, unsigned int duration,
985  unsigned int durationkp, unsigned int durationst, int is_external)
986 {
987  const char *ptr;
988  int res;
989  struct ast_silence_generator *silgen = NULL, *silgen2 = NULL;
990  int (*my_sleep)(struct ast_channel *chan, int ms);
991 
992  if (is_external) {
993  my_sleep = external_sleep;
994  } else {
995  my_sleep = ast_safe_sleep;
996  }
997 
998  if (!between) {
999  between = 100;
1000  }
1001 
1002  /* Need a quiet time before sending digits. */
1004  silgen = ast_channel_start_silence_generator(chan);
1005  if (chan2) {
1006  silgen2 = ast_channel_start_silence_generator(chan2);
1007  }
1008  }
1009  if (chan2) {
1010  ast_autoservice_start(chan2);
1011  }
1012  res = my_sleep(chan, 100);
1013  if (chan2) {
1014  ast_autoservice_stop(chan2);
1015  }
1016  if (res) {
1017  goto mf_stream_cleanup;
1018  }
1019 
1020  for (ptr = digits; *ptr; ptr++) {
1021  if (*ptr == 'w') {
1022  /* 'w' -- wait half a second */
1023  if (chan2) {
1024  ast_autoservice_start(chan2);
1025  }
1026  res = my_sleep(chan, 500);
1027  if (chan2) {
1028  ast_autoservice_stop(chan2);
1029  }
1030  if (res) {
1031  break;
1032  }
1033  } else if (*ptr == 'h' || *ptr == 'H') {
1034  /* 'h' -- 2600 Hz for half a second, but
1035  only to far end of trunk, not near end */
1036  ast_playtones_start(chan, 0, "2600", 0);
1037  if (chan2) {
1038  ast_playtones_start(chan2, 0, "0", 0);
1039  ast_autoservice_start(chan2);
1040  }
1041  res = my_sleep(chan, 250);
1042  ast_senddigit_mf_end(chan);
1043  if (chan2) {
1044  ast_autoservice_stop(chan2);
1045  ast_senddigit_mf_end(chan2);
1046  }
1047  if (res) {
1048  break;
1049  }
1050  } else if (strchr("0123456789*#ABCwWfF", *ptr)) {
1051  if (*ptr == 'f' || *ptr == 'F') {
1052  /* ignore return values if not supported by channel */
1054  } else if (*ptr == 'W') {
1055  /* ignore return values if not supported by channel */
1057  } else {
1058  /* Character represents valid MF */
1059  ast_senddigit_mf(chan, *ptr, duration, durationkp, durationst, is_external);
1060  if (chan2) {
1061  ast_senddigit_mf(chan2, *ptr, duration, durationkp, durationst, is_external);
1062  }
1063  }
1064  /* pause between digits */
1065  /* The DSP code in Asterisk does not currently properly receive repeated tones
1066  if no audio is sent in the middle. Simply sending audio (even 0 Hz)
1067  works around this limitation and guarantees the correct behavior.
1068  */
1069  ast_playtones_start(chan, 0, "0", 0);
1070  if (chan2) {
1071  ast_playtones_start(chan2, 0, "0", 0);
1072  ast_autoservice_start(chan2);
1073  }
1074  res = my_sleep(chan, between);
1075  ast_senddigit_mf_end(chan);
1076  if (chan2) {
1077  ast_autoservice_stop(chan2);
1078  ast_senddigit_mf_end(chan2);
1079  }
1080  if (res) {
1081  break;
1082  }
1083  } else {
1084  ast_log(LOG_WARNING, "Illegal MF character '%c' in string. (0-9*#ABCwWfFhH allowed)\n", *ptr);
1085  }
1086  }
1087 
1088 mf_stream_cleanup:
1089  if (silgen) {
1090  ast_channel_stop_silence_generator(chan, silgen);
1091  }
1092  if (silgen2) {
1093  ast_channel_stop_silence_generator(chan2, silgen2);
1094  }
1095 
1096  return res;
1097 }
1098 
1099 static int dtmf_stream(struct ast_channel *chan, const char *digits, int between, unsigned int duration, int is_external)
1100 {
1101  const char *ptr;
1102  int res;
1103  struct ast_silence_generator *silgen = NULL;
1104  int (*my_sleep)(struct ast_channel *chan, int ms);
1105  int (*my_senddigit)(struct ast_channel *chan, char digit, unsigned int duration);
1106 
1107  if (is_external) {
1108  my_sleep = external_sleep;
1109  my_senddigit = ast_senddigit_external;
1110  } else {
1111  my_sleep = ast_safe_sleep;
1112  my_senddigit = ast_senddigit;
1113  }
1114 
1115  if (!between) {
1116  between = 100;
1117  }
1118 
1119  /* Need a quiet time before sending digits. */
1121  silgen = ast_channel_start_silence_generator(chan);
1122  }
1123  res = my_sleep(chan, 100);
1124  if (res) {
1125  goto dtmf_stream_cleanup;
1126  }
1127 
1128  for (ptr = digits; *ptr; ptr++) {
1129  if (*ptr == 'w') {
1130  /* 'w' -- wait half a second */
1131  res = my_sleep(chan, 500);
1132  if (res) {
1133  break;
1134  }
1135  } else if (*ptr == 'W') {
1136  /* 'W' -- wait a second */
1137  res = my_sleep(chan, 1000);
1138  if (res) {
1139  break;
1140  }
1141  } else if (strchr("0123456789*#abcdfABCDF", *ptr)) {
1142  if (*ptr == 'f' || *ptr == 'F') {
1143  /* ignore return values if not supported by channel */
1145  } else {
1146  /* Character represents valid DTMF */
1147  my_senddigit(chan, *ptr, duration);
1148  }
1149  /* pause between digits */
1150  res = my_sleep(chan, between);
1151  if (res) {
1152  break;
1153  }
1154  } else {
1155  ast_log(LOG_WARNING, "Illegal DTMF character '%c' in string. (0-9*#aAbBcCdD allowed)\n", *ptr);
1156  }
1157  }
1158 
1159 dtmf_stream_cleanup:
1160  if (silgen) {
1161  ast_channel_stop_silence_generator(chan, silgen);
1162  }
1163 
1164  return res;
1165 }
1166 
1167 int ast_sf_stream(struct ast_channel *chan, struct ast_channel *peer, struct ast_channel *chan2, const char *digits, int frequency, int is_external)
1168 {
1169  int res;
1170  if (frequency <= 0) {
1171  frequency = 2600;
1172  }
1173  if (!is_external && !chan2 && peer && ast_autoservice_start(peer)) {
1174  return -1;
1175  }
1176  res = sf_stream(chan, chan2, digits, frequency, is_external);
1177  if (!is_external && !chan2 && peer && ast_autoservice_stop(peer)) {
1178  res = -1;
1179  }
1180  return res;
1181 }
1182 
1183 int ast_mf_stream(struct ast_channel *chan, struct ast_channel *peer, struct ast_channel *chan2, const char *digits,
1184  int between, unsigned int duration, unsigned int durationkp, unsigned int durationst, int is_external)
1185 {
1186  int res;
1187  if (!is_external && !chan2 && peer && ast_autoservice_start(peer)) {
1188  return -1;
1189  }
1190  res = mf_stream(chan, chan2, digits, between, duration, durationkp, durationst, is_external);
1191  if (!is_external && !chan2 && peer && ast_autoservice_stop(peer)) {
1192  res = -1;
1193  }
1194  return res;
1195 }
1196 
1197 int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between, unsigned int duration)
1198 {
1199  int res;
1200 
1201  if (peer && ast_autoservice_start(peer)) {
1202  return -1;
1203  }
1204  res = dtmf_stream(chan, digits, between, duration, 0);
1205  if (peer && ast_autoservice_stop(peer)) {
1206  res = -1;
1207  }
1208 
1209  return res;
1210 }
1211 
1212 void ast_dtmf_stream_external(struct ast_channel *chan, const char *digits, int between, unsigned int duration)
1213 {
1214  dtmf_stream(chan, digits, between, duration, 1);
1215 }
1216 
1218  int fd;
1222 };
1223 
1224 static void linear_release(struct ast_channel *chan, void *params)
1225 {
1226  struct linear_state *ls = params;
1227 
1228  if (ls->origwfmt && ast_set_write_format(chan, ls->origwfmt)) {
1229  ast_log(LOG_WARNING, "Unable to restore channel '%s' to format '%s'\n",
1231  }
1232  ao2_cleanup(ls->origwfmt);
1233 
1234  if (ls->autoclose) {
1235  close(ls->fd);
1236  }
1237 
1238  ast_free(params);
1239 }
1240 
1241 static int linear_generator(struct ast_channel *chan, void *data, int len, int samples)
1242 {
1243  short buf[2048 + AST_FRIENDLY_OFFSET / 2];
1244  struct linear_state *ls = data;
1245  struct ast_frame f = {
1247  .data.ptr = buf + AST_FRIENDLY_OFFSET / 2,
1248  .offset = AST_FRIENDLY_OFFSET,
1249  };
1250  int res;
1251 
1253 
1254  len = samples * 2;
1255  if (len > sizeof(buf) - AST_FRIENDLY_OFFSET) {
1256  ast_log(LOG_WARNING, "Can't generate %d bytes of data!\n" , len);
1257  len = sizeof(buf) - AST_FRIENDLY_OFFSET;
1258  }
1259  res = read(ls->fd, buf + AST_FRIENDLY_OFFSET/2, len);
1260  if (res > 0) {
1261  f.datalen = res;
1262  f.samples = res / 2;
1263  ast_write(chan, &f);
1264  if (res == len) {
1265  return 0;
1266  }
1267  }
1268  return -1;
1269 }
1270 
1271 static void *linear_alloc(struct ast_channel *chan, void *params)
1272 {
1273  struct linear_state *ls = params;
1274 
1275  if (!params) {
1276  return NULL;
1277  }
1278 
1279  /* In this case, params is already malloc'd */
1280  if (ls->allowoverride) {
1282  } else {
1284  }
1285 
1287 
1289  ast_log(LOG_WARNING, "Unable to set '%s' to linear format (write)\n", ast_channel_name(chan));
1290  ao2_cleanup(ls->origwfmt);
1291  ast_free(ls);
1292  ls = params = NULL;
1293  }
1294 
1295  return params;
1296 }
1297 
1298 static struct ast_generator linearstream =
1299 {
1300  .alloc = linear_alloc,
1301  .release = linear_release,
1302  .generate = linear_generator,
1303 };
1304 
1305 int ast_linear_stream(struct ast_channel *chan, const char *filename, int fd, int allowoverride)
1306 {
1307  struct linear_state *lin;
1308  char tmpf[256];
1309  int autoclose = 0;
1310 
1311  if (fd < 0) {
1312  if (ast_strlen_zero(filename)) {
1313  return -1;
1314  }
1315 
1316  autoclose = 1;
1317 
1318  if (filename[0] == '/') {
1319  ast_copy_string(tmpf, filename, sizeof(tmpf));
1320  } else {
1321  snprintf(tmpf, sizeof(tmpf), "%s/%s/%s", ast_config_AST_DATA_DIR, "sounds", filename);
1322  }
1323 
1324  fd = open(tmpf, O_RDONLY);
1325  if (fd < 0) {
1326  ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", tmpf, strerror(errno));
1327  return -1;
1328  }
1329  }
1330 
1331  lin = ast_calloc(1, sizeof(*lin));
1332  if (!lin) {
1333  if (autoclose) {
1334  close(fd);
1335  }
1336 
1337  return -1;
1338  }
1339 
1340  lin->fd = fd;
1342  lin->autoclose = autoclose;
1343 
1344  return ast_activate_generator(chan, &linearstream, lin);
1345 }
1346 
1347 static int control_streamfile(struct ast_channel *chan,
1348  const char *file,
1349  const char *fwd,
1350  const char *rev,
1351  const char *stop,
1352  const char *suspend,
1353  const char *restart,
1354  int skipms,
1355  long *offsetms,
1356  const char *lang,
1358 {
1359  char *breaks = NULL;
1360  char *end = NULL;
1361  int blen = 2;
1362  int res;
1363  long pause_restart_point = 0;
1364  long offset = 0;
1365  struct ast_silence_generator *silgen = NULL;
1366 
1367  if (!file) {
1368  return -1;
1369  }
1370  if (offsetms) {
1371  offset = *offsetms * 8; /* XXX Assumes 8kHz */
1372  }
1373  if (lang == NULL) {
1374  lang = ast_channel_language(chan);
1375  }
1376 
1377  if (stop) {
1378  blen += strlen(stop);
1379  }
1380  if (suspend) {
1381  blen += strlen(suspend);
1382  }
1383  if (restart) {
1384  blen += strlen(restart);
1385  }
1386 
1387  if (blen > 2) {
1388  breaks = ast_alloca(blen + 1);
1389  breaks[0] = '\0';
1390  if (stop) {
1391  strcat(breaks, stop);
1392  }
1393  if (suspend) {
1394  strcat(breaks, suspend);
1395  }
1396  if (restart) {
1397  strcat(breaks, restart);
1398  }
1399  }
1400 
1401  if ((end = strchr(file, ':'))) {
1402  if (!strcasecmp(end, ":end")) {
1403  *end = '\0';
1404  end++;
1405  } else {
1406  end = NULL;
1407  }
1408  }
1409 
1410  for (;;) {
1411  ast_stopstream(chan);
1412  res = ast_streamfile(chan, file, lang);
1413  if (!res) {
1414  if (pause_restart_point) {
1415  ast_seekstream(ast_channel_stream(chan), pause_restart_point, SEEK_SET);
1416  pause_restart_point = 0;
1417  }
1418  else if (end || offset < 0) {
1419  if (offset == -8) {
1420  offset = 0;
1421  }
1422  ast_verb(3, "ControlPlayback seek to offset %ld from end\n", offset);
1423 
1424  ast_seekstream(ast_channel_stream(chan), offset, SEEK_END);
1425  end = NULL;
1426  offset = 0;
1427  } else if (offset) {
1428  ast_verb(3, "ControlPlayback seek to offset %ld\n", offset);
1429  ast_seekstream(ast_channel_stream(chan), offset, SEEK_SET);
1430  offset = 0;
1431  }
1432  if (cb) {
1433  res = ast_waitstream_fr_w_cb(chan, breaks, fwd, rev, skipms, cb);
1434  } else {
1435  res = ast_waitstream_fr(chan, breaks, fwd, rev, skipms);
1436  }
1437  }
1438 
1439  if (res < 1) {
1440  break;
1441  }
1442 
1443  /* We go at next loop if we got the restart char */
1444  if ((restart && strchr(restart, res)) || res == AST_CONTROL_STREAM_RESTART) {
1445  ast_debug(1, "we'll restart the stream here at next loop\n");
1446  pause_restart_point = 0;
1447  ast_test_suite_event_notify("PLAYBACK","Channel: %s\r\n"
1448  "Control: %s\r\n",
1449  ast_channel_name(chan),
1450  "Restart");
1451  continue;
1452  }
1453 
1454  if ((suspend && strchr(suspend, res)) || res == AST_CONTROL_STREAM_SUSPEND) {
1455  pause_restart_point = ast_tellstream(ast_channel_stream(chan));
1456 
1458  silgen = ast_channel_start_silence_generator(chan);
1459  }
1460  ast_test_suite_event_notify("PLAYBACK","Channel: %s\r\n"
1461  "Control: %s\r\n",
1462  ast_channel_name(chan),
1463  "Pause");
1464  for (;;) {
1465  ast_stopstream(chan);
1466  if (!(res = ast_waitfordigit(chan, 1000))) {
1467  continue;
1468  } else if (res == -1 || (suspend && strchr(suspend, res)) || (stop && strchr(stop, res))
1470  break;
1471  }
1472  }
1473  if (silgen) {
1474  ast_channel_stop_silence_generator(chan, silgen);
1475  silgen = NULL;
1476  }
1477 
1478  if ((suspend && (res == *suspend)) || res == AST_CONTROL_STREAM_SUSPEND) {
1479  res = 0;
1480  ast_test_suite_event_notify("PLAYBACK","Channel: %s\r\n"
1481  "Control: %s\r\n",
1482  ast_channel_name(chan),
1483  "Unpause");
1484  continue;
1485  }
1486  }
1487 
1488  if (res == -1) {
1489  break;
1490  }
1491 
1492  /* if we get one of our stop chars, return it to the calling function */
1493  if ((stop && strchr(stop, res)) || res == AST_CONTROL_STREAM_STOP) {
1494  ast_test_suite_event_notify("PLAYBACK","Channel: %s\r\n"
1495  "Control: %s\r\n",
1496  ast_channel_name(chan),
1497  "Stop");
1498  break;
1499  }
1500  }
1501 
1502  if (pause_restart_point) {
1503  offset = pause_restart_point;
1504  } else {
1505  if (ast_channel_stream(chan)) {
1506  offset = ast_tellstream(ast_channel_stream(chan));
1507  } else {
1508  offset = -8; /* indicate end of file */
1509  }
1510  }
1511 
1512  if (offsetms) {
1513  *offsetms = offset / 8; /* samples --> ms ... XXX Assumes 8 kHz */
1514  }
1515 
1516  ast_stopstream(chan);
1517 
1518  return res;
1519 }
1520 
1522  const char *file,
1523  const char *fwd,
1524  const char *rev,
1525  const char *stop,
1526  const char *suspend,
1527  const char *restart,
1528  int skipms,
1529  long *offsetms,
1531 {
1532  return control_streamfile(chan, file, fwd, rev, stop, suspend, restart, skipms, offsetms, NULL, cb);
1533 }
1534 
1535 int ast_control_streamfile(struct ast_channel *chan, const char *file,
1536  const char *fwd, const char *rev,
1537  const char *stop, const char *suspend,
1538  const char *restart, int skipms, long *offsetms)
1539 {
1540  return control_streamfile(chan, file, fwd, rev, stop, suspend, restart, skipms, offsetms, NULL, NULL);
1541 }
1542 
1543 int ast_control_streamfile_lang(struct ast_channel *chan, const char *file,
1544  const char *fwd, const char *rev, const char *stop, const char *suspend,
1545  const char *restart, int skipms, const char *lang, long *offsetms)
1546 {
1547  return control_streamfile(chan, file, fwd, rev, stop, suspend, restart, skipms, offsetms, lang, NULL);
1548 }
1549 
1554 };
1555 
1556 static enum control_tone_frame_response_result control_tone_frame_response(struct ast_channel *chan, struct ast_frame *fr, struct ast_tone_zone_sound *ts, const char *tone, int *paused)
1557 {
1558  switch (fr->subclass.integer) {
1560  ast_playtones_stop(chan);
1563  if (*paused) {
1564  *paused = 0;
1565  if (ast_playtones_start(chan, 0, ts ? ts->data : tone, 0)) {
1567  }
1568  } else {
1569  *paused = 1;
1570  ast_playtones_stop(chan);
1571  }
1574  ast_playtones_stop(chan);
1575  if (ast_playtones_start(chan, 0, ts ? ts->data : tone, 0)) {
1577  }
1580  ast_log(LOG_NOTICE, "Media control operation 'reverse' not supported for media type 'tone'\n");
1583  ast_log(LOG_NOTICE, "Media control operation 'forward' not supported for media type 'tone'\n");
1585  case AST_CONTROL_HANGUP:
1586  case AST_CONTROL_BUSY:
1589  }
1590 
1592 }
1593 
1594 static int parse_tone_uri(char *tone_parser,
1595  const char **tone_indication,
1596  const char **tone_zone)
1597 {
1598  *tone_indication = strsep(&tone_parser, ";");
1599 
1600  if (ast_strlen_zero(tone_parser)) {
1601  /* Only the indication is included */
1602  return 0;
1603  }
1604 
1605  if (!(strncmp(tone_parser, "tonezone=", 9))) {
1606  *tone_zone = tone_parser + 9;
1607  } else {
1608  ast_log(LOG_ERROR, "Unexpected Tone URI component: %s\n", tone_parser);
1609  return -1;
1610  }
1611 
1612  return 0;
1613 }
1614 
1615 int ast_control_tone(struct ast_channel *chan, const char *tone)
1616 {
1617  struct ast_tone_zone *zone = NULL;
1618  struct ast_tone_zone_sound *ts;
1619  int paused = 0;
1620  int res = 0;
1621 
1622  const char *tone_indication = NULL;
1623  const char *tone_zone = NULL;
1624  char *tone_uri_parser;
1625 
1626  if (ast_strlen_zero(tone)) {
1627  return -1;
1628  }
1629 
1630  tone_uri_parser = ast_strdupa(tone);
1631 
1632  if (parse_tone_uri(tone_uri_parser, &tone_indication, &tone_zone)) {
1633  return -1;
1634  }
1635 
1636  if (tone_zone) {
1637  zone = ast_get_indication_zone(tone_zone);
1638  }
1639 
1640  ts = ast_get_indication_tone(zone ? zone : ast_channel_zone(chan), tone_indication);
1641 
1642  if (ast_playtones_start(chan, 0, ts ? ts->data : tone_indication, 0)) {
1643  res = -1;
1644  }
1645 
1646  while (!res) {
1647  struct ast_frame *fr;
1648 
1649  if (ast_waitfor(chan, -1) < 0) {
1650  res = -1;
1651  break;
1652  }
1653 
1654  fr = ast_read_noaudio(chan);
1655 
1656  if (!fr) {
1657  res = -1;
1658  break;
1659  }
1660 
1661  if (fr->frametype != AST_FRAME_CONTROL) {
1662  continue;
1663  }
1664 
1665  res = control_tone_frame_response(chan, fr, ts, tone_indication, &paused);
1666  if (res == CONTROL_TONE_RESPONSE_FINISHED) {
1667  res = 0;
1668  break;
1669  } else if (res == CONTROL_TONE_RESPONSE_FAILED) {
1670  res = -1;
1671  break;
1672  }
1673  }
1674 
1675  if (ts) {
1677  }
1678 
1679  if (zone) {
1680  ast_tone_zone_unref(zone);
1681  }
1682 
1683  return res;
1684 }
1685 
1686 int ast_play_and_wait(struct ast_channel *chan, const char *fn)
1687 {
1688  int d = 0;
1689 
1690  if ((d = ast_streamfile(chan, fn, ast_channel_language(chan)))) {
1691  return d;
1692  }
1693 
1694  d = ast_waitstream(chan, AST_DIGIT_ANY);
1695 
1696  ast_stopstream(chan);
1697 
1698  return d;
1699 }
1700 
1701 /*!
1702  * \brief Construct a silence frame of the same duration as \a orig.
1703  *
1704  * The \a orig frame must be \ref ast_format_slin.
1705  *
1706  * \param orig Frame as basis for silence to generate.
1707  * \return New frame of silence; free with ast_frfree().
1708  * \retval NULL on error.
1709  */
1710 static struct ast_frame *make_silence(const struct ast_frame *orig)
1711 {
1712  struct ast_frame *silence;
1713  size_t size;
1714  size_t datalen;
1715  size_t samples = 0;
1716 
1717  if (!orig) {
1718  return NULL;
1719  }
1720  do {
1722  ast_log(LOG_WARNING, "Attempting to silence non-slin frame\n");
1723  return NULL;
1724  }
1725 
1726  samples += orig->samples;
1727 
1728  orig = AST_LIST_NEXT(orig, frame_list);
1729  } while (orig);
1730 
1731  ast_verb(4, "Silencing %zu samples\n", samples);
1732 
1733 
1734  datalen = sizeof(short) * samples;
1735  size = sizeof(*silence) + datalen;
1736  silence = ast_calloc(1, size);
1737  if (!silence) {
1738  return NULL;
1739  }
1740 
1741  silence->mallocd = AST_MALLOCD_HDR;
1742  silence->frametype = AST_FRAME_VOICE;
1743  silence->data.ptr = (void *)(silence + 1);
1744  silence->samples = samples;
1745  silence->datalen = datalen;
1746 
1748 
1749  return silence;
1750 }
1751 
1752 /*!
1753  * \brief Sets a channel's read format to \ref ast_format_slin, recording
1754  * its original format.
1755  *
1756  * \param chan Channel to modify.
1757  * \param[out] orig_format Output variable to store channel's original read
1758  * format.
1759  * \return 0 on success.
1760  * \return -1 on error.
1761  */
1762 static int set_read_to_slin(struct ast_channel *chan, struct ast_format **orig_format)
1763 {
1764  if (!chan || !orig_format) {
1765  return -1;
1766  }
1767  *orig_format = ao2_bump(ast_channel_readformat(chan));
1768  return ast_set_read_format(chan, ast_format_slin);
1769 }
1770 
1771 static int global_silence_threshold = 128;
1772 static int global_maxsilence = 0;
1773 
1774 /*! Optionally play a sound file or a beep, then record audio and video from the channel.
1775  * \param chan Channel to playback to/record from.
1776  * \param playfile Filename of sound to play before recording begins.
1777  * \param recordfile Filename to record to.
1778  * \param maxtime Maximum length of recording (in seconds).
1779  * \param fmt Format(s) to record message in. Multiple formats may be specified by separating them with a '|'.
1780  * \param duration Where to store actual length of the recorded message (in milliseconds).
1781  * \param sound_duration Where to store the length of the recorded message (in milliseconds), minus any silence
1782  * \param beep Whether to play a beep before starting to record.
1783  * \param silencethreshold
1784  * \param maxsilence Length of silence that will end a recording (in milliseconds).
1785  * \param path Optional filesystem path to unlock.
1786  * \param prepend If true, prepend the recorded audio to an existing file and follow prepend mode recording rules
1787  * \param acceptdtmf DTMF digits that will end the recording.
1788  * \param canceldtmf DTMF digits that will cancel the recording.
1789  * \param skip_confirmation_sound If true, don't play auth-thankyou at end. Nice for custom recording prompts in apps.
1790  * \param if_exists
1791  *
1792  * \retval -1 failure or hangup
1793  * \retval 'S' Recording ended from silence timeout
1794  * \retval 't' Recording ended from the message exceeding the maximum duration, or via DTMF in prepend mode
1795  * \retval dtmfchar Recording ended via the return value's DTMF character for either cancel or accept.
1796  */
1797 static int __ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int *sound_duration, int beep, int silencethreshold, int maxsilence, const char *path, int prepend, const char *acceptdtmf, const char *canceldtmf, int skip_confirmation_sound, enum ast_record_if_exists if_exists)
1798 {
1799  int d = 0;
1800  char *fmts;
1801  char comment[256];
1802  int x, fmtcnt = 1, res = -1, outmsg = 0;
1803  struct ast_filestream *others[AST_MAX_FORMATS];
1804  const char *sfmt[AST_MAX_FORMATS];
1805  char *stringp = NULL;
1806  time_t start, end;
1807  struct ast_dsp *sildet = NULL; /* silence detector dsp */
1808  int totalsilence = 0;
1809  int dspsilence = 0;
1810  int olddspsilence = 0;
1811  struct ast_format *rfmt = NULL;
1812  struct ast_silence_generator *silgen = NULL;
1813  char prependfile[PATH_MAX];
1814  int ioflags; /* IO flags for writing output file */
1815 
1816  ioflags = O_CREAT|O_WRONLY;
1817 
1818  switch (if_exists) {
1820  ioflags |= O_EXCL;
1821  break;
1823  ioflags |= O_TRUNC;
1824  break;
1826  ioflags |= O_APPEND;
1827  break;
1829  ast_assert(0);
1830  break;
1831  }
1832 
1833  if (silencethreshold < 0) {
1835  }
1836 
1837  if (maxsilence < 0) {
1839  }
1840 
1841  /* barf if no pointer passed to store duration in */
1842  if (!duration) {
1843  ast_log(LOG_WARNING, "Error play_and_record called without duration pointer\n");
1844  return -1;
1845  }
1846 
1847  ast_debug(1, "play_and_record: %s, %s, '%s'\n", playfile ? playfile : "<None>", recordfile, fmt);
1848  snprintf(comment, sizeof(comment), "Playing %s, Recording to: %s on %s\n", playfile ? playfile : "<None>", recordfile, ast_channel_name(chan));
1849 
1850  if (playfile || beep) {
1851  if (!beep) {
1852  d = ast_play_and_wait(chan, playfile);
1853  }
1854  if (d > -1) {
1855  d = ast_stream_and_wait(chan, "beep", "");
1856  }
1857  if (d < 0) {
1858  return -1;
1859  }
1860  }
1861 
1862  if (prepend) {
1863  ast_copy_string(prependfile, recordfile, sizeof(prependfile));
1864  strncat(prependfile, "-prepend", sizeof(prependfile) - strlen(prependfile) - 1);
1865  }
1866 
1867  fmts = ast_strdupa(fmt);
1868 
1869  stringp = fmts;
1870  strsep(&stringp, "|");
1871  ast_debug(1, "Recording Formats: sfmts=%s\n", fmts);
1872  sfmt[0] = ast_strdupa(fmts);
1873 
1874  while ((fmt = strsep(&stringp, "|"))) {
1875  if (fmtcnt > AST_MAX_FORMATS - 1) {
1876  ast_log(LOG_WARNING, "Please increase AST_MAX_FORMATS in file.h\n");
1877  break;
1878  }
1879  /*
1880  * Storage for 'fmt' is on the stack and held by 'fmts', which is maintained for
1881  * the rest of this function. So okay to not duplicate 'fmt' here, but only keep
1882  * a pointer to it.
1883  */
1884  sfmt[fmtcnt++] = fmt;
1885  }
1886 
1887  end = start = time(NULL); /* pre-initialize end to be same as start in case we never get into loop */
1888  for (x = 0; x < fmtcnt; x++) {
1889  others[x] = ast_writefile(prepend ? prependfile : recordfile, sfmt[x], comment, ioflags, 0, AST_FILE_MODE);
1890  ast_verb(3, "x=%d, open writing: %s format: %s, %p\n", x, prepend ? prependfile : recordfile, sfmt[x], others[x]);
1891 
1892  if (!others[x]) {
1893  break;
1894  }
1895  }
1896 
1897  if (path) {
1898  ast_unlock_path(path);
1899  }
1900 
1901  if (maxsilence > 0) {
1902  sildet = ast_dsp_new(); /* Create the silence detector */
1903  if (!sildet) {
1904  ast_log(LOG_WARNING, "Unable to create silence detector :(\n");
1905  return -1;
1906  }
1908  res = set_read_to_slin(chan, &rfmt);
1909  if (res < 0) {
1910  ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
1911  ast_dsp_free(sildet);
1912  ao2_cleanup(rfmt);
1913  return -1;
1914  }
1915  }
1916 
1917  if (!prepend) {
1918  /* Request a video update */
1920 
1922  silgen = ast_channel_start_silence_generator(chan);
1923  }
1924  }
1925 
1926  if (x == fmtcnt) {
1927  /* Loop, writing the packets we read to the writer(s), until
1928  * we have reason to stop. */
1929  struct ast_frame *f;
1930  int paused = 0;
1931  int muted = 0;
1932  time_t pause_start = 0;
1933  int paused_secs = 0;
1934  int pausedsilence = 0;
1935 
1936  for (;;) {
1937  if (!(res = ast_waitfor(chan, 2000))) {
1938  ast_debug(1, "One waitfor failed, trying another\n");
1939  /* Try one more time in case of masq */
1940  if (!(res = ast_waitfor(chan, 2000))) {
1941  ast_log(LOG_WARNING, "No audio available on %s??\n", ast_channel_name(chan));
1942  res = -1;
1943  }
1944  }
1945 
1946  if (res < 0) {
1947  f = NULL;
1948  break;
1949  }
1950  if (!(f = ast_read(chan))) {
1951  break;
1952  }
1953  if (f->frametype == AST_FRAME_VOICE) {
1954  /* write each format */
1955  if (paused) {
1956  /* It's all good */
1957  res = 0;
1958  } else {
1959  struct ast_frame *silence = NULL;
1960  struct ast_frame *orig = f;
1961 
1962  if (muted) {
1963  silence = make_silence(orig);
1964  if (!silence) {
1965  ast_log(LOG_WARNING, "Error creating silence\n");
1966  break;
1967  }
1968  f = silence;
1969  }
1970  for (x = 0; x < fmtcnt; x++) {
1971  if (prepend && !others[x]) {
1972  break;
1973  }
1974  res = ast_writestream(others[x], f);
1975  }
1976  ast_frame_dtor(silence);
1977  f = orig;
1978  }
1979 
1980  /* Silence Detection */
1981  if (maxsilence > 0) {
1982  dspsilence = 0;
1983  ast_dsp_silence(sildet, f, &dspsilence);
1984  if (olddspsilence > dspsilence) {
1985  totalsilence += olddspsilence;
1986  }
1987  olddspsilence = dspsilence;
1988 
1989  if (paused) {
1990  /* record how much silence there was while we are paused */
1991  pausedsilence = dspsilence;
1992  } else if (dspsilence > pausedsilence) {
1993  /* ignore the paused silence */
1994  dspsilence -= pausedsilence;
1995  } else {
1996  /* dspsilence has reset, reset pausedsilence */
1997  pausedsilence = 0;
1998  }
1999 
2000  if (dspsilence > maxsilence) {
2001  /* Ended happily with silence */
2002  ast_verb(3, "Recording automatically stopped after a silence of %d seconds\n", dspsilence/1000);
2003  res = 'S';
2004  outmsg = 2;
2005  break;
2006  }
2007  }
2008  /* Exit on any error */
2009  if (res) {
2010  ast_log(LOG_WARNING, "Error writing frame\n");
2011  break;
2012  }
2013  } else if (f->frametype == AST_FRAME_VIDEO) {
2014  /* Write only once */
2015  ast_writestream(others[0], f);
2016  } else if (f->frametype == AST_FRAME_DTMF) {
2017  if (prepend) {
2018  /* stop recording with any digit */
2019  ast_verb(3, "User ended message by pressing %c\n", f->subclass.integer);
2020  res = 't';
2021  outmsg = 2;
2022  break;
2023  }
2024  if (strchr(acceptdtmf, f->subclass.integer)) {
2025  ast_verb(3, "User ended message by pressing %c\n", f->subclass.integer);
2026  res = f->subclass.integer;
2027  outmsg = 2;
2028  break;
2029  }
2030  if (strchr(canceldtmf, f->subclass.integer)) {
2031  ast_verb(3, "User canceled message by pressing %c\n", f->subclass.integer);
2032  res = f->subclass.integer;
2033  outmsg = 0;
2034  break;
2035  }
2036  } else if (f->frametype == AST_FRAME_CONTROL) {
2038  ast_verb(3, "Message canceled by control\n");
2039  outmsg = 0; /* cancels the recording */
2040  res = 0;
2041  break;
2042  } else if (f->subclass.integer == AST_CONTROL_RECORD_STOP) {
2043  ast_verb(3, "Message ended by control\n");
2044  res = 0;
2045  break;
2046  } else if (f->subclass.integer == AST_CONTROL_RECORD_SUSPEND) {
2047  paused = !paused;
2048  ast_verb(3, "Message %spaused by control\n",
2049  paused ? "" : "un");
2050  if (paused) {
2051  pause_start = time(NULL);
2052  } else {
2053  paused_secs += time(NULL) - pause_start;
2054  }
2055  } else if (f->subclass.integer == AST_CONTROL_RECORD_MUTE) {
2056  muted = !muted;
2057  ast_verb(3, "Message %smuted by control\n",
2058  muted ? "" : "un");
2059  /* We can only silence slin frames, so
2060  * set the mode, if we haven't already
2061  * for sildet
2062  */
2063  if (muted && !rfmt) {
2064  ast_verb(3, "Setting read format to linear mode\n");
2065  res = set_read_to_slin(chan, &rfmt);
2066  if (res < 0) {
2067  ast_log(LOG_WARNING, "Unable to set to linear mode, giving up\n");
2068  break;
2069  }
2070  }
2071  }
2072  }
2073  if (maxtime && !paused) {
2074  end = time(NULL);
2075  if (maxtime < (end - start - paused_secs)) {
2076  ast_verb(3, "Took too long, cutting it short...\n");
2077  res = 't';
2078  outmsg = 2;
2079  break;
2080  }
2081  }
2082  ast_frfree(f);
2083  }
2084  if (!f) {
2085  ast_verb(3, "User hung up\n");
2086  res = -1;
2087  outmsg = 1;
2088  } else {
2089  ast_frfree(f);
2090  }
2091  } else {
2092  ast_log(LOG_WARNING, "Error creating writestream '%s', format '%s'\n", recordfile, sfmt[x]);
2093  }
2094 
2095  if (!prepend) {
2096  if (silgen) {
2097  ast_channel_stop_silence_generator(chan, silgen);
2098  }
2099  }
2100 
2101  /*!\note
2102  * Instead of asking how much time passed (end - start), calculate the number
2103  * of seconds of audio which actually went into the file. This fixes a
2104  * problem where audio is stopped up on the network and never gets to us.
2105  *
2106  * Note that we still want to use the number of seconds passed for the max
2107  * message, otherwise we could get a situation where this stream is never
2108  * closed (which would create a resource leak).
2109  */
2110  *duration = others[0] ? ast_tellstream(others[0]) / 8000 : 0;
2111  if (sound_duration) {
2112  *sound_duration = *duration;
2113  }
2114 
2115  if (!prepend) {
2116  /* Reduce duration by a total silence amount */
2117  if (olddspsilence <= dspsilence) {
2118  totalsilence += dspsilence;
2119  }
2120 
2121  if (sound_duration) {
2122  if (totalsilence > 0) {
2123  *sound_duration -= (totalsilence - 200) / 1000;
2124  }
2125  if (*sound_duration < 0) {
2126  *sound_duration = 0;
2127  }
2128  }
2129 
2130  if (dspsilence > 0) {
2131  *duration -= (dspsilence - 200) / 1000;
2132  }
2133 
2134  if (*duration < 0) {
2135  *duration = 0;
2136  }
2137 
2138  for (x = 0; x < fmtcnt; x++) {
2139  if (!others[x]) {
2140  break;
2141  }
2142  /*!\note
2143  * If we ended with silence, trim all but the first 200ms of silence
2144  * off the recording. However, if we ended with '#', we don't want
2145  * to trim ANY part of the recording.
2146  */
2147  if (res > 0 && dspsilence) {
2148  /* rewind only the trailing silence */
2149  ast_stream_rewind(others[x], dspsilence - 200);
2150  }
2151  ast_truncstream(others[x]);
2152  ast_closestream(others[x]);
2153  }
2154  } else if (prepend && outmsg) {
2155  struct ast_filestream *realfiles[AST_MAX_FORMATS];
2156  struct ast_frame *fr;
2157 
2158  for (x = 0; x < fmtcnt; x++) {
2159  snprintf(comment, sizeof(comment), "Opening the real file %s.%s\n", recordfile, sfmt[x]);
2160  realfiles[x] = ast_readfile(recordfile, sfmt[x], comment, O_RDONLY, 0, 0);
2161  if (!others[x]) {
2162  break;
2163  }
2164  if (!realfiles[x]) {
2165  ast_closestream(others[x]);
2166  continue;
2167  }
2168  /*!\note Same logic as above. */
2169  if (dspsilence) {
2170  ast_stream_rewind(others[x], dspsilence - 200);
2171  }
2172  ast_truncstream(others[x]);
2173  /* add the original file too */
2174  while ((fr = ast_readframe(realfiles[x]))) {
2175  ast_writestream(others[x], fr);
2176  ast_frfree(fr);
2177  }
2178  ast_closestream(others[x]);
2179  ast_closestream(realfiles[x]);
2180  ast_filerename(prependfile, recordfile, sfmt[x]);
2181  ast_verb(4, "Recording Format: sfmts=%s, prependfile %s, recordfile %s\n", sfmt[x], prependfile, recordfile);
2182  ast_filedelete(prependfile, sfmt[x]);
2183  }
2184  } else {
2185  for (x = 0; x < fmtcnt; x++) {
2186  if (!others[x]) {
2187  break;
2188  }
2189  ast_closestream(others[x]);
2190  }
2191  }
2192 
2193  if (rfmt && ast_set_read_format(chan, rfmt)) {
2194  ast_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", ast_format_get_name(rfmt), ast_channel_name(chan));
2195  }
2196  ao2_cleanup(rfmt);
2197  if ((outmsg == 2) && (!skip_confirmation_sound)) {
2198  ast_stream_and_wait(chan, "auth-thankyou", "");
2199  }
2200  if (sildet) {
2201  ast_dsp_free(sildet);
2202  }
2203  return res;
2204 }
2205 
2206 static const char default_acceptdtmf[] = "#";
2207 static const char default_canceldtmf[] = "";
2208 
2209 int ast_play_and_record_full(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int *sound_duration, int beep, int silencethreshold, int maxsilence, const char *path, const char *acceptdtmf, const char *canceldtmf, int skip_confirmation_sound, enum ast_record_if_exists if_exists)
2210 {
2211  return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, sound_duration, beep, silencethreshold, maxsilence, path, 0, S_OR(acceptdtmf, ""), S_OR(canceldtmf, default_canceldtmf), skip_confirmation_sound, if_exists);
2212 }
2213 
2214 int ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int *sound_duration, int silencethreshold, int maxsilence, const char *path)
2215 {
2216  return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, sound_duration, 0, silencethreshold, maxsilence, path, 0, default_acceptdtmf, default_canceldtmf, 0, AST_RECORD_IF_EXISTS_OVERWRITE);
2217 }
2218 
2219 int ast_play_and_prepend(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime, char *fmt, int *duration, int *sound_duration, int beep, int silencethreshold, int maxsilence)
2220 {
2221  return __ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, sound_duration, beep, silencethreshold, maxsilence, NULL, 1, default_acceptdtmf, default_canceldtmf, 1, AST_RECORD_IF_EXISTS_OVERWRITE);
2222 }
2223 
2224 /* Channel group core functions */
2225 
2226 int ast_app_group_split_group(const char *data, char *group, int group_max, char *category, int category_max)
2227 {
2228  int res = 0;
2229  char tmp[256];
2230  char *grp = NULL, *cat = NULL;
2231 
2232  if (!ast_strlen_zero(data)) {
2233  ast_copy_string(tmp, data, sizeof(tmp));
2234  grp = tmp;
2235  if ((cat = strchr(tmp, '@'))) {
2236  *cat++ = '\0';
2237  }
2238  }
2239 
2240  if (!ast_strlen_zero(grp)) {
2241  ast_copy_string(group, grp, group_max);
2242  } else {
2243  *group = '\0';
2244  }
2245 
2246  if (!ast_strlen_zero(cat)) {
2247  ast_copy_string(category, cat, category_max);
2248  }
2249 
2250  return res;
2251 }
2252 
2253 int ast_app_group_set_channel(struct ast_channel *chan, const char *data)
2254 {
2255  int res = 0;
2256  char group[80] = "", category[80] = "";
2257  struct ast_group_info *gi = NULL;
2258  size_t len = 0;
2259 
2260  if (ast_app_group_split_group(data, group, sizeof(group), category, sizeof(category))) {
2261  return -1;
2262  }
2263 
2264  /* Calculate memory we will need if this is new */
2265  len = sizeof(*gi) + strlen(group) + 1;
2266  if (!ast_strlen_zero(category)) {
2267  len += strlen(category) + 1;
2268  }
2269 
2272  if ((gi->chan == chan) && ((ast_strlen_zero(category) && ast_strlen_zero(gi->category)) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) {
2274  ast_free(gi);
2275  break;
2276  }
2277  }
2279 
2280  if (ast_strlen_zero(group)) {
2281  /* Enable unsetting the group */
2282  } else if ((gi = ast_calloc(1, len))) {
2283  gi->chan = chan;
2284  gi->group = (char *) gi + sizeof(*gi);
2285  strcpy(gi->group, group);
2286  if (!ast_strlen_zero(category)) {
2287  gi->category = (char *) gi + sizeof(*gi) + strlen(group) + 1;
2288  strcpy(gi->category, category);
2289  }
2291  } else {
2292  res = -1;
2293  }
2294 
2296 
2297  return res;
2298 }
2299 
2300 int ast_app_group_get_count(const char *group, const char *category)
2301 {
2302  struct ast_group_info *gi = NULL;
2303  int count = 0;
2304 
2305  if (ast_strlen_zero(group)) {
2306  return 0;
2307  }
2308 
2311  if (!strcasecmp(gi->group, group) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) {
2312  count++;
2313  }
2314  }
2316 
2317  return count;
2318 }
2319 
2320 int ast_app_group_match_get_count(const char *groupmatch, const char *category)
2321 {
2322  struct ast_group_info *gi = NULL;
2323  regex_t regexbuf_group;
2324  regex_t regexbuf_category;
2325  int count = 0;
2326 
2327  if (ast_strlen_zero(groupmatch)) {
2328  ast_log(LOG_NOTICE, "groupmatch empty\n");
2329  return 0;
2330  }
2331 
2332  /* if regex compilation fails, return zero matches */
2333  if (regcomp(&regexbuf_group, groupmatch, REG_EXTENDED | REG_NOSUB)) {
2334  ast_log(LOG_ERROR, "Regex compile failed on: %s\n", groupmatch);
2335  return 0;
2336  }
2337 
2338  if (!ast_strlen_zero(category) && regcomp(&regexbuf_category, category, REG_EXTENDED | REG_NOSUB)) {
2339  ast_log(LOG_ERROR, "Regex compile failed on: %s\n", category);
2340  regfree(&regexbuf_group);
2341  return 0;
2342  }
2343 
2346  if (!regexec(&regexbuf_group, gi->group, 0, NULL, 0) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !regexec(&regexbuf_category, gi->category, 0, NULL, 0)))) {
2347  count++;
2348  }
2349  }
2351 
2352  regfree(&regexbuf_group);
2353  if (!ast_strlen_zero(category)) {
2354  regfree(&regexbuf_category);
2355  }
2356 
2357  return count;
2358 }
2359 
2360 int ast_app_group_update(struct ast_channel *old, struct ast_channel *new)
2361 {
2362  struct ast_group_info *gi = NULL;
2363 
2366  if (gi->chan == old) {
2367  gi->chan = new;
2368  } else if (gi->chan == new) {
2370  ast_free(gi);
2371  }
2372  }
2375 
2376  return 0;
2377 }
2378 
2380 {
2381  struct ast_group_info *gi = NULL;
2382 
2385  if (gi->chan == chan) {
2387  ast_free(gi);
2388  }
2389  }
2392 
2393  return 0;
2394 }
2395 
2397 {
2398  return AST_RWLIST_WRLOCK(&groups);
2399 }
2400 
2402 {
2403  return AST_RWLIST_RDLOCK(&groups);
2404 }
2405 
2407 {
2408  return AST_RWLIST_FIRST(&groups);
2409 }
2410 
2412 {
2413  return AST_RWLIST_UNLOCK(&groups);
2414 }
2415 
2416 unsigned int __ast_app_separate_args(char *buf, char delim, int remove_chars, char **array, int arraylen)
2417 {
2418  int argc;
2419  char *scan, *wasdelim = NULL;
2420  int paren = 0, quote = 0, bracket = 0;
2421 
2422  if (!array || !arraylen) {
2423  return 0;
2424  }
2425 
2426  memset(array, 0, arraylen * sizeof(*array));
2427 
2428  if (!buf) {
2429  return 0;
2430  }
2431 
2432  scan = buf;
2433 
2434  for (argc = 0; *scan && (argc < arraylen - 1); argc++) {
2435  array[argc] = scan;
2436  for (; *scan; scan++) {
2437  if (*scan == '(') {
2438  paren++;
2439  } else if (*scan == ')') {
2440  if (paren) {
2441  paren--;
2442  }
2443  } else if (*scan == '[') {
2444  bracket++;
2445  } else if (*scan == ']') {
2446  if (bracket) {
2447  bracket--;
2448  }
2449  } else if (*scan == '"' && delim != '"') {
2450  quote = quote ? 0 : 1;
2451  if (remove_chars) {
2452  /* Remove quote character from argument */
2453  memmove(scan, scan + 1, strlen(scan));
2454  scan--;
2455  }
2456  } else if (*scan == '\\') {
2457  if (remove_chars) {
2458  /* Literal character, don't parse */
2459  memmove(scan, scan + 1, strlen(scan));
2460  } else {
2461  scan++;
2462  }
2463  } else if ((*scan == delim) && !paren && !quote && !bracket) {
2464  wasdelim = scan;
2465  *scan++ = '\0';
2466  break;
2467  }
2468  }
2469  }
2470 
2471  /* If the last character in the original string was the delimiter, then
2472  * there is one additional argument. */
2473  if (*scan || (scan > buf && (scan - 1) == wasdelim)) {
2474  array[argc++] = scan;
2475  }
2476 
2477  return argc;
2478 }
2479 
2480 static enum AST_LOCK_RESULT ast_lock_path_lockfile(const char *path)
2481 {
2482  char *s;
2483  char *fs;
2484  int res;
2485  int fd;
2486  int lp = strlen(path);
2487  time_t start;
2488 
2489  s = ast_alloca(lp + 10);
2490  fs = ast_alloca(lp + 20);
2491 
2492  snprintf(fs, strlen(path) + 19, "%s/.lock-%08lx", path, (unsigned long)ast_random());
2493  fd = open(fs, O_WRONLY | O_CREAT | O_EXCL, AST_FILE_MODE);
2494  if (fd < 0) {
2495  ast_log(LOG_ERROR, "Unable to create lock file '%s': %s\n", path, strerror(errno));
2496  return AST_LOCK_PATH_NOT_FOUND;
2497  }
2498  close(fd);
2499 
2500  snprintf(s, strlen(path) + 9, "%s/.lock", path);
2501  start = time(NULL);
2502  while (((res = link(fs, s)) < 0) && (errno == EEXIST) && (time(NULL) - start < 5)) {
2503  sched_yield();
2504  }
2505 
2506  unlink(fs);
2507 
2508  if (res) {
2509  ast_log(LOG_WARNING, "Failed to lock path '%s': %s\n", path, strerror(errno));
2510  return AST_LOCK_TIMEOUT;
2511  } else {
2512  ast_debug(1, "Locked path '%s'\n", path);
2513  return AST_LOCK_SUCCESS;
2514  }
2515 }
2516 
2517 static int ast_unlock_path_lockfile(const char *path)
2518 {
2519  char *s;
2520  int res;
2521 
2522  s = ast_alloca(strlen(path) + 10);
2523 
2524  snprintf(s, strlen(path) + 9, "%s/%s", path, ".lock");
2525 
2526  if ((res = unlink(s))) {
2527  ast_log(LOG_ERROR, "Could not unlock path '%s': %s\n", path, strerror(errno));
2528  } else {
2529  ast_debug(1, "Unlocked path '%s'\n", path);
2530  }
2531 
2532  return res;
2533 }
2534 
2535 struct path_lock {
2537  int fd;
2538  char *path;
2539 };
2540 
2542 
2543 static void path_lock_destroy(struct path_lock *obj)
2544 {
2545  if (obj->fd >= 0) {
2546  close(obj->fd);
2547  }
2548  if (obj->path) {
2549  ast_free(obj->path);
2550  }
2551  ast_free(obj);
2552 }
2553 
2554 static enum AST_LOCK_RESULT ast_lock_path_flock(const char *path)
2555 {
2556  char *fs;
2557  int res;
2558  int fd;
2559  time_t start;
2560  struct path_lock *pl;
2561  struct stat st, ost;
2562 
2563  fs = ast_alloca(strlen(path) + 20);
2564 
2565  snprintf(fs, strlen(path) + 19, "%s/lock", path);
2566  if (lstat(fs, &st) == 0) {
2567  if ((st.st_mode & S_IFMT) == S_IFLNK) {
2568  ast_log(LOG_WARNING, "Unable to create lock file "
2569  "'%s': it's already a symbolic link\n",
2570  fs);
2571  return AST_LOCK_FAILURE;
2572  }
2573  if (st.st_nlink > 1) {
2574  ast_log(LOG_WARNING, "Unable to create lock file "
2575  "'%s': %u hard links exist\n",
2576  fs, (unsigned int) st.st_nlink);
2577  return AST_LOCK_FAILURE;
2578  }
2579  }
2580  if ((fd = open(fs, O_WRONLY | O_CREAT, 0600)) < 0) {
2581  ast_log(LOG_WARNING, "Unable to create lock file '%s': %s\n",
2582  fs, strerror(errno));
2583  return AST_LOCK_PATH_NOT_FOUND;
2584  }
2585  if (!(pl = ast_calloc(1, sizeof(*pl)))) {
2586  /* We don't unlink the lock file here, on the possibility that
2587  * someone else created it - better to leave a little mess
2588  * than create a big one by destroying someone else's lock
2589  * and causing something to be corrupted.
2590  */
2591  close(fd);
2592  return AST_LOCK_FAILURE;
2593  }
2594  pl->fd = fd;
2595  pl->path = ast_strdup(path);
2596 
2597  time(&start);
2598  while (
2599  #ifdef SOLARIS
2600  ((res = fcntl(pl->fd, F_SETLK, fcntl(pl->fd, F_GETFL) | O_NONBLOCK)) < 0) &&
2601  #else
2602  ((res = flock(pl->fd, LOCK_EX | LOCK_NB)) < 0) &&
2603  #endif
2604  (errno == EWOULDBLOCK) &&
2605  (time(NULL) - start < 5))
2606  usleep(1000);
2607  if (res) {
2608  ast_log(LOG_WARNING, "Failed to lock path '%s': %s\n",
2609  path, strerror(errno));
2610  /* No unlinking of lock done, since we tried and failed to
2611  * flock() it.
2612  */
2613  path_lock_destroy(pl);
2614  return AST_LOCK_TIMEOUT;
2615  }
2616 
2617  /* Check for the race where the file is recreated or deleted out from
2618  * underneath us.
2619  */
2620  if (lstat(fs, &st) != 0 && fstat(pl->fd, &ost) != 0 &&
2621  st.st_dev != ost.st_dev &&
2622  st.st_ino != ost.st_ino) {
2623  ast_log(LOG_WARNING, "Unable to create lock file '%s': "
2624  "file changed underneath us\n", fs);
2625  path_lock_destroy(pl);
2626  return AST_LOCK_FAILURE;
2627  }
2628 
2629  /* Success: file created, flocked, and is the one we started with */
2633 
2634  ast_debug(1, "Locked path '%s'\n", path);
2635 
2636  return AST_LOCK_SUCCESS;
2637 }
2638 
2639 static int ast_unlock_path_flock(const char *path)
2640 {
2641  char *s;
2642  struct path_lock *p;
2643 
2644  s = ast_alloca(strlen(path) + 20);
2645 
2648  if (!strcmp(p->path, path)) {
2650  break;
2651  }
2652  }
2655 
2656  if (p) {
2657  snprintf(s, strlen(path) + 19, "%s/lock", path);
2658  unlink(s);
2659  path_lock_destroy(p);
2660  ast_debug(1, "Unlocked path '%s'\n", path);
2661  } else {
2662  ast_debug(1, "Failed to unlock path '%s': "
2663  "lock not found\n", path);
2664  }
2665 
2666  return 0;
2667 }
2668 
2670 {
2671  ast_lock_type = type;
2672 }
2673 
2674 enum AST_LOCK_RESULT ast_lock_path(const char *path)
2675 {
2677 
2678  switch (ast_lock_type) {
2681  break;
2682  case AST_LOCK_TYPE_FLOCK:
2684  break;
2685  }
2686 
2687  return r;
2688 }
2689 
2690 int ast_unlock_path(const char *path)
2691 {
2692  int r = 0;
2693 
2694  switch (ast_lock_type) {
2697  break;
2698  case AST_LOCK_TYPE_FLOCK:
2700  break;
2701  }
2702 
2703  return r;
2704 }
2705 
2706 int ast_record_review(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, const char *path)
2707 {
2708  int silencethreshold;
2709  int maxsilence = 0;
2710  int res = 0;
2711  int cmd = 0;
2712  int max_attempts = 3;
2713  int attempts = 0;
2714  int recorded = 0;
2715  int message_exists = 0;
2716  /* Note that urgent and private are for flagging messages as such in the future */
2717 
2718  /* barf if no pointer passed to store duration in */
2719  if (!duration) {
2720  ast_log(LOG_WARNING, "Error ast_record_review called without duration pointer\n");
2721  return -1;
2722  }
2723 
2724  cmd = '3'; /* Want to start by recording */
2725 
2727 
2728  while ((cmd >= 0) && (cmd != 't')) {
2729  switch (cmd) {
2730  case '1':
2731  if (!message_exists) {
2732  /* In this case, 1 is to record a message */
2733  cmd = '3';
2734  break;
2735  } else {
2736  ast_stream_and_wait(chan, "vm-msgsaved", "");
2737  cmd = 't';
2738  return res;
2739  }
2740  case '2':
2741  /* Review */
2742  ast_verb(3, "Reviewing the recording\n");
2743  cmd = ast_stream_and_wait(chan, recordfile, AST_DIGIT_ANY);
2744  break;
2745  case '3':
2746  message_exists = 0;
2747  /* Record */
2748  ast_verb(3, "R%secording\n", recorded == 1 ? "e-r" : "");
2749  recorded = 1;
2750  if ((cmd = ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, NULL, silencethreshold, maxsilence, path)) == -1) {
2751  /* User has hung up, no options to give */
2752  return cmd;
2753  }
2754  if (cmd == '0') {
2755  break;
2756  } else if (cmd == '*') {
2757  break;
2758  } else {
2759  /* If all is well, a message exists */
2760  message_exists = 1;
2761  cmd = 0;
2762  }
2763  break;
2764  case '4':
2765  case '5':
2766  case '6':
2767  case '7':
2768  case '8':
2769  case '9':
2770  case '*':
2771  case '#':
2772  cmd = ast_play_and_wait(chan, "vm-sorry");
2773  break;
2774  default:
2775  if (message_exists) {
2776  cmd = ast_play_and_wait(chan, "vm-review");
2777  } else {
2778  if (!(cmd = ast_play_and_wait(chan, "vm-torerecord"))) {
2779  cmd = ast_waitfordigit(chan, 600);
2780  }
2781  }
2782 
2783  if (!cmd) {
2784  cmd = ast_waitfordigit(chan, 6000);
2785  }
2786  if (!cmd) {
2787  attempts++;
2788  }
2789  if (attempts > max_attempts) {
2790  cmd = 't';
2791  }
2792  }
2793  }
2794  if (cmd == 't') {
2795  cmd = 0;
2796  }
2797  return cmd;
2798 }
2799 
2800 #define RES_UPONE (1 << 16)
2801 #define RES_EXIT (1 << 17)
2802 #define RES_REPEAT (1 << 18)
2803 #define RES_RESTART ((1 << 19) | RES_REPEAT)
2804 
2805 static int ast_ivr_menu_run_internal(struct ast_channel *chan, struct ast_ivr_menu *menu, void *cbdata);
2806 
2807 static int ivr_dispatch(struct ast_channel *chan, struct ast_ivr_option *option, char *exten, void *cbdata)
2808 {
2809  int res;
2810  int (*ivr_func)(struct ast_channel *, void *);
2811  char *c;
2812  char *n;
2813 
2814  switch (option->action) {
2815  case AST_ACTION_UPONE:
2816  return RES_UPONE;
2817  case AST_ACTION_EXIT:
2818  return RES_EXIT | (((unsigned long)(option->adata)) & 0xffff);
2819  case AST_ACTION_REPEAT:
2820  return RES_REPEAT | (((unsigned long)(option->adata)) & 0xffff);
2821  case AST_ACTION_RESTART:
2822  return RES_RESTART ;
2823  case AST_ACTION_NOOP:
2824  return 0;
2825  case AST_ACTION_BACKGROUND:
2826  res = ast_stream_and_wait(chan, (char *)option->adata, AST_DIGIT_ANY);
2827  if (res < 0) {
2828  ast_log(LOG_NOTICE, "Unable to find file '%s'!\n", (char *)option->adata);
2829  res = 0;
2830  }
2831  return res;
2832  case AST_ACTION_PLAYBACK:
2833  res = ast_stream_and_wait(chan, (char *)option->adata, "");
2834  if (res < 0) {
2835  ast_log(LOG_NOTICE, "Unable to find file '%s'!\n", (char *)option->adata);
2836  res = 0;
2837  }
2838  return res;
2839  case AST_ACTION_MENU:
2840  if ((res = ast_ivr_menu_run_internal(chan, (struct ast_ivr_menu *)option->adata, cbdata)) == -2) {
2841  /* Do not pass entry errors back up, treat as though it was an "UPONE" */
2842  res = 0;
2843  }
2844  return res;
2845  case AST_ACTION_WAITOPTION:
2846  if (!(res = ast_waitfordigit(chan, ast_channel_pbx(chan) ? ast_channel_pbx(chan)->rtimeoutms : 10000))) {
2847  return 't';
2848  }
2849  return res;
2850  case AST_ACTION_CALLBACK:
2851  ivr_func = option->adata;
2852  res = ivr_func(chan, cbdata);
2853  return res;
2854  case AST_ACTION_TRANSFER:
2855  res = ast_parseable_goto(chan, option->adata);
2856  return 0;
2857  case AST_ACTION_PLAYLIST:
2858  case AST_ACTION_BACKLIST:
2859  res = 0;
2860  c = ast_strdupa(option->adata);
2861  while ((n = strsep(&c, ";"))) {
2862  if ((res = ast_stream_and_wait(chan, n,
2863  (option->action == AST_ACTION_BACKLIST) ? AST_DIGIT_ANY : ""))) {
2864  break;
2865  }
2866  }
2867  ast_stopstream(chan);
2868  return res;
2869  default:
2870  ast_log(LOG_NOTICE, "Unknown dispatch function %u, ignoring!\n", option->action);
2871  return 0;
2872  }
2873  return -1;
2874 }
2875 
2876 static int option_exists(struct ast_ivr_menu *menu, char *option)
2877 {
2878  int x;
2879  for (x = 0; menu->options[x].option; x++) {
2880  if (!strcasecmp(menu->options[x].option, option)) {
2881  return x;
2882  }
2883  }
2884  return -1;
2885 }
2886 
2887 static int option_matchmore(struct ast_ivr_menu *menu, char *option)
2888 {
2889  int x;
2890  for (x = 0; menu->options[x].option; x++) {
2891  if ((!strncasecmp(menu->options[x].option, option, strlen(option))) &&
2892  (menu->options[x].option[strlen(option)])) {
2893  return x;
2894  }
2895  }
2896  return -1;
2897 }
2898 
2899 static int read_newoption(struct ast_channel *chan, struct ast_ivr_menu *menu, char *exten, int maxexten)
2900 {
2901  int res = 0;
2902  int ms;
2903  while (option_matchmore(menu, exten)) {
2904  ms = ast_channel_pbx(chan) ? ast_channel_pbx(chan)->dtimeoutms : 5000;
2905  if (strlen(exten) >= maxexten - 1) {
2906  break;
2907  }
2908  if ((res = ast_waitfordigit(chan, ms)) < 1) {
2909  break;
2910  }
2911  exten[strlen(exten) + 1] = '\0';
2912  exten[strlen(exten)] = res;
2913  }
2914  return res > 0 ? 0 : res;
2915 }
2916 
2917 static int ast_ivr_menu_run_internal(struct ast_channel *chan, struct ast_ivr_menu *menu, void *cbdata)
2918 {
2919  /* Execute an IVR menu structure */
2920  int res = 0;
2921  int pos = 0;
2922  int retries = 0;
2923  char exten[AST_MAX_EXTENSION] = "s";
2924  if (option_exists(menu, "s") < 0) {
2925  strcpy(exten, "g");
2926  if (option_exists(menu, "g") < 0) {
2927  ast_log(LOG_WARNING, "No 's' nor 'g' extension in menu '%s'!\n", menu->title);
2928  return -1;
2929  }
2930  }
2931  while (!res) {
2932  while (menu->options[pos].option) {
2933  if (!strcasecmp(menu->options[pos].option, exten)) {
2934  res = ivr_dispatch(chan, menu->options + pos, exten, cbdata);
2935  ast_debug(1, "IVR Dispatch of '%s' (pos %d) yields %d\n", exten, pos, res);
2936  if (res < 0) {
2937  break;
2938  } else if (res & RES_UPONE) {
2939  return 0;
2940  } else if (res & RES_EXIT) {
2941  return res;
2942  } else if (res & RES_REPEAT) {
2943  int maxretries = res & 0xffff;
2944  if ((res & RES_RESTART) == RES_RESTART) {
2945  retries = 0;
2946  } else {
2947  retries++;
2948  }
2949  if (!maxretries) {
2950  maxretries = 3;
2951  }
2952  if ((maxretries > 0) && (retries >= maxretries)) {
2953  ast_debug(1, "Max retries %d exceeded\n", maxretries);
2954  return -2;
2955  } else {
2956  if (option_exists(menu, "g") > -1) {
2957  strcpy(exten, "g");
2958  } else if (option_exists(menu, "s") > -1) {
2959  strcpy(exten, "s");
2960  }
2961  }
2962  pos = 0;
2963  continue;
2964  } else if (res && strchr(AST_DIGIT_ANY, res)) {
2965  ast_debug(1, "Got start of extension, %c\n", res);
2966  exten[1] = '\0';
2967  exten[0] = res;
2968  if ((res = read_newoption(chan, menu, exten, sizeof(exten)))) {
2969  break;
2970  }
2971  if (option_exists(menu, exten) < 0) {
2972  if (option_exists(menu, "i")) {
2973  ast_debug(1, "Invalid extension entered, going to 'i'!\n");
2974  strcpy(exten, "i");
2975  pos = 0;
2976  continue;
2977  } else {
2978  ast_debug(1, "Aborting on invalid entry, with no 'i' option!\n");
2979  res = -2;
2980  break;
2981  }
2982  } else {
2983  ast_debug(1, "New existing extension: %s\n", exten);
2984  pos = 0;
2985  continue;
2986  }
2987  }
2988  }
2989  pos++;
2990  }
2991  ast_debug(1, "Stopping option '%s', res is %d\n", exten, res);
2992  pos = 0;
2993  if (!strcasecmp(exten, "s")) {
2994  strcpy(exten, "g");
2995  } else {
2996  break;
2997  }
2998  }
2999  return res;
3000 }
3001 
3002 int ast_ivr_menu_run(struct ast_channel *chan, struct ast_ivr_menu *menu, void *cbdata)
3003 {
3004  int res = ast_ivr_menu_run_internal(chan, menu, cbdata);
3005  /* Hide internal coding */
3006  return res > 0 ? 0 : res;
3007 }
3008 
3009 char *ast_read_textfile(const char *filename)
3010 {
3011  int fd, count = 0, res;
3012  char *output = NULL;
3013  struct stat filesize;
3014 
3015  if (stat(filename, &filesize) == -1) {
3016  ast_log(LOG_WARNING, "Error can't stat %s\n", filename);
3017  return NULL;
3018  }
3019 
3020  count = filesize.st_size + 1;
3021 
3022  if ((fd = open(filename, O_RDONLY)) < 0) {
3023  ast_log(LOG_WARNING, "Cannot open file '%s' for reading: %s\n", filename, strerror(errno));
3024  return NULL;
3025  }
3026 
3027  if ((output = ast_malloc(count))) {
3028  res = read(fd, output, count - 1);
3029  if (res == count - 1) {
3030  output[res] = '\0';
3031  } else {
3032  ast_log(LOG_WARNING, "Short read of %s (%d of %d): %s\n", filename, res, count - 1, strerror(errno));
3033  ast_free(output);
3034  output = NULL;
3035  }
3036  }
3037 
3038  close(fd);
3039 
3040  return output;
3041 }
3042 
3043 static int parse_options(const struct ast_app_option *options, void *_flags, char **args, char *optstr, int flaglen)
3044 {
3045  char *s, *arg;
3046  int curarg, res = 0;
3047  unsigned int argloc;
3048  struct ast_flags *flags = _flags;
3049  struct ast_flags64 *flags64 = _flags;
3050 
3051  if (flaglen == 32) {
3053  } else {
3054  flags64->flags = 0;
3055  }
3056 
3057  if (!optstr) {
3058  return 0;
3059  }
3060 
3061  s = optstr;
3062  while (*s) {
3063  curarg = *s++ & 0x7f; /* the array (in app.h) has 128 entries */
3064  argloc = options[curarg].arg_index;
3065  if (*s == '(') {
3066  int paren = 1, quote = 0;
3067  int parsequotes = (s[1] == '"') ? 1 : 0;
3068 
3069  /* Has argument */
3070  arg = ++s;
3071  for (; *s; s++) {
3072  if (*s == '(' && !quote) {
3073  paren++;
3074  } else if (*s == ')' && !quote) {
3075  /* Count parentheses, unless they're within quotes (or backslashed, below) */
3076  paren--;
3077  } else if (*s == '"' && parsequotes) {
3078  /* Leave embedded quotes alone, unless they are the first character */
3079  quote = quote ? 0 : 1;
3080  ast_copy_string(s, s + 1, INT_MAX);
3081  s--;
3082  } else if (*s == '\\') {
3083  if (!quote) {
3084  /* If a backslash is found outside of quotes, remove it */
3085  ast_copy_string(s, s + 1, INT_MAX);
3086  } else if (quote && s[1] == '"') {
3087  /* Backslash for a quote character within quotes, remove the backslash */
3088  ast_copy_string(s, s + 1, INT_MAX);
3089  } else {
3090  /* Backslash within quotes, keep both characters */
3091  s++;
3092  }
3093  }
3094 
3095  if (paren == 0) {
3096  break;
3097  }
3098  }
3099  /* This will find the closing paren we found above, or none, if the string ended before we found one. */
3100  if ((s = strchr(s, ')'))) {
3101  if (argloc) {
3102  args[argloc - 1] = arg;
3103  }
3104  *s++ = '\0';
3105  } else {
3106  ast_log(LOG_WARNING, "Missing closing parenthesis for argument '%c' in string '%s'\n", curarg, arg);
3107  res = -1;
3108  break;
3109  }
3110  } else if (argloc) {
3111  args[argloc - 1] = "";
3112  }
3113  if (!options[curarg].flag) {
3114  ast_log(LOG_WARNING, "Unrecognized option: '%c'\n", curarg);
3115  }
3116  if (flaglen == 32) {
3117  ast_set_flag(flags, options[curarg].flag);
3118  } else {
3119  ast_set_flag64(flags64, options[curarg].flag);
3120  }
3121  }
3122 
3123  return res;
3124 }
3125 
3126 int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
3127 {
3128  return parse_options(options, flags, args, optstr, 32);
3129 }
3130 
3131 int ast_app_parse_options64(const struct ast_app_option *options, struct ast_flags64 *flags, char **args, char *optstr)
3132 {
3133  return parse_options(options, flags, args, optstr, 64);
3134 }
3135 
3136 void ast_app_options2str64(const struct ast_app_option *options, struct ast_flags64 *flags, char *buf, size_t len)
3137 {
3138  unsigned int i, found = 0;
3139  for (i = 32; i < 128 && found < len; i++) {
3140  if (ast_test_flag64(flags, options[i].flag)) {
3141  buf[found++] = i;
3142  }
3143  }
3144  buf[found] = '\0';
3145 }
3146 
3147 int ast_get_encoded_char(const char *stream, char *result, size_t *consumed)
3148 {
3149  int i;
3150  *consumed = 1;
3151  *result = 0;
3152  if (ast_strlen_zero(stream)) {
3153  *consumed = 0;
3154  return -1;
3155  }
3156 
3157  if (*stream == '\\') {
3158  *consumed = 2;
3159  switch (*(stream + 1)) {
3160  case 'n':
3161  *result = '\n';
3162  break;
3163  case 'r':
3164  *result = '\r';
3165  break;
3166  case 't':
3167  *result = '\t';
3168  break;
3169  case 'x':
3170  /* Hexadecimal */
3171  if (strchr("0123456789ABCDEFabcdef", *(stream + 2)) && *(stream + 2) != '\0') {
3172  *consumed = 3;
3173  if (*(stream + 2) <= '9') {
3174  *result = *(stream + 2) - '0';
3175  } else if (*(stream + 2) <= 'F') {
3176  *result = *(stream + 2) - 'A' + 10;
3177  } else {
3178  *result = *(stream + 2) - 'a' + 10;
3179  }
3180  } else {
3181  ast_log(LOG_ERROR, "Illegal character '%c' in hexadecimal string\n", *(stream + 2));
3182  return -1;
3183  }
3184 
3185  if (strchr("0123456789ABCDEFabcdef", *(stream + 3)) && *(stream + 3) != '\0') {
3186  *consumed = 4;
3187  *result <<= 4;
3188  if (*(stream + 3) <= '9') {
3189  *result += *(stream + 3) - '0';
3190  } else if (*(stream + 3) <= 'F') {
3191  *result += *(stream + 3) - 'A' + 10;
3192  } else {
3193  *result += *(stream + 3) - 'a' + 10;
3194  }
3195  }
3196  break;
3197  case '0':
3198  /* Octal */
3199  *consumed = 2;
3200  for (i = 2; ; i++) {
3201  if (strchr("01234567", *(stream + i)) && *(stream + i) != '\0') {
3202  (*consumed)++;
3203  ast_debug(5, "result was %d, ", *result);
3204  *result <<= 3;
3205  *result += *(stream + i) - '0';
3206  ast_debug(5, "is now %d\n", *result);
3207  } else {
3208  break;
3209  }
3210  }
3211  break;
3212  default:
3213  *result = *(stream + 1);
3214  }
3215  } else {
3216  *result = *stream;
3217  *consumed = 1;
3218  }
3219  return 0;
3220 }
3221 
3222 char *ast_get_encoded_str(const char *stream, char *result, size_t result_size)
3223 {
3224  char *cur = result;
3225  size_t consumed;
3226 
3227  while (cur < result + result_size - 1 && !ast_get_encoded_char(stream, cur, &consumed)) {
3228  cur++;
3229  stream += consumed;
3230  }
3231  *cur = '\0';
3232  return result;
3233 }
3234 
3235 int ast_str_get_encoded_str(struct ast_str **str, int maxlen, const char *stream)
3236 {
3237  char next, *buf;
3238  size_t offset = 0;
3239  size_t consumed;
3240 
3241  if (strchr(stream, '\\')) {
3242  while (!ast_get_encoded_char(stream, &next, &consumed)) {
3243  if (offset + 2 > ast_str_size(*str) && maxlen > -1) {
3244  ast_str_make_space(str, maxlen > 0 ? maxlen : (ast_str_size(*str) + 48) * 2 - 48);
3245  }
3246  if (offset + 2 > ast_str_size(*str)) {
3247  break;
3248  }
3249  buf = ast_str_buffer(*str);
3250  buf[offset++] = next;
3251  stream += consumed;
3252  }
3253  buf = ast_str_buffer(*str);
3254  buf[offset++] = '\0';
3255  ast_str_update(*str);
3256  } else {
3257  ast_str_set(str, maxlen, "%s", stream);
3258  }
3259  return 0;
3260 }
3261 
3263 {
3264  closefrom(n + 1);
3265 }
3266 
3267 int ast_safe_fork(int stop_reaper)
3268 {
3269  sigset_t signal_set, old_set;
3270  int pid;
3271 
3272  /* Don't let the default signal handler for children reap our status */
3273  if (stop_reaper) {
3275  }
3276 
3277  /* GCC 4.9 gives a bogus "right-hand operand of comma expression has
3278  * no effect" warning */
3279  (void) sigfillset(&signal_set);
3280  pthread_sigmask(SIG_BLOCK, &signal_set, &old_set);
3281 
3282  pid = fork();
3283 
3284  if (pid != 0) {
3285  /* Fork failed or parent */
3286  pthread_sigmask(SIG_SETMASK, &old_set, NULL);
3287  if (!stop_reaper && pid > 0) {
3288  struct zombie *cur = ast_calloc(1, sizeof(*cur));
3289  if (cur) {
3290  cur->pid = pid;
3296  ast_log(LOG_ERROR, "Shaun of the Dead wants to kill zombies, but can't?!!\n");
3298  }
3299  }
3300  }
3301  }
3302  return pid;
3303  } else {
3304  /* Child */
3305 #ifdef HAVE_CAP
3306  cap_set_proc(child_cap);
3307 #endif
3308 
3309  /* Before we unblock our signals, return our trapped signals back to the defaults */
3310  signal(SIGHUP, SIG_DFL);
3311  signal(SIGCHLD, SIG_DFL);
3312  signal(SIGINT, SIG_DFL);
3313  signal(SIGURG, SIG_DFL);
3314  signal(SIGTERM, SIG_DFL);
3315  signal(SIGPIPE, SIG_DFL);
3316  signal(SIGXFSZ, SIG_DFL);
3317 
3318  /* unblock important signal handlers */
3319  if (pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL)) {
3320  ast_log(LOG_WARNING, "unable to unblock signals: %s\n", strerror(errno));
3321  _exit(1);
3322  }
3323 
3324  return pid;
3325  }
3326 }
3327 
3329 {
3331 }
3332 
3333 int ast_app_parse_timelen(const char *timestr, int *result, enum ast_timelen unit)
3334 {
3335  int res;
3336  char u[10];
3337 #ifdef HAVE_LONG_DOUBLE_WIDER
3338  long double amount;
3339  #define FMT "%30Lf%9s"
3340 #else
3341  double amount;
3342  #define FMT "%30lf%9s"
3343 #endif
3344  if (!timestr) {
3345  return -1;
3346  }
3347 
3348  res = sscanf(timestr, FMT, &amount, u);
3349 
3350  if (res == 0 || res == EOF) {
3351 #undef FMT
3352  return -1;
3353  } else if (res == 2) {
3354  switch (u[0]) {
3355  case 'h':
3356  case 'H':
3357  unit = TIMELEN_HOURS;
3358  if (u[1] != '\0') {
3359  return -1;
3360  }
3361  break;
3362  case 's':
3363  case 'S':
3364  unit = TIMELEN_SECONDS;
3365  if (u[1] != '\0') {
3366  return -1;
3367  }
3368  break;
3369  case 'm':
3370  case 'M':
3371  if (toupper(u[1]) == 'S') {
3372  unit = TIMELEN_MILLISECONDS;
3373  if (u[2] != '\0') {
3374  return -1;
3375  }
3376  } else if (u[1] == '\0') {
3377  unit = TIMELEN_MINUTES;
3378  } else {
3379  return -1;
3380  }
3381  break;
3382  default:
3383  return -1;
3384  }
3385  }
3386 
3387  switch (unit) {
3388  case TIMELEN_HOURS:
3389  amount *= 60;
3390  /* fall-through */
3391  case TIMELEN_MINUTES:
3392  amount *= 60;
3393  /* fall-through */
3394  case TIMELEN_SECONDS:
3395  amount *= 1000;
3396  /* fall-through */
3397  case TIMELEN_MILLISECONDS:
3398  ;
3399  }
3400  *result = amount > INT_MAX ? INT_MAX : (int) amount;
3401  return 0;
3402 }
3403 
3405 {
3406  return queue_topic_all;
3407 }
3408 
3409 struct stasis_topic *ast_queue_topic(const char *queuename)
3410 {
3411  return stasis_topic_pool_get_topic(queue_topic_pool, queuename);
3412 }
3413 
3414 static void app_cleanup(void)
3415 {
3416 #ifdef HAS_CAP
3417  cap_free(child_cap);
3418 #endif
3423 }
3424 
3425 int app_init(void)
3426 {
3428 #ifdef HAVE_CAP
3429  child_cap = cap_from_text("cap_net_admin-eip");
3430 #endif
3431  queue_topic_all = stasis_topic_create("queue:all");
3432  if (!queue_topic_all) {
3433  return -1;
3434  }
3436  if (!queue_topic_pool) {
3437  return -1;
3438  }
3439  return 0;
3440 }
#define paren
Definition: ael_lex.c:973
#define comment
Definition: ael_lex.c:976
char digit
@ ignore_hangup
jack_status_t status
Definition: app_jack.c:146
const char * str
Definition: app_jack.c:147
unsigned int stop
Definition: app_meetme.c:1098
static int skipms
static const struct ast_vm_functions vm_table
static int messagecount(const char *mailbox_id, const char *folder)
static int inboxcount(const char *mailbox, int *newmsgs, int *oldmsgs)
static int silencethreshold
static int maxsilence
static int has_voicemail(const char *mailbox, const char *folder)
Determines if the given folder has messages.
static int inboxcount2(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
Check the given mailbox's message count.
static int sayname(struct ast_channel *chan, const char *mailbox, const char *context)
static struct ast_str * prompt
Definition: asterisk.c:2761
Asterisk main include file. File version handling, generic pbx functions.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
#define AST_FILE_MODE
Definition: asterisk.h:32
#define PATH_MAX
Definition: asterisk.h:40
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
Definition: astmm.h:288
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_malloc(len)
A wrapper for malloc()
Definition: astmm.h:191
#define ast_log
Definition: astobj2.c:42
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
#define ao2_global_obj_replace_unref(holder, obj)
Replace an ao2 object in the global holder, throwing away any old object.
Definition: astobj2.h:901
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
Definition: astobj2.h:918
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:404
#define ao2_global_obj_release(holder)
Release the ao2 object held in the global holder.
Definition: astobj2.h:859
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
static int tmp()
Definition: bt_open.c:389
static void suspend(struct cc_core_instance *core_instance)
Definition: ccss.c:3193
static char * table
Definition: cdr_odbc.c:55
static PGresult * result
Definition: cel_pgsql.c:84
static char exten[AST_MAX_EXTENSION]
Definition: chan_alsa.c:122
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:120
static char mailbox[AST_MAX_MAILBOX_UNIQUEID]
Definition: chan_mgcp.c:207
static const char type[]
Definition: chan_ooh323.c:109
General Asterisk PBX channel definitions.
struct ast_filestream * ast_channel_stream(const struct ast_channel *chan)
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
Definition: channel.c:3176
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
Definition: autoservice.c:266
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
Definition: channel.c:2952
struct ast_frame * ast_read_noaudio(struct ast_channel *chan)
Reads a frame, returning AST_FRAME_NULL frame if audio.
Definition: channel.c:4302
int ast_readstring_full(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders, int audiofd, int ctrlfd)
Definition: channel.c:6641
struct ast_format * ast_channel_writeformat(struct ast_channel *chan)
struct ast_silence_generator * ast_channel_start_silence_generator(struct ast_channel *chan)
Starts a silence generator on the given channel.
Definition: channel.c:8247
int ast_queue_hangup(struct ast_channel *chan)
Queue a hangup frame.
Definition: channel.c:1144
struct ast_pbx * ast_channel_pbx(const struct ast_channel *chan)
int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration)
Send a DTMF digit to a channel.
Definition: channel.c:5009
const char * ast_channel_context(const struct ast_channel *chan)
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3163
int ast_channel_priority(const struct ast_channel *chan)
void ast_channel_stop_silence_generator(struct ast_channel *chan, struct ast_silence_generator *state)
Stops a previously-started silence generator on the given channel.
Definition: channel.c:8293
struct ast_tone_zone * ast_channel_zone(const struct ast_channel *chan)
int ast_check_hangup_locked(struct ast_channel *chan)
Definition: channel.c:459
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:5179
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
Definition: autoservice.c:200
const char * ast_channel_name(const struct ast_channel *chan)
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4292
int ast_senddigit_mf_end(struct ast_channel *chan)
End sending an MF digit to a channel.
Definition: channel.c:4978
int ast_senddigit_external(struct ast_channel *chan, char digit, unsigned int duration)
Send a DTMF digit to a channel from an external thread.
Definition: channel.c:5022
@ AST_FLAG_WRITE_INT
Definition: channel.h:983
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
Definition: channel.c:5839
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
const char * ast_channel_language(const struct ast_channel *chan)
const char * ast_channel_exten(const struct ast_channel *chan)
struct ast_format * ast_channel_readformat(struct ast_channel *chan)
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
Definition: channel.c:5880
struct ast_party_caller * ast_channel_caller(struct ast_channel *chan)
int ast_senddigit_mf(struct ast_channel *chan, char digit, unsigned int duration, unsigned int durationkp, unsigned int durationst, int is_external)
Send an MF digit to a channel.
Definition: channel.c:4987
int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders)
Reads multiple digits.
Definition: channel.c:6636
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
Definition: channel.c:4312
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
Definition: channel.c:1568
#define AST_MAX_EXTENSION
Definition: channel.h:134
ast_lock_type
Definition: check_expr.c:35
Convenient Signal Processing routines.
void ast_dsp_set_threshold(struct ast_dsp *dsp, int threshold)
Set the minimum average magnitude threshold to determine talking by the DSP.
Definition: dsp.c:1778
void ast_dsp_free(struct ast_dsp *dsp)
Definition: dsp.c:1773
struct ast_dsp * ast_dsp_new(void)
Allocates a new dsp, assumes 8khz for internal sample rate.
Definition: dsp.c:1748
@ THRESHOLD_SILENCE
Definition: dsp.h:73
int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence)
Process the audio frame for silence.
Definition: dsp.c:1486
int ast_dsp_get_threshold_from_settings(enum threshold which)
Get silence threshold from dsp.conf.
Definition: dsp.c:1999
char * end
Definition: eagi_proxy.c:73
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
long int flag
Definition: f2c.h:83
Generic File Format Support. Should be included by clients of the file handling routines....
off_t ast_tellstream(struct ast_filestream *fs)
Tell where we are in a stream.
Definition: file.c:1083
int ast_waitstream_fr_w_cb(struct ast_channel *c, const char *breakon, const char *forward, const char *rewind, int ms, ast_waitstream_fr_cb cb)
Same as waitstream_fr but allows a callback to be alerted when a user fastforwards or rewinds the fil...
Definition: file.c:1775
void() ast_waitstream_fr_cb(struct ast_channel *chan, long ms, enum ast_waitstream_fr_cb_values val)
callback used during dtmf controlled file playback to indicate location of playback in a file after r...
Definition: file.h:65
int ast_stopstream(struct ast_channel *c)
Stops a stream.
Definition: file.c:222
int ast_writestream(struct ast_filestream *fs, struct ast_frame *f)
Writes a frame to a stream.
Definition: file.c:244
int ast_seekstream(struct ast_filestream *fs, off_t sample_offset, int whence)
Seeks into stream.
Definition: file.c:1073
int ast_stream_rewind(struct ast_filestream *fs, off_t ms)
Rewind stream ms.
Definition: file.c:1098
int ast_filerename(const char *oldname, const char *newname, const char *fmt)
Renames a file.
Definition: file.c:1144
int ast_waitstream_fr(struct ast_channel *c, const char *breakon, const char *forward, const char *rewind, int ms)
Same as waitstream but allows stream to be forwarded or rewound.
Definition: file.c:1786
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:1291
int ast_stream_and_wait(struct ast_channel *chan, const char *file, const char *digits)
stream file until digit If the file name is non-empty, try to play it.
Definition: file.c:1855
struct ast_frame * ast_readframe(struct ast_filestream *s)
Read a frame from a filestream.
Definition: file.c:934
struct ast_filestream * ast_writefile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
Starts writing a file.
Definition: file.c:1402
int ast_truncstream(struct ast_filestream *fs)
Trunc stream at current location.
Definition: file.c:1078
int ast_closestream(struct ast_filestream *f)
Closes a stream.
Definition: file.c:1109
struct ast_filestream * ast_readfile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
Starts reading from a file.
Definition: file.c:1350
int ast_filedelete(const char *filename, const char *fmt)
Deletes a file.
Definition: file.c:1139
#define AST_DIGIT_ANY
Definition: file.h:48
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1817
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
@ AST_FORMAT_CMP_NOT_EQUAL
Definition: format.h:38
Media Format Cache API.
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
static int array(struct ast_channel *chan, const char *cmd, char *var, const char *value)
static int quote(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
ast_getdata_result
@ AST_GETDATA_EMPTY_END_TERMINATED
@ AST_LOCK_SUCCESS
@ AST_LOCK_PATH_NOT_FOUND
@ AST_LOCK_TIMEOUT
@ AST_LOCK_FAILURE
ast_vm_snapshot_sort_val
void ast_replace_sigchld(void)
Replace the SIGCHLD handler.
Definition: extconf.c:801
#define VM_GREETER_MODULE_VERSION
#define VM_MODULE_VERSION
AST_LOCK_TYPE
Type of locking to use in ast_lock_path / ast_unlock_path.
@ AST_LOCK_TYPE_LOCKFILE
@ AST_LOCK_TYPE_FLOCK
void() ast_vm_msg_play_cb(struct ast_channel *chan, const char *playfile, int duration)
Voicemail playback callback function definition.
@ TIMELEN_MILLISECONDS
@ TIMELEN_MINUTES
@ TIMELEN_SECONDS
@ TIMELEN_HOURS
ast_record_if_exists
@ AST_RECORD_IF_EXISTS_FAIL
@ AST_RECORD_IF_EXISTS_APPEND
@ AST_RECORD_IF_EXISTS_OVERWRITE
@ AST_RECORD_IF_EXISTS_ERROR
@ AST_ACTION_UPONE
@ AST_ACTION_BACKLIST
@ AST_ACTION_PLAYBACK
@ AST_ACTION_RESTART
@ AST_ACTION_PLAYLIST
@ AST_ACTION_CALLBACK
@ AST_ACTION_NOOP
@ AST_ACTION_EXIT
@ AST_ACTION_BACKGROUND
@ AST_ACTION_WAITOPTION
@ AST_ACTION_MENU
@ AST_ACTION_REPEAT
@ AST_ACTION_TRANSFER
void ast_unreplace_sigchld(void)
Restore the SIGCHLD handler.
Definition: extconf.c:815
char * strsep(char **str, const char *delims)
void closefrom(int lowfd)
Definition: strcompat.c:429
#define AST_MALLOCD_HDR
#define AST_FRAME_DTMF
void ast_frame_dtor(struct ast_frame *frame)
NULL-safe wrapper for ast_frfree, good for RAII_VAR.
Definition: main/frame.c:187
#define ast_frfree(fr)
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
@ AST_FRAME_VIDEO
@ AST_FRAME_VOICE
@ AST_FRAME_CONTROL
@ AST_CONTROL_RECORD_CANCEL
@ AST_CONTROL_WINK
@ AST_CONTROL_STREAM_RESTART
@ AST_CONTROL_STREAM_SUSPEND
@ AST_CONTROL_BUSY
@ AST_CONTROL_VIDUPDATE
@ AST_CONTROL_STREAM_REVERSE
@ AST_CONTROL_RECORD_STOP
@ AST_CONTROL_CONGESTION
@ AST_CONTROL_RECORD_MUTE
@ AST_CONTROL_HANGUP
@ AST_CONTROL_STREAM_STOP
@ AST_CONTROL_STREAM_FORWARD
@ AST_CONTROL_FLASH
@ AST_CONTROL_RECORD_SUSPEND
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define ast_verb(level,...)
#define LOG_NOTICE
#define LOG_WARNING
Tone Indication Support.
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
struct ast_tone_zone * ast_get_indication_zone(const char *country)
locate ast_tone_zone
Definition: indications.c:433
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:302
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
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
Definition: indications.c:393
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
Asterisk JSON abstraction layer.
A set of macros to manage forward-linked lists.
#define AST_RWLIST_REMOVE_CURRENT
Definition: linkedlists.h:570
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78
#define AST_LIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
Definition: linkedlists.h:291
#define AST_RWLIST_TRAVERSE_SAFE_BEGIN
Definition: linkedlists.h:545
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized.
Definition: linkedlists.h:333
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
Definition: linkedlists.h:450
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
Definition: linkedlists.h:731
#define AST_RWLIST_FIRST
Definition: linkedlists.h:423
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
Definition: linkedlists.h:410
#define AST_RWLIST_TRAVERSE_SAFE_END
Definition: linkedlists.h:617
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
Definition: linkedlists.h:615
#define AST_LIST_LOCK(head)
Locks a list.
Definition: linkedlists.h:40
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:494
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
Definition: linkedlists.h:529
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
Definition: linkedlists.h:557
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:741
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
Definition: linkedlists.h:140
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
Definition: linkedlists.h:421
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
Definition: linkedlists.h:439
Asterisk locking-related definitions:
#define AST_PTHREADT_NULL
Definition: lock.h:66
static enum control_tone_frame_response_result control_tone_frame_response(struct ast_channel *chan, struct ast_frame *fr, struct ast_tone_zone_sound *ts, const char *tone, int *paused)
Definition: main/app.c:1556
int ast_app_group_get_count(const char *group, const char *category)
Get the current channel count of the specified group and category.
Definition: main/app.c:2300
int __ast_vm_greeter_register(const struct ast_vm_greeter_functions *vm_table, struct ast_module *module)
Set voicemail greeter function callbacks.
Definition: main/app.c:549
static int global_maxsilence
Definition: main/app.c:1772
AST_THREADSTORAGE_PUBLIC(ast_str_thread_global_buf)
static int ast_ivr_menu_run_internal(struct ast_channel *chan, struct ast_ivr_menu *menu, void *cbdata)
Definition: main/app.c:2917
int ast_sf_stream(struct ast_channel *chan, struct ast_channel *peer, struct ast_channel *chan2, const char *digits, int frequency, int is_external)
Send a string of SF digits to a channel.
Definition: main/app.c:1167
int ast_play_and_record_full(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int *sound_duration, int beep, int silencethreshold, int maxsilence, const char *path, const char *acceptdtmf, const char *canceldtmf, int skip_confirmation_sound, enum ast_record_if_exists if_exists)
Record a file based on input from a channel This function will play "auth-thankyou" upon successful r...
Definition: main/app.c:2209
int ast_app_getdata_full(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout, int audiofd, int ctrlfd)
Full version with audiofd and controlfd. NOTE: returns '2' on ctrlfd available, not '1' like other fu...
Definition: main/app.c:247
void ast_safe_fork_cleanup(void)
Common routine to cleanup after fork'ed process is complete (if reaping was stopped)
Definition: main/app.c:3328
#define VM_API_CALL(res, api_call, api_parms)
Definition: main/app.c:617
int ast_str_get_encoded_str(struct ast_str **str, int maxlen, const char *stream)
Decode a stream of encoded control or extended ASCII characters.
Definition: main/app.c:3235
int ast_app_messagecount(const char *mailbox_id, const char *folder)
Get the number of messages in a given mailbox folder.
Definition: main/app.c:715
static int parse_options(const struct ast_app_option *options, void *_flags, char **args, char *optstr, int flaglen)
Definition: main/app.c:3043
static int ast_unlock_path_flock(const char *path)
Definition: main/app.c:2639
const char * ast_app_expand_sub_args(struct ast_channel *chan, const char *args)
Add missing context/exten to subroutine argument string.
Definition: main/app.c:348
int __ast_vm_register(const struct ast_vm_functions *vm_table, struct ast_module *module)
Set voicemail function callbacks.
Definition: main/app.c:438
unsigned int __ast_app_separate_args(char *buf, char delim, int remove_chars, char **array, int arraylen)
Separate a string into arguments in an array.
Definition: main/app.c:2416
static int option_exists(struct ast_ivr_menu *menu, char *option)
Definition: main/app.c:2876
int ast_get_encoded_char(const char *stream, char *result, size_t *consumed)
Decode an encoded control or extended ASCII character.
Definition: main/app.c:3147
int ast_linear_stream(struct ast_channel *chan, const char *filename, int fd, int allowoverride)
Stream a filename (or file descriptor) as a generator.
Definition: main/app.c:1305
int ast_control_streamfile_w_cb(struct ast_channel *chan, const char *file, const char *fwd, const char *rev, const char *stop, const char *suspend, const char *restart, int skipms, long *offsetms, ast_waitstream_fr_cb cb)
Stream a file with fast forward, pause, reverse, restart.
Definition: main/app.c:1521
static const char default_acceptdtmf[]
Definition: main/app.c:2206
int app_init(void)
Initialize the application core.
Definition: main/app.c:3425
int ast_app_run_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const char *macro_name, const char *macro_args)
Run a macro on a channel, placing an optional second channel into autoservice.
Definition: main/app.c:317
static pthread_t shaun_of_the_dead_thread
Definition: main/app.c:74
int ast_play_and_prepend(struct ast_channel *chan, char *playfile, char *recordfile, int maxtime, char *fmt, int *duration, int *sound_duration, int beep, int silencethreshold, int maxsilence)
Record a file based on input frm a channel. Recording is performed in 'prepend' mode which works a li...
Definition: main/app.c:2219
static int control_streamfile(struct ast_channel *chan, const char *file, const char *fwd, const char *rev, const char *stop, const char *suspend, const char *restart, int skipms, long *offsetms, const char *lang, ast_waitstream_fr_cb cb)
Definition: main/app.c:1347
int ast_app_group_update(struct ast_channel *old, struct ast_channel *new)
Update all group counting for a channel to a new one.
Definition: main/app.c:2360
void ast_dtmf_stream_external(struct ast_channel *chan, const char *digits, int between, unsigned int duration)
Send a string of DTMF digits to a channel from an external thread.
Definition: main/app.c:1212
int ast_vm_msg_play(struct ast_channel *chan, const char *mailbox, const char *context, const char *folder, const char *msg_num, ast_vm_msg_play_cb *cb)
Play a voicemail msg back on a channel.
Definition: main/app.c:796
static int global_silence_threshold
Definition: main/app.c:1771
static int linear_generator(struct ast_channel *chan, void *data, int len, int samples)
Definition: main/app.c:1241
#define FMT
static int ast_unlock_path_lockfile(const char *path)
Definition: main/app.c:2517
int ast_app_run_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_location, const char *sub_args, int ignore_hangup)
Run a subroutine on a channel, placing an optional second channel into autoservice.
Definition: main/app.c:398
static const struct ast_app_stack_funcs * app_stack_callbacks
Definition: main/app.c:341
int ast_control_streamfile(struct ast_channel *chan, const char *file, const char *fwd, const char *rev, const char *stop, const char *suspend, const char *restart, int skipms, long *offsetms)
Stream a file with fast forward, pause, reverse, restart.
Definition: main/app.c:1535
static int dtmf_stream(struct ast_channel *chan, const char *digits, int between, unsigned int duration, int is_external)
Definition: main/app.c:1099
static int option_matchmore(struct ast_ivr_menu *menu, char *option)
Definition: main/app.c:2887
int ast_app_parse_timelen(const char *timestr, int *result, enum ast_timelen unit)
Common routine to parse time lengths, with optional time unit specifier.
Definition: main/app.c:3333
void ast_vm_greeter_unregister(const char *module_name)
Unregister the specified voicemail greeter provider.
Definition: main/app.c:581
static struct ast_generator linearstream
Definition: main/app.c:1298
int ast_control_tone(struct ast_channel *chan, const char *tone)
Controls playback of a tone.
Definition: main/app.c:1615
enum ast_getdata_result ast_app_getdata(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout)
Plays a stream and gets DTMF data from a channel.
Definition: main/app.c:188
static enum AST_LOCK_RESULT ast_lock_path_lockfile(const char *path)
Definition: main/app.c:2480
#define SF_BETWEEN
static int __ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int *sound_duration, int beep, int silencethreshold, int maxsilence, const char *path, int prepend, const char *acceptdtmf, const char *canceldtmf, int skip_confirmation_sound, enum ast_record_if_exists if_exists)
Definition: main/app.c:1797
static enum AST_LOCK_RESULT ast_lock_path_flock(const char *path)
Definition: main/app.c:2554
struct ast_vm_mailbox_snapshot * ast_vm_mailbox_snapshot_destroy(struct ast_vm_mailbox_snapshot *mailbox_snapshot)
destroy a snapshot
Definition: main/app.c:745
static const char default_canceldtmf[]
Definition: main/app.c:2207
static struct stasis_topic_pool * queue_topic_pool
Definition: main/app.c:91
int ast_app_group_match_get_count(const char *groupmatch, const char *category)
Get the current channel count of all groups that match the specified pattern and category.
Definition: main/app.c:2320
int ast_app_group_set_channel(struct ast_channel *chan, const char *data)
Set the group for a channel, splitting the provided data into group and category, if specified.
Definition: main/app.c:2253
int ast_app_group_list_wrlock(void)
Write Lock the group count list.
Definition: main/app.c:2396
static struct stasis_topic * queue_topic_all
Define Stasis Message Bus API topic objects.
Definition: main/app.c:90
enum AST_LOCK_RESULT ast_lock_path(const char *path)
Lock a filesystem path.
Definition: main/app.c:2674
static void * shaun_of_the_dead(void *data)
Definition: main/app.c:95
int ast_app_has_voicemail(const char *mailboxes, const char *folder)
Determine if a given mailbox has any voicemail If folder is NULL, defaults to "INBOX"....
Definition: main/app.c:652
static void path_lock_destroy(struct path_lock *obj)
Definition: main/app.c:2543
int ast_safe_fork(int stop_reaper)
Common routine to safely fork without a chance of a signal handler firing badly in the child.
Definition: main/app.c:3267
char * ast_get_encoded_str(const char *stream, char *result, size_t result_size)
Decode a stream of encoded control or extended ASCII characters.
Definition: main/app.c:3222
static int sf_stream(struct ast_channel *chan, struct ast_channel *chan2, const char *digits, int frequency, int is_external)
Definition: main/app.c:833
static void app_cleanup(void)
Definition: main/app.c:3414
void ast_install_stack_functions(const struct ast_app_stack_funcs *funcs)
Set stack application function callbacks.
Definition: main/app.c:343
#define VM_GREETER_API_CALL(res, api_call, api_parms)
Definition: main/app.c:638
int ast_record_review(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, const char *path)
Allow to record message and have a review option.
Definition: main/app.c:2706
struct stasis_topic * ast_queue_topic(const char *queuename)
Get the Stasis Message Bus API topic for queue messages for a particular queue name.
Definition: main/app.c:3409
int ast_vm_msg_forward(const char *from_mailbox, const char *from_context, const char *from_folder, const char *to_mailbox, const char *to_context, const char *to_folder, size_t num_msgs, const char *msg_ids[], int delete_old)
forward a message from one mailbox to another.
Definition: main/app.c:779
static int external_sleep(struct ast_channel *chan, int ms)
Definition: main/app.c:827
control_tone_frame_response_result
Definition: main/app.c:1550
@ CONTROL_TONE_RESPONSE_FAILED
Definition: main/app.c:1551
@ CONTROL_TONE_RESPONSE_NORMAL
Definition: main/app.c:1552
@ CONTROL_TONE_RESPONSE_FINISHED
Definition: main/app.c:1553
static int read_newoption(struct ast_channel *chan, struct ast_ivr_menu *menu, char *exten, int maxexten)
Definition: main/app.c:2899
#define SF_BUF_LEN
enum ast_getdata_result ast_app_getdata_terminator(struct ast_channel *c, const char *prompt, char *s, int maxlen, int timeout, char *terminator)
Plays a stream and gets DTMF data from a channel.
Definition: main/app.c:193
static void * linear_alloc(struct ast_channel *chan, void *params)
Definition: main/app.c:1271
#define RES_UPONE
Definition: main/app.c:2800
int ast_app_copy_recording_to_vm(struct ast_vm_recording_data *vm_rec_data)
param[in] vm_rec_data Contains data needed to make the recording. retval 0 voicemail successfully cre...
Definition: main/app.c:666
int ast_vm_greeter_is_registered(void)
Determine if a voicemail greeter provider is registered.
Definition: main/app.c:538
int ast_app_group_list_unlock(void)
Unlock the group count list.
Definition: main/app.c:2411
static int mf_stream(struct ast_channel *chan, struct ast_channel *chan2, const char *digits, int between, unsigned int duration, unsigned int durationkp, unsigned int durationst, int is_external)
Definition: main/app.c:984
#define AST_MAX_FORMATS
Definition: main/app.c:122
void ast_vm_unregister(const char *module_name)
Unregister the specified voicemail provider.
Definition: main/app.c:470
void ast_set_lock_type(enum AST_LOCK_TYPE type)
Set the type of locks used by ast_lock_path()
Definition: main/app.c:2669
int ast_app_exec_macro(struct ast_channel *autoservice_chan, struct ast_channel *macro_chan, const char *macro_args)
Run a macro on a channel, placing an optional second channel into autoservice.
Definition: main/app.c:270
int ast_app_inboxcount(const char *mailboxes, int *newmsgs, int *oldmsgs)
Determine number of new/old messages in a mailbox.
Definition: main/app.c:674
static int vm_greeter_warnings
Definition: main/app.c:536
int ast_app_group_split_group(const char *data, char *group, int group_max, char *category, int category_max)
Split a group string into group and category, returning a default category if none is provided.
Definition: main/app.c:2226
static AO2_GLOBAL_OBJ_STATIC(vm_provider)
The container for the voicemail provider.
int ast_play_and_wait(struct ast_channel *chan, const char *fn)
Play a stream and wait for a digit, returning the digit that was pressed.
Definition: main/app.c:1686
int ast_control_streamfile_lang(struct ast_channel *chan, const char *file, const char *fwd, const char *rev, const char *stop, const char *suspend, const char *restart, int skipms, const char *lang, long *offsetms)
Version of ast_control_streamfile() which allows the language of the media file to be specified.
Definition: main/app.c:1543
#define SF_OFF
int ast_app_sayname(struct ast_channel *chan, const char *mailbox_id)
Play a recorded user name for the mailbox to the specified channel.
Definition: main/app.c:707
static int vm_warnings
Definition: main/app.c:425
#define RES_EXIT
Definition: main/app.c:2801
int ast_ivr_menu_run(struct ast_channel *chan, struct ast_ivr_menu *menu, void *cbdata)
Runs an IVR menu.
Definition: main/app.c:3002
int ast_app_inboxcount2(const char *mailboxes, int *urgentmsgs, int *newmsgs, int *oldmsgs)
Determine number of urgent/new/old messages in a mailbox.
Definition: main/app.c:689
static struct ast_frame * make_silence(const struct ast_frame *orig)
Construct a silence frame of the same duration as orig.
Definition: main/app.c:1710
int ast_vm_msg_move(const char *mailbox, const char *context, size_t num_msgs, const char *oldfolder, const char *old_msg_ids[], const char *newfolder)
Move messages from one folder to another.
Definition: main/app.c:753
static void vm_greeter_warn_no_provider(void)
Definition: main/app.c:631
const char * ast_vm_index_to_foldername(int id)
Return name of folder, given an id.
Definition: main/app.c:723
char * ast_read_textfile(const char *filename)
Read a file into asterisk.
Definition: main/app.c:3009
void ast_app_options2str64(const struct ast_app_option *options, struct ast_flags64 *flags, char *buf, size_t len)
Given a list of options array, return an option string based on passed flags.
Definition: main/app.c:3136
int ast_app_group_discard(struct ast_channel *chan)
Discard all group counting for a channel.
Definition: main/app.c:2379
#define RES_REPEAT
Definition: main/app.c:2802
struct stasis_topic * ast_queue_topic_all(void)
Get the Stasis Message Bus API topic for queue messages.
Definition: main/app.c:3404
int ast_play_and_record(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int *sound_duration, int silencethreshold, int maxsilence, const char *path)
Record a file based on input from a channel. Use default accept and cancel DTMF. This function will p...
Definition: main/app.c:2214
int ast_vm_is_registered(void)
Determine if a voicemail provider is registered.
Definition: main/app.c:427
static int set_read_to_slin(struct ast_channel *chan, struct ast_format **orig_format)
Sets a channel's read format to ast_format_slin, recording its original format.
Definition: main/app.c:1762
struct ast_group_info * ast_app_group_list_head(void)
Get the head of the group count list.
Definition: main/app.c:2406
struct ast_vm_mailbox_snapshot * ast_vm_mailbox_snapshot_create(const char *mailbox, const char *context, const char *folder, int descending, enum ast_vm_snapshot_sort_val sort_val, int combine_INBOX_and_OLD)
Create a snapshot of a mailbox which contains information about every msg.
Definition: main/app.c:731
static void vm_warn_no_provider(void)
Definition: main/app.c:610
int ast_app_exec_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int ignore_hangup)
Run a subroutine on a channel, placing an optional second channel into autoservice.
Definition: main/app.c:367
int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between, unsigned int duration)
Send a string of DTMF digits to a channel.
Definition: main/app.c:1197
int ast_mf_stream(struct ast_channel *chan, struct ast_channel *peer, struct ast_channel *chan2, const char *digits, int between, unsigned int duration, unsigned int durationkp, unsigned int durationst, int is_external)
Send a string of MF digits to a channel.
Definition: main/app.c:1183
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: main/app.c:3126
int ast_app_dtget(struct ast_channel *chan, const char *context, char *collect, size_t size, int maxlen, int timeout)
This function presents a dialtone and reads an extension into 'collect' which must be a pointer to a ...
Definition: main/app.c:138
int ast_vm_msg_remove(const char *mailbox, const char *context, size_t num_msgs, const char *folder, const char *msgs[])
Remove/delete messages from a mailbox folder.
Definition: main/app.c:767
int ast_unlock_path(const char *path)
Unlock a path.
Definition: main/app.c:2690
static int parse_tone_uri(char *tone_parser, const char **tone_indication, const char **tone_zone)
Definition: main/app.c:1594
static int ivr_dispatch(struct ast_channel *chan, struct ast_ivr_option *option, char *exten, void *cbdata)
Definition: main/app.c:2807
int ast_app_parse_options64(const struct ast_app_option *options, struct ast_flags64 *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: main/app.c:3131
int ast_app_group_list_rdlock(void)
Read Lock the group count list.
Definition: main/app.c:2401
static void linear_release(struct ast_channel *chan, void *params)
Definition: main/app.c:1224
void ast_close_fds_above_n(int n)
Common routine for child processes, to close all fds prior to exec(2)
Definition: main/app.c:3262
#define SF_ON
#define RES_RESTART
Definition: main/app.c:2803
int errno
Asterisk module definitions.
#define ast_module_unref(mod)
Release a reference to the module.
Definition: module.h:469
#define ast_module_running_ref(mod)
Hold a reference to the module if it is running.
Definition: module.h:455
@ AST_MODULE_LOAD_DECLINE
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
def from_mailbox(key, val, section, pjsip, nmapped)
#define ast_opt_transmit_silence
Definition: options.h:124
Asterisk file paths, configured in asterisk.conf.
const char * ast_config_AST_DATA_DIR
Definition: options.c:158
Core PBX routines and definitions.
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
Definition: pbx.c:4182
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
Definition: pbx_app.c:471
int ast_ignore_pattern(const char *context, const char *pattern)
Checks to see if a number should be ignored.
int ast_matchmore_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Looks to see if adding anything to this extension might match something. (exists ^ canmatch)
Definition: pbx.c:4202
struct ast_app * pbx_findapp(const char *app)
Look up an application.
Definition: ael_main.c:165
int ast_parseable_goto(struct ast_channel *chan, const char *goto_string)
#define ast_poll(a, b, c)
Definition: poll-compat.h:88
static int maxretries
Definition: res_adsi.c:60
static struct stasis_rest_handlers mailboxes
REST handler for /api-docs/mailboxes.json.
#define NULL
Definition: resample.c:96
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
struct stasis_topic * stasis_topic_pool_get_topic(struct stasis_topic_pool *pool, const char *topic_name)
Find or create a topic in the pool.
Definition: stasis.c:1886
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
Definition: stasis.c:619
struct stasis_topic_pool * stasis_topic_pool_create(struct stasis_topic *pooled_topic)
Create a topic pool that routes messages from dynamically generated topics to the given topic.
Definition: stasis.c:1835
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:739
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one.
Definition: strings.h:80
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:87
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
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:1091
#define ast_str_make_space(buf, new_len)
Definition: strings.h:806
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
Definition: strings.h:684
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:406
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
Definition: strings.h:723
A structure to hold the description of an application 'option'.
Stack applications callback functions.
int(* run_sub)(struct ast_channel *chan, const char *args, int ignore_hangup)
Callback for the routine to run a subroutine on a channel.
const char *(* expand_sub_args)(struct ast_channel *chan, const char *args)
Add missing context/exten to Gosub application argument string.
ast_app: A registered application
Definition: pbx_app.c:45
Main Channel structure associated with a channel.
char x
Definition: extconf.c:81
Definition: dsp.c:407
int totalsilence
Definition: dsp.c:411
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
Definition: mod_format.h:101
Structure used to handle a large number of boolean flags == used only in app_dial?
Definition: utils.h:204
uint64_t flags
Definition: utils.h:205
Structure used to handle boolean flags.
Definition: utils.h:199
unsigned int flags
Definition: utils.h:200
Definition of a media format.
Definition: format.c:43
struct ast_format * format
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
union ast_frame::@254 data
enum ast_frame_type frametype
void *(* alloc)(struct ast_channel *chan, void *params)
Definition: channel.h:226
channel group info
Definition: channel.h:2915
char * category
Definition: channel.h:2917
char * group
Definition: channel.h:2918
struct ast_channel * chan
Definition: channel.h:2916
struct ast_group_info::@238 group_list
struct ast_ivr_option * options
ast_ivr_action action
int rtimeoutms
Definition: pbx.h:216
int dtimeoutms
Definition: pbx.h:215
Support for dynamic strings.
Definition: strings.h:604
Description of a tone.
Definition: indications.h:35
const char * data
Description of a tone.
Definition: indications.h:52
A set of tones for a given locale.
Definition: indications.h:74
Voicemail function table definition.
unsigned int module_version
The version of this function table.
const char * module_name
The name of the module that provides the voicemail functionality.
struct ast_module * module
The module for the voicemail provider.
Voicemail greeter function table definition.
const char * module_name
The name of the module that provides the voicemail greeter functionality.
struct ast_module * module
The module for the voicemail greeter provider.
Structure used for ast_copy_recording_to_vm in order to cleanly supply data needed for making the rec...
struct ast_format * origwfmt
Definition: main/app.c:1221
int allowoverride
Definition: main/app.c:1220
Number structure.
Definition: app_followme.c:154
struct path_lock::@324 le
char * path
Definition: main/app.c:2538
pid_t pid
Definition: main/app.c:77
struct zombie::@323 list
Test Framework API.
#define ast_test_suite_event_notify(s, f,...)
Definition: test.h:189
const char * args
static struct test_options options
static struct test_val d
static struct test_val c
Definitions to aid in the use of thread local storage.
Utility functions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:936
#define ast_test_flag64(p, flag)
Definition: utils.h:120
#define ast_assert(a)
Definition: utils.h:734
#define ast_pthread_create_background(a, b, c, d)
Definition: utils.h:587
#define ast_clear_flag(p, flag)
Definition: utils.h:77
long int ast_random(void)
Definition: main/utils.c:2210
#define ast_set_flag64(p, flag)
Definition: utils.h:127
#define ast_set_flag(p, flag)
Definition: utils.h:70
#define AST_FLAGS_ALL
Definition: utils.h:196