*
*/
#ifndef lint
-static const char rcsid[] = "$Id: fcgiapp.c,v 1.9 1999/08/10 10:05:01 skimo Exp $";
+static const char rcsid[] = "$Id: fcgiapp.c,v 1.12 1999/08/14 21:20:56 roberts Exp $";
#endif /* not lint */
#include "fcgi_config.h"
* Globals
*/
static int libInitialized = 0;
+static int isFastCGI = -1;
static char *webServerAddressList = NULL;
-static FCGX_Request reqData;
-static FCGX_Request *reqDataPtr = &reqData;
+static FCGX_Request the_request;
static void *Malloc(size_t size)
{
* Results:
* TRUE if the process is a CGI process, FALSE if FastCGI.
*
- * Side effects:
- * If this is a FastCGI process there's a chance that a connection
- * will be accepted while performing the test. If this occurs,
- * the connection is saved and used later by the FCGX_Accept logic.
- *
*----------------------------------------------------------------------
*/
int FCGX_IsCGI(void)
{
- static int isFastCGI = -1;
-
if (isFastCGI != -1) {
return !isFastCGI;
}
void FCGX_Finish(void)
{
- FCGX_Finish_r(reqDataPtr);
+ FCGX_Finish_r(&the_request);
}
/*
int FCGX_OpenSocket(const char *path, int backlog)
{
- return OS_CreateLocalIpcFd(path, backlog);
+ int rc = OS_CreateLocalIpcFd(path, backlog);
+ if (rc == FCGI_LISTENSOCK_FILENO && isFastCGI == 0) {
+ /* XXX probably need to call OS_LibInit() again for Win */
+ isFastCGI = 1;
+ }
+ return rc;
}
int FCGX_InitRequest(FCGX_Request *request, int sock, int flags)
/* If our compiler doesn't play by the ISO rules for struct layout, halt. */
ASSERT(sizeof(FCGI_Header) == FCGI_HEADER_LEN);
- FCGX_InitRequest(&reqData, FCGI_LISTENSOCK_FILENO, 0);
+ FCGX_InitRequest(&the_request, FCGI_LISTENSOCK_FILENO, 0);
if (OS_LibInit(NULL) == -1) {
return OS_Errno ? OS_Errno : -9997;
}
p = getenv("FCGI_WEB_SERVER_ADDRS");
- webServerAddressList = p ? StringCopy(p) : "";
+ webServerAddressList = p ? StringCopy(p) : NULL;
libInitialized = 1;
return 0;
FCGX_Stream **err,
FCGX_ParamArray *envp)
{
+ int rc;
+
if (!libInitialized) {
- int rc = FCGX_Init();
- if (rc) {
+ if ((rc = FCGX_Init())) {
return (rc < 0) ? rc : -rc;
}
}
- return FCGX_Accept_r(&reqData);
+ rc = FCGX_Accept_r(&the_request);
+
+ *in = the_request.in;
+ *out = the_request.out;
+ *err = the_request.err;
+ *envp = the_request.envp;
+
+ return rc;
}
/*
*/
int FCGX_Accept_r(FCGX_Request *reqDataPtr)
{
- FCGX_Stream **in = &reqDataPtr->in;
- FCGX_Stream **out = &reqDataPtr->out;
- FCGX_Stream **err = &reqDataPtr->err;
- FCGX_ParamArray *envp = &reqDataPtr->envp;
-
if (!libInitialized) {
return -9998;
}
reqDataPtr->out = NewWriter(reqDataPtr, 8192, FCGI_STDOUT);
reqDataPtr->err = NewWriter(reqDataPtr, 512, FCGI_STDERR);
reqDataPtr->nWriters = 2;
- *in = reqDataPtr->in;
- *out = reqDataPtr->out;
- *err = reqDataPtr->err;
- *envp = reqDataPtr->paramsPtr->vec;
+ reqDataPtr->envp = reqDataPtr->paramsPtr->vec;
return 0;
}
\f
SetError(stream, FCGX_CALL_SEQ_ERROR);
return -1;
}
- SetReaderType(reqDataPtr->in, FCGI_DATA);
+ SetReaderType(stream, FCGI_DATA);
return 0;
}
\f