| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Copyright (C) 1999 - 2005, Digium, Inc. | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Kevin P. Fleming <kpfleming@digium.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Portions taken from the file-based music-on-hold work | 
					
						
							|  |  |  |  * created by Anthony Minessale II in res_musiconhold.c | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  |  * This program is free software, distributed under the terms of | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  | /*! \file
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  |  * \brief External IVR application interface | 
					
						
							| 
									
										
										
										
											2005-12-30 21:18:06 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \author Kevin P. Fleming <kpfleming@digium.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \note Portions taken from the file-based music-on-hold work | 
					
						
							|  |  |  |  * created by Anthony Minessale II in res_musiconhold.c | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * \ingroup applications | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-11 00:52:19 +00:00
										 |  |  | #include <signal.h>
 | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "asterisk/lock.h"
 | 
					
						
							|  |  |  | #include "asterisk/file.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							|  |  |  | #include "asterisk/linkedlists.h"
 | 
					
						
							| 
									
										
										
										
											2005-12-01 02:32:10 +00:00
										 |  |  | #include "asterisk/app.h"
 | 
					
						
							| 
									
										
										
										
											2006-01-11 22:41:34 +00:00
										 |  |  | #include "asterisk/utils.h"
 | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | static const char *app = "ExternalIVR"; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | static const char *synopsis = "Interfaces with an external IVR application"; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | static const char *descrip =  | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | "  ExternalIVR(command[,arg[,arg...]]): Forks an process to run the supplied command,\n" | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | "and starts a generator on the channel. The generator's play list is\n" | 
					
						
							|  |  |  | "controlled by the external application, which can add and clear entries\n" | 
					
						
							|  |  |  | "via simple commands issued over its stdout. The external application\n" | 
					
						
							|  |  |  | "will receive all DTMF events received on the channel, and notification\n" | 
					
						
							|  |  |  | "if the channel is hung up. The application will not be forcibly terminated\n" | 
					
						
							|  |  |  | "when the channel is hung up.\n" | 
					
						
							| 
									
										
										
										
											2006-03-12 17:27:57 +00:00
										 |  |  | "See doc/externalivr.txt for a protocol specification.\n"; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-06 14:30:53 +00:00
										 |  |  | /* XXX the parser in gcc 2.95 gets confused if you don't put a space between 'name' and the comma */ | 
					
						
							|  |  |  | #define ast_chan_log(level, channel, format, ...) ast_log(level, "%s: " format, channel->name , ## __VA_ARGS__)
 | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | struct playlist_entry { | 
					
						
							|  |  |  | 	AST_LIST_ENTRY(playlist_entry) list; | 
					
						
							|  |  |  | 	char filename[1]; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-27 00:31:05 +00:00
										 |  |  | struct ivr_localuser { | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 	struct ast_channel *chan; | 
					
						
							|  |  |  | 	AST_LIST_HEAD(playlist, playlist_entry) playlist; | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 	AST_LIST_HEAD(finishlist, playlist_entry) finishlist; | 
					
						
							| 
									
										
										
										
											2005-09-07 15:32:01 +00:00
										 |  |  | 	int abort_current_sound; | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 	int playing_silence; | 
					
						
							|  |  |  | 	int option_autoclear; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct gen_state { | 
					
						
							| 
									
										
										
										
											2006-01-27 00:31:05 +00:00
										 |  |  | 	struct ivr_localuser *u; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 	struct ast_filestream *stream; | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 	struct playlist_entry *current; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 	int sample_queue; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | static void send_child_event(FILE *handle, const char event, const char *data, | 
					
						
							|  |  |  | 			     const struct ast_channel *chan) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char tmp[256]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!data) { | 
					
						
							| 
									
										
										
										
											2005-12-26 18:35:28 +00:00
										 |  |  | 		snprintf(tmp, sizeof(tmp), "%c,%10d", event, (int)time(NULL)); | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2005-12-26 18:35:28 +00:00
										 |  |  | 		snprintf(tmp, sizeof(tmp), "%c,%10d,%s", event, (int)time(NULL), data); | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-07 15:32:01 +00:00
										 |  |  | 	fprintf(handle, "%s\n", tmp); | 
					
						
							| 
									
										
										
										
											2006-10-03 15:53:07 +00:00
										 |  |  | 	if (option_debug) | 
					
						
							|  |  |  | 		ast_chan_log(LOG_DEBUG, chan, "sent '%s'\n", tmp); | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | static void *gen_alloc(struct ast_channel *chan, void *params) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-01-27 00:31:05 +00:00
										 |  |  | 	struct ivr_localuser *u = params; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 	struct gen_state *state; | 
					
						
							| 
									
										
										
										
											2006-01-11 22:41:34 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if (!(state = ast_calloc(1, sizeof(*state)))) | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	state->u = u; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return state; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void gen_closestream(struct gen_state *state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if (!state->stream) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ast_closestream(state->stream); | 
					
						
							|  |  |  | 	state->u->chan->stream = NULL; | 
					
						
							|  |  |  | 	state->stream = NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void gen_release(struct ast_channel *chan, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct gen_state *state = data; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	gen_closestream(state); | 
					
						
							| 
									
										
										
										
											2007-06-06 21:20:11 +00:00
										 |  |  | 	ast_free(data); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* caller has the playlist locked */ | 
					
						
							|  |  |  | static int gen_nextfile(struct gen_state *state) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-01-27 00:31:05 +00:00
										 |  |  | 	struct ivr_localuser *u = state->u; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 	char *file_to_stream; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-09-07 15:32:01 +00:00
										 |  |  | 	u->abort_current_sound = 0; | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 	u->playing_silence = 0; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 	gen_closestream(state); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (!state->stream) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 		state->current = AST_LIST_REMOVE_HEAD(&u->playlist, list); | 
					
						
							|  |  |  | 		if (state->current) { | 
					
						
							|  |  |  | 			file_to_stream = state->current->filename; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2006-12-11 22:31:20 +00:00
										 |  |  | 			file_to_stream = "silence/10"; | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 			u->playing_silence = 1; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!(state->stream = ast_openstream_full(u->chan, file_to_stream, u->chan->language, 1))) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 			ast_chan_log(LOG_WARNING, u->chan, "File '%s' could not be opened: %s\n", file_to_stream, strerror(errno)); | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 			if (!u->playing_silence) { | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 				continue; | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 			} else {  | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return (!state->stream); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct ast_frame *gen_readframe(struct gen_state *state) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct ast_frame *f = NULL; | 
					
						
							| 
									
										
										
										
											2006-01-27 00:31:05 +00:00
										 |  |  | 	struct ivr_localuser *u = state->u; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2005-09-07 15:32:01 +00:00
										 |  |  | 	if (u->abort_current_sound || | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 	    (u->playing_silence && AST_LIST_FIRST(&u->playlist))) { | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		gen_closestream(state); | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 		AST_LIST_LOCK(&u->playlist); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		gen_nextfile(state); | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 		AST_LIST_UNLOCK(&u->playlist); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(state->stream && (f = ast_readframe(state->stream)))) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 		if (state->current) { | 
					
						
							|  |  |  | 			AST_LIST_LOCK(&u->finishlist); | 
					
						
							|  |  |  | 			AST_LIST_INSERT_TAIL(&u->finishlist, state->current, list); | 
					
						
							|  |  |  | 			AST_LIST_UNLOCK(&u->finishlist); | 
					
						
							|  |  |  | 			state->current = NULL; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		if (!gen_nextfile(state)) | 
					
						
							|  |  |  | 			f = ast_readframe(state->stream); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return f; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int gen_generate(struct ast_channel *chan, void *data, int len, int samples) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct gen_state *state = data; | 
					
						
							|  |  |  | 	struct ast_frame *f = NULL; | 
					
						
							|  |  |  | 	int res = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	state->sample_queue += samples; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (state->sample_queue > 0) { | 
					
						
							|  |  |  | 		if (!(f = gen_readframe(state))) | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		res = ast_write(chan, f); | 
					
						
							|  |  |  | 		ast_frfree(f); | 
					
						
							|  |  |  | 		if (res < 0) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 			ast_chan_log(LOG_WARNING, chan, "Failed to write frame: %s\n", strerror(errno)); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		state->sample_queue -= f->samples; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct ast_generator gen = | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	alloc: gen_alloc, | 
					
						
							|  |  |  | 	release: gen_release, | 
					
						
							|  |  |  | 	generate: gen_generate, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct playlist_entry *make_entry(const char *filename) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct playlist_entry *entry; | 
					
						
							| 
									
										
										
										
											2006-01-11 22:41:34 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-01-27 00:31:05 +00:00
										 |  |  | 	if (!(entry = ast_calloc(1, sizeof(*entry) + strlen(filename) + 10))) /* XXX why 10 ? */ | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	strcpy(entry->filename, filename); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return entry; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int app_exec(struct ast_channel *chan, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct playlist_entry *entry; | 
					
						
							|  |  |  | 	int child_stdin[2] = { 0,0 }; | 
					
						
							|  |  |  | 	int child_stdout[2] = { 0,0 }; | 
					
						
							|  |  |  | 	int child_stderr[2] = { 0,0 }; | 
					
						
							|  |  |  | 	int res = -1; | 
					
						
							|  |  |  | 	int gen_active = 0; | 
					
						
							|  |  |  | 	int pid; | 
					
						
							| 
									
										
										
										
											2005-12-01 02:32:10 +00:00
										 |  |  | 	char *buf, *command; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 	FILE *child_commands = NULL; | 
					
						
							|  |  |  | 	FILE *child_errors = NULL; | 
					
						
							|  |  |  | 	FILE *child_events = NULL; | 
					
						
							| 
									
										
										
										
											2006-05-11 20:07:44 +00:00
										 |  |  | 	struct ivr_localuser foo = { | 
					
						
							|  |  |  | 		.playlist = AST_LIST_HEAD_INIT_VALUE, | 
					
						
							|  |  |  | 		.finishlist = AST_LIST_HEAD_INIT_VALUE, | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	struct ivr_localuser *u = &foo; | 
					
						
							| 
									
										
										
										
											2006-12-11 00:52:19 +00:00
										 |  |  | 	sigset_t fullset, oldset; | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | 	AST_DECLARE_APP_ARGS(args, | 
					
						
							|  |  |  | 		AST_APP_ARG(cmd)[32]; | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2006-01-27 00:31:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-11 00:52:19 +00:00
										 |  |  | 	sigfillset(&fullset); | 
					
						
							|  |  |  | 	pthread_sigmask(SIG_BLOCK, &fullset, &oldset); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-19 18:19:02 +00:00
										 |  |  | 	u->abort_current_sound = 0; | 
					
						
							| 
									
										
										
										
											2006-02-16 22:59:38 +00:00
										 |  |  | 	u->chan = chan; | 
					
						
							| 
									
										
										
										
											2005-10-19 18:19:02 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | 	if (ast_strlen_zero(data)) { | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "ExternalIVR requires a command to execute\n"); | 
					
						
							| 
									
										
										
										
											2006-01-27 00:31:05 +00:00
										 |  |  | 		return -1;	 | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-10 13:22:15 +00:00
										 |  |  | 	buf = ast_strdupa(data); | 
					
						
							| 
									
										
										
										
											2007-07-23 19:51:41 +00:00
										 |  |  | 	AST_STANDARD_APP_ARGS(args, buf); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (pipe(child_stdin)) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 		ast_chan_log(LOG_WARNING, chan, "Could not create pipe for child input: %s\n", strerror(errno)); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		goto exit; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (pipe(child_stdout)) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 		ast_chan_log(LOG_WARNING, chan, "Could not create pipe for child output: %s\n", strerror(errno)); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		goto exit; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (pipe(child_stderr)) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 		ast_chan_log(LOG_WARNING, chan, "Could not create pipe for child errors: %s\n", strerror(errno)); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		goto exit; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (chan->_state != AST_STATE_UP) { | 
					
						
							|  |  |  | 		ast_answer(chan); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ast_activate_generator(chan, &gen, u) < 0) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 		ast_chan_log(LOG_WARNING, chan, "Failed to activate generator\n"); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		goto exit; | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		gen_active = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pid = fork(); | 
					
						
							|  |  |  | 	if (pid < 0) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Failed to fork(): %s\n", strerror(errno)); | 
					
						
							|  |  |  | 		goto exit; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!pid) { | 
					
						
							|  |  |  | 		/* child process */ | 
					
						
							|  |  |  | 		int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-11 00:52:19 +00:00
										 |  |  | 		signal(SIGPIPE, SIG_DFL); | 
					
						
							|  |  |  | 		pthread_sigmask(SIG_UNBLOCK, &fullset, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-01 21:48:30 +00:00
										 |  |  | 		if (ast_opt_high_priority) | 
					
						
							|  |  |  | 			ast_set_priority(0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		dup2(child_stdin[0], STDIN_FILENO); | 
					
						
							|  |  |  | 		dup2(child_stdout[1], STDOUT_FILENO); | 
					
						
							|  |  |  | 		dup2(child_stderr[1], STDERR_FILENO); | 
					
						
							|  |  |  | 		for (i = STDERR_FILENO + 1; i < 1024; i++) | 
					
						
							|  |  |  | 			close(i); | 
					
						
							| 
									
										
										
										
											2007-08-06 14:37:52 +00:00
										 |  |  | 		execv(args.cmd[0], args.cmd); | 
					
						
							|  |  |  | 		fprintf(stderr, "Failed to execute '%s': %s\n", args.cmd[0], strerror(errno)); | 
					
						
							| 
									
										
										
										
											2006-10-27 17:42:57 +00:00
										 |  |  | 		_exit(1); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		/* parent process */ | 
					
						
							|  |  |  | 		int child_events_fd = child_stdin[1]; | 
					
						
							|  |  |  | 		int child_commands_fd = child_stdout[0]; | 
					
						
							|  |  |  | 		int child_errors_fd = child_stderr[0]; | 
					
						
							|  |  |  | 		struct ast_frame *f; | 
					
						
							|  |  |  | 		int ms; | 
					
						
							|  |  |  | 		int exception; | 
					
						
							|  |  |  | 		int ready_fd; | 
					
						
							|  |  |  | 		int waitfds[2] = { child_errors_fd, child_commands_fd }; | 
					
						
							|  |  |  | 		struct ast_channel *rchan; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-12-11 00:52:19 +00:00
										 |  |  | 		pthread_sigmask(SIG_SETMASK, &oldset, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		close(child_stdin[0]); | 
					
						
							| 
									
										
										
										
											2005-09-01 19:44:51 +00:00
										 |  |  | 		child_stdin[0] = 0; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		close(child_stdout[1]); | 
					
						
							| 
									
										
										
										
											2005-09-01 19:44:51 +00:00
										 |  |  | 		child_stdout[1] = 0; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		close(child_stderr[1]); | 
					
						
							| 
									
										
										
										
											2005-09-01 19:44:51 +00:00
										 |  |  | 		child_stderr[1] = 0; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (!(child_events = fdopen(child_events_fd, "w"))) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 			ast_chan_log(LOG_WARNING, chan, "Could not open stream for child events\n"); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 			goto exit; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!(child_commands = fdopen(child_commands_fd, "r"))) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 			ast_chan_log(LOG_WARNING, chan, "Could not open stream for child commands\n"); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 			goto exit; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!(child_errors = fdopen(child_errors_fd, "r"))) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 			ast_chan_log(LOG_WARNING, chan, "Could not open stream for child errors\n"); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 			goto exit; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-12 17:31:45 +00:00
										 |  |  | 		setvbuf(child_events, NULL, _IONBF, 0); | 
					
						
							|  |  |  | 		setvbuf(child_commands, NULL, _IONBF, 0); | 
					
						
							|  |  |  | 		setvbuf(child_errors, NULL, _IONBF, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		res = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		while (1) { | 
					
						
							|  |  |  | 			if (ast_test_flag(chan, AST_FLAG_ZOMBIE)) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 				ast_chan_log(LOG_NOTICE, chan, "Is a zombie\n"); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 				res = -1; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (ast_check_hangup(chan)) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 				ast_chan_log(LOG_NOTICE, chan, "Got check_hangup\n"); | 
					
						
							|  |  |  | 				send_child_event(child_events, 'H', NULL, chan); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 				res = -1; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			ready_fd = 0; | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 			ms = 100; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 			errno = 0; | 
					
						
							|  |  |  | 			exception = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			rchan = ast_waitfor_nandfds(&chan, 1, waitfds, 2, &exception, &ready_fd, &ms); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 			if (!AST_LIST_EMPTY(&u->finishlist)) { | 
					
						
							|  |  |  | 				AST_LIST_LOCK(&u->finishlist); | 
					
						
							|  |  |  | 				while ((entry = AST_LIST_REMOVE_HEAD(&u->finishlist, list))) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 					send_child_event(child_events, 'F', entry->filename, chan); | 
					
						
							| 
									
										
										
										
											2007-06-06 21:20:11 +00:00
										 |  |  | 					ast_free(entry); | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				AST_LIST_UNLOCK(&u->finishlist); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 			if (rchan) { | 
					
						
							|  |  |  | 				/* the channel has something */ | 
					
						
							|  |  |  | 				f = ast_read(chan); | 
					
						
							|  |  |  | 				if (!f) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 					ast_chan_log(LOG_NOTICE, chan, "Returned no frame\n"); | 
					
						
							|  |  |  | 					send_child_event(child_events, 'H', NULL, chan); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 					res = -1; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (f->frametype == AST_FRAME_DTMF) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 					send_child_event(child_events, f->subclass, NULL, chan); | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 					if (u->option_autoclear) { | 
					
						
							| 
									
										
										
										
											2005-09-07 15:32:01 +00:00
										 |  |  | 						if (!u->abort_current_sound && !u->playing_silence) | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 							send_child_event(child_events, 'T', NULL, chan); | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 						AST_LIST_LOCK(&u->playlist); | 
					
						
							|  |  |  | 						while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list))) { | 
					
						
							| 
									
										
										
										
											2005-09-07 15:32:01 +00:00
										 |  |  | 							send_child_event(child_events, 'D', entry->filename, chan); | 
					
						
							| 
									
										
										
										
											2007-06-06 21:20:11 +00:00
										 |  |  | 							ast_free(entry); | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2005-09-07 15:32:01 +00:00
										 |  |  | 						if (!u->playing_silence) | 
					
						
							|  |  |  | 							u->abort_current_sound = 1; | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 						AST_LIST_UNLOCK(&u->playlist); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 				} else if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP)) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 					ast_chan_log(LOG_NOTICE, chan, "Got AST_CONTROL_HANGUP\n"); | 
					
						
							|  |  |  | 					send_child_event(child_events, 'H', NULL, chan); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 					ast_frfree(f); | 
					
						
							|  |  |  | 					res = -1; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				ast_frfree(f); | 
					
						
							|  |  |  | 			} else if (ready_fd == child_commands_fd) { | 
					
						
							|  |  |  | 				char input[1024]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (exception || feof(child_commands)) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 					ast_chan_log(LOG_WARNING, chan, "Child process went away\n"); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 					res = -1; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (!fgets(input, sizeof(input), child_commands)) | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				command = ast_strip(input); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-03 15:53:07 +00:00
										 |  |  | 				if (option_debug) | 
					
						
							|  |  |  | 					ast_chan_log(LOG_DEBUG, chan, "got command '%s'\n", input); | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 				if (strlen(input) < 4) | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (input[0] == 'S') { | 
					
						
							| 
									
										
										
										
											2006-10-19 17:22:13 +00:00
										 |  |  | 					if (ast_fileexists(&input[2], NULL, u->chan->language) == -1) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 						ast_chan_log(LOG_WARNING, chan, "Unknown file requested '%s'\n", &input[2]); | 
					
						
							|  |  |  | 						send_child_event(child_events, 'Z', NULL, chan); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 						strcpy(&input[2], "exception"); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2005-09-07 15:32:01 +00:00
										 |  |  | 					if (!u->abort_current_sound && !u->playing_silence) | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 						send_child_event(child_events, 'T', NULL, chan); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 					AST_LIST_LOCK(&u->playlist); | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 					while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list))) { | 
					
						
							| 
									
										
										
										
											2005-09-07 15:32:01 +00:00
										 |  |  | 						send_child_event(child_events, 'D', entry->filename, chan); | 
					
						
							| 
									
										
										
										
											2007-06-06 21:20:11 +00:00
										 |  |  | 						ast_free(entry); | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2005-09-07 15:32:01 +00:00
										 |  |  | 					if (!u->playing_silence) | 
					
						
							|  |  |  | 						u->abort_current_sound = 1; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 					entry = make_entry(&input[2]); | 
					
						
							|  |  |  | 					if (entry) | 
					
						
							| 
									
										
										
										
											2005-08-11 18:34:03 +00:00
										 |  |  | 						AST_LIST_INSERT_TAIL(&u->playlist, entry, list); | 
					
						
							|  |  |  | 					AST_LIST_UNLOCK(&u->playlist); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 				} else if (input[0] == 'A') { | 
					
						
							| 
									
										
										
										
											2006-10-19 17:22:13 +00:00
										 |  |  | 					if (ast_fileexists(&input[2], NULL, u->chan->language) == -1) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 						ast_chan_log(LOG_WARNING, chan, "Unknown file requested '%s'\n", &input[2]); | 
					
						
							|  |  |  | 						send_child_event(child_events, 'Z', NULL, chan); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 						strcpy(&input[2], "exception"); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					entry = make_entry(&input[2]); | 
					
						
							|  |  |  | 					if (entry) { | 
					
						
							|  |  |  | 						AST_LIST_LOCK(&u->playlist); | 
					
						
							|  |  |  | 						AST_LIST_INSERT_TAIL(&u->playlist, entry, list); | 
					
						
							|  |  |  | 						AST_LIST_UNLOCK(&u->playlist); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2007-01-23 04:45:43 +00:00
										 |  |  | 				} else if (input[0] == 'E') { | 
					
						
							|  |  |  | 					ast_chan_log(LOG_NOTICE, chan, "Exiting: %s\n", &input[2]); | 
					
						
							|  |  |  | 					send_child_event(child_events, 'E', NULL, chan); | 
					
						
							|  |  |  | 					res = 0; | 
					
						
							|  |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 				} else if (input[0] == 'H') { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 					ast_chan_log(LOG_NOTICE, chan, "Hanging up: %s\n", &input[2]); | 
					
						
							|  |  |  | 					send_child_event(child_events, 'H', NULL, chan); | 
					
						
							| 
									
										
										
										
											2007-01-23 04:45:43 +00:00
										 |  |  | 					res = -1; | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2005-08-24 14:24:55 +00:00
										 |  |  | 				} else if (input[0] == 'O') { | 
					
						
							|  |  |  | 					if (!strcasecmp(&input[2], "autoclear")) | 
					
						
							|  |  |  | 						u->option_autoclear = 1; | 
					
						
							|  |  |  | 					else if (!strcasecmp(&input[2], "noautoclear")) | 
					
						
							|  |  |  | 						u->option_autoclear = 0; | 
					
						
							|  |  |  | 					else | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 						ast_chan_log(LOG_WARNING, chan, "Unknown option requested '%s'\n", &input[2]); | 
					
						
							| 
									
										
										
										
											2007-01-23 04:45:43 +00:00
										 |  |  | 				} else if (input[0] == 'V') { | 
					
						
							|  |  |  | 					char *c; | 
					
						
							|  |  |  | 					c = strchr(&input[2], '='); | 
					
						
							|  |  |  | 					if (!c) { | 
					
						
							|  |  |  | 						send_child_event(child_events, 'Z', NULL, chan); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						*c++ = '\0'; | 
					
						
							|  |  |  | 						pbx_builtin_setvar_helper(chan, &input[2], c); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} else if (ready_fd == child_errors_fd) { | 
					
						
							|  |  |  | 				char input[1024]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (exception || feof(child_errors)) { | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 					ast_chan_log(LOG_WARNING, chan, "Child process went away\n"); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 					res = -1; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if (fgets(input, sizeof(input), child_errors)) { | 
					
						
							|  |  |  | 					command = ast_strip(input); | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 					ast_chan_log(LOG_NOTICE, chan, "stderr: %s\n", command); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} else if ((ready_fd < 0) && ms) {  | 
					
						
							|  |  |  | 				if (errno == 0 || errno == EINTR) | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-08-24 23:10:55 +00:00
										 |  |  | 				ast_chan_log(LOG_WARNING, chan, "Wait failed (%s)\n", strerror(errno)); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  exit: | 
					
						
							|  |  |  | 	if (gen_active) | 
					
						
							|  |  |  | 		ast_deactivate_generator(chan); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (child_events) | 
					
						
							|  |  |  | 		fclose(child_events); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (child_commands) | 
					
						
							|  |  |  | 		fclose(child_commands); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (child_errors) | 
					
						
							|  |  |  | 		fclose(child_errors); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-01 19:44:51 +00:00
										 |  |  | 	if (child_stdin[0]) | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		close(child_stdin[0]); | 
					
						
							| 
									
										
										
										
											2005-09-01 19:44:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (child_stdin[1]) | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		close(child_stdin[1]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-01 19:44:51 +00:00
										 |  |  | 	if (child_stdout[0]) | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		close(child_stdout[0]); | 
					
						
							| 
									
										
										
										
											2005-09-01 19:44:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (child_stdout[1]) | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		close(child_stdout[1]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-01 19:44:51 +00:00
										 |  |  | 	if (child_stderr[0]) | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		close(child_stderr[0]); | 
					
						
							| 
									
										
										
										
											2005-09-01 19:44:51 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (child_stderr[1]) | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 		close(child_stderr[1]); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-19 18:19:02 +00:00
										 |  |  | 	while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list))) | 
					
						
							| 
									
										
										
										
											2007-06-06 21:20:11 +00:00
										 |  |  | 		ast_free(entry); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-16 13:35:20 +00:00
										 |  |  | 	return ast_unregister_application(app); | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2005-08-10 23:24:39 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	return ast_register_application(app, app_exec, synopsis, descrip); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "External IVR Interface Application"); |