| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-15 15:44:26 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 2002, Christos Ricudis | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2004-03-15 16:51:58 +00:00
										 |  |  |  * Christos Ricudis <ricudis@itc.auth.gr> | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-15 15:44:26 +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. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  |  * This program is free software, distributed under the terms of | 
					
						
							| 
									
										
										
										
											2005-09-15 15:44:26 +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-15 15:44:26 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  |  * \brief Connect to festival | 
					
						
							| 
									
										
										
										
											2005-12-30 21:18:06 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \author Christos Ricudis <ricudis@itc.auth.gr> | 
					
						
							| 
									
										
										
										
											2007-02-24 19:27:50 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \extref  The Festival Speech Synthesis System - http://www.cstr.ed.ac.uk/projects/festival/
 | 
					
						
							| 
									
										
										
										
											2005-09-15 15:44:26 +00:00
										 |  |  |  *  | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * \ingroup applications | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-14 20:13:06 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							|  |  |  | 	<support_level>extended</support_level> | 
					
						
							|  |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | #include <sys/socket.h>
 | 
					
						
							|  |  |  | #include <netdb.h>
 | 
					
						
							|  |  |  | #include <netinet/in.h>
 | 
					
						
							|  |  |  | #include <arpa/inet.h>
 | 
					
						
							|  |  |  | #include <signal.h>
 | 
					
						
							|  |  |  | #include <fcntl.h>
 | 
					
						
							|  |  |  | #include <ctype.h>
 | 
					
						
							| 
									
										
										
										
											2008-11-02 18:52:13 +00:00
										 |  |  | #include <errno.h>
 | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-06 22:39:32 +00:00
										 |  |  | #include "asterisk/file.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							|  |  |  | #include "asterisk/md5.h"
 | 
					
						
							|  |  |  | #include "asterisk/config.h"
 | 
					
						
							|  |  |  | #include "asterisk/utils.h"
 | 
					
						
							|  |  |  | #include "asterisk/lock.h"
 | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | #include "asterisk/app.h"
 | 
					
						
							| 
									
										
										
										
											2010-08-30 22:28:47 +00:00
										 |  |  | #include "asterisk/endian.h"
 | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #define FESTIVAL_CONFIG "festival.conf"
 | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | #define MAXLEN 180
 | 
					
						
							|  |  |  | #define MAXFESTLEN 2048
 | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | /*** DOCUMENTATION
 | 
					
						
							|  |  |  | 	<application name="Festival" language="en_US"> | 
					
						
							|  |  |  | 		<synopsis> | 
					
						
							|  |  |  | 			Say text to the user. | 
					
						
							|  |  |  | 		</synopsis> | 
					
						
							|  |  |  | 		<syntax> | 
					
						
							|  |  |  | 			<parameter name="text" required="true" /> | 
					
						
							|  |  |  | 			<parameter name="intkeys" /> | 
					
						
							|  |  |  | 		</syntax> | 
					
						
							|  |  |  | 		<description> | 
					
						
							|  |  |  | 			<para>Connect to Festival, send the argument, get back the waveform, play it to the user, | 
					
						
							|  |  |  | 			allowing any given interrupt keys to immediately terminate and return the value, or | 
					
						
							|  |  |  | 			<literal>any</literal> to allow any number back (useful in dialplan).</para> | 
					
						
							|  |  |  | 		</description> | 
					
						
							|  |  |  | 	</application> | 
					
						
							|  |  |  |  ***/ | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | static char *app = "Festival"; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | static char *socket_receive_file_to_buff(int fd, int *size) | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 	/* Receive file (probably a waveform file) from socket using
 | 
					
						
							|  |  |  | 	 * Festival key stuff technique, but long winded I know, sorry | 
					
						
							|  |  |  | 	 * but will receive any file without closing the stream or | 
					
						
							|  |  |  | 	 * using OOB data | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	static char *file_stuff_key = "ft_StUfF_key"; /* must == Festival's key */ | 
					
						
							|  |  |  | 	char *buff, *tmp; | 
					
						
							|  |  |  | 	int bufflen; | 
					
						
							|  |  |  | 	int n,k,i; | 
					
						
							|  |  |  | 	char c; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 	bufflen = 1024; | 
					
						
							|  |  |  | 	if (!(buff = ast_malloc(bufflen))) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	*size = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (k = 0; file_stuff_key[k] != '\0';) { | 
					
						
							|  |  |  | 		n = read(fd, &c, 1); | 
					
						
							|  |  |  | 		if (n == 0) | 
					
						
							|  |  |  | 			break;  /* hit stream eof before end of file */ | 
					
						
							|  |  |  | 		if ((*size) + k + 1 >= bufflen) { | 
					
						
							|  |  |  | 			/* +1 so you can add a terminating NULL if you want */ | 
					
						
							|  |  |  | 			bufflen += bufflen / 4; | 
					
						
							|  |  |  | 			if (!(tmp = ast_realloc(buff, bufflen))) { | 
					
						
							|  |  |  | 				ast_free(buff); | 
					
						
							|  |  |  | 				return NULL; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			buff = tmp; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (file_stuff_key[k] == c) | 
					
						
							|  |  |  | 			k++; | 
					
						
							|  |  |  | 		else if ((c == 'X') && (file_stuff_key[k+1] == '\0')) { | 
					
						
							|  |  |  | 			/* It looked like the key but wasn't */ | 
					
						
							|  |  |  | 			for (i = 0; i < k; i++, (*size)++) | 
					
						
							|  |  |  | 				buff[*size] = file_stuff_key[i]; | 
					
						
							|  |  |  | 			k = 0; | 
					
						
							|  |  |  | 			/* omit the stuffed 'X' */ | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			for (i = 0; i < k; i++, (*size)++) | 
					
						
							|  |  |  | 				buff[*size] = file_stuff_key[i]; | 
					
						
							|  |  |  | 			k = 0; | 
					
						
							|  |  |  | 			buff[*size] = c; | 
					
						
							|  |  |  | 			(*size)++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return buff; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | static int send_waveform_to_fd(char *waveform, int length, int fd) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int res; | 
					
						
							| 
									
										
										
										
											2010-08-30 22:28:47 +00:00
										 |  |  | #if __BYTE_ORDER == __BIG_ENDIAN
 | 
					
						
							| 
									
										
										
										
											2009-07-22 21:43:57 +00:00
										 |  |  | 	int x; | 
					
						
							| 
									
										
										
										
											2004-01-11 08:32:50 +00:00
										 |  |  | 	char c; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-12-11 00:52:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-16 22:57:54 +00:00
										 |  |  | 	res = ast_safe_fork(0); | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 	if (res < 0) | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Fork failed\n"); | 
					
						
							|  |  |  | 	if (res) { | 
					
						
							|  |  |  | 		return res; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-04-16 22:57:54 +00:00
										 |  |  | 	dup2(fd, 0); | 
					
						
							|  |  |  | 	ast_close_fds_above_n(0); | 
					
						
							| 
									
										
										
										
											2006-05-01 21:48:30 +00:00
										 |  |  | 	if (ast_opt_high_priority) | 
					
						
							|  |  |  | 		ast_set_priority(0); | 
					
						
							| 
									
										
										
										
											2010-08-30 22:28:47 +00:00
										 |  |  | #if __BYTE_ORDER == __BIG_ENDIAN
 | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 	for (x = 0; x < length; x += 2) { | 
					
						
							|  |  |  | 		c = *(waveform + x + 1); | 
					
						
							|  |  |  | 		*(waveform + x + 1) = *(waveform + x); | 
					
						
							|  |  |  | 		*(waveform + x) = c; | 
					
						
							| 
									
										
										
										
											2004-01-11 08:32:50 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2010-08-30 22:28:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (write(0, waveform, length) < 0) { | 
					
						
							|  |  |  | 		/* Cannot log -- all FDs are already closed */ | 
					
						
							| 
									
										
										
										
											2008-11-02 18:52:13 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	close(fd); | 
					
						
							| 
									
										
										
										
											2010-08-30 22:28:47 +00:00
										 |  |  | 	_exit(0); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | static int send_waveform_to_channel(struct ast_channel *chan, char *waveform, int length, char *intkeys) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int res = 0; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	int fds[2]; | 
					
						
							| 
									
										
										
										
											2003-08-14 15:58:55 +00:00
										 |  |  | 	int needed = 0; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	int owriteformat; | 
					
						
							|  |  |  | 	struct ast_frame *f; | 
					
						
							|  |  |  | 	struct myframe { | 
					
						
							|  |  |  | 		struct ast_frame f; | 
					
						
							|  |  |  | 		char offset[AST_FRIENDLY_OFFSET]; | 
					
						
							| 
									
										
										
										
											2003-08-14 15:58:55 +00:00
										 |  |  | 		char frdata[2048]; | 
					
						
							| 
									
										
										
										
											2007-05-24 15:04:51 +00:00
										 |  |  | 	} myf = { | 
					
						
							|  |  |  | 		.f = { 0, }, | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (pipe(fds)) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Unable to create pipe\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-04-16 02:51:47 +00:00
										 |  |  | 	/* Answer if it's not already going */ | 
					
						
							|  |  |  | 	if (chan->_state != AST_STATE_UP) | 
					
						
							|  |  |  | 		ast_answer(chan); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	ast_stopstream(chan); | 
					
						
							| 
									
										
										
										
											2006-01-17 20:16:18 +00:00
										 |  |  | 	ast_indicate(chan, -1); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	owriteformat = chan->writeformat; | 
					
						
							| 
									
										
										
										
											2004-04-06 22:17:32 +00:00
										 |  |  | 	res = ast_set_write_format(chan, AST_FORMAT_SLINEAR); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	if (res < 0) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Unable to set write format to signed linear\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 	res = send_waveform_to_fd(waveform, length, fds[1]); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	if (res >= 0) { | 
					
						
							|  |  |  | 		/* Order is important -- there's almost always going to be mp3...  we want to prioritize the
 | 
					
						
							|  |  |  | 		   user */ | 
					
						
							|  |  |  | 		for (;;) { | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 			res = ast_waitfor(chan, 1000); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 			if (res < 1) { | 
					
						
							|  |  |  | 				res = -1; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2003-08-14 15:58:55 +00:00
										 |  |  | 			f = ast_read(chan); | 
					
						
							|  |  |  | 			if (!f) { | 
					
						
							| 
									
										
										
										
											2003-09-27 02:31:07 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Null frame == hangup() detected\n"); | 
					
						
							| 
									
										
										
										
											2003-08-14 15:58:55 +00:00
										 |  |  | 				res = -1; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (f->frametype == AST_FRAME_DTMF) { | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 				ast_debug(1, "User pressed a key\n"); | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 				if (intkeys && strchr(intkeys, f->subclass.integer)) { | 
					
						
							|  |  |  | 					res = f->subclass.integer; | 
					
						
							| 
									
										
										
										
											2003-08-15 04:38:39 +00:00
										 |  |  | 					ast_frfree(f); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2003-08-14 15:58:55 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (f->frametype == AST_FRAME_VOICE) { | 
					
						
							|  |  |  | 				/* Treat as a generator */ | 
					
						
							| 
									
										
										
										
											2003-08-14 16:01:25 +00:00
										 |  |  | 				needed = f->samples * 2; | 
					
						
							| 
									
										
										
										
											2003-08-14 15:58:55 +00:00
										 |  |  | 				if (needed > sizeof(myf.frdata)) { | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "Only able to deliver %d of %d requested samples\n", | 
					
						
							| 
									
										
										
										
											2004-06-13 21:25:10 +00:00
										 |  |  | 						(int)sizeof(myf.frdata) / 2, needed/2); | 
					
						
							| 
									
										
										
										
											2003-08-14 15:58:55 +00:00
										 |  |  | 					needed = sizeof(myf.frdata); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2003-08-14 15:58:55 +00:00
										 |  |  | 				res = read(fds[0], myf.frdata, needed); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 				if (res > 0) { | 
					
						
							|  |  |  | 					myf.f.frametype = AST_FRAME_VOICE; | 
					
						
							| 
									
										
										
										
											2009-11-04 14:05:12 +00:00
										 |  |  | 					myf.f.subclass.codec = AST_FORMAT_SLINEAR; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 					myf.f.datalen = res; | 
					
						
							| 
									
										
										
										
											2002-11-29 02:14:13 +00:00
										 |  |  | 					myf.f.samples = res / 2; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 					myf.f.offset = AST_FRIENDLY_OFFSET; | 
					
						
							|  |  |  | 					myf.f.src = __PRETTY_FUNCTION__; | 
					
						
							| 
									
										
										
										
											2008-05-22 16:29:54 +00:00
										 |  |  | 					myf.f.data.ptr = myf.frdata; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 					if (ast_write(chan, &myf.f) < 0) { | 
					
						
							|  |  |  | 						res = -1; | 
					
						
							| 
									
										
										
										
											2006-06-11 20:46:05 +00:00
										 |  |  | 						ast_frfree(f); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2004-12-19 21:13:41 +00:00
										 |  |  | 					if (res < needed) { /* last frame */ | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 						ast_debug(1, "Last frame\n"); | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 						res = 0; | 
					
						
							| 
									
										
										
										
											2006-06-11 20:46:05 +00:00
										 |  |  | 						ast_frfree(f); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2007-06-14 19:39:12 +00:00
										 |  |  | 					ast_debug(1, "No more waveform\n"); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 					res = 0; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2003-08-14 15:58:55 +00:00
										 |  |  | 			ast_frfree(f); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	close(fds[0]); | 
					
						
							|  |  |  | 	close(fds[1]); | 
					
						
							| 
									
										
										
										
											2004-12-19 21:13:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	if (!res && owriteformat) | 
					
						
							| 
									
										
										
										
											2004-04-06 22:17:32 +00:00
										 |  |  | 		ast_set_write_format(chan, owriteformat); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int festival_exec(struct ast_channel *chan, const char *vdata) | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int usecache; | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 	int res = 0; | 
					
						
							|  |  |  | 	struct sockaddr_in serv_addr; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	struct hostent *serverhost; | 
					
						
							| 
									
										
										
										
											2004-04-22 00:20:34 +00:00
										 |  |  | 	struct ast_hostent ahp; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	int fd; | 
					
						
							|  |  |  | 	FILE *fs; | 
					
						
							| 
									
										
										
										
											2006-09-20 20:40:39 +00:00
										 |  |  | 	const char *host; | 
					
						
							|  |  |  | 	const char *cachedir; | 
					
						
							|  |  |  | 	const char *temp; | 
					
						
							|  |  |  | 	const char *festivalcommand; | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 	int port = 1314; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	int n; | 
					
						
							|  |  |  | 	char ack[4]; | 
					
						
							|  |  |  | 	char *waveform; | 
					
						
							|  |  |  | 	int filesize; | 
					
						
							|  |  |  | 	char bigstring[MAXFESTLEN]; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	struct MD5Context md5ctx; | 
					
						
							|  |  |  | 	unsigned char MD5Res[16]; | 
					
						
							| 
									
										
										
										
											2004-07-14 07:22:30 +00:00
										 |  |  | 	char MD5Hex[33] = ""; | 
					
						
							|  |  |  | 	char koko[4] = ""; | 
					
						
							|  |  |  | 	char cachefile[MAXFESTLEN]=""; | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 	int readcache = 0; | 
					
						
							|  |  |  | 	int writecache = 0; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	int strln; | 
					
						
							| 
									
										
										
										
											2003-08-15 04:38:39 +00:00
										 |  |  | 	int fdesc = -1; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	char buffer[16384]; | 
					
						
							| 
									
										
										
										
											2003-08-15 04:38:39 +00:00
										 |  |  | 	int seekpos = 0;	 | 
					
						
							| 
									
										
										
										
											2005-10-19 18:19:02 +00:00
										 |  |  | 	char *data;	 | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	struct ast_config *cfg; | 
					
						
							| 
									
										
										
										
											2006-05-09 05:30:05 +00:00
										 |  |  | 	char *newfestivalcommand; | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 	struct ast_flags config_flags = { 0 }; | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 	AST_DECLARE_APP_ARGS(args, | 
					
						
							|  |  |  | 		AST_APP_ARG(text); | 
					
						
							|  |  |  | 		AST_APP_ARG(interrupt); | 
					
						
							|  |  |  | 	); | 
					
						
							| 
									
										
										
										
											2005-10-19 18:19:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-26 19:48:14 +00:00
										 |  |  | 	if (ast_strlen_zero(vdata)) { | 
					
						
							| 
									
										
										
										
											2005-10-19 18:19:02 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "festival requires an argument (text)\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 	cfg = ast_config_load(FESTIVAL_CONFIG, config_flags); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	if (!cfg) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "No such configuration file %s\n", FESTIVAL_CONFIG); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2008-09-12 23:30:03 +00:00
										 |  |  | 	} else if (cfg == CONFIG_STATUS_FILEINVALID) { | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "Config file " FESTIVAL_CONFIG " is in an invalid format.  Aborting.\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-09-12 23:30:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	if (!(host = ast_variable_retrieve(cfg, "general", "host"))) { | 
					
						
							|  |  |  | 		host = "localhost"; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (!(temp = ast_variable_retrieve(cfg, "general", "port"))) { | 
					
						
							|  |  |  | 		port = 1314; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		port = atoi(temp); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (!(temp = ast_variable_retrieve(cfg, "general", "usecache"))) { | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 		usecache = 0; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2003-06-27 23:02:52 +00:00
										 |  |  | 		usecache = ast_true(temp); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (!(cachedir = ast_variable_retrieve(cfg, "general", "cachedir"))) { | 
					
						
							|  |  |  | 		cachedir = "/tmp/"; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-03-18 15:43:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	data = ast_strdupa(vdata); | 
					
						
							|  |  |  | 	AST_STANDARD_APP_ARGS(args, data); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	if (!(festivalcommand = ast_variable_retrieve(cfg, "general", "festivalcommand"))) { | 
					
						
							| 
									
										
										
										
											2008-03-18 15:43:34 +00:00
										 |  |  | 		const char *startcmd = "(tts_textasterisk \""; | 
					
						
							|  |  |  | 		const char *endcmd = "\" 'file)(quit)\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		strln = strlen(startcmd) + strlen(args.text) + strlen(endcmd) + 1; | 
					
						
							|  |  |  | 		newfestivalcommand = alloca(strln); | 
					
						
							|  |  |  | 		snprintf(newfestivalcommand, strln, "%s%s%s", startcmd, args.text, endcmd); | 
					
						
							|  |  |  | 		festivalcommand = newfestivalcommand; | 
					
						
							| 
									
										
										
										
											2006-05-09 05:30:05 +00:00
										 |  |  | 	} else { /* This else parses the festivalcommand that we're sent from the config file for \n's, etc */ | 
					
						
							| 
									
										
										
										
											2008-08-10 14:45:25 +00:00
										 |  |  | 		int x, j; | 
					
						
							| 
									
										
										
										
											2008-03-18 15:43:34 +00:00
										 |  |  | 		newfestivalcommand = alloca(strlen(festivalcommand) + strlen(args.text) + 1); | 
					
						
							| 
									
										
										
										
											2006-05-09 05:30:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-10 14:45:25 +00:00
										 |  |  | 		for (x = 0, j = 0; x < strlen(festivalcommand); x++) { | 
					
						
							|  |  |  | 			if (festivalcommand[x] == '\\' && festivalcommand[x + 1] == 'n') { | 
					
						
							| 
									
										
										
										
											2006-05-09 05:30:05 +00:00
										 |  |  | 				newfestivalcommand[j++] = '\n'; | 
					
						
							| 
									
										
										
										
											2008-08-10 14:45:25 +00:00
										 |  |  | 				x++; | 
					
						
							|  |  |  | 			} else if (festivalcommand[x] == '\\') { | 
					
						
							|  |  |  | 				newfestivalcommand[j++] = festivalcommand[x + 1]; | 
					
						
							|  |  |  | 				x++; | 
					
						
							|  |  |  | 			} else if (festivalcommand[x] == '%' && festivalcommand[x + 1] == 's') { | 
					
						
							| 
									
										
										
										
											2008-03-18 15:43:34 +00:00
										 |  |  | 				sprintf(&newfestivalcommand[j], "%s", args.text); /* we know it is big enough */ | 
					
						
							|  |  |  | 				j += strlen(args.text); | 
					
						
							| 
									
										
										
										
											2008-08-10 14:45:25 +00:00
										 |  |  | 				x++; | 
					
						
							| 
									
										
										
										
											2006-05-09 05:30:05 +00:00
										 |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2008-08-10 14:45:25 +00:00
										 |  |  | 				newfestivalcommand[j++] = festivalcommand[x]; | 
					
						
							| 
									
										
										
										
											2006-05-09 05:30:05 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		newfestivalcommand[j] = '\0'; | 
					
						
							|  |  |  | 		festivalcommand = newfestivalcommand; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-10-19 18:19:02 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 	if (args.interrupt && !strcasecmp(args.interrupt, "any")) | 
					
						
							|  |  |  | 		args.interrupt = AST_DIGIT_ANY; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ast_debug(1, "Text passed to festival server : %s\n", args.text); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	/* Connect to local festival server */ | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-10-03 15:53:07 +00:00
										 |  |  | 	fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-03 15:53:07 +00:00
										 |  |  | 	if (fd < 0) { | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "festival_client: can't get socket\n"); | 
					
						
							| 
									
										
										
										
											2005-01-25 06:10:20 +00:00
										 |  |  | 		ast_config_destroy(cfg); | 
					
						
							| 
									
										
										
										
											2006-10-03 15:53:07 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-10-03 15:53:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	memset(&serv_addr, 0, sizeof(serv_addr)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((serv_addr.sin_addr.s_addr = inet_addr(host)) == -1) { | 
					
						
							|  |  |  | 		/* its a name rather than an ipnum */ | 
					
						
							|  |  |  | 		serverhost = ast_gethostbyname(host, &ahp); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 		if (serverhost == NULL) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "festival_client: gethostbyname failed\n"); | 
					
						
							| 
									
										
										
										
											2005-01-25 06:10:20 +00:00
										 |  |  | 			ast_config_destroy(cfg); | 
					
						
							| 
									
										
										
										
											2006-10-03 15:53:07 +00:00
										 |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 		memmove(&serv_addr.sin_addr, serverhost->h_addr, serverhost->h_length); | 
					
						
							| 
									
										
										
										
											2006-10-03 15:53:07 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	serv_addr.sin_family = AF_INET; | 
					
						
							|  |  |  | 	serv_addr.sin_port = htons(port); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (connect(fd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) != 0) { | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "festival_client: connect to server failed\n"); | 
					
						
							| 
									
										
										
										
											2005-01-25 06:10:20 +00:00
										 |  |  | 		ast_config_destroy(cfg); | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Compute MD5 sum of string */ | 
					
						
							|  |  |  | 	MD5Init(&md5ctx); | 
					
						
							|  |  |  | 	MD5Update(&md5ctx, (unsigned char *)args.text, strlen(args.text)); | 
					
						
							|  |  |  | 	MD5Final(MD5Res, &md5ctx); | 
					
						
							|  |  |  | 	MD5Hex[0] = '\0'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Convert to HEX and look if there is any matching file in the cache 
 | 
					
						
							|  |  |  | 		directory */ | 
					
						
							|  |  |  | 	for (i = 0; i < 16; i++) { | 
					
						
							|  |  |  | 		snprintf(koko, sizeof(koko), "%X", MD5Res[i]); | 
					
						
							|  |  |  | 		strncat(MD5Hex, koko, sizeof(MD5Hex) - strlen(MD5Hex) - 1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	readcache = 0; | 
					
						
							|  |  |  | 	writecache = 0; | 
					
						
							|  |  |  | 	if (strlen(cachedir) + strlen(MD5Hex) + 1 <= MAXFESTLEN && (usecache == -1)) { | 
					
						
							|  |  |  | 		snprintf(cachefile, sizeof(cachefile), "%s/%s", cachedir, MD5Hex); | 
					
						
							|  |  |  | 		fdesc = open(cachefile, O_RDWR); | 
					
						
							|  |  |  | 		if (fdesc == -1) { | 
					
						
							|  |  |  | 			fdesc = open(cachefile, O_CREAT | O_RDWR, AST_FILE_MODE); | 
					
						
							|  |  |  | 			if (fdesc != -1) { | 
					
						
							|  |  |  | 				writecache = 1; | 
					
						
							|  |  |  | 				strln = strlen(args.text); | 
					
						
							|  |  |  | 				ast_debug(1, "line length : %d\n", strln); | 
					
						
							| 
									
										
										
										
											2008-11-02 18:52:13 +00:00
										 |  |  |     				if (write(fdesc,&strln,sizeof(int)) < 0) { | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  |     				if (write(fdesc,data,strln) < 0) { | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 				seekpos = lseek(fdesc, 0, SEEK_CUR); | 
					
						
							|  |  |  | 				ast_debug(1, "Seek position : %d\n", seekpos); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2008-11-02 18:52:13 +00:00
										 |  |  |     			if (read(fdesc,&strln,sizeof(int)) != sizeof(int)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno)); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 			ast_debug(1, "Cache file exists, strln=%d, strlen=%d\n", strln, (int)strlen(args.text)); | 
					
						
							|  |  |  | 			if (strlen(args.text) == strln) { | 
					
						
							|  |  |  | 				ast_debug(1, "Size OK\n"); | 
					
						
							| 
									
										
										
										
											2008-11-02 18:52:13 +00:00
										 |  |  |     				if (read(fdesc,&bigstring,strln) != strln) { | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "read() failed: %s\n", strerror(errno)); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 				bigstring[strln] = 0; | 
					
						
							|  |  |  | 				if (strcmp(bigstring, args.text) == 0) {  | 
					
						
							|  |  |  | 					readcache = 1; | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "Strings do not match\n"); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Size mismatch\n"); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (readcache == 1) { | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 		close(fd); | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 		fd = fdesc; | 
					
						
							|  |  |  | 		ast_debug(1, "Reading from cache...\n"); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 		ast_debug(1, "Passing text to festival...\n"); | 
					
						
							|  |  |  | 		fs = fdopen(dup(fd), "wb"); | 
					
						
							| 
									
										
										
										
											2008-03-18 15:43:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		fprintf(fs, "%s", festivalcommand); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 		fflush(fs); | 
					
						
							|  |  |  | 		fclose(fs); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* Write to cache and then pass it down */ | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 	if (writecache == 1) { | 
					
						
							|  |  |  | 		ast_debug(1, "Writing result to cache...\n"); | 
					
						
							|  |  |  | 		while ((strln = read(fd, buffer, 16384)) != 0) { | 
					
						
							| 
									
										
										
										
											2008-11-02 18:52:13 +00:00
										 |  |  | 			if (write(fdesc,buffer,strln) < 0) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "write() failed: %s\n", strerror(errno)); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		close(fd); | 
					
						
							|  |  |  | 		close(fdesc); | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 		fd = open(cachefile, O_RDWR); | 
					
						
							|  |  |  | 		lseek(fd, seekpos, SEEK_SET); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 	ast_debug(1, "Passing data to channel...\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	/* Read back info from server */ | 
					
						
							|  |  |  | 	/* This assumes only one waveform will come back, also LP is unlikely */ | 
					
						
							|  |  |  | 	do { | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 		int read_data; | 
					
						
							|  |  |  | 		for (n = 0; n < 3; ) { | 
					
						
							|  |  |  | 			read_data = read(fd, ack + n, 3 - n); | 
					
						
							|  |  |  | 			/* this avoids falling in infinite loop
 | 
					
						
							|  |  |  | 			 * in case that festival server goes down | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			if (read_data == -1) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Unable to read from cache/festival fd\n"); | 
					
						
							|  |  |  | 				close(fd); | 
					
						
							|  |  |  | 				ast_config_destroy(cfg); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			n += read_data; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 		ack[3] = '\0'; | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 		if (strcmp(ack, "WV\n") == 0) {         /* receive a waveform */ | 
					
						
							|  |  |  | 			ast_debug(1, "Festival WV command\n"); | 
					
						
							|  |  |  | 			if ((waveform = socket_receive_file_to_buff(fd, &filesize))) { | 
					
						
							|  |  |  | 				res = send_waveform_to_channel(chan, waveform, filesize, args.interrupt); | 
					
						
							|  |  |  | 				ast_free(waveform); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 		} else if (strcmp(ack, "LP\n") == 0) {   /* receive an s-expr */ | 
					
						
							|  |  |  | 			ast_debug(1, "Festival LP command\n"); | 
					
						
							|  |  |  | 			if ((waveform = socket_receive_file_to_buff(fd, &filesize))) { | 
					
						
							|  |  |  | 				waveform[filesize] = '\0'; | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Festival returned LP : %s\n", waveform); | 
					
						
							|  |  |  | 				ast_free(waveform); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else if (strcmp(ack, "ER\n") == 0) {    /* server got an error */ | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Festival returned ER\n"); | 
					
						
							|  |  |  | 			res = -1; | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2007-07-31 01:10:47 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} while (strcmp(ack, "OK\n") != 0); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	close(fd); | 
					
						
							| 
									
										
										
										
											2005-01-25 06:10:20 +00:00
										 |  |  | 	ast_config_destroy(cfg); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-16 13:35:20 +00:00
										 |  |  | 	return ast_unregister_application(app); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-08-16 21:09:46 +00:00
										 |  |  | 	struct ast_flags config_flags = { 0 }; | 
					
						
							|  |  |  | 	struct ast_config *cfg = ast_config_load(FESTIVAL_CONFIG, config_flags); | 
					
						
							| 
									
										
										
										
											2006-08-31 21:00:20 +00:00
										 |  |  | 	if (!cfg) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "No such configuration file %s\n", FESTIVAL_CONFIG); | 
					
						
							|  |  |  | 		return AST_MODULE_LOAD_DECLINE; | 
					
						
							| 
									
										
										
										
											2008-09-12 23:30:03 +00:00
										 |  |  | 	} else if (cfg == CONFIG_STATUS_FILEINVALID) { | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "Config file " FESTIVAL_CONFIG " is in an invalid format.  Aborting.\n"); | 
					
						
							|  |  |  | 		return AST_MODULE_LOAD_DECLINE; | 
					
						
							| 
									
										
										
										
											2006-08-31 21:00:20 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	ast_config_destroy(cfg); | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 	return ast_register_application_xml(app, festival_exec); | 
					
						
							| 
									
										
										
										
											2002-09-11 17:09:48 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Festival Interface"); |