Index: branches/PublicaMundi_David-devel/thirds/cgic206/Makefile
===================================================================
--- branches/PublicaMundi_David-devel/thirds/cgic206/Makefile	(revision 547)
+++ branches/PublicaMundi_David-devel/thirds/cgic206/Makefile	(revision 548)
@@ -16,5 +16,5 @@
 RANLIB=ranlib
 
-all: libcgic.a cgictest.cgi capture
+all: libcgic.a 
 
 install: libcgic.a
@@ -31,11 +31,11 @@
 #mingw32 and cygwin users: replace .cgi with .exe
 
-cgictest.cgi: cgictest.o libcgic.a
-	gcc cgictest.o -o cgictest.cgi ${LIBS}
+#cgictest.cgi: cgictest.o libcgic.a
+#	gcc cgictest.o -o cgictest.cgi ${LIBS}
 
-capture: capture.o libcgic.a
-	gcc capture.o -o capture ${LIBS}
+#capture: capture.o libcgic.a
+#	gcc capture.o -o capture ${LIBS}
 
 clean:
-	rm -f *.o *.a cgictest.cgi capture
+	rm -f *.o *.a #cgictest.cgi capture
 
Index: branches/PublicaMundi_David-devel/thirds/cgic206/cgic.c
===================================================================
--- branches/PublicaMundi_David-devel/thirds/cgic206/cgic.c	(revision 547)
+++ branches/PublicaMundi_David-devel/thirds/cgic206/cgic.c	(revision 548)
@@ -10,4 +10,5 @@
 
 #include <fcgi_stdio.h>
+
 #if CGICDEBUG
 #define CGICDEBUGSTART \
@@ -48,5 +49,5 @@
 
 #define cgiStrEq(a, b) (!strcmp((a), (b)))
-
+/**
 char *cgiServerSoftware;
 char *cgiServerName;
@@ -77,9 +78,11 @@
 FILE *cgiOut;
 
+**/
+
 /* True if CGI environment was restored from a file. */
-static int cgiRestored = 0;
-static int cgiTreatUrlEncoding;
-
-static void cgiGetenv(char **s, char *var);
+//static int cgiRestored = 0;
+//static int cgiTreatUrlEncoding;
+
+//static void cgiGetenv(char **s, char *var);
 
 typedef enum {
@@ -97,29 +100,12 @@
 	VALUES. Make local copies if modifications are desired. */
 
-typedef struct cgiFormEntryStruct {
-        char *attr;
-	/* value is populated for regular form fields only.
-		For file uploads, it points to an empty string, and file
-		upload data should be read from the file tfileName. */ 
-	char *value;
-	/* When fileName is not an empty string, tfileName is not null,
-		and 'value' points to an empty string. */
-	/* Valid for both files and regular fields; does not include
-		terminating null of regular fields. */
-	int valueLength;
-	char *fileName;	
-	char *contentType;
-	/* Temporary file name for working storage of file uploads. */
-	char *tfileName;
-        struct cgiFormEntryStruct *next;
-} cgiFormEntry;
 
 /* The first form entry. */
-static cgiFormEntry *cgiFormEntryFirst;
-
-static cgiParseResultType cgiParseGetFormInput();
-static cgiParseResultType cgiParsePostFormInput();
-static cgiParseResultType cgiParsePostMultipartInput();
-static cgiParseResultType cgiParseFormInput(char *data, int length);
+//static cgiFormEntry *cgiFormEntryFirst;
+
+static cgiParseResultType cgiParseGetFormInput(struct cgi_env ** ce);
+static cgiParseResultType cgiParsePostFormInput(struct cgi_env ** ce, FCGX_Stream *in);
+static cgiParseResultType cgiParsePostMultipartInput(struct cgi_env **cet, FCGX_Stream *in);
+static cgiParseResultType cgiParseFormInput(char *data, int length,struct cgi_env ** ce);
 static void cgiSetupConstants();
 void cgiFreeResources();
@@ -130,56 +116,64 @@
 
 
-int cgiMain_init(int argc, char *argv[]) {
-	int result;
+int cgiMain_init(int argc, char *argv[],struct cgi_env ** c,FCGX_Request *request) {
+    struct cgi_env * cgi = * c;
+    cgi->cgiFindTarget = 0;
+    cgi->cgiFindPos = 0;
+
+    cgi->cgiContentType = cgi->cgiContentTypeData;
+    cgi->cgiRestored = 0;
+    int result = 0;
 	char *cgiContentLengthString;
 	char *e;
 	cgiSetupConstants();
-	cgiGetenv(&cgiServerSoftware, "SERVER_SOFTWARE");
-	cgiGetenv(&cgiServerName, "SERVER_NAME");
-	cgiGetenv(&cgiGatewayInterface, "GATEWAY_INTERFACE");
-	cgiGetenv(&cgiServerProtocol, "SERVER_PROTOCOL");
-	cgiGetenv(&cgiServerPort, "SERVER_PORT");
-	cgiGetenv(&cgiRequestMethod, "REQUEST_METHOD");
-	if(strcmp(cgiRequestMethod,"")==0 && argc>=1)
-		cgiRequestMethod="GET";
-	cgiGetenv(&cgiPathInfo, "PATH_INFO");
-	cgiGetenv(&cgiPathTranslated, "PATH_TRANSLATED");
-	cgiGetenv(&cgiScriptName, "SCRIPT_NAME");
-	cgiGetenv(&cgiQueryString, "QUERY_STRING");
-	cgiSid=NULL;
-	if(cgiQueryString!=NULL && argc>=2){
-		cgiQueryString=argv[1];
+    cgi->cgiServerSoftware = FCGX_GetParam("SERVER_SOFTWARE",request->envp);
+	cgi->cgiServerName = FCGX_GetParam("SERVER_NAME",request->envp);
+    cgi->cgiGatewayInterface = FCGX_GetParam("GATEWAY_INTERFACE",request->envp);
+    cgi->cgiServerProtocol = FCGX_GetParam("SERVER_PROTOCOL",request->envp);
+    cgi->cgiServerPort = FCGX_GetParam("SERVER_PORT",request->envp);
+    cgi->cgiRequestMethod = FCGX_GetParam("REQUEST_METHOD",request->envp);
+	if(strcmp(cgi->cgiRequestMethod,"")==0 && argc>=1)
+		cgi->cgiRequestMethod="GET";
+    cgi->cgiPathInfo = FCGX_GetParam("PATH_INFO",request->envp);
+	cgi->cgiPathTranslated = FCGX_GetParam("PATH_TRANSLATED",request->envp);
+	cgi->cgiScriptName = FCGX_GetParam("SCRIPT_NAME",request->envp);
+	cgi->cgiQueryString = FCGX_GetParam("QUERY_STRING",request->envp);
+	cgi->cgiSid=NULL;
+	if(cgi->cgiQueryString!=NULL && argc>=2){
+		cgi->cgiQueryString=argv[1];
 		if(argc>2){
-		  cgiSid=argv[2];
-		}
-	}
-	cgiGetenv(&cgiRemoteHost, "REMOTE_HOST");
-	cgiGetenv(&cgiRemoteAddr, "REMOTE_ADDR");
-	cgiGetenv(&cgiAuthType, "AUTH_TYPE");
-	cgiGetenv(&cgiRemoteUser, "REMOTE_USER");
-	cgiGetenv(&cgiRemoteIdent, "REMOTE_IDENT");
+		  cgi->cgiSid=argv[2];
+		}
+	}
+    cgi->cgiRemoteHost = FCGX_GetParam("REMOTE_HOST",request->envp);
+	cgi->cgiRemoteAddr = FCGX_GetParam("REMOTE_ADDR",request->envp);
+	cgi->cgiAuthType = FCGX_GetParam("AUTH_TYPE",request->envp);
+	cgi->cgiRemoteUser = FCGX_GetParam("REMOTE_USER",request->envp);
+	cgi->cgiRemoteIdent = FCGX_GetParam("REMOTE_IDENT",request->envp);
+    //cgiGetenv(&cgiRemoteIdent, "REMOTE_IDENT");
 	/* 2.0: the content type string needs to be parsed and modified, so
 		copy it to a buffer. */
-	e = getenv("CONTENT_TYPE");
-	if (e) {
-		if (strlen(e) < sizeof(cgiContentTypeData)) {
-			strcpy(cgiContentType, e);
+	//e = getenv("CONTENT_TYPE");
+	e = FCGX_GetParam("CONTENT_TYPE",request->envp);
+    if (e) {
+		if (strlen(e) < sizeof(cgi->cgiContentTypeData)) {
+			strcpy(cgi->cgiContentType, e);
 		} else {
 			/* Truncate safely in the event of what is almost certainly
 				a hack attempt */
-			strncpy(cgiContentType, e, sizeof(cgiContentTypeData));
-			cgiContentType[sizeof(cgiContentTypeData) - 1] = '\0';
+			strncpy(cgi->cgiContentType, e, sizeof(cgi->cgiContentTypeData));
+			cgi->cgiContentType[sizeof(cgi->cgiContentTypeData) - 1] = '\0';
 		}
 	} else {
-		cgiContentType[0] = '\0';
+		cgi->cgiContentType[0] = '\0';
 	}
 	/* Never null */
-	cgiMultipartBoundary = "";
+	cgi->cgiMultipartBoundary = "";
 	/* 2.0: parse semicolon-separated additional parameters of the
 		content type. The one we're interested in is 'boundary'.
 		We discard the rest to make cgiContentType more useful
 		to the typical programmer. */
-	if (strchr(cgiContentType, ';')) {
-		char *sat = strchr(cgiContentType, ';');
+	if (strchr(cgi->cgiContentType, ';')) {
+		char *sat = strchr(cgi->cgiContentType, ';');
 		while (sat) {
 			*sat = '\0';
@@ -190,6 +184,6 @@
 			if (cgiStrBeginsNc(sat, "boundary=")) {
 				char *s;
-				cgiMultipartBoundary = sat + strlen("boundary=");
-				s = cgiMultipartBoundary;
+				cgi->cgiMultipartBoundary = sat + strlen("boundary=");
+				s = cgi->cgiMultipartBoundary;
 				while ((*s) && (!isspace(*s))) {
 					s++;
@@ -202,20 +196,17 @@
 		}
 	}
-	cgiGetenv(&cgiContentLengthString, "CONTENT_LENGTH");
-	cgiContentLength = atoi(cgiContentLengthString);	
-	if(cgiContentLength==0 && argc>=2){
-		cgiContentLength=strlen(argv[1]);
-	}
-	cgiGetenv(&cgiAccept, "HTTP_ACCEPT");
-	cgiGetenv(&cgiUserAgent, "HTTP_USER_AGENT");
-	cgiGetenv(&cgiReferrer, "HTTP_REFERER");
-	cgiGetenv(&cgiCookie, "HTTP_COOKIE");
-#ifdef CGICDEBUG
-	CGICDEBUGSTART
-	fprintf(dout, "%d\n", cgiContentLength);
-	fprintf(dout, "%s\n", cgiRequestMethod);
-	fprintf(dout, "%s\n", cgiContentType);
-	CGICDEBUGEND	
-#endif /* CGICDEBUG */
+    
+    cgiContentLengthString = FCGX_GetParam("CONTENT_LENGTH",request->envp);
+    if (cgiContentLengthString != NULL)
+	    cgi->cgiContentLength = strtol(cgiContentLengthString,NULL,10);
+    else
+        cgi->cgiContentLength = 0;
+	if(cgi->cgiContentLength==0 && argc>=2){
+		cgi->cgiContentLength=strlen(argv[1]);
+	}
+    cgi->cgiAccept = FCGX_GetParam("HTTP_ACCEPT",request->envp);
+	cgi->cgiUserAgent = FCGX_GetParam("HTTP_USER_AGENT",request->envp);
+	cgi->cgiReferrer = FCGX_GetParam("HTTP_REFERER",request->envp);
+	cgi->cgiCookie = FCGX_GetParam("HTTP_COOKIE",request->envp);
 #ifdef WIN32
 	/* 1.07: Must set stdin and stdout to binary mode */
@@ -224,8 +215,8 @@
 	_setmode( FCGI_fileno( stdout ), _O_BINARY );
 #endif /* WIN32 */
-	cgiFormEntryFirst = 0;
-	cgiIn = FCGI_stdin;
-	cgiOut = FCGI_stdout;
-	cgiRestored = 0;
+	cgi->cgiFormEntryFirst = 0;
+	//cgiIn = FCGI_stdin;
+	//cgiOut = FCGI_stdout;
+	//cgiRestored = 0;
 
 
@@ -235,12 +226,12 @@
 	if (argc) {
 		if (argv[0]) {
-			cgiRestored = 0;
+			cgi->cgiRestored = 0;
 		}
 	}	
 
 
-	cgiTreatUrlEncoding=0;
-	if (cgiStrEqNc(cgiRequestMethod, "post")) {
-		cgiTreatUrlEncoding=0;
+	cgi->cgiTreatUrlEncoding=0;
+	if (cgiStrEqNc(cgi->cgiRequestMethod, "post")) {
+		cgi->cgiTreatUrlEncoding=0;
 #ifdef CGICDEBUG
 		CGICDEBUGSTART
@@ -248,5 +239,5 @@
 		CGICDEBUGEND
 #endif /* CGICDEBUG */
-		if (cgiStrEqNc(cgiContentType, "application/x-www-form-urlencoded")) {	
+		if (cgiStrEqNc(cgi->cgiContentType, "application/x-www-form-urlencoded")) {	
 #ifdef CGICDEBUG
 			CGICDEBUGSTART
@@ -254,5 +245,5 @@
 			CGICDEBUGEND	
 #endif /* CGICDEBUG */
-			if (cgiParsePostFormInput() != cgiParseSuccess) {
+			if (cgiParsePostFormInput(&cgi,request->in) != cgiParseSuccess) {
 #ifdef CGICDEBUG
 				CGICDEBUGSTART
@@ -260,5 +251,5 @@
 				CGICDEBUGEND	
 #endif /* CGICDEBUG */
-				cgiFreeResources();
+				cgiFreeResources(&cgi);
 				return -1;
 			}	
@@ -268,5 +259,5 @@
 			CGICDEBUGEND	
 #endif /* CGICDEBUG */
-		} else if (cgiStrEqNc(cgiContentType, "multipart/form-data")) {
+		} else if (cgiStrEqNc(cgi->cgiContentType, "multipart/form-data")) {
 #ifdef CGICDEBUG
 			CGICDEBUGSTART
@@ -274,5 +265,5 @@
 			CGICDEBUGEND	
 #endif /* CGICDEBUG */
-			if (cgiParsePostMultipartInput() != cgiParseSuccess) {
+			if (cgiParsePostMultipartInput(&cgi,request->in) != cgiParseSuccess) {
 #ifdef CGICDEBUG
 				CGICDEBUGSTART
@@ -280,5 +271,5 @@
 				CGICDEBUGEND	
 #endif /* CGICDEBUG */
-				cgiFreeResources();
+				cgiFreeResources(&cgi);
 				return -1;
 			}	
@@ -289,9 +280,9 @@
 #endif /* CGICDEBUG */
 		}
-	} else if (cgiStrEqNc(cgiRequestMethod, "get")) {	
+	} else if (cgiStrEqNc(cgi->cgiRequestMethod, "get")) {	
 		/* The spec says this should be taken care of by
 			the server, but... it isn't */
-		cgiContentLength = strlen(cgiQueryString);
-		if (cgiParseGetFormInput() != cgiParseSuccess) {
+		cgi->cgiContentLength = strlen(cgi->cgiQueryString);
+		if (cgiParseGetFormInput(&cgi) != cgiParseSuccess) {
 #ifdef CGICDEBUG
 			CGICDEBUGSTART
@@ -299,5 +290,5 @@
 			CGICDEBUGEND	
 #endif /* CGICDEBUG */
-			cgiFreeResources();
+			cgiFreeResources(&cgi);
 			return -1;
 		} else {	
@@ -311,5 +302,5 @@
 	return result;
 }
-
+/**
 static void cgiGetenv(char **s, char *var){
 	*s = getenv(var);
@@ -318,21 +309,22 @@
 	}
 }
-
-static cgiParseResultType cgiParsePostFormInput() {
+**/
+static cgiParseResultType cgiParsePostFormInput(struct cgi_env **ce, FCGX_Stream *in) {
+    struct cgi_env * cgi = *ce;
 	char *input;
 	cgiParseResultType result;
-	if (!cgiContentLength) {
+	if (!cgi->cgiContentLength) {
 		return cgiParseSuccess;
 	}
-	input = (char *) malloc(cgiContentLength);
+	input = (char *) malloc(cgi->cgiContentLength);
 	if (!input) {
 		return cgiParseMemory;	
 	}
-	if (((int) fread(input, 1, cgiContentLength, cgiIn)) 
-		!= cgiContentLength) 
+	//if (((int) fread(input, 1, cgiContentLength, cgiIn)) != cgiContentLength) 
+    if (((int) FCGX_GetStr (input, cgi->cgiContentLength, in)) != cgi->cgiContentLength)    
 	{
 		return cgiParseIO;
 	}	
-	result = cgiParseFormInput(input, cgiContentLength);
+	result = cgiParseFormInput(input,cgi->cgiContentLength,&cgi);
 	free(input);
 	return result;
@@ -361,5 +353,5 @@
 } mpStream, *mpStreamPtr;
 
-int mpRead(mpStreamPtr mpp, char *buffer, int len)
+int mpRead(mpStreamPtr mpp, char *buffer, int len, int cgiContentLength,FCGX_Stream *in)
 {
 	int ilen = len;
@@ -381,5 +373,6 @@
 	}
 	if (len) {
-		int fgot = fread(buffer, 1, len, cgiIn);
+        int fgot = FCGX_GetStr(buffer,len,in);
+		//int fgot = fread(buffer, 1, len, cgiIn);
 		if (fgot >= 0) {
 			mpp->offset += (got + fgot);
@@ -430,5 +423,8 @@
 	char **outP,
 	int *bodyLengthP,
-	int first
+	int first,
+    int cgiContentLength,
+    FCGX_Stream *in,
+    char * cgiMultipartBoundary
 	);
 
@@ -438,5 +434,7 @@
 	int attrSpace,
 	char *value,
-	int valueSpace);
+	int valueSpace,
+    int cgiContentLength,
+    FCGX_Stream *in);
 
 static void decomposeValue(char *value,
@@ -454,6 +452,7 @@
 static cgiParseResultType getTempFileName(char *tfileName);
 
-static cgiParseResultType cgiParsePostMultipartInput() {
-	cgiParseResultType result;
+static cgiParseResultType cgiParsePostMultipartInput(struct cgi_env ** ce,FCGX_Stream * in) {
+	struct cgi_env * cgi = *ce;
+    cgiParseResultType result;
 	cgiFormEntry *n = 0, *l = 0;
 	int got;
@@ -464,9 +463,9 @@
 	mpStreamPtr mpp = &mp;
 	memset(&mp, 0, sizeof(mp));
-	if (!cgiContentLength) {
+	if (!cgi->cgiContentLength) {
 		return cgiParseSuccess;
 	}
 	/* Read first boundary, including trailing newline */
-	result = afterNextBoundary(mpp, 0, 0, 0, 1);
+	result = afterNextBoundary(mpp, 0, 0, 0, 1,cgi->cgiContentLength,in,cgi->cgiMultipartBoundary);
 	if (result == cgiParseIO) {	
 		/* An empty submission is not necessarily an error */
@@ -491,5 +490,5 @@
 		outf = 0;
 		/* Check for EOF */
-		got = mpRead(mpp, d, 2);
+		got = mpRead(mpp, d, 2,cgi->cgiContentLength,in);
 		if (got < 2) {
 			/* Crude EOF */
@@ -503,5 +502,5 @@
 		/* Read header lines until end of header */
 		while (readHeaderLine(
-				mpp, attr, sizeof(attr), value, sizeof(value))) 
+				mpp, attr, sizeof(attr), value, sizeof(value),cgi->cgiContentLength,in)) 
 		{
 			char *argNames[3];
@@ -548,5 +547,5 @@
 			tfileName[0] = '\0';
 		}	
-		result = afterNextBoundary(mpp, outf, &out, &bodyLength, 0);
+		result = afterNextBoundary(mpp, outf, &out, &bodyLength, 0,cgi->cgiContentLength,in,cgi->cgiMultipartBoundary);
 		if (result != cgiParseSuccess) {
 			/* Lack of a boundary here is an error. */
@@ -587,5 +586,5 @@
 		n->next = 0;
 		if (!l) {
-			cgiFormEntryFirst = n;
+			cgi->cgiFormEntryFirst = n;
 		} else {
 			l->next = n;
@@ -704,5 +703,5 @@
 
 cgiParseResultType afterNextBoundary(mpStreamPtr mpp, FILE *outf, char **outP,
-	int *bodyLengthP, int first)
+	int *bodyLengthP, int first,int cgiContentLength,FCGX_Stream *in,char *cgiMultipartBoundary)
 {
 	int outLen = 0;
@@ -733,5 +732,5 @@
 	workingBoundaryLength = strlen(workingBoundary);
 	while (1) {
-		got = mpRead(mpp, d, 1);
+		got = mpRead(mpp, d, 1,cgiContentLength,in);
 		if (got != 1) {
 			/* 2.01: cgiParseIO, not cgiFormIO */
@@ -768,5 +767,5 @@
 	/* Read trailing newline or -- EOF marker. A literal EOF here
 		would be an error in the input stream. */
-	got = mpRead(mpp, d, 2);
+	got = mpRead(mpp, d, 2,cgiContentLength,in);
 	if (got != 2) {
 		result = cgiParseIO;
@@ -929,5 +928,7 @@
 	int attrSpace,
 	char *value,
-	int valueSpace)
+	int valueSpace,
+    int cgiContentLength,
+    FCGX_Stream *in)
 {	
 	int attrLen = 0;
@@ -936,10 +937,10 @@
 	while (1) {
 		char d[1];
-		int got = mpRead(mpp, d, 1);
+		int got = mpRead(mpp, d, 1,cgiContentLength,in);
 		if (got != 1) {	
 			return 0;
 		}
 		if (d[0] == '\r') {
-			got = mpRead(mpp, d, 1);
+			got = mpRead(mpp, d, 1,cgiContentLength,in);
 			if (got == 1) {	
 				if (d[0] == '\n') {
@@ -954,5 +955,5 @@
 		} else if ((d[0] == ':') && attrLen) {
 			valueFound = 1;
-			while (mpRead(mpp, d, 1) == 1) {
+			while (mpRead(mpp, d, 1,cgiContentLength,in) == 1) {
 				if (!isspace(d[0])) {
 					mpPutBack(mpp, d, 1);
@@ -985,6 +986,7 @@
 }
 
-static cgiParseResultType cgiParseGetFormInput() {
-	return cgiParseFormInput(cgiQueryString, cgiContentLength);
+static cgiParseResultType cgiParseGetFormInput(struct cgi_env ** ce) {
+    struct cgi_env * cgi = *ce;
+	return cgiParseFormInput(cgi->cgiQueryString, cgi->cgiContentLength,ce);
 }
 
@@ -1000,8 +1002,9 @@
 } cgiUnescapeResultType;
 
-static cgiUnescapeResultType cgiUnescapeChars(char **sp, char *cp, int len);
-
-static cgiParseResultType cgiParseFormInput(char *data, int length) {
+static cgiUnescapeResultType cgiUnescapeChars(char **sp, char *cp, int len,int cgiTreatUrlEncoding);
+
+static cgiParseResultType cgiParseFormInput(char *data, int length,struct cgi_env ** ce) {
 	/* Scan for pairs, unescaping and storing them as they are found. */
+    struct cgi_env * cgi = *ce;
 	int pos = 0;
 	cgiFormEntry *n;
@@ -1026,5 +1029,5 @@
 			break;
 		}
-		if (cgiUnescapeChars(&attr, data+start, len)
+		if (cgiUnescapeChars(&attr, data+start, len,cgi->cgiTreatUrlEncoding)
 			!= cgiUnescapeSuccess) {
 			return cgiParseMemory;
@@ -1043,5 +1046,5 @@
 		/* The last pair probably won't be followed by a &, but
 			that's fine, so check for that after accepting it */
-		if (cgiUnescapeChars(&value, data+start, len)
+		if (cgiUnescapeChars(&value, data+start, len, cgi->cgiTreatUrlEncoding)
 			!= cgiUnescapeSuccess) {
 			free(attr);
@@ -1087,5 +1090,5 @@
 		n->next = 0;
 		if (!l) {
-			cgiFormEntryFirst = n;
+			cgi->cgiFormEntryFirst = n;
 		} else {
 			l->next = n;
@@ -1101,5 +1104,5 @@
 static int cgiHexValue[256];
 
-cgiUnescapeResultType cgiUnescapeChars(char **sp, char *cp, int len) {
+cgiUnescapeResultType cgiUnescapeChars(char **sp, char *cp, int len,int cgiTreatUrlEncoding ) {
 	char *s;
 	cgiEscapeState escapeState = cgiEscapeRest;
@@ -1172,6 +1175,7 @@
 }
 
-void cgiFreeResources() {
-	cgiFormEntry *c = cgiFormEntryFirst;
+void cgiFreeResources(struct cgi_env **cgi) {
+    struct cgi_env * cc = *cgi;
+	cgiFormEntry *c = cc->cgiFormEntryFirst;
 	cgiFormEntry *n;
 	while (c) {
@@ -1190,29 +1194,31 @@
 	/* If the cgi environment was restored from a saved environment,
 		then these are in allocated space and must also be freed */
-	if (cgiRestored) {
-		free(cgiServerSoftware);
-		free(cgiServerName);
-		free(cgiGatewayInterface);
-		free(cgiServerProtocol);
-		free(cgiServerPort);
-		free(cgiRequestMethod);
-		free(cgiPathInfo);
-		free(cgiPathTranslated);
-		free(cgiScriptName);
-		free(cgiQueryString);
-		free(cgiRemoteHost);
-		free(cgiRemoteAddr);
-		free(cgiAuthType);
-		free(cgiRemoteUser);
-		free(cgiRemoteIdent);
-		free(cgiContentType);
-		free(cgiAccept);
-		free(cgiUserAgent);
-		free(cgiReferrer);
-	}
+	/**
+    if (cc->cgiRestored) {
+		free(cc->cgiServerSoftware);
+		free(cc->cgiServerName);
+		free(cc->cgiGatewayInterface);
+		free(cc->cgiServerProtocol);
+		free(cc->cgiServerPort);
+		free(cc->cgiRequestMethod);
+		free(cc->cgiPathInfo);
+		free(cc->cgiPathTranslated);
+		free(cc->cgiScriptName);
+		free(cc->cgiQueryString);
+		free(cc->cgiRemoteHost);
+		free(cc->cgiRemoteAddr);
+		free(cc->cgiAuthType);
+		free(cc->cgiRemoteUser);
+		free(cc->cgiRemoteIdent);
+		free(cc->cgiContentType);
+		free(cc->cgiAccept);
+		free(cc->cgiUserAgent);
+		free(cc->cgiReferrer);
+	}
+    **/
 	/* 2.0: to clean up the environment for cgiReadEnvironment,
 		we must set these correctly */
-	cgiFormEntryFirst = 0;
-	cgiRestored = 0;
+	cc->cgiFormEntryFirst = 0;
+	cc->cgiRestored = 0;
 }
 
@@ -1220,11 +1226,11 @@
 	cgiFormEntry *e, char *result, int max, int newlines);
 
-static cgiFormEntry *cgiFormEntryFindFirst(char *name);
-static cgiFormEntry *cgiFormEntryFindNext();
+static cgiFormEntry *cgiFormEntryFindFirst(char *name, struct cgi_env ** ce);
+static cgiFormEntry *cgiFormEntryFindNext(struct cgi_env ** ce);
 
 cgiFormResultType cgiFormString(
-        char *name, char *result, int max) {
+        char *name, char *result, int max,struct cgi_env ** ce) {
 	cgiFormEntry *e;
-	e = cgiFormEntryFindFirst(name);
+	e = cgiFormEntryFindFirst(name,ce);
 	if (!e) {
 		strcpy(result, "");
@@ -1235,10 +1241,10 @@
 
 cgiFormResultType cgiFormFileName(
-	char *name, char *result, int resultSpace)
+	char *name, char *result, int resultSpace,struct cgi_env ** ce)
 {
 	cgiFormEntry *e;
 	int resultLen = 0;
 	char *s;
-	e = cgiFormEntryFindFirst(name);
+	e = cgiFormEntryFindFirst(name,ce);
 	if (!e) {
 		strcpy(result, "");
@@ -1263,10 +1269,10 @@
 
 cgiFormResultType cgiFormFileContentType(
-	char *name, char *result, int resultSpace)
+	char *name, char *result, int resultSpace,struct cgi_env ** ce)
 {
 	cgiFormEntry *e;
 	int resultLen = 0;
 	char *s;
-	e = cgiFormEntryFindFirst(name);
+	e = cgiFormEntryFindFirst(name,ce);
 	if (!e) {
 		if (resultSpace) {
@@ -1293,8 +1299,8 @@
 
 cgiFormResultType cgiFormFileSize(
-	char *name, int *sizeP)
+	char *name, int *sizeP,struct cgi_env ** ce)
 {
 	cgiFormEntry *e;
-	e = cgiFormEntryFindFirst(name);
+	e = cgiFormEntryFindFirst(name,ce);
 	if (!e) {
 		if (sizeP) {
@@ -1320,9 +1326,9 @@
 
 cgiFormResultType cgiFormFileOpen(
-	char *name, cgiFilePtr *cfpp)
+	char *name, cgiFilePtr *cfpp,struct cgi_env ** ce)
 {
 	cgiFormEntry *e;
 	cgiFilePtr cfp;
-	e = cgiFormEntryFindFirst(name);
+	e = cgiFormEntryFindFirst(name,ce);
 	if (!e) {
 		*cfpp = 0;
@@ -1374,7 +1380,7 @@
 
 cgiFormResultType cgiFormStringNoNewlines(
-        char *name, char *result, int max) {
+        char *name, char *result, int max,struct cgi_env ** ce) {
 	cgiFormEntry *e;
-	e = cgiFormEntryFindFirst(name);
+	e = cgiFormEntryFindFirst(name,ce);
 	if (!e) {
 		strcpy(result, "");
@@ -1385,5 +1391,5 @@
 
 cgiFormResultType cgiFormStringMultiple(
-        char *name, char ***result) {
+        char *name, char ***result,struct cgi_env ** ce) {
 	char **stringArray;
 	cgiFormEntry *e;
@@ -1393,9 +1399,9 @@
 		function is not commonly used. The select menu and
 		radio box functions are faster. */
-	e = cgiFormEntryFindFirst(name);
+	e = cgiFormEntryFindFirst(name,ce);
 	if (e != 0) {
 		do {
 			total++;
-		} while ((e = cgiFormEntryFindNext()) != 0); 
+		} while ((e = cgiFormEntryFindNext(ce)) != 0); 
 	}
 	stringArray = (char **) malloc(sizeof(char *) * (total + 1));
@@ -1409,5 +1415,5 @@
 	}
 	/* Now go get the entries */
-	e = cgiFormEntryFindFirst(name);
+	e = cgiFormEntryFindFirst(name,ce);
 #ifdef CGICDEBUG
 	CGICDEBUGSTART
@@ -1429,5 +1435,5 @@
 			cgiFormEntryString(e, stringArray[i], max, 1);
 			i++;
-		} while ((e = cgiFormEntryFindNext()) != 0); 
+		} while ((e = cgiFormEntryFindNext(ce)) != 0); 
 		*result = stringArray;
 #ifdef CGICDEBUG
@@ -1449,7 +1455,7 @@
 
 cgiFormResultType cgiFormStringSpaceNeeded(
-        char *name, int *result) {
+        char *name, int *result,struct cgi_env ** ce) {
 	cgiFormEntry *e;
-	e = cgiFormEntryFindFirst(name);
+	e = cgiFormEntryFindFirst(name,ce);
 	if (!e) {
 		*result = 1;
@@ -1543,8 +1549,8 @@
 
 cgiFormResultType cgiFormInteger(
-        char *name, int *result, int defaultV) {
+        char *name, int *result, int defaultV,struct cgi_env ** ce) {
 	cgiFormEntry *e;
 	int ch;
-	e = cgiFormEntryFindFirst(name);
+	e = cgiFormEntryFindFirst(name,ce);
 	if (!e) {
 		*result = defaultV;
@@ -1566,6 +1572,6 @@
 
 cgiFormResultType cgiFormIntegerBounded(
-        char *name, int *result, int min, int max, int defaultV) {
-	cgiFormResultType error = cgiFormInteger(name, result, defaultV);
+        char *name, int *result, int min, int max, int defaultV,struct cgi_env ** ce) {
+	cgiFormResultType error = cgiFormInteger(name, result, defaultV,ce);
 	if (error != cgiFormSuccess) {
 		return error;
@@ -1583,8 +1589,8 @@
 
 cgiFormResultType cgiFormDouble(
-        char *name, double *result, double defaultV) {
+        char *name, double *result, double defaultV,struct cgi_env ** ce) {
 	cgiFormEntry *e;
 	int ch;
-	e = cgiFormEntryFindFirst(name);
+	e = cgiFormEntryFindFirst(name,ce);
 	if (!e) {
 		*result = defaultV;
@@ -1606,6 +1612,6 @@
 
 cgiFormResultType cgiFormDoubleBounded(
-        char *name, double *result, double min, double max, double defaultV) {
-	cgiFormResultType error = cgiFormDouble(name, result, defaultV);
+        char *name, double *result, double min, double max, double defaultV,struct cgi_env ** ce) {
+	cgiFormResultType error = cgiFormDouble(name, result, defaultV,ce);
 	if (error != cgiFormSuccess) {
 		return error;
@@ -1624,9 +1630,9 @@
 cgiFormResultType cgiFormSelectSingle(
 	char *name, char **choicesText, int choicesTotal, 
-	int *result, int defaultV) 
+	int *result, int defaultV,struct cgi_env ** ce) 
 {
 	cgiFormEntry *e;
 	int i;
-	e = cgiFormEntryFindFirst(name);
+	e = cgiFormEntryFindFirst(name,ce);
 #ifdef CGICDEBUG
 	CGICDEBUGSTART
@@ -1660,5 +1666,5 @@
 cgiFormResultType cgiFormSelectMultiple(
 	char *name, char **choicesText, int choicesTotal, 
-	int *result, int *invalid) 
+	int *result, int *invalid,struct cgi_env ** ce) 
 {
 	cgiFormEntry *e;
@@ -1669,5 +1675,5 @@
 		result[i] = 0;
 	}
-	e = cgiFormEntryFindFirst(name);
+	e = cgiFormEntryFindFirst(name,ce);
 	if (!e) {
 		*invalid = invalidE;
@@ -1687,5 +1693,5 @@
 			invalidE++;
 		}
-	} while ((e = cgiFormEntryFindNext()) != 0);
+	} while ((e = cgiFormEntryFindNext(ce)) != 0);
 
 	*invalid = invalidE;
@@ -1699,8 +1705,8 @@
 
 cgiFormResultType cgiFormCheckboxSingle(
-	char *name)
+	char *name,struct cgi_env ** ce)
 {
 	cgiFormEntry *e;
-	e = cgiFormEntryFindFirst(name);
+	e = cgiFormEntryFindFirst(name,ce);
 	if (!e) {
 		return cgiFormNotFound;
@@ -1711,18 +1717,18 @@
 extern cgiFormResultType cgiFormCheckboxMultiple(
 	char *name, char **valuesText, int valuesTotal, 
-	int *result, int *invalid)
+	int *result, int *invalid,struct cgi_env ** ce)
 {
 	/* Implementation is identical to cgiFormSelectMultiple. */
 	return cgiFormSelectMultiple(name, valuesText, 
-		valuesTotal, result, invalid);
+		valuesTotal, result, invalid,ce);
 }
 
 cgiFormResultType cgiFormRadio(
 	char *name, 
-	char **valuesText, int valuesTotal, int *result, int defaultV)
+	char **valuesText, int valuesTotal, int *result, int defaultV,struct cgi_env **ce)
 {
 	/* Implementation is identical to cgiFormSelectSingle. */
 	return cgiFormSelectSingle(name, valuesText, valuesTotal, 
-		result, defaultV);
+		result, defaultV,ce);
 }
 
@@ -1730,5 +1736,6 @@
 	char *name,
 	char *value,
-	int space)
+	int space,
+    char * cgiCookie)
 {
 	char *p = cgiCookie;
@@ -1803,9 +1810,10 @@
 	char *name,
 	int *result,
-	int defaultV)
+	int defaultV,
+    char * cgiCookie)
 {
 	char buffer[256];
 	cgiFormResultType r = 
-		cgiCookieString(name, buffer, sizeof(buffer));
+		cgiCookieString(name, buffer, sizeof(buffer),cgiCookie);
 	if (r != cgiFormSuccess) {
 		*result = defaultV;
@@ -1817,9 +1825,9 @@
 
 void cgiHeaderCookieSetInteger(char *name, int value, int secondsToLive,
-	char *path, char *domain)
+	char *path, char *domain,FCGX_Stream * out)
 {
 	char svalue[256];
 	sprintf(svalue, "%d", value);
-	cgiHeaderCookieSetString(name, svalue, secondsToLive, path, domain);
+	cgiHeaderCookieSetString(name, svalue, secondsToLive, path, domain,out);
 }
 
@@ -1850,5 +1858,5 @@
 
 void cgiHeaderCookieSetString(char *name, char *value, int secondsToLive,
-	char *path, char *domain)
+	char *path, char *domain,FCGX_Stream * out)
 {
 	/* cgic 2.02: simpler and more widely compatible implementation.
@@ -1868,5 +1876,5 @@
 	then = now + secondsToLive;
 	gt = gmtime(&then);
-	fprintf(cgiOut, 
+	FCGX_FPrintF(out, 
 		"Set-Cookie: %s=%s; domain=%s; expires=%s, %02d-%s-%04d %02d:%02d:%02d GMT; path=%s\r\n",
 		name, value, domain, 
@@ -1881,29 +1889,29 @@
 }
 
-void cgiHeaderLocation(char *redirectUrl) {
-	fprintf(cgiOut, "Location: %s\r\n\r\n", redirectUrl);
-}
-
-void cgiHeaderStatus(int status, char *statusMessage) {
-	fprintf(cgiOut, "Status: %d %s\r\n\r\n", status, statusMessage);
-}
-
-void cgiHeaderContentType(char *mimeType) {
-	fprintf(cgiOut, "Content-type: %s\r\n\r\n", mimeType);
-}
-
-static int cgiWriteString(FILE *out, char *s);
-
-static int cgiWriteInt(FILE *out, int i);
+void cgiHeaderLocation(char *redirectUrl,FCGX_Stream * out) {
+	FCGX_FPrintF(out, "Location: %s\r\n\r\n", redirectUrl);
+}
+
+void cgiHeaderStatus(int status, char *statusMessage,FCGX_Stream * out) {
+	FCGX_FPrintF(out, "Status: %d %s\r\n\r\n", status, statusMessage);
+}
+
+void cgiHeaderContentType(char *mimeType,FCGX_Stream * out) {
+	FCGX_FPrintF(out, "Content-type: %s\r\n\r\n", mimeType);
+}
+
+//static int cgiWriteString(FILE *out, char *s);
+
+//static int cgiWriteInt(FILE *out, int i);
 
 #define CGIC_VERSION "2.0"
-
+/**
 cgiEnvironmentResultType cgiWriteEnvironment(char *filename) {
 	FILE *out;
 	cgiFormEntry *e;
-	/* Be sure to open in binary mode */
+	// Be sure to open in binary mode 
 	out = fopen(filename, "wb");
 	if (!out) {
-		/* Can't create file */
+		// Can't create file 
 		return cgiEnvironmentIO;
 	}
@@ -1983,5 +1991,5 @@
 			goto error;
 		}
-		/* New 2.0 fields and file uploads */
+		// New 2.0 fields and file uploads 
 		if (!cgiWriteString(out, e->fileName)) {
 			goto error;
@@ -2022,11 +2030,14 @@
 error:
 	fclose(out);
-	/* If this function is not defined in your system,
-		you must substitute the appropriate 
-		file-deletion function. */
+	// If this function is not defined in your system,
+	//	you must substitute the appropriate 
+	//	file-deletion function. 
 	unlink(filename);
 	return cgiEnvironmentIO;
 }
 
+**/
+
+/**
 static int cgiWriteString(FILE *out, char *s) {
 	int len = (int) strlen(s);
@@ -2049,16 +2060,20 @@
 static int cgiReadInt(FILE *out, int *i);
 
+**/
+
+
+/**
 cgiEnvironmentResultType cgiReadEnvironment(char *filename) {
 	FILE *in;
 	cgiFormEntry *e = 0, *p;
 	char *version;
-	/* Prevent compiler warnings */
+	// Prevent compiler warnings 
 	cgiEnvironmentResultType result = cgiEnvironmentIO;
-	/* Free any existing data first */
+	// Free any existing data first 
 	cgiFreeResources();
-	/* Be sure to open in binary mode */
+	/ Be sure to open in binary mode
 	in = fopen(filename, "rb");
 	if (!in) {
-		/* Can't access file */
+		// Can't access file
 		return cgiEnvironmentIO;
 	}
@@ -2067,9 +2082,9 @@
 	}
 	if (strcmp(version, "CGIC" CGIC_VERSION)) {
-		/* 2.02: Merezko Oleg */
+		// 2.02: Merezko Oleg 
 		free(version);
 		return cgiEnvironmentWrongVersion;
 	}	
-	/* 2.02: Merezko Oleg */
+	// 2.02: Merezko Oleg 
 	free(version);
 	if (!cgiReadString(in, &cgiServerSoftware)) {
@@ -2130,5 +2145,5 @@
 		goto error;
 	}
-	/* 2.0 */
+	// 2.0 
 	if (!cgiReadString(in, &cgiCookie)) {
 		goto error;
@@ -2148,6 +2163,6 @@
 		memset(e, 0, sizeof(cgiFormEntry));
 		if (!cgiReadString(in, &e->attr)) {
-			/* This means we've reached the end of the list. */
-			/* 2.02: thanks to Merezko Oleg */
+			// This means we've reached the end of the list. 
+			// 2.02: thanks to Merezko Oleg 
 			free(e);
 			break;
@@ -2186,7 +2201,7 @@
 			}
 			while (len > 0) {		
-				/* 2.01: try is a bad variable name in
-					C++, and it wasn't being used
-					properly either */
+				// 2.01: try is a bad variable name in
+				//	C++, and it wasn't being used
+				//	properly either 
 				int tryr = len;
 				if (tryr > ((int) sizeof(buffer))) {
@@ -2208,5 +2223,5 @@
 				len -= got;
 			}
-			/* cgic 2.05: should be fclose not rewind */
+			// cgic 2.05: should be fclose not rewind 
 			fclose(out);
 			e->tfileName = (char *) malloc((int) strlen(tfileName) + 1);
@@ -2260,8 +2275,11 @@
 	return result;
 }
-
+**/
+
+
+/**
 static int cgiReadString(FILE *in, char **s) {
 	int len;
-	/* 2.0 fix: test cgiReadInt for failure! */ 
+	//  2.0 fix: test cgiReadInt for failure! 
 	if (!cgiReadInt(in, &len)) {
 		return 0;
@@ -2284,5 +2302,5 @@
 	return 1;
 }
-
+**/
 static int cgiStrEqNc(char *s1, char *s2) {
 	while(1) {
@@ -2327,18 +2345,20 @@
 }
 
-static char *cgiFindTarget = 0;
-static cgiFormEntry *cgiFindPos = 0;
-
-static cgiFormEntry *cgiFormEntryFindFirst(char *name) {
-	cgiFindTarget = name;
-	cgiFindPos = cgiFormEntryFirst;
-	return cgiFormEntryFindNext();
-}
-
-static cgiFormEntry *cgiFormEntryFindNext() {
-	while (cgiFindPos) {
-		cgiFormEntry *c = cgiFindPos;
-		cgiFindPos = c->next;
-		if (!strcmp(c -> attr, cgiFindTarget)) {
+//static char *cgiFindTarget = 0;
+//static cgiFormEntry *cgiFindPos = 0;
+
+static cgiFormEntry *cgiFormEntryFindFirst(char *name,struct cgi_env ** ce) {
+    struct cgi_env * cgi = * ce;
+	cgi->cgiFindTarget = name;
+	cgi->cgiFindPos = cgi->cgiFormEntryFirst;
+	return cgiFormEntryFindNext(ce);
+}
+
+static cgiFormEntry *cgiFormEntryFindNext(struct cgi_env ** ce) {
+    struct cgi_env * cgi = * ce;
+	while (cgi->cgiFindPos) {
+		cgiFormEntry *c = cgi->cgiFindPos;
+		cgi->cgiFindPos = c->next;
+		if (!strcmp(c -> attr, cgi->cgiFindTarget)) {
 			return c;
 		}
@@ -2365,5 +2385,5 @@
 }	
 
-cgiFormResultType cgiCookies(char ***result) {
+cgiFormResultType cgiCookies(char ***result,char *cgiCookie) {
 	char **stringArray;
 	int i;
@@ -2422,14 +2442,15 @@
 }
 
-cgiFormResultType cgiFormEntries(char ***result) {
+cgiFormResultType cgiFormEntries(char ***result,struct cgi_env ** ce) {
+    struct cgi_env * cgi = *ce;
 	char **stringArray;
 	cgiFormEntry *e, *pe;
 	int i;
 	int total = 0;
-	e = cgiFormEntryFirst;
+	e = cgi->cgiFormEntryFirst;
 	while (e) {
 		/* Don't count a field name more than once if
 			multiple values happen to be present for it */
-		pe = cgiFormEntryFirst;
+		pe = cgi->cgiFormEntryFirst;
 		while (pe != e) {
 			if (!strcmp(e->attr, pe->attr)) {
@@ -2452,5 +2473,5 @@
 	}
 	/* Now go get the entries */
-	e = cgiFormEntryFirst;
+	e = cgi->cgiFormEntryFirst;
 	i = 0;
 	while (e) {
@@ -2458,5 +2479,5 @@
 		/* Don't return a field name more than once if
 			multiple values happen to be present for it */
-		pe = cgiFormEntryFirst;
+		pe = cgi->cgiFormEntryFirst;
 		while (pe != e) {
 			if (!strcmp(e->attr, pe->attr)) {
@@ -2482,32 +2503,32 @@
 }
 
-#define TRYPUTC(ch) \
+#define TRYPUTC(ch,out) \
 	{ \
-		if (putc((ch), cgiOut) == EOF) { \
+		if (FCGX_PutChar((int)ch, out) == -1) { \
 			return cgiFormIO; \
 		} \
 	} 
 
-cgiFormResultType cgiHtmlEscapeData(char *data, int len)
+cgiFormResultType cgiHtmlEscapeData(char *data, int len,FCGX_Stream *out)
 {
 	while (len--) {
 		if (*data == '<') {
-			TRYPUTC('&');
-			TRYPUTC('l');
-			TRYPUTC('t');
-			TRYPUTC(';');
+			TRYPUTC('&',out);
+			TRYPUTC('l',out);
+			TRYPUTC('t',out);
+			TRYPUTC(';',out);
 		} else if (*data == '&') {
-			TRYPUTC('&');
-			TRYPUTC('a');
-			TRYPUTC('m');
-			TRYPUTC('p');
-			TRYPUTC(';');
+			TRYPUTC('&',out);
+			TRYPUTC('a',out);
+			TRYPUTC('m',out);
+			TRYPUTC('p',out);
+			TRYPUTC(';',out);
 		} else if (*data == '>') {
-			TRYPUTC('&');
-			TRYPUTC('g');
-			TRYPUTC('t');
-			TRYPUTC(';');
+			TRYPUTC('&',out);
+			TRYPUTC('g',out);
+			TRYPUTC('t',out);
+			TRYPUTC(';',out);
 		} else {
-			TRYPUTC(*data);
+			TRYPUTC(*data,out);
 		}
 		data++;
@@ -2516,7 +2537,7 @@
 }
 
-cgiFormResultType cgiHtmlEscape(char *s)
+cgiFormResultType cgiHtmlEscape(char *s, FCGX_Stream *out)
 {
-	return cgiHtmlEscapeData(s, (int) strlen(s));
+	return cgiHtmlEscapeData(s, (int) strlen(s),out);
 }
 
@@ -2527,15 +2548,15 @@
 	bytes in 'data'. Returns cgiFormIO in the event
 	of error, cgiFormSuccess otherwise. */
-cgiFormResultType cgiValueEscapeData(char *data, int len)
+cgiFormResultType cgiValueEscapeData(char *data, int len,FCGX_Stream *out)
 {
 	while (len--) {
 		if (*data == '\"') {
-			TRYPUTC('&');
-			TRYPUTC('#');
-			TRYPUTC('3');
-			TRYPUTC('4');
-			TRYPUTC(';');
+			TRYPUTC('&',out);
+			TRYPUTC('#',out);
+			TRYPUTC('3',out);
+			TRYPUTC('4',out);
+			TRYPUTC(';',out);
 		} else {
-			TRYPUTC(*data);
+			TRYPUTC(*data,out);
 		}
 		data++;
@@ -2544,8 +2565,8 @@
 }
 
-cgiFormResultType cgiValueEscape(char *s)
+cgiFormResultType cgiValueEscape(char *s,FCGX_Stream *out)
 {
-	return cgiValueEscapeData(s, (int) strlen(s));
-}
-
-
+	return cgiValueEscapeData(s, (int) strlen(s),out);
+}
+
+
Index: branches/PublicaMundi_David-devel/thirds/cgic206/cgic.h
===================================================================
--- branches/PublicaMundi_David-devel/thirds/cgic206/cgic.h	(revision 547)
+++ branches/PublicaMundi_David-devel/thirds/cgic206/cgic.h	(revision 548)
@@ -10,6 +10,7 @@
 	types defined by it, such as FILE *. */
 
-#include "fcgi_stdio.h"
-//#include <stdio.h>
+//#include "fcgi_stdio.h"
+#include <fcgiapp.h>
+#include <stdio.h>
 
 /* The various CGI environment variables. Instead of using getenv(),
@@ -21,112 +22,57 @@
 	for debugging. */
 
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
+
+typedef struct cgiFormEntryStruct {
+        char *attr;
+    /* value is populated for regular form fields only.
+        For file uploads, it points to an empty string, and file
+        upload data should be read from the file tfileName. */ 
+    char *value;
+    /* When fileName is not an empty string, tfileName is not null,
+        and 'value' points to an empty string. */
+    /* Valid for both files and regular fields; does not include
+        terminating null of regular fields. */
+    int valueLength;
+    char *fileName; 
+    char *contentType;
+    /* Temporary file name for working storage of file uploads. */
+    char *tfileName;
+        struct cgiFormEntryStruct *next;
+} cgiFormEntry;
+
+
+
+
+struct cgi_env {
+int cgiRestored;// = 0;
 char *cgiServerSoftware;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiServerName;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiGatewayInterface;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiServerProtocol;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiServerPort;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiRequestMethod;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiPathInfo;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiPathTranslated;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiScriptName;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiQueryString;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiRemoteHost;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiRemoteAddr;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiAuthType;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiRemoteUser;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiRemoteIdent;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
-char *cgiContentType;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
+char cgiContentTypeData[1024];
+char *cgiContentType;// = cgiContentTypeData;
+
+char * cgiMultipartBoundary;
+cgiFormEntry *cgiFormEntryFirst;
+int cgiTreatUrlEncoding;
+
 char *cgiAccept;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiUserAgent;
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiReferrer;
 
 /* Cookies as sent to the server. You can also get them
 	individually, or as a string array; see the documentation. */
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiCookie;
-
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 char *cgiSid;
 
@@ -140,8 +86,4 @@
 	directly from cgiIn; the programmer need not do so. */
 
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
 int cgiContentLength;
 
@@ -152,20 +94,8 @@
 	cgiOut is always equivalent to stdout. */
 
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
-FILE *cgiOut;
-
-/* Pointer to CGI input. The programmer does not read from this.
-	We have continued to export it for backwards compatibility
-	so that cgic 1.x applications link properly. */
-
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
-FILE *cgiIn;
-
+char *cgiFindTarget;
+cgiFormEntry *cgiFindPos;
+
+};
 /* Possible return codes from the cgiForm family of functions (see below). */
 
@@ -195,5 +125,5 @@
 #endif
 cgiFormResultType cgiFormString(
-	char *name, char *result, int max);
+	char *name, char *result, int max,struct cgi_env **);
 
 extern 
@@ -202,5 +132,5 @@
 #endif
 cgiFormResultType cgiFormStringNoNewlines(
-	char *name, char *result, int max);
+	char *name, char *result, int max,struct cgi_env ** ce);
 
 
@@ -210,5 +140,5 @@
 #endif
 cgiFormResultType cgiFormStringSpaceNeeded(
-	char *name, int *length);
+	char *name, int *length,struct cgi_env ** ce);
 
 
@@ -218,5 +148,5 @@
 #endif
 cgiFormResultType cgiFormStringMultiple(
-	char *name, char ***ptrToStringArray);
+	char *name, char ***ptrToStringArray,struct cgi_env ** ce);
 
 extern 
@@ -231,5 +161,5 @@
 #endif
 cgiFormResultType cgiFormInteger(
-	char *name, int *result, int defaultV);
+	char *name, int *result, int defaultV,struct cgi_env ** ce);
 
 extern 
@@ -238,5 +168,5 @@
 #endif
 cgiFormResultType cgiFormIntegerBounded(
-	char *name, int *result, int min, int max, int defaultV);
+	char *name, int *result, int min, int max, int defaultV,struct cgi_env **ce);
 
 extern 
@@ -245,5 +175,5 @@
 #endif
 cgiFormResultType cgiFormDouble(
-	char *name, double *result, double defaultV);
+	char *name, double *result, double defaultV,struct cgi_env **);
 
 extern 
@@ -252,5 +182,5 @@
 #endif
 cgiFormResultType cgiFormDoubleBounded(
-	char *name, double *result, double min, double max, double defaultV);
+	char *name, double *result, double min, double max, double defaultV, struct cgi_env ** ce);
 
 extern 
@@ -260,5 +190,5 @@
 cgiFormResultType cgiFormSelectSingle(
 	char *name, char **choicesText, int choicesTotal, 
-	int *result, int defaultV);	
+	int *result, int defaultV,struct cgi_env **ce);	
 
 
@@ -269,5 +199,5 @@
 cgiFormResultType cgiFormSelectMultiple(
 	char *name, char **choicesText, int choicesTotal, 
-	int *result, int *invalid);
+	int *result, int *invalid,struct cgi_env **);
 
 /* Just an alias; users have asked for this */
@@ -279,5 +209,5 @@
 #endif
 cgiFormResultType cgiFormCheckboxSingle(
-	char *name);
+	char *name,struct cgi_env ** ce);
 
 extern 
@@ -287,5 +217,5 @@
 cgiFormResultType cgiFormCheckboxMultiple(
 	char *name, char **valuesText, int valuesTotal, 
-	int *result, int *invalid);
+	int *result, int *invalid,struct cgi_env ** ce);
 
 extern 
@@ -295,5 +225,5 @@
 cgiFormResultType cgiFormRadio(
 	char *name, char **valuesText, int valuesTotal, 
-	int *result, int defaultV);	
+	int *result, int defaultV,struct cgi_env **ce);	
 
 /* The paths returned by this function are the original names of files
@@ -305,5 +235,5 @@
 #endif
 cgiFormResultType cgiFormFileName(
-	char *name, char *result, int max);
+	char *name, char *result, int max,struct cgi_env **);
 
 /* The content type of the uploaded file, as reported by the browser.
@@ -315,5 +245,5 @@
 #endif
 cgiFormResultType cgiFormFileContentType(
-	char *name, char *result, int max);
+	char *name, char *result, int max,struct cgi_env ** ce);
 
 extern 
@@ -322,5 +252,5 @@
 #endif
 cgiFormResultType cgiFormFileSize(
-	char *name, int *sizeP);
+	char *name, int *sizeP,struct cgi_env ** ce);
 
 typedef struct cgiFileStruct *cgiFilePtr;
@@ -331,5 +261,5 @@
 #endif
 cgiFormResultType cgiFormFileOpen(
-	char *name, cgiFilePtr *cfpp);
+	char *name, cgiFilePtr *cfpp,struct cgi_env ** ce);
 
 extern 
@@ -352,5 +282,5 @@
 #endif
 cgiFormResultType cgiCookieString(
-	char *name, char *result, int max);
+	char *name, char *result, int max,char * cgiCookie);
 
 extern 
@@ -359,8 +289,8 @@
 #endif
 cgiFormResultType cgiCookieInteger(
-	char *name, int *result, int defaultV);
+	char *name, int *result, int defaultV,char * cgiCookie);
 
 cgiFormResultType cgiCookies(
-	char ***ptrToStringArray);
+	char ***ptrToStringArray,char* cgiCookie);
 
 /* path can be null or empty in which case a path of / (entire site) is set. 
@@ -372,5 +302,5 @@
 #endif
 void cgiHeaderCookieSetString(char *name, char *value, 
-	int secondsToLive, char *path, char *domain);
+	int secondsToLive, char *path, char *domain,FCGX_Stream *out);
 extern 
 #ifdef __cplusplus
@@ -378,20 +308,20 @@
 #endif
 void cgiHeaderCookieSetInteger(char *name, int value,
-	int secondsToLive, char *path, char *domain);
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
-void cgiHeaderLocation(char *redirectUrl);
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
-void cgiHeaderStatus(int status, char *statusMessage);
-extern 
-#ifdef __cplusplus
-"C" 
-#endif
-void cgiHeaderContentType(char *mimeType);
+	int secondsToLive, char *path, char *domain,FCGX_Stream *out);
+extern 
+#ifdef __cplusplus
+"C" 
+#endif
+void cgiHeaderLocation(char *redirectUrl,FCGX_Stream * out);
+extern 
+#ifdef __cplusplus
+"C" 
+#endif
+void cgiHeaderStatus(int status, char *statusMessage,FCGX_Stream * out);
+extern 
+#ifdef __cplusplus
+"C" 
+#endif
+void cgiHeaderContentType(char *mimeType,FCGX_Stream * out);
 
 typedef enum {
@@ -421,10 +351,10 @@
 #endif
 cgiFormResultType cgiFormEntries(
-	char ***ptrToStringArray);
+	char ***ptrToStringArray,struct cgi_env **ce);
 
 /* Output string with the <, &, and > characters HTML-escaped. 
 	's' is null-terminated. Returns cgiFormIO in the event
 	of error, cgiFormSuccess otherwise. */
-cgiFormResultType cgiHtmlEscape(char *s);
+cgiFormResultType cgiHtmlEscape(char *s,FCGX_Stream *out);
 
 /* Output data with the <, &, and > characters HTML-escaped. 
@@ -432,5 +362,5 @@
 	bytes in 'data'. Returns cgiFormIO in the event
 	of error, cgiFormSuccess otherwise. */
-cgiFormResultType cgiHtmlEscapeData(char *data, int len);
+cgiFormResultType cgiHtmlEscapeData(char *data, int len,FCGX_Stream *out);
 
 /* Output string with the " character HTML-escaped, and no
@@ -439,5 +369,5 @@
 	's' is null-terminated. Returns cgiFormIO in the event
 	of error, cgiFormSuccess otherwise. */
-cgiFormResultType cgiValueEscape(char *s);
+cgiFormResultType cgiValueEscape(char *s,FCGX_Stream *out);
 
 /* Output data with the " character HTML-escaped, and no
@@ -447,9 +377,9 @@
 	bytes in 'data'. Returns cgiFormIO in the event
 	of error, cgiFormSuccess otherwise. */
-cgiFormResultType cgiValueEscapeData(char *data, int len);
-
-int cgiMain_init(int argc, char *argv[]);
-
-void cgiFreeResources();
+cgiFormResultType cgiValueEscapeData(char *data, int len,FCGX_Stream *out);
+
+int cgiMain_init(int argc, char *argv[],struct cgi_env ** c,FCGX_Request *);
+
+void cgiFreeResources(struct cgi_env ** c);
 
 #endif /* CGI_C */
