*
*/
#ifndef lint
-static const char rcsid[] = "$Id: fcgiapp.c,v 1.15 2000/10/02 12:43:13 robs Exp $";
+static const char rcsid[] = "$Id: fcgiapp.c,v 1.24 2001/06/22 09:12:03 skimo Exp $";
#endif /* not lint */
-#include "fcgi_config.h"
-
-#ifdef _WIN32
-#define DLLAPI __declspec(dllexport)
-#endif
-
#include <assert.h>
#include <errno.h>
#include <fcntl.h> /* for fcntl */
#include <string.h>
#include <sys/types.h>
+#include "fcgi_config.h"
+
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h> /* for getpeername */
#endif
#include <unistd.h>
#endif
-#include "fcgimisc.h"
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#endif
+
+#ifdef _WIN32
+#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
{
int c;
char *p = str;
+
n--;
while (n > 0) {
c = FCGX_GetChar(stream);
else
break;
}
- *p++ = c;
+ *p++ = (char) c;
n--;
if(c == '\n')
break;
|| stream->rdNext == stream->stopUnget)
return EOF;
--(stream->rdNext);
- *stream->rdNext = c;
+ *stream->rdNext = (unsigned char) c;
return c;
}
int FCGX_PutChar(int c, FCGX_Stream *stream)
{
if(stream->wrNext != stream->stop)
- return (*stream->wrNext++ = c);
+ return (*stream->wrNext++ = (unsigned char) c);
if(stream->isClosed || stream->isReader)
return EOF;
stream->emptyBuffProc(stream, FALSE);
if(stream->wrNext != stream->stop)
- return (*stream->wrNext++ = c);
+ return (*stream->wrNext++ = (unsigned char) c);
ASSERT(stream->isClosed); /* bug in emptyBuffProc if not */
return EOF;
}
int FCGX_VFPrintF(FCGX_Stream *stream, const char *format, va_list arg)
{
char *f, *fStop, *percentPtr, *p, *fmtBuffPtr, *buffPtr;
- int op, performedOp, sizeModifier, buffCount, buffLen, specifierLength;
- int fastPath, n, auxBuffLen, buffReqd, minWidth, precision, exp;
+ int op, performedOp, sizeModifier, buffCount = 0, buffLen, specifierLength;
+ int fastPath, n, auxBuffLen = 0, buffReqd, minWidth, precision, exp;
char *auxBuffPtr = NULL;
int streamCount = 0;
char fmtBuff[FMT_BUFFLEN];
unsigned unsignedArg;
unsigned long uLongArg;
unsigned short uShortArg;
- char *charPtrArg;
+ char *charPtrArg = NULL;
void *voidPtrArg;
int *intPtrArg;
long *longPtrArg;
short *shortPtrArg;
- double doubleArg;
- LONG_DOUBLE lDoubleArg;
+ double doubleArg = 0.0;
+ LONG_DOUBLE lDoubleArg = 0.0L;
fmtBuff[0] = '%';
f = (char *) format;
case 'h':
sizeModifier = op;
op = *(percentPtr + 2);
- fmtBuff[1] = sizeModifier;
- fmtBuff[2] = op;
+ fmtBuff[1] = (char) sizeModifier;
+ fmtBuff[2] = (char) op;
fmtBuff[3] = '\0';
specifierLength = 3;
break;
default:
sizeModifier = ' ';
- fmtBuff[1] = op;
+ fmtBuff[1] = (char) op;
fmtBuff[2] = '\0';
specifierLength = 2;
break;
switch(sizeModifier) {
case ' ':
doubleArg = va_arg(arg, double);
- frexp(doubleArg, &exp);
+ frexp(doubleArg, &exp);
break;
case 'L':
lDoubleArg = va_arg(arg, LONG_DOUBLE);
- frexp(lDoubleArg, &exp);
+ /* XXX Need to check for the presence of
+ * frexpl() and use it if available */
+ frexp((double) lDoubleArg, &exp);
break;
default:
goto ErrorReturn;
*longPtrArg = streamCount;
break;
case 'h':
- shortPtrArg = va_arg(arg, short *);
- *shortPtrArg = streamCount;
+ shortPtrArg = (short *) va_arg(arg, short *);
+ *shortPtrArg = (short) streamCount;
break;
default:
goto ErrorReturn;
{
int len;
char **p;
+
+ if (name == NULL || envp == NULL) return NULL;
+
len = strlen(name);
- if(len == 0) return NULL;
- for (p = envp; *p != NULL; p++) {
+
+ for (p = envp; *p; ++p) {
if((strncmp(name, *p, len) == 0) && ((*p)[len] == '=')) {
return *p+len+1;
}
ASSERT(contentLength >= 0 && contentLength <= FCGI_MAX_LENGTH);
ASSERT(paddingLength >= 0 && paddingLength <= 0xff);
header.version = FCGI_VERSION_1;
- header.type = type;
- header.requestIdB1 = (requestId >> 8) & 0xff;
- header.requestIdB0 = (requestId ) & 0xff;
- header.contentLengthB1 = (contentLength >> 8) & 0xff;
- header.contentLengthB0 = (contentLength ) & 0xff;
- header.paddingLength = paddingLength;
+ header.type = (unsigned char) type;
+ header.requestIdB1 = (unsigned char) ((requestId >> 8) & 0xff);
+ header.requestIdB0 = (unsigned char) ((requestId ) & 0xff);
+ header.contentLengthB1 = (unsigned char) ((contentLength >> 8) & 0xff);
+ header.contentLengthB0 = (unsigned char) ((contentLength ) & 0xff);
+ header.paddingLength = (unsigned char) paddingLength;
header.reserved = 0;
return header;
}
int protocolStatus)
{
FCGI_EndRequestBody body;
- body.appStatusB3 = (appStatus >> 24) & 0xff;
- body.appStatusB2 = (appStatus >> 16) & 0xff;
- body.appStatusB1 = (appStatus >> 8) & 0xff;
- body.appStatusB0 = (appStatus ) & 0xff;
- body.protocolStatus = protocolStatus;
+ body.appStatusB3 = (unsigned char) ((appStatus >> 24) & 0xff);
+ body.appStatusB2 = (unsigned char) ((appStatus >> 16) & 0xff);
+ body.appStatusB1 = (unsigned char) ((appStatus >> 8) & 0xff);
+ body.appStatusB0 = (unsigned char) ((appStatus ) & 0xff);
+ body.protocolStatus = (unsigned char) protocolStatus;
memset(body.reserved, 0, sizeof(body.reserved));
return body;
}
int type)
{
FCGI_UnknownTypeBody body;
- body.type = type;
+ body.type = (unsigned char) type;
memset(body.reserved, 0, sizeof(body.reserved));
return body;
}
char **pPtr;
char response[64]; /* 64 = 8 + 3*(1+1+14+1)* + padding */
char *responseP = &response[FCGI_HEADER_LEN];
- char *name, value;
+ char *name, value = '\0';
int len, paddedLen;
if(type == FCGI_GET_VALUES) {
ReadParams(paramsPtr, stream);
int errStatus = FCGX_FClose(reqDataPtr->err);
int outStatus = FCGX_FClose(reqDataPtr->out);
- if (errStatus || outStatus
- || FCGX_GetError(reqDataPtr->in)
- || !reqDataPtr->keepConnection)
+ if (errStatus || outStatus || FCGX_GetError(reqDataPtr->in))
{
OS_IpcClose(reqDataPtr->ipcFd);
+ reqDataPtr->ipcFd = -1;
}
+ }
- ASSERT(reqDataPtr->nWriters == 0);
-
- FreeStream(&reqDataPtr->in);
- reqDataPtr->in = NULL;
-
- FreeStream(&reqDataPtr->out);
- reqDataPtr->out = NULL;
+ FCGX_Free(reqDataPtr);
+}
- FreeStream(&reqDataPtr->err);
- reqDataPtr->err = NULL;
+void FCGX_Free(FCGX_Request * request)
+{
+ if (request == NULL)
+ return;
- FreeParams(&reqDataPtr->paramsPtr);
- reqDataPtr->paramsPtr = NULL;
- }
+ FreeStream(&request->in);
+ FreeStream(&request->out);
+ FreeStream(&request->err);
+ FreeParams(&request->paramsPtr);
- if (!reqDataPtr->keepConnection) {
- reqDataPtr->ipcFd = -1;
+ if (!request->keepConnection)
+ {
+ OS_IpcClose(request->ipcFd);
+ request->ipcFd = -1;
}
}
/* @@@ Should validate against "known" flags */
request->flags = flags;
+ request->ipcFd = -1;
+
return 0;
}
{
int rc;
- if (!libInitialized) {
- if ((rc = FCGX_Init())) {
- return (rc < 0) ? rc : -rc;
+ if (! libInitialized) {
+ rc = FCGX_Init();
+ if (rc) {
+ return rc;
}
}
* Close the connection and try again.
*/
TryAgain:
- FreeParams(&reqDataPtr->paramsPtr);
- reqDataPtr->paramsPtr = NULL;
-
- FreeStream(&reqDataPtr->in);
- reqDataPtr->in = NULL;
+ reqDataPtr->keepConnection = 0;
+ FCGX_Free(reqDataPtr);
- OS_Close(reqDataPtr->ipcFd);
- reqDataPtr->ipcFd = -1;
} /* for (;;) */
/*
* Build the remaining data structures representing the new