2 * Extended AGI test application
4 * This code is released into the public domain
5 * with no warranty of any kind
10 #define AUDIO_FILENO (STDERR_FILENO + 1)
13 * Extended AGI test application
15 * This code is released into the public domain
16 * with no warranty of any kind
21 static int read_environment(void)
25 /* Read environment */
27 fgets(buf
, sizeof(buf
), stdin
);
30 buf
[strlen(buf
) - 1] = '\0';
31 /* Check for end of environment */
34 val
= strchr(buf
, ':');
36 fprintf(stderr
, "Invalid environment: '%s'\n", buf
);
43 fprintf(stderr
, "Environment: '%s' is '%s'\n", buf
, val
);
45 /* Load into normal environment */
53 static char *wait_result(void)
58 static char astresp
[256];
62 FD_SET(STDIN_FILENO
, &fds
);
63 FD_SET(AUDIO_FILENO
, &fds
);
64 /* Wait for *some* sort of I/O */
65 res
= select(AUDIO_FILENO
+ 1, &fds
, NULL
, NULL
, NULL
);
67 fprintf(stderr
, "Error in select: %s\n", strerror(errno
));
70 if (FD_ISSET(STDIN_FILENO
, &fds
)) {
71 fgets(astresp
, sizeof(astresp
), stdin
);
73 fprintf(stderr
, "Got hungup on apparently\n");
76 astresp
[strlen(astresp
) - 1] = '\0';
77 fprintf(stderr
, "Ooh, got a response from Asterisk: '%s'\n", astresp
);
80 if (FD_ISSET(AUDIO_FILENO
, &fds
)) {
81 res
= read(AUDIO_FILENO
, audiobuf
, sizeof(audiobuf
));
83 /* XXX Process the audio with sphinx here XXX */
85 fprintf(stderr
, "Got %d/%d bytes of audio\n", res
, bytes
);
88 /* Prentend we detected some audio after 3 seconds */
89 if (bytes
> 16000 * 3) {
90 return "Sample Message";
99 static char *run_command(char *command
)
101 fprintf(stdout
, "%s\n", command
);
102 return wait_result();
105 static int run_script(void)
108 res
= run_command("STREAM FILE demo-enterkeywords 0123456789*#");
110 fprintf(stderr
, "Failed to execute command\n");
113 fprintf(stderr
, "1. Result is '%s'\n", res
);
114 res
= run_command("STREAM FILE demo-nomatch 0123456789*#");
116 fprintf(stderr
, "Failed to execute command\n");
119 fprintf(stderr
, "2. Result is '%s'\n", res
);
120 res
= run_command("SAY NUMBER 23452345 0123456789*#");
122 fprintf(stderr
, "Failed to execute command\n");
125 fprintf(stderr
, "3. Result is '%s'\n", res
);
126 res
= run_command("GET DATA demo-enterkeywords");
128 fprintf(stderr
, "Failed to execute command\n");
131 fprintf(stderr
, "4. Result is '%s'\n", res
);
132 res
= run_command("STREAM FILE auth-thankyou \"\"");
134 fprintf(stderr
, "Failed to execute command\n");
137 fprintf(stderr
, "5. Result is '%s'\n", res
);
141 int main(int argc
, char *argv
[])
146 /* Setup stdin/stdout for line buffering */
149 if (read_environment()) {
150 fprintf(stderr
, "Failed to read environment: %s\n", strerror(errno
));
153 tmp
= getenv("agi_enhanced");
155 if (sscanf(tmp
, "%d.%d", &ver
, &subver
) != 2)
159 fprintf(stderr
, "No enhanced AGI services available. Use EAGI, not AGI\n");