2 * Extended AGI test application
4 * This code is released into the public domain
5 * with no warranty of any kind
13 #include <sys/select.h>
14 #include <asterisk/compat.h>
16 #define AUDIO_FILENO (STDERR_FILENO + 1)
18 static int read_environment(void)
22 /* Read environment */
24 fgets(buf, sizeof(buf), stdin);
27 buf[strlen(buf) - 1] = '\0';
28 /* Check for end of environment */
31 val = strchr(buf, ':');
33 fprintf(stderr, "Invalid environment: '%s'\n", buf);
40 fprintf(stderr, "Environment: '%s' is '%s'\n", buf, val);
42 /* Load into normal environment */
50 static char *wait_result(void)
55 static char astresp[256];
59 FD_SET(STDIN_FILENO, &fds);
60 FD_SET(AUDIO_FILENO, &fds);
61 /* Wait for *some* sort of I/O */
62 res = select(AUDIO_FILENO + 1, &fds, NULL, NULL, NULL);
64 fprintf(stderr, "Error in select: %s\n", strerror(errno));
67 if (FD_ISSET(STDIN_FILENO, &fds)) {
68 fgets(astresp, sizeof(astresp), stdin);
70 fprintf(stderr, "Got hungup on apparently\n");
73 astresp[strlen(astresp) - 1] = '\0';
74 fprintf(stderr, "Ooh, got a response from Asterisk: '%s'\n", astresp);
77 if (FD_ISSET(AUDIO_FILENO, &fds)) {
78 res = read(AUDIO_FILENO, audiobuf, sizeof(audiobuf));
80 /* XXX Process the audio with sphinx here XXX */
82 fprintf(stderr, "Got %d/%d bytes of audio\n", res, bytes);
85 /* Prentend we detected some audio after 3 seconds */
86 if (bytes > 16000 * 3) {
87 return "Sample Message";
96 static char *run_command(char *command)
98 fprintf(stdout, "%s\n", command);
102 static int run_script(void)
105 res = run_command("STREAM FILE demo-enterkeywords 0123456789*#");
107 fprintf(stderr, "Failed to execute command\n");
110 fprintf(stderr, "1. Result is '%s'\n", res);
111 res = run_command("STREAM FILE demo-nomatch 0123456789*#");
113 fprintf(stderr, "Failed to execute command\n");
116 fprintf(stderr, "2. Result is '%s'\n", res);
117 res = run_command("SAY NUMBER 23452345 0123456789*#");
119 fprintf(stderr, "Failed to execute command\n");
122 fprintf(stderr, "3. Result is '%s'\n", res);
123 res = run_command("GET DATA demo-enterkeywords");
125 fprintf(stderr, "Failed to execute command\n");
128 fprintf(stderr, "4. Result is '%s'\n", res);
129 res = run_command("STREAM FILE auth-thankyou \"\"");
131 fprintf(stderr, "Failed to execute command\n");
134 fprintf(stderr, "5. Result is '%s'\n", res);
138 int main(int argc, char *argv[])
143 /* Setup stdin/stdout for line buffering */
146 if (read_environment()) {
147 fprintf(stderr, "Failed to read environment: %s\n", strerror(errno));
150 tmp = getenv("agi_enhanced");
152 if (sscanf(tmp, "%d.%d", &ver, &subver) != 2)
156 fprintf(stderr, "No enhanced AGI services available. Use EAGI, not AGI\n");