X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=cgi-fcgi%2Fcgi-fcgi.c;h=9de2f5a0b440abfe6958fdce63c9747e80e15c22;hb=de53af2a082e5e13b59b69c846827f9356d3df75;hp=32dfd83f92fc34ae1610084dc54164a9254bf53c;hpb=0198fd3ca83ad0dbdb1c3bfb967d1843a7d02296;p=catagits%2Ffcgi2.git diff --git a/cgi-fcgi/cgi-fcgi.c b/cgi-fcgi/cgi-fcgi.c index 32dfd83..9de2f5a 100644 --- a/cgi-fcgi/cgi-fcgi.c +++ b/cgi-fcgi/cgi-fcgi.c @@ -1,4 +1,4 @@ -/* +/* * cgifcgi.c -- * * CGI to FastCGI bridge @@ -10,39 +10,50 @@ * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * */ - #ifndef lint -static const char rcsid[] = "$Id: cgi-fcgi.c,v 1.1 1997/09/16 15:36:25 stanleyg Exp $"; +static const char rcsid[] = "$Id: cgi-fcgi.c,v 1.7 1999/07/28 00:38:34 roberts Exp $"; #endif /* not lint */ -#include -#ifdef HAVE_UNISTD_H -#include -#endif -#include +#include "fcgi_config.h" + #include +#include +#include +#include +#include #include #include -#include -#include + #ifdef HAVE_NETDB_H #include #endif -#ifdef HAVE_SYS_TIME_H -#include + +#ifdef _WIN32 +#include +#else +extern char **environ; #endif + #ifdef HAVE_SYS_PARAM_H #include #endif + +#ifdef HAVE_SYS_TIME_H +#include +#endif + +#if defined HAVE_UNISTD_H +#include +#endif + #include "fcgimisc.h" #include "fcgiapp.h" #include "fcgiappmisc.h" #include "fastcgi.h" -#include "fcgi_config.h" #include "fcgios.h" + static int wsReadPending = 0; -static int wsWritePending = 0; static int fcgiReadPending = 0; static int fcgiWritePending = 0; @@ -395,7 +406,7 @@ static void AppServerWriteHandler(ClientData clientData, int bytesWritten) } ScheduleIo(); -} +} /* @@ -409,7 +420,7 @@ static void AppServerWriteHandler(ClientData clientData, int bytesWritten) * * Side effects: * This routine will signal the ioEvent upon completion. - * + * */ static void ScheduleIo(void) { @@ -436,7 +447,7 @@ static void ScheduleIo(void) if(!fcgiReadPending && appServerSock != -1) { fromAS.next = &fromAS.buff[0]; - if(OS_AsyncRead(appServerSock, 0, fromAS.next, BUFFLEN, + if(OS_AsyncRead(appServerSock, 0, fromAS.next, BUFFLEN, AppServerReadHandler, (ClientData)appServerSock) == -1) { FCGIexit(OS_Errno); @@ -452,7 +463,7 @@ static void ScheduleIo(void) !fcgiWritePending && fromWS.next == &fromWS.buff[0]) { if(OS_AsyncReadStdin(fromWS.next + sizeof(FCGI_Header), - BUFFLEN - sizeof(FCGI_Header), + BUFFLEN - sizeof(FCGI_Header), WebServerReadHandler, STDIN_FILENO)== -1) { FCGIexit(OS_Errno); } else { @@ -476,12 +487,11 @@ static void ScheduleIo(void) static void FCGI_Start(char *bindPath, char *appPath, int nServers) { int listenFd, i; - int tcp = FALSE; if((listenFd = OS_CreateLocalIpcFd(bindPath)) == -1) { exit(OS_Errno); } - + if(access(appPath, X_OK) == -1) { fprintf(stderr, "%s is not executable\n", appPath); exit(1); @@ -514,8 +524,6 @@ static void FCGI_Start(char *bindPath, char *appPath, int nServers) * *---------------------------------------------------------------------- */ -static buildNameValueHeaderCalls = 0; /* XXX: for testing */ - static void FCGIUtil_BuildNameValueHeader( int nameLen, int valueLen, @@ -524,7 +532,7 @@ static void FCGIUtil_BuildNameValueHeader( unsigned char *startHeaderBuffPtr = headerBuffPtr; ASSERT(nameLen >= 0); - if(nameLen < 0x80 && (buildNameValueHeaderCalls & 1) == 0) { + if (nameLen < 0x80) { *headerBuffPtr++ = nameLen; } else { *headerBuffPtr++ = (nameLen >> 24) | 0x80; @@ -533,7 +541,7 @@ static void FCGIUtil_BuildNameValueHeader( *headerBuffPtr++ = nameLen; } ASSERT(valueLen >= 0); - if(valueLen < 0x80 && (buildNameValueHeaderCalls & 2) == 0) { + if (valueLen < 0x80) { *headerBuffPtr++ = valueLen; } else { *headerBuffPtr++ = (valueLen >> 24) | 0x80; @@ -542,7 +550,6 @@ static void FCGIUtil_BuildNameValueHeader( *headerBuffPtr++ = valueLen; } *headerLenPtr = headerBuffPtr - startHeaderBuffPtr; - buildNameValueHeaderCalls++; } @@ -605,7 +612,7 @@ static int ParseArgs(int argc, char *argv[], "%d is max from a file\n", MAXARGS); exit(-1); } - if((av[ac] = malloc(strlen(tp1)+1)) == NULL) { + if((av[ac] = (char *)malloc(strlen(tp1)+1)) == NULL) { fprintf(stderr, "Cannot allocate %d bytes\n", strlen(tp1)+1); exit(-1); @@ -669,7 +676,7 @@ static int ParseArgs(int argc, char *argv[], This hack lets me test the ability to create a local process listening to a TCP/IP port for connections and subsequently connect to the app like we do for Unix domain and named pipes. - + if(*doStartPtr && *doBindPtr) { fprintf(stderr, " of form hostName:portNumber " @@ -684,8 +691,9 @@ static int ParseArgs(int argc, char *argv[], return err; } -void main(int argc, char **argv, char **envp) +int main(int argc, char **argv) { + char **envp = environ; int count; FCGX_Stream *paramsStream; int numFDs; @@ -721,7 +729,7 @@ void main(int argc, char **argv, char **envp) } else { bytesToRead = 0; } - + if(doBind) { appServerSock = OS_FcgiConnect(bindPath); } @@ -806,4 +814,6 @@ void main(int argc, char **argv, char **envp) } else { FCGIexit(999); } + + return 0; }