Code cleanup of res_agi

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@74713 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Joshua Colp
2007-07-11 21:09:42 +00:00
parent 21e30f9d7d
commit 48f166e87b

View File

@@ -126,30 +126,28 @@ static void agi_debug_cli(int fd, char *fmt, ...)
va_start(ap, fmt); va_start(ap, fmt);
res = vasprintf(&stuff, fmt, ap); res = vasprintf(&stuff, fmt, ap);
va_end(ap); va_end(ap);
if (res == -1) { if (res == -1) {
ast_log(LOG_ERROR, "Out of memory\n"); ast_log(LOG_ERROR, "Out of memory\n");
} else { return;
if (agidebug)
ast_verbose("AGI Tx >> %s\n", stuff);
ast_carefulwrite(fd, stuff, strlen(stuff), 100);
ast_free(stuff);
} }
if (agidebug)
ast_verbose("AGI Tx >> %s\n", stuff);
ast_carefulwrite(fd, stuff, strlen(stuff), 100);
ast_free(stuff);
} }
/* launch_netscript: The fastagi handler. /* launch_netscript: The fastagi handler.
FastAGI defaults to port 4573 */ FastAGI defaults to port 4573 */
static enum agi_result launch_netscript(char *agiurl, char *argv[], int *fds, int *efd, int *opid) static enum agi_result launch_netscript(char *agiurl, char *argv[], int *fds, int *efd, int *opid)
{ {
int s; int s, flags, res, port = AGI_PORT;
int flags;
struct pollfd pfds[1]; struct pollfd pfds[1];
char *host; char *host, *c, *script = "";
char *c; int port = AGI_PORT;
char *script="";
struct sockaddr_in sin; struct sockaddr_in sin;
struct hostent *hp; struct hostent *hp;
struct ast_hostent ahp; struct ast_hostent ahp;
int res;
/* agiusl is "agi://host.domain[:port][/script/name]" */ /* agiusl is "agi://host.domain[:port][/script/name]" */
host = ast_strdupa(agiurl + 6); /* Remove agi:// */ host = ast_strdupa(agiurl + 6); /* Remove agi:// */
@@ -168,18 +166,15 @@ static enum agi_result launch_netscript(char *agiurl, char *argv[], int *fds, in
ast_log(LOG_WARNING, "AGI URI's don't support Enhanced AGI yet\n"); ast_log(LOG_WARNING, "AGI URI's don't support Enhanced AGI yet\n");
return -1; return -1;
} }
hp = ast_gethostbyname(host, &ahp); if (!(hp = ast_gethostbyname(host, &ahp))) {
if (!hp) {
ast_log(LOG_WARNING, "Unable to locate host '%s'\n", host); ast_log(LOG_WARNING, "Unable to locate host '%s'\n", host);
return -1; return -1;
} }
s = socket(AF_INET, SOCK_STREAM, 0); if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
if (s < 0) {
ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno)); ast_log(LOG_WARNING, "Unable to create socket: %s\n", strerror(errno));
return -1; return -1;
} }
flags = fcntl(s, F_GETFL); if ((flags = fcntl(s, F_GETFL)) < 0) {
if (flags < 0) {
ast_log(LOG_WARNING, "Fcntl(F_GETFL) failed: %s\n", strerror(errno)); ast_log(LOG_WARNING, "Fcntl(F_GETFL) failed: %s\n", strerror(errno));
close(s); close(s);
return -1; return -1;
@@ -236,12 +231,7 @@ static enum agi_result launch_netscript(char *agiurl, char *argv[], int *fds, in
static enum agi_result launch_script(char *script, char *argv[], int *fds, int *efd, int *opid) static enum agi_result launch_script(char *script, char *argv[], int *fds, int *efd, int *opid)
{ {
char tmp[256]; char tmp[256];
int pid; int pid, toast[2], fromast[2], audio[2], x, res;
int toast[2];
int fromast[2];
int audio[2];
int x;
int res;
sigset_t signal_set, old_set; sigset_t signal_set, old_set;
struct stat st; struct stat st;
@@ -296,8 +286,7 @@ static enum agi_result launch_script(char *script, char *argv[], int *fds, int *
/* Block SIGHUP during the fork - prevents a race */ /* Block SIGHUP during the fork - prevents a race */
sigfillset(&signal_set); sigfillset(&signal_set);
pthread_sigmask(SIG_BLOCK, &signal_set, &old_set); pthread_sigmask(SIG_BLOCK, &signal_set, &old_set);
pid = fork(); if ((pid = fork()) < 0) {
if (pid < 0) {
ast_log(LOG_WARNING, "Failed to fork(): %s\n", strerror(errno)); ast_log(LOG_WARNING, "Failed to fork(): %s\n", strerror(errno));
pthread_sigmask(SIG_SETMASK, &old_set, NULL); pthread_sigmask(SIG_SETMASK, &old_set, NULL);
return AGI_RESULT_FAILURE; return AGI_RESULT_FAILURE;
@@ -322,11 +311,10 @@ static enum agi_result launch_script(char *script, char *argv[], int *fds, int *
/* Redirect stdin and out, provide enhanced audio channel if desired */ /* Redirect stdin and out, provide enhanced audio channel if desired */
dup2(fromast[0], STDIN_FILENO); dup2(fromast[0], STDIN_FILENO);
dup2(toast[1], STDOUT_FILENO); dup2(toast[1], STDOUT_FILENO);
if (efd) { if (efd)
dup2(audio[0], STDERR_FILENO + 1); dup2(audio[0], STDERR_FILENO + 1);
} else { else
close(STDERR_FILENO + 1); close(STDERR_FILENO + 1);
}
/* Before we unblock our signals, return our trapped signals back to the defaults */ /* Before we unblock our signals, return our trapped signals back to the defaults */
signal(SIGHUP, SIG_DFL); signal(SIGHUP, SIG_DFL);
@@ -344,7 +332,7 @@ static enum agi_result launch_script(char *script, char *argv[], int *fds, int *
} }
/* Close everything but stdin/out/error */ /* Close everything but stdin/out/error */
for (x=STDERR_FILENO + 2;x<1024;x++) for (x = STDERR_FILENO + 2; x < 1024; x++)
close(x); close(x);
/* Execute script */ /* Execute script */
@@ -360,9 +348,8 @@ static enum agi_result launch_script(char *script, char *argv[], int *fds, int *
ast_verbose(VERBOSE_PREFIX_3 "Launched AGI Script %s\n", script); ast_verbose(VERBOSE_PREFIX_3 "Launched AGI Script %s\n", script);
fds[0] = toast[0]; fds[0] = toast[0];
fds[1] = fromast[1]; fds[1] = fromast[1];
if (efd) { if (efd)
*efd = audio[1]; *efd = audio[1];
}
/* close what we're not using in the parent */ /* close what we're not using in the parent */
close(toast[1]); close(toast[1]);
close(fromast[0]); close(fromast[0]);
@@ -416,20 +403,20 @@ static void setup_env(struct ast_channel *chan, char *request, int fd, int enhan
static int handle_answer(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) static int handle_answer(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{ {
int res; int res = 0;
res = 0;
if (chan->_state != AST_STATE_UP) { /* Answer the channel */
/* Answer the chan */ if (chan->_state != AST_STATE_UP)
res = ast_answer(chan); res = ast_answer(chan);
}
fdprintf(agi->fd, "200 result=%d\n", res); fdprintf(agi->fd, "200 result=%d\n", res);
return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE; return (res >= 0) ? RESULT_SUCCESS : RESULT_FAILURE;
} }
static int handle_waitfordigit(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) static int handle_waitfordigit(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{ {
int res; int res, to;
int to;
if (argc != 4) if (argc != 4)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
if (sscanf(argv[3], "%d", &to) != 1) if (sscanf(argv[3], "%d", &to) != 1)
@@ -442,8 +429,10 @@ static int handle_waitfordigit(struct ast_channel *chan, AGI *agi, int argc, cha
static int handle_sendtext(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) static int handle_sendtext(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{ {
int res; int res;
if (argc != 3) if (argc != 3)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
/* At the moment, the parser (perhaps broken) returns with /* At the moment, the parser (perhaps broken) returns with
the last argument PLUS the newline at the end of the input the last argument PLUS the newline at the end of the input
buffer. This probably needs to be fixed, but I wont do that buffer. This probably needs to be fixed, but I wont do that
@@ -459,8 +448,10 @@ static int handle_sendtext(struct ast_channel *chan, AGI *agi, int argc, char *a
static int handle_recvchar(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) static int handle_recvchar(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{ {
int res; int res;
if (argc != 3) if (argc != 3)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
res = ast_recvchar(chan,atoi(argv[2])); res = ast_recvchar(chan,atoi(argv[2]));
if (res == 0) { if (res == 0) {
fdprintf(agi->fd, "200 result=%d (timeout)\n", res); fdprintf(agi->fd, "200 result=%d (timeout)\n", res);
@@ -482,6 +473,7 @@ static int handle_recvtext(struct ast_channel *chan, AGI *agi, int argc, char *a
if (argc != 3) if (argc != 3)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
buf = ast_recvtext(chan,atoi(argv[2])); buf = ast_recvtext(chan,atoi(argv[2]));
if (buf) { if (buf) {
fdprintf(agi->fd, "200 result=1 (%s)\n", buf); fdprintf(agi->fd, "200 result=1 (%s)\n", buf);
@@ -494,9 +486,11 @@ static int handle_recvtext(struct ast_channel *chan, AGI *agi, int argc, char *a
static int handle_tddmode(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) static int handle_tddmode(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{ {
int res,x; int res, x;
if (argc != 3) if (argc != 3)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
if (!strncasecmp(argv[2],"on",2)) if (!strncasecmp(argv[2],"on",2))
x = 1; x = 1;
else else
@@ -516,8 +510,10 @@ static int handle_tddmode(struct ast_channel *chan, AGI *agi, int argc, char *ar
static int handle_sendimage(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) static int handle_sendimage(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{ {
int res; int res;
if (argc != 3) if (argc != 3)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
res = ast_send_image(chan, argv[2]); res = ast_send_image(chan, argv[2]);
if (!ast_check_hangup(chan)) if (!ast_check_hangup(chan))
res = 0; res = 0;
@@ -527,12 +523,8 @@ static int handle_sendimage(struct ast_channel *chan, AGI *agi, int argc, char *
static int handle_controlstreamfile(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) static int handle_controlstreamfile(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{ {
int res = 0; int res = 0, skipms = 3000;
int skipms = 3000; char *fwd = NULL, *rev = NULL, *pause = NULL, *stop = NULL;
char *fwd = NULL;
char *rev = NULL;
char *pause = NULL;
char *stop = NULL;
if (argc < 5 || argc > 9) if (argc < 5 || argc > 9)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
@@ -569,12 +561,9 @@ static int handle_controlstreamfile(struct ast_channel *chan, AGI *agi, int argc
static int handle_streamfile(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) static int handle_streamfile(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{ {
int res; int res, vres;
int vres; struct ast_filestream *fs, *vfs;
struct ast_filestream *fs; long sample_offset = 0, max_length;
struct ast_filestream *vfs;
long sample_offset = 0;
long max_length;
char *edigits = ""; char *edigits = "";
if (argc < 4 || argc > 5) if (argc < 4 || argc > 5)
@@ -585,10 +574,8 @@ static int handle_streamfile(struct ast_channel *chan, AGI *agi, int argc, char
if ((argc > 4) && (sscanf(argv[4], "%ld", &sample_offset) != 1)) if ((argc > 4) && (sscanf(argv[4], "%ld", &sample_offset) != 1))
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
fs = ast_openstream(chan, argv[2], chan->language); if (!(fs = ast_openstream(chan, argv[2], chan->language))) {
if (!fs) {
fdprintf(agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset); fdprintf(agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset);
return RESULT_SUCCESS; return RESULT_SUCCESS;
} }
@@ -624,12 +611,9 @@ static int handle_streamfile(struct ast_channel *chan, AGI *agi, int argc, char
/* get option - really similar to the handle_streamfile, but with a timeout */ /* get option - really similar to the handle_streamfile, but with a timeout */
static int handle_getoption(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) static int handle_getoption(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{ {
int res; int res, vres;
int vres; struct ast_filestream *fs, *vfs;
struct ast_filestream *fs; long sample_offset = 0, max_length;
struct ast_filestream *vfs;
long sample_offset = 0;
long max_length;
int timeout = 0; int timeout = 0;
char *edigits = ""; char *edigits = "";
@@ -646,8 +630,7 @@ static int handle_getoption(struct ast_channel *chan, AGI *agi, int argc, char *
timeout = chan->pbx->dtimeout * 1000; /* in msec */ timeout = chan->pbx->dtimeout * 1000; /* in msec */
} }
fs = ast_openstream(chan, argv[2], chan->language); if (!(fs = ast_openstream(chan, argv[2], chan->language))) {
if (!fs) {
fdprintf(agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset); fdprintf(agi->fd, "200 result=%d endpos=%ld\n", 0, sample_offset);
ast_log(LOG_WARNING, "Unable to open %s\n", argv[2]); ast_log(LOG_WARNING, "Unable to open %s\n", argv[2]);
return RESULT_SUCCESS; return RESULT_SUCCESS;
@@ -697,8 +680,8 @@ static int handle_getoption(struct ast_channel *chan, AGI *agi, int argc, char *
/* While waiting, we're sending a NULL. */ /* While waiting, we're sending a NULL. */
static int handle_saynumber(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) static int handle_saynumber(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{ {
int res; int res, num;
int num;
if (argc < 4 || argc > 5) if (argc < 4 || argc > 5)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
if (sscanf(argv[2], "%d", &num) != 1) if (sscanf(argv[2], "%d", &num) != 1)
@@ -712,8 +695,7 @@ static int handle_saynumber(struct ast_channel *chan, AGI *agi, int argc, char *
static int handle_saydigits(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) static int handle_saydigits(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{ {
int res; int res, num;
int num;
if (argc != 4) if (argc != 4)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
@@ -743,8 +725,8 @@ static int handle_sayalpha(struct ast_channel *chan, AGI *agi, int argc, char *a
static int handle_saydate(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) static int handle_saydate(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{ {
int res; int res, num;
int num;
if (argc != 4) if (argc != 4)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
if (sscanf(argv[2], "%d", &num) != 1) if (sscanf(argv[2], "%d", &num) != 1)
@@ -758,8 +740,8 @@ static int handle_saydate(struct ast_channel *chan, AGI *agi, int argc, char *ar
static int handle_saytime(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) static int handle_saytime(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{ {
int res; int res, num;
int num;
if (argc != 4) if (argc != 4)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
if (sscanf(argv[2], "%d", &num) != 1) if (sscanf(argv[2], "%d", &num) != 1)
@@ -773,9 +755,9 @@ static int handle_saytime(struct ast_channel *chan, AGI *agi, int argc, char *ar
static int handle_saydatetime(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) static int handle_saydatetime(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{ {
int res=0; int res = 0;
time_t unixtime; time_t unixtime;
char *format, *zone=NULL; char *format, *zone = NULL;
if (argc < 4) if (argc < 4)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
@@ -821,10 +803,8 @@ static int handle_sayphonetic(struct ast_channel *chan, AGI *agi, int argc, char
static int handle_getdata(struct ast_channel *chan, AGI *agi, int argc, char *argv[]) static int handle_getdata(struct ast_channel *chan, AGI *agi, int argc, char *argv[])
{ {
int res; int res, max, timeout;
char data[1024]; char data[1024];
int max;
int timeout;
if (argc < 3) if (argc < 3)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
@@ -870,6 +850,7 @@ static int handle_setextension(struct ast_channel *chan, AGI *agi, int argc, cha
static int handle_setpriority(struct ast_channel *chan, AGI *agi, int argc, char **argv) static int handle_setpriority(struct ast_channel *chan, AGI *agi, int argc, char **argv)
{ {
int pri; int pri;
if (argc != 3) if (argc != 3)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
@@ -1081,6 +1062,7 @@ static int handle_autohangup(struct ast_channel *chan, AGI *agi, int argc, char
static int handle_hangup(struct ast_channel *chan, AGI *agi, int argc, char **argv) static int handle_hangup(struct ast_channel *chan, AGI *agi, int argc, char **argv)
{ {
struct ast_channel *c; struct ast_channel *c;
if (argc == 1) { if (argc == 1) {
/* no argument: hangup the current channel */ /* no argument: hangup the current channel */
ast_softhangup(chan,AST_SOFTHANGUP_EXPLICIT); ast_softhangup(chan,AST_SOFTHANGUP_EXPLICIT);
@@ -1115,9 +1097,7 @@ static int handle_exec(struct ast_channel *chan, AGI *agi, int argc, char **argv
if (option_verbose > 2) if (option_verbose > 2)
ast_verbose(VERBOSE_PREFIX_3 "AGI Script Executing Application: (%s) Options: (%s)\n", argv[1], argv[2]); ast_verbose(VERBOSE_PREFIX_3 "AGI Script Executing Application: (%s) Options: (%s)\n", argv[1], argv[2]);
app = pbx_findapp(argv[1]); if ((app = pbx_findapp(argv[1]))) {
if (app) {
res = pbx_exec(chan, app, argv[2]); res = pbx_exec(chan, app, argv[2]);
} else { } else {
ast_log(LOG_WARNING, "Could not find application (%s)\n", argv[1]); ast_log(LOG_WARNING, "Could not find application (%s)\n", argv[1]);
@@ -1303,6 +1283,7 @@ static int handle_dbdel(struct ast_channel *chan, AGI *agi, int argc, char **arg
static int handle_dbdeltree(struct ast_channel *chan, AGI *agi, int argc, char **argv) static int handle_dbdeltree(struct ast_channel *chan, AGI *agi, int argc, char **argv)
{ {
int res; int res;
if ((argc < 3) || (argc > 4)) if ((argc < 3) || (argc > 4))
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
if (argc == 4) if (argc == 4)
@@ -1652,13 +1633,14 @@ static agi_command commands[MAX_COMMANDS] = {
static int help_workhorse(int fd, char *match[]) static int help_workhorse(int fd, char *match[])
{ {
char fullcmd[80]; char fullcmd[80], matchstr[80];
char matchstr[80];
int x; int x;
struct agi_command *e; struct agi_command *e;
if (match) if (match)
ast_join(matchstr, sizeof(matchstr), match); ast_join(matchstr, sizeof(matchstr), match);
for (x=0;x<sizeof(commands)/sizeof(commands[0]);x++) {
for (x = 0; x < sizeof(commands) / sizeof(commands[0]); x++) {
e = &commands[x]; e = &commands[x];
if (!e->cmda[0]) if (!e->cmda[0])
break; break;
@@ -1676,13 +1658,14 @@ static int help_workhorse(int fd, char *match[])
int ast_agi_register(agi_command *agi) int ast_agi_register(agi_command *agi)
{ {
int x; int x;
for (x=0; x<MAX_COMMANDS - 1; x++) {
for (x = 0; x < MAX_COMMANDS - 1; x++) {
if (commands[x].cmda[0] == agi->cmda[0]) { if (commands[x].cmda[0] == agi->cmda[0]) {
ast_log(LOG_WARNING, "Command already registered!\n"); ast_log(LOG_WARNING, "Command already registered!\n");
return -1; return -1;
} }
} }
for (x=0; x<MAX_COMMANDS - 1; x++) { for (x = 0; x < MAX_COMMANDS - 1; x++) {
if (!commands[x].cmda[0]) { if (!commands[x].cmda[0]) {
commands[x] = *agi; commands[x] = *agi;
return 0; return 0;
@@ -1695,7 +1678,7 @@ int ast_agi_register(agi_command *agi)
void ast_agi_unregister(agi_command *agi) void ast_agi_unregister(agi_command *agi)
{ {
int x; int x;
for (x=0; x<MAX_COMMANDS - 1; x++) { for (x = 0; x < MAX_COMMANDS - 1; x++) {
if (commands[x].cmda[0] == agi->cmda[0]) { if (commands[x].cmda[0] == agi->cmda[0]) {
memset(&commands[x], 0, sizeof(agi_command)); memset(&commands[x], 0, sizeof(agi_command));
} }
@@ -1704,16 +1687,14 @@ void ast_agi_unregister(agi_command *agi)
static agi_command *find_command(char *cmds[], int exact) static agi_command *find_command(char *cmds[], int exact)
{ {
int x; int x, y, match;
int y;
int match;
for (x=0; x < sizeof(commands) / sizeof(commands[0]); x++) { for (x = 0; x < sizeof(commands) / sizeof(commands[0]); x++) {
if (!commands[x].cmda[0]) if (!commands[x].cmda[0])
break; break;
/* start optimistic */ /* start optimistic */
match = 1; match = 1;
for (y=0; match && cmds[y]; y++) { for (y = 0; match && cmds[y]; y++) {
/* If there are no more words in the command (and we're looking for /* If there are no more words in the command (and we're looking for
an exact match) or there is a difference between the two words, an exact match) or there is a difference between the two words,
then this is not a match */ then this is not a match */
@@ -1738,10 +1719,7 @@ static agi_command *find_command(char *cmds[], int exact)
static int parse_args(char *s, int *max, char *argv[]) static int parse_args(char *s, int *max, char *argv[])
{ {
int x=0; int x = 0, quoted = 0, escaped = 0, whitespace = 1;
int quoted=0;
int escaped=0;
int whitespace=1;
char *cur; char *cur;
cur = s; cur = s;
@@ -1805,13 +1783,11 @@ normal:
static int agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf) static int agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf)
{ {
char *argv[MAX_ARGS]; char *argv[MAX_ARGS];
int argc = MAX_ARGS; int argc = MAX_ARGS, res;
int res;
agi_command *c; agi_command *c;
parse_args(buf, &argc, argv); parse_args(buf, &argc, argv);
c = find_command(argv, 0); if ((c = find_command(argv, 0))) {
if (c) {
res = c->handler(chan, agi, argc, argv); res = c->handler(chan, agi, argc, argv);
switch(res) { switch(res) {
case RESULT_SHOWUSAGE: case RESULT_SHOWUSAGE:
@@ -1837,8 +1813,7 @@ static int agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf)
static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid, int *status, int dead, int argc, char *argv[]) static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid, int *status, int dead, int argc, char *argv[])
{ {
struct ast_channel *c; struct ast_channel *c;
int outfd; int outfd, ms;
int ms;
enum agi_result returnstatus = AGI_RESULT_SUCCESS; enum agi_result returnstatus = AGI_RESULT_SUCCESS;
struct ast_frame *f; struct ast_frame *f;
char buf[2048]; char buf[2048];
@@ -1923,8 +1898,10 @@ static int handle_showagi(int fd, int argc, char *argv[])
{ {
struct agi_command *e; struct agi_command *e;
char fullcmd[80]; char fullcmd[80];
if ((argc < 2)) if ((argc < 2))
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
if (argc > 2) { if (argc > 2) {
e = find_command(argv + 2, 1); e = find_command(argv + 2, 1);
if (e) if (e)
@@ -1995,7 +1972,7 @@ static int handle_agidumphtml(int fd, int argc, char *argv[])
fprintf(htmlfile, "<TABLE BORDER=\"0\" CELLSPACING=\"10\">\n"); fprintf(htmlfile, "<TABLE BORDER=\"0\" CELLSPACING=\"10\">\n");
for (x=0;x<sizeof(commands)/sizeof(commands[0]);x++) { for (x = 0; x < sizeof(commands) / sizeof(commands[0]); x++) {
char *stringp, *tempstr; char *stringp, *tempstr;
e = &commands[x]; e = &commands[x];
@@ -2037,14 +2014,8 @@ static int agi_exec_full(struct ast_channel *chan, void *data, int enhanced, int
{ {
enum agi_result res; enum agi_result res;
struct ast_module_user *u; struct ast_module_user *u;
char *argv[MAX_ARGS]; char *argv[MAX_ARGS], buf[2048] = "", *tmp = buf, *stringp;
char buf[2048]=""; int argc = 0, fds[2], efd = -1, pid;
char *tmp = buf;
int argc = 0;
int fds[2];
int efd = -1;
int pid;
char *stringp;
AGI agi; AGI agi;
if (ast_strlen_zero(data)) { if (ast_strlen_zero(data)) {
@@ -2113,8 +2084,7 @@ static int agi_exec(struct ast_channel *chan, void *data)
static int eagi_exec(struct ast_channel *chan, void *data) static int eagi_exec(struct ast_channel *chan, void *data)
{ {
int readformat; int readformat, res;
int res;
if (chan->_softhangup) if (chan->_softhangup)
ast_log(LOG_WARNING, "If you want to run AGI on hungup channels you should use DeadAGI!\n"); ast_log(LOG_WARNING, "If you want to run AGI on hungup channels you should use DeadAGI!\n");