diff --git a/res/res_agi.c b/res/res_agi.c index 5cbc138f0..88c259c01 100755 --- a/res/res_agi.c +++ b/res/res_agi.c @@ -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,7 +186,13 @@ static int launch_netscript(char *agiurl, char *argv[], int *fds, int *efd, int close(s); return -1; } - ast_log(LOG_DEBUG, "Wow, connected!\n"); + + /* 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; *opid = -1; @@ -307,8 +315,8 @@ static void setup_env(struct ast_channel *chan, char *request, int fd, int enhan fdprintf(fd, "agi_priority: %d\n", chan->priority); fdprintf(fd, "agi_enhanced: %s\n", enhanced ? "1.0" : "0.0"); - /* User information */ - fdprintf(fd, "agi_accountcode: %s\n", chan->accountcode ? chan->accountcode : ""); + /* User information */ + fdprintf(fd, "agi_accountcode: %s\n", chan->accountcode ? chan->accountcode : ""); /* End with empty return */ fdprintf(fd, "\n"); @@ -390,10 +398,15 @@ 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; - res = ast_channel_setoption(chan,AST_OPTION_TDD,&x,sizeof(char),0); + 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) return RESULT_SUCCESS; @@ -450,7 +463,7 @@ static int handle_streamfile(struct ast_channel *chan, AGI *agi, int argc, char res = ast_waitstream_full(chan, argv[3], agi->audio, agi->ctrl); /* this is to check for if ast_waitstream closed the stream, we probably are at * the end of the stream, return that amount, else check for the amount */ - sample_offset = (chan->stream)?ast_tellstream(fs):max_length; + sample_offset = (chan->stream) ? ast_tellstream(fs) : max_length; ast_stopstream(chan); if (res == 1) { /* Stop this command, don't print a result line, as there is a new command */ @@ -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; @@ -831,7 +850,7 @@ static int handle_recordfile(struct ast_channel *chan, AGI *agi, int argc, char gettimeofday(&tv, NULL); if (gotsilence) break; - } + } if (gotsilence) { ast_stream_rewind(fs, silence-1000); @@ -872,32 +891,32 @@ 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) { - struct ast_channel *c; - if (argc==1) { - /* no argument: hangup the current channel */ - ast_softhangup(chan,AST_SOFTHANGUP_EXPLICIT); - fdprintf(agi->fd, "200 result=1\n"); - return RESULT_SUCCESS; - } else if (argc==2) { - /* one argument: look for info on the specified channel */ - c = ast_channel_walk_locked(NULL); - while (c) { - if (strcasecmp(argv[1],c->name)==0) { - /* we have a matching channel */ - ast_softhangup(c,AST_SOFTHANGUP_EXPLICIT); - fdprintf(agi->fd, "200 result=1\n"); - ast_mutex_unlock(&c->lock); - return RESULT_SUCCESS; - } + struct ast_channel *c; + if (argc == 1) { + /* no argument: hangup the current channel */ + ast_softhangup(chan,AST_SOFTHANGUP_EXPLICIT); + fdprintf(agi->fd, "200 result=1\n"); + return RESULT_SUCCESS; + } else if (argc == 2) { + /* one argument: look for info on the specified channel */ + c = ast_channel_walk_locked(NULL); + while (c) { + if (strcasecmp(argv[1], c->name) == 0) { + /* we have a matching channel */ + ast_softhangup(c,AST_SOFTHANGUP_EXPLICIT); + fdprintf(agi->fd, "200 result=1\n"); ast_mutex_unlock(&c->lock); - c = ast_channel_walk_locked(c); - } - /* if we get this far no channel name matched the argument given */ - fdprintf(agi->fd, "200 result=-1\n"); - return RESULT_SUCCESS; - } else { - return RESULT_SHOWUSAGE; - } + return RESULT_SUCCESS; + } + ast_mutex_unlock(&c->lock); + c = ast_channel_walk_locked(c); + } + /* if we get this far no channel name matched the argument given */ + fdprintf(agi->fd, "200 result=-1\n"); + return RESULT_SUCCESS; + } else { + return RESULT_SHOWUSAGE; + } } static int handle_exec(struct ast_channel *chan, AGI *agi, int argc, char **argv) @@ -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); @@ -947,11 +967,11 @@ static int handle_setcallerid(struct ast_channel *chan, AGI *agi, int argc, char static int handle_channelstatus(struct ast_channel *chan, AGI *agi, int argc, char **argv) { struct ast_channel *c; - if (argc==2) { + if (argc == 2) { /* no argument: supply info on the current channel */ fdprintf(agi->fd, "200 result=%d\n", chan->_state); return RESULT_SUCCESS; - } else if (argc==3) { + } else if (argc == 3) { /* one argument: look for info on the specified channel */ c = ast_channel_walk_locked(NULL); while (c) { @@ -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]); @@ -1265,7 +1290,7 @@ static char usage_waitfordigit[] = static char usage_sendtext[] = " Usage: SEND TEXT \"\"\n" -" Sends the given text on a channel. Most channels do not support the\n" +" Sends the given text on a channel. Most channels do not support the\n" " transmission of text. Returns 0 if text is sent, or if the channel does not\n" " support text transmission. Returns -1 only on error/hangup. Text\n" " consisting of greater than one word should be placed in quotes since the\n" @@ -1273,9 +1298,9 @@ static char usage_sendtext[] = static char usage_recvchar[] = " Usage: RECEIVE CHAR \n" -" Receives a character of text on a channel. Specify timeout to be the\n" +" Receives a character of text on a channel. Specify timeout to be the\n" " maximum time to wait for input in milliseconds, or 0 for infinite. Most channels\n" -" do not support the reception of text. Returns the decimal value of the character\n" +" do not support the reception of text. Returns the decimal value of the character\n" " if one is received, or 0 if the channel does not support text reception. Returns\n" " -1 only on error/hangup.\n"; @@ -1286,19 +1311,19 @@ static char usage_tddmode[] = static char usage_sendimage[] = " Usage: SEND IMAGE \n" -" Sends the given image on a channel. Most channels do not support the\n" -" transmission of images. Returns 0 if image is sent, or if the channel does not\n" -" support image transmission. Returns -1 only on error/hangup. Image names\n" +" Sends the given image on a channel. Most channels do not support the\n" +" transmission of images. Returns 0 if image is sent, or if the channel does not\n" +" support image transmission. Returns -1 only on error/hangup. Image names\n" " should not include extensions.\n"; static char usage_streamfile[] = " Usage: STREAM FILE [sample offset]\n" " Send the given file, allowing playback to be interrupted by the given\n" -" digits, if any. Use double quotes for the digits if you wish none to be\n" -" permitted. If sample offset is provided then the audio will seek to sample\n" +" digits, if any. Use double quotes for the digits if you wish none to be\n" +" permitted. If sample offset is provided then the audio will seek to sample\n" " offset before play starts. Returns 0 if playback completes without a digit\n" " being pressed, or the ASCII numerical value of the digit if one was pressed,\n" -" or -1 on error or if the channel was disconnected. Remember, the file\n" +" or -1 on error or if the channel was disconnected. Remember, the file\n" " extension must not be included in the filename.\n"; static char usage_getoption[] = @@ -1315,14 +1340,14 @@ static char usage_saynumber[] = static char usage_saydigits[] = " Usage: SAY DIGITS \n" " Say a given digit string, returning early if any of the given DTMF digits\n" -" are received on the channel. Returns 0 if playback completes without a digit\n" +" are received on the channel. Returns 0 if playback completes without a digit\n" " being pressed, or the ASCII numerical value of the digit if one was pressed or\n" " -1 on error/hangup.\n"; static char usage_sayalpha[] = " Usage: SAY ALPHA \n" " Say a given character string, returning early if any of the given DTMF digits\n" -" are received on the channel. Returns 0 if playback completes without a digit\n" +" are received on the channel. Returns 0 if playback completes without a digit\n" " being pressed, or the ASCII numerical value of the digit if one was pressed or\n" " -1 on error/hangup.\n"; @@ -1330,14 +1355,14 @@ static char usage_saytime[] = " Usage: SAY TIME