95 static const char app[] =
"ExternalIVR";
98 #define ast_chan_log(level, channel, format, ...) ast_log(level, "%s: " format, ast_channel_name(channel) , ## __VA_ARGS__) 101 #define EIVR_CMD_APND 'A' 102 #define EIVR_CMD_DTMF 'D' 103 #define EIVR_CMD_EXIT 'E' 104 #define EIVR_CMD_GET 'G' 105 #define EIVR_CMD_HGUP 'H' 106 #define EIVR_CMD_IRPT 'I' 107 #define EIVR_CMD_LOG 'L' 108 #define EIVR_CMD_OPT 'O' 109 #define EIVR_CMD_PARM 'P' 110 #define EIVR_CMD_SQUE 'S' 111 #define EIVR_CMD_ANS 'T' 112 #define EIVR_CMD_SVAR 'V' 113 #define EIVR_CMD_XIT 'X' 115 #define EXTERNALIVR_PORT 2949 210 char *file_to_stream;
221 file_to_stream =
"silence/10";
309 char *
inbuf, *variable;
316 for (j = 1, inbuf = data; ; j++) {
317 variable =
strsep(&inbuf,
",");
318 if (variable ==
NULL) {
319 int outstrlen = strlen(outbuf);
320 if (outstrlen && outbuf[outstrlen - 1] ==
',') {
321 outbuf[outstrlen - 1] = 0;
343 for (variable =
strsep(&inbuf,
","); variable; variable =
strsep(&inbuf,
",")) {
344 ast_debug(1,
"Setting up a variable: %s\n", variable);
346 value = strchr(variable,
'=');
360 int dinterval = 0, duration = 0;
376 ast_verb(4,
"Sending DTMF: %s %d %d\n",
args.digits, dinterval <= 0 ? 250 : dinterval, duration);
384 if (!(entry =
ast_calloc(1,
sizeof(*entry) + strlen(filename) + 10)))
397 int child_stdin[2] = { -1, -1 };
398 int child_stdout[2] = { -1, -1 };
399 int child_stderr[2] = { -1, -1 };
401 *stream_stderr =
NULL;
411 .playing_silence = 1,
417 char *s, **app_args, *e;
439 ast_verb(4,
"ExternalIVR received application and arguments: %s\n", eivr_args.application);
440 ast_verb(4,
"ExternalIVR received options: %s\n", eivr_args.options);
443 if ((s = strchr(eivr_args.application,
'('))) {
445 if ((e = strrchr(s,
')'))) {
454 app_args = application_args.argv;
458 for (j = 0; application_args.cmd[j] !=
NULL; j++) {
459 ast_str_append(&comma_delim_args, 0,
"%s%s", j == 0 ?
"" :
",", application_args.cmd[j]);
463 if (eivr_args.options && (s = strchr(eivr_args.options,
','))) {
468 ast_verb(4,
"Parsing options from: [%s]\n", eivr_args.options);
474 ast_verb(4,
"ignore_hangup is set\n");
481 ast_verb(3,
"Answering channel and starting generator\n");
484 ast_chan_log(
LOG_ERROR, chan,
"Running ExternalIVR with 'd'ead flag on non-hungup channel isn't supported\n");
497 if (!strncmp(app_args[0],
"ivr://",
sizeof(
"ivr://") - 1)) {
503 int num_addrs = 0, i = 0;
504 char *
host = app_args[0] +
sizeof(
"ivr://") - 1;
507 ast_debug(1,
"Parsing hostname/port for socket connect from \"%s\"\n", host);
514 for (i = 0; i < num_addrs; i++) {
528 if (i == num_addrs) {
536 if (pipe(child_stdin)) {
540 if (pipe(child_stdout)) {
544 if (pipe(child_stderr)) {
560 dup2(child_stdin[0], STDIN_FILENO);
561 dup2(child_stdout[1], STDOUT_FILENO);
562 dup2(child_stderr[1], STDERR_FILENO);
564 execv(app_args[0], app_args);
565 fprintf(stderr,
"Failed to execute '%s': %s\n", app_args[0], strerror(
errno));
569 close(child_stdin[0]);
571 close(child_stdout[1]);
572 child_stdout[1] = -1;
573 close(child_stderr[1]);
574 child_stderr[1] = -1;
580 res =
eivr_comm(chan, u, stream_stdin, stream_stdout, stream_stderr, comma_delim_args, flags);
597 if (child_stdin[0] > -1) {
598 close(child_stdin[0]);
600 if (child_stdin[1] > -1) {
601 close(child_stdin[1]);
603 if (child_stdout[0] > -1) {
604 close(child_stdout[0]);
606 if (child_stdout[1] > -1) {
607 close(child_stdout[1]);
609 if (child_stderr[0] > -1) {
610 close(child_stderr[0]);
612 if (child_stderr[1] > -1) {
613 close(child_stderr[1]);
640 int hangup_info_sent = 0;
652 ast_verb(3,
"Got check_hangup, but ignore_hangup set so sending 'I' command\n");
654 hangup_info_sent = 1;
667 rchan =
ast_waitfor_nandfds(&chan, 1, waitfds, (eivr_errors) ? 2 : 1, &exception, &ready_fd, &ms);
706 ast_verb(3,
"Got AST_CONTROL_HANGUP\n");
715 }
else if (ready_fd == waitfds[0]) {
731 ast_verb(4,
"got command '%s'\n", input);
733 if (strlen(input) < 3) {
741 ast_verb(4,
"Sending DTMF: %s\n", &input[2]);
744 ast_verb(3,
"Answering channel if needed and starting generator\n");
747 ast_chan_log(
LOG_WARNING, chan,
"Running ExternalIVR with 'd'ead flag on non-hungup channel isn't supported\n");
837 ast_verb(4,
"Retriving Variables from channel: %s\n", &input[2]);
841 ast_verb(4,
"Setting Variables in channel: %s\n", &input[2]);
865 if (!strcasecmp(&input[2],
"autoclear"))
867 else if (!strcasecmp(&input[2],
"noautoclear"))
872 }
else if (ready_fd == waitfds[1]) {
885 }
else if ((ready_fd < 0) && ms) {
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 sip_cc_notify_state state
#define ast_channel_lock(chan)
Main Channel structure associated with a channel.
#define AST_LIST_LOCK(head)
Locks a list.
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.
#define AST_LIST_HEAD(name, type)
Defines a structure to be used to hold a list of specified type.
static void ast_eivr_getvariable(struct ast_channel *chan, char *data, char *outbuf, int outbuflen)
static void * gen_alloc(struct ast_channel *chan, void *params)
void *(* alloc)(struct ast_channel *chan, void *params)
struct ivr_localuser::playlist playlist
#define ast_test_flag(p, flag)
int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
ssize_t ast_iostream_write(struct ast_iostream *stream, const void *buffer, size_t count)
Write data to an iostream.
void ast_channel_hangupcause_set(struct ast_channel *chan, int value)
static int gen_generate(struct ast_channel *chan, void *data, int len, int samples)
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
#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.
#define ast_chan_log(level, channel, format,...)
void ast_close_fds_above_n(int n)
Common routine for child processes, to close all fds prior to exec(2)
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
ast_channel_state
ast_channel states
struct ast_iostream * ast_iostream_from_fd(int *fd)
Create an iostream from a file descriptor.
struct playlist_entry * current
AST_MODULE_INFO_STANDARD_EXTENDED(ASTERISK_GPL_KEY, "External IVR Interface Application")
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
int ast_iostream_get_fd(struct ast_iostream *stream)
Get an iostream's file descriptor.
arguments for the accepting thread
struct ast_filestream * ast_openstream_full(struct ast_channel *chan, const char *filename, const char *preflang, int asis)
Opens stream for use in seeking, playing.
#define AST_LIST_EMPTY(head)
Checks whether the specified list contains any entries.
#define ast_str_alloca(init_len)
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
static int inbuf(struct baseio *bio, FILE *fi)
utility used by inchar(), for base_encode()
static int load_module(void)
Generic support for tcp/tls servers in Asterisk.
static int input(yyscan_t yyscanner)
int ast_unregister_application(const char *app)
Unregister an application.
Socket address structure.
struct ast_channel * ast_waitfor_nandfds(struct ast_channel **chan, int n, int *fds, int nfds, int *exception, int *outfd, int *ms)
Waits for activity on a group of channels.
#define ast_verb(level,...)
static void send_eivr_event(struct ast_iostream *stream, const char event, const char *data, const struct ast_channel *chan)
static struct ast_frame * gen_readframe(struct gen_state *state)
const char * pbx_builtin_getvar_helper(struct ast_channel *chan, const char *name)
Return a pointer to the value of the corresponding channel variable.
struct ast_frame_subclass subclass
char * ast_str_truncate(struct ast_str *buf, ssize_t len)
Truncates the enclosed string to the given length.
#define ast_strlen_zero(foo)
void ast_channel_stream_set(struct ast_channel *chan, struct ast_filestream *value)
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
#define ast_debug(level,...)
Log a DEBUG message.
int ast_iostream_close(struct ast_iostream *stream)
Close an iostream.
General Asterisk PBX channel definitions.
static struct ast_generator gen
static int gen_nextfile(struct gen_state *state)
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
static void ast_eivr_senddtmf(struct ast_channel *chan, char *vdata)
struct ast_sockaddr remote_address
#define ao2_ref(o, delta)
static int eivr_comm(struct ast_channel *chan, struct ivr_localuser *u, struct ast_iostream *eivr_events, struct ast_iostream *eivr_commands, struct ast_iostream *eivr_errors, const struct ast_str *args, const struct ast_flags flags)
#define ast_strdupa(s)
duplicate a string in memory from the stack
A set of macros to manage forward-linked lists.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
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.
Core PBX routines and definitions.
describes a server instance
static void gen_closestream(struct gen_state *state)
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
int ast_set_priority(int)
We set ourselves to a high priority, that we might pre-empt everything else. If your PBX has heavy ac...
static int app_exec(struct ast_channel *chan, const char *data)
static int unload_module(void)
static void gen_release(struct ast_channel *chan, void *data)
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
struct ast_filestream * stream
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
struct ast_frame * ast_readframe(struct ast_filestream *s)
Read a frame from a filestream.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int ast_safe_fork(int stop_reaper)
Common routine to safely fork without a chance of a signal handler firing badly in the child...
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define ast_channel_unlock(chan)
#define ast_calloc(num, len)
A wrapper for calloc()
int ast_closestream(struct ast_filestream *f)
Closes a stream.
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.
Structure used to handle boolean flags.
struct ast_iostream * stream
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
ssize_t ast_iostream_gets(struct ast_iostream *stream, char *buffer, size_t size)
Read a LF-terminated string from an iostream.
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
void ast_deactivate_generator(struct ast_channel *chan)
struct playlist_entry::@23 list
char * strsep(char **str, const char *delims)
static const struct ast_app_option app_opts[128]
This structure is allocated by file.c in one chunk, together with buf_size and desc_size bytes of mem...
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
struct ast_tcptls_session_instance * ast_tcptls_client_create(struct ast_tcptls_session_args *desc)
int ast_fileexists(const char *filename, const char *fmt, const char *preflang)
Checks for the existence of a given file.
int ast_answer(struct ast_channel *chan)
Answer a channel.
Data structure associated with a single frame of data.
const char * ast_channel_language(const struct ast_channel *chan)
struct ivr_localuser::finishlist finishlist
struct ast_tcptls_session_instance * ast_tcptls_client_start(struct ast_tcptls_session_instance *tcptls_session)
attempts to connect and start tcptls session, on error the tcptls_session's ref count is decremented...
union ast_frame::@263 data
enum ast_frame_type frametype
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
int ast_app_parse_timelen(const char *timestr, int *result, enum ast_timelen defunit)
Common routine to parse time lengths, with optional time unit specifier.
#define AST_LIST_HEAD_INIT_VALUE
Defines initial values for a declaration of AST_LIST_HEAD.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
static void ast_eivr_setvariable(struct ast_channel *chan, char *data)
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
static struct playlist_entry * make_entry(const char *filename)
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
#define ast_opt_high_priority
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
int ast_sockaddr_resolve(struct ast_sockaddr **addrs, const char *str, int flags, int family)
Parses a string with an IPv4 or IPv6 address and place results into an array.
#define AST_APP_ARG(name)
Define an application argument.
struct ast_channel * chan