109
109
static int eivr_comm(struct ast_channel *chan, struct ivr_localuser *u,
110
int eivr_events_fd, int eivr_commands_fd, int eivr_errors_fd,
110
int *eivr_events_fd, int *eivr_commands_fd, int *eivr_errors_fd,
111
111
const struct ast_str *args, const struct ast_flags flags);
113
113
int eivr_connect_socket(struct ast_channel *chan, const char *host, int port);
316
316
struct ast_flags flags = { 0, };
318
318
struct playlist_entry *entry;
319
int child_stdin[2] = { 0, 0 };
320
int child_stdout[2] = { 0, 0 };
321
int child_stderr[2] = { 0, 0 };
319
int child_stdin[2] = { -1, -1 };
320
int child_stdout[2] = { -1, -1 };
321
int child_stderr[2] = { -1, -1 };
349
349
u->abort_current_sound = 0;
352
if (ast_strlen_zero(data)) {
353
ast_log(LOG_WARNING, "ExternalIVR requires a command to execute\n");
352
357
buf = ast_strdupa(data);
353
358
AST_STANDARD_APP_ARGS(eivr_args, buf);
433
438
ivr_desc.local_address.sin_family = AF_INET;
434
439
ivr_desc.local_address.sin_port = htons(port);
435
440
memcpy(&ivr_desc.local_address.sin_addr.s_addr, hp.hp.h_addr, hp.hp.h_length);
436
ser = ast_tcptls_client_start(&ivr_desc);
441
if (!(ser = ast_tcptls_client_create(&ivr_desc)) || !(ser = ast_tcptls_client_start(ser))) {
441
res = eivr_comm(chan, u, ser->fd, ser->fd, -1, pipe_delim_args, flags);
444
res = eivr_comm(chan, u, &ser->fd, &ser->fd, NULL, pipe_delim_args, flags);
445
447
if (pipe(child_stdin)) {
446
448
ast_chan_log(LOG_WARNING, chan, "Could not create pipe for child input: %s\n", strerror(errno));
477
479
/* parent process */
478
480
close(child_stdin[0]);
480
482
close(child_stdout[1]);
483
child_stdout[1] = -1;
482
484
close(child_stderr[1]);
484
res = eivr_comm(chan, u, child_stdin[1], child_stdout[0], child_stderr[0], pipe_delim_args, flags);
485
child_stderr[1] = -1;
486
res = eivr_comm(chan, u, &child_stdin[1], &child_stdout[0], &child_stderr[0], pipe_delim_args, flags);
490
492
ast_deactivate_generator(chan);
494
if (child_stdin[0] > -1) {
493
495
close(child_stdin[0]);
497
if (child_stdin[1] > -1) {
496
498
close(child_stdin[1]);
500
if (child_stdout[0] > -1) {
499
501
close(child_stdout[0]);
503
if (child_stdout[1] > -1) {
502
504
close(child_stdout[1]);
506
if (child_stderr[0] > -1) {
505
507
close(child_stderr[0]);
509
if (child_stderr[1] > -1) {
508
510
close(child_stderr[1]);
510
513
ao2_ref(ser, -1);
512
while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list)))
515
while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list))) {
518
521
static int eivr_comm(struct ast_channel *chan, struct ivr_localuser *u,
519
int eivr_events_fd, int eivr_commands_fd, int eivr_errors_fd,
522
int *eivr_events_fd, int *eivr_commands_fd, int *eivr_errors_fd,
520
523
const struct ast_str *args, const struct ast_flags flags)
522
525
struct playlist_entry *entry;
535
538
FILE *eivr_errors = NULL;
536
539
FILE *eivr_events = NULL;
538
if (!(eivr_events = fdopen(eivr_events_fd, "w"))) {
541
if (!(eivr_events = fdopen(*eivr_events_fd, "w"))) {
539
542
ast_chan_log(LOG_WARNING, chan, "Could not open stream to send events\n");
542
if (!(eivr_commands = fdopen(eivr_commands_fd, "r"))) {
545
if (!(eivr_commands = fdopen(*eivr_commands_fd, "r"))) {
543
546
ast_chan_log(LOG_WARNING, chan, "Could not open stream to receive commands\n");
546
if (eivr_errors_fd > -1) { /* if opening a socket connection, error stream will not be used */
547
if (!(eivr_errors = fdopen(eivr_errors_fd, "r"))) {
549
if (eivr_errors_fd) { /* if opening a socket connection, error stream will not be used */
550
if (!(eivr_errors = fdopen(*eivr_errors_fd, "r"))) {
548
551
ast_chan_log(LOG_WARNING, chan, "Could not open stream to receive errors\n");
587
rchan = ast_waitfor_nandfds(&chan, 1, waitfds, (eivr_errors_fd < 0) ? 1 : 2, &exception, &ready_fd, &ms);
590
rchan = ast_waitfor_nandfds(&chan, 1, waitfds, (eivr_errors_fd) ? 2 : 1, &exception, &ready_fd, &ms);
589
592
if (chan->_state == AST_STATE_UP && !AST_LIST_EMPTY(&u->finishlist)) {
590
593
AST_LIST_LOCK(&u->finishlist);
632
} else if (ready_fd == eivr_commands_fd) {
635
} else if (ready_fd == *eivr_commands_fd) {
633
636
char input[1024];
635
if (exception || (dup2(eivr_commands_fd, test_available_fd) == -1) || feof(eivr_commands)) {
638
if (exception || (dup2(*eivr_commands_fd, test_available_fd) == -1) || feof(eivr_commands)) {
636
639
ast_chan_log(LOG_WARNING, chan, "Child process went away\n");
753
756
ast_chan_log(LOG_WARNING, chan, "Unknown option requested '%s'\n", &input[2]);
755
} else if (eivr_errors_fd && ready_fd == eivr_errors_fd) {
758
} else if (eivr_errors_fd && (ready_fd == *eivr_errors_fd)) {
756
759
char input[1024];
758
761
if (exception || feof(eivr_errors)) {