37 #ifdef HAVE_SYS_STAT_H
44 #include <sys/types.h>
46 #ifndef HAVE_CLOSEFROM
50 #include <sys/capability.h>
68 #include "asterisk/stasis_channels.h"
72 AST_THREADSTORAGE_PUBLIC(ast_str_thread_global_buf);
74 static pthread_t shaun_of_the_dead_thread = AST_PTHREADT_NULL;
84 static cap_t child_cap;
95 static void *shaun_of_the_dead(
void *data)
102 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
105 if (waitpid(cur->pid, &status, WNOHANG) != 0) {
112 pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
114 pthread_testcancel();
122 #define AST_MAX_FORMATS 10
148 if (ast_channel_pbx(chan) && ast_channel_pbx(chan)->dtimeoutms) {
159 ast_log(LOG_NOTICE,
"Huh....? no dial for indications?\n");
162 for (x = strlen(collect); x < maxlen; ) {
175 S_COR(ast_channel_caller(chan)->
id.
number.valid, ast_channel_caller(chan)->
id.
number.str, NULL))) {
182 S_COR(ast_channel_caller(chan)->
id.
number.valid, ast_channel_caller(chan)->
id.
number.str, NULL)) ? 1 : 0;
194 int maxlen,
int timeout,
char *terminator)
196 int res = 0, to, fto;
197 char *front, *filename;
209 if (!ast_strlen_zero(front)) {
214 if (ast_strlen_zero(filename)) {
216 fto = ast_channel_pbx(c) ? ast_channel_pbx(c)->
rtimeoutms : 6000;
217 to = ast_channel_pbx(c) ? ast_channel_pbx(c)->
dtimeoutms : 2000;
223 fto = to = 1000000000;
230 to = ast_channel_pbx(c) ? ast_channel_pbx(c)->
dtimeoutms : 2000;
232 res =
ast_readstring(c, s, maxlen, to, fto, (terminator ? terminator :
"#"));
236 if (!ast_strlen_zero(s)) {
245 static enum AST_LOCK_TYPE ast_lock_type = AST_LOCK_TYPE_LOCKFILE;
249 int res, to = 2000, fto = 6000;
251 if (!ast_strlen_zero(prompt)) {
262 fto = to = 1000000000;
265 res = ast_readstring_full(c, s, maxlen, to, fto,
"#", audiofd, ctrlfd);
275 app_stack_callbacks = funcs;
281 const char *new_args;
283 funcs = app_stack_callbacks;
286 "Cannot expand 'Gosub(%s)' arguments. The app_stack module is not available.\n",
302 funcs = app_stack_callbacks;
305 "Cannot run 'Gosub(%s)'. The app_stack module is not available.\n",
310 if (autoservice_chan) {
314 res = funcs->
run_sub(sub_chan, sub_args, ignore_hangup);
317 if (autoservice_chan) {
321 if (!ignore_hangup && ast_check_hangup_locked(sub_chan)) {
334 if (ast_strlen_zero(sub_args)) {
335 return ast_app_exec_sub(autoservice_chan, sub_chan, sub_location, ignore_hangup);
339 args_len = strlen(sub_location) + strlen(sub_args) + 3;
344 snprintf(args_str, args_len,
"%s(%s)", sub_location, sub_args);
346 res =
ast_app_exec_sub(autoservice_chan, sub_chan, args_str, ignore_hangup);
363 is_registered = table ? 1 : 0;
365 return is_registered;
373 ast_log(LOG_ERROR,
"Voicemail provider missing required information.\n");
377 ast_log(LOG_ERROR,
"Voicemail provider '%s' has incorrect version\n",
384 ast_log(LOG_WARNING,
"Voicemail provider already registered by %s.\n",
405 if (table && !strcmp(table->
module_name, module_name)) {
411 #ifdef TEST_FRAMEWORK
414 static int provider_is_swapped = 0;
421 if (provider_is_swapped) {
422 ast_log(LOG_ERROR,
"Attempted to swap in test function table without swapping out old test table.\n");
436 *new_table = *vm_table;
439 provider_is_swapped = 1;
442 void ast_vm_test_swap_table_out(
void)
446 if (!provider_is_swapped) {
447 ast_log(LOG_ERROR,
"Attempted to swap out test function table, but none is currently installed.\n");
458 provider_is_swapped = 0;
474 is_registered = table ? 1 : 0;
476 return is_registered;
484 ast_log(LOG_ERROR,
"Voicemail greeter provider missing required information.\n");
488 ast_log(LOG_ERROR,
"Voicemail greeter provider '%s' has incorrect version\n",
495 ast_log(LOG_WARNING,
"Voicemail greeter provider already registered by %s.\n",
516 if (table && !strcmp(table->
module_name, module_name)) {
522 #ifdef TEST_FRAMEWORK
523 static ast_vm_test_create_user_fn *ast_vm_test_create_user_func = NULL;
524 static ast_vm_test_destroy_user_fn *ast_vm_test_destroy_user_func = NULL;
526 void ast_install_vm_test_functions(ast_vm_test_create_user_fn *vm_test_create_user_func,
527 ast_vm_test_destroy_user_fn *vm_test_destroy_user_func)
529 ast_vm_test_create_user_func = vm_test_create_user_func;
530 ast_vm_test_destroy_user_func = vm_test_destroy_user_func;
533 void ast_uninstall_vm_test_functions(
void)
535 ast_vm_test_create_user_func = NULL;
536 ast_vm_test_destroy_user_func = NULL;
540 static void vm_warn_no_provider(
void)
543 ast_verb(3,
"No voicemail provider registered.\n");
547 #define VM_API_CALL(res, api_call, api_parms) \
549 struct ast_vm_functions *table; \
550 table = ao2_global_obj_ref(vm_provider); \
552 vm_warn_no_provider(); \
553 } else if (table->api_call) { \
554 ast_module_ref(table->module); \
555 (res) = table->api_call api_parms; \
556 ast_module_unref(table->module); \
558 ao2_cleanup(table); \
561 static void vm_greeter_warn_no_provider(
void)
563 if (vm_greeter_warnings++ % 10 == 0) {
564 ast_verb(3,
"No voicemail greeter provider registered.\n");
568 #define VM_GREETER_API_CALL(res, api_call, api_parms) \
570 struct ast_vm_greeter_functions *table; \
571 table = ao2_global_obj_ref(vm_greeter_provider); \
573 vm_greeter_warn_no_provider(); \
574 } else if (table->api_call) { \
575 ast_module_ref(table->module); \
576 (res) = table->api_call api_parms; \
577 ast_module_unref(table->module); \
579 ao2_cleanup(table); \
600 VM_API_CALL(res, copy_recording_to_vm, (vm_rec_data));
615 VM_API_CALL(res, inboxcount, (mailboxes, newmsgs, oldmsgs));
633 VM_API_CALL(res,
inboxcount2, (mailboxes, urgentmsgs, newmsgs, oldmsgs));
641 VM_GREETER_API_CALL(res, sayname, (chan, mailbox_id));
649 VM_API_CALL(res, messagecount, (mailbox_id, folder));
655 const char *res = NULL;
657 VM_API_CALL(res, index_to_foldername, (
id));
665 enum ast_vm_snapshot_sort_val sort_val,
666 int combine_INBOX_and_OLD)
670 VM_API_CALL(res, mailbox_snapshot_create, (mailbox, context, folder, descending,
671 sort_val, combine_INBOX_and_OLD));
679 VM_API_CALL(res, mailbox_snapshot_destroy, (mailbox_snapshot));
686 const char *oldfolder,
687 const char *old_msg_ids[],
688 const char *newfolder)
692 VM_API_CALL(res, msg_move, (mailbox, context, num_msgs, oldfolder, old_msg_ids,
705 VM_API_CALL(res, msg_remove, (mailbox, context, num_msgs, folder, msgs));
710 const char *from_context,
711 const char *from_folder,
712 const char *to_mailbox,
713 const char *to_context,
714 const char *to_folder,
716 const char *msg_ids[],
721 VM_API_CALL(res, msg_forward, (from_mailbox, from_context, from_folder, to_mailbox,
722 to_context, to_folder, num_msgs, msg_ids, delete_old));
735 VM_API_CALL(res, msg_play, (chan, mailbox, context, folder, msg_num, cb));
739 #ifdef TEST_FRAMEWORK
740 int ast_vm_test_create_user(
const char *context,
const char *mailbox)
742 if (ast_vm_test_create_user_func) {
743 return ast_vm_test_create_user_func(context, mailbox);
748 int ast_vm_test_destroy_user(
const char *context,
const char *mailbox)
750 if (ast_vm_test_destroy_user_func) {
751 return ast_vm_test_destroy_user_func(context, mailbox);
757 static int external_sleep(
struct ast_channel *chan,
int ms)
763 static int sf_stream(
struct ast_channel *chan,
struct ast_channel *chan2,
const char *digits,
int frequency,
int is_external)
768 #define SF_BETWEEN 600
776 if (frequency >= 100000) {
777 ast_log(LOG_WARNING,
"Frequency too large: %d\n", frequency);
782 my_sleep = external_sleep;
788 if (ast_opt_transmit_silence) {
797 res = my_sleep(chan, 100);
802 goto sf_stream_cleanup;
806 #define SF_BUF_LEN 20
809 snprintf(freq, SF_BUF_LEN,
"%d/%d,%d/%d", frequency, SF_ON, 0, SF_OFF);
811 for (ptr = digits; *ptr; ptr++) {
817 res = my_sleep(chan, 500);
824 }
else if (*ptr ==
'h' || *ptr ==
'H') {
832 res = my_sleep(chan, 250);
841 }
else if (strchr(
"0123456789*#ABCDabcdwWfF", *ptr)) {
842 if (*ptr ==
'f' || *ptr ==
'F') {
845 }
else if (*ptr ==
'W') {
853 }
else if (*ptr ==
'#') {
855 }
else if (*ptr ==
'D') {
857 }
else if (*ptr ==
'C') {
859 }
else if (*ptr ==
'B') {
861 }
else if (*ptr ==
'A') {
864 beeps = (*ptr ==
'0') ? 10 : *ptr -
'0';
866 while (beeps-- > 0) {
872 res = my_sleep(chan, SF_ON + SF_OFF);
889 res = my_sleep(chan, SF_BETWEEN);
899 ast_log(LOG_WARNING,
"Illegal SF character '%c' in string. (0-9A-DwWfFhH allowed)\n", *ptr);
914 static int mf_stream(
struct ast_channel *chan,
struct ast_channel *chan2,
const char *digits,
int between,
unsigned int duration,
915 unsigned int durationkp,
unsigned int durationst,
int is_external)
923 my_sleep = external_sleep;
933 if (ast_opt_transmit_silence) {
942 res = my_sleep(chan, 100);
947 goto mf_stream_cleanup;
950 for (ptr = digits; *ptr; ptr++) {
956 res = my_sleep(chan, 500);
963 }
else if (*ptr ==
'h' || *ptr ==
'H') {
971 res = my_sleep(chan, 250);
980 }
else if (strchr(
"0123456789*#ABCwWfF", *ptr)) {
981 if (*ptr ==
'f' || *ptr ==
'F') {
984 }
else if (*ptr ==
'W') {
989 ast_senddigit_mf(chan, *ptr, duration, durationkp, durationst, is_external);
991 ast_senddigit_mf(chan2, *ptr, duration, durationkp, durationst, is_external);
1004 res = my_sleep(chan, between);
1014 ast_log(LOG_WARNING,
"Illegal MF character '%c' in string. (0-9*#ABCwWfFhH allowed)\n", *ptr);
1029 static int dtmf_stream(
struct ast_channel *chan,
const char *digits,
int between,
unsigned int duration,
int is_external)
1034 int (*my_sleep)(
struct ast_channel *chan,
int ms);
1035 int (*my_senddigit)(
struct ast_channel *chan,
char digit,
unsigned int duration);
1038 my_sleep = external_sleep;
1050 if (ast_opt_transmit_silence) {
1053 res = my_sleep(chan, 100);
1055 goto dtmf_stream_cleanup;
1058 for (ptr = digits; *ptr; ptr++) {
1061 res = my_sleep(chan, 500);
1065 }
else if (*ptr ==
'W') {
1067 res = my_sleep(chan, 1000);
1071 }
else if (strchr(
"0123456789*#abcdfABCDF", *ptr)) {
1072 if (*ptr ==
'f' || *ptr ==
'F') {
1077 my_senddigit(chan, *ptr, duration);
1080 res = my_sleep(chan, between);
1085 ast_log(LOG_WARNING,
"Illegal DTMF character '%c' in string. (0-9*#aAbBcCdD allowed)\n", *ptr);
1089 dtmf_stream_cleanup:
1100 if (frequency <= 0) {
1106 res = sf_stream(chan, chan2, digits, frequency, is_external);
1114 int between,
unsigned int duration,
unsigned int durationkp,
unsigned int durationst,
int is_external)
1120 res = mf_stream(chan, chan2, digits, between, duration, durationkp, durationst, is_external);
1134 res = dtmf_stream(chan, digits, between, duration, 0);
1144 dtmf_stream(chan, digits, between, duration, 1);
1154 static void linear_release(
struct ast_channel *chan,
void *params)
1159 ast_log(LOG_WARNING,
"Unable to restore channel '%s' to format '%s'\n",
1162 ao2_cleanup(ls->origwfmt);
1164 if (ls->autoclose) {
1171 static int linear_generator(
struct ast_channel *chan,
void *data,
int len,
int samples)
1186 ast_log(LOG_WARNING,
"Can't generate %d bytes of data!\n" , len);
1201 static void *linear_alloc(
struct ast_channel *chan,
void *params)
1210 if (ls->allowoverride) {
1216 ls->origwfmt =
ao2_bump(ast_channel_writeformat(chan));
1219 ast_log(LOG_WARNING,
"Unable to set '%s' to linear format (write)\n", ast_channel_name(chan));
1220 ao2_cleanup(ls->origwfmt);
1230 .alloc = linear_alloc,
1231 .release = linear_release,
1232 .generate = linear_generator,
1242 if (ast_strlen_zero(filename)) {
1248 if (filename[0] ==
'/') {
1251 snprintf(tmpf,
sizeof(tmpf),
"%s/%s/%s", ast_config_AST_DATA_DIR,
"sounds", filename);
1254 fd = open(tmpf, O_RDONLY);
1256 ast_log(LOG_WARNING,
"Unable to open file '%s': %s\n", tmpf, strerror(errno));
1271 lin->allowoverride = allowoverride;
1272 lin->autoclose = autoclose;
1277 static int control_streamfile(
struct ast_channel *chan,
1282 const char *suspend,
1283 const char *restart,
1289 char *breaks = NULL;
1293 long pause_restart_point = 0;
1301 offset = *offsetms * 8;
1304 lang = ast_channel_language(chan);
1308 blen += strlen(stop);
1311 blen += strlen(suspend);
1314 blen += strlen(restart);
1321 strcat(breaks, stop);
1324 strcat(breaks, suspend);
1327 strcat(breaks, restart);
1331 if ((end = strchr(file,
':'))) {
1332 if (!strcasecmp(end,
":end")) {
1344 if (pause_restart_point) {
1345 ast_seekstream(ast_channel_stream(chan), pause_restart_point, SEEK_SET);
1346 pause_restart_point = 0;
1348 else if (end || offset < 0) {
1352 ast_verb(3,
"ControlPlayback seek to offset %ld from end\n", offset);
1357 }
else if (offset) {
1358 ast_verb(3,
"ControlPlayback seek to offset %ld\n", offset);
1375 ast_debug(1,
"we'll restart the stream here at next loop\n");
1376 pause_restart_point = 0;
1379 ast_channel_name(chan),
1387 if (ast_opt_transmit_silence) {
1392 ast_channel_name(chan),
1398 }
else if (res == -1 || (suspend && strchr(suspend, res)) || (stop && strchr(stop, res))
1412 ast_channel_name(chan),
1426 ast_channel_name(chan),
1432 if (pause_restart_point) {
1433 offset = pause_restart_point;
1435 if (ast_channel_stream(chan)) {
1443 *offsetms = offset / 8;
1456 const char *suspend,
1457 const char *restart,
1462 return control_streamfile(chan, file, fwd, rev, stop, suspend, restart, skipms, offsetms, NULL, cb);
1466 const char *fwd,
const char *rev,
1467 const char *stop,
const char *suspend,
1468 const char *restart,
int skipms,
long *offsetms)
1470 return control_streamfile(chan, file, fwd, rev, stop, suspend, restart, skipms, offsetms, NULL, NULL);
1474 const char *fwd,
const char *rev,
const char *stop,
const char *suspend,
1475 const char *restart,
int skipms,
const char *lang,
long *offsetms)
1477 return control_streamfile(chan, file, fwd, rev, stop, suspend, restart, skipms, offsetms, lang, NULL);
1480 enum control_tone_frame_response_result {
1481 CONTROL_TONE_RESPONSE_FAILED = -1,
1482 CONTROL_TONE_RESPONSE_NORMAL = 0,
1483 CONTROL_TONE_RESPONSE_FINISHED = 1,
1491 return CONTROL_TONE_RESPONSE_FINISHED;
1496 return CONTROL_TONE_RESPONSE_FAILED;
1502 return CONTROL_TONE_RESPONSE_NORMAL;
1506 return CONTROL_TONE_RESPONSE_FAILED;
1508 return CONTROL_TONE_RESPONSE_NORMAL;
1510 ast_log(LOG_NOTICE,
"Media control operation 'reverse' not supported for media type 'tone'\n");
1511 return CONTROL_TONE_RESPONSE_NORMAL;
1513 ast_log(LOG_NOTICE,
"Media control operation 'forward' not supported for media type 'tone'\n");
1514 return CONTROL_TONE_RESPONSE_NORMAL;
1518 return CONTROL_TONE_RESPONSE_FINISHED;
1521 return CONTROL_TONE_RESPONSE_NORMAL;
1524 static int parse_tone_uri(
char *tone_parser,
1525 const char **tone_indication,
1526 const char **tone_zone)
1528 *tone_indication = strsep(&tone_parser,
";");
1530 if (ast_strlen_zero(tone_parser)) {
1535 if (!(strncmp(tone_parser,
"tonezone=", 9))) {
1536 *tone_zone = tone_parser + 9;
1538 ast_log(LOG_ERROR,
"Unexpected Tone URI component: %s\n", tone_parser);
1552 const char *tone_indication = NULL;
1553 const char *tone_zone = NULL;
1554 char *tone_uri_parser;
1556 if (ast_strlen_zero(tone)) {
1562 if (parse_tone_uri(tone_uri_parser, &tone_indication, &tone_zone)) {
1595 res = control_tone_frame_response(chan, fr, ts, tone_indication, &paused);
1596 if (res == CONTROL_TONE_RESPONSE_FINISHED) {
1599 }
else if (res == CONTROL_TONE_RESPONSE_FAILED) {
1620 if ((d =
ast_streamfile(chan, fn, ast_channel_language(chan)))) {
1652 ast_log(LOG_WARNING,
"Attempting to silence non-slin frame\n");
1661 ast_verb(4,
"Silencing %zu samples\n", samples);
1664 datalen =
sizeof(short) * samples;
1665 size =
sizeof(*silence) +
datalen;
1673 silence->
data.ptr = (
void *)(silence + 1);
1694 if (!chan || !orig_format) {
1697 *orig_format =
ao2_bump(ast_channel_readformat(chan));
1701 static int global_silence_threshold = 128;
1728 const char *recordfile,
int maxtime,
const char *fmt,
int *duration,
1729 int *sound_duration,
int beep,
int silencethreshold,
int maxsilence,
1730 const char *path,
int prepend,
const char *acceptdtmf,
const char *canceldtmf,
1736 int x, fmtcnt = 1, res = -1, outmsg = 0;
1739 char *stringp = NULL;
1741 struct ast_dsp *sildet = NULL;
1744 int olddspsilence = 0;
1747 char prependfile[PATH_MAX];
1749 SCOPE_ENTER(3,
"%s: play: '%s' record: '%s' path: '%s' prepend: %d\n",
1750 ast_channel_name(chan), playfile, recordfile, path, prepend);
1752 ioflags = O_CREAT|O_WRONLY;
1754 switch (if_exists) {
1762 ioflags |= O_APPEND;
1769 if (silencethreshold < 0) {
1770 silencethreshold = global_silence_threshold;
1773 if (maxsilence < 0) {
1779 ast_log(LOG_WARNING,
"Error play_and_record called without duration pointer\n");
1783 ast_debug(1,
"play_and_record: %s, %s, '%s'\n", playfile ? playfile :
"<None>", recordfile, fmt);
1784 snprintf(comment,
sizeof(comment),
"Playing %s, Recording to: %s on %s\n", playfile ? playfile :
"<None>", recordfile, ast_channel_name(chan));
1786 if (playfile || beep) {
1788 ast_trace(-1,
"Playing '%s' to '%s'\n", playfile, ast_channel_name(chan));
1792 ast_trace(-1,
"Playing 'beep' to '%s'\n", ast_channel_name(chan));
1796 SCOPE_EXIT_RTN_VALUE(-1,
"Failed to play. RC: %d\n", d);
1802 strncat(prependfile,
"-prepend",
sizeof(prependfile) - strlen(prependfile) - 1);
1803 ast_trace(-1,
"Prepending to '%s'\n", prependfile);
1809 strsep(&stringp,
"|");
1810 ast_debug(1,
"Recording Formats: sfmts=%s\n", fmts);
1813 while ((fmt = strsep(&stringp,
"|"))) {
1815 ast_log(LOG_WARNING,
"Please increase AST_MAX_FORMATS in file.h\n");
1823 sfmt[fmtcnt++] = fmt;
1826 end = start = time(NULL);
1827 for (x = 0; x < fmtcnt; x++) {
1828 others[x] =
ast_writefile(prepend ? prependfile : recordfile, sfmt[x], comment, ioflags, 0, AST_FILE_MODE);
1829 ast_trace(-1,
"x=%d, open writing: %s format: %s, %p\n", x, prepend ? prependfile : recordfile, sfmt[x], others[x]);
1840 if (maxsilence > 0) {
1843 ast_log(LOG_WARNING,
"Unable to create silence detector :(\n");
1849 ast_log(LOG_WARNING,
"Unable to set to linear mode, giving up\n");
1850 ast_dsp_free(sildet);
1860 if (ast_opt_transmit_silence) {
1871 time_t pause_start = 0;
1872 int paused_secs = 0;
1873 int pausedsilence = 0;
1877 ast_debug(1,
"One waitfor failed, trying another\n");
1880 ast_log(LOG_WARNING,
"No audio available on %s??\n", ast_channel_name(chan));
1904 ast_log(LOG_WARNING,
"Error creating silence\n");
1909 for (x = 0; x < fmtcnt; x++) {
1910 if (prepend && !others[x]) {
1920 if (maxsilence > 0) {
1923 if (olddspsilence > dspsilence) {
1924 totalsilence += olddspsilence;
1926 olddspsilence = dspsilence;
1930 pausedsilence = dspsilence;
1931 }
else if (dspsilence > pausedsilence) {
1933 dspsilence -= pausedsilence;
1939 if (dspsilence > maxsilence) {
1941 ast_verb(3,
"Recording automatically stopped after a silence of %d seconds\n", dspsilence/1000);
1949 ast_log(LOG_WARNING,
"Error writing frame\n");
1955 }
else if (f->
frametype == AST_FRAME_DTMF) {
1958 ast_verb(3,
"User ended message by pressing %c\n", f->
subclass.
integer);
1964 ast_verb(3,
"User ended message by pressing %c\n", f->
subclass.
integer);
1970 ast_verb(3,
"User canceled message by pressing %c\n", f->
subclass.
integer);
1977 ast_verb(3,
"Message canceled by control\n");
1982 ast_verb(3,
"Message ended by control\n");
1987 ast_verb(3,
"Message %spaused by control\n",
1988 paused ?
"" :
"un");
1990 pause_start = time(NULL);
1992 paused_secs += time(NULL) - pause_start;
1996 ast_verb(3,
"Message %smuted by control\n",
2002 if (muted && !rfmt) {
2003 ast_verb(3,
"Setting read format to linear mode\n");
2006 ast_log(LOG_WARNING,
"Unable to set to linear mode, giving up\n");
2012 if (maxtime && !paused) {
2014 if (maxtime < (end - start - paused_secs)) {
2015 ast_verb(3,
"Took too long, cutting it short...\n");
2024 ast_verb(3,
"User hung up\n");
2031 ast_log(LOG_WARNING,
"Error creating writestream '%s', format '%s'\n", recordfile, sfmt[x]);
2050 if (sound_duration) {
2051 *sound_duration = *duration;
2056 if (olddspsilence <= dspsilence) {
2057 totalsilence += dspsilence;
2060 if (sound_duration) {
2061 if (totalsilence > 0) {
2062 *sound_duration -= (totalsilence - 200) / 1000;
2064 if (*sound_duration < 0) {
2065 *sound_duration = 0;
2069 if (dspsilence > 0) {
2070 *duration -= (dspsilence - 200) / 1000;
2073 if (*duration < 0) {
2077 for (x = 0; x < fmtcnt; x++) {
2086 if (res > 0 && dspsilence) {
2093 }
else if (prepend && outmsg) {
2097 for (x = 0; x < fmtcnt; x++) {
2098 snprintf(comment,
sizeof(comment),
"Opening the real file %s.%s\n", recordfile, sfmt[x]);
2099 realfiles[x] =
ast_readfile(recordfile, sfmt[x], comment, O_RDONLY, 0, 0);
2103 if (!realfiles[x]) {
2120 ast_trace(-1,
"Recording Format: sfmts=%s, prependfile %s, recordfile %s\n", sfmt[x], prependfile, recordfile);
2121 ast_trace(-1,
"Deleting the prepend file %s.%s\n", recordfile, sfmt[x]);
2125 for (x = 0; x < fmtcnt; x++) {
2134 ast_log(LOG_WARNING,
"Unable to restore format %s to channel '%s'\n",
ast_format_get_name(rfmt), ast_channel_name(chan));
2137 if ((outmsg == 2) && (!skip_confirmation_sound)) {
2141 ast_dsp_free(sildet);
2143 SCOPE_EXIT_RTN_VALUE(res,
"Done. RC: %d\n", res);
2146 static const char default_acceptdtmf[] =
"#";
2147 static const char default_canceldtmf[] =
"";
2149 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)
2151 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);
2154 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)
2156 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);
2159 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)
2161 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);
2170 char *grp = NULL, *cat = NULL;
2172 if (!ast_strlen_zero(data)) {
2175 if ((cat = strchr(tmp,
'@'))) {
2180 if (!ast_strlen_zero(grp)) {
2186 if (!ast_strlen_zero(cat)) {
2196 char group[80] =
"", category[80] =
"";
2205 len =
sizeof(*gi) + strlen(group) + 1;
2206 if (!ast_strlen_zero(category)) {
2207 len += strlen(category) + 1;
2211 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&
groups, gi, group_list) {
2212 if ((gi->chan == chan) && ((ast_strlen_zero(category) && ast_strlen_zero(gi->category)) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) {
2213 AST_RWLIST_REMOVE_CURRENT(group_list);
2218 AST_RWLIST_TRAVERSE_SAFE_END;
2220 if (ast_strlen_zero(group)) {
2224 gi->group = (
char *) gi +
sizeof(*gi);
2225 strcpy(gi->group, group);
2226 if (!ast_strlen_zero(category)) {
2227 gi->category = (
char *) gi +
sizeof(*gi) + strlen(group) + 1;
2228 strcpy(gi->category, category);
2230 AST_RWLIST_INSERT_TAIL(&
groups, gi, group_list);
2245 if (ast_strlen_zero(group)) {
2250 AST_RWLIST_TRAVERSE(&
groups, gi, group_list) {
2251 if (!strcasecmp(gi->group, group) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !strcasecmp(gi->category, category)))) {
2263 regex_t regexbuf_group;
2264 regex_t regexbuf_category;
2267 if (ast_strlen_zero(groupmatch)) {
2268 ast_log(LOG_NOTICE,
"groupmatch empty\n");
2273 if (regcomp(®exbuf_group, groupmatch, REG_EXTENDED | REG_NOSUB)) {
2274 ast_log(LOG_ERROR,
"Regex compile failed on: %s\n", groupmatch);
2278 if (!ast_strlen_zero(category) && regcomp(®exbuf_category, category, REG_EXTENDED | REG_NOSUB)) {
2279 ast_log(LOG_ERROR,
"Regex compile failed on: %s\n", category);
2280 regfree(®exbuf_group);
2285 AST_RWLIST_TRAVERSE(&
groups, gi, group_list) {
2286 if (!regexec(®exbuf_group, gi->group, 0, NULL, 0) && (ast_strlen_zero(category) || (!ast_strlen_zero(gi->category) && !regexec(®exbuf_category, gi->category, 0, NULL, 0)))) {
2292 regfree(®exbuf_group);
2293 if (!ast_strlen_zero(category)) {
2294 regfree(®exbuf_category);
2305 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&
groups, gi, group_list) {
2306 if (gi->chan == old) {
2308 }
else if (gi->chan ==
new) {
2309 AST_RWLIST_REMOVE_CURRENT(group_list);
2313 AST_RWLIST_TRAVERSE_SAFE_END;
2324 AST_RWLIST_TRAVERSE_SAFE_BEGIN(&
groups, gi, group_list) {
2325 if (gi->chan == chan) {
2326 AST_RWLIST_REMOVE_CURRENT(group_list);
2330 AST_RWLIST_TRAVERSE_SAFE_END;
2348 return AST_RWLIST_FIRST(&
groups);
2359 char *scan, *wasdelim = NULL;
2360 int paren = 0, quote = 0, bracket = 0;
2362 if (!array || !arraylen) {
2366 memset(array, 0, arraylen *
sizeof(*array));
2374 for (argc = 0; *scan && (argc < arraylen - 1); argc++) {
2376 for (; *scan; scan++) {
2379 }
else if (*scan ==
')') {
2383 }
else if (*scan ==
'[') {
2385 }
else if (*scan ==
']') {
2389 }
else if (*scan ==
'"' && delim !=
'"') {
2390 quote = quote ? 0 : 1;
2393 memmove(scan, scan + 1, strlen(scan));
2396 }
else if (*scan ==
'\\') {
2399 memmove(scan, scan + 1, strlen(scan));
2403 }
else if ((*scan == delim) && !paren && !quote && !bracket) {
2413 if (*scan || (scan > buf && (scan - 1) == wasdelim)) {
2414 array[argc++] = scan;
2420 static enum AST_LOCK_RESULT ast_lock_path_lockfile(
const char *path)
2426 int lp = strlen(path);
2432 snprintf(fs, strlen(path) + 19,
"%s/.lock-%08lx", path, (
unsigned long)ast_random());
2433 fd = open(fs, O_WRONLY | O_CREAT | O_EXCL, AST_FILE_MODE);
2435 ast_log(LOG_ERROR,
"Unable to create lock file '%s': %s\n", path, strerror(errno));
2436 return AST_LOCK_PATH_NOT_FOUND;
2440 snprintf(s, strlen(path) + 9,
"%s/.lock", path);
2442 while (((res = link(fs, s)) < 0) && (errno == EEXIST) && (time(NULL) - start < 5)) {
2449 ast_log(LOG_WARNING,
"Failed to lock path '%s': %s\n", path, strerror(errno));
2450 return AST_LOCK_TIMEOUT;
2452 ast_debug(1,
"Locked path '%s'\n", path);
2453 return AST_LOCK_SUCCESS;
2457 static int ast_unlock_path_lockfile(
const char *path)
2464 snprintf(s, strlen(path) + 9,
"%s/%s", path,
".lock");
2466 if ((res = unlink(s))) {
2467 ast_log(LOG_ERROR,
"Could not unlock path '%s': %s\n", path, strerror(errno));
2469 ast_debug(1,
"Unlocked path '%s'\n", path);
2483 static void path_lock_destroy(
struct path_lock *obj)
2489 ast_free(obj->path);
2494 static enum AST_LOCK_RESULT ast_lock_path_flock(
const char *path)
2501 struct stat st, ost;
2505 snprintf(fs, strlen(path) + 19,
"%s/lock", path);
2506 if (lstat(fs, &st) == 0) {
2507 if ((st.st_mode & S_IFMT) == S_IFLNK) {
2508 ast_log(LOG_WARNING,
"Unable to create lock file "
2509 "'%s': it's already a symbolic link\n",
2511 return AST_LOCK_FAILURE;
2513 if (st.st_nlink > 1) {
2514 ast_log(LOG_WARNING,
"Unable to create lock file "
2515 "'%s': %u hard links exist\n",
2516 fs, (
unsigned int) st.st_nlink);
2517 return AST_LOCK_FAILURE;
2520 if ((fd = open(fs, O_WRONLY | O_CREAT, 0600)) < 0) {
2521 ast_log(LOG_WARNING,
"Unable to create lock file '%s': %s\n",
2522 fs, strerror(errno));
2523 return AST_LOCK_PATH_NOT_FOUND;
2532 return AST_LOCK_FAILURE;
2540 ((res = fcntl(pl->fd, F_SETLK, fcntl(pl->fd, F_GETFL) | O_NONBLOCK)) < 0) &&
2542 ((res = flock(pl->fd, LOCK_EX | LOCK_NB)) < 0) &&
2544 (errno == EWOULDBLOCK) &&
2545 (time(NULL) - start < 5))
2548 ast_log(LOG_WARNING,
"Failed to lock path '%s': %s\n",
2549 path, strerror(errno));
2553 path_lock_destroy(pl);
2554 return AST_LOCK_TIMEOUT;
2560 if (lstat(fs, &st) != 0 && fstat(pl->fd, &ost) != 0 &&
2561 st.st_dev != ost.st_dev &&
2562 st.st_ino != ost.st_ino) {
2563 ast_log(LOG_WARNING,
"Unable to create lock file '%s': "
2564 "file changed underneath us\n", fs);
2565 path_lock_destroy(pl);
2566 return AST_LOCK_FAILURE;
2574 ast_debug(1,
"Locked path '%s'\n", path);
2576 return AST_LOCK_SUCCESS;
2579 static int ast_unlock_path_flock(
const char *path)
2588 if (!strcmp(p->path, path)) {
2597 snprintf(s, strlen(path) + 19,
"%s/lock", path);
2599 path_lock_destroy(p);
2600 ast_debug(1,
"Unlocked path '%s'\n", path);
2602 ast_debug(1,
"Failed to unlock path '%s': "
2603 "lock not found\n", path);
2611 ast_lock_type = type;
2616 enum AST_LOCK_RESULT r = AST_LOCK_FAILURE;
2618 switch (ast_lock_type) {
2619 case AST_LOCK_TYPE_LOCKFILE:
2620 r = ast_lock_path_lockfile(path);
2622 case AST_LOCK_TYPE_FLOCK:
2623 r = ast_lock_path_flock(path);
2634 switch (ast_lock_type) {
2635 case AST_LOCK_TYPE_LOCKFILE:
2636 r = ast_unlock_path_lockfile(path);
2638 case AST_LOCK_TYPE_FLOCK:
2639 r = ast_unlock_path_flock(path);
2646 int ast_record_review(
struct ast_channel *chan,
const char *playfile,
const char *recordfile,
int maxtime,
const char *fmt,
int *duration,
const char *path)
2648 int silencethreshold;
2652 int max_attempts = 3;
2655 int message_exists = 0;
2660 ast_log(LOG_WARNING,
"Error ast_record_review called without duration pointer\n");
2668 while ((cmd >= 0) && (cmd !=
't')) {
2671 if (!message_exists) {
2682 ast_verb(3,
"Reviewing the recording\n");
2688 ast_verb(3,
"R%secording\n", recorded == 1 ?
"e-r" :
"");
2690 if ((cmd =
ast_play_and_record(chan, playfile, recordfile, maxtime, fmt, duration, NULL, silencethreshold, maxsilence, path)) == -1) {
2696 }
else if (cmd ==
'*') {
2715 if (message_exists) {
2729 if (attempts > max_attempts) {
2740 #define RES_UPONE (1 << 16)
2741 #define RES_EXIT (1 << 17)
2742 #define RES_REPEAT (1 << 18)
2743 #define RES_RESTART ((1 << 19) | RES_REPEAT)
2754 switch (option->action) {
2758 return RES_EXIT | (((
unsigned long)(option->adata)) & 0xffff);
2760 return RES_REPEAT | (((
unsigned long)(option->adata)) & 0xffff);
2762 return RES_RESTART ;
2768 ast_log(LOG_NOTICE,
"Unable to find file '%s'!\n", (
char *)option->adata);
2775 ast_log(LOG_NOTICE,
"Unable to find file '%s'!\n", (
char *)option->adata);
2780 if ((res = ast_ivr_menu_run_internal(chan, (
struct ast_ivr_menu *)option->adata, cbdata)) == -2) {
2786 if (!(res =
ast_waitfordigit(chan, ast_channel_pbx(chan) ? ast_channel_pbx(chan)->rtimeoutms : 10000))) {
2791 ivr_func = option->adata;
2792 res = ivr_func(chan, cbdata);
2801 while ((n = strsep(&c,
";"))) {
2810 ast_log(LOG_NOTICE,
"Unknown dispatch function %u, ignoring!\n", option->action);
2816 static int option_exists(
struct ast_ivr_menu *menu,
char *option)
2819 for (x = 0; menu->
options[x].option; x++) {
2820 if (!strcasecmp(menu->
options[x].option, option)) {
2827 static int option_matchmore(
struct ast_ivr_menu *menu,
char *option)
2830 for (x = 0; menu->
options[x].option; x++) {
2831 if ((!strncasecmp(menu->
options[x].option, option, strlen(option))) &&
2832 (menu->
options[x].option[strlen(option)])) {
2843 while (option_matchmore(menu, exten)) {
2844 ms = ast_channel_pbx(chan) ? ast_channel_pbx(chan)->
dtimeoutms : 5000;
2845 if (strlen(exten) >= maxexten - 1) {
2851 exten[strlen(exten) + 1] =
'\0';
2852 exten[strlen(exten)] = res;
2854 return res > 0 ? 0 : res;
2864 if (option_exists(menu,
"s") < 0) {
2866 if (option_exists(menu,
"g") < 0) {
2867 ast_log(LOG_WARNING,
"No 's' nor 'g' extension in menu '%s'!\n", menu->
title);
2872 while (menu->
options[pos].option) {
2873 if (!strcasecmp(menu->
options[pos].option, exten)) {
2874 res = ivr_dispatch(chan, menu->
options + pos, exten, cbdata);
2875 ast_debug(1,
"IVR Dispatch of '%s' (pos %d) yields %d\n", exten, pos, res);
2878 }
else if (res & RES_UPONE) {
2880 }
else if (res & RES_EXIT) {
2882 }
else if (res & RES_REPEAT) {
2883 int maxretries = res & 0xffff;
2884 if ((res & RES_RESTART) == RES_RESTART) {
2892 if ((maxretries > 0) && (retries >= maxretries)) {
2893 ast_debug(1,
"Max retries %d exceeded\n", maxretries);
2896 if (option_exists(menu,
"g") > -1) {
2898 }
else if (option_exists(menu,
"s") > -1) {
2904 }
else if (res && strchr(AST_DIGIT_ANY, res)) {
2905 ast_debug(1,
"Got start of extension, %c\n", res);
2908 if ((res = read_newoption(chan, menu, exten,
sizeof(exten)))) {
2911 if (option_exists(menu, exten) < 0) {
2912 if (option_exists(menu,
"i")) {
2913 ast_debug(1,
"Invalid extension entered, going to 'i'!\n");
2918 ast_debug(1,
"Aborting on invalid entry, with no 'i' option!\n");
2923 ast_debug(1,
"New existing extension: %s\n", exten);
2931 ast_debug(1,
"Stopping option '%s', res is %d\n", exten, res);
2933 if (!strcasecmp(exten,
"s")) {
2944 int res = ast_ivr_menu_run_internal(chan, menu, cbdata);
2946 return res > 0 ? 0 : res;
2951 int fd, count = 0, res;
2952 char *output = NULL;
2953 struct stat filesize;
2955 if (stat(filename, &filesize) == -1) {
2956 ast_log(LOG_WARNING,
"Error can't stat %s\n", filename);
2960 count = filesize.st_size + 1;
2962 if ((fd = open(filename, O_RDONLY)) < 0) {
2963 ast_log(LOG_WARNING,
"Cannot open file '%s' for reading: %s\n", filename, strerror(errno));
2968 res = read(fd, output, count - 1);
2969 if (res == count - 1) {
2972 ast_log(LOG_WARNING,
"Short read of %s (%d of %d): %s\n", filename, res, count - 1, strerror(errno));
2983 static int parse_options(
const struct ast_app_option *options,
void *_flags,
char **args,
char *optstr,
int flaglen)
2986 int curarg, res = 0;
2987 unsigned int argloc;
2991 if (flaglen == 32) {
2992 ast_clear_flag(flags, AST_FLAGS_ALL);
3003 curarg = *s++ & 0x7f;
3006 int paren = 1, quote = 0;
3007 int parsequotes = (s[1] ==
'"') ? 1 : 0;
3012 if (*s ==
'(' && !quote) {
3014 }
else if (*s ==
')' && !quote) {
3017 }
else if (*s ==
'"' && parsequotes) {
3019 quote = quote ? 0 : 1;
3022 }
else if (*s ==
'\\') {
3026 }
else if (quote && s[1] ==
'"') {
3040 if ((s = strchr(s,
')'))) {
3042 args[argloc - 1] = arg;
3046 ast_log(LOG_WARNING,
"Missing closing parenthesis for argument '%c' in string '%s'\n", curarg, arg);
3050 }
else if (argloc) {
3051 args[argloc - 1] =
"";
3053 if (!options[curarg].flag) {
3054 ast_log(LOG_WARNING,
"Unrecognized option: '%c'\n", curarg);
3056 if (flaglen == 32) {
3057 ast_set_flag(flags, options[curarg].flag);
3059 ast_set_flag64(flags64, options[curarg].flag);
3068 return parse_options(options, flags, args, optstr, 32);
3073 return parse_options(options, flags, args, optstr, 64);
3078 unsigned int i, found = 0;
3079 for (i = 32; i < 128 && found < len; i++) {
3080 if (ast_test_flag64(flags, options[i].flag)) {
3092 if (ast_strlen_zero(stream)) {
3097 if (*stream ==
'\\') {
3099 switch (*(stream + 1)) {
3111 if (strchr(
"0123456789ABCDEFabcdef", *(stream + 2)) && *(stream + 2) !=
'\0') {
3113 if (*(stream + 2) <=
'9') {
3114 *result = *(stream + 2) -
'0';
3115 }
else if (*(stream + 2) <=
'F') {
3116 *result = *(stream + 2) -
'A' + 10;
3118 *result = *(stream + 2) -
'a' + 10;
3121 ast_log(LOG_ERROR,
"Illegal character '%c' in hexadecimal string\n", *(stream + 2));
3125 if (strchr(
"0123456789ABCDEFabcdef", *(stream + 3)) && *(stream + 3) !=
'\0') {
3128 if (*(stream + 3) <=
'9') {
3129 *result += *(stream + 3) -
'0';
3130 }
else if (*(stream + 3) <=
'F') {
3131 *result += *(stream + 3) -
'A' + 10;
3133 *result += *(stream + 3) -
'a' + 10;
3140 for (i = 2; ; i++) {
3141 if (strchr(
"01234567", *(stream + i)) && *(stream + i) !=
'\0') {
3143 ast_debug(5,
"result was %d, ", *result);
3145 *result += *(stream + i) -
'0';
3153 *result = *(stream + 1);
3181 if (strchr(stream,
'\\')) {
3184 ast_str_make_space(str, maxlen > 0 ? maxlen : (
ast_str_size(*str) + 48) * 2 - 48);
3190 buf[offset++] = next;
3194 buf[offset++] =
'\0';
3209 sigset_t signal_set, old_set;
3219 (void) sigfillset(&signal_set);
3220 pthread_sigmask(SIG_BLOCK, &signal_set, &old_set);
3226 pthread_sigmask(SIG_SETMASK, &old_set, NULL);
3227 if (!stop_reaper && pid > 0) {
3234 if (shaun_of_the_dead_thread == AST_PTHREADT_NULL) {
3235 if (ast_pthread_create_background(&shaun_of_the_dead_thread, NULL, shaun_of_the_dead, NULL)) {
3236 ast_log(LOG_ERROR,
"Shaun of the Dead wants to kill zombies, but can't?!!\n");
3237 shaun_of_the_dead_thread = AST_PTHREADT_NULL;
3246 cap_set_proc(child_cap);
3250 signal(SIGHUP, SIG_DFL);
3251 signal(SIGCHLD, SIG_DFL);
3252 signal(SIGINT, SIG_DFL);
3253 signal(SIGURG, SIG_DFL);
3254 signal(SIGTERM, SIG_DFL);
3255 signal(SIGPIPE, SIG_DFL);
3256 signal(SIGXFSZ, SIG_DFL);
3259 if (pthread_sigmask(SIG_UNBLOCK, &signal_set, NULL)) {
3260 ast_log(LOG_WARNING,
"unable to unblock signals: %s\n", strerror(errno));
3277 #ifdef HAVE_LONG_DOUBLE_WIDER
3279 #define FMT "%30Lf%9s"
3282 #define FMT "%30lf%9s"
3288 res = sscanf(timestr, FMT, &amount, u);
3290 if (res == 0 || res == EOF) {
3293 }
else if (res == 2) {
3297 unit = TIMELEN_HOURS;
3304 unit = TIMELEN_SECONDS;
3311 if (toupper(u[1]) ==
'S') {
3312 unit = TIMELEN_MILLISECONDS;
3316 }
else if (u[1] ==
'\0') {
3317 unit = TIMELEN_MINUTES;
3331 case TIMELEN_MINUTES:
3334 case TIMELEN_SECONDS:
3337 case TIMELEN_MILLISECONDS:
3340 *result = amount > INT_MAX ? INT_MAX : (int) amount;
3354 static void app_cleanup(
void)
3357 cap_free(child_cap);
3359 ao2_cleanup(queue_topic_pool);
3360 queue_topic_pool = NULL;
3361 ao2_cleanup(queue_topic_all);
3362 queue_topic_all = NULL;
3369 child_cap = cap_from_text(
"cap_net_admin-eip");
3372 if (!queue_topic_all) {
3376 if (!queue_topic_pool) {
unsigned int module_version
The version of this function table.
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.
int ast_safe_sleep(struct ast_channel *chan, int ms)
Wait for a specified amount of time, looking for hangups.
int ast_queue_hangup(struct ast_channel *chan)
Queue a hangup frame.
int app_init(void)
Initialize the application core.
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) ...
Main Channel structure associated with a channel.
struct ast_module * module
The module for the voicemail provider.
struct stasis_topic * ast_queue_topic(const char *queuename)
Get the Stasis Message Bus API topic for queue messages for a particular queue name.
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)
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...
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
#define AST_LIST_LOCK(head)
Locks a list.
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.
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.
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
#define AST_LIST_FIRST(head)
Returns the first entry contained in a list.
static AO2_GLOBAL_OBJ_STATIC(vm_provider)
The container for the voicemail provider.
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...
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
int ast_app_inboxcount2(const char *mailboxes, int *urgentmsgs, int *newmsgs, int *oldmsgs)
Determine number of urgent/new/old messages in a mailbox.
static struct stasis_topic * queue_topic_all
Define Stasis Message Bus API topic objects.
static struct ast_tone_zone * ast_tone_zone_unref(struct ast_tone_zone *tz)
Release a reference to an ast_tone_zone.
void ast_unreplace_sigchld(void)
Restore the SIGCHLD handler.
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...
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.
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". If folder is "INBOX", includes the number of messages in the "Urgent" folder.
static int vm_greeter_warnings
int ast_app_inboxcount(const char *mailboxes, int *newmsgs, int *oldmsgs)
Determine number of new/old messages in a mailbox.
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
int ast_indicate(struct ast_channel *chan, int condition)
Indicates condition of channel.
size_t ast_str_size(const struct ast_str *buf)
Returns the current maximum length (without reallocation) of the current buffer.
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.
Convenient Signal Processing routines.
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...
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
int ast_vm_greeter_is_registered(void)
Determine if a voicemail greeter provider is registered.
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Voicemail greeter function table definition.
int ast_unlock_path(const char *path)
Unlock a path.
static struct stasis_rest_handlers mailboxes
REST handler for /api-docs/mailboxes.json.
struct ast_dsp * ast_dsp_new(void)
Allocates a new dsp, assumes 8khz for internal sample rate.
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
void ast_close_fds_above_n(int n)
Common routine for child processes, to close all fds prior to exec(2)
#define AST_LIST_NEXT(elm, field)
Returns the next entry in the list after the given entry.
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
void( ast_vm_msg_play_cb)(struct ast_channel *chan, const char *playfile, int duration)
Voicemail playback callback function definition.
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
int ast_ignore_pattern(const char *context, const char *pattern)
Checks to see if a number should be ignored.
int ast_senddigit_external(struct ast_channel *chan, char digit, unsigned int duration)
Send a DTMF digit to a channel from an external thread.
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
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.
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.
#define ast_strdup(str)
A wrapper for strdup()
struct ast_vm_mailbox_snapshot * ast_vm_mailbox_snapshot_destroy(struct ast_vm_mailbox_snapshot *mailbox_snapshot)
destroy a snapshot
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.
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
void ast_playtones_stop(struct ast_channel *chan)
Stop playing tones on a channel.
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.
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.
Definitions to aid in the use of thread local storage.
int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration)
Send a DTMF digit to a channel.
int ast_filedelete(const char *filename, const char *fmt)
Deletes a file.
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 ...
static int inboxcount2(const char *mailbox, int *urgentmsgs, int *newmsgs, int *oldmsgs)
Check the given mailbox's message count.
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.
Structure used to handle a large number of boolean flags == used only in app_dial?
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...
struct stasis_topic * ast_queue_topic_all(void)
Get the Stasis Message Bus API topic for queue messages.
#define AST_LIST_TRAVERSE_SAFE_END
Closes a safe loop traversal block.
int ast_linear_stream(struct ast_channel *chan, const char *filename, int fd, int allowoverride)
Stream a filename (or file descriptor) as a generator.
const char * ast_vm_index_to_foldername(int id)
Return name of folder, given an id.
struct ast_frame_subclass subclass
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...
off_t ast_tellstream(struct ast_filestream *fs)
Tell where we are in a stream.
void ast_frame_dtor(struct ast_frame *frame)
NULL-safe wrapper for ast_frfree, good for RAII_VAR.
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.
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized...
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
int ast_app_group_get_count(const char *group, const char *category)
Get the current channel count of the specified group and category.
int ast_app_group_list_rdlock(void)
Read Lock the group count list.
A structure to hold the description of an application 'option'.
static struct ast_frame * make_silence(const struct ast_frame *orig)
Construct a silence frame of the same duration as orig.
General Asterisk PBX channel definitions.
Asterisk JSON abstraction layer.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Asterisk file paths, configured in asterisk.conf.
#define AST_FRIENDLY_OFFSET
Offset into a frame's data buffer.
int ast_set_read_format(struct ast_channel *chan, struct ast_format *format)
Sets read format on channel chan.
A set of tones for a given locale.
#define ast_strdupa(s)
duplicate a string in memory from the stack
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.
int ast_app_group_update(struct ast_channel *old, struct ast_channel *new)
Update all group counting for a channel to a new one.
int ast_parseable_goto(struct ast_channel *chan, const char *goto_string)
#define AST_MAX_EXTENSION
#define AST_LIST_REMOVE_CURRENT(field)
Removes the current entry from a list during a traversal.
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...
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
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.
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.
char * ast_strsep(char **s, const char sep, uint32_t flags)
Act like strsep but ignore separators inside quotes.
A set of macros to manage forward-linked lists.
#define ast_malloc(len)
A wrapper for malloc()
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.
#define ast_debug(level,...)
Log a DEBUG message.
int ast_set_write_format(struct ast_channel *chan, struct ast_format *format)
Sets write format on channel chan.
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
void ast_vm_greeter_unregister(const char *module_name)
Unregister the specified voicemail greeter provider.
int ast_exists_extension(struct ast_channel *c, const char *context, const char *exten, int priority, const char *callerid)
Determine whether an extension exists.
void ast_replace_sigchld(void)
Replace the SIGCHLD handler.
Core PBX routines and definitions.
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
struct ast_module * module
The module for the voicemail greeter provider.
const char * ast_app_expand_sub_args(struct ast_channel *chan, const char *args)
Add missing context/exten to subroutine argument string.
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.
static int global_maxsilence
#define AST_LIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
void ast_dsp_set_threshold(struct ast_dsp *dsp, int threshold)
Set the minimum average magnitude threshold to determine talking by the DSP.
#define ast_test_suite_event_notify(s, f,...)
#define ast_alloca(size)
call __builtin_alloca to ensure we get gcc builtin semantics
struct ast_silence_generator * ast_channel_start_silence_generator(struct ast_channel *chan)
Starts a silence generator on the given channel.
int ast_app_messagecount(const char *mailbox_id, const char *folder)
Get the number of messages in a given mailbox folder.
int __ast_vm_greeter_register(const struct ast_vm_greeter_functions *vm_table, struct ast_module *module)
Set voicemail greeter function callbacks.
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.
int ast_app_sayname(struct ast_channel *chan, const char *mailbox_id)
Play a recorded user name for the mailbox to the specified channel.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
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.
Support for dynamic strings.
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.
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.
const char * module_name
The name of the module that provides the voicemail greeter functionality.
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...
struct ast_frame * ast_readframe(struct ast_filestream *s)
Read a frame from a filestream.
#define ao2_global_obj_release(holder)
Release the ao2 object held in the global holder.
Stack applications callback functions.
int ast_senddigit_mf_end(struct ast_channel *chan)
End sending an MF digit to a channel.
int ast_stream_rewind(struct ast_filestream *fs, off_t ms)
Rewind stream ms.
struct ast_tone_zone * ast_get_indication_zone(const char *country)
locate ast_tone_zone
int ast_control_tone(struct ast_channel *chan, const char *tone)
Controls playback of a tone.
struct ast_tone_zone_sound * ast_get_indication_tone(const struct ast_tone_zone *zone, const char *indication)
Locate a tone zone sound.
int ast_app_group_discard(struct ast_channel *chan)
Discard all group counting for a channel.
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.
int ast_seekstream(struct ast_filestream *fs, off_t sample_offset, int whence)
Seeks into stream.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
void ast_set_lock_type(enum AST_LOCK_TYPE type)
Set the type of locks used by ast_lock_path()
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.
union ast_frame::@224 data
#define ast_calloc(num, len)
A wrapper for calloc()
void ast_install_stack_functions(const struct ast_app_stack_funcs *funcs)
Set stack application function callbacks.
int ast_app_group_list_wrlock(void)
Write Lock the group count list.
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.
int ast_closestream(struct ast_filestream *f)
Closes a stream.
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.
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.
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.
void ast_safe_fork_cleanup(void)
Common routine to cleanup after fork'ed process is complete (if reaping was stopped) ...
Module has failed to load, may be in an inconsistent state.
unsigned int arg_index
The index of the entry in the arguments array that should be used for this option's argument...
Structure used to handle boolean flags.
int(* run_sub)(struct ast_channel *chan, const char *args, int ignore_hangup)
Callback for the routine to run a subroutine on a channel.
int ast_truncstream(struct ast_filestream *fs)
Trunc stream at current location.
#define ast_module_unref(mod)
Release a reference to the module.
#define ast_module_running_ref(mod)
Hold a reference to the module if it is running.
int ast_waitfordigit(struct ast_channel *c, int ms)
Waits for a digit.
const char * module_name
The name of the module that provides the voicemail functionality.
void ast_vm_unregister(const char *module_name)
Unregister the specified voicemail provider.
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.
#define ao2_global_obj_replace_unref(holder, obj)
Replace an ao2 object in the global holder, throwing away any old object.
int ast_dsp_silence(struct ast_dsp *dsp, struct ast_frame *f, int *totalsilence)
Process the audio frame for silence.
struct ast_group_info * ast_app_group_list_head(void)
Get the head of the group count list.
Structure used for ast_copy_recording_to_vm in order to cleanly supply data needed for making the rec...
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
char * ast_get_encoded_str(const char *stream, char *result, size_t result_size)
Decode a stream of encoded control or extended ASCII characters.
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
int __ast_vm_register(const struct ast_vm_functions *vm_table, struct ast_module *module)
Set voicemail function callbacks.
int ast_safe_fork(int stop_reaper)
Common routine to safely fork without a chance of a signal handler firing badly in the child...
static int has_voicemail(const char *mailbox, const char *folder)
Determines if the given folder has messages.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
void ast_str_update(struct ast_str *buf)
Update the length of the buffer, after using ast_str merely as a buffer.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
int ast_vm_is_registered(void)
Determine if a voicemail provider is registered.
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.
int ast_writestream(struct ast_filestream *fs, struct ast_frame *f)
Writes a frame to a stream.
char * ast_read_textfile(const char *filename)
Read a file into asterisk.
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
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...
Data structure associated with a single frame of data.
int ast_app_group_list_unlock(void)
Unlock the group count list.
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.
unsigned int module_version
The version of this function table.
int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible)
Start playing a list of tones on a channel.
int ast_filerename(const char *oldname, const char *newname, const char *fmt)
Renames a file.
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...
const char * data
Description of a tone.
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
#define AST_LIST_TRAVERSE_SAFE_BEGIN(head, var, field)
Loops safely over (traverses) the entries in a list.
enum ast_frame_type frametype
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.
int ast_readstring(struct ast_channel *c, char *s, int len, int timeout, int rtimeout, char *enders)
Reads multiple digits.
struct ast_format * format
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.
int ast_dsp_get_threshold_from_settings(enum threshold which)
Get silence threshold from dsp.conf.
Asterisk module definitions.
int ast_ivr_menu_run(struct ast_channel *chan, struct ast_ivr_menu *menu, void *cbdata)
Runs an IVR menu.
Voicemail function table definition.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
AST_LOCK_TYPE
Type of locking to use in ast_lock_path / ast_unlock_path.
struct ast_frame * ast_read_noaudio(struct ast_channel *chan)
Reads a frame, returning AST_FRAME_NULL frame if audio.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
const char *(* expand_sub_args)(struct ast_channel *chan, const char *args)
Add missing context/exten to Gosub application argument string.
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.
int ast_get_encoded_char(const char *stream, char *result, size_t *consumed)
Decode an encoded control or extended ASCII character.
int ast_stopstream(struct ast_channel *c)
Stops a stream.
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...
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.
enum AST_LOCK_RESULT ast_lock_path(const char *path)
Lock a filesystem path.