*
*/
#ifndef lint
-static const char rcsid[] = "$Id: fcgiapp.c,v 1.25 2001/06/22 13:17:19 skimo Exp $";
+static const char rcsid[] = "$Id: fcgiapp.c,v 1.35 2003/06/22 00:16:43 robs Exp $";
#endif /* not lint */
#include <assert.h>
#define DLLAPI __declspec(dllexport)
#endif
-#include "fcgiapp.h"
-#include "fcgiappmisc.h"
-
#include "fcgimisc.h"
#include "fastcgi.h"
#include "fcgios.h"
+#include "fcgiapp.h"
/*
* This is a workaround for one version of the HP C compiler
static char *webServerAddressList = NULL;
static FCGX_Request the_request;
+void FCGX_ShutdownPending(void)
+{
+ OS_ShutdownPending();
+}
+
static void *Malloc(size_t size)
{
void *result = malloc(size);
return newString;
}
-\f
+
/*
*----------------------------------------------------------------------
*
*/
int FCGX_GetChar(FCGX_Stream *stream)
{
- if(stream->rdNext != stream->stop)
- return *stream->rdNext++;
- if(stream->isClosed || !stream->isReader)
+ if (stream->isClosed || ! stream->isReader)
return EOF;
+
+ if (stream->rdNext != stream->stop)
+ return *stream->rdNext++;
+
stream->fillBuffProc(stream);
+ if (stream->isClosed)
+ return EOF;
+
stream->stopUnget = stream->rdNext;
- if(stream->rdNext != stream->stop)
+ if (stream->rdNext != stream->stop)
return *stream->rdNext++;
+
ASSERT(stream->isClosed); /* bug in fillBufProc if not */
return EOF;
}
-\f
+
/*
*----------------------------------------------------------------------
*
{
int m, bytesMoved;
- if(n <= 0) {
+ if (stream->isClosed || ! stream->isReader || n <= 0) {
return 0;
}
/*
if(bytesMoved == n)
return bytesMoved;
str += m;
- }
+ }
if(stream->isClosed || !stream->isReader)
return bytesMoved;
stream->fillBuffProc(stream);
+ if (stream->isClosed)
+ return bytesMoved;
+
stream->stopUnget = stream->rdNext;
}
}
-\f
+
/*
*----------------------------------------------------------------------
*
*p = '\0';
return str;
}
-\f
+
/*
*----------------------------------------------------------------------
*
int FCGX_HasSeenEOF(FCGX_Stream *stream) {
return (stream->isClosed) ? EOF : 0;
}
-\f
+
/*
*----------------------------------------------------------------------
*
ASSERT(stream->isClosed); /* bug in emptyBuffProc if not */
return EOF;
}
-\f
+
/*
*----------------------------------------------------------------------
*
stream->emptyBuffProc(stream, FALSE);
}
}
-\f
+
/*
*----------------------------------------------------------------------
*
{
return FCGX_PutStr(str, strlen(str), stream);
}
-\f
+
/*
*----------------------------------------------------------------------
*
*destPtr = dest;
*srcPtr = src;
}
-\f
+
/*
*----------------------------------------------------------------------
*
stream->emptyBuffProc(stream, FALSE);
return (stream->isClosed) ? -1 : 0;
}
-\f
+
/*
*----------------------------------------------------------------------
*
}
return (stream->FCGI_errno == 0) ? 0 : EOF;
}
-\f
+
/*
*----------------------------------------------------------------------
*
*/
if(stream->FCGI_errno == 0) {
stream->FCGI_errno = FCGI_errno;
- stream->isClosed = TRUE;
}
+
+ stream->isClosed = TRUE;
}
/*
* of the stream that are now all lumped under isClosed.
*/
}
-\f
+
/*
*======================================================================
* Parameters
char **cur; /* current item in vec; *cur == NULL */
} Params;
typedef Params *ParamsPtr;
-\f
+
/*
*----------------------------------------------------------------------
*
*result->cur = NULL;
return result;
}
-\f
+
/*
*----------------------------------------------------------------------
*
free(paramsPtr);
*paramsPtrPtr = NULL;
}
-\f
+
/*
*----------------------------------------------------------------------
*
}
*paramsPtr->cur = NULL;
}
-\f
+
/*
*----------------------------------------------------------------------
*
}
return NULL;
}
-\f
+
/*
*----------------------------------------------------------------------
*
*
*----------------------------------------------------------------------
*/
-\f
+
/*
*----------------------------------------------------------------------
*
}
return 0;
}
-\f
+
/*
*----------------------------------------------------------------------
*
header.reserved = 0;
return header;
}
-\f
+
/*
*----------------------------------------------------------------------
*
memset(body.reserved, 0, sizeof(body.reserved));
return body;
}
-\f
+
/*
*----------------------------------------------------------------------
*
memset(body.reserved, 0, sizeof(body.reserved));
return body;
}
-\f
+
/*
*----------------------------------------------------------------------
*
u = ((u + 7) & (ULONG_MAX - 7)) - u;
return p + u;
}
-\f
+
/*
* State associated with a stream
int rawWrite; /* writer: write data without stream headers */
FCGX_Request *reqDataPtr; /* request data not specific to one stream */
} FCGX_Stream_Data;
-\f
+
/*
*----------------------------------------------------------------------
*
}
data->reqDataPtr->nWriters--;
}
-\f
+
static int write_it_all(int fd, char *buf, int len)
stream->wrNext += sizeof(FCGI_Header);
}
}
-\f
+
/*
* Return codes for Process* functions
*/
return MGMT_RECORD;
}
-\f
+
/*
*----------------------------------------------------------------------
*
data->reqDataPtr->isBeginProcessed = TRUE;
return BEGIN_RECORD;
}
-\f
+
/*
*----------------------------------------------------------------------
*
}
return STREAM_RECORD;
}
-\f
+
/*
*----------------------------------------------------------------------
*
}
}
}
-\f
+
/*
*----------------------------------------------------------------------
*
}
return stream;
}
-\f
+
/*
*----------------------------------------------------------------------
*
- * FreeStream --
+ * FCGX_FreeStream --
*
* Frees all storage allocated when *streamPtr was created,
* and nulls out *streamPtr.
*
*----------------------------------------------------------------------
*/
-void FreeStream(FCGX_Stream **streamPtr)
+void FCGX_FreeStream(FCGX_Stream **streamPtr)
{
FCGX_Stream *stream = *streamPtr;
FCGX_Stream_Data *data;
free(stream);
*streamPtr = NULL;
}
-\f
+
/*
*----------------------------------------------------------------------
*
stream->isClosed = FALSE;
return stream;
}
-\f
+
/*
*----------------------------------------------------------------------
*
return NewStream(reqDataPtr, bufflen, TRUE, streamType);
}
-
/*
*----------------------------------------------------------------------
*
return NewStream(reqDataPtr, bufflen, FALSE, streamType);
}
-
/*
*----------------------------------------------------------------------
*
- * CreateWriter --
+ * FCGX_CreateWriter --
*
* Creates a stream to write streamType FastCGI records, using
* the given ipcFd and request Id. This function is provided
*
*----------------------------------------------------------------------
*/
-FCGX_Stream *CreateWriter(
+FCGX_Stream *FCGX_CreateWriter(
int ipcFd,
int requestId,
int bufflen,
reqDataPtr->nWriters = 2;
return NewWriter(reqDataPtr, bufflen, streamType);
}
-\f
+
/*
*======================================================================
* Control
return !isFastCGI;
}
-\f
+
/*
*----------------------------------------------------------------------
*
if (request == NULL)
return;
- FreeStream(&request->in);
- FreeStream(&request->out);
- FreeStream(&request->err);
+ FCGX_FreeStream(&request->in);
+ FCGX_FreeStream(&request->out);
+ FCGX_FreeStream(&request->err);
FreeParams(&request->paramsPtr);
if (close) {
- OS_IpcClose(request->ipcFd);
+ OS_IpcClose(request->ipcFd, ! request->detached);
request->ipcFd = -1;
+ request->detached = 0;
}
}
return 0;
}
- /* If our compiler doesn't play by the ISO rules for struct layout, halt. */
- ASSERT(sizeof(FCGI_Header) == FCGI_HEADER_LEN);
-
FCGX_InitRequest(&the_request, FCGI_LISTENSOCK_FILENO, 0);
if (OS_LibInit(NULL) == -1) {
reqDataPtr->envp = reqDataPtr->paramsPtr->vec;
return 0;
}
-\f
+
/*
*----------------------------------------------------------------------
*
SetReaderType(stream, FCGI_DATA);
return 0;
}
-\f
+
/*
*----------------------------------------------------------------------
*
data->reqDataPtr->appStatus = status;
}
+
+int
+FCGX_Attach(FCGX_Request * r)
+{
+ r->detached = FALSE;
+ return 0;
+}
+
+
+int
+FCGX_Detach(FCGX_Request * r)
+{
+ if (r->ipcFd <= 0)
+ {
+ return -1;
+ }
+
+ r->detached = TRUE;
+ return 0;
+}