AGI formatting fixes (bug #3270)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4715 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2005-01-08 19:35:20 +00:00
parent 96d17b07a5
commit 2d8160ecd5

View File

@@ -112,6 +112,8 @@ static void agi_debug_cli(int fd, char *fmt, ...)
}
}
/* launch_netscript: The fastagi handler.
FastAGI defaults to port 4573 */
static int launch_netscript(char *agiurl, char *argv[], int *fds, int *efd, int *opid)
{
int s;
@@ -123,8 +125,8 @@ static int launch_netscript(char *agiurl, char *argv[], int *fds, int *efd, int
struct sockaddr_in sin;
struct hostent *hp;
struct ast_hostent ahp;
ast_log(LOG_DEBUG, "Blah\n");
host = ast_strdupa(agiurl + 6);
host = ast_strdupa(agiurl + 6); /* Remove agi:// */
if (!host)
return -1;
/* Strip off any script name */
@@ -184,6 +186,12 @@ static int launch_netscript(char *agiurl, char *argv[], int *fds, int *efd, int
close(s);
return -1;
}
/* If we have a script parameter, relay it to the fastagi server */
if (!ast_strlen_zero(script))
fdprintf(s, "agi_network_script: %s\n", script);
if (option_debug > 3)
ast_log(LOG_DEBUG, "Wow, connected!\n");
fds[0] = s;
fds[1] = s;
@@ -390,9 +398,14 @@ static int handle_tddmode(struct ast_channel *chan, AGI *agi, int argc, char *ar
int res,x;
if (argc != 3)
return RESULT_SHOWUSAGE;
if (!strncasecmp(argv[2],"on",2)) x = 1; else x = 0;
if (!strncasecmp(argv[2],"mate",4)) x = 2;
if (!strncasecmp(argv[2],"tdd",3)) x = 1;
if (!strncasecmp(argv[2],"on",2))
x = 1;
else
x = 0;
if (!strncasecmp(argv[2],"mate",4))
x = 2;
if (!strncasecmp(argv[2],"tdd",3))
x = 1;
res = ast_channel_setoption(chan, AST_OPTION_TDD, &x, sizeof(char), 0);
fdprintf(agi->fd, "200 result=%d\n", res);
if (res >= 0)
@@ -637,8 +650,14 @@ static int handle_getdata(struct ast_channel *chan, AGI *agi, int argc, char *ar
if (argc < 3)
return RESULT_SHOWUSAGE;
if (argc >= 4) timeout = atoi(argv[3]); else timeout = 0;
if (argc >= 5) max = atoi(argv[4]); else max = 1024;
if (argc >= 4)
timeout = atoi(argv[3]);
else
timeout = 0;
if (argc >= 5)
max = atoi(argv[4]);
else
max = 1024;
res = ast_app_getdata_full(chan, argv[2], data, max, timeout, agi->audio, agi->ctrl);
if (res == 2) /* New command */
return RESULT_SUCCESS;
@@ -928,6 +947,7 @@ static int handle_setcallerid(struct ast_channel *chan, AGI *agi, int argc, char
{
char tmp[256]="";
char *l = NULL, *n = NULL;
if (argv[2]) {
strncpy(tmp, argv[2], sizeof(tmp) - 1);
ast_callerid_parse(tmp, &n, &l);
@@ -984,6 +1004,7 @@ static int handle_getvariable(struct ast_channel *chan, AGI *agi, int argc, char
{
char *ret;
char tempstr[1024];
if (argc != 3)
return RESULT_SHOWUSAGE;
pbx_retrieve_variable(chan, argv[2], &ret, tempstr, sizeof(tempstr), NULL);
@@ -999,6 +1020,7 @@ static int handle_getvariablefull(struct ast_channel *chan, AGI *agi, int argc,
{
char tmp[4096];
struct ast_channel *chan2=NULL;
if ((argc != 4) && (argc != 5))
return RESULT_SHOWUSAGE;
if (argc == 5) {
@@ -1060,6 +1082,7 @@ static int handle_dbget(struct ast_channel *chan, AGI *agi, int argc, char **arg
{
int res;
char tmp[256];
if (argc != 4)
return RESULT_SHOWUSAGE;
res = ast_db_get(argv[2], argv[3], tmp, sizeof(tmp));
@@ -1074,6 +1097,7 @@ static int handle_dbget(struct ast_channel *chan, AGI *agi, int argc, char **arg
static int handle_dbput(struct ast_channel *chan, AGI *agi, int argc, char **argv)
{
int res;
if (argc != 5)
return RESULT_SHOWUSAGE;
res = ast_db_put(argv[2], argv[3], argv[4]);
@@ -1088,6 +1112,7 @@ static int handle_dbput(struct ast_channel *chan, AGI *agi, int argc, char **arg
static int handle_dbdel(struct ast_channel *chan, AGI *agi, int argc, char **argv)
{
int res;
if (argc != 4)
return RESULT_SHOWUSAGE;
res = ast_db_del(argv[2], argv[3]);
@@ -1419,6 +1444,7 @@ static agi_command commands[MAX_COMMANDS] = {
static void join(char *s, size_t len, char *w[])
{
int x;
/* Join words into a string */
if (!s) {
return;
@@ -1491,8 +1517,10 @@ static agi_command *find_command(char *cmds[], int exact)
int x;
int y;
int match;
for (x=0; x < sizeof(commands) / sizeof(commands[0]); x++) {
if (!commands[x].cmda[0]) break;
if (!commands[x].cmda[0])
break;
/* start optimistic */
match = 1;
for (y=0; match && cmds[y]; y++) {
@@ -1502,7 +1530,8 @@ static agi_command *find_command(char *cmds[], int exact)
if (!commands[x].cmda[y] && !exact)
break;
/* don't segfault if the next part of a command doesn't exist */
if (!commands[x].cmda[y]) return NULL;
if (!commands[x].cmda[y])
return NULL;
if (strcasecmp(commands[x].cmda[y], cmds[y]))
match = 0;
}
@@ -1590,6 +1619,7 @@ static int agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf)
int res;
agi_command *c;
argc = MAX_ARGS;
parse_args(buf, &argc, argv);
#if 0
{ int x;
@@ -1790,6 +1820,7 @@ static int agi_exec_full(struct ast_channel *chan, void *data, int enhanced, int
int pid;
char *stringp;
AGI agi;
if (!data || ast_strlen_zero(data)) {
ast_log(LOG_WARNING, "AGI requires an argument (script)\n");
return -1;
@@ -1837,6 +1868,7 @@ static int eagi_exec(struct ast_channel *chan, void *data)
{
int readformat;
int res;
if (chan->_softhangup)
ast_log(LOG_WARNING, "If you want to run AGI on hungup channels you should use DeadAGI!\n");
readformat = chan->readformat;