23#include <sys/select.h>
25#include <sys/socket.h>
26#include <netinet/in.h>
34#define AUDIO_FILENO (STDERR_FILENO + 1)
36#define SPHINX_HOST "192.168.1.108"
37#define SPHINX_PORT 3460
44 struct sockaddr_in sin;
48 fprintf(stderr,
"Unable to resolve '%s'\n",
SPHINX_HOST);
53 fprintf(stderr,
"Unable to allocate socket: %s\n", strerror(
errno));
56 memset(&sin, 0,
sizeof(sin));
57 sin.sin_family = AF_INET;
59 memcpy(&sin.sin_addr, hp->h_addr,
sizeof(sin.sin_addr));
60 if (connect(
sphinx_sock, (
struct sockaddr *)&sin,
sizeof(sin))) {
61 fprintf(stderr,
"Unable to connect on socket: %s\n", strerror(
errno));
67 if ((res < 0) || (fcntl(
sphinx_sock, F_SETFL, res | O_NONBLOCK) < 0)) {
68 fprintf(stderr,
"Unable to set flags on socket: %s\n", strerror(
errno));
82 if (!fgets(
buf,
sizeof(
buf), stdin)) {
87 buf[strlen(
buf) - 1] =
'\0';
93 fprintf(stderr,
"Invalid environment: '%s'\n",
buf);
100 fprintf(stderr,
"Environment: '%s' is '%s'\n",
buf,
val);
115 static char astresp[256];
116 static char sphinxresp[256];
120 FD_SET(STDIN_FILENO, &fds);
131 fprintf(stderr,
"Error in select: %s\n", strerror(
errno));
134 if (FD_ISSET(STDIN_FILENO, &fds)) {
135 if (!fgets(astresp,
sizeof(astresp), stdin)) {
139 fprintf(stderr,
"Got hungup on apparently\n");
142 astresp[strlen(astresp) - 1] =
'\0';
143 fprintf(stderr,
"Ooh, got a response from Asterisk: '%s'\n", astresp);
150 fprintf(stderr,
"write() failed: %s\n", strerror(
errno));
155 res = read(
sphinx_sock, sphinxresp,
sizeof(sphinxresp));
157 fprintf(stderr,
"Oooh, Sphinx found a token: '%s'\n", sphinxresp);
159 }
else if (res == 0) {
160 fprintf(stderr,
"Hrm, lost sphinx, guess we're on our own\n");
171 fprintf(stdout,
"%s\n", command);
178 res =
run_command(
"STREAM FILE demo-enterkeywords 0123456789*#");
180 fprintf(stderr,
"Failed to execute command\n");
183 fprintf(stderr,
"1. Result is '%s'\n", res);
184 res =
run_command(
"STREAM FILE demo-nomatch 0123456789*#");
186 fprintf(stderr,
"Failed to execute command\n");
189 fprintf(stderr,
"2. Result is '%s'\n", res);
190 res =
run_command(
"SAY NUMBER 23452345 0123456789*#");
192 fprintf(stderr,
"Failed to execute command\n");
195 fprintf(stderr,
"3. Result is '%s'\n", res);
198 fprintf(stderr,
"Failed to execute command\n");
201 fprintf(stderr,
"4. Result is '%s'\n", res);
202 res =
run_command(
"STREAM FILE auth-thankyou \"\"");
204 fprintf(stderr,
"Failed to execute command\n");
207 fprintf(stderr,
"5. Result is '%s'\n", res);
211int main(
int argc,
char *argv[])
220 fprintf(stderr,
"Failed to read environment: %s\n", strerror(
errno));
224 tmp = getenv(
"agi_enhanced");
226 if (sscanf(
tmp,
"%30d.%30d", &ver, &subver) != 2)
230 fprintf(stderr,
"No enhanced AGI services available. Use EAGI, not AGI\n");
Asterisk main include file. File version handling, generic pbx functions.
int main(int argc, char *argv[])
static int run_script(void)
static int read_environment(void)
static int connect_sphinx(void)
static char * run_command(char *command)
static char * wait_result(void)
General Definitions for Asterisk top level program Included by asterisk.h to handle platform-specific...
int setenv(const char *name, const char *value, int overwrite)